Bug 1446233 - P1: Update AudioIPC to commit b933866. r=kinetik
☠☠ backed out by d2bf7b9c80a7 ☠ ☠
authorDan Glastonbury <dan.glastonbury@gmail.com>
Thu, 08 Mar 2018 15:20:23 +1000
changeset 409579 20301e359a4e73d7c2bf5f1ac7f98366a986d6ae
parent 409578 cbcc7b902237d350cc78ca9b3cd2d04abbf2e7d5
child 409580 6f3488ff7c600cf7737a5d2a33bff97517085910
push id33692
push usernbeleuzu@mozilla.com
push dateFri, 23 Mar 2018 09:49:37 +0000
treeherdermozilla-central@9b72102a99b3 [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: 6Z2eTu5o1yp
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,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 f6c4829f826950fc059dbf7b33e8aa9e20c447a5 (2018-03-07 20:25:18 +0100)
+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
@@ -1,19 +1,19 @@
 [package]
 name = "audioipc-client"
-version = "0.3.0"
+version = "0.4.0"
 authors = [
         "Matthew Gregan <kinetik@flim.org>",
         "Dan Glastonbury <dan.glastonbury@gmail.com>"
         ]
 description = "Cubeb Backend for talking to remote cubeb server."
 
 [dependencies]
 audioipc = { path="../audioipc" }
 cubeb-backend = "0.4"
 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, ChannelLayout, 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 _) })
@@ -260,17 +265,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)
 }