Offer the codecs every TeamSpeak client decodes before H.264

The official client could not show a Voelin stream: its decoder was
libwebrtc's NullVideoDecoder. Its log says why. On a machine with a
hardware H.264 encoder our offer put H.264 first, with every H.264
variant str0m knows; the client answered H.264 42e01f, then had no
decoder for it, because it decodes H.264 only with an OpenH264 library it
downloads at start-up, and that download failed (HTTP 403). Its SDP
capabilities list H.264 either way. VP8, VP9 and AV1 it always decodes:
FFmpeg's decoders, dav1d and libaom are built into it.

- The hardware encoder order, the automatic stream codec
  (`preferred_codec`) and the offer (`offer_codecs`) now put the codecs
  every client decodes (`decoded_everywhere`: AV1, VP9, VP8) before
  H.264, HEVC last. A viewer answers with the first codec of the offer it
  lists, so official clients take one they can decode; H.264 stays
  offered for peers that want it, and `stream.codec` can still choose it
  (its description now says what that means for official clients).
- A streamer offers H.264 only as it encodes it (Constrained High,
  packetization mode 1), not str0m's other variants, which let a viewer
  answer a profile, or packetization mode 0, we never send. Viewers still
  accept every variant.

Tests: `crates/voelin-core/tests/browser_codecs.rs` (VOELIN_INTEROP=1)
streams the test pattern through every encoder this machine has, VA-API
also from DMA-BUFs, to headless Chromium's libwebrtc: VA-API H.264 and
AV1, libvpx VP8 and VP9, x264, SVT-AV1 and libaom all decode at
1280x720. A second test makes the offer a share makes here
([AV1, VP8, H264, H265]) and checks the browser picks and decodes a
codec every client decodes. The browser driver now takes playwright-core
with a system Chromium (VOELIN_CHROMIUM), which decodes H.264, and the
interop tests accept Chromium 152's name for the SRTP cipher. The
official client itself could not be run here (its beta needs a
myTeamSpeak sign-in on first start).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
selikhovandClaude Opus 5.5 committed 2026-10-03 17:50:37 +03:00
1 parent a9a12bb4db
commit 630ff848b2
13 files changed
+431 -116

No files matched your search

+12 -4
View File
@@ -282,7 +282,7 @@ impl Peer {
) -> Result<(Self, String), PeerError> {
let start = options.start_bitrate.unwrap_or(DEFAULT_START_BITRATE).max(1);
let bwe = config.bandwidth_estimation.then_some(start);
let (mut rtc, srtp_profile) = build_rtc(config, &config.video_codecs, bwe);
let (mut rtc, srtp_profile) = build_rtc(config, &config.video_codecs, true, bwe);
if bwe.is_some() {
let desired = options.desired_bitrate.unwrap_or(start);
rtc.bwe().set_desired_bitrate(Bitrate::bps(desired));
@@ -333,7 +333,7 @@ impl Peer {
}
}
let offer = SdpOffer::from_sdp_string(offer).map_err(|e| PeerError::Sdp(e.to_string()))?;
let (mut rtc, srtp_profile) = build_rtc(config, &codecs, None);
let (mut rtc, srtp_profile) = build_rtc(config, &codecs, false, None);
let net = Net::bind(config, &mut rtc).await?;
let answer = rtc.sdp_api().accept_offer(offer)?;
let peer = Self::spawn(rtc, net, config, None, Vec::new(), srtp_profile);
@@ -462,10 +462,15 @@ fn simulcast_offer(layers: &[LayerSpec]) -> Option<Simulcast> {
}
/// An RTC with Opus and `video` codecs, in this order of preference, our
/// DTLS, and bandwidth estimation starting at `bwe` bit/s if given.
/// DTLS, and bandwidth estimation starting at `bwe` bit/s if given. An
/// offer lists H.264 only as our encoders produce it (`profile-level-id`
/// [`PeerConfig::h264_profile_level_id`], packetization mode 1): with
/// str0m's other variants offered too, a viewer may answer a profile we
/// never send. An answer takes every variant the offer has.
fn build_rtc(
config: &PeerConfig,
video: &[VideoCodec],
offer: bool,
bwe: Option<u64>,
) -> (Rtc, NegotiatedProfile) {
let mut rtc_config =
@@ -475,7 +480,7 @@ fn build_rtc(
VideoCodec::Vp8 => rtc_config.enable_vp8(true),
VideoCodec::Vp9 => rtc_config.enable_vp9(true),
VideoCodec::H264 => {
let mut c = rtc_config.enable_h264(true);
let mut c = if offer { rtc_config } else { rtc_config.enable_h264(true) };
c.codec_config().add_h264(
112.into(),
Some(113.into()),
@@ -935,6 +940,9 @@ mod tests {
};
let (_peer, offer) = Peer::offer(&streamer, "s").await.unwrap();
assert!(offer.contains("profile-level-id=640c1f"), "{offer}");
// Only the profile we encode: a viewer must not answer another.
let h264 = offer.lines().filter(|l| l.contains(" H264/90000")).count();
assert_eq!(h264, 1, "{offer}");
let (_peer, answer) = Peer::answer(&PeerConfig::loopback(), &offer).await.unwrap();
assert_eq!(offered_video_codecs(&answer)[0], VideoCodec::H264, "{answer}");
let vp8_only =