Bug 1530715 - P35: Store layout in the stream instead of context. r=padenot

We store global layout info and channels info in the cubeb context.
However, the streams might output to different devices. We should store
the layout info of the output device in the stream directly instead of
in the context. On the other hand, the `channels` value is a duplicate
of `output_desc.mChannelsPerFrame` or `mixer.out_channels` so we don't
need to store this value.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Chun-Min Chang 2019-07-10 08:07:10 +00:00
Родитель 6c5d3ff715
Коммит 4f393e66ea
2 изменённых файлов: 12 добавлений и 22 удалений

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

@ -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 d23565b1fd9342681f4e7eafc49a2aa1df4f7da0 (2019-06-25 11:32:22 -0700)
The git commit ID used was 8b3af7047c9463c5d47e2323e48359dba19be4cb (2019-06-25 11:32:22 -0700)

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

@ -2014,8 +2014,6 @@ pub struct AudioUnitContext {
// without ARC(Automatic Reference Counting) support, so it should be released
// by dispatch_release(release_dispatch_queue).
serial_queue: dispatch_queue_t,
layout: atomic::Atomic<ChannelLayout>,
channels: u32,
latency_controller: Mutex<LatencyController>,
devices: Mutex<SharedDevices>,
}
@ -2025,8 +2023,6 @@ impl AudioUnitContext {
Self {
_ops: &OPS as *const _,
serial_queue: create_dispatch_queue(DISPATCH_QUEUE_LABEL, DISPATCH_QUEUE_SERIAL),
layout: atomic::Atomic::new(ChannelLayout::UNDEFINED),
channels: 0,
latency_controller: Mutex::new(LatencyController::default()),
devices: Mutex::new(SharedDevices::default()),
}
@ -2508,6 +2504,7 @@ struct AudioUnitStream<'ctx> {
// I/O device sample rate
input_hw_rate: f64,
output_hw_rate: f64,
device_layout: ChannelLayout,
mutex: OwnedCriticalSection,
// Hold the input samples in every input callback iteration.
// Only accessed on input/output callback thread and during initial configure.
@ -2575,6 +2572,7 @@ impl<'ctx> AudioUnitStream<'ctx> {
output_unit: ptr::null_mut(),
input_hw_rate: 0_f64,
output_hw_rate: 0_f64,
device_layout: ChannelLayout::UNDEFINED,
mutex: OwnedCriticalSection::new(),
input_linear_buffer: None,
frames_played: AtomicU64::new(0),
@ -3140,35 +3138,27 @@ impl<'ctx> AudioUnitStream<'ctx> {
self as *const AudioUnitStream,
output_hw_desc
);
self.context.channels = output_hw_desc.mChannelsPerFrame;
let hw_channels = output_hw_desc.mChannelsPerFrame;
// Set the input layout to match the output device layout.
self.context.layout.store(
audiounit_get_current_channel_layout(self.output_unit),
atomic::Ordering::SeqCst,
);
audiounit_set_channel_layout(
self.output_unit,
io_side::OUTPUT,
self.context.layout.load(atomic::Ordering::SeqCst),
);
self.device_layout = audiounit_get_current_channel_layout(self.output_unit);
audiounit_set_channel_layout(self.output_unit, io_side::OUTPUT, self.device_layout);
cubeb_log!(
"({:p}) Output hardware layout: {:?}",
self,
self.context.layout
self.device_layout
);
{
let mut stream_device = self.stream_device.lock().unwrap();
stream_device.mixer = if self.context.channels != self.output_stream_params.channels()
|| self.context.layout.load(atomic::Ordering::SeqCst)
!= self.output_stream_params.layout()
stream_device.mixer = if hw_channels != self.output_stream_params.channels()
|| self.device_layout != self.output_stream_params.layout()
{
cubeb_log!("Incompatible channel layouts detected, setting up remixer");
// We will be remixing the data before it reaches the output device.
// We need to adjust the number of channels and other
// AudioStreamDescription details.
self.output_desc.mChannelsPerFrame = self.context.channels;
self.output_desc.mChannelsPerFrame = hw_channels;
self.output_desc.mBytesPerFrame =
(self.output_desc.mBitsPerChannel / 8) * self.output_desc.mChannelsPerFrame;
self.output_desc.mBytesPerPacket =
@ -3177,8 +3167,8 @@ impl<'ctx> AudioUnitStream<'ctx> {
self.output_stream_params.format(),
self.output_stream_params.channels(),
self.output_stream_params.layout(),
self.context.channels,
self.context.layout.load(atomic::Ordering::SeqCst),
hw_channels,
self.device_layout,
))
} else {
None