Ejemplo n.º 1
0
        public bool StartDynamicDecode(CameraConf camera, int iWnd)
        {
            CHCNetSDK.NET_DVR_PU_STREAM_CFG_V41 struStreamCfgV41 = new CHCNetSDK.NET_DVR_PU_STREAM_CFG_V41();
            CHCNetSDK.NET_DVR_DEC_STREAM_DEV_EX struStreamDev    = new CHCNetSDK.NET_DVR_DEC_STREAM_DEV_EX();

            struStreamCfgV41.dwSize                       = (uint)Marshal.SizeOf(struStreamCfgV41);
            struStreamCfgV41.byStreamMode                 = 1; //取流模式
            struStreamDev.struDevChanInfo.byChanType      = 0; //通道类型
            struStreamDev.struDevChanInfo.byChannel       = 0; //该参数无效,通道号见dwChannel
            struStreamDev.struDevChanInfo.byTransProtocol = 0; //传输协议类型0-TCP,1-UDP
            struStreamDev.struDevChanInfo.byFactoryType   = 0; //前端设备厂家类型,通过接口获取

            struStreamDev.struDevChanInfo.byAddress   = camera.CameraIP;
            struStreamDev.struDevChanInfo.wDVRPort    = (ushort)camera.CameraPort;
            struStreamDev.struDevChanInfo.dwChannel   = (uint)camera.DwChannel; //通道号
            struStreamDev.struDevChanInfo.byTransMode = (byte)camera.Mllx;      //传输码流模式
            struStreamDev.struDevChanInfo.sUserName   = camera.RasUser;
            struStreamDev.struDevChanInfo.sPassword   = camera.RasPassword;

            if (!string.IsNullOrEmpty(camera.MediaIP))                    //流媒体 IP 不为空
            {
                struStreamDev.struStreamMediaSvrCfg.byValid        = 1;   //启用流媒体
                struStreamDev.struStreamMediaSvrCfg.wDevPort       = 554; //端口
                struStreamDev.struStreamMediaSvrCfg.byTransmitType = 0;   //TCP
                struStreamDev.struStreamMediaSvrCfg.byAddress      = camera.MediaIP;
            }

            uint   dwUnionSize    = (uint)Marshal.SizeOf(struStreamCfgV41.uDecStreamMode);
            IntPtr ptrStreamUnion = Marshal.AllocHGlobal((Int32)dwUnionSize);

            Marshal.StructureToPtr(struStreamDev, ptrStreamUnion, false);
            struStreamCfgV41.uDecStreamMode = (CHCNetSDK.NET_DVR_DEC_STREAM_MODE)Marshal.PtrToStructure(ptrStreamUnion, typeof(CHCNetSDK.NET_DVR_DEC_STREAM_MODE));
            Marshal.FreeHGlobal(ptrStreamUnion);

            if (!CHCNetSDK.NET_DVR_MatrixStartDynamic_V41(m_userId, m_deChannel[iWnd], ref struStreamCfgV41))
            {
                uint errorCode = CHCNetSDK.NET_DVR_GetLastError();
                Log.GetLogger().ErrorFormat("NET_DVR_MatrixStartDynamic_V41 failed, error code = {0}", errorCode);
                return(false);
            }

            Log.GetLogger().InfoFormat("开启动态解码,考车{0},ecode={1},子窗口={2},mediaIP={3},码流={4}(0主码流,1子码流),{5}_{6}",
                                       m_kch, camera.CameraBH, m_deChannel[iWnd], camera.MediaIP, camera.Mllx, camera.CameraIP, camera.DwChannel);
            return(true);
        }
