Bug 1399978 - Update cubeb-pulse-rs to git commit 2e22e53. r?kinetik draft
authorDan Glastonbury <dglastonbury@mozilla.com>
Mon, 25 Sep 2017 15:23:30 +1000
changeset 670223 25306163fdb34f22ea5a0a7803c1b56a53a89ad0
parent 669596 7e962631ba4298bcefa571008661983d77c3e652
child 733175 f25a0042561a2fd4c27c44009e95fba4035c70b0
push id81565
push userbmo:dglastonbury@mozilla.com
push dateTue, 26 Sep 2017 03:47:28 +0000
reviewerskinetik
bugs1399978
milestone58.0a1
Bug 1399978 - Update cubeb-pulse-rs to git commit 2e22e53. r?kinetik MozReview-Commit-ID: INksO0nbT1F
media/libcubeb/cubeb-pulse-rs/README_MOZILLA
media/libcubeb/cubeb-pulse-rs/pulse-rs/src/context.rs
media/libcubeb/cubeb-pulse-rs/src/backend/context.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 a386d91d7f34e6d3a949ee4fa44e848e29634587 (2017-09-05 13:34:32 +1000)
+The git commit ID used was 2e22e5359000f11c47346c54b34182bb350fe9d3 (2017-09-26 15:30:09 +1300)
--- a/media/libcubeb/cubeb-pulse-rs/pulse-rs/src/context.rs
+++ b/media/libcubeb/cubeb-pulse-rs/pulse-rs/src/context.rs
@@ -206,18 +206,20 @@ impl Context {
 
             result
         }
 
         op_or_err!(self,
                    ffi::pa_context_get_server_info(self.raw_mut(), Some(wrapped::<CB>), userdata))
     }
 
-    pub fn get_sink_info_by_name<CB>(&self, name: &CStr, _: CB, userdata: *mut c_void) -> Result<Operation>
-        where CB: Fn(&Context, *const SinkInfo, i32, *mut c_void)
+    pub fn get_sink_info_by_name<'str, CS, CB>(&self, name: CS, _: CB, userdata: *mut c_void) -> Result<Operation>
+    where
+        CB: Fn(&Context, *const SinkInfo, i32, *mut c_void),
+        CS: Into<Option<&'str CStr>>,
     {
         debug_assert_eq!(::std::mem::size_of::<CB>(), 0);
 
         // See: A note about `wrapped` functions
         unsafe extern "C" fn wrapped<F>(c: *mut ffi::pa_context,
                                         info: *const ffi::pa_sink_info,
                                         eol: c_int,
                                         userdata: *mut c_void)
@@ -227,17 +229,20 @@ impl Context {
             let ctx = context::from_raw_ptr(c);
             let result = uninitialized::<F>()(&ctx, info, eol, userdata);
             forget(ctx);
 
             result
         }
 
         op_or_err!(self,
-                   ffi::pa_context_get_sink_info_by_name(self.raw_mut(), name.as_ptr(), Some(wrapped::<CB>), userdata))
+                   ffi::pa_context_get_sink_info_by_name(self.raw_mut(),
+                                                        name.into().unwrap_cstr(),
+                                                        Some(wrapped::<CB>),
+                                                        userdata))
     }
 
     pub fn get_sink_info_list<CB>(&self, _: CB, userdata: *mut c_void) -> Result<Operation>
         where CB: Fn(&Context, *const SinkInfo, i32, *mut c_void)
     {
         debug_assert_eq!(::std::mem::size_of::<CB>(), 0);
 
         // See: A note about `wrapped` functions
--- a/media/libcubeb/cubeb-pulse-rs/src/backend/context.rs
+++ b/media/libcubeb/cubeb-pulse-rs/src/backend/context.rs
@@ -129,17 +129,17 @@ impl Context {
                                                      sample_spec: info.sample_spec,
                                                      channel_map: info.channel_map,
                                                      flags: flags,
                                                  });
                 }
                 ctx.mainloop.signal();
             }
 
