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:
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);
|
||||
}
|
||||
Reference in new issue
Block a user