Bug 1518106 - Update cubeb-pulse-rs from upstream to 17c1629. r=kinetik
authorAlex Chronopoulos <achronop@gmail.com>
Wed, 23 Jan 2019 19:37:18 +0000
changeset 515238 42246dc57f621bdf3f28790f28c940d64e809b92
parent 515237 3692b1c3df6076cb3c07b102726e17cd0acce818
child 515239 7259ee92e345359164baba67b035cc5d98b76ff4
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskinetik
bugs1518106
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1518106 - Update cubeb-pulse-rs from upstream to 17c1629. r=kinetik Differential Revision: https://phabricator.services.mozilla.com/D17400
media/libcubeb/cubeb-pulse-rs/README_MOZILLA
media/libcubeb/cubeb-pulse-rs/pulse-ffi/src/ffi_funcs.rs
media/libcubeb/cubeb-pulse-rs/pulse-rs/src/lib.rs
media/libcubeb/cubeb-pulse-rs/src/backend/stream.rs
--- a/media/libcubeb/cubeb-pulse-rs/README_MOZILLA
+++ b/media/libcubeb/cubeb-pulse-rs/README_MOZILLA
@@ -1,8 +1,8 @@
 The source from this directory was copied from the cubeb-pulse-rs
 git repository using the update.sh script.  The only changes
 made were those applied by update.sh and the addition of
 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 100b85828388d4bf8b9713fe5c5dd9dc00d8f24f (2018-10-19 10:32:47 +1300)
