|
|
@ -17,11 +17,6 @@ public class CameraDataCenter |
|
|
|
|
|
|
|
private Thread _thread { get; set; } |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// (cbCameraId, MarkSearcherBase)
|
|
|
|
/// </summary>
|
|
|
|
private ConcurrentDictionary<long, MarkSearcherBase> _markSearcherDict { get; set; } = new(); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// (cbCameraId, cbCameraIp)
|
|
|
|
/// </summary>
|
|
|
@ -37,6 +32,22 @@ public class CameraDataCenter |
|
|
|
/// </summary>
|
|
|
|
private ConcurrentDictionary<string, PtzInfo> _cameraPtzInfoDict { get; set; } = new(); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// _markSearcherDict 锁对象,写锁
|
|
|
|
/// </summary>
|
|
|
|
private static readonly ReaderWriterLockSlim msDictLock = new(); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// (cbCameraId, MarkSearcherBase)
|
|
|
|
/// </summary>
|
|
|
|
private ConcurrentDictionary<long, MarkSearcherBase> _markSearcherDict { get; set; } = new(); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// (cameraId, List(MarkLabelCalcResult))
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
private ConcurrentDictionary<long, List<MarkLabelCalcResult>> _markLabelCalcResultListDict { get; set; } = new(); |
|
|
|
|
|
|
|
#endregion Attr
|
|
|
|
|
|
|
|
public CameraDataCenter() |
|
|
@ -105,6 +116,7 @@ public class CameraDataCenter |
|
|
|
if (ptzInfo == null) continue; |
|
|
|
markSearcher.UpdateCameraCalcInfo(ptzInfo); |
|
|
|
List<MarkLabelCalcResult> resultList = markSearcher.Calc(); |
|
|
|
_markLabelCalcResultListDict[cameraId] = resultList; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -119,11 +131,18 @@ public class CameraDataCenter |
|
|
|
/// <returns></returns>
|
|
|
|
public bool ActiveCamera(long cameraId) |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
msDictLock.EnterWriteLock(); |
|
|
|
if (_markSearcherDict.ExistsKey(cameraId)) |
|
|
|
return false; |
|
|
|
// 获取 cbCamera
|
|
|
|
CbCamera cbCamera = _cbCameraRep.GetById(cameraId); |
|
|
|
if (cbCamera == null) return false; |
|
|
|
// 获取 tbPtzCamera
|
|
|
|
TbPtzCamera tbPtzCamera; |
|
|
|
string cameraIp = cbCamera.Ip; |
|
|
|
if (!_tbPtzCameraDict.IsExistKey(cameraIp)) |
|
|
|
if (!_tbPtzCameraDict.ExistsKey(cameraIp)) |
|
|
|
{ |
|
|
|
tbPtzCamera = _tbPtzCameraRep.GetFirst(u => u.Ip == cameraIp); |
|
|
|
if (tbPtzCamera == null) return false; |
|
|
@ -133,10 +152,15 @@ public class CameraDataCenter |
|
|
|
{ |
|
|
|
tbPtzCamera = _tbPtzCameraDict[cameraIp]; |
|
|
|
} |
|
|
|
// 存储 cbCamera id 对应 ip 关系
|
|
|
|
_cbCameraId2IpDict[cbCamera.Id] = cameraIp; |
|
|
|
// 创建 cameraCalcInfo
|
|
|
|
CameraCalcInfo cameraCalcInfo = CameraCalcInfo.New(cameraId, _ptzServerApi.GetPtzInfo(tbPtzCamera.Id)); |
|
|
|
// 创建 markSeacher
|
|
|
|
HikMarkSeacher markSeacher = new(cameraCalcInfo); |
|
|
|
// 获取 cmMarkLabel 列表
|
|
|
|
List<CmMarkLabel> cmMarkLabelList = _cmMarkLableRep.GetList(u => u.CbCameraId == cameraId); |
|
|
|
// 将 cmMarkLabel 一一添加到 markSeacher
|
|
|
|
foreach (CmMarkLabel item in cmMarkLabelList) |
|
|
|
{ |
|
|
|
MarkLabelCalcInfo markLabelCalcInfo = MarkLabelCalcInfo.New( |
|
|
@ -149,7 +173,13 @@ public class CameraDataCenter |
|
|
|
); |
|
|
|
markSeacher.AddMarkLabelCalcInfo(markLabelCalcInfo); |
|
|
|
} |
|
|
|
// 将 markSeacher 放入字典
|
|
|
|
_markSearcherDict[cameraId] = markSeacher; |
|
|
|
} |
|
|
|
finally |
|
|
|
{ |
|
|
|
msDictLock.ExitWriteLock(); |
|
|
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
@ -160,12 +190,52 @@ public class CameraDataCenter |
|
|
|
/// <returns></returns>
|
|
|
|
public bool DeActiveCamera(long cameraId) |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
msDictLock.EnterWriteLock(); |
|
|
|
_markSearcherDict.Remove(cameraId); |
|
|
|
_markLabelCalcResultListDict.Remove(cameraId); |
|
|
|
} |
|
|
|
finally |
|
|
|
{ |
|
|
|
msDictLock.ExitWriteLock(); |
|
|
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
public bool AddCameraMarkLabel(long cameraId, long markLabelId) |
|
|
|
{ |
|
|
|
if (!_markSearcherDict.ExistsKey(cameraId)) |
|
|
|
return false; |
|
|
|
MarkSearcherBase markSearcher = _markSearcherDict[cameraId]; |
|
|
|
if (markSearcher.ExistsMarkLabelCalcInfo(markLabelId)) |
|
|
|
return false; |
|
|
|
CmMarkLabel label = _cmMarkLableRep.GetById(markLabelId); |
|
|
|
if (label == null) |
|
|
|
return false; |
|
|
|
MarkLabelCalcInfo markLabelCalcInfo = MarkLabelCalcInfo.New( |
|
|
|
label.Id, |
|
|
|
PtzInfo.New(label.PanPosition, label.TiltPosition, label.ZoomPosition), |
|
|
|
label.CanvasWidth, |
|
|
|
label.CanvasHeight, |
|
|
|
label.CanvasLeft, |
|
|
|
label.CanvasTop |
|
|
|
); |
|
|
|
return markSearcher.AddMarkLabelCalcInfo(markLabelCalcInfo); |
|
|
|
} |
|
|
|
|
|
|
|
public bool UpdateCamera(long cameraId, long markLabelId) |
|
|
|
public bool DeleteCameraMarkLabel(long cameraId, long marklabelId) |
|
|
|
{ |
|
|
|
if (!_markSearcherDict.ExistsKey(cameraId)) |
|
|
|
return false; |
|
|
|
MarkSearcherBase markSearcher = _markSearcherDict[cameraId]; |
|
|
|
return markSearcher.DeleteMarkLabelCalcInfo(marklabelId); |
|
|
|
} |
|
|
|
|
|
|
|
public List<MarkLabelCalcResult> GetMarkLabelCalcResults(long cameraId) |
|
|
|
{ |
|
|
|
|
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
#endregion external call
|
|
|
|