Bug 1539225 - Update AudioIPC to pick up backend selection & context name support. r=chunmin
authorMatthew Gregan <kinetik@flim.org>
Tue, 23 Jul 2019 19:34:52 +0000
changeset 483904 d9eed0a390132dc20e2d0aae58de5eb9ca4110e8
parent 483903 e3dcc1a1bfcbe9ed11923096a2d5e12cc68f2ccb
child 483905 790684b8a27c97bac4bb66338c182e8dfecbbf58
push id36336
push usermalexandru@mozilla.com
push dateWed, 24 Jul 2019 09:54:28 +0000
treeherdermozilla-central@5585edba8fdb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschunmin
bugs1539225
milestone70.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 1539225 - Update AudioIPC to pick up backend selection & context name support. r=chunmin Differential Revision: https://phabricator.services.mozilla.com/D38957
media/audioipc/README_MOZILLA
media/audioipc/server/Cargo.toml
media/audioipc/server/src/lib.rs
media/audioipc/server/src/server.rs
--- a/media/audioipc/README_MOZILLA
+++ b/media/audioipc/README_MOZILLA
@@ -1,8 +1,8 @@
 The source from this directory was copied from the audioipc-2
 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 audioipc-2 git repository is: https://github.com/djg/audioipc-2.git
 
-The git commit ID used was fd56198506287cbe95b7da3fd93665a47ff8dd96 (2019-05-10 10:47:19 +1200)
+The git commit ID used was 1c6e33942d726d71cb911fb8f57138aadf577057 (2019-07-23 15:56:25 +1200)
--- a/media/audioipc/server/Cargo.toml
+++ b/media/audioipc/server/Cargo.toml
@@ -14,12 +14,13 @@ bytes = "0.4"
 lazycell = "^0.4"
 libc = "0.2"
 log = "0.4"
 slab = "0.3.0"
 futures = "0.1.18"
 tokio-core = "0.1"
 tokio-uds = "0.1.7"
 audio_thread_priority = "0.15.0"
+lazy_static = "1.2.0"
 
 [dependencies.error-chain]
 version = "0.11.0"
 default-features = false
--- a/media/audioipc/server/src/lib.rs
+++ b/media/audioipc/server/src/lib.rs
@@ -14,30 +14,46 @@ extern crate bytes;
 extern crate cubeb_core as cubeb;
 extern crate futures;
 extern crate lazycell;
 extern crate libc;
 extern crate slab;
 extern crate tokio_core;
 extern crate tokio_uds;
 extern crate audio_thread_priority;
+#[macro_use]
+extern crate lazy_static;
 
 use audioipc::core;
 use audioipc::platformhandle_passing::framed_with_platformhandles;
 use audioipc::rpc;
 use audioipc::{MessageStream, PlatformHandle, PlatformHandleType};
 use futures::sync::oneshot;
 use futures::Future;
 use std::error::Error;
 use std::os::raw::c_void;
 use std::ptr;
 use audio_thread_priority::promote_current_thread_to_real_time;
+use std::ffi::{CStr, CString};
+use std::sync::Mutex;
 
 mod server;
 
+struct CubebContextParams {
+    context_name: CString,
+    backend_name: Option<CString>,
+}
+
+lazy_static! {
+    static ref G_CUBEB_CONTEXT_PARAMS: Mutex<CubebContextParams> = Mutex::new(CubebContextParams {
+        context_name: CString::new("AudioIPC Server").unwrap(),
+        backend_name: None,
+    });
+}
+
 #[allow(deprecated)]
 pub mod errors {
     error_chain! {
         links {
             AudioIPC(::audioipc::errors::Error, ::audioipc::errors::ErrorKind);
         }
         foreign_links {
             Cubeb(::cubeb::Error);
@@ -88,17 +104,26 @@ fn run() -> Result<ServerWrapper> {
 
     Ok(ServerWrapper {
         core_thread: core_thread,
         callback_thread: callback_thread,
     })
 }
 
 #[no_mangle]
-pub extern "C" fn audioipc_server_start() -> *mut c_void {
+pub extern "C" fn audioipc_server_start(context_name: *const std::os::raw::c_char,
+                                        backend_name: *const std::os::raw::c_char) -> *mut c_void {
+    let mut params = G_CUBEB_CONTEXT_PARAMS.lock().unwrap();
+    if !context_name.is_null() {
+        params.context_name = unsafe { CStr::from_ptr(context_name) }.to_owned();
+    }
+    if !backend_name.is_null() {
+        let backend_string = unsafe { CStr::from_ptr(backend_name) }.to_owned();
+        params.backend_name = Some(backend_string);
+    }
     match run() {
         Ok(server) => Box::into_raw(Box::new(server)) as *mut _,
         Err(_) => ptr::null_mut() as *mut _,
     }
 }
 
 #[no_mangle]
 pub extern "C" fn audioipc_server_new_client(p: *mut c_void) -> PlatformHandleType {
--- a/media/audioipc/server/src/server.rs
+++ b/media/audioipc/server/src/server.rs
@@ -18,40 +18,46 @@ use audioipc::shm::{SharedMemReader, Sha
 use cubeb;
 use cubeb::ffi;
 use futures::future::{self, FutureResult};
 use futures::sync::oneshot;
 use futures::Future;
 use slab;
 use std::cell::RefCell;
 use std::convert::From;
-use std::ffi::{CStr, CString};
+use std::ffi::CStr;
 use std::mem::{size_of, ManuallyDrop};
 use std::os::raw::{c_long, c_void};
 use std::{panic, slice};
 use tokio_core::reactor::Remote;
 
 use errors::*;
 
 fn error(error: cubeb::Error) -> ClientMessage {
     ClientMessage::Error(error.raw_code())
 }
 
 type ContextKey = RefCell<Option<cubeb::Result<cubeb::Context>>>;
-thread_local!(static CONTEXT_KEY:ContextKey = RefCell::new(None));
+thread_local!(static CONTEXT_KEY: ContextKey = RefCell::new(None));
 
 fn with_local_context<T, F>(f: F) -> T
 where
     F: FnOnce(&cubeb::Result<cubeb::Context>) -> T,
 {
     CONTEXT_KEY.with(|k| {
         let mut context = k.borrow_mut();
         if context.is_none() {
-            let name = CString::new("AudioIPC Server").unwrap();
-            *context = Some(cubeb::Context::init(Some(name.as_c_str()), None));
+            let params = super::G_CUBEB_CONTEXT_PARAMS.lock().unwrap();
+            let context_name = Some(params.context_name.as_c_str());
+            let backend_name = if let Some(ref name) = params.backend_name {
+                Some(name.as_c_str())
+            } else {
+                None
+            };
+            *context = Some(cubeb::Context::init(context_name, backend_name));
         }
         f(context.as_ref().unwrap())
     })
 }
 
 // TODO: Remove and let caller allocate based on cubeb backend requirements.
 const SHM_AREA_SIZE: usize = 2 * 1024 * 1024;