diff --git a/media/audioipc/README_MOZILLA b/media/audioipc/README_MOZILLA index b383874540ae..7e672705c91e 100644 --- a/media/audioipc/README_MOZILLA +++ b/media/audioipc/README_MOZILLA @@ -5,4 +5,4 @@ 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) diff --git a/media/audioipc/client/Cargo.toml b/media/audioipc/client/Cargo.toml index dbda32def316..cf113d9efec4 100644 --- a/media/audioipc/client/Cargo.toml +++ b/media/audioipc/client/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "audioipc-client" -version = "0.3.0" +version = "0.4.0" authors = [ "Matthew Gregan ", "Dan Glastonbury " @@ -12,7 +12,7 @@ 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" diff --git a/media/audioipc/client/src/context.rs b/media/audioipc/client/src/context.rs index 3acd459730f6..25a85e32d9d2 100644 --- a/media/audioipc/client/src/context.rs +++ b/media/audioipc/client/src/context.rs @@ -3,7 +3,7 @@ // 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}; @@ -69,7 +69,7 @@ impl ClientContext { // TODO: encapsulate connect, etc inside audioipc. fn open_server_stream() -> Result { unsafe { - if let Some(fd) = super::G_SERVER_FD { + if let Some(fd) = G_SERVER_FD { return Ok(net::UnixStream::from_raw_fd(fd)); } @@ -113,9 +113,14 @@ impl ContextOps for ClientContext { 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 _, @@ -265,7 +270,7 @@ impl Drop for ClientContext { 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()); } } diff --git a/media/audioipc/client/src/lib.rs b/media/audioipc/client/src/lib.rs index d12bc4038f2d..f2cd99362d0f 100644 --- a/media/audioipc/client/src/lib.rs +++ b/media/audioipc/client/src/lib.rs @@ -26,7 +26,33 @@ use std::os::raw::{c_char, c_int}; use std::os::unix::io::RawFd; use stream::ClientStream; +type InitParamsTls = std::cell::RefCell>; + thread_local!(static IN_CALLBACK: std::cell::RefCell = 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| { @@ -41,6 +67,15 @@ fn assert_not_in_callback() { }); } +fn set_cpupool_init_params

(params: P) +where + P: Into>, +{ + CPUPOOL_INIT_PARAMS.with(|p| { + *p.borrow_mut() = params.into(); + }); +} + static mut G_SERVER_FD: Option = None; #[no_mangle] @@ -48,15 +83,24 @@ static mut G_SERVER_FD: Option = None; 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::(c, context_name) }