Exemple #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            //1、登录
            SDK_TDWYSDK.LogonPara tInfo = new SDK_TDWYSDK.LogonPara();
            tInfo.iSize    = Marshal.SizeOf(tInfo);
            tInfo.iNvsPort = CurrentVideoInfo.DVSConnectPort;
            tInfo.cNvsIP   = new char[32];
            Array.Copy(CurrentVideoInfo.DVSAddress.ToArray(), tInfo.cNvsIP, CurrentVideoInfo.DVSAddress.Length);
            tInfo.cUserName = new char[16];
            Array.Copy(CurrentVideoInfo.UserName.ToArray(), tInfo.cUserName, CurrentVideoInfo.UserName.Length);
            tInfo.cUserPwd = new char[16];
            Array.Copy(CurrentVideoInfo.Password.ToArray(), tInfo.cUserPwd, CurrentVideoInfo.Password.Length);
            IntPtr intptr = Marshal.AllocCoTaskMem(tInfo.iSize);

            Marshal.StructureToPtr(tInfo, intptr, true);//false容易造成内存泄漏
            int iRet = SDK_TDWYSDK.NetClient_Logon_V4(0, intptr, tInfo.iSize);

            Marshal.FreeHGlobal(intptr);//释放分配的非托管内存。
            m_iLogonId = iRet;
            if (m_iLogonId < 0)
            {
                //登录失败
                iRet = SDK_TDWYSDK.NetClient_Logoff(m_iLogonId);
            }
        }
        public override bool VideoClose()
        {
            VideoEnvironment.VideoEnvironment_TDWY.MAIN_NOTIFYEvent -= VideoEnvironment_TDWY_MAIN_NOTIFYEvent;
            int iRet = SDK_TDWYSDK.NetClient_StopPlay(m_iConnectId);

            iRet = SDK_TDWYSDK.NetClient_StopRecv(m_iConnectId);
            iRet = SDK_TDWYSDK.NetClient_Logoff(_iLogonID);
            VideoPlayCallback(new VideoPlayCallbackValue {
                evType = Enum_VideoPlayEventType.VideoClose
            });
            return(true);
        }
        /// <summary>
        /// 视频播放
        /// </summary>
        /// <returns></returns>
        public override bool VideoPlay()
        {
            VideoEnvironment.VideoEnvironment_TDWY.MAIN_NOTIFYEvent -= VideoEnvironment_TDWY_MAIN_NOTIFYEvent;
            VideoEnvironment.VideoEnvironment_TDWY.MAIN_NOTIFYEvent += VideoEnvironment_TDWY_MAIN_NOTIFYEvent;
            //1、登录
            SDK_TDWYSDK.LogonPara tInfo = new SDK_TDWYSDK.LogonPara();
            tInfo.iSize    = Marshal.SizeOf(tInfo);
            tInfo.iNvsPort = CurrentVideoInfo.DVSConnectPort;
            tInfo.cNvsIP   = new char[32];
            Array.Copy(CurrentVideoInfo.DVSAddress.ToArray(), tInfo.cNvsIP, CurrentVideoInfo.DVSAddress.Length);
            tInfo.cUserName = new char[16];
            Array.Copy(CurrentVideoInfo.UserName.ToArray(), tInfo.cUserName, CurrentVideoInfo.UserName.Length);
            tInfo.cUserPwd = new char[16];
            Array.Copy(CurrentVideoInfo.Password.ToArray(), tInfo.cUserPwd, CurrentVideoInfo.Password.Length);
            IntPtr intptr = Marshal.AllocCoTaskMem(tInfo.iSize);

            Marshal.StructureToPtr(tInfo, intptr, true);//false容易造成内存泄漏
            VideoPlayCallback(new VideoPlayCallbackValue {
                evType = Enum_VideoPlayEventType.LoginStart
            });
            int iRet = SDK_TDWYSDK.NetClient_Logon_V4(0, intptr, tInfo.iSize);

            Marshal.FreeHGlobal(intptr);//释放分配的非托管内存。
            _iLogonID = iRet;
            if (_iLogonID < 0)
            {
                //登录失败
                iRet = SDK_TDWYSDK.NetClient_Logoff(_iLogonID);
                VideoPlayCallback(new VideoPlayCallbackValue {
                    evType = Enum_VideoPlayEventType.DevLoginException
                });
                return(false);
            }
            //通过回调进行后续操作
            return(true);
        }