Bug 1530715 - P36: Move out minimum_resampling_input_frames of output callback. r=padenot

Avoid calling minimum_resampling_input_frames by a borrowing from
AudioUnitStream

Differential Revision: https://phabricator.services.mozilla.com/D34069

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Chun-Min Chang 2019-07-09 19:57:06 +00:00
Родитель fcb7b1184a
Коммит 03fce17902
2 изменённых файлов: 15 добавлений и 13 удалений

Просмотреть файл

@ -3,4 +3,4 @@ git repository using the update.sh script.
The cubeb-coreaudio-rs git repository is: https://github.com/ChunMinChang/cubeb-coreaudio-rs
The git commit ID used was 8b3af7047c9463c5d47e2323e48359dba19be4cb (2019-06-25 11:32:22 -0700)
The git commit ID used was 197915345fb17690bc431b4952758f61bcb4ff14 (2019-06-25 11:32:22 -0700)

Просмотреть файл

@ -370,6 +370,15 @@ fn get_volume(unit: AudioUnit) -> Result<f32> {
}
}
fn minimum_resampling_input_frames(input_rate: f64, output_rate: f64, output_frames: i64) -> i64 {
assert_ne!(input_rate, 0_f64);
assert_ne!(output_rate, 0_f64);
if input_rate == output_rate {
return output_frames;
}
(input_rate * output_frames as f64 / output_rate).ceil() as i64
}
fn audiounit_make_silent(io_data: &mut AudioBuffer) {
assert!(!io_data.mData.is_null());
let bytes = unsafe {
@ -602,7 +611,11 @@ extern "C" fn audiounit_output_callback(
// currently switching, we add some silence as well to compensate for the
// fact that we're lacking some input data.
let frames_written = stm.frames_written.load(Ordering::SeqCst);
let input_frames_needed = stm.minimum_resampling_input_frames(frames_written);
let input_frames_needed = minimum_resampling_input_frames(
stm.input_hw_rate,
f64::from(stm.output_stream_params.rate()),
frames_written,
);
let missing_frames = input_frames_needed - stm.frames_read.load(Ordering::SeqCst);
if missing_frames > 0 {
stm.input_linear_buffer.as_mut().unwrap().push_zeros(
@ -2640,17 +2653,6 @@ impl<'ctx> AudioUnitStream<'ctx> {
self.output_stream_params.rate() > 0
}
fn minimum_resampling_input_frames(&self, output_frames: i64) -> i64 {
assert_ne!(self.input_hw_rate, 0_f64);
assert_ne!(self.output_stream_params.rate(), 0);
if self.input_hw_rate == f64::from(self.output_stream_params.rate()) {
// Fast path.
return output_frames;
}
(self.input_hw_rate * output_frames as f64 / f64::from(self.output_stream_params.rate()))
.ceil() as i64
}
fn reinit(&mut self) -> Result<()> {
if !self.shutdown.load(Ordering::SeqCst) {
self.stop_internal();