diff --git a/extensions/warp-blink-wrtc/src/host_media/audio/mod.rs b/extensions/warp-blink-wrtc/src/host_media/audio/mod.rs index 8b2e7e3da..994715ad1 100644 --- a/extensions/warp-blink-wrtc/src/host_media/audio/mod.rs +++ b/extensions/warp-blink-wrtc/src/host_media/audio/mod.rs @@ -18,11 +18,11 @@ pub use self::opus::sink::OpusSink; pub use self::opus::source::OpusSource; pub use hardware_config::*; +// for webrtc, the number of audio channels is hardcoded to 1. #[derive(Debug, Clone)] pub struct AudioCodec { pub mime: MimeType, pub sample_rate: AudioSampleRate, - pub channels: u16, } #[derive(Clone)] @@ -50,9 +50,6 @@ impl AudioCodec { pub fn frame_size(&self) -> usize { self.sample_rate.frame_size() } - pub fn channels(&self) -> u16 { - self.channels - } } impl Default for AudioCodec { @@ -60,7 +57,6 @@ impl Default for AudioCodec { Self { mime: MimeType::OPUS, sample_rate: AudioSampleRate::High, - channels: 1, } } } diff --git a/extensions/warp-blink-wrtc/src/host_media/audio/opus/mod.rs b/extensions/warp-blink-wrtc/src/host_media/audio/opus/mod.rs index 52ffeda42..271fd40ec 100644 --- a/extensions/warp-blink-wrtc/src/host_media/audio/opus/mod.rs +++ b/extensions/warp-blink-wrtc/src/host_media/audio/opus/mod.rs @@ -80,8 +80,9 @@ impl ChannelMixer { ChannelMixerConfig::Average { to_sum: num } => { self.sum += sample; self.num_summed += 1; - if self.num_summed == num { - let avg = self.sum / num as f32; + // using >= to prevent the ChannelMixer from being stuck. otherwise == would do. + if self.num_summed >= num { + let avg = self.sum / self.num_summed as f32; self.sum = 0.0; self.num_summed = 0; ChannelMixerOutput::Single(avg) diff --git a/extensions/warp-blink-wrtc/src/host_media/audio/opus/sink/mod.rs b/extensions/warp-blink-wrtc/src/host_media/audio/opus/sink/mod.rs index 9a904b3ef..fed419daa 100644 --- a/extensions/warp-blink-wrtc/src/host_media/audio/opus/sink/mod.rs +++ b/extensions/warp-blink-wrtc/src/host_media/audio/opus/sink/mod.rs @@ -67,7 +67,7 @@ impl OpusSink { let resampler = Resampler::new(resampler_config); // webtrtc codec is guaranteed to have 1 channel - let channel_mixer_config = match webrtc_codec.channels().cmp(&sink_config.channels()) { + let channel_mixer_config = match 1.cmp(&sink_config.channels()) { Ordering::Equal => ChannelMixerConfig::None, Ordering::Greater => { unreachable!("invalid channels for OpusSink. sink config has less than 1 channel") diff --git a/extensions/warp-blink-wrtc/src/host_media/audio/opus/source/framer.rs b/extensions/warp-blink-wrtc/src/host_media/audio/opus/source/framer.rs index 1a4d84d30..ed13e1e34 100644 --- a/extensions/warp-blink-wrtc/src/host_media/audio/opus/source/framer.rs +++ b/extensions/warp-blink-wrtc/src/host_media/audio/opus/source/framer.rs @@ -64,7 +64,7 @@ impl Framer { }; // webrtc_codec.channels() is guaranteed to be 1 channel - let channel_mixer_config = match webrtc_codec.channels().cmp(&source_config.channels()) { + let channel_mixer_config = match 1.cmp(&source_config.channels()) { Ordering::Equal => ChannelMixerConfig::None, Ordering::Less => ChannelMixerConfig::Average { to_sum: source_config.channels() as _, diff --git a/extensions/warp-blink-wrtc/src/host_media/mp4_logger/mod.rs b/extensions/warp-blink-wrtc/src/host_media/mp4_logger/mod.rs index 773d0049a..428ef02f2 100644 --- a/extensions/warp-blink-wrtc/src/host_media/mp4_logger/mod.rs +++ b/extensions/warp-blink-wrtc/src/host_media/mp4_logger/mod.rs @@ -405,13 +405,11 @@ fn write_mp4_header( pre_skip: 0, input_sample_rate: audio_codec.sample_rate(), output_gain: 0, - channel_mapping_family: mp4::ChannelMappingFamily::Family0 { - stereo: audio_codec.channels() == 2, - }, + channel_mapping_family: mp4::ChannelMappingFamily::Family0 { stereo: false }, }; let opus = OpusBox { data_reference_index: 1, - channelcount: audio_codec.channels(), + channelcount: 1, samplesize: 16, // per https://opus-codec.org/docs/opus_in_isobmff.html samplerate: FixedPointU16::new(audio_codec.sample_rate() as u16), dops, diff --git a/extensions/warp-blink-wrtc/src/lib.rs b/extensions/warp-blink-wrtc/src/lib.rs index 02d55a010..851296faa 100644 --- a/extensions/warp-blink-wrtc/src/lib.rs +++ b/extensions/warp-blink-wrtc/src/lib.rs @@ -295,7 +295,7 @@ impl BlinkImpl { let rtc_rtp_codec: RTCRtpCodecCapability = RTCRtpCodecCapability { mime_type: webrtc_codec.mime_type(), clock_rate: webrtc_codec.sample_rate(), - channels: webrtc_codec.channels(), + channels: 1, ..Default::default() }; let track = self