diff --git a/media/libcubeb/cubeb-pulse-rs/Cargo.toml b/media/libcubeb/cubeb-pulse-rs/Cargo.toml index 41bae6bc2d71..833e3678826a 100644 --- a/media/libcubeb/cubeb-pulse-rs/Cargo.toml +++ b/media/libcubeb/cubeb-pulse-rs/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cubeb-pulse" -version = "0.1.1" +version = "0.2.0" authors = ["Dan Glastonbury "] description = "Cubeb backed for PulseAudio written in Rust" @@ -11,7 +11,7 @@ pulse-dlopen = ["pulse-ffi/dlopen"] crate-type = ["staticlib", "rlib"] [dependencies] -cubeb-backend = "0.4" +cubeb-backend = "0.5" pulse-ffi = { path = "pulse-ffi" } pulse = { path = "pulse-rs" } semver = "^0.6" diff --git a/media/libcubeb/cubeb-pulse-rs/README_MOZILLA b/media/libcubeb/cubeb-pulse-rs/README_MOZILLA index 9be7fa83d3b8..6f18dd2c704f 100644 --- a/media/libcubeb/cubeb-pulse-rs/README_MOZILLA +++ b/media/libcubeb/cubeb-pulse-rs/README_MOZILLA @@ -5,4 +5,4 @@ Makefile.in build files for the Mozilla build system. The cubeb-pulse-rs git repository is: https://github.com/djg/cubeb-pulse-rs.git -The git commit ID used was 22cdde3e573303649a77e48a19f7ca2c4d308047 (2018-03-06 10:39:46 +1000) +The git commit ID used was 247b01d8e971d0680fa1cc39e63d17e0fc030556 (2018-03-23 08:27:05 +1000) diff --git a/media/libcubeb/cubeb-pulse-rs/src/backend/context.rs b/media/libcubeb/cubeb-pulse-rs/src/backend/context.rs index 7cca19b27eb4..a63268cc9875 100644 --- a/media/libcubeb/cubeb-pulse-rs/src/backend/context.rs +++ b/media/libcubeb/cubeb-pulse-rs/src/backend/context.rs @@ -4,9 +4,8 @@ // accompanying file LICENSE for details. use backend::*; -use cubeb_backend::{ffi, log_enabled, ChannelLayout, Context, ContextOps, DeviceCollectionRef, - DeviceId, DeviceType, Error, Ops, Result, Stream, StreamParams, - StreamParamsRef}; +use cubeb_backend::{ffi, log_enabled, Context, ContextOps, DeviceCollectionRef, DeviceId, + DeviceType, Error, Ops, Result, Stream, StreamParams, StreamParamsRef}; use pulse::{self, ProplistExt}; use pulse_ffi::*; use semver; @@ -17,38 +16,6 @@ use std::mem; use std::os::raw::c_void; use std::ptr; -fn pa_channel_to_cubeb_channel(channel: pulse::ChannelPosition) -> ffi::cubeb_channel { - use cubeb_backend::ffi::*; - use pulse::ChannelPosition; - assert_ne!(channel, ChannelPosition::Invalid); - match channel { - ChannelPosition::Mono => CHANNEL_MONO, - ChannelPosition::FrontLeft => CHANNEL_LEFT, - ChannelPosition::FrontRight => CHANNEL_RIGHT, - ChannelPosition::FrontCenter => CHANNEL_CENTER, - ChannelPosition::SideLeft => CHANNEL_LS, - ChannelPosition::SideRight => CHANNEL_RS, - ChannelPosition::RearLeft => CHANNEL_RLS, - ChannelPosition::RearCenter => CHANNEL_RCENTER, - ChannelPosition::RearRight => CHANNEL_RRS, - ChannelPosition::LowFreqEffects => CHANNEL_LFE, - _ => CHANNEL_INVALID, - } -} - -fn channel_map_to_layout(cm: &pulse::ChannelMap) -> ChannelLayout { - use cubeb_backend::ffi::{cubeb_channel_map, cubeb_channel_map_to_layout}; - use pulse::ChannelPosition; - let mut cubeb_map: cubeb_channel_map = unsafe { mem::zeroed() }; - cubeb_map.channels = u32::from(cm.channels); - for i in 0usize..cm.channels as usize { - cubeb_map.map[i] = pa_channel_to_cubeb_channel( - ChannelPosition::try_from(cm.map[i]).unwrap_or(ChannelPosition::Invalid), - ); - } - ChannelLayout::from(unsafe { cubeb_channel_map_to_layout(&cubeb_map) }) -} - #[derive(Debug)] pub struct DefaultInfo { pub sample_spec: pulse::SampleSpec, @@ -70,7 +37,8 @@ pub struct PulseContext { pub error: bool, pub version_2_0_0: bool, pub version_0_9_8: bool, - #[cfg(feature = "pulse-dlopen")] pub libpulse: LibLoader, + #[cfg(feature = "pulse-dlopen")] + pub libpulse: LibLoader, devids: RefCell, } @@ -118,7 +86,11 @@ impl PulseContext { } fn new(name: Option<&CStr>) -> Result> { - fn server_info_cb(context: &pulse::Context, info: Option<&pulse::ServerInfo>, u: *mut c_void) { + fn server_info_cb( + context: &pulse::Context, + info: Option<&pulse::ServerInfo>, + u: *mut c_void, + ) { fn sink_info_cb( _: &pulse::Context, i: *const pulse::SinkInfo, @@ -218,13 +190,6 @@ impl ContextOps for PulseContext { } } - fn preferred_channel_layout(&mut self) -> Result { - match self.default_sink_info { - Some(ref info) => Ok(channel_map_to_layout(&info.channel_map)), - None => Err(Error::error()), - } - } - fn enumerate_devices( &mut self, devtype: DeviceType, @@ -596,12 +561,16 @@ impl PulseContext { } self.mainloop.lock(); - if let Some(ref context) = self.context { + let connected = if let Some(ref context) = self.context { context.set_state_callback(error_state, context_ptr); - let _ = context.connect(None, pulse::ContextFlags::empty(), ptr::null()); - } + context + .connect(None, pulse::ContextFlags::empty(), ptr::null()) + .is_ok() + } else { + false + }; - if !self.wait_until_context_ready() { + if !connected || !self.wait_until_context_ready() { self.mainloop.unlock(); self.context_destroy(); return Err(Error::error()); diff --git a/media/libcubeb/cubeb-pulse-rs/src/backend/mod.rs b/media/libcubeb/cubeb-pulse-rs/src/backend/mod.rs index eae1ba29c93d..8e067e6caecb 100644 --- a/media/libcubeb/cubeb-pulse-rs/src/backend/mod.rs +++ b/media/libcubeb/cubeb-pulse-rs/src/backend/mod.rs @@ -5,7 +5,6 @@ mod context; mod cork_state; -mod mixer; mod stream; mod intern; diff --git a/media/libcubeb/cubeb-pulse-rs/src/backend/stream.rs b/media/libcubeb/cubeb-pulse-rs/src/backend/stream.rs index ad9d2a3ac9d8..1d5c22a3a8dd 100644 --- a/media/libcubeb/cubeb-pulse-rs/src/backend/stream.rs +++ b/media/libcubeb/cubeb-pulse-rs/src/backend/stream.rs @@ -16,34 +16,46 @@ use std::os::raw::{c_long, c_void}; const PULSE_NO_GAIN: f32 = -1.0; fn cubeb_channel_to_pa_channel(channel: ffi::cubeb_channel) -> pa_channel_position_t { - use cubeb_backend::ffi::*; - assert_ne!(channel, CHANNEL_INVALID); - match channel { - CHANNEL_LEFT => PA_CHANNEL_POSITION_FRONT_LEFT, - CHANNEL_RIGHT => PA_CHANNEL_POSITION_FRONT_RIGHT, - CHANNEL_CENTER => PA_CHANNEL_POSITION_FRONT_CENTER, - CHANNEL_LS => PA_CHANNEL_POSITION_SIDE_LEFT, - CHANNEL_RS => PA_CHANNEL_POSITION_SIDE_RIGHT, - CHANNEL_RLS => PA_CHANNEL_POSITION_REAR_LEFT, - CHANNEL_RCENTER => PA_CHANNEL_POSITION_REAR_CENTER, - CHANNEL_RRS => PA_CHANNEL_POSITION_REAR_RIGHT, - CHANNEL_LFE => PA_CHANNEL_POSITION_LFE, - // Also handles CHANNEL_MONO case - _ => PA_CHANNEL_POSITION_MONO, + ffi::CHANNEL_FRONT_LEFT => PA_CHANNEL_POSITION_FRONT_LEFT, + ffi::CHANNEL_FRONT_RIGHT => PA_CHANNEL_POSITION_FRONT_RIGHT, + ffi::CHANNEL_FRONT_CENTER => PA_CHANNEL_POSITION_FRONT_CENTER, + ffi::CHANNEL_LOW_FREQUENCY => PA_CHANNEL_POSITION_LFE, + ffi::CHANNEL_BACK_LEFT => PA_CHANNEL_POSITION_REAR_LEFT, + ffi::CHANNEL_BACK_RIGHT => PA_CHANNEL_POSITION_REAR_RIGHT, + ffi::CHANNEL_FRONT_LEFT_OF_CENTER => PA_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER, + ffi::CHANNEL_FRONT_RIGHT_OF_CENTER => PA_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER, + ffi::CHANNEL_BACK_CENTER => PA_CHANNEL_POSITION_REAR_CENTER, + ffi::CHANNEL_SIDE_LEFT => PA_CHANNEL_POSITION_SIDE_LEFT, + ffi::CHANNEL_SIDE_RIGHT => PA_CHANNEL_POSITION_SIDE_RIGHT, + ffi::CHANNEL_TOP_CENTER => PA_CHANNEL_POSITION_TOP_CENTER, + ffi::CHANNEL_TOP_FRONT_LEFT => PA_CHANNEL_POSITION_TOP_FRONT_LEFT, + ffi::CHANNEL_TOP_FRONT_CENTER => PA_CHANNEL_POSITION_TOP_FRONT_CENTER, + ffi::CHANNEL_TOP_FRONT_RIGHT => PA_CHANNEL_POSITION_TOP_FRONT_RIGHT, + ffi::CHANNEL_TOP_BACK_LEFT => PA_CHANNEL_POSITION_TOP_REAR_LEFT, + ffi::CHANNEL_TOP_BACK_CENTER => PA_CHANNEL_POSITION_TOP_REAR_CENTER, + ffi::CHANNEL_TOP_BACK_RIGHT => PA_CHANNEL_POSITION_TOP_REAR_RIGHT, + _ => PA_CHANNEL_POSITION_INVALID, } } fn layout_to_channel_map(layout: ChannelLayout) -> pulse::ChannelMap { - assert_ne!(layout, ChannelLayout::Undefined); - - let order = mixer::channel_index_to_order(layout.into()); + assert_ne!(layout, ChannelLayout::UNDEFINED); let mut cm = pulse::ChannelMap::init(); - cm.channels = order.len() as u8; - for (s, d) in order.iter().zip(cm.map.iter_mut()) { - *d = cubeb_channel_to_pa_channel(*s); + + let mut channel_map = layout.bits(); + let mut i = 0; + while channel_map != 0 { + let channel = (channel_map & 1) << i; + if channel != 0 { + cm.map[i] = cubeb_channel_to_pa_channel(channel); + i += 1; + } + channel_map = channel_map >> 1; } + + cm.channels = layout.num_channels() as _; cm } @@ -626,7 +638,7 @@ impl<'ctx> PulseStream<'ctx> { }; let cm: Option = match stream_params.layout() { - ChannelLayout::Undefined => None, + ChannelLayout::UNDEFINED => None, _ => Some(layout_to_channel_map(stream_params.layout())), };