Refuse streams without a common codec; voelinctl streams VP8 by default
On a machine with hardware encoders, voelinctl's streamer chose H.264 (the first hardware codec) and, sending through a FrameSource, offered it alone. A viewer that cannot decode H.264 (no OpenH264 library) answered with a video section that listed no payload type at all; the streamer could not parse that answer and dropped the viewer, which only saw "removed by the streamer (Failed)". A viewer now refuses such an offer with the codecs on both sides, and voelinctl's single-codec offer defaults to VP8, which every client decodes; --codec or a named --encoder still pick another. The engine's own streams are unaffected: they offer several codecs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b80855d081
commit
1febc504c2
2 files changed
+46
-7
No files matched your search
@@ -178,6 +178,11 @@ pub enum PeerError {
|
||||
Io(#[from] std::io::Error),
|
||||
#[error("invalid SDP: {0}")]
|
||||
Sdp(String),
|
||||
/// The offer's video uses none of the codecs we decode.
|
||||
#[error(
|
||||
"no video codec in common: the stream offers {offered}, this client decodes {accepted}"
|
||||
)]
|
||||
NoCommonCodec { offered: String, accepted: String },
|
||||
#[error("WebRTC: {0}")]
|
||||
Rtc(#[from] RtcError),
|
||||
#[error("no usable local address")]
|
||||
@@ -304,10 +309,24 @@ impl Peer {
|
||||
/// Viewer side: accept the streamer's offer; returns our SDP answer.
|
||||
pub async fn answer(config: &PeerConfig, offer: &str) -> Result<(Self, String), PeerError> {
|
||||
// Our codecs in the order of the offer, then the rest.
|
||||
let mut codecs: Vec<_> = offered_video_codecs(offer)
|
||||
.into_iter()
|
||||
.filter(|c| config.accept_video_codecs.contains(c))
|
||||
.collect();
|
||||
let offered = offered_video_codecs(offer);
|
||||
let mut codecs: Vec<_> =
|
||||
offered.iter().copied().filter(|c| config.accept_video_codecs.contains(c)).collect();
|
||||
// Without one, the answer's video section would list no payload type,
|
||||
// which no peer (str0m included) can parse.
|
||||
if config.video
|
||||
&& codecs.is_empty()
|
||||
&& offer.lines().any(|l| l.trim_start().starts_with("m=video "))
|
||||
{
|
||||
let names = |codecs: &[VideoCodec]| match codecs {
|
||||
[] => "none we know".to_owned(),
|
||||
_ => codecs.iter().map(|c| c.sdp_name()).collect::<Vec<_>>().join(", "),
|
||||
};
|
||||
return Err(PeerError::NoCommonCodec {
|
||||
offered: names(&offered),
|
||||
accepted: names(&config.accept_video_codecs),
|
||||
});
|
||||
}
|
||||
for c in &config.accept_video_codecs {
|
||||
if !codecs.contains(c) {
|
||||
codecs.push(*c);
|
||||
@@ -924,6 +943,23 @@ mod tests {
|
||||
assert_eq!(offered_video_codecs(&answer), [VideoCodec::Vp8], "{answer}");
|
||||
}
|
||||
|
||||
/// An offer of codecs we cannot decode is refused with the reason, not
|
||||
/// answered with a video section the streamer cannot parse.
|
||||
#[tokio::test]
|
||||
async fn no_common_codec_is_refused() {
|
||||
let streamer =
|
||||
PeerConfig { video_codecs: vec![VideoCodec::H264], ..PeerConfig::loopback() };
|
||||
let (_peer, offer) = Peer::offer(&streamer, "s").await.unwrap();
|
||||
let vp8_only =
|
||||
PeerConfig { accept_video_codecs: vec![VideoCodec::Vp8], ..PeerConfig::loopback() };
|
||||
let error = Peer::answer(&vp8_only, &offer).await.err().expect("refused");
|
||||
assert!(matches!(error, PeerError::NoCommonCodec { .. }), "{error}");
|
||||
assert_eq!(
|
||||
error.to_string(),
|
||||
"no video codec in common: the stream offers H264, this client decodes VP8"
|
||||
);
|
||||
}
|
||||
|
||||
/// Several codecs offered: the streamer learns which one each viewer's
|
||||
/// answer chose; H.264 carries the level the stream needs.
|
||||
#[tokio::test]
|
||||
|
||||
@@ -14,7 +14,7 @@ use tokio::time::{Instant, Interval, sleep_until};
|
||||
use tsclientlib::prelude::*;
|
||||
use tsclientlib::{ClientId, Connection, MessageHandle, StreamItem};
|
||||
use voelin_core::media::voelin_media::capture::SourceId;
|
||||
use voelin_core::media::voelin_media::{Codecs, VideoFrame, convert};
|
||||
use voelin_core::media::voelin_media::{Codec, Codecs, VideoFrame, convert};
|
||||
use voelin_core::media::{
|
||||
CaptureBackend, EncodedSource, EncoderPreference, Latest, Streamer, StreamerConfig,
|
||||
VideoPipeline, peer_config, preferred_codec, stream_codec, video_codec,
|
||||
@@ -96,8 +96,8 @@ pub enum StreamCommand {
|
||||
/// bitrate, no encoder) instead of capturing.
|
||||
#[arg(long, conflicts_with_all = ["source", "synthetic"])]
|
||||
placeholder: bool,
|
||||
/// Video codec: vp8, vp9, h264, av1 [default: the first the encoder
|
||||
/// choice gives: hardware first, else VP8].
|
||||
/// Video codec: vp8, vp9, h264, av1 [default: VP8, which every client
|
||||
/// decodes; with --encoder, that encoder's codec]. One codec is offered.
|
||||
#[arg(long)]
|
||||
codec: Option<String>,
|
||||
/// Encoder: `auto`, `software` or a backend name from `voelinctl
|
||||
@@ -177,6 +177,9 @@ pub async fn run(con: &mut Connection, args: &StreamArgs) -> Result<()> {
|
||||
} else {
|
||||
let configured = match codec {
|
||||
Some(codec) => Some(codec.parse().map_err(|e| anyhow::anyhow!("{e}"))?),
|
||||
// One codec is offered (below): by default the one every
|
||||
// client decodes. A named encoder brings its own codec.
|
||||
None if encoder == "auto" => Some(Codec::Vp8),
|
||||
None => None,
|
||||
};
|
||||
if let Some(codec) = preferred_codec(&codecs, configured) {
|
||||
|
||||
Reference in new issue
Block a user