Ejemplo n.º 2
0
        private void btnChanInfo_Click(object sender, EventArgs e)
        {
            CHCNetSDK.NET_DVR_MATRIX_DEC_CHAN_INFO_V41 m_struDecChanInfo = new CHCNetSDK.NET_DVR_MATRIX_DEC_CHAN_INFO_V41();

            if (!CHCNetSDK.NET_DVR_MatrixGetDecChanInfo_V41(m_lUserID, dwDecChanNum, ref m_struDecChanInfo))
            {
                iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                strErr   = "NET_DVR_MatrixGetDecChanInfo_V41 failed, error code= " + iLastErr;
                //获取当前解码通道信息失败,输出错误号 Failed to get the decoding info of the channel and output the error code
                MessageBox.Show(strErr);
            }
            else
            {
                comboBoxStreamMode.SelectedIndex = m_struDecChanInfo.byStreamMode - 1;
                //通过IP地址或者域名从设备或者流媒体服务器取流
                if (m_struDecChanInfo.byStreamMode == 1)
                {
                    uint   dwUnionSize    = (uint)Marshal.SizeOf(m_struDecChanInfo.uDecStreamMode);
                    IntPtr ptrStreamUnion = Marshal.AllocHGlobal((Int32)dwUnionSize);
                    Marshal.StructureToPtr(m_struDecChanInfo.uDecStreamMode, ptrStreamUnion, false);
                    m_struStreamDev = (CHCNetSDK.NET_DVR_DEC_STREAM_DEV_EX)Marshal.PtrToStructure(ptrStreamUnion, typeof(CHCNetSDK.NET_DVR_DEC_STREAM_DEV_EX));
                    Marshal.FreeHGlobal(ptrStreamUnion);

                    comboBoxChanType.SelectedIndex = m_struStreamDev.struDevChanInfo.byChanType;
                    if (m_struStreamDev.struDevChanInfo.byChanType == 2)
                    {
                        textBoxChanNo.Text = m_struStreamDev.struDevChanInfo.byStreamId;
                    }
                    else
                    {
                        textBoxChanNo.Text = Convert.ToString(m_struStreamDev.struDevChanInfo.dwChannel);
                    }

                    textBoxDevIP.Text                = m_struStreamDev.struDevChanInfo.byAddress;
                    textBoxDevPort.Text              = Convert.ToString(m_struStreamDev.struDevChanInfo.wDVRPort);
                    comboBoxTransType.SelectedIndex  = m_struStreamDev.struDevChanInfo.byTransProtocol;
                    comboBoxStreamType.SelectedIndex = m_struStreamDev.struDevChanInfo.byTransMode;
                    for (int i = 0; i < (int)m_struProtoList.dwProtoNum; i++)
                    {
                        //设备(厂家)协议类型,通过NET_DVR_GetIPCProtoList获取
                        if (m_struProtoList.struProto[i].dwType == m_struStreamDev.struDevChanInfo.byFactoryType)
                        {
                            comboBoxFactory.SelectedIndex = i;
                        }
                    }
                    textBoxUserName.Text = m_struStreamDev.struDevChanInfo.sUserName;
                    textBoxPassword.Text = m_struStreamDev.struDevChanInfo.sPassword;

                    if (m_struStreamDev.struStreamMediaSvrCfg.byValid == 1)
                    {
                        checkBoxStreamSever.Checked         = true;
                        textBoxSeverIP.Text                 = m_struStreamDev.struStreamMediaSvrCfg.byAddress;
                        textBoxServerPort.Text              = Convert.ToString(m_struStreamDev.struStreamMediaSvrCfg.wDevPort);
                        comboBoxSeverProcotol.SelectedIndex = m_struStreamDev.struStreamMediaSvrCfg.byTransmitType;
                    }
                    else
                    {
                        checkBoxStreamSever.Checked = false;
                    }
                }

                //通过URL从设备或者流媒体服务器取流
                if (m_struDecChanInfo.byStreamMode == 2)
                {
                    uint   dwUnionSize    = (uint)Marshal.SizeOf(m_struDecChanInfo.uDecStreamMode);
                    IntPtr ptrStreamUnion = Marshal.AllocHGlobal((Int32)dwUnionSize);
                    Marshal.StructureToPtr(m_struDecChanInfo.uDecStreamMode, ptrStreamUnion, false);
                    m_struStreamURL = (CHCNetSDK.NET_DVR_PU_STREAM_URL)Marshal.PtrToStructure(ptrStreamUnion, typeof(CHCNetSDK.NET_DVR_PU_STREAM_URL));
                    Marshal.FreeHGlobal(ptrStreamUnion);

                    if (m_struStreamURL.byEnable == 1)
                    {
                        textBoxURL.Text = m_struStreamURL.strURL;
                    }
                }

                //通过动态域名解析从设备或者流媒体服务器取流
                if (m_struDecChanInfo.byStreamMode == 3)
                {
                    uint   dwUnionSize    = (uint)Marshal.SizeOf(m_struDecChanInfo.uDecStreamMode);
                    IntPtr ptrStreamUnion = Marshal.AllocHGlobal((Int32)dwUnionSize);
                    Marshal.StructureToPtr(m_struDecChanInfo.uDecStreamMode, ptrStreamUnion, false);
                    m_struStreamDDNS = (CHCNetSDK.NET_DVR_DEC_DDNS_DEV)Marshal.PtrToStructure(ptrStreamUnion, typeof(CHCNetSDK.NET_DVR_DEC_DDNS_DEV));
                    Marshal.FreeHGlobal(ptrStreamUnion);

                    comboBoxChanType_D.SelectedIndex = m_struStreamDDNS.struDdnsInfo.byChanType;
                    if (m_struStreamDDNS.struDdnsInfo.byChanType == 2)
                    {
                        textBoxChanNo_D.Text = m_struStreamDDNS.struDdnsInfo.byStreamId;
                    }
                    else
                    {
                        textBoxChanNo_D.Text = Convert.ToString(m_struStreamDDNS.struDdnsInfo.dwChannel);
                    }

                    textBoxDevDomain.Text              = m_struStreamDDNS.struDdnsInfo.byDevAddress;
                    comboBoxTransType_D.SelectedIndex  = m_struStreamDDNS.struDdnsInfo.byTransProtocol;
                    comboBoxStreamType_D.SelectedIndex = m_struStreamDDNS.struDdnsInfo.byTransMode;
                    textBoxDDNSAddr.Text = m_struStreamDDNS.struDdnsInfo.byDdnsAddress;
                    textBoxDDNSPort.Text = Convert.ToString(m_struStreamDDNS.struDdnsInfo.wDdnsPort);

                    for (int i = 0; i < (int)m_struProtoList.dwProtoNum; i++)
                    {
                        //设备(厂家)协议类型,通过NET_DVR_GetIPCProtoList获取
                        if (m_struProtoList.struProto[i].dwType == m_struStreamDDNS.struDdnsInfo.byFactoryType)
                        {
                            comboBoxFactory_D.SelectedIndex = i;
                        }
                    }

                    textBoxUserName_D.Text = m_struStreamDDNS.struDdnsInfo.sUserName;
                    textBoxPassword_D.Text = m_struStreamDDNS.struDdnsInfo.sPassword;
                    textBoxDevPort_D.Text  = Convert.ToString(m_struStreamDDNS.struDdnsInfo.wDevPort);

                    if (m_struStreamDDNS.struMediaServer.byValid == 1)
                    {
                        checkBoxStreamSever.Checked         = true;
                        textBoxSeverIP.Text                 = m_struStreamDDNS.struMediaServer.byAddress;
                        textBoxServerPort.Text              = Convert.ToString(m_struStreamDDNS.struMediaServer.wDevPort);
                        comboBoxSeverProcotol.SelectedIndex = m_struStreamDDNS.struMediaServer.byTransmitType;
                    }
                    else
                    {
                        checkBoxStreamSever.Checked = false;
                    }
                }
            }
        }