Exemple #1
0
        public static ResToWebHookOnRecordMP4 OnRecordMp4(ReqForWebHookOnRecordMP4 req)
        {
            Logger.Info($"[{Common.LoggerHead}]->收到WebHook-OnRecordMp4回调->{JsonHelper.ToJson(req)}");

            var mediaServer = Common.MediaServerList.FindLast(x => x.MediaServerId.Equals(req.MediaServerId));

            if (mediaServer == null)
            {
                return(new ResToWebHookOnRecordMP4()
                {
                    Code = -1,
                    Msg = "没找到相应的流媒体服务器",
                });
            }

            var videoChannel = ORMHelper.Db.Select <VideoChannel>().Where(x => x.MainId.Equals(req.Stream)).First();

            if (videoChannel == null)
            {
                return(new ResToWebHookOnRecordMP4()
                {
                    Code = 0,
                    Msg = "success"
                });
            }

            var        st          = UtilsHelper.ConvertDateTimeToInt((long)req.Start_Time);
            DateTime   currentTime = DateTime.Now;
            RecordFile tmpDvrVideo = new RecordFile();

            tmpDvrVideo.App             = req.App;
            tmpDvrVideo.Vhost           = req.Vhost;
            tmpDvrVideo.Streamid        = req.Stream;
            tmpDvrVideo.FileSize        = req.File_Size;
            tmpDvrVideo.DownloadUrl     = req.Url;
            tmpDvrVideo.VideoPath       = req.File_Path;
            tmpDvrVideo.StartTime       = st;
            tmpDvrVideo.EndTime         = st.AddSeconds((int)req.Time_Len);
            tmpDvrVideo.Duration        = req.Time_Len;
            tmpDvrVideo.Undo            = false;
            tmpDvrVideo.Deleted         = false;
            tmpDvrVideo.MediaServerId   = req.MediaServerId;
            tmpDvrVideo.UpdateTime      = currentTime;
            tmpDvrVideo.RecordDate      = st.ToString("yyyy-MM-dd");
            tmpDvrVideo.MainId          = videoChannel.MainId;
            tmpDvrVideo.MediaServerIp   = mediaServer.IpV4Address;
            tmpDvrVideo.ChannelName     = videoChannel.ChannelName;
            tmpDvrVideo.DepartmentId    = videoChannel.DepartmentId;
            tmpDvrVideo.DepartmentName  = videoChannel.DepartmentName;
            tmpDvrVideo.PDepartmentId   = videoChannel.PDepartmentId;
            tmpDvrVideo.PDepartmentName = videoChannel.PDepartmentName;
            tmpDvrVideo.DeviceId        = videoChannel.DeviceId;
            tmpDvrVideo.ChannelId       = videoChannel.ChannelId;
            tmpDvrVideo.VideoSrcUrl     = videoChannel.VideoSrcUrl;
            tmpDvrVideo.CreateTime      = DateTime.Now;
            string tmp = tmpDvrVideo.DownloadUrl;

            tmp = tmp.Replace("\\", "/", StringComparison.Ordinal); //跨平台兼容
            if (tmp.Contains(":"))
            {
                tmp = tmp.Substring(tmp.IndexOf(':') + 1); //清除掉类似  c: 这样的字符,跨平台兼容
            }

            bool found = false;

            foreach (var recordPath in mediaServer.RecordPathList)
            {
                if (!string.IsNullOrEmpty(recordPath.Value) && req.File_Path.Contains(recordPath.Value))
                {
                    tmp = tmp.Replace(recordPath.Value, "", StringComparison.Ordinal);
                    if (tmp.StartsWith("/"))
                    {
                        tmp = tmp.TrimStart('/');
                    }

                    string str = recordPath.Value.EndsWith('/') == true ? recordPath.Value : recordPath.Value + "/";
                    str = str.StartsWith('/') == true ? str : "/" + str;
                    tmpDvrVideo.DownloadUrl = "http://" + mediaServer.IpV4Address + ":" + mediaServer.KeeperPort +
                                              str.Trim() + tmp;
                    found = true;
                }
            }

            if (!found)
            {
                //如果不包含自定义视频存储目录地址,就认为是默认地址
                if (!string.IsNullOrEmpty(tmp) && tmp.Contains("/record/"))
                {
                    tmp = tmp.Replace("/record/", "", StringComparison.Ordinal);
                }

                tmpDvrVideo.DownloadUrl = "http://" + mediaServer.IpV4Address + ":" + mediaServer.HttpPort +
                                          "/" + tmp;
            }

            try
            {
                var dbRet = ORMHelper.Db.Insert(tmpDvrVideo).ExecuteAffrows();
            }
            catch (Exception ex)
            {
                ResponseStruct rs = new ResponseStruct()
                {
                    Code             = ErrorNumber.Sys_DataBaseExcept,
                    Message          = ErrorMessage.ErrorDic ![ErrorNumber.Sys_DataBaseExcept],