oximedia_transcode/hw_accel/probe.rs
1//! Hardware probe trait and implementation stubs.
2//!
3//! [`HwProbe`] is a `Send + Sync` trait that abstracts platform detection.
4//! [`SystemProbe`] dispatches to the OS-specific implementation at compile
5//! time. [`MockProbe`] is for use in unit tests.
6
7use super::capabilities::HwAccelCapabilities;
8
9// ─── HwProbe trait ───────────────────────────────────────────────────────────
10
11/// Abstraction over hardware acceleration probing.
12///
13/// Implement this trait (or use [`MockProbe`]) to supply capability data
14/// without touching OS APIs — useful for unit tests and deterministic CI.
15pub trait HwProbe: Send + Sync {
16 /// Probe the system and return discovered capabilities.
17 fn probe(&self) -> HwAccelCapabilities;
18}
19
20// ─── SystemProbe ─────────────────────────────────────────────────────────────
21
22/// Real system probe — dispatches to OS-specific code at compile time.
23///
24/// On macOS: parses `sysctl` output to identify the Apple Silicon/Intel
25/// chip family, then returns a static codec table.
26///
27/// On Linux: walks `/sys/class/drm/` to find DRM devices, resolves vendor
28/// IDs to driver families, and maps those to supported codecs.
29///
30/// On Windows / WASM / other: returns [`HwAccelCapabilities::none()`].
31pub struct SystemProbe;
32
33// ─── MockProbe ───────────────────────────────────────────────────────────────
34
35/// A test double that returns a pre-built capability set.
36///
37/// ```
38/// use oximedia_transcode::{HwAccelCapabilities, MockProbe, HwProbe};
39///
40/// let probe = MockProbe(HwAccelCapabilities::none());
41/// assert!(probe.probe().is_empty());
42/// ```
43pub struct MockProbe(pub HwAccelCapabilities);
44
45impl HwProbe for MockProbe {
46 fn probe(&self) -> HwAccelCapabilities {
47 self.0.clone()
48 }
49}
50
51// ─── Platform dispatch ────────────────────────────────────────────────────────
52
53#[cfg(target_os = "macos")]
54impl HwProbe for SystemProbe {
55 fn probe(&self) -> HwAccelCapabilities {
56 crate::hw_accel::macos::probe_macos()
57 }
58}
59
60#[cfg(target_os = "linux")]
61impl HwProbe for SystemProbe {
62 fn probe(&self) -> HwAccelCapabilities {
63 crate::hw_accel::linux::probe_linux()
64 }
65}
66
67#[cfg(target_os = "windows")]
68impl HwProbe for SystemProbe {
69 fn probe(&self) -> HwAccelCapabilities {
70 tracing::warn!(
71 "HW accel detection not yet implemented on Windows; \
72 returning empty capabilities"
73 );
74 HwAccelCapabilities::none()
75 }
76}
77
78#[cfg(target_arch = "wasm32")]
79impl HwProbe for SystemProbe {
80 fn probe(&self) -> HwAccelCapabilities {
81 HwAccelCapabilities::none()
82 }
83}
84
85#[cfg(not(any(
86 target_os = "macos",
87 target_os = "linux",
88 target_os = "windows",
89 target_arch = "wasm32"
90)))]
91impl HwProbe for SystemProbe {
92 fn probe(&self) -> HwAccelCapabilities {
93 HwAccelCapabilities::none()
94 }
95}