public void RemoteDisplayCBFun(int nPort, IntPtr pBuf, int nSize, int nWidth, int nHeight, int nStamp, int nType, int nReserved)
        {
            //MyDebugInfo AlarmInfo = new MyDebugInfo(DebugInfo);
            if (!m_bJpegCapture)
            {
                return;
            }
            else
            {
                uint nLastErr = 100;
                // save picture as you want
                if (!PlayCtrl.PlayM4_ConvertToJpegFile(pBuf, nSize, nWidth, nHeight, nType, "C:/Capture.jpg"))
                {
                    //Debug.WriteLine("PlayM4_ConvertToJpegFile fail");
                    nLastErr = PlayCtrl.PlayM4_GetLastError(m_lPort);
                    //this.BeginInvoke(AlarmInfo, "Jpeg Capture fail");
                }
                else
                {
                    // this.BeginInvoke(AlarmInfo, "Jpeg Capture Succ");
                    //Debug.WriteLine("PlayM4_ConvertToJpegFile Succ");
                }
            }

            m_bJpegCapture = false;
        }
Пример #2
0
        private void btnJpegCapture_Click(object sender, EventArgs e)
        {
            m_bJpegCapture = true;
            IntPtr ptrJpeg     = new IntPtr();
            uint   nBuffersize = 2 * 1024 * 1024;

            ptrJpeg = Marshal.AllocHGlobal((int)nBuffersize);
            uint dwJpegSize = 0;

            if (PlayCtrl.PlayM4_GetJPEG(m_lPort, ptrJpeg, nBuffersize, ref dwJpegSize))
            {
                DebugInfo("PlayM4_GetJPEG succ");
            }
            else
            {
                uint dwErrorNo = PlayCtrl.PlayM4_GetLastError(m_lPort);
                DebugInfo("PlayM4_GetJPEG fail");
            }
            FileStream fs = new FileStream("C:/GetJpegSave.jpg", FileMode.Create);

            byte[] by = new byte[dwJpegSize];
            Marshal.Copy(ptrJpeg, by, 0, (int)dwJpegSize);
            fs.Write(by, 0, (int)dwJpegSize);
            fs.Close();

            Marshal.FreeHGlobal(ptrJpeg);
            //public static extern bool PlayM4_GetJPEG(int nPort, ref byte pJpeg, uint nBufSize, ref uint pJpegSize);
        }
Пример #3
0
        private void btnPrivate_Click(object sender, EventArgs e)
        {
            int iPort = CHCNetSDK.NET_DVR_GetRealPlayerIndex(m_lRealHandle);

            if (iPort > -1)
            {
                if (!PlayCtrl.PlayM4_RenderPrivateData(iPort, 0x20, true))
                {
                    iLastErr = PlayCtrl.PlayM4_GetLastError(iPort);
                    str      = "PlayM4_RenderPrivateData failed, error code= " + iLastErr;
                    DebugInfo(str);
                }
                if (!PlayCtrl.PlayM4_RenderPrivateDataEx(iPort, 0x00000020, 0x00000001 + 0x00000002 + 0x00000004, true))
                {
                    iLastErr = PlayCtrl.PlayM4_GetLastError(iPort);
                    str      = "PlayM4_RenderPrivateDataEx failed, error code= " + iLastErr;
                    DebugInfo(str);
                }
                if (!PlayCtrl.PlayM4_SetOverlayPriInfoFlag(iPort, 0x20, true))
                {
                    iLastErr = PlayCtrl.PlayM4_GetLastError(iPort);
                    str      = "PlayM4_SetOverlayPriInfoFlag failed, error code= " + iLastErr;
                    DebugInfo(str);
                }
            }
        }
Пример #4
0
 private void StartPlayVideo(string filename)
 {
     if (filename != "")
     {
         StopVideo();
         if (PlayCtrl.PlayM4_GetPort(ref m_lPort))
         {
             m_ptrRealHandle = picPlayBack.Handle;
             m_FileRefDone   = new PlayCtrl.PFILEREFDONE(PlayCallBack);
             if (PlayCtrl.PlayM4_SetFileRefCallBack(m_lPort, m_FileRefDone, 0))
             {
             }
             if (PlayCtrl.PlayM4_OpenFile(m_lPort, filename))
             {
                 if (PlayCtrl.PlayM4_Play(m_lPort, m_ptrRealHandle))
                 {
                     m_CurPlayState = PlayState.PlayNormal;
                     SetCtrlEnable();
                 }
                 else
                 {
                     uint error = PlayCtrl.PlayM4_GetLastError(m_lPort);
                 }
             }
         }
         else
         {
             uint error = PlayCtrl.PlayM4_GetLastError(m_lPort);
         }
     }
 }
Пример #5
0
 private void StopVideo()
 {
     if (m_CurPlayState != PlayState.PlayStop && m_CurPlayState != PlayState.None)
     {
         if (PlayCtrl.PlayM4_Stop(m_lPort))
         {
             if (PlayCtrl.PlayM4_CloseFile(m_lPort))
             {
                 if (PlayCtrl.PlayM4_FreePort(m_lPort))
                 {
                     m_CurPlayState = PlayState.PlayStop;
                     SetCtrlEnable();
                 }
             }
             else
             {
                 uint error = PlayCtrl.PlayM4_GetLastError(m_lPort);
             }
         }
         else
         {
             uint error = PlayCtrl.PlayM4_GetLastError(m_lPort);
         }
     }
 }
