Ejemplo n.º 1
0
        public async Task <int> StopRealPreview()
        {
            if (m_lReadHandle < 0)
            {
                LoggerService.logger.Error($"摄像头{ip},未启动过预览。");
                return(-1);
            }

            if (!HKNetSDKS.NET_DVR_StopRealPlay(m_lReadHandle))
            {
                LoggerService.logger.Error($"摄像头{ip},播放器无法停止预览。错误代码:{HKNetSDKS.NET_DVR_GetLastError()}");
            }

            if (m_lPort >= 0)
            {
                if (!HKPlayCtrlSDK.PlayM4_Stop(m_lPort))
                {
                    LoggerService.logger.Error($"摄像头{ip},播放器无法停止工作。错误代码:{HKPlayCtrlSDK.PlayM4_GetLastError(m_lPort)}");
                }

                if (!HKPlayCtrlSDK.PlayM4_CloseStream(m_lPort))
                {
                    LoggerService.logger.Error($"摄像头{ip},播放器无法关闭数据流。错误代码:{HKPlayCtrlSDK.PlayM4_GetLastError(m_lPort)}");
                }
                if (!HKPlayCtrlSDK.PlayM4_FreePort(m_lPort))
                {
                    LoggerService.logger.Error($"摄像头{ip},播放器无法释放播放端口。错误代码:{HKPlayCtrlSDK.PlayM4_GetLastError(m_lPort)}");
                }

                m_lPort = -1;
            }


            LoggerService.logger.Info($"摄像头{ip},已停止预览。");

            m_lReadHandle = -1;
            Statue        = CameraStatue.StopReadPlay;
            if (PictrueBoxId != null)
            {
                PictrueBoxId.Invalidate();
                PictrueBoxId = null;
            }
            return(0);
        }
Ejemplo n.º 2
0
        public void RealDataCallBack(int lReadHandle, uint dwDataType, IntPtr pBuffer, uint dwBufSize, IntPtr pUser)
        {
            switch (dwDataType)
            {
            case GloableVar.NET_DVR_SYSHEAD:
            {
                if (dwBufSize > 0)
                {
                    if (m_lPort >= 0)
                    {
                        return;
                    }

                    //获取播放器句柄
                    if (!HKPlayCtrlSDK.PlayM4_GetPort(ref m_lPort))
                    {
                        LoggerService.logger.Error($"摄像头{ip},获取播放句柄错误 代码:{HKPlayCtrlSDK.PlayM4_GetLastError(m_lPort)}");
                        break;
                    }

                    //设置流播放模式
                    if (!HKPlayCtrlSDK.PlayM4_SetStreamOpenMode(m_lPort, GloableVar.STREAME_REALTIME))
                    {
                        LoggerService.logger.Error($"摄像头{ip},设置播放流错误 代码:{HKPlayCtrlSDK.PlayM4_GetLastError(m_lPort)}");
                    }

                    //打开码流,送入头数据 1080P视频流建议开到6M的缓存
                    if (!HKPlayCtrlSDK.PlayM4_OpenStream(m_lPort, pBuffer, dwBufSize, 6 * 1024 * 1024))
                    {
                        LoggerService.logger.Error($"摄像头{ip},打开播放流错误 代码:{HKPlayCtrlSDK.PlayM4_GetLastError(m_lPort)}");
                        break;
                    }

                    //设置显示缓冲区个数
                    if (!HKPlayCtrlSDK.PlayM4_SetDisplayBuf(m_lPort, 1))
                    {
                        LoggerService.logger.Error($"摄像头{ip},设置显示缓存区错误 代码:{HKPlayCtrlSDK.PlayM4_GetLastError(m_lPort)}");
                    }

                    //设置显示模式
                    if (!HKPlayCtrlSDK.PlayM4_SetOverlayMode(m_lPort, 0, 0))
                    {
                        LoggerService.logger.Error($"摄像头{ip},设置显示属性错误 代码:{HKPlayCtrlSDK.PlayM4_GetLastError(m_lPort)}");
                    }

                    //deccbfun也是个解码器,将DecCallbackFUN方法传入,为了将yu12图片通过Egmu转化成bgr格式的图片
                    m_fDisplayFun = new HKPlayCtrlSDK.DECCBFUN(DecCallbackFUN);
                    if (!HKPlayCtrlSDK.PlayM4_SetDecCallBackEx(m_lPort, m_fDisplayFun, IntPtr.Zero, 0))
                    {
                        LoggerService.logger.Error($"摄像头{ip},设置解码回调函数错误 代码:{HKPlayCtrlSDK.PlayM4_GetLastError(m_lPort)}");
                    }

                    if (!HKPlayCtrlSDK.PlayM4_Play(m_lPort, m_ptrReadHandle))
                    {
                        LoggerService.logger.Error($"摄像头{ip},播放软件播放错误 代码:{HKPlayCtrlSDK.PlayM4_GetLastError(m_lPort)}");
                        break;
                    }

                    LoggerService.logger.Info($"摄像头{ip},解码器运行,通道{m_lPort}");
                }
            }
            break;

            case GloableVar.NET_DVR_STREAMDATA:     //如果是流数据
            default:
            {
                if (dwBufSize > 0 && m_lPort != -1)
                {
                    bool inData = HKPlayCtrlSDK.PlayM4_InputData(m_lPort, pBuffer, dwBufSize);
                    while (!inData)
                    {
                        Thread.Sleep(10);
                        //play4是解码器,解码成为一个图片,但图片是vy12的格式图片
                        inData = HKPlayCtrlSDK.PlayM4_InputData(m_lPort, pBuffer, dwBufSize);
                    }
                }
            }
            break;
            }
        }