Skip to main content

sew_call_client/video/
codec_pref.rs

1//! The video codec preference and the receive codec set.
2//!
3//! **The preference** ([`VideoCodecPreference`]) is a per-device user setting: which codec a
4//! camera or screen of this device publishes in. [`effective_publish_codec`] turns it and the
5//! run-time H.264 detection ([`H264Detection`]) into the codec the publish side uses, with the
6//! reason when "Prefer H.264" can't apply ([`CodecPreferenceReason`]). H.264 is only ever the
7//! OS's own encoder, found at run time (`h264_encode_detection`, with `video-core`); nothing
8//! assumes it from the platform, and nothing here ships or loads an H.264 codec.
9//!
10//! The engine keeps the setting ([`crate::CallClient::set_video_codec_preference`]) for every
11//! call it makes, until the process ends. **Persisting it is the host's job**: read it back with
12//! [`crate::CallClient::video_codec_preference`], store it with the app's settings, and set it
13//! again at start.
14//!
15//! **The receive codec set** is what this device's media connection offers to receive:
16//! VP8 always (kessel-video's pure-Rust decoder exists everywhere), and H.264 only when the
17//! host declared it can decode it ([`crate::CallClient::set_video_decode`]: the OS decoders its
18//! kessel-video backend lists and its webview's WebCodecs probe), never on Linux, and never
19//! under [`VideoCodecPreference::PreferVp8`].
20
21use std::sync::Mutex;
22
23use serde::{Deserialize, Serialize};
24
25use super::types::VideoCodec;
26
27/// Which codec this device's camera and screen publish in. A per-device user setting; the
28/// default is [`VideoCodecPreference::Automatic`].
29///
30/// Its JSON is `"automatic"`, `"prefer_h264"` or `"prefer_vp8"`.
31#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
32#[serde(rename_all = "snake_case")]
33#[non_exhaustive]
34pub enum VideoCodecPreference {
35    /// H.264 where this device's OS has a usable hardware H.264 encoder (found at run time),
36    /// else VP8. An H.264 publication always carries a VP8 backup for subscribers that can't
37    /// decode H.264.
38    #[default]
39    Automatic,
40    /// H.264 when the run-time detection passes, as `Automatic`; otherwise VP8, and the
41    /// readback says why ([`CodecPreferenceReason`]).
42    PreferH264,
43    /// VP8 always. This device also stops offering to receive H.264 (from its next join), so
44    /// every sender reaches it in VP8.
45    PreferVp8,
46}
47
48impl VideoCodecPreference {
49    /// The setting's name: `automatic`, `prefer_h264` or `prefer_vp8`.
50    pub fn as_str(self) -> &'static str {
51        match self {
52            VideoCodecPreference::Automatic => "automatic",
53            VideoCodecPreference::PreferH264 => "prefer_h264",
54            VideoCodecPreference::PreferVp8 => "prefer_vp8",
55        }
56    }
57
58    /// The setting of a name [`VideoCodecPreference::as_str`] gives; `None` for any other.
59    pub fn from_name(name: &str) -> Option<VideoCodecPreference> {
60        match name {
61            "automatic" => Some(VideoCodecPreference::Automatic),
62            "prefer_h264" => Some(VideoCodecPreference::PreferH264),
63            "prefer_vp8" => Some(VideoCodecPreference::PreferVp8),
64            _ => None,
65        }
66    }
67}
68
69/// What the run-time check of this device's OS H.264 encoder found.
70///
71/// "Usable" means a hardware encoder: the backend's capabilities list an H.264 **encode** entry
72/// run by hardware, the encoder opens with hardware only, and the opened session says it runs in
73/// hardware. `h264_encode_detection` (with `video-core`) does the first check; the publish side
74/// does the other two when the camera or screen turns on (`H264Detection::from_session`, with
75/// `video-core`).
76#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
77#[serde(rename_all = "snake_case")]
78#[non_exhaustive]
79pub enum H264Detection {
80    /// A hardware H.264 encoder is there (or opened and runs in hardware).
81    Usable,
82    /// The check ran and found no usable one: none listed, only a software one, or the
83    /// hardware-only open failed.
84    NotDetected,
85    /// An encoder may be there, but the OS can't confirm it runs in hardware (an iOS before
86    /// 17.4). Never treated as usable.
87    Unconfirmed,
88    /// This platform has no run-time check (yet): Linux (no OS H.264), Android and Windows
89    /// (their backends would list an encoder without probing it). Never treated as usable.
90    NoPlatformCheck,
91}
92
93impl H264Detection {
94    /// Whether H.264 may be published.
95    pub fn is_usable(self) -> bool {
96        self == H264Detection::Usable
97    }
98}
99
100/// Why "Prefer H.264" could not apply, so the device publishes VP8.
101///
102/// Its JSON is `"not_detected"`, `"platform"` or `"policy"`.
103#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
104#[serde(rename_all = "snake_case")]
105#[non_exhaustive]
106pub enum CodecPreferenceReason {
107    /// The run-time check found no usable hardware H.264 encoder
108    /// ([`H264Detection::NotDetected`]).
109    NotDetected,
110    /// This platform can't publish H.264 here: no run-time check on Linux, Android or Windows
111    /// yet ([`H264Detection::NoPlatformCheck`]), or an iOS before 17.4, which can't confirm a
112    /// hardware encoder ([`H264Detection::Unconfirmed`]).
113    Platform,
114    /// The call's media policy (the room's or the install's codecs) doesn't allow H.264
115    /// ([`effective_publish_codec_under_policy`]).
116    Policy,
117}
118
119impl CodecPreferenceReason {
120    /// The reason's name: `not_detected`, `platform` or `policy`.
121    pub fn as_str(self) -> &'static str {
122        match self {
123            CodecPreferenceReason::NotDetected => "not_detected",
124            CodecPreferenceReason::Platform => "platform",
125            CodecPreferenceReason::Policy => "policy",
126        }
127    }
128}
129
130/// The codec a camera or screen of this device publishes in under `pref`, given what the H.264
131/// detection found, and why "Prefer H.264" didn't apply when it didn't.
132///
133/// | `pref` | `detected` | result |
134/// |---|---|---|
135/// | `PreferVp8` | any | `(Vp8, None)` |
136/// | `Automatic` | `Usable` | `(H264, None)` |
137/// | `Automatic` | otherwise | `(Vp8, None)` |
138/// | `PreferH264` | `Usable` | `(H264, None)` |
139/// | `PreferH264` | `NotDetected` | `(Vp8, Some(NotDetected))` |
140/// | `PreferH264` | `Unconfirmed`, `NoPlatformCheck` | `(Vp8, Some(Platform))` |
141///
142/// `H264` means H.264 as the primary codec; the publish side still adds the VP8 backup. This is
143/// the preference and the device only; in a call, use
144/// [`effective_publish_codec_under_policy`], which also applies the media policy.
145pub fn effective_publish_codec(
146    pref: VideoCodecPreference,
147    detected: H264Detection,
148) -> (VideoCodec, Option<CodecPreferenceReason>) {
149    match (pref, detected) {
150        (VideoCodecPreference::PreferVp8, _) => (VideoCodec::Vp8, None),
151        (_, H264Detection::Usable) => (VideoCodec::H264, None),
152        (VideoCodecPreference::PreferH264, H264Detection::NotDetected) => {
153            (VideoCodec::Vp8, Some(CodecPreferenceReason::NotDetected))
154        }
155        (VideoCodecPreference::PreferH264, _) => {
156            (VideoCodec::Vp8, Some(CodecPreferenceReason::Platform))
157        }
158        _ => (VideoCodec::Vp8, None),
159    }
160}
161
162/// [`effective_publish_codec`] in a call whose media policy allows H.264 (`h264_allowed`) or
163/// not: without it, an `H264` turns into VP8, with [`CodecPreferenceReason::Policy`] under
164/// "Prefer H.264". The device's own reasons come first (a device that can't publish H.264 says
165/// so whatever the policy).
166pub fn effective_publish_codec_under_policy(
167    pref: VideoCodecPreference,
168    detected: H264Detection,
169    h264_allowed: bool,
170) -> (VideoCodec, Option<CodecPreferenceReason>) {
171    match effective_publish_codec(pref, detected) {
172        (VideoCodec::H264, _) if !h264_allowed => {
173            let reason =
174                (pref == VideoCodecPreference::PreferH264).then_some(CodecPreferenceReason::Policy);
175            (VideoCodec::Vp8, reason)
176        }
177        out => out,
178    }
179}
180
181/// The video backends with no run-time H.264 check yet: always
182/// [`H264Detection::NoPlatformCheck`]. Linux has no OS H.264; Android's and Windows' backends
183/// would list one without probing it.
184#[cfg(feature = "video-core")]
185const NO_H264_BACKENDS: [&str; 4] = ["linux", "android", "windows", "null"];
186
187/// The first of the three checks, from a kessel-video backend's capabilities: an H.264
188/// **encode** entry run by hardware. A software entry never counts. Linux, Android and Windows
189/// backends are always [`H264Detection::NoPlatformCheck`]. An iOS before 17.4 lists none, since
190/// it can't confirm hardware: [`H264Detection::Unconfirmed`].
191///
192/// A `Usable` here can still turn into `NotDetected` or `Unconfirmed` when the encoder opens
193/// (`H264Detection::from_session`, with `video-core`).
194#[cfg(feature = "video-core")]
195pub fn h264_encode_detection(caps: &kessel_video::Capabilities) -> H264Detection {
196    use kessel_video::{CodecDirection, Implementation};
197    if NO_H264_BACKENDS.contains(&caps.backend) {
198        return H264Detection::NoPlatformCheck;
199    }
200    let hardware = caps.codecs.iter().any(|c| {
201        c.codec == kessel_video::VideoCodec::H264
202            && c.direction == CodecDirection::Encode
203            && c.implementation == Implementation::Hardware
204    });
205    if hardware {
206        H264Detection::Usable
207    } else if ios_before_17_4(&caps.os) {
208        H264Detection::Unconfirmed
209    } else {
210        H264Detection::NotDetected
211    }
212}
213
214#[cfg(feature = "video-core")]
215impl H264Detection {
216    /// The last two checks, from an H.264 encoder opened with hardware only: what the session
217    /// says runs it. Hardware is `Usable`; software is `NotDetected`; an OS that doesn't say
218    /// (an iOS before 17.4) is `Unconfirmed`. A failed hardware-only open is `NotDetected`.
219    pub fn from_session(implementation: kessel_video::Implementation) -> H264Detection {
220        match implementation {
221            kessel_video::Implementation::Hardware => H264Detection::Usable,
222            kessel_video::Implementation::Software => H264Detection::NotDetected,
223            _ => H264Detection::Unconfirmed,
224        }
225    }
226}
227
228/// Whether `os` (kessel-video's `Capabilities::os`, e.g. `iOS Version 17.2 (Build 21C62)`) is
229/// an iOS before 17.4. Anything it can't read is `false`.
230#[cfg(feature = "video-core")]
231fn ios_before_17_4(os: &str) -> bool {
232    let Some(rest) = os.strip_prefix("iOS") else {
233        return false;
234    };
235    let Some(version) = rest
236        .split(|c: char| !(c.is_ascii_digit() || c == '.'))
237        .find(|t| t.contains(|c: char| c.is_ascii_digit()))
238    else {
239        return false;
240    };
241    let mut parts = version.split('.').map(|p| p.parse::<u32>().ok());
242    match (parts.next().flatten(), parts.next().flatten().unwrap_or(0)) {
243        (Some(major), minor) => (major, minor) < (17, 4),
244        _ => false,
245    }
246}
247
248/// The video codecs a media connection offers to receive: VP8 always, H.264 when `h264`.
249#[derive(Clone, Copy, Debug, PartialEq, Eq)]
250pub(crate) struct CodecSet {
251    h264: bool,
252}
253
254impl CodecSet {
255    /// VP8 only.
256    #[cfg_attr(not(test), allow(dead_code))]
257    pub(crate) const VP8_ONLY: CodecSet = CodecSet { h264: false };
258    /// VP8 and H.264.
259    #[cfg_attr(not(test), allow(dead_code))]
260    pub(crate) const ALL: CodecSet = CodecSet { h264: true };
261
262    /// Whether `codec` is in the set.
263    pub(crate) fn contains(self, codec: VideoCodec) -> bool {
264        match codec {
265            VideoCodec::Vp8 => true,
266            VideoCodec::H264 => self.h264,
267        }
268    }
269
270    /// The codecs, VP8 first.
271    pub(crate) fn codecs(self) -> Vec<VideoCodec> {
272        let mut v = vec![VideoCodec::Vp8];
273        if self.h264 {
274            v.push(VideoCodec::H264);
275        }
276        v
277    }
278
279    /// The set a call's media connection offers:
280    /// - VP8 always;
281    /// - H.264 only with `cfg_h264` ([`crate::ClientConfig::video_h264`]), and not under
282    ///   [`VideoCodecPreference::PreferVp8`], and, once the host declared what it decodes
283    ///   (`declared`), only if that lists H.264 and never on Linux.
284    ///
285    /// A host that never declared keeps `cfg_h264` alone (the behaviour before the
286    /// declaration existed).
287    pub(crate) fn negotiated(
288        cfg_h264: bool,
289        declared: Option<&[VideoCodec]>,
290        pref: VideoCodecPreference,
291    ) -> CodecSet {
292        let declared_ok = match declared {
293            None => true,
294            Some(d) => !cfg!(target_os = "linux") && d.contains(&VideoCodec::H264),
295        };
296        CodecSet {
297            h264: cfg_h264 && pref != VideoCodecPreference::PreferVp8 && declared_ok,
298        }
299    }
300}
301
302/// The engine's video codec settings, shared by the [`crate::CallClient`] and its calls: the
303/// preference and what the host declared it decodes.
304#[derive(Debug, Default)]
305pub(crate) struct CodecSettings {
306    pref: Mutex<VideoCodecPreference>,
307    decode: Mutex<Option<Vec<VideoCodec>>>,
308}
309
310fn lock<T>(m: &Mutex<T>) -> std::sync::MutexGuard<'_, T> {
311    m.lock().unwrap_or_else(std::sync::PoisonError::into_inner)
312}
313
314impl CodecSettings {
315    pub(crate) fn preference(&self) -> VideoCodecPreference {
316        *lock(&self.pref)
317    }
318
319    pub(crate) fn set_preference(&self, pref: VideoCodecPreference) {
320        *lock(&self.pref) = pref;
321    }
322
323    pub(crate) fn decode(&self) -> Option<Vec<VideoCodec>> {
324        lock(&self.decode).clone()
325    }
326
327    pub(crate) fn set_decode(&self, codecs: &[VideoCodec]) {
328        let mut v = codecs.to_vec();
329        v.sort_by_key(|c| c.as_str());
330        v.dedup();
331        *lock(&self.decode) = Some(v);
332    }
333
334    /// The set a call joined now offers ([`CodecSet::negotiated`]).
335    pub(crate) fn negotiated(&self, cfg_h264: bool) -> CodecSet {
336        CodecSet::negotiated(cfg_h264, self.decode().as_deref(), self.preference())
337    }
338}
339
340#[cfg(test)]
341mod tests {
342    use super::*;
343
344    const PREFS: [VideoCodecPreference; 3] = [
345        VideoCodecPreference::Automatic,
346        VideoCodecPreference::PreferH264,
347        VideoCodecPreference::PreferVp8,
348    ];
349    const DETECTIONS: [H264Detection; 4] = [
350        H264Detection::Usable,
351        H264Detection::NotDetected,
352        H264Detection::Unconfirmed,
353        H264Detection::NoPlatformCheck,
354    ];
355
356    #[test]
357    fn the_effective_codec_follows_the_table() {
358        use CodecPreferenceReason as R;
359        use H264Detection as D;
360        use VideoCodec::{H264, Vp8};
361        use VideoCodecPreference as P;
362        let want = [
363            (P::Automatic, D::Usable, (H264, None)),
364            (P::Automatic, D::NotDetected, (Vp8, None)),
365            (P::Automatic, D::Unconfirmed, (Vp8, None)),
366            (P::Automatic, D::NoPlatformCheck, (Vp8, None)),
367            (P::PreferH264, D::Usable, (H264, None)),
368            (P::PreferH264, D::NotDetected, (Vp8, Some(R::NotDetected))),
369            (P::PreferH264, D::Unconfirmed, (Vp8, Some(R::Platform))),
370            (P::PreferH264, D::NoPlatformCheck, (Vp8, Some(R::Platform))),
371            (P::PreferVp8, D::Usable, (Vp8, None)),
372            (P::PreferVp8, D::NotDetected, (Vp8, None)),
373            (P::PreferVp8, D::Unconfirmed, (Vp8, None)),
374            (P::PreferVp8, D::NoPlatformCheck, (Vp8, None)),
375        ];
376        assert_eq!(want.len(), PREFS.len() * DETECTIONS.len());
377        for (p, d, out) in want {
378            assert_eq!(effective_publish_codec(p, d), out, "{p:?} {d:?}");
379            // A policy that allows H.264 changes nothing.
380            assert_eq!(effective_publish_codec_under_policy(p, d, true), out);
381        }
382        // A policy without H.264: VP8, and Prefer H.264 says `policy`.
383        assert_eq!(
384            effective_publish_codec_under_policy(P::PreferH264, D::Usable, false),
385            (Vp8, Some(R::Policy))
386        );
387        assert_eq!(
388            effective_publish_codec_under_policy(P::Automatic, D::Usable, false),
389            (Vp8, None)
390        );
391        // The device's own reason first.
392        assert_eq!(
393            effective_publish_codec_under_policy(P::PreferH264, D::NoPlatformCheck, false),
394            (Vp8, Some(R::Platform))
395        );
396    }
397
398    #[test]
399    fn h264_is_published_only_when_detected() {
400        for p in PREFS {
401            for d in DETECTIONS {
402                let (codec, _) = effective_publish_codec(p, d);
403                if codec == VideoCodec::H264 {
404                    assert!(d.is_usable(), "{p:?} {d:?}");
405                    assert_ne!(p, VideoCodecPreference::PreferVp8);
406                }
407            }
408        }
409    }
410
411    #[test]
412    fn the_preference_names_round_trip() {
413        for p in PREFS {
414            assert_eq!(VideoCodecPreference::from_name(p.as_str()), Some(p));
415            let json = serde_json::to_string(&p).unwrap_or_default();
416            assert_eq!(json, format!("\"{}\"", p.as_str()));
417        }
418        assert_eq!(VideoCodecPreference::from_name("h264"), None);
419        assert_eq!(
420            VideoCodecPreference::default(),
421            VideoCodecPreference::Automatic
422        );
423        for r in [
424            CodecPreferenceReason::NotDetected,
425            CodecPreferenceReason::Platform,
426            CodecPreferenceReason::Policy,
427        ] {
428            let json = serde_json::to_string(&r).unwrap_or_default();
429            assert_eq!(json, format!("\"{}\"", r.as_str()));
430        }
431    }
432
433    #[cfg(feature = "video-core")]
434    #[test]
435    fn ios_versions() {
436        assert!(ios_before_17_4("iOS Version 17.2 (Build 21C62)"));
437        assert!(ios_before_17_4("iOS Version 16.7.8 (Build 20H343)"));
438        assert!(ios_before_17_4("iOS 17"));
439        assert!(!ios_before_17_4("iOS Version 17.4 (Build 21E219)"));
440        assert!(!ios_before_17_4("iOS Version 18.1 (Build 22B83)"));
441        assert!(!ios_before_17_4("macOS Version 14.2 (Build 23C64)"));
442        assert!(!ios_before_17_4("iOS"));
443        assert!(!ios_before_17_4("fake"));
444    }
445
446    #[test]
447    fn prefer_vp8_and_a_declaration_without_h264_offer_vp8_only() {
448        use VideoCodec::{H264, Vp8};
449        for p in PREFS {
450            assert_eq!(
451                CodecSet::negotiated(false, None, p),
452                CodecSet::VP8_ONLY,
453                "{p:?}"
454            );
455            assert_eq!(
456                CodecSet::negotiated(true, Some(&[Vp8][..]), p),
457                CodecSet::VP8_ONLY
458            );
459            assert_eq!(
460                CodecSet::negotiated(true, Some(&[][..]), p),
461                CodecSet::VP8_ONLY
462            );
463        }
464        for declared in [None, Some(&[Vp8, H264][..])] {
465            assert_eq!(
466                CodecSet::negotiated(true, declared, VideoCodecPreference::PreferVp8),
467                CodecSet::VP8_ONLY
468            );
469        }
470        // Before any declaration, the config alone decides (0.5.0's behaviour).
471        assert_eq!(
472            CodecSet::negotiated(true, None, VideoCodecPreference::Automatic),
473            CodecSet::ALL
474        );
475        assert!(CodecSet::VP8_ONLY.contains(Vp8));
476        assert!(!CodecSet::VP8_ONLY.contains(H264));
477        assert_eq!(CodecSet::ALL.codecs(), vec![Vp8, H264]);
478    }
479
480    /// Linux: a declared decode set never brings H.264 in, whatever it lists.
481    #[cfg(target_os = "linux")]
482    #[test]
483    fn linux_never_offers_h264_once_declared() {
484        use VideoCodec::{H264, Vp8};
485        for p in PREFS {
486            for cfg_h264 in [false, true] {
487                for declared in [&[][..], &[Vp8][..], &[H264][..], &[Vp8, H264][..]] {
488                    let set = CodecSet::negotiated(cfg_h264, Some(declared), p);
489                    assert!(!set.contains(H264), "{p:?} {cfg_h264} {declared:?}");
490                    assert!(set.contains(Vp8));
491                }
492            }
493            // The default config (no H.264 on Linux) without a declaration: VP8 only too.
494            let cfg = crate::ClientConfig::new("t", std::env::temp_dir());
495            assert!(!CodecSet::negotiated(cfg.video_h264, None, p).contains(H264));
496        }
497        let s = CodecSettings::default();
498        s.set_decode(&[H264, Vp8, H264]);
499        assert_eq!(s.decode(), Some(vec![H264, Vp8]));
500        assert!(!s.negotiated(true).contains(H264));
501    }
502
503    #[cfg(not(target_os = "linux"))]
504    #[test]
505    fn a_declared_h264_decoder_is_offered() {
506        use VideoCodec::{H264, Vp8};
507        let s = CodecSettings::default();
508        assert_eq!(s.negotiated(true), CodecSet::ALL);
509        s.set_decode(&[Vp8]);
510        assert_eq!(s.negotiated(true), CodecSet::VP8_ONLY);
511        s.set_decode(&[Vp8, H264]);
512        assert_eq!(s.negotiated(true), CodecSet::ALL);
513        assert_eq!(s.negotiated(false), CodecSet::VP8_ONLY);
514        s.set_preference(VideoCodecPreference::PreferVp8);
515        assert_eq!(s.negotiated(true), CodecSet::VP8_ONLY);
516    }
517
518    #[cfg(feature = "video-core")]
519    #[test]
520    fn detection_from_capabilities() {
521        use kessel_video::{Capabilities, CodecCapability, CodecDirection, Implementation};
522        let entry = |dir, imp| {
523            CodecCapability::new(
524                kessel_video::VideoCodec::H264,
525                dir,
526                imp,
527                "t",
528                1920,
529                1080,
530                30,
531            )
532        };
533        let caps = |backend: &'static str, os: &str, entries: Vec<CodecCapability>| {
534            let mut c = Capabilities::new(backend, os);
535            c.codecs = entries;
536            c
537        };
538        let hw = || entry(CodecDirection::Encode, Implementation::Hardware);
539        let sw = || entry(CodecDirection::Encode, Implementation::Software);
540        let dec = || entry(CodecDirection::Decode, Implementation::Hardware);
541        let mac = "macOS Version 14.2 (Build 23C64)";
542        assert_eq!(
543            h264_encode_detection(&caps("apple", mac, vec![hw(), sw(), dec()])),
544            H264Detection::Usable
545        );
546        // Software only (a Mac VM): not usable; a decoder alone isn't an encoder.
547        assert_eq!(
548            h264_encode_detection(&caps("apple", mac, vec![sw(), dec()])),
549            H264Detection::NotDetected
550        );
551        assert_eq!(
552            h264_encode_detection(&caps(
553                "apple",
554                "iOS Version 17.2 (Build 21C62)",
555                vec![dec()]
556            )),
557            H264Detection::Unconfirmed
558        );
559        assert_eq!(
560            h264_encode_detection(&caps(
561                "apple",
562                "iOS Version 17.5 (Build 21F79)",
563                vec![dec()]
564            )),
565            H264Detection::NotDetected
566        );
567        // No run-time check on these yet, whatever they list.
568        for b in NO_H264_BACKENDS {
569            assert_eq!(
570                h264_encode_detection(&caps(b, "x", vec![hw()])),
571                H264Detection::NoPlatformCheck,
572                "{b}"
573            );
574        }
575        // A test backend's hardware entry counts (the lanes' fixture).
576        assert_eq!(
577            h264_encode_detection(&caps("fixture", "fixture", vec![hw()])),
578            H264Detection::Usable
579        );
580        assert_eq!(
581            H264Detection::from_session(Implementation::Hardware),
582            H264Detection::Usable
583        );
584        assert_eq!(
585            H264Detection::from_session(Implementation::Software),
586            H264Detection::NotDetected
587        );
588        assert_eq!(
589            H264Detection::from_session(Implementation::Unknown),
590            H264Detection::Unconfirmed
591        );
592    }
593}