Bug 1446233 - P1: Update AudioIPC to commit b933866. r=kinetik draft
authorDan Glastonbury <dan.glastonbury@gmail.com>
Thu, 08 Mar 2018 15:20:23 +1000
changeset 771421 e1b522cb288e5427a6522efaeeaf5cc5e2acad2c
parent 771413 28d966d1881897e84a816a7c760e94905741bc85
child 771422 75ffc7ad4cdfbcf7212eb751b4e23ef77c549aee
push id103676
push userbmo:dglastonbury@mozilla.com
push dateFri, 23 Mar 2018 01:08:37 +0000
reviewerskinetik
bugs1446233
milestone61.0a1
Bug 1446233 - P1: Update AudioIPC to commit b933866. r=kinetik MozReview-Commit-ID: 4ZUP1Wu9SgA
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)
 }