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

@@ -14,6 +14,7 @@ public record UpdateCameraRequest(
string? RtspUrl,
CameraStatus? Status);
/// <summary>Camera response including all discovery and stream test metadata.</summary>
public record CameraResponse(
Guid Id,
Guid SiteId,
@@ -22,7 +23,22 @@ public record CameraResponse(
string? Manufacturer,
string? Model,
string? RtspUrl,
string? SubRtspUrl,
CameraStatus Status,
CameraDiscoveryMethod DiscoveryMethod,
DetectedCameraType DetectedType,
CameraCapability Capabilities,
string? IpAddress,
string? MacAddress,
int? RtspPort,
int? HttpPort,
int? OnvifPort,
string? LastTestedCodecs,
int? LastTestedWidth,
int? LastTestedHeight,
long? LastTestedLatencyMs,
DateTime? LastDiscoveredAt,
DateTime? LastStreamTestAt,
bool HasPtz,
bool HasAudio,
bool HasMotionDetection,
@@ -0,0 +1,140 @@
using Heimdall.Domain.Enums;
namespace Heimdall.Application.DTOs;
// ────────────────────────────────────────────────────────────────────
// Probe Requests
// ────────────────────────────────────────────────────────────────────
/// <summary>Probe a single IP address for camera services.</summary>
public record ProbeRequest(Guid SiteId, string Ip);
/// <summary>Scan an entire subnet for cameras.</summary>
public record ScanRequest(Guid SiteId, string SubnetCidr, int TimeoutMs = 30000);
// ────────────────────────────────────────────────────────────────────
// Probe Responses
// ────────────────────────────────────────────────────────────────────
/// <summary>Full probe result for a single IP, combining all detection methods.</summary>
public record ProbeResponse(
string Ip,
bool IsReachable,
DetectedCameraType CameraType,
CameraDiscoveryMethod DiscoveryMethod,
ArpInfo? Arp,
int[] OpenPorts,
OnvifProbeInfo? Onvif,
HttpProbeInfo? Http,
HomeKitProbeInfo? HomeKit,
string[]? MatchedBrands);
/// <summary>ARP table lookup result.</summary>
public record ArpInfo(string MacAddress, string? Vendor);
/// <summary>ONVIF WS-Discovery probe result.</summary>
public record OnvifProbeInfo(
string DeviceServiceUrl,
int Port,
string? Name,
string? Hardware,
string? Location);
/// <summary>HTTP probe result (server header analysis).</summary>
public record HttpProbeInfo(int Port, int StatusCode, string? ServerHeader);
/// <summary>HomeKit / mDNS probe result.</summary>
public record HomeKitProbeInfo(
string Name,
string DeviceId,
string Model,
string Category,
bool IsPaired,
int Port);
// ────────────────────────────────────────────────────────────────────
// Scan Progress
// ────────────────────────────────────────────────────────────────────
/// <summary>Progress update emitted during a subnet scan.</summary>
public record ScanProgress(
int TotalHosts,
int Scanned,
int Discovered,
string? CurrentIp);
// ────────────────────────────────────────────────────────────────────
// Camera Database Search
// ────────────────────────────────────────────────────────────────────
/// <summary>Result from the camera database (preset, brand, or model).</summary>
public record CameraDbEntry(
string Type, // "preset" | "brand" | "model"
string Id, // "p:{id}" | "b:{id}" | "m:{brand}:{model}"
string Name);
/// <summary>Search response.</summary>
public record SearchResponse(CameraDbEntry[] Results);
/// <summary>Build stream URLs from database entries.</summary>
public record StreamBuildRequest(
string[] Ids, // e.g. ["b:hikvision", "p:onvif"]
string Ip,
string? Username,
string? Password,
int Channel = 0,
int[]? PortFilter = null);
/// <summary>Stream build response.</summary>
public record StreamBuildResponse(string[] Streams);
// ────────────────────────────────────────────────────────────────────
// Stream Testing
// ────────────────────────────────────────────────────────────────────
/// <summary>Request to test a set of stream URLs.</summary>
public record StreamTestRequest(string SourceId, string[] Streams);
/// <summary>A tested stream result.</summary>
public record StreamTestResult(
string SourceUrl,
string[] Codecs,
int Width,
int Height,
long LatencyMs,
string? ScreenshotUrl,
bool IsAlive);
/// <summary>The session state for stream testing (polled).</summary>
public record StreamTestSession(
Guid SessionId,
string Status, // "running" | "done"
int Total,
int Tested,
int Alive,
StreamTestResult[] Results);
// ────────────────────────────────────────────────────────────────────
// Confirm Discovery
// ────────────────────────────────────────────────────────────────────
/// <summary>Confirm a discovery result and create a Camera entity.</summary>
public record ConfirmDiscoveryRequest(
Guid SiteId,
string Name,
Guid DiscoveryResultId,
string MainStreamUrl,
string? SubStreamUrl,
string? Username,
string? Password,
CameraDetectionProfileRequest? DetectionProfile);
/// <summary>Inline detection profile during camera creation.</summary>
public record CameraDetectionProfileRequest(
bool DetectPerson = true,
bool DetectVehicle = true,
bool DetectAnimal = false,
bool DetectPackage = false,
bool DetectMotion = true,
bool FaceRecognition = true,
bool LicensePlateRecognition = true);
@@ -0,0 +1,75 @@
using Heimdall.Application.Common;
using Heimdall.Application.DTOs;
namespace Heimdall.Application.Services;
/// <summary>
/// Camera discovery service — probes network devices, searches the camera
/// database, builds and tests stream URLs, and creates Camera entities.
/// Inspired by Strix (github.com/eduard256/Strix).
/// </summary>
public interface ICameraDiscoveryService
{
/// <summary>
/// Probe a single IP address using all available methods in parallel
/// (ONVIF WS-Discovery, HTTP, mDNS, ARP, port scan). Returns within ~100ms.
/// </summary>
Task<ServiceResult<ProbeResponse>> ProbeIpAsync(
ProbeRequest request, CancellationToken ct);
/// <summary>
/// Scan an entire subnet for camera devices. Runs port scans in parallel
/// with 20+ workers. Reports progress via IProgress{ScanProgress}.
/// </summary>
Task<ServiceResult<IReadOnlyList<ProbeResponse>>> ScanSubnetAsync(
ScanRequest request, CancellationToken ct,
IProgress<ScanProgress>? progress = null);
/// <summary>
/// Search the built-in camera database (StrixCamDB) by brand, model, or preset.
/// Supports multi-word queries (each word matches independently).
/// </summary>
Task<ServiceResult<SearchResponse>> SearchDatabaseAsync(
string query, CancellationToken ct);
/// <summary>
/// Build full stream URLs from camera database entries, substituting
/// placeholders ([CHANNEL], [USERNAME], [IP], etc.) with actual values.
/// </summary>
Task<ServiceResult<StreamBuildResponse>> BuildStreamUrlsAsync(
StreamBuildRequest request, CancellationToken ct);
/// <summary>
/// Test stream URLs in parallel (20 workers) — connects to each,
/// extracts codecs, resolution, latency, and captures a screenshot.
/// Returns a session ID for polling.
/// </summary>
Task<ServiceResult<StreamTestSession>> TestStreamsAsync(
StreamTestRequest request, CancellationToken ct);
/// <summary>
/// Poll a stream test session for updated results.
/// </summary>
Task<ServiceResult<StreamTestSession>> GetTestSessionAsync(
Guid sessionId, CancellationToken ct);
/// <summary>
/// Get a screenshot from a stream test session.
/// </summary>
Task<byte[]?> GetScreenshotAsync(
Guid sessionId, int index, CancellationToken ct);
/// <summary>
/// Cancel a running stream test session.
/// </summary>
Task<ServiceResult> CancelTestSessionAsync(
Guid sessionId, CancellationToken ct);
/// <summary>
/// Confirm a discovery result — creates a Camera entity with all
/// discovered metadata, credentials (encrypted), and an optional
/// detection profile.
/// </summary>
Task<ServiceResult<CameraResponse>> ConfirmDiscoveryAsync(
ConfirmDiscoveryRequest request, CancellationToken ct);
}
+103 -4
View File
@@ -5,6 +5,7 @@ namespace Heimdall.Domain.Entities;
public class Camera : Entity<Guid>, IAuditableEntity, ISoftDeletable
{
// ── Core ────────────────────────────────────────────────────────
public Guid SiteId { get; private set; }
public Guid? AgentId { get; private set; }
public string Name { get; private set; } = string.Empty;
@@ -13,12 +14,51 @@ public class Camera : Entity<Guid>, IAuditableEntity, ISoftDeletable
public string? RtspUrl { get; private set; }
public CameraStatus Status { get; private set; } = CameraStatus.Disabled;
// Capabilities
// ── Discovery ───────────────────────────────────────────────────
/// <summary>How this camera was discovered (manual, ONVIF, mDNS, etc.).</summary>
public CameraDiscoveryMethod DiscoveryMethod { get; private set; } = CameraDiscoveryMethod.Manual;
/// <summary>High-level classification from the probe phase.</summary>
public DetectedCameraType DetectedType { get; private set; } = DetectedCameraType.Standard;
// Network
public string? IpAddress { get; private set; }
public string? MacAddress { get; private set; }
// Ports detected during probe
public int? RtspPort { get; private set; }
public int? HttpPort { get; private set; }
public int? OnvifPort { get; private set; }
// Capabilities flags (bitmask)
public CameraCapability Capabilities { get; private set; } = CameraCapability.None;
/// <summary>Timestamp of the last successful discovery probe.</summary>
public DateTime? LastDiscoveredAt { get; private set; }
// ── Stream test results ─────────────────────────────────────────
/// <summary>Secondary / sub-stream URL (lower resolution for AI detection).</summary>
public string? SubRtspUrl { get; private set; }
/// <summary>Last stream test results (JSON array of codecs).</summary>
public string? LastTestedCodecs { get; private set; }
/// <summary>Resolution of the last successful stream test.</summary>
public int? LastTestedWidth { get; private set; }
public int? LastTestedHeight { get; private set; }
/// <summary>Connection latency in ms (last test).</summary>
public long? LastTestedLatencyMs { get; private set; }
/// <summary>Timestamp of the last stream test.</summary>
public DateTime? LastStreamTestAt { get; private set; }
// ── Legacy capabilities (kept for backward compat) ──────────────
public bool HasPtz { get; private set; }
public bool HasAudio { get; private set; }
public bool HasMotionDetection { get; private set; }
// Audit
// ── Audit ───────────────────────────────────────────────────────
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }
@@ -26,7 +66,7 @@ public class Camera : Entity<Guid>, IAuditableEntity, ISoftDeletable
public bool IsDeleted { get; private set; }
public DateTime? DeletedAt { get; private set; }
// Navigation
// ── Navigation ──────────────────────────────────────────────────
public Site Site { get; private set; } = null!;
public Agent? Agent { get; private set; }
public CameraCredentials? Credentials { get; private set; }
@@ -34,7 +74,12 @@ public class Camera : Entity<Guid>, IAuditableEntity, ISoftDeletable
private Camera() { } // EF Core
public Camera(Guid siteId, string name, string? rtspUrl = null, string? manufacturer = null, string? model = null)
public Camera(
Guid siteId,
string name,
string? rtspUrl = null,
string? manufacturer = null,
string? model = null)
: base(Guid.NewGuid())
{
SiteId = siteId;
@@ -44,6 +89,8 @@ public class Camera : Entity<Guid>, IAuditableEntity, ISoftDeletable
Model = model;
}
// ── Behaviour ───────────────────────────────────────────────────
public void AssignAgent(Guid agentId) => AgentId = agentId;
public void Update(string name, string? manufacturer, string? model, string? rtspUrl)
@@ -67,6 +114,58 @@ public class Camera : Entity<Guid>, IAuditableEntity, ISoftDeletable
public void SetDetectionProfile(CameraDetectionProfile profile) => DetectionProfile = profile;
/// <summary>
/// Populates discovery-related fields after a successful probe.
/// </summary>
public void SetDiscoveryInfo(
CameraDiscoveryMethod method,
DetectedCameraType type,
string? macAddress,
string ipAddress)
{
DiscoveryMethod = method;
DetectedType = type;
MacAddress = macAddress;
IpAddress = ipAddress;
LastDiscoveredAt = DateTime.UtcNow;
}
/// <summary>
/// Updates known ports from probe results.
/// </summary>
public void SetPorts(int? rtspPort, int? httpPort, int? onvifPort)
{
RtspPort = rtspPort;
HttpPort = httpPort;
OnvifPort = onvifPort;
}
/// <summary>
/// Updates capability bitmask from all probe data.
/// </summary>
public void SetCapabilityFlags(CameraCapability capabilities)
{
Capabilities = capabilities;
}
/// <summary>
/// Records the result of a stream validation test.
/// </summary>
public void SetStreamTestResult(
string? subRtspUrl,
string codecsJson,
int width,
int height,
long latencyMs)
{
SubRtspUrl = subRtspUrl;
LastTestedCodecs = codecsJson;
LastTestedWidth = width;
LastTestedHeight = height;
LastTestedLatencyMs = latencyMs;
LastStreamTestAt = DateTime.UtcNow;
}
public void SoftDelete()
{
IsDeleted = true;
@@ -0,0 +1,120 @@
using Heimdall.Domain.Enums;
using Heimdall.Domain.Primitives;
namespace Heimdall.Domain.Entities;
/// <summary>
/// Transient entity representing the outcome of probing a single IP address
/// during the camera discovery pipeline. Retained temporarily for the
/// discovery workflow (probe → search → test → confirm).
/// </summary>
public class CameraDiscoveryResult : Entity<Guid>
{
// ── Identification ──────────────────────────────────────────────
public Guid SiteId { get; private set; }
public Site Site { get; private set; } = null!;
/// <summary>Probed IP address.</summary>
public string IpAddress { get; private set; } = string.Empty;
/// <summary>MAC address from ARP table lookup.</summary>
public string? MacAddress { get; private set; }
/// <summary>Vendor/manufacturer name resolved from OUI.</summary>
public string? Vendor { get; private set; }
/// <summary>Reverse DNS hostname (if resolvable).</summary>
public string? Hostname { get; private set; }
// ── Classification ──────────────────────────────────────────────
/// <summary>Device is reachable on the network.</summary>
public bool IsReachable { get; private set; }
/// <summary>Detected camera type (standard / homekit / nvr / doorbell).</summary>
public DetectedCameraType DetectedType { get; private set; } = DetectedCameraType.Unknown;
/// <summary>Primary discovery method that identified this device.</summary>
public CameraDiscoveryMethod DiscoveryMethod { get; private set; }
// ── Probe results ───────────────────────────────────────────────
/// <summary>Open ports discovered during port scan.</summary>
public int[] OpenPorts { get; private set; } = [];
// ONVIF
public string? OnvifDeviceServiceUrl { get; private set; }
public string? OnvifName { get; private set; }
public string? OnvifHardware { get; private set; }
public int? OnvifPort { get; private set; }
// HTTP
public string? HttpServerHeader { get; private set; }
public int? HttpStatusCode { get; private set; }
public int? HttpPort { get; private set; }
// HomeKit
public bool? IsHomeKitCamera { get; private set; }
public string? HomeKitName { get; private set; }
public string? HomeKitDeviceId { get; private set; }
public string? HomeKitModel { get; private set; }
// ── Status ──────────────────────────────────────────────────────
/// <summary>When this probe was performed.</summary>
public DateTime ProbedAt { get; private set; } = DateTime.UtcNow;
/// <summary>True when this result has been processed (confirmed or rejected).</summary>
public bool IsProcessed { get; private set; }
// ── Navigation ──────────────────────────────────────────────────
public ICollection<DiscoveredStreamUrl> DiscoveredStreams { get; private set; } = [];
private CameraDiscoveryResult() { } // EF Core
public CameraDiscoveryResult(Guid siteId, string ipAddress)
: base(Guid.NewGuid())
{
SiteId = siteId;
IpAddress = ipAddress;
}
// ── Behaviour ───────────────────────────────────────────────────
public void MarkReachable(DetectedCameraType type, CameraDiscoveryMethod method)
{
IsReachable = true;
DetectedType = type;
DiscoveryMethod = method;
}
public void SetOpenPorts(int[] ports) => OpenPorts = ports;
public void SetOnvifResult(string deviceServiceUrl, string? name, string? hardware, int port)
{
OnvifDeviceServiceUrl = deviceServiceUrl;
OnvifName = name;
OnvifHardware = hardware;
OnvifPort = port;
}
public void SetHttpResult(int port, int statusCode, string? serverHeader)
{
HttpPort = port;
HttpStatusCode = statusCode;
HttpServerHeader = serverHeader;
}
public void SetHomeKitResult(string name, string deviceId, string model)
{
IsHomeKitCamera = true;
HomeKitName = name;
HomeKitDeviceId = deviceId;
HomeKitModel = model;
}
public void SetArpInfo(string mac, string? vendor)
{
MacAddress = mac;
Vendor = vendor;
}
public void MarkProcessed() => IsProcessed = true;
}
@@ -0,0 +1,63 @@
using Heimdall.Domain.Enums;
namespace Heimdall.Domain.Entities;
/// <summary>
/// A single stream URL that was tested during the discovery pipeline.
/// Contains the test result (codecs, resolution, latency, screenshot).
/// </summary>
public class DiscoveredStreamUrl
{
public Guid Id { get; private set; }
public Guid DiscoveryResultId { get; private set; }
/// <summary>The full stream URL (credentials may be included).</summary>
public string Url { get; private set; } = string.Empty;
/// <summary>Protocol scheme (rtsp, http, rtmp, dvrip, etc.).</summary>
public StreamProtocol Protocol { get; private set; }
/// <summary>Detected codec names (e.g. ["H264", "PCMA"]).</summary>
public string[] Codecs { get; private set; } = [];
/// <summary>Stream resolution.</summary>
public int Width { get; private set; }
public int Height { get; private set; }
/// <summary>Connection latency in milliseconds.</summary>
public long LatencyMs { get; private set; }
/// <summary>True if the stream is the main (highest-resolution) stream.</summary>
public bool IsMainStream { get; private set; }
/// <summary>True if the stream responded successfully.</summary>
public bool IsAlive { get; private set; }
// Navigation
public CameraDiscoveryResult DiscoveryResult { get; private set; } = null!;
private DiscoveredStreamUrl() { } // EF Core
public DiscoveredStreamUrl(
Guid discoveryResultId,
string url,
StreamProtocol protocol,
string[] codecs,
int width,
int height,
long latencyMs,
bool isMainStream,
bool isAlive)
{
Id = Guid.NewGuid();
DiscoveryResultId = discoveryResultId;
Url = url;
Protocol = protocol;
Codecs = codecs;
Width = width;
Height = height;
LatencyMs = latencyMs;
IsMainStream = isMainStream;
IsAlive = isAlive;
}
}
@@ -0,0 +1,44 @@
namespace Heimdall.Domain.Enums;
/// <summary>
/// Flags enum describing camera capabilities detected during discovery.
/// Stored as a bitmask in the database.
/// </summary>
[Flags]
public enum CameraCapability
{
None = 0,
/// <summary>RTSP streaming (H264/H265).</summary>
RtspStreaming = 1 << 0,
/// <summary>MJPEG stream over HTTP.</summary>
HttpMjpeg = 1 << 1,
/// <summary>Single JPEG snapshot over HTTP.</summary>
HttpSnapshot = 1 << 2,
/// <summary>ONVIF protocol support (WS-Discovery responded).</summary>
Onvif = 1 << 3,
/// <summary>PTZ control available via ONVIF.</summary>
OnvifPtz = 1 << 4,
/// <summary>Audio input (microphone) available.</summary>
OnvifAudioIn = 1 << 5,
/// <summary>Audio output (speaker) available.</summary>
OnvifAudioOut = 1 << 6,
/// <summary>Apple HomeKit (HAP) support.</summary>
HomeKit = 1 << 7,
/// <summary>Dahua DVRIP / Sofia protocol.</summary>
Dvrip = 1 << 8,
/// <summary>RTMP streaming.</summary>
Rtmp = 1 << 9,
/// <summary>Camera provides a sub-stream (secondary, lower-res stream).</summary>
SubStream = 1 << 10
}
@@ -0,0 +1,28 @@
namespace Heimdall.Domain.Enums;
/// <summary>
/// Method by which a camera was discovered on the network.
/// </summary>
public enum CameraDiscoveryMethod
{
/// <summary>Manually configured by the user (existing flow).</summary>
Manual = 0,
/// <summary>Discovered via ONVIF WS-Discovery (UDP probe on port 3702).</summary>
OnvifWsDiscovery = 1,
/// <summary>Discovered via mDNS / HomeKit Accessory Protocol (_hap._tcp).</summary>
MdnsHomeKit = 2,
/// <summary>Generic network scan (port scan + ping).</summary>
NetworkScan = 3,
/// <summary>Detected via HTTP server header analysis.</summary>
HttpProbe = 4,
/// <summary>Discovered via ARP table lookup + OUI vendor resolution.</summary>
ArpProbe = 5,
/// <summary>Imported from external file or bulk operation.</summary>
Imported = 6
}
@@ -0,0 +1,23 @@
namespace Heimdall.Domain.Enums;
/// <summary>
/// High-level classification of a detected camera's type.
/// Determined during the probe phase based on protocol signatures.
/// </summary>
public enum DetectedCameraType
{
/// <summary>Standard IP camera (RTSP + HTTP).</summary>
Standard = 0,
/// <summary>Apple HomeKit camera / doorbell (HAP over mDNS).</summary>
HomeKit = 1,
/// <summary>NVR / DVR with multiple channels (DVRIP / Sofia protocol).</summary>
Nvr = 2,
/// <summary>Video doorbell (HomeKit or proprietary).</summary>
Doorbell = 3,
/// <summary>Device is reachable but camera type could not be determined.</summary>
Unknown = 4
}
@@ -0,0 +1,18 @@
namespace Heimdall.Domain.Enums;
/// <summary>
/// Streaming protocols supported by the discovery and test pipeline.
/// Maps directly to the protocol handlers in StreamTesterService.
/// </summary>
public enum StreamProtocol
{
Rtsp,
Rtsps,
Http,
Https,
Rtmp,
Rtmps,
Dvrip,
Bubble,
HomeKit
}
@@ -23,6 +23,10 @@ public class AppDbContext : IdentityDbContext<AppUser, AppRole, Guid>
public DbSet<AppSetting> AppSettings => Set<AppSetting>();
public DbSet<AgentSetting> AgentSettings => Set<AgentSetting>();
// Discovery entities
public DbSet<CameraDiscoveryResult> CameraDiscoveryResults => Set<CameraDiscoveryResult>();
public DbSet<DiscoveredStreamUrl> DiscoveredStreams => Set<DiscoveredStreamUrl>();
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
@@ -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);
}
}
@@ -107,5 +107,10 @@ public class CameraService : ICameraService
private static CameraResponse MapResponse(Camera c) => new(
c.Id, c.SiteId, c.AgentId, c.Name, c.Manufacturer, c.Model,
c.RtspUrl, c.Status, c.HasPtz, c.HasAudio, c.HasMotionDetection, c.CreatedAt);
c.RtspUrl, c.SubRtspUrl,
c.Status, c.DiscoveryMethod, c.DetectedType, c.Capabilities,
c.IpAddress, c.MacAddress, c.RtspPort, c.HttpPort, c.OnvifPort,
c.LastTestedCodecs, c.LastTestedWidth, c.LastTestedHeight, c.LastTestedLatencyMs,
c.LastDiscoveredAt, c.LastStreamTestAt,
c.HasPtz, c.HasAudio, c.HasMotionDetection, c.CreatedAt);
}