public void RealDataCallBack(int lRealHandle, uint dwDataType, IntPtr pBuffer, uint dwBufSize, IntPtr pUser) { var alarmInfo = new MyDebugInfo(DebugInfo); switch (dwDataType) { case ChcNetSdk.NetDvrSyshead: // sys head if (dwBufSize > 0) { //获取播放句柄 Get the port to play if (!PlayCtrl.PlayM4_GetPort(ref _mLPort)) { _iLastErr = PlayCtrl.PlayM4_GetLastError(_mLPort); _str = "PlayM4_GetPort failed, error code= " + _iLastErr; BeginInvoke(alarmInfo, _str); break; } //设置流播放模式 Set the stream mode: real-time stream mode if (!PlayCtrl.PlayM4_SetStreamOpenMode(_mLPort, PlayCtrl.StreameRealtime)) { _iLastErr = PlayCtrl.PlayM4_GetLastError(_mLPort); _str = "Set STREAME_REALTIME mode failed, error code= " + _iLastErr; BeginInvoke(alarmInfo, _str); } //打开码流,送入头数据 Open stream if (!PlayCtrl.PlayM4_OpenStream(_mLPort, pBuffer, dwBufSize, 2 * 1024 * 1024)) { _iLastErr = PlayCtrl.PlayM4_GetLastError(_mLPort); _str = "PlayM4_OpenStream failed, error code= " + _iLastErr; BeginInvoke(alarmInfo, _str); break; } //设置显示缓冲区个数 Set the display buffer number if (!PlayCtrl.PlayM4_SetDisplayBuf(_mLPort, 15)) { _iLastErr = PlayCtrl.PlayM4_GetLastError(_mLPort); _str = "PlayM4_SetDisplayBuf failed, error code= " + _iLastErr; BeginInvoke(alarmInfo, _str); } //设置显示模式 Set the display mode if (!PlayCtrl.PlayM4_SetOverlayMode(_mLPort, 0, 0 /* COLORREF(0)*/)) //play off screen { _iLastErr = PlayCtrl.PlayM4_GetLastError(_mLPort); _str = "PlayM4_SetOverlayMode failed, error code= " + _iLastErr; BeginInvoke(alarmInfo, _str); } //设置解码回调函数,获取解码后音视频原始数据 Set callback function of decoded data _mFDisplayFun = DecCallbackFun; if (!PlayCtrl.PlayM4_SetDecCallBackEx(_mLPort, _mFDisplayFun, IntPtr.Zero, 0)) { BeginInvoke(alarmInfo, "PlayM4_SetDisplayCallBack fail"); } //开始解码 Start to play if (!PlayCtrl.PlayM4_Play(_mLPort, _mPtrRealHandle)) { _iLastErr = PlayCtrl.PlayM4_GetLastError(_mLPort); _str = "PlayM4_Play failed, error code= " + _iLastErr; BeginInvoke(alarmInfo, _str); } } break; case ChcNetSdk.NetDvrStreamdata: // video stream data if (dwBufSize > 0 && _mLPort != -1) { for (var i = 0; i < 999; i++) { //送入码流数据进行解码 Input the stream data to decode if (!PlayCtrl.PlayM4_InputData(_mLPort, pBuffer, dwBufSize)) { _iLastErr = PlayCtrl.PlayM4_GetLastError(_mLPort); _str = "PlayM4_InputData failed, error code= " + _iLastErr; Thread.Sleep(2); } else { break; } } } break; default: if (dwBufSize > 0 && _mLPort != -1) { //送入其他数据 Input the other data for (var i = 0; i < 999; i++) { if (!PlayCtrl.PlayM4_InputData(_mLPort, pBuffer, dwBufSize)) { _iLastErr = PlayCtrl.PlayM4_GetLastError(_mLPort); _str = "PlayM4_InputData failed, error code= " + _iLastErr; Thread.Sleep(2); } else { break; } } } break; } }
public void RealDataCallBack(Int32 lRealHandle, UInt32 dwDataType, IntPtr pBuffer, UInt32 dwBufSize, IntPtr pUser) { 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 m_lPort)) { iLastErr = PlayCtrl.PlayM4_GetLastError(m_lPort); str = "PlayM4_GetPort failed, error code= " + iLastErr; this.BeginInvoke(AlarmInfo, str); break; } //设置流播放模式 Set the stream mode: real-time stream mode if (!PlayCtrl.PlayM4_SetStreamOpenMode(m_lPort, PlayCtrl.STREAME_REALTIME)) { iLastErr = PlayCtrl.PlayM4_GetLastError(m_lPort); str = "Set STREAME_REALTIME mode failed, error code= " + iLastErr; this.BeginInvoke(AlarmInfo, str); } //打开码流,送入头数据 Open stream if (!PlayCtrl.PlayM4_OpenStream(m_lPort, pBuffer, dwBufSize, 2 * 1024 * 1024)) { iLastErr = PlayCtrl.PlayM4_GetLastError(m_lPort); str = "PlayM4_OpenStream failed, error code= " + iLastErr; this.BeginInvoke(AlarmInfo, str); break; } //设置显示缓冲区个数 Set the display buffer number if (!PlayCtrl.PlayM4_SetDisplayBuf(m_lPort, 15)) { iLastErr = PlayCtrl.PlayM4_GetLastError(m_lPort); str = "PlayM4_SetDisplayBuf failed, error code= " + iLastErr; this.BeginInvoke(AlarmInfo, str); } //设置显示模式 Set the display mode if (!PlayCtrl.PlayM4_SetOverlayMode(m_lPort, 0, 0 /* COLORREF(0)*/)) //play off screen { iLastErr = PlayCtrl.PlayM4_GetLastError(m_lPort); str = "PlayM4_SetOverlayMode failed, error code= " + iLastErr; this.BeginInvoke(AlarmInfo, str); } //设置解码回调函数,获取解码后音视频原始数据 Set callback function of decoded data m_fDisplayFun = new PlayCtrl.DECCBFUN(DecCallbackFUN); if (!PlayCtrl.PlayM4_SetDecCallBackEx(m_lPort, m_fDisplayFun, IntPtr.Zero, 0)) { this.BeginInvoke(AlarmInfo, "PlayM4_SetDisplayCallBack fail"); } //开始解码 Start to play if (!PlayCtrl.PlayM4_Play(m_lPort, m_ptrRealHandle)) { iLastErr = PlayCtrl.PlayM4_GetLastError(m_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 && m_lPort != -1) { for (int i = 0; i < 999; i++) { //送入码流数据进行解码 Input the stream data to decode if (!PlayCtrl.PlayM4_InputData(m_lPort, pBuffer, dwBufSize)) { iLastErr = PlayCtrl.PlayM4_GetLastError(m_lPort); str = "PlayM4_InputData failed, error code= " + iLastErr; Thread.Sleep(2); } else { break; } } } break; default: if (dwBufSize > 0 && m_lPort != -1) { //送入其他数据 Input the other data for (int i = 0; i < 999; i++) { if (!PlayCtrl.PlayM4_InputData(m_lPort, pBuffer, dwBufSize)) { iLastErr = PlayCtrl.PlayM4_GetLastError(m_lPort); str = "PlayM4_InputData failed, error code= " + iLastErr; Thread.Sleep(2); } else { break; } } } break; } }