let params = AUDIOIPC_INIT_PARAMS.with(|p| p.replace(None).unwrap()); let thread_create_callback = params.thread_create_callback; let thread_destroy_callback = params.thread_destroy_callback;
let server_connection = unsafe { sys::Pipe::from_raw_handle(PlatformHandle::new(params.server_connection)) };
let rpc_thread = ipccore::EventLoopThread::new( "AudioIPC Client RPC".to_string(),
None, move || register_thread(thread_create_callback), move || unregister_thread(thread_destroy_callback),
)
.map_err(|_| Error::default())?; let rpc = rpc_thread
.handle()
.bind_client::<CubebClient>(server_connection)
.map_err(|_| Error::default())?; let rpc2 = rpc.clone();
// Don't let errors bubble from here. Later calls against this context // 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 = CString::new(backend_id).expect("backend_id query failed");
fn enumerate_devices(
&mutself,
devtype: DeviceType,
collection: &DeviceCollectionRef,
) -> Result<()> {
assert_not_in_callback(); let v: Vec<ffi::cubeb_device_info> = send_recv!( self.rpc(), ContextGetDeviceEnumeration(devtype.bits()) => ContextEnumeratedDevices())?
.into_iter()
.map(|i| i.into())
.collect(); letmut vs = v.into_boxed_slice(); let coll = unsafe { &mut *collection.as_ptr() };
coll.device = vs.as_mut_ptr();
coll.count = vs.len(); // Giving away the memory owned by vs. Don't free it! // Reclaimed in `device_collection_destroy`.
mem::forget(vs);
Ok(())
}
fn device_collection_destroy(&mutself, collection: &='color:red'>mut DeviceCollectionRef) -> Result<()> {
assert_not_in_callback(); unsafe { let coll = &mut *collection.as_ptr(); letmut devices = Vec::from_raw_parts(coll.device, coll.count, coll.count); for dev in &mut devices { if !dev.device_id.is_null() { let _ = CString::from_raw(dev.device_id as *mut _);
} if !dev.group_id.is_null() { let _ = CString::from_raw(dev.group_id as *mut _);
} if !dev.vendor_name.is_null() { let _ = CString::from_raw(dev.vendor_name as *mut _);
} if !dev.friendly_name.is_null() { let _ = CString::from_raw(dev.friendly_name as *mut _);
}
}
coll.device = ptr::null_mut();
coll.count = 0;
Ok(())
}
}
fn stream_init(
&mutself,
stream_name: Option<&CStr>,
input_device: DeviceId,
input_stream_params: Option<&StreamParamsRef>,
output_device: DeviceId,
output_stream_params: Option<&StreamParamsRef>,
latency_frames: u32, // These params aren't sent to the server
data_callback: ffi::cubeb_data_callback,
state_callback: ffi::cubeb_state_callback,
user_ptr: *mut c_void,
) -> Result<Stream> {
assert_not_in_callback();
let stream_name = stream_name.map(|name| name.to_bytes_with_nul().to_vec());
let input_stream_params = input_stream_params.map(messages::StreamParams::from); let output_stream_params = output_stream_params.map(messages::StreamParams::from);
let init_params = messages::StreamInitParams {
stream_name,
input_device: input_device as usize,
input_stream_params,
output_device: output_device as usize,
output_stream_params,
latency_frames,
};
stream::init(self, init_params, data_callback, state_callback, user_ptr)
}
if !self.device_collection_rpc { letmut fd = send_recv!(self.rpc(),
ContextSetupDeviceCollectionCallback =>
ContextSetupDeviceCollectionCallback())?;
let stream = unsafe { sys::Pipe::from_raw_handle(fd.platform_handle.take_handle()) };
let server = DeviceCollectionServer {
input_device_callback: self.input_device_callback.clone(),
output_device_callback: self.output_device_callback.clone(),
};
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.