Exemple #1
0
        /// <summary>
        /// 启动摄像头预览
        /// </summary>
        /// <param name="cameraNo">摄像头编号</param>
        /// <returns></returns>
        public SmcErr StartReceiveVideo(string cameraNo)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: TiandyVideoMonitor.StartReceiveVideo({0}).", cameraNo);
            SmcErr err = new CgwError();

            TiandyCamera camera = null;
            Host host = null;

            //摄像头所连接的流媒体服务器
            MediaServer cameraMediaServer = null;
            if (this.cameraOperateLock.TryEnterReadLock(CgwConst.ENTER_LOCK_WAIT_TIME))
            {
                try
                {
                    if (!this.tiandyCameraDictionary.ContainsKey(cameraNo))
                    {
                        err.SetErrorNo(CgwError.CAMERA_NOT_FOUND);
                        logEx.Error("Start Receive camera video data failed.Camera No is not found.Camera No:{0}", cameraNo);
                        return err;
                    }
                    camera = this.tiandyCameraDictionary[cameraNo];
                    host = this.hostDictionary[camera.HostNo];
                    cameraMediaServer = this.mediaServerDictionary[host.MediaServerNo];
                }
                catch (Exception e)
                {
                    err.SetErrorNo(CgwError.START_RECEIVE_VIDEO_FAILED);
                    logEx.Error("Start Receive camera video data failed.Camera No:{0},Execption message:{1}", cameraNo, e.Message);
                    return err;
                }
                finally
                {
                    this.cameraOperateLock.ExitReadLock();
                }
            }

            if (camera == null)
            {
                err.SetErrorNo(CgwError.START_RECEIVE_VIDEO_FAILED);
                logEx.Error("Start Receive camera video data failed.Camera No is not found.Camera No:{0}", cameraNo);
                return err;
            }

            RealPlayInfo real = new RealPlayInfo();
            real.ch = camera.Channel;
            real.data_type = (int)TiandyDateType.PRIMARY;
            real.hPlayWnd = null;

            int result = this.sdkClient.StartReceiveVideo(host.No, cameraMediaServer, ref real);

            //如果为负数,表示预览失败
            if (result < 0)
            {
                err.SetErrorNo(CgwError.START_RECEIVE_VIDEO_FAILED);
                logEx.Error("Start Receive camera video data failed.Camera No:{0}.", cameraNo);
                return err;
            }
            else
            {
                //需要停止的预览句柄
                int needToStopHandel = CgwConst.START_RECEIVE_VIDEO_DATA_FAILED;
                if (this.handelOperateLock.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME))
                {
                    try
                    {
                        //如果预览句柄已经存在,删除掉原来的句柄,用新的句柄替换
                        if (this.cameraVideoHandeDic.ContainsKey(cameraNo))
                        {
                            needToStopHandel = this.cameraVideoHandeDic[cameraNo];
                            this.videoHandleCameraDic.Remove(needToStopHandel);
                            this.cameraVideoHandeDic.Remove(cameraNo);
                        }
                        this.cameraVideoHandeDic.Add(cameraNo, result);
                        this.videoHandleCameraDic.Add(result, cameraNo);
                    }
                    finally
                    {
                        this.handelOperateLock.ExitWriteLock();
                    }
                }
                logEx.Info("Start Receive camera video data success.Camera No:{0},Handle:{1}.", cameraNo, result);
                //重新预览后,更新了预览句柄,需要将原来的预览停止,放在handelOperateLock外面,防止长时间占用锁
                if (needToStopHandel != CgwConst.START_RECEIVE_VIDEO_DATA_FAILED)
                {
                    this.sdkClient.StopReceiveVideo(needToStopHandel);
                }
            }

            return err;
        }