Пример #6
0
        private void RemoteDisplayCBFun(int nPort, IntPtr pBuf, int nSize, int nWidth, int nHeight, int nStamp, int nType, int nReserved)
        {
            try
            {
                if (!m_bJpegCapture)
                {
                    return;
                }
                else
                {
                    uint nLastErr = 100;
                    // save picture as you want
                    if (!PlayCtrl.PlayM4_ConvertToJpegFile(pBuf, nSize, nWidth, nHeight, nType, "C:/Capture.jpg"))
                    {
                        nLastErr = PlayCtrl.PlayM4_GetLastError(nPort);  //m_Channel
                    }
                    else
                    {
                    }
                }

                m_bJpegCapture = false;
            }
            catch (Exception ex)
            { }
        }
Пример #7
0
        /// <summary>
        ///		Start Preview in realtime.
        ///		<para><paramref name="playWndHandle"/> - window handle, on fitch will be drawing.</para>
        ///		<para><paramref name="previewSettings"/> - preview settings.</para>
        /// </summary>
        public void StartPreview(IntPtr playWndHandle, NvrPreviewSettings previewSettings)
        {
            if (livePlayer_.RealPlayHandle != -1)
            {
                throw new NvrBadLogicException("Call StopPreview before calling StartPreview");
            }

            if (!NvrUserSession.IsSessionValid())
            {
                throw new NvrBadLogicException("Call StartPreview when NvrUserSession is invalid");
            }

            livePlayer_ = new LivePlayer(playWndHandle, previewSettings);

            CHCNetSDK.NET_DVR_PREVIEWINFO previewInfo = new CHCNetSDK.NET_DVR_PREVIEWINFO()
            {
                lChannel        = NvrUserSession.UserSessionState.SelectedChannelNum,
                dwStreamType    = livePlayer_.PreviewSettings.StreamType,
                dwLinkMode      = (uint)livePlayer_.PreviewSettings.LinkMode,
                bBlocked        = livePlayer_.PreviewSettings.IsBlocked,
                dwDisplayBufNum = livePlayer_.PreviewSettings.DisplayBufNum,
                byPreviewMode   = (byte)livePlayer_.PreviewSettings.PreviewMode
            };

            switch (previewSettings.PreviewHandleMode)
            {
            case PreviewHandleType.Direct:
                livePlayer_.RealDataCallBackFunc = null;
                previewInfo.hPlayWnd             = livePlayer_.PlayWndHandlePtr;
                break;

            case PreviewHandleType.CallBack:
                livePlayer_.RealDataCallBackFunc = new CHCNetSDK.REALDATACALLBACK(realDataCallBack);                        // Real-time stream callback function
                previewInfo.hPlayWnd             = IntPtr.Zero;
                break;
            }

            livePlayer_.RealPlayHandle = CHCNetSDK.NET_DVR_RealPlay_V40(NvrUserSession.UserSessionState.UserId, ref previewInfo, livePlayer_.RealDataCallBackFunc, IntPtr.Zero);

            if (livePlayer_.RealPlayHandle == -1)
            {
                throw new NvrSdkException(CHCNetSDK.NET_DVR_GetLastError(), "NET_DVR_RealPlay_V40 failed: " + livePlayer_.RealPlayHandle);
            }

            if (previewSettings.PreviewHandleMode == PreviewHandleType.Direct)
            {
                livePlayer_.DrawCallBackFunc = new CHCNetSDK.DRAWFUN(drawCallBack);
                if (!CHCNetSDK.NET_DVR_RigisterDrawFun(livePlayer_.RealPlayHandle, livePlayer_.DrawCallBackFunc, 0))
                {
                    invokeOnPreviewErrorEvent(PlayCtrl.PlayM4_GetLastError(livePlayer_.RealPlayPort), "NET_DVR_RigisterDrawFun failed");
                }
            }

            debugInfo("NET_DVR_RealPlay_V40 succ!");
        }
Пример #8
0
        /// <summary>
        ///		Stop Preview.
        /// </summary>
        public void StopPreview()
        {
            if (livePlayer_.RealPlayHandle == -1)
            {
                debugInfo("Preview not started!");
                return;
            }

            {
                // Set to null Draw CallBack Function
                CHCNetSDK.NET_DVR_RigisterDrawFun(livePlayer_.RealPlayHandle, null, 0);
            }

            bool isStopRealPlayOk;

            {
                // Stop live view
                isStopRealPlayOk = CHCNetSDK.NET_DVR_StopRealPlay(livePlayer_.RealPlayHandle);

                if (livePlayer_.RealPlayPort >= 0)
                {
                    if (!PlayCtrl.PlayM4_Stop(livePlayer_.RealPlayPort))
                    {
                        invokeOnPreviewErrorEvent(PlayCtrl.PlayM4_GetLastError(livePlayer_.RealPlayPort), "PlayM4_Stop failed");
                    }

                    if (!PlayCtrl.PlayM4_CloseStream(livePlayer_.RealPlayPort))
                    {
                        invokeOnPreviewErrorEvent(PlayCtrl.PlayM4_GetLastError(livePlayer_.RealPlayPort), "PlayM4_CloseStream failed");
                    }

                    if (!PlayCtrl.PlayM4_FreePort(livePlayer_.RealPlayPort))
                    {
                        invokeOnPreviewErrorEvent(PlayCtrl.PlayM4_GetLastError(livePlayer_.RealPlayPort), "PlayM4_FreePort failed");
                    }
                }
            }

            livePlayer_ = LivePlayer.Default();

            if (isStopRealPlayOk)
            {
                debugInfo("NET_DVR_StopRealPlay succ!");
            }
            else
            {
                throw new NvrSdkException(CHCNetSDK.NET_DVR_GetLastError(), "NET_DVR_StopRealPlay failed");
            }
        }
