/*===========================================================
        *  视频点播相关接口
        *  ===========================================================*/
        /*===========================================================
        *  功  能:点播视频
        *  参  数:ptVodInfo - 点播信息
        *       pfuncPlayPos - 进度回调函数,传Null标示不需要回调进度
        *       dwUserData - 用户数据
        *  返回值:-1表示失败,其他值表示返回的点播标示值。
        *  ===========================================================*/
        public UInt32 RvodSdk_PlayBackVideo(IntPtr hWnd, RVODFileInfo info)
        {
            TRVODSDK_PLAYBACK_VOD_INFO ptVodInfo = new TRVODSDK_PLAYBACK_VOD_INFO()
            {
                hPlayWnd    = (uint)hWnd.ToInt32(),
                szVideoPath = info.VodFileName,
                tServerInfo = new TRVODSDK_SERVER_INFO()
                {
                    szDevIp = info.ServerIP, wDevPort = (ushort)info.ServerPort,
                },
            };

            pfuncPlayPos = OnTfuncPlayPosCB;
            UInt32 dwUserData = 0;

            MyLog4Net.ILogExtension.DebugWithDebugView(MyLog4Net.Container.Instance.Log, "IVXRVODSDKProtocol RvodSdk_PlayBackVideo hWnd:" + hWnd.ToInt32() + ",VodFileName:" + info.VodFileName + ",VodFileSize:" + info.VodFileSize + ",ServerIP:" + info.ServerIP + ",ServerPort:" + info.ServerPort);
            uint retVal = IVXRVODSDKProtocol.RvodSdk_PlayBackVideo(ref ptVodInfo, pfuncPlayPos, dwUserData);

            if (retVal <= 0 || retVal == 0xffffffff)
            {
                RVOD_GetError();
            }

            MyLog4Net.ILogExtension.DebugWithDebugView(MyLog4Net.Container.Instance.Log, "IVXRVODSDKProtocol RvodSdk_PlayBackVideo ret :" + retVal);
            return(retVal);
        }
        /*===========================================================
        *  功  能:查询下一个视频资源信息(遍历接口)
        *  参  数:lQueryHandle - 查询标示值
        *       ptVideoInfo - 视频文件信息
        *  返回值:成功返回TRUE,失败返回FALSE。
        *  ===========================================================*/

        public RVODFileInfo RvodSdk_QueryNextVideoResource(UInt32 lQueryHandle)
        {
            TRVODSDK_VIDEO_INFO ptVideoInfo = new TRVODSDK_VIDEO_INFO()
            {
                dwVideoSize = 0, szVideoPath = "",
            };

            MyLog4Net.ILogExtension.DebugWithDebugView(MyLog4Net.Container.Instance.Log, "IVXRVODSDKProtocol RvodSdk_QueryNextVideoResource lQueryHandle:" + lQueryHandle);
            bool retVal = IVXRVODSDKProtocol.RvodSdk_QueryNextVideoResource(lQueryHandle, out ptVideoInfo);

            if (string.IsNullOrEmpty(ptVideoInfo.szVideoPath))
            {
                return(null);
            }
            //if (retVal < 0)
            //{
            //    RVOD_GetError();
            //}

            string       path = ptVideoInfo.szVideoPath.Replace('\\', '/');
            RVODFileInfo info = new RVODFileInfo()
            {
                VodFileName = path,
                VodFileSize = ptVideoInfo.dwVideoSize,
            };

            MyLog4Net.ILogExtension.DebugWithDebugView(MyLog4Net.Container.Instance.Log, "IVXRVODSDKProtocol RvodSdk_QueryNextVideoResource ret:" + retVal + ",szVideoPath:" + ptVideoInfo.szVideoPath + ",dwVideoSize:" + ptVideoInfo.dwVideoSize);
            return(info);
        }
        public string RvodSdk_GetErrorMsg(UInt32 dwErrCode)
        {
            MyLog4Net.ILogExtension.DebugWithDebugView(MyLog4Net.Container.Instance.Log, "IVXRVODSDKProtocol RvodSdk_GetErrorMsg dwErrCode:" + dwErrCode);
            string retVal = IVXRVODSDKProtocol.RvodSdk_GetErrorMsg(dwErrCode);

            MyLog4Net.ILogExtension.DebugWithDebugView(MyLog4Net.Container.Instance.Log, "IVXRVODSDKProtocol RvodSdk_GetErrorMsg ret:" + retVal);
            return(retVal);
        }
        //获取错误码
        public UInt32 RvodSdk_GetLastError()
        {
            MyLog4Net.ILogExtension.DebugWithDebugView(MyLog4Net.Container.Instance.Log, "IVXRVODSDKProtocol RvodSdk_GetRvodtError ");
            UInt32 retVal = IVXRVODSDKProtocol.RvodSdk_GetLastError();

            MyLog4Net.ILogExtension.DebugWithDebugView(MyLog4Net.Container.Instance.Log, "IVXRVODSDKProtocol RvodSdk_GetRvodtError ret:" + retVal);
            return(retVal);
        }
        //获取SDK的版本信息
        public string RvodSdk_GetSdkVersion()
        {
            MyLog4Net.ILogExtension.DebugWithDebugView(MyLog4Net.Container.Instance.Log, "IVXRVODSDKProtocol RvodSdk_Init ");
            string retVal = IVXRVODSDKProtocol.RvodSdk_GetSdkVersion();

            MyLog4Net.ILogExtension.DebugWithDebugView(MyLog4Net.Container.Instance.Log, "IVXRVODSDKProtocol RvodSdk_Init ret:" + retVal);
            return(retVal);
        }
        //停止播放
        public bool RvodSdk_StopPlayBack(UInt32 lVodHandle)
        {
            MyLog4Net.ILogExtension.DebugWithDebugView(MyLog4Net.Container.Instance.Log, "IVXRVODSDKProtocol RvodSdk_StopPlayBack lVodHandle:" + lVodHandle);
            bool retVal = IVXRVODSDKProtocol.RvodSdk_StopPlayBack(lVodHandle);

            if (!retVal)
            {
                RVOD_GetError();
            }

            MyLog4Net.ILogExtension.DebugWithDebugView(MyLog4Net.Container.Instance.Log, "IVXRVODSDKProtocol RvodSdk_StopPlayBack ret :" + retVal);
            return(retVal);
        }
        /*===========================================================
        *  功  能:播放控制
        *  参  数:lVodHandle - 点播标示句柄
        *       dwControlCode - 播放控制类型,见E_VDA_PLAYCTRL_TYPE定义
        *       dwInValue - 播放控制输入参数
        *       pdwOutValue - 播放控制输出参数,如获取的进度等
        *  返回值:成功返回TRUE,失败返回FALSE
        *  ===========================================================*/
        public bool RvodSdk_PlayBackControl(UInt32 lVodHandle, UInt32 dwControlCode, UInt32 dwInValue, out UInt32 pdwOutValue)
        {
            MyLog4Net.ILogExtension.DebugWithDebugView(MyLog4Net.Container.Instance.Log, "IVXRVODSDKProtocol RvodSdk_PlayBackControl lVodHandle:" + lVodHandle + ",dwControlCode:" + dwControlCode + ",dwInValue:" + dwInValue);
            bool retVal = IVXRVODSDKProtocol.RvodSdk_PlayBackControl(lVodHandle, dwControlCode, dwInValue, out pdwOutValue);

            if (!retVal)
            {
                RVOD_GetError();
            }

            MyLog4Net.ILogExtension.DebugWithDebugView(MyLog4Net.Container.Instance.Log, "IVXRVODSDKProtocol RvodSdk_PlayBackControl ret :" + retVal + ",pdwOutValue:" + pdwOutValue);
            return(retVal);
        }
        /*===========================================================
        *  功  能:关闭视频资源查询查询
        *  参  数:lQueryHandle 查询标示值
        *  返回值:成功返回TRUE,失败返回FALSE。
        *  ===========================================================*/
        public bool RvodSdk_CloseVideoResourceQuery(UInt32 lQueryHandle)
        {
            MyLog4Net.ILogExtension.DebugWithDebugView(MyLog4Net.Container.Instance.Log, "IVXRVODSDKProtocol RvodSdk_CloseVideoResourceQuery lQueryHandle:" + lQueryHandle);
            bool retVal = IVXRVODSDKProtocol.RvodSdk_CloseVideoResourceQuery(lQueryHandle);;

            if (!retVal)
            {
                RVOD_GetError();
            }

            MyLog4Net.ILogExtension.DebugWithDebugView(MyLog4Net.Container.Instance.Log, "IVXRVODSDKProtocol RvodSdk_CloseVideoResourceQuery ret :" + retVal);
            return(retVal);
        }
        //退出
        public bool RvodSdk_UnInit()
        {
            MyLog4Net.ILogExtension.DebugWithDebugView(MyLog4Net.Container.Instance.Log, "IVXRVODSDKProtocol RvodSdk_UnInit ");
            bool retVal = IVXRVODSDKProtocol.RvodSdk_UnInit();

            if (!retVal)
            {
                RVOD_GetError();
            }

            MyLog4Net.ILogExtension.DebugWithDebugView(MyLog4Net.Container.Instance.Log, "IVXRVODSDKProtocol RvodSdk_UnInit ret:" + retVal);
            return(retVal);
        }
        /*===========================================================
        *  获取服务器视频列表相关接口
        *  ===========================================================*/
        /*===========================================================
        *  功  能:获取指定盘符下视频文件个数
        *  参  数:	ptSearch - 视频查询条件
        *       pdwQueryHandle - 检索句柄
        *  返回值:成功返回文件个数,失败返回-1
        *  ===========================================================*/
        public UInt32 RvodSdk_GetVideoResourceTotalNum(string ip, uint port, out UInt32 pdwQueryHandle)
        {
            TRVODSDK_SERVER_INFO ptServer = new TRVODSDK_SERVER_INFO()
            {
                szDevIp  = ip,
                wDevPort = (ushort)port,
            };

            MyLog4Net.ILogExtension.DebugWithDebugView(MyLog4Net.Container.Instance.Log, "IVXRVODSDKProtocol RvodSdk_GetVideoResourceTotalNum ip:" + ip + ",port:" + port);
            UInt32 retVal = IVXRVODSDKProtocol.RvodSdk_GetVideoResourceTotalNum(ref ptServer, out pdwQueryHandle);;

            if (pdwQueryHandle <= 0 || pdwQueryHandle == 0xffffffff)
            {
                RVOD_GetError();
            }

            MyLog4Net.ILogExtension.DebugWithDebugView(MyLog4Net.Container.Instance.Log, "IVXRVODSDKProtocol RvodSdk_GetVideoResourceTotalNum ret count:" + retVal + ",handel:" + pdwQueryHandle);
            return(retVal);
        }
        /*===========================================================
        *  功  能:抓图并获取数据
        *  参  数:lVodHandle - 点播标示句柄
        *       dwPicType - 抓取图片的类型,见E_VDA_GRAB_PIC_TYPE
        *       pPicBuf - 图片缓存区(只有在输入缓存区大小足够前提下,才会输出图片数据)
        *       dwBufLen - 输入图片缓存区大小
        *       dwPicDataLen - 实际图片数据大小
        *  返回值:成功返回TRUE,失败返回FALSE
        *  ===========================================================*/
        public System.Drawing.Image RvodSdk_GrabPictureData(UInt32 lVodHandle)
        {
            MyLog4Net.ILogExtension.DebugWithDebugView(MyLog4Net.Container.Instance.Log, "IVXRVODSDKProtocol RvodSdk_GrabPictureData lVodHandle:" + lVodHandle);


            uint   buflen     = DataModel.Common.MAX_PIC_DATA_LEN;
            IntPtr picbuf     = Marshal.AllocHGlobal((int)buflen);
            uint   picdatalen = 0;

            bool retVal = IVXRVODSDKProtocol.RvodSdk_GrabPictureData(lVodHandle, (uint)E_VDA_GRAB_PIC_TYPE.E_GRAB_PIC_BMP, picbuf, buflen, out picdatalen);

            if (!retVal && picdatalen > buflen && picdatalen > 0)
            {
                if (picbuf != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(picbuf);
                }

                buflen     = picdatalen;
                picbuf     = Marshal.AllocHGlobal((int)buflen);
                picdatalen = 0;
                retVal     = IVXRVODSDKProtocol.RvodSdk_GrabPictureData(lVodHandle, (uint)E_VDA_GRAB_PIC_TYPE.E_GRAB_PIC_BMP, picbuf, buflen, out picdatalen);
            }

            if (!retVal)
            {
                RVOD_GetError();
            }
            System.Drawing.Image img = DataModel.Common.GetImage(picbuf, (int)buflen);
            if (picbuf != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(picbuf);
            }

            MyLog4Net.ILogExtension.DebugWithDebugView(MyLog4Net.Container.Instance.Log, "IVXRVODSDKProtocol RvodSdk_GrabPictureData ret:" + retVal);

            return(img);
        }
        public bool GetRVodPlayResolution(UInt32 dwStrmId, out UInt32 pdwWidth, out UInt32 pdwHeight)
        {
            MyLog4Net.ILogExtension.DebugWithDebugView(MyLog4Net.Container.Instance.Log, string.Format("IVXRVODSDKProtocol RvodSdk_GetPlayResolution dwStrmId:{0}"
                                                                                                       , dwStrmId
                                                                                                       ));

            bool retVal = IVXRVODSDKProtocol.RvodSdk_GetPlayResolution(dwStrmId, out pdwWidth, out pdwHeight);

            if (!retVal)
            {
                // 调用失败,抛异常
                RVOD_GetError();
            }


            MyLog4Net.ILogExtension.DebugWithDebugView(MyLog4Net.Container.Instance.Log, string.Format("IVXRVODSDKProtocol RvodSdk_GetPlayResolution ret:{0}"
                                                                                                       + ",pdwWidth:{1}"
                                                                                                       + ",pdwHeight:{2}"
                                                                                                       , retVal
                                                                                                       , pdwWidth
                                                                                                       , pdwHeight
                                                                                                       ));
            return(retVal);
        }