-            let _ = context.get_sink_info_by_name(unsafe { CStr::from_ptr(info.default_sink_name) },
+            let _ = context.get_sink_info_by_name(try_cstr_from(info.default_sink_name),
                                                   sink_info_cb,
                                                   u);
         }
 
         let name = super::try_cstr_from(name).map(|s| s.to_owned());
         let mut ctx = try!(Context::_new(name));
 
         if ctx.mainloop.start().is_err() {
@@ -157,17 +157,16 @@ impl Context {
          * which is responsible for initializing default_sink_info
          * and signalling the mainloop to end the wait. */
         let user_data: *mut c_void = ctx.as_mut() as *mut _ as *mut _;
         if let Some(ref context) = ctx.context {
             if let Ok(o) = context.get_server_info(server_info_cb, user_data) {
                 ctx.operation_wait(None, &o);
             }
         }
-        assert!(ctx.default_sink_info.is_some());
         ctx.mainloop.unlock();
 
         // Return the result.
         Ok(ctx)
     }
 
     pub fn destroy(&mut self) {
         self.context_destroy();
@@ -227,24 +226,27 @@ impl Context {
         match self.default_sink_info {
             Some(ref info) => Ok(channel_map_to_layout(&info.channel_map)),
             None => Err(cubeb::ERROR),
         }
     }
 
     pub fn enumerate_devices(&self, devtype: cubeb::DeviceType) -> Result<cubeb::DeviceCollection> {
         fn add_output_device(_: &pulse::Context, i: *const pulse::SinkInfo, eol: i32, user_data: *mut c_void) {
+            let mut list_data = unsafe { &mut *(user_data as *mut PulseDevListData) };
+            let ctx = &(*list_data.context);
+
             if eol != 0 {
+                ctx.mainloop.signal();
                 return;
             }
 
             debug_assert!(!i.is_null());
             debug_assert!(!user_data.is_null());
 
-            let mut list_data = unsafe { &mut *(user_data as *mut PulseDevListData) };
             let info = unsafe { &*i };
 
             let group_id = match info.proplist().gets("sysfs.path") {
                 Some(p) => p.to_owned().into_raw(),
                 _ => ptr::null_mut(),
             };
 
             let vendor_name = match info.proplist().gets("device.vendor.name") {
@@ -256,17 +258,16 @@ impl Context {
             let info_description = unsafe { CStr::from_ptr(info.description) }.to_owned();
 
             let preferred = if *info_name == *list_data.default_sink_name {
                 cubeb::DEVICE_PREF_ALL
             } else {
                 cubeb::DevicePref::empty()
             };
 
-            let ctx = &(*list_data.context);
             let device_id = ctx.devids.borrow_mut().add(info_name);
             let friendly_name = info_description.into_raw();
             let devinfo = cubeb::DeviceInfo {
                 device_id: device_id,
                 devid: device_id as cubeb::DeviceId,
                 friendly_name: friendly_name,
                 group_id: group_id,
                 vendor_name: vendor_name,
@@ -278,29 +279,30 @@ impl Context {
                 max_channels: info.channel_map.channels as u32,
                 min_rate: 1,
                 max_rate: PA_RATE_MAX,
                 default_rate: info.sample_spec.rate,
                 latency_lo: 0,
                 latency_hi: 0,
             };
             list_data.devinfo.push(devinfo);
-
-            ctx.mainloop.signal();
         }
 
         fn add_input_device(_: &pulse::Context, i: *const pulse::SourceInfo, eol: i32, user_data: *mut c_void) {
+            let mut list_data = unsafe { &mut *(user_data as *mut PulseDevListData) };
+            let ctx = &(*list_data.context);
+
             if eol != 0 {
+                ctx.mainloop.signal();
                 return;
             }
 
             debug_assert!(!user_data.is_null());
             debug_assert!(!i.is_null());
 
-            let mut list_data = unsafe { &mut *(user_data as *mut PulseDevListData) };
             let info = unsafe { &*i };
 
             let group_id = match info.proplist().gets("sysfs.path") {
                 Some(p) => p.to_owned().into_raw(),
                 _ => ptr::null_mut(),
             };
 
             let vendor_name = match info.proplist().gets("device.vendor.name") {
@@ -312,17 +314,16 @@ impl Context {
             let info_description = unsafe { CStr::from_ptr(info.description) }.to_owned();
 
             let preferred = if *info_name == *list_data.default_source_name {
                 cubeb::DEVICE_PREF_ALL
             } else {
                 cubeb::DevicePref::empty()
             };
 
-            let ctx = &(*list_data.context);
             let device_id = ctx.devids.borrow_mut().add(info_name);
             let friendly_name = info_description.into_raw();
             let devinfo = cubeb::DeviceInfo {
                 device_id: device_id,
                 devid: device_id as cubeb::DeviceId,
                 friendly_name: friendly_name,
                 group_id: group_id,
                 vendor_name: vendor_name,
@@ -336,24 +337,27 @@ impl Context {
                 max_rate: PA_RATE_MAX,
                 default_rate: info.sample_spec.rate,
                 latency_lo: 0,
                 latency_hi: 0,
             };
 
             list_data.devinfo.push(devinfo);
 
-            ctx.mainloop.signal();
         }
 
         fn default_device_names(_: &pulse::Context, info: &pulse::ServerInfo, user_data: *mut c_void) {
             let list_data = unsafe { &mut *(user_data as *mut PulseDevListData) };
 
-            list_data.default_sink_name = unsafe { CStr::from_ptr(info.default_sink_name) }.to_owned();
-            list_data.default_source_name = unsafe { CStr::from_ptr(info.default_source_name) }.to_owned();
+            list_data.default_sink_name = super::try_cstr_from(info.default_sink_name)
+                .map(|s| s.to_owned())
+                .unwrap_or_default();
+            list_data.default_source_name = super::try_cstr_from(info.default_source_name)
+                .map(|s| s.to_owned())
+                .unwrap_or_default();
 
             (*list_data.context).mainloop.signal();
         }
 
         let mut user_data = PulseDevListData::new(self);
 
         if let Some(ref context) = self.context {
             self.mainloop.lock();