|
|
@ -1,8 +1,8 @@ |
|
|
|
using Cis.Application.Core.Component.MarkSeacher; |
|
|
|
using Cis.Application.Core.Component.PtzServer; |
|
|
|
using EC.Helper.CameraSDK; |
|
|
|
using FreeRedis; |
|
|
|
using StackExchange.Profiling.Internal; |
|
|
|
using StackExchange.Redis; |
|
|
|
using System.Collections.Concurrent; |
|
|
|
|
|
|
|
namespace Cis.Application.Core; |
|
|
@ -11,7 +11,7 @@ public class CameraDataCenter : ISingleton |
|
|
|
{ |
|
|
|
#region Attr
|
|
|
|
|
|
|
|
private readonly IDatabase _cache; |
|
|
|
private readonly RedisClient _cache; |
|
|
|
private readonly CameraDataOptions _options; |
|
|
|
private readonly ICameraSdkServer _cameraSdkServer; |
|
|
|
private readonly IMarkSearcherServer _markSearcherServer; |
|
|
@ -25,7 +25,7 @@ public class CameraDataCenter : ISingleton |
|
|
|
#endregion Attr
|
|
|
|
|
|
|
|
public CameraDataCenter( |
|
|
|
IDatabase cache, |
|
|
|
RedisClient cache, |
|
|
|
ICameraSdkServer cameraSdkServer, |
|
|
|
IMarkSearcherServer markSearcherServer |
|
|
|
) |
|
|
@ -49,11 +49,11 @@ public class CameraDataCenter : ISingleton |
|
|
|
private void InitThread() |
|
|
|
{ |
|
|
|
// 初始化 CameraPtzThread
|
|
|
|
RefreshCameraPtzThread = new Thread(() => |
|
|
|
RefreshCameraPtzThread = new Thread(async () => |
|
|
|
{ |
|
|
|
while (true) |
|
|
|
{ |
|
|
|
RefreshCameraPtzInfos(); |
|
|
|
await RefreshCameraPtzInfos(); |
|
|
|
Thread.Sleep(_options.CameraPtz.LoopInterval); |
|
|
|
} |
|
|
|
}) |
|
|
@ -63,20 +63,20 @@ public class CameraDataCenter : ISingleton |
|
|
|
// 启动 CameraPtzThread
|
|
|
|
RefreshCameraPtzThread.Start(); |
|
|
|
|
|
|
|
// 初始化 MarkSearcherThread
|
|
|
|
RefreshMarkSearcherThread = new Thread(() => |
|
|
|
{ |
|
|
|
while (true) |
|
|
|
{ |
|
|
|
RefreshMarkSearchers(); |
|
|
|
Thread.Sleep(_options.MarkSearcher.LoopInterval); |
|
|
|
} |
|
|
|
}) |
|
|
|
{ |
|
|
|
IsBackground = true// 设置后台线程
|
|
|
|
}; |
|
|
|
// 启动 MarkSearcherThread
|
|
|
|
RefreshMarkSearcherThread.Start(); |
|
|
|
//// 初始化 MarkSearcherThread
|
|
|
|
//RefreshMarkSearcherThread = new Thread(async () =>
|
|
|
|
//{
|
|
|
|
// while (true)
|
|
|
|
// {
|
|
|
|
// await RefreshMarkSearchers();
|
|
|
|
// Thread.Sleep(_options.MarkSearcher.LoopInterval);
|
|
|
|
// }
|
|
|
|
//})
|
|
|
|
//{
|
|
|
|
// IsBackground = true// 设置后台线程
|
|
|
|
//};
|
|
|
|
//// 启动 MarkSearcherThread
|
|
|
|
//RefreshMarkSearcherThread.Start();
|
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
@ -84,13 +84,12 @@ public class CameraDataCenter : ISingleton |
|
|
|
/// 有待改善,应设置超时计数机制
|
|
|
|
/// https://blog.csdn.net/qq_28368039/article/details/118597396
|
|
|
|
/// </summary>
|
|
|
|
private async void RefreshCameraPtzInfos() |
|
|
|
private async Task RefreshCameraPtzInfos() |
|
|
|
{ |
|
|
|
HashEntry[] entries = _cache.HashGetAll(CacheInfo.CameraIpCounts); |
|
|
|
string[] cameraIpList = await _cache.HKeysAsync(CacheInfo.CameraIpCounts); |
|
|
|
List<Task> tasks = new(); |
|
|
|
foreach (HashEntry entry in entries) |
|
|
|
foreach (string cameraIp in cameraIpList) |
|
|
|
{ |
|
|
|
string cameraIp = entry.Name; |
|
|
|
tasks.Add(RefreshCameraPtzInfo(cameraIp)); |
|
|
|
} |
|
|
|
await Task.WhenAny(Task.WhenAll(tasks), Task.Delay(_options.CameraPtz.Timeout)); |
|
|
@ -103,21 +102,20 @@ public class CameraDataCenter : ISingleton |
|
|
|
/// <returns></returns>
|
|
|
|
private async Task RefreshCameraPtzInfo(string cameraIp) |
|
|
|
{ |
|
|
|
bool ret = _cameraSdkServer.GetPtzInfoByIp(cameraIp, out PtzInfo ptzInfo); |
|
|
|
bool ret = _cameraSdkServer.TryGetPtzInfoByIp(cameraIp, out PtzInfo ptzInfo); |
|
|
|
if (!ret) return; |
|
|
|
await _cache.HashSetAsync(CacheInfo.CameraPtzInfos, cameraIp, ptzInfo.ToJson()); |
|
|
|
await _cache.HSetAsync(CacheInfo.CameraPtzInfos, cameraIp, ptzInfo.ToJson()); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 刷新所有 markSearcher
|
|
|
|
/// </summary>
|
|
|
|
private async void RefreshMarkSearchers() |
|
|
|
private async Task RefreshMarkSearchers() |
|
|
|
{ |
|
|
|
HashEntry[] entries = _cache.HashGetAll(CacheInfo.CameraId2Ip); |
|
|
|
string[] cameraIdList = await _cache.HKeysAsync(CacheInfo.CameraId2Ip); |
|
|
|
List<Task> tasks = new(); |
|
|
|
foreach (HashEntry entry in entries) |
|
|
|
foreach (string cameraId in cameraIdList) |
|
|
|
{ |
|
|
|
string cameraId = entry.Name; |
|
|
|
tasks.Add(RefreshMarkSearcher(cameraId.ToLong())); |
|
|
|
} |
|
|
|
await Task.WhenAny(Task.WhenAll(tasks), Task.Delay(_options.CameraPtz.Timeout)); |
|
|
@ -132,10 +130,11 @@ public class CameraDataCenter : ISingleton |
|
|
|
{ |
|
|
|
MarkSearcherBase markSearcher = _markSearcherServer.GetSearcher(cameraId); |
|
|
|
if (markSearcher == null) return; |
|
|
|
string cameraIp = _cache.HashGet(CacheInfo.CameraId2Ip, cameraId); |
|
|
|
RedisValue value = _cache.HashGet(CacheInfo.CameraPtzInfos, cameraIp); |
|
|
|
if (!value.HasValue) return; |
|
|
|
PtzInfo ptzInfo = value.ToString().FromJson<PtzInfo>(); |
|
|
|
string cameraIp = await _cache.HGetAsync(CacheInfo.CameraId2Ip, cameraId.ToString()); |
|
|
|
string ptzInfoStr = await _cache.HGetAsync(CacheInfo.CameraPtzInfos, cameraIp); |
|
|
|
if (string.IsNullOrEmpty(ptzInfoStr)) return; |
|
|
|
PtzInfo ptzInfo = ptzInfoStr.ToObject<PtzInfo>(); |
|
|
|
if (ptzInfo == null) return; |
|
|
|
markSearcher.UpdateCameraCalcParams(ptzInfo); |
|
|
|
List<MarkLabelCalcResult> resultList = await markSearcher.SearchAsync(); |
|
|
|
SearchResultListDict[cameraId] = resultList; |
|
|
|