示例#1
0
        /// <summary>
        /// 获取sip设备的历史录制文件列表
        /// </summary>
        /// <param name="deviceId"></param>
        /// <param name="channelId"></param>
        /// <param name="queryRecordFile"></param>
        /// <param name="rs"></param>
        /// <returns></returns>
        public static bool GetHistroyRecordFileList(string deviceId, string channelId,
                                                    SipQueryRecordFile queryRecordFile, out ResponseStruct rs)
        {
            ServerInstance mediaServer;
            VideoChannel   videoChannel;
            SipDevice      sipDevice;
            SipChannel     sipChannel;

            rs = new ResponseStruct()
            {
                Code    = ErrorNumber.None,
                Message = ErrorMessage.ErrorDic ![ErrorNumber.None],
示例#2
0
 /// <summary>
 /// 删除rtc配置
 /// </summary>
 /// <param name="deviceId"></param>
 /// <param name="vhostDomain"></param>
 /// <param name="rs"></param>
 /// <returns></returns>
 public static bool DeleteVhostRtc(string deviceId, string vhostDomain, out ResponseStruct rs)
 {
     rs = new ResponseStruct()
     {
         Code    = ErrorNumber.None,
         Message = ErrorMessage.ErrorDic ![ErrorNumber.None],
 /// <summary>
 /// 只有rtp推流或才rtmp,rtsp推流才会有onpublish事件触发,因此这里忽略ffmpeg推流的方式
 /// </summary>
 /// <param name="req"></param>
 /// <param name="rs"></param>
 /// <returns></returns>
 public static ResToWebHookOnPublish OnPublishNew(ReqForWebHookOnPublish req, out ResponseStruct rs)
 {
     rs = new ResponseStruct()
     {
         Code    = ErrorNumber.None,
         Message = ErrorMessage.ErrorDic ![ErrorNumber.None],
示例#4
0
        private void KeepRecord()
        {
            while (true)
            {
                try
                {
                    ResponseStruct rs               = null;
                    var            recordPlanList   = RecordPlanService.GetRecordPlanList("", out rs);
                    var            videoChannelList = ORMHelper.Db.Select <VideoChannel>().Where(x => x.Enabled.Equals(true))
                                                      .Where(x => !string.IsNullOrEmpty(x.RecordPlanName))
                                                      .Where(x => x.AutoRecord.Equals(true)).ToList();
                    if (rs.Code.Equals(ErrorNumber.None) && recordPlanList != null && recordPlanList.Count > 0)
                    {
                        try
                        {
                            var retlist = GCommon.Ldb.VideoOnlineInfo.FindAll().ToList();
                            foreach (var obj in retlist)
                            {
                                if (obj != null && obj.MediaServerStreamInfo != null)
                                {
                                    var videoChannel = videoChannelList.FindLast(x => x.MainId.Equals(obj.MainId));
                                    if (videoChannel != null)
                                    {
                                        //启用了自动录制
                                        var recordPlan =
                                            recordPlanList.FindLast(x => x.Name.Equals(videoChannel.RecordPlanName));
                                        if (recordPlan != null && recordPlan.Enable == true)
                                        {
                                            //说明绑定了录制模板
                                            var fileSize     = getRecordFileSize(videoChannel.MainId);     //得到文件总长度
                                            var fileDateList = getRecordFileDataList(videoChannel.MainId); //得到记录天数列表
                                            if (fileDateList == null)
                                            {
                                                fileDateList = new List <string>();
                                            }

                                            var  inRange = checkTimeRange(recordPlan);
                                            bool stopIt  = false;
                                            if (!inRange)
                                            {
                                                stopIt = true;
                                            }

                                            if (inRange && recordPlan.LimitDays >= fileDateList.Count &&
                                                recordPlan.LimitSpace >= fileSize)
                                            {
                                                stopIt = false;
                                            }

                                            if (inRange && (recordPlan.LimitDays < fileDateList.Count ||
                                                            recordPlan.LimitSpace < fileSize))
                                            {
                                                stopIt = true;
                                            }


                                            if (stopIt && obj.MediaServerStreamInfo.IsRecorded == true)
                                            {
                                                switch (recordPlan.OverStepPlan)
                                                {
                                                case OverStepPlan.StopDvr:
                                                    string info =
                                                        $"自动停止录制文件条件被触发->{obj.MediaServerId}->{obj.MainId}->{videoChannel.RecordPlanName}";
                                                    info += (recordPlan.LimitDays < fileDateList.Count)
                                                            ? $"限制录制文件天数:{recordPlan.LimitDays}<实际录制文件天数:{fileDateList.Count}"
                                                            : "";
                                                    info +=
                                                        $"->限制录制空间:{recordPlan.LimitSpace}Bytes<实际录制空间:{fileSize}Bytes";
                                                    info += !inRange ? "->超出录制模板规定的时间区间" : "";
                                                    GCommon.Logger.Info(
                                                        $"[{Common.LoggerHead}]->{info}");
                                                    MediaServerService.StopRecord(videoChannel.MediaServerId,
                                                                                  videoChannel.MainId, out rs);
                                                    break;

                                                case OverStepPlan.DeleteFile:
                                                    if (!inRange)
                                                    {
                                                        string info3 = "超出录制模板规定的时间区间";
                                                        GCommon.Logger.Info(
                                                            $"[{Common.LoggerHead}]->自动停止录制文件条件被触发->{info3}->{obj.MediaServerId}->{obj.MainId}->{videoChannel.RecordPlanName}");
                                                        MediaServerService.StopRecord(videoChannel.MediaServerId,
                                                                                      videoChannel.MainId, out rs);
                                                    }
                                                    else
                                                    {
                                                        string info2 =
                                                            $"自动删除录制文件条件被触发->{obj.MediaServerId}->{obj.MainId}->{videoChannel.RecordPlanName}";
                                                        info2 += (recordPlan.LimitDays < fileDateList.Count)
                                                                ? $"限制录制文件天数:{recordPlan.LimitDays}<实际录制文件天数:{fileDateList.Count}"
                                                                : "";
                                                        info2 +=
                                                            $"->限制录制空间:{recordPlan.LimitSpace}Bytes<实际录制空间:{fileSize}Bytes";
                                                        GCommon.Logger.Info(
                                                            $"[{Common.LoggerHead}]->{info2}");
                                                        bool p = false;
                                                        if (recordPlan.LimitDays < fileDateList.Count)     //先一天一天删除
                                                        {
                                                            int?loopCount = fileDateList.Count -
                                                                            recordPlan.LimitDays;

                                                            List <string> willDeleteDays = new List <string>();
                                                            for (int i = 0; i < loopCount; i++)
                                                            {
                                                                willDeleteDays.Add(fileDateList[i] !);
                                                            }

                                                            DeleteFileByDay(willDeleteDays,
                                                                            obj.MediaServerStreamInfo);
                                                            p = true;
                                                        }

                                                        if (p)
                                                        {
                                                            fileSize = getRecordFileSize(videoChannel
                                                                                         .MainId); //删除完一天以后再取一下文件总长度
                                                        }

                                                        if (recordPlan.LimitSpace < fileSize)     //还大,再删除一个文件
                                                        {
                                                            deleteFileOneByOne(fileSize, obj.MediaServerStreamInfo,
                                                                               recordPlan);
                                                        }
                                                    }

                                                    break;
                                                }
                                            }
                                            else
                                            {
                                                if (obj.MediaServerStreamInfo.IsRecorded == false && inRange &&
                                                    stopIt == false)
                                                {
                                                    GCommon.Logger.Info(
                                                        $"[{Common.LoggerHead}]->自动启动录制文件条件被触发->{obj.MediaServerId}->{obj.MainId}->{videoChannel.RecordPlanName}" +
                                                        $"限制录制文件天数:{recordPlan.LimitDays}>实际录制文件天数:{fileDateList.Count}->限制录制空间:{recordPlan.LimitSpace}Bytes>实际录制空间:{fileSize}Bytes" +
                                                        $"录制计划模板中时间区间被击中,开始录制音视频流");

                                                    MediaServerService.StartRecord(videoChannel.MediaServerId,
                                                                                   videoChannel.MainId, out rs);
                                                }
                                                else if (stopIt && obj.MediaServerStreamInfo.IsRecorded == false)
                                                {
                                                    //既没启动录制,又不让启动录制,这时要查一下有没有需要删除的文件
                                                    if (recordPlan.OverStepPlan == OverStepPlan.DeleteFile)
                                                    {
                                                        if (recordPlan.LimitDays < fileDateList.Count)
                                                        {
                                                            string info2 =
                                                                $"自动删除录制文件条件被触发->{obj.MediaServerId}->{obj.MainId}->{videoChannel.RecordPlanName}";
                                                            info2 += (recordPlan.LimitDays < fileDateList.Count)
                                                                ? $"限制录制文件天数:{recordPlan.LimitDays}<实际录制文件天数:{fileDateList.Count}"
                                                                : "";
                                                            info2 +=
                                                                $"->限制录制空间:{recordPlan.LimitSpace}Bytes<实际录制空间:{fileSize}Bytes";
                                                            GCommon.Logger.Info(
                                                                $"[{Common.LoggerHead}]->{info2}");
                                                            bool p = false;
                                                            if (recordPlan.LimitDays < fileDateList.Count) //先一天一天删除
                                                            {
                                                                int?loopCount = fileDateList.Count -
                                                                                recordPlan.LimitDays;

                                                                List <string> willDeleteDays = new List <string>();
                                                                for (int i = 0; i < loopCount; i++)
                                                                {
                                                                    willDeleteDays.Add(fileDateList[i] !);
                                                                }

                                                                DeleteFileByDay(willDeleteDays,
                                                                                obj.MediaServerStreamInfo);
                                                                p = true;
                                                            }

                                                            if (p)
                                                            {
                                                                fileSize = getRecordFileSize(videoChannel
                                                                                             .MainId); //删除完一天以后再取一下文件总长度
                                                            }

                                                            if (recordPlan.LimitSpace < fileSize) //还大,再删除一个文件
                                                            {
                                                                deleteFileOneByOne(fileSize, obj.MediaServerStreamInfo,
                                                                                   recordPlan);
                                                            }
                                                        }
                                                        else if (recordPlan.LimitSpace < fileSize)
                                                        {
                                                            //如果文件天数不足,则删除一个文件
                                                            deleteFileOneByOne(fileSize, obj.MediaServerStreamInfo,
                                                                               recordPlan);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        else if (recordPlan != null && recordPlan.Enable == false)
                                        {
                                            if (obj.MediaServerStreamInfo.IsRecorded == true)
                                            {
                                                GCommon.Logger.Info(
                                                    $"[{Common.LoggerHead}]->自动停止录制条件被触发,结束录制音视频流->{obj.MediaServerId}->{obj.MainId}->{videoChannel.RecordPlanName}-录制计划模板已禁用");

                                                MediaServerService.StopRecord(videoChannel.MediaServerId,
                                                                              videoChannel.MainId, out rs);
                                            }
                                        }
                                        else if (recordPlan == null)
                                        {
                                            if (obj.MediaServerStreamInfo.IsRecorded == true)
                                            {
                                                GCommon.Logger.Info(
                                                    $"[{Common.LoggerHead}]->自动停止录制条件被触发,结束录制音视频流->{obj.MediaServerId}->{obj.MainId}->未绑定录制计划模板");

                                                MediaServerService.StopRecord(videoChannel.MediaServerId,
                                                                              videoChannel.MainId, out rs);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        catch
                        {
                            //
                        }
                    }
                }
                catch
                {
                    //
                }


                Thread.Sleep(10000);
            }
        }
示例#5
0
 /// <summary>
 /// 添加一个裁剪合并任务
 /// </summary>
 /// <param name="mediaServerId"></param>
 /// <param name="reqKeeper"></param>
 /// <param name="rs"></param>
 /// <returns></returns>
 public static ResKeeperCutMergeTaskResponse AddCutOrMergeTask(string mediaServerId,
                                                               ReqKeeperCutMergeTask reqKeeper, out ResponseStruct rs)
 {
     rs = new ResponseStruct()
     {
         Code    = ErrorNumber.None,
         Message = ErrorMessage.ErrorDic ![ErrorNumber.None],
 /// <summary>
 /// 获取AKStreamKeeper的版本标识
 /// </summary>
 /// <param name="mediaServerId"></param>
 /// <param name="rs"></param>
 /// <returns></returns>
 public static string GetVersion(string mediaServerId, out ResponseStruct rs)
 {
     rs = new ResponseStruct()
     {
         Code    = ErrorNumber.None,
         Message = ErrorMessage.ErrorDic ![ErrorNumber.None],
示例#7
0
 /// <summary>
 /// 通过ingest获取onvif设备配置
 /// </summary>
 /// <param name="deviceId"></param>
 /// <param name="vhostDomain"></param>
 /// <param name="ingestName"></param>
 /// <param name="rs"></param>
 /// <returns></returns>
 public static OnvifMonitorStruct GetOnvifMonitorInfoByIngest(string deviceId, string vhostDomain,
                                                              string ingestName, out ResponseStruct rs)
 {
     rs = new ResponseStruct()
     {
         Code    = ErrorNumber.None,
         Message = ErrorMessage.ErrorDic ![ErrorNumber.None],
示例#8
0
 /// <summary>
 /// 获取合并裁剪任务的情况
 /// </summary>
 /// <param name="taskId"></param>
 /// <param name="rs"></param>
 /// <returns></returns>
 public static ResKeeperCutMergeTaskStatusResponse GetMergeTaskStatus(string taskId, out ResponseStruct rs)
 {
     rs = new ResponseStruct()
     {
         Code    = ErrorNumber.None,
         Message = ErrorMessage.ErrorDic ![ErrorNumber.None],
示例#9
0
        /// <summary>
        /// Takes one encoded response, computes delay and diff and stores it
        /// </summary>
        /// <param name="packet"></param>
        private void responseHandler(NetworkPacket packet)
        {
            // unpacking response
            TimeSyncRsMsg response = new TimeSyncRsMsg();
            response.Deserialize(packet.Data);
            Hash sender = packet.PublicKeySource;

            // if never sent request to this peer, drop packet
            if (!sentRequests.Keys.Contains(sender))
                return;

            // store response and calculated results
            if (sentRequests[sender].token == packet.Token)
            {
                ResponseStruct rs = new ResponseStruct();
                rs.sentTime = response.senderTime;
                rs.token = packet.Token;
                rs.receivedTime = nodeState.SystemTime;
                rs.responderTime = response.responderTime;
                long delay = (rs.receivedTime - rs.sentTime) / 2;
                rs.diff = rs.responderTime - delay - rs.sentTime;
                collectedResponses.AddOrUpdate(sender, rs, (ok, ov) => rs);
            }
        }
示例#10
0
        public static OnvifMonitor InitOnvifMonitorByIpAddrWhenNotInit(string ipAddr, out ResponseStruct rs)
        {
            if (Common.OnvifManagers != null)
            {
                OnvifInstance ovi = Common.OnvifManagers.FindLast(x => x.IpAddr.Trim().Equals(ipAddr.Trim())) !;
                if (ovi != null)
                {
                    if (ovi.OnvifMonitor == null)
                    {
                        ovi.OnvifMonitor = new OnvifMonitor(ovi.IpAddr, ovi.Username !, ovi.Password !);
                        ovi.OnvifMonitor.InitMonitor().Wait();
                        return(GetOnvifMonitor(ipAddr, out rs));
                    }

                    return(GetOnvifMonitor(ipAddr, out rs));
                }

                rs = new ResponseStruct()
                {
                    Code    = ErrorNumber.OnvifMonitorNotInit,
                    Message = ErrorMessage.ErrorDic ![ErrorNumber.OnvifMonitorNotInit],
示例#11
0
 /// <summary>
 /// 通过id删除一个录制计划
 /// </summary>
 /// <param name="id"></param>
 /// <param name="rs"></param>
 /// <returns></returns>
 public static bool DeleteDvrPlanById(long id, out ResponseStruct rs)
 {
     rs = new ResponseStruct()
     {
         Code    = ErrorNumber.None,
         Message = ErrorMessage.ErrorDic ![ErrorNumber.None],
示例#12
0
 /// <summary>
 /// 获取需要裁剪合并的文件列表
 /// </summary>
 /// <param name="rcmv"></param>
 /// <param name="rs"></param>
 /// <returns></returns>
 private static List <CutMergeStruct> analysisVideoFile(ReqCutOrMergeVideoFile rcmv, out ResponseStruct rs)
 {
     rs = new ResponseStruct()
     {
         Code    = ErrorNumber.None,
         Message = ErrorMessage.ErrorDic ![ErrorNumber.None],
示例#13
0
 /// <summary>
 /// 处理srs心跳信息
 /// </summary>
 /// <param name="heartbeat"></param>
 /// <param name="rs"></param>
 /// <returns></returns>
 public static bool OnHeartbeat(ReqSrsHeartbeat heartbeat, out ResponseStruct rs)
 {
     rs = new ResponseStruct()
     {
         Code    = ErrorNumber.None,
         Message = ErrorMessage.ErrorDic ![ErrorNumber.None],