Files
Heimdall/src/Heimdall.Application/Services/ICameraDiscoveryService.cs
T

111 lines
4.4 KiB
C#

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);
/// <summary>
/// Check if a camera with the same IP or MAC already exists for this site.
/// Use this before ConfirmDiscoveryAsync to avoid duplicate cameras.
/// </summary>
Task<ServiceResult<CameraCheckResponse>> CheckDuplicateAsync(
CheckDuplicateRequest request, CancellationToken ct);
/// <summary>
/// Receive a batch of devices probed by an agent's network scan. Persists
/// them as CameraDiscoveryResult (upsert by site+IP for unprocessed results),
/// then enriches each candidate: authenticated ONVIF GetDeviceInformation
/// using the site's declared credential pool, and candidate stream URL
/// building from the built-in camera database.
/// </summary>
Task<ServiceResult<AgentDiscoverySubmitResponse>> SubmitAgentDiscoveriesAsync(
Guid agentId, IReadOnlyList<AgentDiscoveredDevice> devices, CancellationToken ct);
/// <summary>
/// List pending (unprocessed) discovery results for a site, newest first.
/// </summary>
Task<ServiceResult<IReadOnlyList<PendingDiscoveryResponse>>> ListPendingDiscoveriesAsync(
Guid siteId, CancellationToken ct);
/// <summary>
/// Mark a discovery result as rejected (ignored) so it no longer appears
/// in the pending list. Does not delete the row.
/// </summary>
Task<ServiceResult> RejectDiscoveryAsync(Guid resultId, CancellationToken ct);
/// <summary>
/// Get the in-memory screenshot (agent-captured JPEG) for a discovery
/// result. Returns null when absent or expired (TTL 10 min).
/// </summary>
byte[]? GetDiscoveryScreenshot(Guid resultId);
}