Bug 1501148 - Introduce portable PlatformHandleType to AudioIPC and use it. r=chunmin
authorMatthew Gregan <kinetik@flim.org>
Tue, 23 Oct 2018 16:36:41 +1300
changeset 490750 69e4a961b4e4b21548dba0c2f3a80e216258fb50
parent 490749 1e036ba2e247a79a10dc8f6841b2992aafd711e4
child 490751 74f6186ded6d62b5cfd170cc099acf9d11419382
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewerschunmin
bugs1501148
milestone65.0a1
Bug 1501148 - Introduce portable PlatformHandleType to AudioIPC and use it. r=chunmin
media/audioipc/README_MOZILLA
media/audioipc/audioipc/src/codec.rs
media/audioipc/audioipc/src/lib.rs
media/audioipc/client/src/lib.rs
media/audioipc/server/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 3d716fe897ccb3ea43a2af0c794ea57c433400d7 (2018-07-30 08:51:04 +1200)
+The git commit ID used was 709eeb98ce93d949f05f7ecd8a7f15162b44dfad (2018-10-23 16:40:20 +1300)
--- a/media/audioipc/audioipc/src/codec.rs
+++ b/media/audioipc/audioipc/src/codec.rs
@@ -159,17 +159,17 @@ where
             return Err(io::Error::new(
                 io::ErrorKind::InvalidInput,
                 "encoded message too big",
             ));
         }
 
         buf.reserve((encoded_len + 2) as usize);
 
-        buf.put_u16::<LittleEndian>(encoded_len as u16);
+        buf.put_u16_le(encoded_len as u16);
 
         if let Err(e) = bincode::config()
             .limit(encoded_len)
             .serialize_into::<_, Self::In>(&mut buf.writer(), &item)
         {
             match *e {
                 bincode::ErrorKind::Io(e) => return Err(e),
                 _ => return Err(io::Error::new(io::ErrorKind::Other, *e)),
--- a/media/audioipc/audioipc/src/lib.rs
+++ b/media/audioipc/audioipc/src/lib.rs
@@ -47,16 +47,23 @@ use libc::MSG_CMSG_CLOEXEC;
 pub use messages::{ClientMessage, ServerMessage};
 use std::env::temp_dir;
 use std::io;
 use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
 use std::path::PathBuf;
 #[cfg(not(target_os = "linux"))]
 const MSG_CMSG_CLOEXEC: libc::c_int = 0;
 
+// This must match the definition of
+// ipc::FileDescriptor::PlatformHandleType in Gecko.
+#[cfg(target_os = "windows")]
+pub type PlatformHandleType = *mut std::os::raw::c_void;
+#[cfg(not(target_os = "windows"))]
+pub type PlatformHandleType = libc::c_int;
+
 // Extend sys::os::unix::net::UnixStream to support sending and receiving a single file desc.
 // We can extend UnixStream by using traits, eliminating the need to introduce a new wrapped
 // UnixStream type.
 pub trait RecvMsg {
     fn recv_msg(
         &mut self,
         iov: &mut [&mut IoVec],
         cmsg: &mut [u8],
--- a/media/audioipc/client/src/lib.rs
+++ b/media/audioipc/client/src/lib.rs
@@ -15,31 +15,32 @@ extern crate log;
 extern crate tokio_core;
 extern crate tokio_uds;
 
 #[macro_use]
 mod send_recv;
 mod context;
 mod stream;
 
+use audioipc::PlatformHandleType;
 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 server_connection: PlatformHandleType,
     pub pool_size: usize,
     pub stack_size: usize,
     pub thread_create_callback: Option<extern "C" fn(*const ::std::os::raw::c_char)>,
 }
 
 #[derive(Clone, Copy, Debug)]
 struct CpuPoolInitParams {
     pub pool_size: usize,
--- a/media/audioipc/server/src/lib.rs
+++ b/media/audioipc/server/src/lib.rs
@@ -17,16 +17,17 @@ extern crate tokio_uds;
 use audioipc::codec::LengthDelimitedCodec;
 use audioipc::core;
 use audioipc::fd_passing::{framed_with_fds, FramedWithFds};
 use audioipc::frame::{framed, Framed};
 use audioipc::messages::{CallbackReq, CallbackResp, ClientMessage, Device, DeviceInfo,
                          ServerMessage, StreamCreate, StreamInitParams, StreamParams};
 use audioipc::rpc;
 use audioipc::shm::{SharedMemReader, SharedMemWriter};
+use audioipc::PlatformHandleType;
 use cubeb::ffi;
 use futures::future::{self, FutureResult};
 use futures::sync::oneshot;
 use futures::Future;
 use std::cell::RefCell;
 use std::convert::From;
 use std::error::Error;
 use std::ffi::{CStr, CString};
@@ -482,17 +483,17 @@ fn run() -> Result<ServerWrapper> {
 pub extern "C" fn audioipc_server_start() -> *mut c_void {
     match run() {
         Ok(server) => Box::into_raw(Box::new(server)) as *mut _,
         Err(_) => ptr::null_mut() as *mut _,
     }
 }
 
 #[no_mangle]
-pub extern "C" fn audioipc_server_new_client(p: *mut c_void) -> libc::c_int {
+pub extern "C" fn audioipc_server_new_client(p: *mut c_void) -> PlatformHandleType {
     let (wait_tx, wait_rx) = oneshot::channel();
     let wrapper: &ServerWrapper = unsafe { &*(p as *mut _) };
 
     let cb_remote = wrapper.callback_thread.remote();
 
     // We create a pair of connected unix domain sockets. One socket is
     // registered with the reactor core, the other is returned to the
     // caller.