108 lines
5.3 KiB
C#
108 lines
5.3 KiB
C#
![]() |
using Quartz;
|
|||
|
using System;
|
|||
|
using System.IO;
|
|||
|
using System.Threading;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using VideoSurveillanceAdapter;
|
|||
|
using Yunda.ISAS.DataMonitoringServer.DataAnalysis;
|
|||
|
using Yunda.ISAS.DataMonitoringServer.DataAnalysis.Model;
|
|||
|
using YunDa.ISAS.Redis.Entities.LinkageCategory;
|
|||
|
|
|||
|
namespace Yunda.ISAS.DataMonitoringServer.TimeWorkers
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 下载联动录像
|
|||
|
/// </summary>
|
|||
|
[DisallowConcurrentExecution]
|
|||
|
public class DownloadAndTranscodeLinkResult : IJob
|
|||
|
{
|
|||
|
public async Task Execute(IJobExecutionContext context)
|
|||
|
{
|
|||
|
return;
|
|||
|
if (TimeWorkService._redisDataRepository.LinkageResultInfoRedis != null)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
//var redis = MonitoringDataService.SingleInstance.RedisCamAuthRepository.LinkageResultInfoRedis;
|
|||
|
var last = await TimeWorkService._redisDataRepository.LinkageResultInfoRedis.GetListTailDataAsync(nameof(LinkageResultInfoRedis));
|
|||
|
if (last == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
while (DateTime.Now - last.DateTime >= TimeSpan.FromMinutes(5))
|
|||
|
{
|
|||
|
var data = await TimeWorkService._redisDataRepository.LinkageResultInfoRedis.ListRightPopAsync(nameof(LinkageResultInfoRedis));
|
|||
|
VideoPlayer videoPlayer = new VideoPlayer();
|
|||
|
CameraBrand cb = CameraBrand.None;
|
|||
|
Enum.TryParse(data.VideoDevOutput.Parent.ManufacturerInfo.ManufacturerCode, out cb);
|
|||
|
if (cb == CameraBrand.None)
|
|||
|
{
|
|||
|
MonitoringEventBus.LogHandler("[" + data.VideoDevOutput.Parent.DevName + "]NVR厂商品牌不正确!", "摄像头error");
|
|||
|
return;
|
|||
|
}
|
|||
|
videoPlayer.CameraConfigure = new CameraConfigure
|
|||
|
{
|
|||
|
ID = data.VideoDevOutput.Parent.Id.ToString(),
|
|||
|
Name = data.VideoDevOutput.Parent.DevName,
|
|||
|
Ip = data.VideoDevOutput.Parent.IP,
|
|||
|
Port = (int)data.VideoDevOutput.Parent.Port,
|
|||
|
UserName = data.VideoDevOutput.Parent.DevUserName,
|
|||
|
Password = data.VideoDevOutput.Parent.DevPassword,
|
|||
|
IsRecordVideo = false,
|
|||
|
//VideoPath = @".\Video\",
|
|||
|
//CapturePath = @".\Capture\",
|
|||
|
CameraBrand = cb,
|
|||
|
//PlayChannel = Convert.ToInt32(camera.ChannelNo)
|
|||
|
};
|
|||
|
var player = TimeWorkService._cameraDataCenter.FindCamera(videoPlayer);
|
|||
|
if (player == null)
|
|||
|
{
|
|||
|
var isloginSuccess = videoPlayer.LoginCamera();
|
|||
|
if (isloginSuccess)
|
|||
|
{
|
|||
|
TimeWorkService._cameraDataCenter.CameraCollection.Add(videoPlayer);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
MonitoringEventBus.LogHandler($"{videoPlayer.CameraConfigure.Name}登陆失败", "异常信息");
|
|||
|
return;
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
videoPlayer = player;
|
|||
|
}
|
|||
|
AutoResetEvent autoResetEvent = new AutoResetEvent(true);
|
|||
|
DownloadFileCallBack downloadFileCallBack = arg =>
|
|||
|
{
|
|||
|
if (arg.Progress == 100)
|
|||
|
{
|
|||
|
autoResetEvent.Set();
|
|||
|
}
|
|||
|
};
|
|||
|
var path = $"./RecordVideo/{data.VideoDevOutput.DevName}_{data.PresetPointOutput.Name}_{data.DateTime.Ticks}.mp4";
|
|||
|
videoPlayer.DownloadFileByTime(path,
|
|||
|
data.LinkageResultOuput.LinkageStartTime - TimeSpan.FromSeconds(10),
|
|||
|
data.LinkageResultOuput.LinkageStartTime + TimeSpan.FromSeconds(data.Duration), downloadFileCallBack, data.VideoDevOutput.ChannelNo
|
|||
|
);
|
|||
|
autoResetEvent.WaitOne();
|
|||
|
autoResetEvent.Dispose();
|
|||
|
string result = TimeWorkService._webApiRequest.ResumeFile(ConstantModel.RequestLinkageResultFileUploadUri, path, data.RelativePath, 0, 1024 * 128);
|
|||
|
MonitoringEventBus.LogHandler($"{videoPlayer.CameraConfigure.Name}上传{result}", "上传联动录像信息");
|
|||
|
if (File.Exists(path))
|
|||
|
{
|
|||
|
File.Delete(path);
|
|||
|
}
|
|||
|
last = await TimeWorkService._redisDataRepository.LinkageResultInfoRedis.GetListTailDataAsync(nameof(LinkageResultInfoRedis));
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
MonitoringEventBus.LogHandler($"上传联动录像信息异常:{ex.Message}", "异常信息");
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
}
|