/// <summary> /// 停止预览摄像头视频,并清理命名管道 /// </summary> /// <param name="cameraNo"></param> /// <returns></returns> public SmcErr StopReceiveVideoByPipe(string cameraNo) { SmcErr err = new CgwError(); NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log); err = CheckSession(currentSessionID); //调任何接口前 需要判断监控平台是否加载成功 if (err.IsSuccess()) { err = VideoMonitorManage.Instance().StopReceiveVideo(cameraNo); VideoPipe videoPipe = VideoPipeManage.Instance().DeleteVideoPipe(cameraNo); if (videoPipe == null) { logEx.Error("MonitorManageService StopReceiveVideoByPipe failed,VideoPipe is null,cameraNo = {0}", cameraNo); err.SetErrorNo(CgwError.STOP_RECEIVE_VIDEO_FAILED); } else { videoPipe.Stop(); } } if (err.IsSuccess()) { logEx.Info("MonitorManageService StopReceiveVideoByPipe Successful,Current Cgw IP is : {0}", CgwConst.ClientIp); } else { logEx.Error("MonitorManageService StopReceiveVideoByPipe failed,ErrNo :{0}", err.ErrNo); } return(err); }
/// <summary> /// 指定码流数据异常回调函数 /// </summary> /// <param name="dataExceptionCallBack">回调函数</param> public void SetDataExceptionCallBackFunc(Common.DataExceptionCallBack dataExceptionCallBack) { NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log); logEx.Trace("Enter: CgwMonitorManageAdapter.SetDataExceptionCallBackFunc({0})", dataExceptionCallBack); VideoPipeManage.Instance().SetDataExceptionCallBackFunc(dataExceptionCallBack); }
/// <summary> /// 码流回调委托 /// </summary> /// <param name="cameraNo">摄像头编号</param> /// <param name="mediaData">码流</param> /// <param name="sender">调用者,区别哪个平台的回调</param> public void DataCallBackFunc(string cameraNo, MediaData mediaData, string sender) { NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log); //logEx.Trace("Enter: MonitorManageService.SetDataCallBackFunc.sender ={0},cameraNo ={1}", sender, cameraNo); VideoPipe videoPipe = VideoPipeManage.Instance().GetVideoPipe(cameraNo); if (videoPipe != null && videoPipe.HaveConnect) { videoPipe.SenderData(mediaData); //logEx.Trace("Enter: Send MediaData.sender ={0},cameraNo ={1},size ={2},data ={3}", sender, cameraNo, mediaData.Size, mediaData.Data); } }
/// <summary> /// 停止预览摄像头视频,并清理命名管道 /// </summary> /// <param name="cameraNo"></param> /// <returns></returns> public Cgw.SmcError.SmcErr StopReceiveVideoByPipe(string cameraNo) { NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log); logEx.Trace("Enter: CgwMonitorManageAdapter.StopReceiveVideoByPipe"); Cgw.SmcError.SmcErr err = new Cgw.SmcError.SmcErr(); try { //if (serviceControl.MonitorServiceRun() && client.State == CommunicationState.Opened) if (serviceControl.MonitorServiceRun()) { client = new MonitorManageServiceClient(); CgwMonitorManageServiceReference.SmcErr serviceErr = client.StopReceiveVideoByPipe(cameraNo); client.Close(); if (serviceErr.ErrNo != Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_SUCCESS) { logEx.Error("CgwMonitorManageAdapter.StopReceiveVideoByPipe failed. ErrNo = {0} ", serviceErr.ErrNo); err = SetCgwErrNo(serviceErr); } else { VideoPipe videoPipe = VideoPipeManage.Instance().DeleteVideoPipe(cameraNo); if (videoPipe != null) { videoPipe.Stop(); logEx.Info("CgwMonitorManageAdapter.StopReceiveVideoByPipe Success. cameraNo = {0} ", cameraNo); } else { logEx.Error("CgwMonitorManageAdapter.StopReceiveVideoByPipe failed. ErrNo = {0} ", serviceErr.ErrNo); } } } else { err.SetErrorNo(Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_RESTARTING); } } catch (System.Exception ex) { err.SetErrorNo(Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_RESTARTING); logEx.Error("CgwMonitorManageServiceReference.StopReceiveVideoByPipe failed. Exception is {0} ", ex.ToString()); logEx.Error("CameraNo:" + cameraNo); } return(err); }
/// <summary> /// 预览摄像头视频,使用命名管道方式接收数据 /// </summary> /// <param name="cameraNo"></param> /// <param name="pipeName"></param> /// <returns></returns> public SmcErr StartReceiveVideoByPipe(string cameraNo, out string pipeName) { SmcErr err = new CgwError(); NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log); pipeName = string.Empty; err = CheckSession(currentSessionID); //调任何接口前 需要判断监控平台是否加载成功 if (err.IsSuccess()) { err = VideoMonitorManage.Instance().StartReceiveVideo(cameraNo); //开始监控平台成功、开始通过管道发送数据 if (err.IsSuccess()) { VideoPipeManage.Instance().DeleteVideoPipe(cameraNo); VideoPipe videoPipe = VideoPipeManage.Instance().AddVideoPipe(cameraNo); if (videoPipe != null) { pipeName = videoPipe.PipeName; videoPipe.Run(); logEx.Info("MonitorManageService StartReceiveVideoByPipe Successful,Current Cgw IP is : {0}", CgwConst.ClientIp); } else { logEx.Error("MonitorManageService AddVideoPipe failed.cameraNo = {0}", cameraNo); err.SetErrorNo(CgwError.START_RECEIVE_VIDEO_FAILED); StopReceiveVideoByPipe(cameraNo); } } else { logEx.Error("MonitorManageService StartReceiveVideoByPipe failed,ErrNo :{0}", err.ErrNo); } } else { logEx.Error("MonitorManageService StartReceiveVideoByPipe failed,ErrNo :{0}", err.ErrNo); } return(err); }
/// <summary> /// 预览摄像头视频,使用命名管道方式接收数据 /// </summary> /// <param name="cameraNo"></param> /// <param name="pipeName"></param> /// <returns></returns> public Cgw.SmcError.SmcErr StartReceiveVideoByPipe(string cameraNo, out string pipeName) { NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log); logEx.Trace("Enter: CgwMonitorManageAdapter.StartReceiveVideoByPipe"); pipeName = ""; Cgw.SmcError.SmcErr err = new Cgw.SmcError.SmcErr(); try { //if (serviceControl.MonitorServiceRun() && client.State == CommunicationState.Opened) if (serviceControl.MonitorServiceRun()) { client = new MonitorManageServiceClient(); CgwMonitorManageServiceReference.SmcErr serviceErr = client.StartReceiveVideoByPipe(out pipeName, cameraNo); client.Close(); if (serviceErr.ErrNo != Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_SUCCESS) { logEx.Error("CgwMonitorManageAdapter.StartReceiveVideoByPipe failed. ErrNo = {0} ", serviceErr.ErrNo); err = SetCgwErrNo(serviceErr); } else { //将摄像头通道删除。避免重启服务后,VideoPipe未清除,导致调用停止播放。by zWX231378 2015/7/16 VideoPipe delVideoPipe = VideoPipeManage.Instance().DeleteVideoPipe(cameraNo); if (delVideoPipe != null) { logEx.Info("CgwMonitorManageAdapter.StartReceiveVideoByPipe delete VideoPipe. cameraNo = {0}", cameraNo); delVideoPipe.Stop(); } VideoPipe videoPipe = VideoPipeManage.Instance().AddVideoPipe(cameraNo, pipeName); if (videoPipe != null) { try { videoPipe.Run(); if (videoPipe.HaveConnect) { videoPipe.ReadData(this.dataCallBack); logEx.Info("CgwMonitorManageAdapter.StartReceiveVideoByPipe Success. pipeName = {0} ", pipeName); } else { logEx.Error("CgwMonitorManageAdapter.StartReceiveVideoByPipe failed. cameraNo = {0} ", cameraNo); } } catch (System.Exception ex) { logEx.Error("CgwMonitorManageAdapter.StartReceiveVideoByPipe Exception= {0} ", ex.ToString()); } } else { logEx.Error("CgwMonitorManageAdapter.StartReceiveVideoByPipe failed. cameraNo = {0} ", cameraNo); } } } else { //当监控服务未启动,则关闭管道。 //StopReceiveVideoByPipe(cameraNo); err.SetErrorNo(Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_RESTARTING); } } catch (System.Exception ex) { err.SetErrorNo(Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_RESTARTING); logEx.Error("CgwMonitorManageServiceReference.StartReceiveVideoByPipe failed. Exception is {0} ", ex.ToString()); } return(err); }