Bug 1446233 - P1: Update AudioIPC to commit b933866. r=kinetik
authorDan Glastonbury <dan.glastonbury@gmail.com>
Thu, 08 Mar 2018 15:20:23 +1000
changeset 463910 706096f3276a0dd2e3beaadf32efe57d5ebbaf14
parent 463909 73958e9bfd07b97e2030315ac61e4f2772ce3705
child 463911 4e337c4c8c2fb1d336c0297f005d4f860b0d35db
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskinetik
bugs1446233
milestone61.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 1446233 - P1: Update AudioIPC to commit b933866. r=kinetik MozReview-Commit-ID: FxWVwbHUPkv
media/audioipc/README_MOZILLA
media/audioipc/client/Cargo.toml
media/audioipc/client/src/context.rs
media/audioipc/client/src/lib.rs
--- a/media/audioipc/README_MOZILLA
+++ b/media/audioipc/README_MOZILLA
@@ -1,12 +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 2a48416231f906ad797d3a94ca4719963c7b9fb4 (2018-03-22 11:18:36 +1000)
-A custom version was creating excluding commits:
-ead320ae24fdf8540efa909f35bec9b78925186a
-b93386611d7d9689c4f0177a4704f0adc16bc2d1
-94eb08a062e1e84e867c20bd56cd250c8aeec7ce
+The git commit ID used was b93386611d7d9689c4f0177a4704f0adc16bc2d1 (2018-03-09 14:45:24 +1000)
--- a/media/audioipc/client/Cargo.toml
+++ b/media/audioipc/client/Cargo.toml
@@ -7,13 +7,13 @@ authors = [
         ]
 description = "Cubeb Backend for talking to remote cubeb server."
 
 [dependencies]
 audioipc = { path="../audioipc" }
 cubeb-backend = "0.5"
 foreign-types = "0.3"
 futures = { version="0.1.18", default-features=false, features=["use_std"] }
-futures-cpupool = { version="0.1.5", default-features=false }
+futures-cpupool = { version="0.1.8", default-features=false }
 libc = "0.2"
 log = "^0.3.6"
 tokio-core = "0.1"
 tokio-uds = "0.1.7"
--- a/media/audioipc/client/src/context.rs
+++ b/media/audioipc/client/src/context.rs
@@ -1,14 +1,14 @@
 // Copyright © 2017 Mozilla Foundation
 //
 // This program is made available under an ISC-style license.  See the
 // accompanying file LICENSE for details
 
-use ClientStream;
+use {ClientStream, CPUPOOL_INIT_PARAMS, G_SERVER_FD};
 use assert_not_in_callback;
 use audioipc::{messages, ClientMessage, ServerMessage};
 use audioipc::{core, rpc};
 use audioipc::codec::LengthDelimitedCodec;
 use audioipc::fd_passing::{framed_with_fds, FramedWithFds};
 use cubeb_backend::{ffi, Context, ContextOps, DeviceCollectionRef, DeviceId, DeviceType, Error,
                     Ops, Result, Stream, StreamParams, StreamParamsRef};
 use futures::Future;
@@ -64,17 +64,17 @@ impl ClientContext {
     pub fn cpu_pool(&self) -> CpuPool {
         self.cpu_pool.clone()
     }
 }
 
 // TODO: encapsulate connect, etc inside audioipc.
 fn open_server_stream() -> Result<net::UnixStream> {
     unsafe {
-        if let Some(fd) = super::G_SERVER_FD {
+        if let Some(fd) = G_SERVER_FD {
             return Ok(net::UnixStream::from_raw_fd(fd));
         }
 
         Err(Error::default())
     }
 }
 
 impl ContextOps for ClientContext {
@@ -108,19 +108,24 @@ impl ContextOps for ClientContext {
                         io::ErrorKind::Other,
                         "Failed to open stream and create rpc.",
                     )
                 })
         }));
 
         let rpc = t!(rx_rpc.recv());
 
