Skip to content

Commit

Permalink
chore(AudioCodec): remove channels field because it's always 1
Browse files Browse the repository at this point in the history
  • Loading branch information
sdwoodbury committed Sep 15, 2023
1 parent 2726766 commit d546aab
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 14 deletions.
6 changes: 1 addition & 5 deletions extensions/warp-blink-wrtc/src/host_media/audio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -50,17 +50,13 @@ impl AudioCodec {
pub fn frame_size(&self) -> usize {
self.sample_rate.frame_size()
}
pub fn channels(&self) -> u16 {
self.channels
}
}

impl Default for AudioCodec {
fn default() -> Self {
Self {
mime: MimeType::OPUS,
sample_rate: AudioSampleRate::High,
channels: 1,
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions extensions/warp-blink-wrtc/src/host_media/audio/opus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 _,
Expand Down
6 changes: 2 additions & 4 deletions extensions/warp-blink-wrtc/src/host_media/mp4_logger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion extensions/warp-blink-wrtc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d546aab

Please sign in to comment.