CgwMonitorManage.Tiandy.TiandySdkClient.StartReceiveVideo C# (CSharp) Method

StartReceiveVideo() public method

启动实时预览
public StartReceiveVideo ( string dev_id, MediaServer cameraMediaServer, RealPlayInfo &info ) : int
dev_id string 主机ID
cameraMediaServer MediaServer 设备端接入的流媒体服务器信息
info RealPlayInfo 实时播放信息
return int
        public int StartReceiveVideo(string dev_id, MediaServer cameraMediaServer, ref RealPlayInfo info)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: TiandySdkClient.StartReceiveVideo({0},{1},{2}).", dev_id, cameraMediaServer.No, info);

            int iPlayFd = CgwConst.START_RECEIVE_VIDEO_DATA_FAILED;

            //如果摄像机的流媒体服务器为空,那么启动码流失败
            if (cameraMediaServer == null)
            {
                logEx.Error("cameraMediaServer can't be null");
                return CgwConst.START_RECEIVE_VIDEO_DATA_FAILED;

            }

            MediaServer clientMediaServer = this.sdkMediaServer;
            if (clientMediaServer == null)
            {
                clientMediaServer = cameraMediaServer;
            }

            try
            {

                iPlayFd = client_sdk_realplay2_ex(
                                    dev_id,
                                    clientMediaServer.User,
                                    clientMediaServer.Pwd,
                                    clientMediaServer.No,
                                    cameraMediaServer.No,
                                    clientMediaServer.Ip,
                                    clientMediaServer.Port,
                                    ref info,
                                    null,
                                    0);

                if (iPlayFd == CgwConst.START_RECEIVE_VIDEO_DATA_FAILED)
                {
                    logEx.Error("Call Tiandy sdk function client_sdk_realplay2_ex failed.");
                    return iPlayFd;
                }
                else
                {
                    logEx.Info("Call Tiandy sdk function client_sdk_realplay2_ex success.dev_id:{0},username:{1},client_sup_id:{2},dev_sup_id{3},client_sup_ip:{4},client_sup_port:{5}.",
                                    dev_id,
                                    clientMediaServer.User,
                                    clientMediaServer.No,
                                    cameraMediaServer.No,
                                    clientMediaServer.Ip,
                                    clientMediaServer.Port);
                }

                //预览成功设置码流回调
                //if (!client_sdk_set_realdata_callback(iPlayFd, func, 0))
                if (!client_sdk_set_h264_callback(iPlayFd, this.sdkRealDataCallBackFunc, 0))
                {
                    logEx.Error("Start Receive camera video data failed.Call Tiandy sdk function client_sdk_set_h264_callback failed.playfd:{0}", iPlayFd);
                    return CgwConst.START_RECEIVE_VIDEO_DATA_FAILED;
                }
                else
                {
                    logEx.Info("Call Tiandy sdk function client_sdk_set_h264_callback success.playfd:{0}", iPlayFd);
                }
                //因天地伟业的预览接口是异步的,还需要通过消息回调判断是否成功
                int count = 0;
                bool isSuccess = false;
                //循环5次
                while (count < 5)
                {
                    //等待500ms
                    Thread.Sleep(CgwConst.CHECK_RECEIVE_STATUS_WAIT_TIME);
                    if (this.handelOperateLock.TryEnterReadLock(CgwConst.ENTER_LOCK_WAIT_TIME))
                    {
                        try
                        {
                            if (this.receiveSuccHandle.Contains(iPlayFd))
                            {
                                logEx.Info("Start Receive camera video data success.");
                                isSuccess = true;
                                break;
                            }
                        }
                        finally
                        {
                            this.handelOperateLock.ExitReadLock();
                        }
                    }
                    //等待500ms
                    Thread.Sleep(CgwConst.CHECK_RECEIVE_STATUS_WAIT_TIME);
                    count++;
                }

                if (!isSuccess)
                {
                    logEx.Error("Set callback function success. But not receive any video data.Try to stop receive.");

                    client_sdk_set_h264_callback(iPlayFd, null, 0);
                    client_sdk_stop_realplay(iPlayFd);
                    iPlayFd = CgwConst.START_RECEIVE_VIDEO_DATA_FAILED;
                }

            }
            catch (Exception e)
            {

                iPlayFd = CgwConst.START_RECEIVE_VIDEO_DATA_FAILED;
                logEx.Error("Start Receive camera video data failed.Exception message:{0}.", e.Message);
            }

            return iPlayFd;
        }