-        let cpupool = futures_cpupool::Builder::new()
-            .name_prefix("AudioIPC")
-            .create();
+        let cpupool = CPUPOOL_INIT_PARAMS.with(|p| {
+            let params = p.replace(None).unwrap();
+            futures_cpupool::Builder::new()
+                .name_prefix("AudioIPC")
+                .pool_size(params.pool_size)
+                .stack_size(params.stack_size)
+                .create()
+        });
 
         let ctx = Box::new(ClientContext {
             _ops: &CLIENT_OPS as *const _,
             rpc: rpc,
             core: core,
             cpu_pool: cpupool,
         });
         Ok(unsafe { Context::from_ptr(Box::into_raw(ctx) as *mut _) })
@@ -251,17 +256,17 @@ impl ContextOps for ClientContext {
     }
 }
 
 impl Drop for ClientContext {
     fn drop(&mut self) {
         debug!("ClientContext drop...");
         let _ = send_recv!(self.rpc(), ClientDisconnect => ClientDisconnected);
         unsafe {
-            if super::G_SERVER_FD.is_some() {
+            if G_SERVER_FD.is_some() {
                 libc::close(super::G_SERVER_FD.take().unwrap());
             }
         }
     }
 }
 
 impl fmt::Debug for ClientContext {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
--- a/media/audioipc/client/src/lib.rs
+++ b/media/audioipc/client/src/lib.rs
@@ -21,42 +21,86 @@ mod context;
 mod stream;
 
 use context::ClientContext;
 use cubeb_backend::{capi, ffi};
 use std::os::raw::{c_char, c_int};
 use std::os::unix::io::RawFd;
 use stream::ClientStream;
 
+type InitParamsTls = std::cell::RefCell<Option<CpuPoolInitParams>>;
+
 thread_local!(static IN_CALLBACK: std::cell::RefCell<bool> = std::cell::RefCell::new(false));
+thread_local!(static CPUPOOL_INIT_PARAMS: InitParamsTls = std::cell::RefCell::new(None));
+
+#[repr(C)]
+#[derive(Clone, Copy, Debug)]
+pub struct AudioIpcInitParams {
+    pub server_connection: c_int,
+    pub pool_size: usize,
+    pub stack_size: usize,
+}
+
+#[derive(Clone, Copy, Debug)]
+struct CpuPoolInitParams {
+    pub pool_size: usize,
+    pub stack_size: usize,
+}
+
+impl CpuPoolInitParams {
+    pub fn init_with(params: &AudioIpcInitParams) -> Self {
+        CpuPoolInitParams {
+            pool_size: params.pool_size,
+            stack_size: params.stack_size,
+        }
+    }
+}
 
 fn set_in_callback(in_callback: bool) {
     IN_CALLBACK.with(|b| {
         assert_eq!(*b.borrow(), !in_callback);
         *b.borrow_mut() = in_callback;
     });
 }
 
 fn assert_not_in_callback() {
     IN_CALLBACK.with(|b| {
         assert_eq!(*b.borrow(), false);
     });
 }
 
+fn set_cpupool_init_params<P>(params: P)
+where
+    P: Into<Option<CpuPoolInitParams>>,
+{
+    CPUPOOL_INIT_PARAMS.with(|p| {
+        *p.borrow_mut() = params.into();
+    });
+}
+
 static mut G_SERVER_FD: Option<RawFd> = None;
 
 #[no_mangle]
 /// Entry point from C code.
 pub unsafe extern "C" fn audioipc_client_init(
     c: *mut *mut ffi::cubeb,
     context_name: *const c_char,
-    server_connection: c_int,
+    init_params: *const AudioIpcInitParams,
 ) -> c_int {
+    if init_params.is_null() {
+        return cubeb_backend::ffi::CUBEB_ERROR;
+    }
+
+    let init_params = &*init_params;
+
     // TODO: Windows portability (for fd).
     // TODO: Better way to pass extra parameters to Context impl.
     if G_SERVER_FD.is_some() {
         panic!("audioipc client's server connection already initialized.");
     }
-    if server_connection >= 0 {
-        G_SERVER_FD = Some(server_connection);
+    if init_params.server_connection >= 0 {
+        G_SERVER_FD = Some(init_params.server_connection);
     }
+
+    let cpupool_init_params = CpuPoolInitParams::init_with(&init_params);
+    set_cpupool_init_params(cpupool_init_params);
     capi::capi_init::<ClientContext>(c, context_name)
 }