Пример #9
0
        private void realDataCallBack(int realHandle, uint dataType, IntPtr buffer, uint bufferSize, IntPtr pUser)
        {
            if (bufferSize <= 0)
            {
                return;
            }

            if (dataType == CHCNetSDK.NET_DVR_SYSHEAD)
            {
                if (livePlayer_.RealPlayPort >= 0)
                {
                    return;                     // The same code stream does not need to call the open stream interface multiple times.
                }

                // Get the port to play
                if (!PlayCtrl.PlayM4_GetPort(ref livePlayer_.RealPlayPort))
                {
                    invokeOnPreviewErrorEvent(PlayCtrl.PlayM4_GetLastError(livePlayer_.RealPlayPort), "PlayM4_GetPort failed");
                    return;
                }

                // Set the stream mode: real-time stream mode
                if (!PlayCtrl.PlayM4_SetStreamOpenMode(livePlayer_.RealPlayPort, PlayCtrl.STREAME_REALTIME))
                {
                    invokeOnPreviewErrorEvent(PlayCtrl.PlayM4_GetLastError(livePlayer_.RealPlayPort), "PlayM4_SetStreamOpenMode 'STREAME_REALTIME' failed");
                    return;
                }

                // Open stream
                if (!PlayCtrl.PlayM4_OpenStream(livePlayer_.RealPlayPort, buffer, bufferSize, livePlayer_.PreviewSettings.PlayerBufSize))
                {
                    invokeOnPreviewErrorEvent(PlayCtrl.PlayM4_GetLastError(livePlayer_.RealPlayPort), "PlayM4_OpenStream failed");
                    return;
                }

                // Set the display buffer number
                if (!PlayCtrl.PlayM4_SetDisplayBuf(livePlayer_.RealPlayPort, livePlayer_.PreviewSettings.DisplayBufNum))
                {
                    invokeOnPreviewErrorEvent(PlayCtrl.PlayM4_GetLastError(livePlayer_.RealPlayPort), "PlayM4_SetDisplayBuf failed");
                    return;
                }

                // Set the display mode
                if (!PlayCtrl.PlayM4_SetOverlayMode(livePlayer_.RealPlayPort, 0, 0 /* COLORREF(0)*/))
                {
                    invokeOnPreviewErrorEvent(PlayCtrl.PlayM4_GetLastError(livePlayer_.RealPlayPort), "PlayM4_SetOverlayMode failed");
                    return;
                }

                if (livePlayer_.PreviewSettings.PreviewQuality != PreviewQualityType.NotSet)
                {
                    if (!PlayCtrl.PlayM4_SetPicQuality(livePlayer_.RealPlayPort, (int)livePlayer_.PreviewSettings.PreviewQuality))
                    {
                        invokeOnPreviewErrorEvent(PlayCtrl.PlayM4_GetLastError(livePlayer_.RealPlayPort), "PlayM4_SetPicQuality failed");
                        return;
                    }
                }

                // Set the decoding callback function to obtain the decoded audio and video raw data.
                //m_fDisplayFun = new PlayCtrl.DECCBFUN(DecCallbackFUN);
                //if (!PlayCtrl.PlayM4_SetDecCallBackEx(livePlayer_.RealPlayPort, m_fDisplayFun, IntPtr.Zero, 0)) {
                //	invokeOnPreviewErrorEvent(PlayCtrl.PlayM4_GetLastError(livePlayer_.RealPlayPort), "PlayM4_SetDecCallBackEx failed");
                //}

                // Start to play
                if (!PlayCtrl.PlayM4_Play(livePlayer_.RealPlayPort, livePlayer_.PlayWndHandlePtr))
                {
                    invokeOnPreviewErrorEvent(PlayCtrl.PlayM4_GetLastError(livePlayer_.RealPlayPort), "PlayM4_Play failed");
                    return;
                }
            }
            else if (dataType == CHCNetSDK.NET_DVR_AUDIOSTREAMDATA)
            {
                debugInfo("NET_DVR_AUDIOSTREAMDATA");
            }
            else if (dataType == 112 /*NET_DVR_PRIVATE_DATA*/)
            {
                // NET_DVR_PRIVATE_DATA - Private data, including intelligent information
            }
            else
            {
                // dataType == CHCNetSDK.NET_DVR_STREAMDATA or else
                if (livePlayer_.RealPlayPort != -1)
                {
                    for (int i = 0; i < 999; i++)
                    {
                        // Input the stream data to decode
                        if (!PlayCtrl.PlayM4_InputData(livePlayer_.RealPlayPort, buffer, bufferSize))
                        {
                            debugInfo("RealDataCallBack: PlayM4_InputData failed, error=" + PlayCtrl.PlayM4_GetLastError(livePlayer_.RealPlayPort));
                            Thread.Sleep(50);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
        }
Пример #10
0
        private void btnPreview_Click(object sender, EventArgs e)
        {
            if (_mLUserId < 0)
            {
                MessageBox.Show(@"Please login the device firstly!");
                return;
            }

            if (_mBRecord)
            {
                MessageBox.Show(@"Please stop recording firstly!");
                return;
            }

            if (_mLRealHandle < 0)
            {
                var lpPreviewInfo = new ChcNetSdk.NetDvrPreviewinfo
                {
                    hPlayWnd     = RealPlayWnd.Handle,
                    lChannel     = _iChannelNum[(int)_iSelIndex],
                    dwStreamType = 0,
                    dwLinkMode   = 0,
                    bBlocked     = true
                };
                //预览窗口 live view window
                //预览的设备通道 the device channel number
                //码流类型:0-主码流,1-子码流,2-码流3,3-码流4,以此类推
                //连接方式:0- TCP方式,1- UDP方式,2- 多播方式,3- RTP方式,4-RTP/RTSP,5-RSTP/HTTP
                //0- 非阻塞取流,1- 阻塞取流

                var pUser = IntPtr.Zero;//用户数据 user data

                if (comboBoxView.SelectedIndex == 0)
                {
                    //打开预览 Start live view
                    _mLRealHandle = ChcNetSdk.NET_DVR_RealPlay_V40(_mLUserId, ref lpPreviewInfo, null /*RealData*/, pUser);
                }
                else
                {
                    lpPreviewInfo.hPlayWnd = IntPtr.Zero; //预览窗口 live view window
                    _mPtrRealHandle        = RealPlayWnd.Handle;
                    _realData     = RealDataCallBack;     //预览实时流回调函数 real-time stream callback function
                    _mLRealHandle = ChcNetSdk.NET_DVR_RealPlay_V40(_mLUserId, ref lpPreviewInfo, _realData, pUser);
                }

                if (_mLRealHandle < 0)
                {
                    _iLastErr = ChcNetSdk.NET_DVR_GetLastError();
                    _str      = "NET_DVR_RealPlay_V40 failed, error code= " + _iLastErr; //预览失败,输出错误号 failed to start live view, and output the error code.
                    DebugInfo(_str);
                }
                else
                {
                    //预览成功
                    DebugInfo("NET_DVR_RealPlay_V40 succ!");
                    btnPreview.Text = @"Stop View";
                }
            }
            else
            {
                //停止预览 Stop live view
                if (!ChcNetSdk.NET_DVR_StopRealPlay(_mLRealHandle))
                {
                    _iLastErr = ChcNetSdk.NET_DVR_GetLastError();
                    _str      = "NET_DVR_StopRealPlay failed, error code= " + _iLastErr;
                    DebugInfo(_str);
                    return;
                }

                if ((comboBoxView.SelectedIndex == 1) && (_mLPort >= 0))
                {
                    if (!PlayCtrl.PlayM4_Stop(_mLPort))
                    {
                        _iLastErr = PlayCtrl.PlayM4_GetLastError(_mLPort);
                        _str      = "PlayM4_Stop failed, error code= " + _iLastErr;
                        DebugInfo(_str);
                    }
                    if (!PlayCtrl.PlayM4_CloseStream(_mLPort))
                    {
                        _iLastErr = PlayCtrl.PlayM4_GetLastError(_mLPort);
                        _str      = "PlayM4_CloseStream failed, error code= " + _iLastErr;
                        DebugInfo(_str);
                    }
                    if (!PlayCtrl.PlayM4_FreePort(_mLPort))
                    {
                        _iLastErr = PlayCtrl.PlayM4_GetLastError(_mLPort);
                        _str      = "PlayM4_FreePort failed, error code= " + _iLastErr;
                        DebugInfo(_str);
                    }
                    _mLPort = -1;
                }

                DebugInfo("NET_DVR_StopRealPlay succ!");
                _mLRealHandle   = -1;
                btnPreview.Text = @"Live View";
                RealPlayWnd.Invalidate();//刷新窗口 refresh the window
            }
        }
Пример #11
0
        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;
            }
        }
Пример #12
0
        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;
            }
        }
