Camera Information System
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

73 lines
1.9 KiB

using Cis.Application.Core.Component.PtzServer;
using EC.Helper.CameraSDK;
using StackExchange.Redis;
using System.Collections.Concurrent;
namespace Cis.Application.Core.Component.CameraSDK;
/// <summary>
/// 相机 sdk 服务类
/// </summary>
public class CameraSdkServer : ICameraSdkServer, ISingleton
{
#region Attr
private readonly IDatabase _cache;
/// <summary>
/// {ip, ICameraSDK}
/// </summary>
private ConcurrentDictionary<string, ICameraSDK> CameraSdkDict { get; set; } = new();
#endregion Attr
public CameraSdkServer(IDatabase cache)
{
_cache = cache;
}
#region Base Method
public bool RegisterCamera(CameraInfo cameraInfo)
{
bool ret = CameraSdkDict.ContainsKey(cameraInfo.Ip);
if (ret) return false;
ICameraSDK cameraSDK = ((CameraType)cameraInfo.Type).CreateCameraSDK(cameraInfo);
if (cameraSDK == null) return false;
ret = cameraSDK.Init();
if (!ret) return false;
ret = CameraSdkDict.TryAdd(cameraInfo.Ip, cameraSDK);
return ret;
}
public bool DeleteCamera(string ip)
{
return CameraSdkDict.TryRemove(ip, out _);
}
public bool IsExistsCamera(string ip)
{
return CameraSdkDict.ContainsKey(ip);
}
#endregion Base Method
#region Main Method
public bool GetPtzInfoById(string cameraId, out PtzInfo ptzInfo)
{
RedisValue value = _cache.HashGet(CacheInfo.CameraId2Ip, cameraId);
if (value.IsNull) { ptzInfo = PtzInfo.Default; return false; }
string ip = value.ToString();
return GetPtzInfoByIp(ip, out ptzInfo);
}
public bool GetPtzInfoByIp(string ip, out PtzInfo ptzInfo)
{
bool ret = CameraSdkDict.TryGetValue(ip, out ICameraSDK cameraSDK);
if (!ret) { ptzInfo = PtzInfo.Default; return false; }
return cameraSDK.GetPtzInfo(out ptzInfo);
}
#endregion Main Method
}