支持通过网页增加、删除、修改摄像头配置信息

支持摄像头配置信息中句柄的设置,并实测有效
This commit is contained in:
2025-12-28 08:07:55 +08:00
parent 3718465463
commit 2ee25a4f7c
25 changed files with 2298 additions and 75 deletions

View File

@@ -34,6 +34,30 @@ public class FrameController
_accumulators.TryRemove(appId, out _);
}
// 修改 Register 方法,接收整个 Requirement 对象或多个参数
public void Register(FrameRequirement req)
{
_requirements.AddOrUpdate(req.AppId,
_ => req, // 如果不存在,直接添加整个对象
(_, old) =>
{
// 如果已存在,更新关键业务字段,同时保留统计状态
old.TargetFps = req.TargetFps;
old.Memo = req.Memo;
old.Handle = req.Handle;
old.Type = req.Type;
old.SavePath = req.SavePath;
// 注意:不要覆盖 old.RealFps保留之前的统计值
return old;
});
// 如果是降频(<=20确保积分器存在
if (req.TargetFps <= 20)
{
_accumulators.GetOrAdd(req.AppId, 0);
}
}
public void Unregister(string appId)
{
if (string.IsNullOrWhiteSpace(appId)) return;
@@ -100,6 +124,9 @@ public class FrameController
// 扣除成本,保留余数 (余数是精度的关键)
acc -= LOGICAL_BASE_FPS;
// 【核心修复】在此处触发统计RealFps 才会开始跳动
req.UpdateRealFps();
req.LastCaptureTick = currentTick;
}
@@ -120,6 +147,6 @@ public class FrameController
// ---------------------------------------------------------
public List<dynamic> GetCurrentRequirements()
{
return _requirements.Values.Select(r => new { r.AppId, r.TargetFps, LastActive = r.LastCaptureTick }).ToList<dynamic>();
return _requirements.Values.Select(r => new { r.AppId, r.TargetFps, r.RealFps, LastActive = r.LastCaptureTick, r.Memo, r.SavePath, r.Handle, r.TargetIp, r.TargetPort, r.Protocol, r.Type }).ToList<dynamic>();
}
}

View File

@@ -7,6 +7,36 @@
/// </summary>
public class FrameRequirement
{
public FrameRequirement()
{
}
public FrameRequirement(SubscriptionDto dto)
{
// 1. 核心标识
this.AppId = dto.AppId;
this.Type = dto.Type;
// 2. 流控参数
this.TargetFps = dto.DisplayFps;
// 3. 业务动态参数
this.Memo = dto.Memo;
this.Handle = dto.Handle;
this.RecordDuration = dto.RecordDuration;
this.SavePath = dto.SavePath;
// 4. 网络转发相关参数 (补全)
this.Protocol = dto.Protocol;
this.TargetIp = dto.TargetIp;
this.TargetPort = dto.TargetPort;
// 5. 初始化内部统计状态
this.LastCaptureTick = Environment.TickCount64;
this._lastFpsCalcTick = Environment.TickCount64;
this.IsActive = true;
}
#region --- (Subscriber Core Identification) ---
/// <summary> 订阅者唯一ID如 "Client_A"、"AI_Service"、"WPF_Display_Main" </summary>
@@ -81,16 +111,20 @@ public class FrameRequirement
/// <remarks> 每当成功分发一帧后调用,内部自动按秒计算 RealFps </remarks>
public void UpdateRealFps()
{
_frameCount++;
long currentTick = Environment.TickCount64;
long elapsed = currentTick - _lastFpsCalcTick;
if (elapsed >= 1000) // 达到 1 秒周期
try
{
RealFps = Math.Round(_frameCount / (elapsed / 1000.0), 1);
_frameCount = 0;
_lastFpsCalcTick = currentTick;
_frameCount++;
long currentTick = Environment.TickCount64;
long elapsed = currentTick - _lastFpsCalcTick;
if (elapsed >= 1000) // 达到 1 秒周期
{
RealFps = Math.Round(_frameCount / (elapsed / 1000.0), 1);
_frameCount = 0;
_lastFpsCalcTick = currentTick;
}
}
catch{ }
}
#endregion