Exemple #2
0
        /// <summary>
        /// 启动摄像头预览
        /// </summary>
        /// <param name="cameraNo">摄像头编号</param>
        /// <returns></returns>
        public SmcErr StartReceiveVideo(string cameraNo)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: TiandyVideoMonitor.StartReceiveVideo({0}).", cameraNo);
            SmcErr err = new CgwError();

            TiandyCamera camera = null;
            Host         host   = null;

            //摄像头所连接的流媒体服务器
            MediaServer cameraMediaServer = null;

            if (this.cameraOperateLock.TryEnterReadLock(CgwConst.ENTER_LOCK_WAIT_TIME))
            {
                try
                {
                    if (!this.tiandyCameraDictionary.ContainsKey(cameraNo))
                    {
                        err.SetErrorNo(CgwError.CAMERA_NOT_FOUND);
                        logEx.Error("Start Receive camera video data failed.Camera No is not found.Camera No:{0}", cameraNo);
                        return(err);
                    }
                    camera            = this.tiandyCameraDictionary[cameraNo];
                    host              = this.hostDictionary[camera.HostNo];
                    cameraMediaServer = this.mediaServerDictionary[host.MediaServerNo];
                }
                catch (Exception e)
                {
                    err.SetErrorNo(CgwError.START_RECEIVE_VIDEO_FAILED);
                    logEx.Error("Start Receive camera video data failed.Camera No:{0},Execption message:{1}", cameraNo, e.Message);
                    return(err);
                }
                finally
                {
                    this.cameraOperateLock.ExitReadLock();
                }
            }

            if (camera == null)
            {
                err.SetErrorNo(CgwError.START_RECEIVE_VIDEO_FAILED);
                logEx.Error("Start Receive camera video data failed.Camera No is not found.Camera No:{0}", cameraNo);
                return(err);
            }

            RealPlayInfo real = new RealPlayInfo();

            real.ch        = camera.Channel;
            real.data_type = (int)TiandyDateType.PRIMARY;
            real.hPlayWnd  = null;

            int result = this.sdkClient.StartReceiveVideo(host.No, cameraMediaServer, ref real);

            //如果为负数,表示预览失败
            if (result < 0)
            {
                err.SetErrorNo(CgwError.START_RECEIVE_VIDEO_FAILED);
                logEx.Error("Start Receive camera video data failed.Camera No:{0}.", cameraNo);
                return(err);
            }
            else
            {
                //需要停止的预览句柄
                int needToStopHandel = CgwConst.START_RECEIVE_VIDEO_DATA_FAILED;
                if (this.handelOperateLock.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME))
                {
                    try
                    {
                        //如果预览句柄已经存在,删除掉原来的句柄,用新的句柄替换
                        if (this.cameraVideoHandeDic.ContainsKey(cameraNo))
                        {
                            needToStopHandel = this.cameraVideoHandeDic[cameraNo];
                            this.videoHandleCameraDic.Remove(needToStopHandel);
                            this.cameraVideoHandeDic.Remove(cameraNo);
                        }
                        this.cameraVideoHandeDic.Add(cameraNo, result);
                        this.videoHandleCameraDic.Add(result, cameraNo);
                    }
                    finally
                    {
                        this.handelOperateLock.ExitWriteLock();
                    }
                }
                logEx.Info("Start Receive camera video data success.Camera No:{0},Handle:{1}.", cameraNo, result);
                //重新预览后,更新了预览句柄,需要将原来的预览停止,放在handelOperateLock外面,防止长时间占用锁
                if (needToStopHandel != CgwConst.START_RECEIVE_VIDEO_DATA_FAILED)
                {
                    this.sdkClient.StopReceiveVideo(needToStopHandel);
                }
            }

            return(err);
        }
Exemple #3
0
        /// <summary>
        /// 启动实时预览
        /// </summary>
        /// <param name="dev_id">主机ID </param>
        /// <param name="cameraMediaServer">设备端接入的流媒体服务器信息 </param>
        /// <param name="info">实时播放信息</param>
        /// <returns>-1 失败,其他则是返回预览句柄</returns>
        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);
        }
Exemple #4
0
 private static extern int client_sdk_realplay2_ex(string dev_id, string username, string password, string client_sup_id, string dev_sup_id, string client_sup_ip, int client_sup_port, ref RealPlayInfo info, RealDataCallBackFunc func, int usr);
Exemple #5
0
 private static extern int client_sdk_realplay2_ex(string dev_id, string username, string password, string client_sup_id, string dev_sup_id, string client_sup_ip, int client_sup_port, ref RealPlayInfo info, RealDataCallBackFunc func, int usr);
Exemple #6
0
        /// <summary>
        /// 启动实时预览
        /// </summary>
        /// <param name="dev_id">主机ID </param>
        /// <param name="cameraMediaServer">设备端接入的流媒体服务器信息 </param>
        /// <param name="info">实时播放信息</param>
        /// <returns>-1 失败,其他则是返回预览句柄</returns>
        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;
        }