Пример #1
0
        public void RealDataCallBack(Int32 lRealHandle, UInt32 dwDataType, IntPtr pBuffer, UInt32 dwBufSize, IntPtr pUser)
        {
            int lChannel = (int)pUser;
            int lPort    = channelPortDict[lChannel];

            //下面数据处理建议使用委托的方式
            MyDebugInfo AlarmInfo = new MyDebugInfo(DebugInfo);

            switch (dwDataType)
            {
            case CHCNetSDK.NET_DVR_SYSHEAD:         // sys head
                if (dwBufSize > 0)
                {
                    //获取播放句柄 Get the port to play
                    if (!PlayCtrl.PlayM4_GetPort(ref lPort))
                    {
                        iLastErr = PlayCtrl.PlayM4_GetLastError(lPort);
                        str      = "PlayM4_GetPort failed, error code= " + iLastErr;
                        this.BeginInvoke(AlarmInfo, str);
                        break;
                    }
                    else
                    {
                        channelPortDict[lChannel] = lPort;
                    }

                    //设置流播放模式 Set the stream mode: real-time stream mode
                    if (!PlayCtrl.PlayM4_SetStreamOpenMode(lPort, PlayCtrl.STREAME_REALTIME))
                    {
                        iLastErr = PlayCtrl.PlayM4_GetLastError(lPort);
                        str      = "Set STREAME_REALTIME mode failed, error code= " + iLastErr;
                        this.BeginInvoke(AlarmInfo, str);
                    }

                    //打开码流,送入头数据 Open stream
                    if (!PlayCtrl.PlayM4_OpenStream(lPort, pBuffer, dwBufSize, 2 * 1024 * 1024))
                    {
                        iLastErr = PlayCtrl.PlayM4_GetLastError(lPort);
                        str      = "PlayM4_OpenStream failed, error code= " + iLastErr;
                        this.BeginInvoke(AlarmInfo, str);
                        break;
                    }


                    //设置显示缓冲区个数 Set the display buffer number
                    if (!PlayCtrl.PlayM4_SetDisplayBuf(lPort, 15))
                    {
                        iLastErr = PlayCtrl.PlayM4_GetLastError(lPort);
                        str      = "PlayM4_SetDisplayBuf failed, error code= " + iLastErr;
                        this.BeginInvoke(AlarmInfo, str);
                    }

                    //设置显示模式 Set the display mode
                    if (!PlayCtrl.PlayM4_SetOverlayMode(lPort, 0, 0 /* COLORREF(0)*/))    //play off screen
                    {
                        iLastErr = PlayCtrl.PlayM4_GetLastError(lPort);
                        str      = "PlayM4_SetOverlayMode failed, error code= " + iLastErr;
                        this.BeginInvoke(AlarmInfo, str);
                    }

                    //设置解码回调函数,获取解码后音视频原始数据 Set callback function of decoded data
                    PlayCtrl.DECCBFUN m_fDisplayFun = new PlayCtrl.DECCBFUN(DecCallbackFUN);
                    fDisplayFunDict.Add(lChannel, m_fDisplayFun);
                    if (!PlayCtrl.PlayM4_SetDecCallBackExMend(lPort, m_fDisplayFun, IntPtr.Zero, 0, lPort))
                    {
                        //this.BeginInvoke(AlarmInfo, "PlayM4_SetDisplayCallBack fail");
                    }


                    //开始解码 Start to play
                    if (!PlayCtrl.PlayM4_Play(lPort, ptrRealHandleDict[lChannel]))
                    {
                        iLastErr = PlayCtrl.PlayM4_GetLastError(lPort);
                        str      = "PlayM4_Play failed, error code= " + iLastErr;
                        this.BeginInvoke(AlarmInfo, str);
                        break;
                    }
                }
                break;

            case CHCNetSDK.NET_DVR_STREAMDATA:         // video stream data
                if (dwBufSize > 0 && lPort != -1)
                {
                    //for (int i = 0; i < 999; i++)  //dingyh
                    {
                        //送入码流数据进行解码 Input the stream data to decode
                        if (!PlayCtrl.PlayM4_InputData(lPort, pBuffer, dwBufSize))
                        {
                            iLastErr = PlayCtrl.PlayM4_GetLastError(lPort);
                            str      = "PlayM4_InputData failed, error code= " + iLastErr;
                            Thread.Sleep(2);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                break;

            default:
                if (dwBufSize > 0 && lPort != -1)
                {
                    //送入其他数据 Input the other data
                    //for (int i = 0; i < 999; i++) //dingyh
                    {
                        if (!PlayCtrl.PlayM4_InputData(lPort, pBuffer, dwBufSize))
                        {
                            iLastErr = PlayCtrl.PlayM4_GetLastError(lPort);
                            str      = "PlayM4_InputData failed, error code= " + iLastErr;
                            Thread.Sleep(2);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                break;
            }
        }