mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-03 23:30:46 +00:00
Bug 1623799 - Update audioipc to 7f7c997e. r=chunmin
Differential Revision: https://phabricator.services.mozilla.com/D67577 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
cd46b4fea7
commit
451e1de678
@ -1 +1 @@
|
||||
# Cubeb Audio Remoting Prototype
|
||||
# Cubeb Audio Remoting Prototype
|
||||
|
@ -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 9e4f94a50e7b94d13b820f36b73ee9d07b4afdc1 (2020-03-10 12:15:37 +1300)
|
||||
The git commit ID used was 7f7c997eb9c311ae19167cffd60ef9421c2b2fa7 (2020-03-20 11:35:26 +1300)
|
||||
|
@ -14,9 +14,10 @@ use std::env::temp_dir;
|
||||
fn open_shm_file(id: &str) -> Result<File> {
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
let id_cstring = std::ffi::CString::new(id).unwrap();
|
||||
unsafe {
|
||||
let r = libc::syscall(libc::SYS_memfd_create,
|
||||
std::ffi::CString::new(id).unwrap().as_ptr(),
|
||||
id_cstring.as_ptr(),
|
||||
0);
|
||||
if r >= 0 {
|
||||
use std::os::unix::io::FromRawFd as _;
|
||||
|
@ -14,10 +14,13 @@ use audioipc::codec::LengthDelimitedCodec;
|
||||
use audioipc::frame::{framed, Framed};
|
||||
use audioipc::platformhandle_passing::{framed_with_platformhandles, FramedWithPlatformHandles};
|
||||
use audioipc::{core, rpc};
|
||||
use audioipc::{messages, messages::DeviceCollectionReq, messages::DeviceCollectionResp, ClientMessage, ServerMessage};
|
||||
use audioipc::{
|
||||
messages, messages::DeviceCollectionReq, messages::DeviceCollectionResp, ClientMessage,
|
||||
ServerMessage,
|
||||
};
|
||||
use cubeb_backend::{
|
||||
ffi, Context, ContextOps, DeviceCollectionRef, DeviceId, DeviceType, Error, Ops, Result, Stream, StreamParams,
|
||||
StreamParamsRef,
|
||||
ffi, Context, ContextOps, DeviceCollectionRef, DeviceId, DeviceType, Error, Ops, Result,
|
||||
Stream, StreamParams, StreamParamsRef,
|
||||
};
|
||||
use futures::Future;
|
||||
use futures_cpupool::{CpuFuture, CpuPool};
|
||||
@ -35,8 +38,10 @@ struct CubebClient;
|
||||
impl rpc::Client for CubebClient {
|
||||
type Request = ServerMessage;
|
||||
type Response = ClientMessage;
|
||||
type Transport =
|
||||
FramedWithPlatformHandles<audioipc::AsyncMessageStream, LengthDelimitedCodec<Self::Request, Self::Response>>;
|
||||
type Transport = FramedWithPlatformHandles<
|
||||
audioipc::AsyncMessageStream,
|
||||
LengthDelimitedCodec<Self::Request, Self::Response>,
|
||||
>;
|
||||
}
|
||||
|
||||
pub const CLIENT_OPS: Ops = capi_new!(ClientContext, ClientStream);
|
||||
@ -136,12 +141,16 @@ impl rpc::Server for DeviceCollectionServer {
|
||||
type Request = DeviceCollectionReq;
|
||||
type Response = DeviceCollectionResp;
|
||||
type Future = CpuFuture<Self::Response, ()>;
|
||||
type Transport = Framed<audioipc::AsyncMessageStream, LengthDelimitedCodec<Self::Response, Self::Request>>;
|
||||
type Transport =
|
||||
Framed<audioipc::AsyncMessageStream, LengthDelimitedCodec<Self::Response, Self::Request>>;
|
||||
|
||||
fn process(&mut self, req: Self::Request) -> Self::Future {
|
||||
match req {
|
||||
DeviceCollectionReq::DeviceChange(device_type) => {
|
||||
trace!("ctx_thread: DeviceChange Callback: device_type={}", device_type);
|
||||
trace!(
|
||||
"ctx_thread: DeviceChange Callback: device_type={}",
|
||||
device_type
|
||||
);
|
||||
|
||||
let devtype = cubeb_backend::DeviceType::from_bits_truncate(device_type);
|
||||
|
||||
@ -157,10 +166,14 @@ impl rpc::Server for DeviceCollectionServer {
|
||||
self.cpu_pool.spawn_fn(move || {
|
||||
run_in_callback(|| {
|
||||
if devtype.contains(cubeb_backend::DeviceType::INPUT) {
|
||||
unsafe { input_cb.unwrap()(ptr::null_mut(), input_user_ptr as *mut c_void) }
|
||||
unsafe {
|
||||
input_cb.unwrap()(ptr::null_mut(), input_user_ptr as *mut c_void)
|
||||
}
|
||||
}
|
||||
if devtype.contains(cubeb_backend::DeviceType::OUTPUT) {
|
||||
unsafe { output_cb.unwrap()(ptr::null_mut(), output_user_ptr as *mut c_void) }
|
||||
unsafe {
|
||||
output_cb.unwrap()(ptr::null_mut(), output_user_ptr as *mut c_void)
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -193,7 +206,8 @@ impl ContextOps for ClientContext {
|
||||
let thread_create_callback = params.thread_create_callback;
|
||||
let thread_destroy_callback = params.thread_destroy_callback;
|
||||
|
||||
let server_stream = unsafe { audioipc::MessageStream::from_raw_fd(params.server_connection) };
|
||||
let server_stream =
|
||||
unsafe { audioipc::MessageStream::from_raw_fd(params.server_connection) };
|
||||
|
||||
let core = core::spawn_thread(
|
||||
"AudioIPC Client RPC",
|
||||
@ -217,8 +231,8 @@ impl ContextOps for ClientContext {
|
||||
// will return errors the caller expects to handle.
|
||||
let _ = send_recv!(rpc, ClientConnect(std::process::id()) => ClientConnected);
|
||||
|
||||
let backend_id =
|
||||
send_recv!(rpc, ContextGetBackendId => ContextBackendId()).unwrap_or_else(|_| "(remote error)".to_string());
|
||||
let backend_id = send_recv!(rpc, ContextGetBackendId => ContextBackendId())
|
||||
.unwrap_or_else(|_| "(remote error)".to_string());
|
||||
let backend_id = CString::new(backend_id).expect("backend_id query failed");
|
||||
|
||||
let cpu_pool = futures_cpupool::Builder::new()
|
||||
@ -263,7 +277,11 @@ impl ContextOps for ClientContext {
|
||||
send_recv!(self.rpc(), ContextGetPreferredSampleRate => ContextPreferredSampleRate())
|
||||
}
|
||||
|
||||
fn enumerate_devices(&mut self, devtype: DeviceType, collection: &DeviceCollectionRef) -> Result<()> {
|
||||
fn enumerate_devices(
|
||||
&mut self,
|
||||
devtype: DeviceType,
|
||||
collection: &DeviceCollectionRef,
|
||||
) -> Result<()> {
|
||||
assert_not_in_callback();
|
||||
let v: Vec<ffi::cubeb_device_info> = match send_recv!(self.rpc(),
|
||||
ContextGetDeviceEnumeration(devtype.bits()) =>
|
||||
@ -286,7 +304,11 @@ impl ContextOps for ClientContext {
|
||||
assert_not_in_callback();
|
||||
unsafe {
|
||||
let coll = &mut *collection.as_ptr();
|
||||
let mut devices = Vec::from_raw_parts(coll.device as *mut ffi::cubeb_device_info, coll.count, coll.count);
|
||||
let mut devices = Vec::from_raw_parts(
|
||||
coll.device as *mut ffi::cubeb_device_info,
|
||||
coll.count,
|
||||
coll.count,
|
||||
);
|
||||
for dev in &mut devices {
|
||||
if !dev.device_id.is_null() {
|
||||
let _ = CString::from_raw(dev.device_id as *mut _);
|
||||
@ -361,7 +383,8 @@ impl ContextOps for ClientContext {
|
||||
ContextSetupDeviceCollectionCallback =>
|
||||
ContextSetupDeviceCollectionCallback())?;
|
||||
|
||||
let stream = unsafe { audioipc::MessageStream::from_raw_fd(fds.platform_handles[0].into_raw()) };
|
||||
let stream =
|
||||
unsafe { audioipc::MessageStream::from_raw_fd(fds.platform_handles[0].into_raw()) };
|
||||
|
||||
// TODO: The lowest comms layer expects exactly 3 PlatformHandles, but we only
|
||||
// need one here. Drop the dummy handles the other side sent us to discard.
|
||||
|
@ -62,7 +62,8 @@ impl rpc::Server for CallbackServer {
|
||||
type Request = CallbackReq;
|
||||
type Response = CallbackResp;
|
||||
type Future = CpuFuture<Self::Response, ()>;
|
||||
type Transport = Framed<audioipc::AsyncMessageStream, LengthDelimitedCodec<Self::Response, Self::Request>>;
|
||||
type Transport =
|
||||
Framed<audioipc::AsyncMessageStream, LengthDelimitedCodec<Self::Response, Self::Request>>;
|
||||
|
||||
fn process(&mut self, req: Self::Request) -> Self::Future {
|
||||
match req {
|
||||
@ -93,7 +94,10 @@ impl rpc::Server for CallbackServer {
|
||||
self.cpu_pool.spawn_fn(move || {
|
||||
// TODO: This is proof-of-concept. Make it better.
|
||||
let input_ptr: *const u8 = match input_shm {
|
||||
Some(shm) => shm.get_slice(nframes as usize * input_frame_size).unwrap().as_ptr(),
|
||||
Some(shm) => shm
|
||||
.get_slice(nframes as usize * input_frame_size)
|
||||
.unwrap()
|
||||
.as_ptr(),
|
||||
None => ptr::null(),
|
||||
};
|
||||
let output_ptr: *mut u8 = match output_shm {
|
||||
@ -169,20 +173,36 @@ impl<'ctx> ClientStream<'ctx> {
|
||||
let rpc = ctx.rpc();
|
||||
let data = send_recv!(rpc, StreamInit(init_params) => StreamCreated())?;
|
||||
|
||||
debug!("token = {}, handles = {:?}", data.token, data.platform_handles);
|
||||
debug!(
|
||||
"token = {}, handles = {:?}",
|
||||
data.token, data.platform_handles
|
||||
);
|
||||
|
||||
let stream = unsafe { audioipc::MessageStream::from_raw_fd(data.platform_handles[0].into_raw()) };
|
||||
let stream =
|
||||
unsafe { audioipc::MessageStream::from_raw_fd(data.platform_handles[0].into_raw()) };
|
||||
|
||||
let input_file = unsafe { data.platform_handles[1].into_file() };
|
||||
let input_shm = if has_input {
|
||||
Some(SharedMemSlice::from(&input_file, audioipc::SHM_AREA_SIZE).unwrap())
|
||||
match SharedMemSlice::from(&input_file, audioipc::SHM_AREA_SIZE) {
|
||||
Ok(shm) => Some(shm),
|
||||
Err(e) => {
|
||||
debug!("Client failed to set up input shmem: {}", e);
|
||||
return Err(Error::error());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let output_file = unsafe { data.platform_handles[2].into_file() };
|
||||
let output_shm = if has_output {
|
||||
Some(SharedMemMutSlice::from(&output_file, audioipc::SHM_AREA_SIZE).unwrap())
|
||||
match SharedMemMutSlice::from(&output_file, audioipc::SHM_AREA_SIZE) {
|
||||
Ok(shm) => Some(shm),
|
||||
Err(e) => {
|
||||
debug!("Client failed to set up output shmem: {}", e);
|
||||
return Err(Error::error());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user