+The git commit ID used was 17c1629c323ff24d656ff9449bf50d6758aafc1a (2019-01-24 07:50:09 +1300)
--- a/media/libcubeb/cubeb-pulse-rs/pulse-ffi/src/ffi_funcs.rs
+++ b/media/libcubeb/cubeb-pulse-rs/pulse-ffi/src/ffi_funcs.rs
@@ -12,16 +12,20 @@ mod static_fns {
     use super::*;
     use std::os::raw::{c_char, c_double, c_float, c_int, c_uint, c_void};
 
     #[link(name = "pulse")]
     extern "C" {
         pub fn pa_get_library_version() -> *const c_char;
         pub fn pa_channel_map_can_balance(map: *const pa_channel_map) -> c_int;
         pub fn pa_channel_map_init(m: *mut pa_channel_map) -> *mut pa_channel_map;
+        pub fn pa_channel_map_init_auto(m: *mut pa_channel_map,
+                                        ch: u32,
+                                        def: pa_channel_map_def_t)
+                                        -> *mut pa_channel_map;
         pub fn pa_context_connect(c: *mut pa_context,
                                   server: *const c_char,
                                   flags: pa_context_flags_t,
                                   api: *const pa_spawn_api)
                                   -> c_int;
         pub fn pa_context_disconnect(c: *mut pa_context);
         pub fn pa_context_drain(c: *mut pa_context,
                                 cb: pa_context_notify_cb_t,
@@ -202,16 +206,23 @@ mod dynamic_fns {
             };
             PA_CHANNEL_MAP_INIT = {
                 let fp = dlsym(h, cstr!("pa_channel_map_init"));
                 if fp.is_null() {
                     return None;
                 }
                 fp
             };
+            PA_CHANNEL_MAP_INIT_AUTO = {
+                let fp = dlsym(h, cstr!("pa_channel_map_init_auto"));
+                if fp.is_null() {
+                    return None;
+                }
+                fp
+            };
             PA_CONTEXT_CONNECT = {
                 let fp = dlsym(h, cstr!("pa_context_connect"));
                 if fp.is_null() {
                     return None;
                 }
                 fp
             };
             PA_CONTEXT_DISCONNECT = {
@@ -740,16 +751,29 @@ mod dynamic_fns {
     }
 
     static mut PA_CHANNEL_MAP_INIT: *mut ::libc::c_void = 0 as *mut _;
     #[inline]
     pub unsafe fn pa_channel_map_init(m: *mut pa_channel_map) -> *mut pa_channel_map {
         (::std::mem::transmute::<_, extern "C" fn(*mut pa_channel_map) -> *mut pa_channel_map>(PA_CHANNEL_MAP_INIT))(m)
     }
 
+    static mut PA_CHANNEL_MAP_INIT_AUTO: *mut ::libc::c_void = 0 as *mut _;
+    #[inline]
+    pub unsafe fn pa_channel_map_init_auto(m: *mut pa_channel_map,
+                                           ch: u32,
+                                           def: pa_channel_map_def_t)
+                                           -> *mut pa_channel_map {
+        (::std::mem::transmute::<_,
+                                 extern "C" fn(*mut pa_channel_map,
+                                               u32,
+                                               pa_channel_map_def_t)
+                                               -> *mut pa_channel_map>(PA_CHANNEL_MAP_INIT_AUTO))(m, ch, def)
+    }
+
     static mut PA_CONTEXT_CONNECT: *mut ::libc::c_void = 0 as *mut _;
     #[inline]
     pub unsafe fn pa_context_connect(c: *mut pa_context,
                                      server: *const c_char,
                                      flags: pa_context_flags_t,
                                      api: *const pa_spawn_api)
                                      -> c_int {
         (::std::mem::transmute::<_,
--- a/media/libcubeb/cubeb-pulse-rs/pulse-rs/src/lib.rs
+++ b/media/libcubeb/cubeb-pulse-rs/pulse-rs/src/lib.rs
@@ -588,27 +588,39 @@ impl CVolumeExt for CVolume {
         unsafe {
             ffi::pa_cvolume_set_balance(self, map, new_balance);
         }
     }
 }
 
 pub trait ChannelMapExt {
     fn init() -> ChannelMap;
+    fn init_auto(ch: u32, def: ffi::pa_channel_map_def_t) -> Option<ChannelMap>;
     fn can_balance(&self) -> bool;
 }
 
 impl ChannelMapExt for ChannelMap {
     fn init() -> ChannelMap {
         let mut cm = ChannelMap::default();
         unsafe {
             ffi::pa_channel_map_init(&mut cm);
         }
         cm
     }
+    fn init_auto(ch: u32, def: ffi::pa_channel_map_def_t) -> Option<ChannelMap> {
+        let mut cm = ChannelMap::default();
+        let r: *mut ffi::pa_channel_map = unsafe {
+            ffi::pa_channel_map_init_auto(&mut cm, ch, def)
+        };
+        if r.is_null() {
+            None
+        } else {
+            Some(cm)
+        }
+    }
     fn can_balance(&self) -> bool {
         unsafe { ffi::pa_channel_map_can_balance(self) > 0 }
     }
 }
 
 pub trait ProplistExt {
     fn proplist(&self) -> Proplist;
 }
--- a/media/libcubeb/cubeb-pulse-rs/src/backend/stream.rs
+++ b/media/libcubeb/cubeb-pulse-rs/src/backend/stream.rs
@@ -76,16 +76,32 @@ fn layout_to_channel_map(layout: Channel
     let mut cm = pulse::ChannelMap::init();
     for (i, channel) in channel_layout_iter(layout).enumerate() {
         cm.map[i] = cubeb_channel_to_pa_channel(channel.into());
     }
     cm.channels = layout.num_channels() as _;
     cm
 }
 
+fn default_layout_for_channels(ch: u32) -> ChannelLayout {
+    match ch {
+        1 => ChannelLayout::MONO,
+        2 => ChannelLayout::STEREO,
+        3 => ChannelLayout::_3F,
+        4 => ChannelLayout::QUAD,
+        5 => ChannelLayout::_3F2,
+        6 => ChannelLayout::_3F_LFE
+             | ChannelLayout::SIDE_LEFT
+             | ChannelLayout::SIDE_RIGHT,
+        7 => ChannelLayout::_3F3R_LFE,
+        8 => ChannelLayout::_3F4_LFE,
+        _ => panic!("channel must be between 1 to 8.")
+    }
+}
+
 pub struct Device(ffi::cubeb_device);
 
 impl Drop for Device {
     fn drop(&mut self) {
         unsafe {
             if !self.0.input_name.is_null() {
                 let _ = CString::from_raw(self.0.input_name as *mut _);
             }
@@ -656,17 +672,25 @@ impl<'ctx> PulseStream<'ctx> {
 
         let ss = pulse::SampleSpec {
             channels: stream_params.channels() as u8,
             format: fmt.into(),
             rate: stream_params.rate(),
         };
 
         let cm: Option<pa_channel_map> = match stream_params.layout() {
-            ChannelLayout::UNDEFINED => None,
+            ChannelLayout::UNDEFINED =>
+                if stream_params.channels() <= 8
+                  && pulse::ChannelMap::init_auto(stream_params.channels(), PA_CHANNEL_MAP_DEFAULT).is_none() {
+                    cubeb_log!("Layout undefined and PulseAudio's default layout has not been configured, guess one.");
+                    Some(layout_to_channel_map(default_layout_for_channels(stream_params.channels())))
+                } else {
+                    cubeb_log!("Layout undefined, PulseAudio will use its default.");
+                    None
+                },
             _ => Some(layout_to_channel_map(stream_params.layout())),
         };
 
         let stream = pulse::Stream::new(context, stream_name.unwrap(), &ss, cm.as_ref());
 
         match stream {
             None => Err(Error::error()),
             Some(stm) => Ok(stm),