diff --git a/crates/voelin-core/src/media.rs b/crates/voelin-core/src/media.rs index 6d77331..5eb0986 100644 --- a/crates/voelin-core/src/media.rs +++ b/crates/voelin-core/src/media.rs @@ -3410,7 +3410,14 @@ mod tests { assert!(all.is_hardware(backend), "{codec} offered in software"); } if all.encoder_codecs().contains(&Codec::H264) && !offer.contains(&Codec::H264) { - assert_eq!(offer_codecs(&all, Codec::H264)[..2], [Codec::H264, Codec::Vp8]); + // H.264 in software only (so not in `offer`): it leads the same + // codecs as with VP8 as the stream codec, whichever hardware + // encoders this machine has (a hardware AV1 or VP9 encoder ranks + // before VP8, so VP8 is not always second). + let h264 = offer_codecs(&all, Codec::H264); + assert_eq!(h264[0], Codec::H264, "{h264:?}"); + assert_eq!(h264.len(), offer.len() + 1, "{h264:?} against {offer:?}"); + assert!(offer.iter().all(|c| h264.contains(c)), "{h264:?} against {offer:?}"); } // Whatever this machine has: codecs every TeamSpeak client decodes // come before H.264, HEVC last, and the automatic stream codec is @@ -3423,10 +3430,23 @@ mod tests { let ranks: Vec<_> = offer[1..].iter().map(rank).collect(); assert!(ranks.is_sorted(), "{offer:?}"); assert!(preferred_codec(&all, None).is_some_and(decoded_everywhere), "{all:?}"); - assert_eq!( - preferred_codec(&all, Some(Codec::H264)).is_some(), - all.encoder_codecs().contains(&Codec::H264) - ); + // A configured codec is the stream codec when this machine can encode + // it; otherwise the result is the automatic choice, + // `preferred_codec(&all, None)` (some codec on any machine that + // encodes anything). Whether H.264 is encodable depends on the + // machine (a desktop with FFmpeg or a GPU has an encoder, a CI + // runner has none), so the expectation follows `all.encoder_codecs()`. + let h264 = preferred_codec(&all, Some(Codec::H264)); + if all.encoder_codecs().contains(&Codec::H264) { + assert_eq!(h264, Some(Codec::H264), "{all:?}"); + } else { + assert_eq!(h264, preferred_codec(&all, None), "{all:?}"); + } + // The built-in codecs are the same everywhere (no OpenH264 loaded): + // VP9 is encodable and wins, H.264 is not and falls back to VP8. + assert_eq!(preferred_codec(&codecs, Some(Codec::Vp9)), Some(Codec::Vp9)); + assert_eq!(preferred_codec(&codecs, Some(Codec::H264)), preferred_codec(&codecs, None)); + assert_eq!(preferred_codec(&codecs, None), Some(Codec::Vp8)); } /// A sink whose viewers chose `codecs`; keeps every video frame with its