コード例 #1
0
        public override void OpenForSnapshot(bool _async)
        {
            if (!_IsReadyForSnapshot)
            {
                ST_DeviceInfo stDeviceInfo = new ST_DeviceInfo();
                stDeviceInfo.st_InetAddr.szHostIP    = VideoSource.MediaSource;
                stDeviceInfo.st_InetAddr.nPORT       = (ushort)VideoSource.StreamPort;
                stDeviceInfo.st_InetAddr.nIPProtoVer = 1;
                stDeviceInfo.szUserID    = VideoSource.UserName;
                stDeviceInfo.szPassword  = VideoSource.Password;
                stDeviceInfo.nDeviceType = 1;  //

                int nRet      = 0;
                int nProtocol = 1;  //1表示udp协议,2表示tcp协议 4表示rtp协议
                //初始化设备信息
                nRet = InitRemoteLivePlayer2.Remote_Nvd_Init(ref nHandle, ref stDeviceInfo, nProtocol);

                //设置远程抓拍超时时间
                nRet = InitRemoteLivePlayer2.Remote_Snapshot_SetTimeout(nHandle, _RemoteSnapshotTimeout);

                //if (nRet == 0)
                //{
                //    nRet = InitRemoteLivePlayer2.Remote_Snapshot_Open(nHandle);//在抓拍时才打开远程抓拍
                //}
                this._IsReadyForSnapshot = (nRet == 0);
            }
        }
コード例 #2
0
 private void video_Resize(object sender, EventArgs e)
 {
     lock (_StatusLock)
     {
         if (_Status == VideoStatus.Playing)
         {
             InitRemoteLivePlayer2.Remote_LivePlayer2_SetVideoWindow(nHandle, int.Parse(video.Handle.ToString()), 0, 0, video.Width, video.Height);
         }
     }
 }
コード例 #3
0
        /// <summary>
        /// 获取错误信息
        /// </summary>
        /// <param name="nRet"></param>
        /// <returns></returns>
        private string GetErrMessage(int nRet)
        {
            string szErrorInfo = string.Empty;

            byte[] errorby = new byte[512];
            string retStr  = "";

            InitRemoteLivePlayer2.Remote_Nvd_formatMessage(nRet, errorby, 512);
            retStr = Encoding.ASCII.GetString(errorby);

            return(retStr);
        }
コード例 #4
0
 public override void Pause()
 {
     lock (_StatusLock)
     {
         if (VideoSource == null)
         {
             return;
         }
         int nRet = InitRemoteLivePlayer2.Remote_LivePlayer2_Pause(nHandle);
         this._Status             = VideoStatus.Paused;
         this._IsReadyForSnapshot = false;
     }
 }
コード例 #5
0
        private void SetVideoWindow()
        {
            Action action = delegate()
            {
                InitRemoteLivePlayer2.Remote_LivePlayer2_SetVideoWindow(nHandle, int.Parse(video.Handle.ToString()), 0, 0, video.Width, video.Height);
            };

            if (this.video.InvokeRequired)
            {
                this.video.Invoke(action);
            }
            else
            {
                action();
            }
        }
コード例 #6
0
 public override void Close()
 {
     lock (_StatusLock)
     {
         if (VideoSource != null)
         {
             InitRemoteLivePlayer2.Remote_Snapshot_Close(nHandle);
             InitRemoteLivePlayer2.Remote_Nvd_UnInit(nHandle);
             InitRemoteLivePlayer2.Remote_LivePlayer2_Close(nHandle);
         }
         this._Status             = VideoStatus.Disconnected;
         this._IsReadyForSnapshot = false;
     }
     if (!this.TitlePanel.InvokeRequired)
     {
         this.TitlePanel.Visible = false;
         this.video.BackColor    = Color.Navy;
     }
 }
コード例 #7
0
        public override void Play(bool isAsync)
        {
            lock (_StatusLock)
            {
                if (this._Status != VideoStatus.Playing)
                {
                    if (VideoSource == null)
                    {
                        return;
                    }
                    if (!this.TitlePanel.InvokeRequired) //显示视频头
                    {
                        this.Caption            = VideoSource.VideoName;
                        this.TitlePanel.Visible = ShowTitle;
                    }

                    ST_DeviceInfo stDeviceInfo = new ST_DeviceInfo();
                    stDeviceInfo.st_InetAddr.szHostIP    = VideoSource.MediaSource;
                    stDeviceInfo.st_InetAddr.nPORT       = (ushort)VideoSource.StreamPort;
                    stDeviceInfo.st_InetAddr.nIPProtoVer = 1;
                    stDeviceInfo.szUserID    = VideoSource.UserName;
                    stDeviceInfo.szPassword  = VideoSource.Password;
                    stDeviceInfo.nDeviceType = 1;  //

                    int nRet      = 0;
                    int nProtocol = 1;  //1表示udp协议,2表示tcp协议 4表示rtp协议
                    //初始化设备信息
                    nRet = InitRemoteLivePlayer2.Remote_Nvd_Init(ref nHandle, ref stDeviceInfo, nProtocol);
                    if (nRet != 0)
                    {
                        return;
                    }

                    //设置是否拉伸模式
                    nRet = InitRemoteLivePlayer2.Remote_LivePlayer2_SetStretchMode(nHandle, StretchToFit);
                    nRet = InitRemoteLivePlayer2.Remote_LivePlayer2_SetAutoResizeFlag(nHandle, StretchToFit);
                    if (nRet != 0)
                    {
                        return;
                    }

                    //设置默认流ID,需根据网络摄像机的流设置来设置ID,不同码流会有不同的分辨率
                    nRet = InitRemoteLivePlayer2.Remote_LivePlayer2_SetDefaultStreamId(nHandle, VideoSource.Channel);
                    if (nRet != 0)
                    {
                        return;
                    }

                    nRet = InitRemoteLivePlayer2.Remote_LivePlayer2_SetAutoConnectFlag(nHandle, VideoSource.AutoReconnect);
                    if (nRet != 0)
                    {
                        return;
                    }

                    //打开摄像机
                    nRet = InitRemoteLivePlayer2.Remote_LivePlayer2_Open(nHandle, 1);
                    if (nRet != 0)
                    {
                        return;
                    }

                    //播放视频
                    nRet = InitRemoteLivePlayer2.Remote_LivePlayer2_Play(nHandle);
                    if (nRet != 0)
                    {
                        return;
                    }

                    nRet = InitRemoteLivePlayer2.Remote_LivePlayer2_SetVideoWindow(nHandle, int.Parse(video.Handle.ToString()), 0, 0, video.Width, video.Height);
                    if (nRet != 0)
                    {
                        return;
                    }

                    //设置远程抓拍超时时间
                    nRet = InitRemoteLivePlayer2.Remote_Snapshot_SetTimeout(nHandle, _RemoteSnapshotTimeout);

                    ////打开远程抓拍,不调用这个方法,打开视频时不能抓拍图片
                    //nRet = InitRemoteLivePlayer2.Remote_Snapshot_Open(nHandle);//在抓拍时才打开

                    if (nRet != 0)
                    {
                        return;
                    }
                    this._Status             = VideoStatus.Playing;
                    this._IsReadyForSnapshot = true;
                }
            }
        }
