feat(agent): pipeline capture vidéo — FFmpeg par caméra, snapshots adaptatifs, frames → analyseur (Fixes #1)

- CameraStreamService enregistré dans le DI + hosted SnapshotPipelineService
  qui synchronise les captures avec les caméras assignées (Central = source de
  vérité via clés camera.<id>.* dans la config agent ; fallback local Agent:Cameras)
- Découpage du flux MJPEG en frames JPEG (JpegFrameSplitter, marqueurs SOI/EOI)
- Intervalle adaptatif (spec Phase 15) : scène vide 1000ms / mouvement 500ms /
  objet détecté 200ms, doublé si CPU > 80% ; état de scène piloté par les
  résultats de l'analyseur + proxy de mouvement (FrameMotionDetector, pixel diff
  réel en Phase 16)
- Channel borné 100 snapshots (DropOldest) — backpressure + compteur de drops
  et log rate-limité (alerte admin via remontée des logs agent)
- Frames réellement transmises à FrameAnalyzerService (compteur AnalyzedFrameCount)
- Central : GET /api/settings/agent/{id} embarque les caméras assignées
  (name/rtsp/sub_rtsp/enabled) ; ConfigReceiverService les applique à chaud
- Tests : JpegFrameSplitter, intervalle adaptatif, tracker de scène, motion
  detector, CameraConfigStore, pipeline (snapshot → analyseur), handler config
This commit is contained in:
Arnaud Dartois committed 2026-08-11 21:16:28 +02:00
1 parent ea773b17a1
commit c38d69a1e5
24 files changed
+1365 -12

No files matched your search

@@ -1,6 +1,7 @@
using Heimdall.Application.Common;
using Heimdall.Application.DTOs;
using Heimdall.Application.Security;
using Heimdall.Domain.Enums;
using MediatR;
using Microsoft.EntityFrameworkCore;
@@ -68,6 +69,29 @@ public class GetEffectiveAgentConfigQueryHandler
}
}
// ── Camera assignments ──
// The agent needs the RTSP URLs of the cameras it must capture. The
// Central is the source of truth: cameras assigned to this agent (and
// not soft-deleted) are shipped as flat `camera.<id>.*` keys so the
// existing config pipeline (full reload + live SettingChanged events)
// carries them to the agent without a new API surface.
var cameras = await _db.Cameras
.AsNoTracking()
.Where(c => c.AgentId == request.AgentId && !c.IsDeleted)
.ToListAsync(ct)
.ConfigureAwait(false);
foreach (var camera in cameras)
{
var prefix = $"camera.{camera.Id}";
config[$"{prefix}.name"] = camera.Name;
if (!string.IsNullOrWhiteSpace(camera.RtspUrl))
config[$"{prefix}.rtsp"] = camera.RtspUrl;
if (!string.IsNullOrWhiteSpace(camera.SubRtspUrl))
config[$"{prefix}.sub_rtsp"] = camera.SubRtspUrl;
config[$"{prefix}.enabled"] = camera.Status != CameraStatus.Disabled ? "true" : "false";
}
return ServiceResult<Dictionary<string, string>>.Success(config);
}
}