Пример #13
0
        private void btnPreview_Click(object sender, EventArgs e)
        {
            if (camera_id < 0)
            {
                MessageBox.Show("Please login the device firstly!");
                return;
            }

            if (m_bRecord)
            {
                MessageBox.Show("Please stop recording firstly!");
                return;
            }
            //    MessageBox.Show();
            if (camera_handle < 0)
            {
                CHCNetSDK.NET_DVR_PREVIEWINFO lpPreviewInfo = new CHCNetSDK.NET_DVR_PREVIEWINFO();
                lpPreviewInfo.hPlayWnd     = picCameraOutput.Handle;      //预览窗口 live view window
                lpPreviewInfo.lChannel     = iChannelNum[(int)iSelIndex]; //预览的设备通道 the device channel number
                lpPreviewInfo.dwStreamType = 0;                           //码流类型:0-主码流,1-子码流,2-码流3,3-码流4,以此类推
                lpPreviewInfo.dwLinkMode   = 0;                           //连接方式:0- TCP方式,1- UDP方式,2- 多播方式,3- RTP方式,4-RTP/RTSP,5-RSTP/HTTP
                lpPreviewInfo.bBlocked     = true;                        //0- 非阻塞取流,1- 阻塞取流

                IntPtr pUser = IntPtr.Zero;                               //用户数据 user data

                if (true)
                {
                    //打开预览 Start live view
                    camera_handle = CHCNetSDK.NET_DVR_RealPlay_V40(camera_id, ref lpPreviewInfo, null /*RealData*/, pUser);
                }
                else
                {
                    lpPreviewInfo.hPlayWnd = IntPtr.Zero;                             //预览窗口 live view window
                    m_ptrRealHandle        = picCameraOutput.Handle;
                    RealData      = new CHCNetSDK.REALDATACALLBACK(RealDataCallBack); //预览实时流回调函数 real-time stream callback function
                    camera_handle = CHCNetSDK.NET_DVR_RealPlay_V40(camera_id, ref lpPreviewInfo, RealData, pUser);
                }

                if (camera_handle < 0)
                {
                    iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                    str      = "NET_DVR_RealPlay_V40 failed, error code= " + iLastErr; //预览失败,输出错误号 failed to start live view, and output the error code.
                    DebugInfo(str);
                    return;
                }
                else
                {
                    //预览成功
                    DebugInfo("NET_DVR_RealPlay_V40 succ!");
                    //btnPreview.Text = "Stop View";
                }
            }
            else
            {
                //停止预览 Stop live view
                if (!CHCNetSDK.NET_DVR_StopRealPlay(camera_handle))
                {
                    iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                    str      = "NET_DVR_StopRealPlay failed, error code= " + iLastErr;
                    DebugInfo(str);
                    return;
                }

                if ((true) && (m_lPort >= 0))
                {
                    if (!PlayCtrl.PlayM4_Stop(m_lPort))
                    {
                        iLastErr = PlayCtrl.PlayM4_GetLastError(m_lPort);
                        str      = "PlayM4_Stop failed, error code= " + iLastErr;
                        DebugInfo(str);
                    }
                    if (!PlayCtrl.PlayM4_CloseStream(m_lPort))
                    {
                        iLastErr = PlayCtrl.PlayM4_GetLastError(m_lPort);
                        str      = "PlayM4_CloseStream failed, error code= " + iLastErr;
                        DebugInfo(str);
                    }
                    if (!PlayCtrl.PlayM4_FreePort(m_lPort))
                    {
                        iLastErr = PlayCtrl.PlayM4_GetLastError(m_lPort);
                        str      = "PlayM4_FreePort failed, error code= " + iLastErr;
                        DebugInfo(str);
                    }
                    m_lPort = -1;
                }

                DebugInfo("NET_DVR_StopRealPlay succ!");
                camera_handle = -1;
                // btnPreview.Text = "Live View";
                picCameraOutput.Invalidate();//刷新窗口 refresh the window
            }
            return;
        }