コード例 #8
0
        /// <summary>
        /// 抓拍图片
        /// </summary>
        /// <param name="path"></param>
        /// <param name="timeout">超时时间(ms)</param>
        /// <returns></returns>
        public override bool SnapShotTo(ref string path, int timeout, bool force)
        {
            bool           success       = false;
            ST_AVFrameData stAVFrameData = new ST_AVFrameData();

            try
            {
                lock (_StatusLock)
                {
                    //在初始化时设置超时时间了,这里就不再设置超时时间了
                    //int nRet = InitRemoteLivePlayer2.Remote_Snapshot_SetTimeout(nHandle, timeout);

                    //在这里打开远程抓拍,是因为当打开远程抓拍后,如果一段时间内不进行抓拍动作,再进行抓拍时会报错
                    //所以在这里打开远程抓拍,并且抓拍完成后,需关闭远程抓拍
                    int nRet = InitRemoteLivePlayer2.Remote_Snapshot_Open(nHandle);
                    if (nRet == 0)
                    {
                        ST_RemoteSnapshotParam stRemoteSnapshotParam = new ST_RemoteSnapshotParam();
                        //stRemoteSnapshotParam.nCameraID = this.VideoSource.Channel;
                        //这里设置nCameraID为1,是因为IP Camera设备只有一个Camera,所以固定设为1
                        stRemoteSnapshotParam.nCameraID    = 1;
                        stRemoteSnapshotParam.nQuality     = 5;
                        stRemoteSnapshotParam.nPhotoFormat = 1;// PHOTOFORMAT_JPEG

                        nRet = InitRemoteLivePlayer2.Remote_Snapshot_GetSnapshotPicture(nHandle, ref stRemoteSnapshotParam, ref stAVFrameData);
                        if (nRet != 0)
                        {
                            if (Ralid.Park.BusinessModel.Configuration.AppSettings.CurrentSetting.Debug)
                            {
                                string logmsg = string.Format("【{0}】远程抓拍失败  ", this.VideoSource.VideoName);
                                logmsg += " 错误代码:" + nRet;
                                logmsg += " 错误信息:" + GetErrMessage(nRet);

                                Ralid.GeneralLibrary.LOG.FileLog.Log("FrmSnapShoter", logmsg);
                            }
                        }
                    }
                    else
                    {
                        if (Ralid.Park.BusinessModel.Configuration.AppSettings.CurrentSetting.Debug)
                        {
                            string logmsg = string.Format("【{0}】打开远程抓拍失败  ", this.VideoSource.VideoName);
                            logmsg += " 错误代码:" + nRet;
                            logmsg += " 错误信息:" + GetErrMessage(nRet);
                            Ralid.GeneralLibrary.LOG.FileLog.Log("FrmSnapShoter", logmsg);
                        }
                    }
                    if (nRet == 0)
                    {
                        byte[] data = new byte[stAVFrameData.nDataLength];
                        System.Runtime.InteropServices.Marshal.Copy(stAVFrameData.pszData, data, 0, stAVFrameData.nDataLength);
                        File.WriteAllBytes(path, data);
                    }

                    //关闭远程抓拍
                    nRet = InitRemoteLivePlayer2.Remote_Snapshot_Close(nHandle);
                    if (nRet != 0)
                    {
                        if (Ralid.Park.BusinessModel.Configuration.AppSettings.CurrentSetting.Debug)
                        {
                            string logmsg = string.Format("【{0}】关闭远程抓拍失败  ", this.VideoSource.VideoName);
                            logmsg += " 错误代码:" + nRet;
                            logmsg += " 错误信息:" + GetErrMessage(nRet);
                            Ralid.GeneralLibrary.LOG.FileLog.Log("FrmSnapShoter", logmsg);
                        }
                    }

                    return(File.Exists(path));
                }
            }
            catch (Exception ex)
            {
                Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex);
            }
            return(success);
        }