feat(discovery): add camera detection pipeline inspired by Strix

Add complete camera discovery and stream testing specification,
Domain entities, enums, DTOs, Application interfaces, and EF Core
configurations for automated ONVIF/mDNS/HTTP/ARP camera detection.

- 4 new enums: CameraDiscoveryMethod, DetectedCameraType,
  StreamProtocol, CameraCapability (flags)
- Camera entity extended with 15+ discovery/test fields
- New entities: CameraDiscoveryResult, DiscoveredStreamUrl
- DTOs: ProbeRequest/Response, StreamTestRequest/Session, etc.
- Interface: ICameraDiscoveryService (8 methods)
- EF Core configurations for all new tables + columns
- Full spec doc: docs/specifications/detection-camera.md (16 sections)
- 145 tests pass, 0 warnings

Inspiré de Strix (github.com/eduard256/Strix) — moteur de
découverte de flux IP supportant 3600+ marques, 100K+ patterns.
This commit is contained in:
Arnaud Dartois committed 2026-07-18 21:15:05 +00:00
1 parent 8c6b2610a0
commit 7e66bb4fbb
16 files changed
+1815 -7

No files matched your search

@@ -1,4 +1,5 @@
using Heimdall.Domain.Entities;
using Heimdall.Domain.Enums;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
@@ -12,6 +13,7 @@ public class CameraConfiguration : IEntityTypeConfiguration<Camera>
builder.HasKey(c => c.Id);
// ── Core ────────────────────────────────────────────────────
builder.Property(c => c.Name)
.HasMaxLength(200)
.IsRequired()
@@ -33,17 +35,67 @@ public class CameraConfiguration : IEntityTypeConfiguration<Camera>
.IsRequired()
.IsUnicode(false);
// ── Discovery ───────────────────────────────────────────────
builder.Property(c => c.DiscoveryMethod)
.HasConversion<string>()
.HasMaxLength(20)
.IsUnicode(false);
builder.Property(c => c.DetectedType)
.HasConversion<string>()
.HasMaxLength(20)
.IsUnicode(false);
builder.Property(c => c.IpAddress)
.HasMaxLength(45); // IPv6 max length
builder.Property(c => c.MacAddress)
.HasMaxLength(17); // "XX:XX:XX:XX:XX:XX"
builder.Property(c => c.RtspPort);
builder.Property(c => c.HttpPort);
builder.Property(c => c.OnvifPort);
builder.Property(c => c.Capabilities)
.HasConversion<string>()
.HasMaxLength(64)
.IsUnicode(false);
builder.Property(c => c.LastDiscoveredAt);
// ── Stream test ─────────────────────────────────────────────
builder.Property(c => c.SubRtspUrl)
.HasMaxLength(1000)
.IsUnicode(false);
builder.Property(c => c.LastTestedCodecs)
.HasMaxLength(200)
.IsUnicode(false);
builder.Property(c => c.LastTestedWidth);
builder.Property(c => c.LastTestedHeight);
builder.Property(c => c.LastTestedLatencyMs);
builder.Property(c => c.LastStreamTestAt);
// ── Legacy capabilities ─────────────────────────────────────
builder.Property(c => c.HasPtz);
builder.Property(c => c.HasAudio);
builder.Property(c => c.HasMotionDetection);
// ── Audit ───────────────────────────────────────────────────
builder.Property(c => c.CreatedAt)
.HasDefaultValueSql("NOW()");
builder.Property(c => c.UpdatedAt)
.HasDefaultValueSql("NOW()");
// Indexes
// ── Indexes ─────────────────────────────────────────────────
builder.HasIndex(c => c.SiteId);
builder.HasIndex(c => c.AgentId);
builder.HasIndex(c => c.IpAddress);
builder.HasIndex(c => c.MacAddress);
// Relationships
// ── Relationships ───────────────────────────────────────────
builder.HasOne(c => c.Site)
.WithMany(s => s.Cameras)
.HasForeignKey(c => c.SiteId)
@@ -0,0 +1,106 @@
using Heimdall.Domain.Entities;
using Heimdall.Domain.Enums;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Heimdall.Infrastructure.Data.Configurations;
public class CameraDiscoveryResultConfiguration : IEntityTypeConfiguration<CameraDiscoveryResult>
{
public void Configure(EntityTypeBuilder<CameraDiscoveryResult> builder)
{
builder.ToTable("camera_discovery_results");
builder.HasKey(r => r.Id);
// ── Identification ──────────────────────────────────────────
builder.Property(r => r.IpAddress)
.HasMaxLength(45)
.IsRequired()
.IsUnicode(false);
builder.Property(r => r.MacAddress)
.HasMaxLength(17)
.IsUnicode(false);
builder.Property(r => r.Vendor)
.HasMaxLength(100)
.IsUnicode(false);
builder.Property(r => r.Hostname)
.HasMaxLength(255)
.IsUnicode(false);
// ── Classification ──────────────────────────────────────────
builder.Property(r => r.DetectedType)
.HasConversion<string>()
.HasMaxLength(20)
.IsUnicode(false);
builder.Property(r => r.DiscoveryMethod)
.HasConversion<string>()
.HasMaxLength(20)
.IsUnicode(false);
// ── Ports ───────────────────────────────────────────────────
builder.Property(r => r.OpenPorts)
.HasColumnType("integer[]")
.IsUnicode(false);
// ONVIF
builder.Property(r => r.OnvifDeviceServiceUrl)
.HasMaxLength(500)
.IsUnicode(false);
builder.Property(r => r.OnvifName)
.HasMaxLength(200)
.IsUnicode(false);
builder.Property(r => r.OnvifHardware)
.HasMaxLength(200)
.IsUnicode(false);
builder.Property(r => r.OnvifPort);
// HTTP
builder.Property(r => r.HttpServerHeader)
.HasMaxLength(200)
.IsUnicode(false);
builder.Property(r => r.HttpStatusCode);
builder.Property(r => r.HttpPort);
// HomeKit
builder.Property(r => r.HomeKitName)
.HasMaxLength(200)
.IsUnicode(false);
builder.Property(r => r.HomeKitDeviceId)
.HasMaxLength(50)
.IsUnicode(false);
builder.Property(r => r.HomeKitModel)
.HasMaxLength(200)
.IsUnicode(false);
// ── Status ──────────────────────────────────────────────────
builder.Property(r => r.ProbedAt)
.HasDefaultValueSql("NOW()");
// ── Indexes ─────────────────────────────────────────────────
builder.HasIndex(r => r.SiteId);
builder.HasIndex(r => r.IpAddress);
builder.HasIndex(r => r.IsProcessed);
// ── Relationships ───────────────────────────────────────────
builder.HasOne(r => r.Site)
.WithMany()
.HasForeignKey(r => r.SiteId)
.OnDelete(DeleteBehavior.Cascade);
builder.HasMany(r => r.DiscoveredStreams)
.WithOne(ds => ds.DiscoveryResult)
.HasForeignKey(ds => ds.DiscoveryResultId)
.OnDelete(DeleteBehavior.Cascade);
}
}
@@ -0,0 +1,40 @@
using Heimdall.Domain.Entities;
using Heimdall.Domain.Enums;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Heimdall.Infrastructure.Data.Configurations;
public class DiscoveredStreamConfiguration : IEntityTypeConfiguration<DiscoveredStreamUrl>
{
public void Configure(EntityTypeBuilder<DiscoveredStreamUrl> builder)
{
builder.ToTable("discovered_streams");
builder.HasKey(ds => ds.Id);
builder.Property(ds => ds.Url)
.HasMaxLength(2000)
.IsRequired()
.IsUnicode(false);
builder.Property(ds => ds.Protocol)
.HasConversion<string>()
.HasMaxLength(20)
.IsRequired()
.IsUnicode(false);
builder.Property(ds => ds.Codecs)
.HasColumnType("text[]")
.IsUnicode(false);
builder.Property(ds => ds.Width);
builder.Property(ds => ds.Height);
builder.Property(ds => ds.LatencyMs);
// Indexes
builder.HasIndex(ds => ds.DiscoveryResultId);
builder.HasIndex(ds => ds.IsAlive);
builder.HasIndex(ds => ds.IsMainStream);
}
}