Пример #14
0
        private void ConnectToCamera()
        {
            try
            {
                string ip_address_top = txtIPAddress.Text;

                Int16  DVRPortNumber = 8000;
                string DVRUserName   = txtUsername.Text;
                string DVRPassword   = txtPassword.Text;
                //登录设备 Login the device
                camera_id       = CHCNetSDK.NET_DVR_Login_V30(ip_address_top, DVRPortNumber, DVRUserName, DVRPassword, ref DeviceInfo_top);
                dwAChanTotalNum = (uint)DeviceInfo_top.byChanNum;

                for (i = 0; i < dwAChanTotalNum; i++)
                {
                    ListAnalogChannel(i + 1, 1);
                    iChannelNum[i] = i + (int)DeviceInfo_top.byStartChan;
                }
                if (camera_id < 0)
                {
                    if (MessageBox.Show("IP Cameras Connecting Error", "Fatal Error - IP Camera", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry)
                    {
                        btnStart_Click(null, null);
                        return;
                    }
                }
                if (m_bRecord)
                {
                    MessageBox.Show("Please stop recording firstly!");
                    return;
                }
                if (camera_handle < 0)
                {
                    //  StartLiveView();

                    if (camera_handle < 0)
                    {
                        iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                        str      = "NET_DVR_RealPlay_V40 failed, error code= " + iLastErr; //预览失败,输出错误号 failed to start live view, and output the error code.
                        DebugInfo(str);
                        return;
                    }
                    else
                    {
                        //预览成功
                        DebugInfo("NET_DVR_RealPlay_V40 succ!");
                        // btnStart.Text = "Stop View";
                    }
                }
                else
                {
                    //停止预览 Stop live view
                    if (!CHCNetSDK.NET_DVR_StopRealPlay(camera_handle))
                    {
                        iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                        str      = "NET_DVR_StopRealPlay failed, error code= " + iLastErr;
                        DebugInfo(str);
                        return;
                    }

                    if ((true) && (m_lPort >= 0))
                    {
                        if (!PlayCtrl.PlayM4_Stop(m_lPort))
                        {
                            iLastErr = PlayCtrl.PlayM4_GetLastError(m_lPort);
                            str      = "PlayM4_Stop failed, error code= " + iLastErr;
                            DebugInfo(str);
                        }
                        if (!PlayCtrl.PlayM4_CloseStream(m_lPort))
                        {
                            iLastErr = PlayCtrl.PlayM4_GetLastError(m_lPort);
                            str      = "PlayM4_CloseStream failed, error code= " + iLastErr;
                            DebugInfo(str);
                        }
                        if (!PlayCtrl.PlayM4_FreePort(m_lPort))
                        {
                            iLastErr = PlayCtrl.PlayM4_GetLastError(m_lPort);
                            str      = "PlayM4_FreePort failed, error code= " + iLastErr;
                            DebugInfo(str);
                        }
                        m_lPort = -1;
                    }

                    DebugInfo("NET_DVR_StopRealPlay succ!");
                    camera_handle = -1;
                    //btnStart.Text= "Live View";
                    picCameraOutput.Invalidate();//刷新窗口 refresh the window
                }
            }
            catch
            {
                //btnStart.Enabled = true;
                //btnStop.Enabled = false;
                MessageBox.Show("Error in Connecting Camera\nContact SSF Groups");
                Application.Exit();
                this.Close();
                return;
            }

            //btnStart.Enabled = false;
        }
Пример #15
0
        private void btnBMP_Click(object sender, EventArgs e)
        {
            if (m_lRealHandle < 0)
            {
                DebugInfo("Please start live view firstly!"); //BMP抓图需要先打开预览
                return;
            }

            string sBmpPicFileName;

            //图片保存路径和文件名 the path and file name to save
            sBmpPicFileName = "test.bmp";

            if (comboBoxView.SelectedIndex == 0)
            {
                //BMP抓图 Capture a BMP picture
                if (!CHCNetSDK.NET_DVR_CapturePicture(m_lRealHandle, sBmpPicFileName))
                {
                    iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                    str      = "NET_DVR_CapturePicture failed, error code= " + iLastErr;
                    DebugInfo(str);
                    return;
                }
                else
                {
                    str = "NET_DVR_CapturePicture succ and the saved file is " + sBmpPicFileName;
                    DebugInfo(str);
                }
            }
            else
            {
                int  iWidth = 0, iHeight = 0;
                uint iActualSize = 0;

                if (!PlayCtrl.PlayM4_GetPictureSize(m_lPort, ref iWidth, ref iHeight))
                {
                    iLastErr = PlayCtrl.PlayM4_GetLastError(m_lPort);
                    str      = "PlayM4_GetPictureSize failed, error code= " + iLastErr;
                    DebugInfo(str);
                    return;
                }

                uint nBufSize = (uint)(iWidth * iHeight) * 5;

                byte[] pBitmap = new byte[nBufSize];

                if (!PlayCtrl.PlayM4_GetBMP(m_lPort, pBitmap, nBufSize, ref iActualSize))
                {
                    iLastErr = PlayCtrl.PlayM4_GetLastError(m_lPort);
                    str      = "PlayM4_GetBMP failed, error code= " + iLastErr;
                    DebugInfo(str);
                }
                else
                {
                    FileStream fs = new FileStream(sBmpPicFileName, FileMode.Create);
                    fs.Write(pBitmap, 0, (int)iActualSize);
                    fs.Close();
                    str = "PlayM4_GetBMP succ and the saved file is " + sBmpPicFileName;
                    DebugInfo(str);
                }
            }
            return;
        }
Пример #16
0
        /// <summary>
        /// 关闭视频
        /// </summary>
        public override void CloseAllVideo(bool IsExit)
        {
            try
            {
                for (int i = 0; i < m_lRealHandle.Length; i++)
                {
                    if (IsCallBack)
                    {
                        if (m_Channel[i] != -1)
                        {
                            //if (!PlayCtrl.PlayM4_FEC_Disable(m_Channel[i]))
                            //{
                            //    iLastErr = PlayCtrl.PlayM4_GetLastError(m_Channel[i]);
                            //}
                            if (!PlayCtrl.PlayM4_Stop(m_Channel[i]))
                            {
                                iLastErr = PlayCtrl.PlayM4_GetLastError(m_Channel[i]);
                            }
                            if (!PlayCtrl.PlayM4_CloseStream(m_Channel[i]))
                            {
                                iLastErr = PlayCtrl.PlayM4_GetLastError(m_Channel[i]);
                            }
                            //if (!PlayCtrl.PlayM4_CloseFile(m_Channel[i]))
                            //{
                            //    iLastErr = PlayCtrl.PlayM4_GetLastError(m_Channel[i]);
                            //}
                            if (!PlayCtrl.PlayM4_FreePort(m_Channel[i]))
                            {
                                iLastErr = PlayCtrl.PlayM4_GetLastError(m_Channel[i]);
                            }
                            m_Channel[i] = -1;
                        }
                    }
                    if (m_lRealHandle[i] >= 0)
                    {
                        bool IsStopReal = CHCNetSDK.NET_DVR_StopRealPlay(m_lRealHandle[i]);
                        m_lRealHandle[i] = -1;
                    }
                    IsPreviewing = false;
                }
                IsPreviewing = false;
                this.pnlPreview.BackgroundImage = global::ToolsManage.Properties.Resources.播放;
                //关闭当前回放视频
                if (m_lPlayBackHandle != -1)
                {
                    CHCNetSDK.NET_DVR_StopPlayBack(m_lPlayBackHandle);
                    m_lPlayBackHandle = -1;
                }
                if (m_PlayBackPort != -1)
                {
                    PlayCtrl.PlayM4_Stop(m_PlayBackPort);
                    if (PlayCtrl.PlayM4_CloseStream(m_PlayBackPort))
                    {
                        PlayCtrl.PlayM4_FreePort(m_PlayBackPort);
                        m_PlayBackPort = -1;
                    }
                }

                //if (m_PlayBackRet >= 0)
                //{
                //    CHCNetSDK.NET_DVR_StopPlayBack(m_PlayBackRet);
                //    m_PlayBackRet = -1;
                //}
                bool IsOk = false;
                if (IsExit)
                {
                    if (m_lUserID >= 0)
                    {
                        //IsOk = CHCNetSDK.NET_DVR_Logout_V30(m_lUserID);
                        IsOk = CHCNetSDK.NET_DVR_Logout(m_lUserID);
                    }
                    if (m_bInitSDK == true)
                    {
                        IsOk = CHCNetSDK.NET_DVR_Cleanup();
                    }
                    if (!IsOk)
                    {
                    }
                }
            }
            catch (Exception ex)
            {
                TXTWriteHelper.WriteException("StopHikVideo-" + ex.ToString());
            }
        }
Пример #17
0
        private void RealDataCallBack(Int32 lRealHandler, UInt32 dwDataType, ref byte pBuffer, UInt32 dwBufSize, IntPtr pUser)
        {
            try
            {
                int lRealHandle = 0;
                if (dicRealHandlerChannel.ContainsKey(lRealHandler))
                {
                    lRealHandle = dicRealHandlerChannel[lRealHandler] % StartDChan;
                }
                else
                {
                    return;
                }
                //int lRealHandle = lRealHandler % CameraCount;
                uint dwErr = 0;
                switch (dwDataType)
                {
                case CHCNetSDK.NET_DVR_SYSHEAD:
                    if (m_Channel[lRealHandle] != -1)
                    {
                        return;
                    }
                    if (m_Channel[lRealHandle] == -1)
                    {
                        if (!PlayCtrl.PlayM4_GetPort(ref m_Channel[lRealHandle]))
                        {
                            //dwErr = PlayCtrl.PlayM4_GetLastError(m_Channel);
                        }
                        //m_Channel[lRealHandle] = lRealHandle;
                        uint version = PlayCtrl.PlayM4_GetSdkVersion();
                    }
                    if (dwBufSize > 0)
                    {
                        if (!PlayCtrl.PlayM4_SetStreamOpenMode(m_Channel[lRealHandle], m_StreamPlayMode))      //设置实时流播放模式
                        {
                            dwErr = PlayCtrl.PlayM4_GetLastError(m_Channel[lRealHandle]);
                            break;
                        }

                        if (!PlayCtrl.PlayM4_OpenStream(m_Channel[lRealHandle], ref pBuffer, dwBufSize, 15 * 1024 * 1024))     //打开流接口
                        {
                            dwErr = PlayCtrl.PlayM4_GetLastError(m_Channel[lRealHandle]);
                            break;
                        }

                        if (!PlayCtrl.PlayM4_SetDisplayBuf(m_Channel[lRealHandle], 6))
                        {
                            dwErr = PlayCtrl.PlayM4_GetLastError(m_Channel[lRealHandle]);
                            break;
                        }

                        //if (!PlayCtrl.PlayM4_SetDecodeEngineEx(m_Channel[lRealHandle], PlayCtrl.HARD_DECODE_ENGINE))
                        //{
                        //    dwErr = PlayCtrl.PlayM4_GetLastError(m_Channel[lRealHandle]);
                        //    break;
                        //}
                        if (CheckEagleEyeStream(dicRealHandlerChannel[lRealHandler]))    //小鹰眼码流的特殊处理
                        {
                            if (!PlayCtrl.PlayM4_SetDecodeEngineEx(m_Channel[lRealHandle], PlayCtrl.HARD_DECODE_ENGINE))
                            {
                                break;
                            }
                            //UCVideo video= listVideo.Find(p => Convert.ToInt32(p.Tag) == lRealHandle);
                            PlayCtrl.PLAYM4SRMODELMODE struParam = new PlayCtrl.PLAYM4SRMODELMODE();
                            struParam.emTextureMode  = (uint)PlayCtrl.PLAYM4SRTEXTUREMODE.PLAYM4_TEXTURE_DOUBLE;
                            struParam.ulDisplayType  = PlayCtrl.PLAYM4_MODEL_SOLID;
                            struParam.nTransformMode = 0;
                            struParam.emModelType    = (uint)PlayCtrl.PLAYM4SRMODELTYPE.PLAYM4_MODELTYPE_EAGLE_EYE;
                            struParam.bModelMode     = true; // true是碗装,false是块状
                            int    dwSize       = Marshal.SizeOf(struParam);
                            IntPtr ptrDeviceCfg = Marshal.AllocHGlobal(dwSize);
                            Marshal.StructureToPtr(struParam, ptrDeviceCfg, false);
                            if (!PlayCtrl.PlayM4_SR_SetConfig(m_Channel[lRealHandle], PlayCtrl.CFG_DISPLAY_MODEL_MODE, ptrDeviceCfg))
                            {
                                Marshal.FreeHGlobal(ptrDeviceCfg);
                                break;
                            }
                            Marshal.FreeHGlobal(ptrDeviceCfg);
                        }

                        if (!PlayCtrl.PlayM4_Play(m_Channel[lRealHandle], m_ptrRealHandle[lRealHandle]))     //播放开始
                        {
                            break;
                        }
                    }
                    break;

                case CHCNetSDK.NET_DVR_STREAMDATA:
                    if (dwBufSize > 0 && m_Channel[lRealHandle] != -1)
                    {
                        for (int i = 0; i < 4000; i++)
                        {
                            if (!PlayCtrl.PlayM4_InputData(m_Channel[lRealHandle], ref pBuffer, dwBufSize))
                            {
                                dwErr = PlayCtrl.PlayM4_GetLastError(m_Channel[lRealHandle]);
                                if (dwErr == PlayCtrl.PLAYM4_BUF_OVER)
                                {
                                    continue;
                                }
                                else
                                {
                                    return;
                                }
                            }
                            else
                            {
                                return;
                            }
                        }
                    }
                    break;
                }
            }
            catch (Exception ex)
            { }
        }
Пример #18
0
        public void btnPreview_Click_1(object sender, EventArgs e)
        {
            if (m_lUserID < 0)
            {
                DebugInfo("预览失败,请检查是否登录录像机!");
                return;
            }
            if (m_bRecord)
            {
                DebugInfo("预览失败,请先停止正在录制的录像机!");
                return;
            }

            if (m_lRealHandle < 0)
            {
                CHCNetSDK.NET_DVR_PREVIEWINFO lpPreviewInfo = new CHCNetSDK.NET_DVR_PREVIEWINFO();
                lpPreviewInfo.hPlayWnd        = RealPlayWnd.Handle;          //预览窗口 live view window
                lpPreviewInfo.lChannel        = iChannelNum[(int)iSelIndex]; //预览的设备通道 the device channel number
                lpPreviewInfo.dwStreamType    = 0;                           //码流类型:0-主码流,1-子码流,2-码流3,3-码流4,以此类推
                lpPreviewInfo.dwLinkMode      = 0;                           //连接方式:0- TCP方式,1- UDP方式,2- 多播方式,3- RTP方式,4-RTP/RTSP,5-RSTP/HTTP
                lpPreviewInfo.bBlocked        = true;                        //0- 非阻塞取流,1- 阻塞取流
                lpPreviewInfo.dwDisplayBufNum = 15;                          //播放库显示缓冲区最大帧数
                IntPtr pUser = IntPtr.Zero;                                  //用户数据 user data
                if (comboBoxView.SelectedIndex == 0)
                {
                    //打开预览 Start live view
                    m_lRealHandle = CHCNetSDK.NET_DVR_RealPlay_V40(m_lUserID, ref lpPreviewInfo, null /*RealData*/, pUser);
                }
                else
                {
                    lpPreviewInfo.hPlayWnd = IntPtr.Zero;                             //预览窗口 live view window
                    m_ptrRealHandle        = RealPlayWnd.Handle;
                    RealData      = new CHCNetSDK.REALDATACALLBACK(RealDataCallBack); //预览实时流回调函数 real-time stream callback function
                    m_lRealHandle = CHCNetSDK.NET_DVR_RealPlay_V40(m_lUserID, ref lpPreviewInfo, RealData, pUser);
                }
                if (m_lRealHandle < 0)
                {
                    iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                    str      = "预览失败,错误代码:" + iLastErr;
                    DebugInfo(str);
                    return;
                }
                else
                {
                    //预览成功
                    DebugInfo("预览成功!");
                    recordStatus    = 3;
                    btnPreview.Text = "关闭录像机";
                }
            }
            else
            {
                //停止预览 Stop live view
                if (!CHCNetSDK.NET_DVR_StopRealPlay(m_lRealHandle))
                {
                    iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                    str      = "停止预览失败,错误代码:" + iLastErr;
                    DebugInfo(str);
                    return;
                }

                if ((comboBoxView.SelectedIndex == 1) && (m_lPort >= 0))
                {
                    if (!PlayCtrl.PlayM4_Stop(m_lPort))
                    {
                        iLastErr = PlayCtrl.PlayM4_GetLastError(m_lPort);
                        str      = "PlayM4_Stop failed, error code= " + iLastErr;
                        DebugInfo(str);
                    }
                    if (!PlayCtrl.PlayM4_CloseStream(m_lPort))
                    {
                        iLastErr = PlayCtrl.PlayM4_GetLastError(m_lPort);
                        str      = "PlayM4_CloseStream failed, error code= " + iLastErr;
                        DebugInfo(str);
                    }
                    if (!PlayCtrl.PlayM4_FreePort(m_lPort))
                    {
                        iLastErr = PlayCtrl.PlayM4_GetLastError(m_lPort);
                        str      = "PlayM4_FreePort failed, error code= " + iLastErr;
                        DebugInfo(str);
                    }
                    m_lPort = -1;
                }
                DebugInfo("停止预览成功!");
                m_lRealHandle   = -1;
                recordStatus    = 2;
                btnPreview.Text = "启动录像机";
                RealPlayWnd.Invalidate();//刷新窗口 refresh the window
            }
            return;
        }