pub struct ContextRef(/* private fields */);Implementations§
Source§impl ContextRef
impl ContextRef
Sourcepub unsafe fn from_ptr<'a>(ptr: *mut cubeb) -> &'a ContextRef
pub unsafe fn from_ptr<'a>(ptr: *mut cubeb) -> &'a ContextRef
§Safety
This function is unsafe because it dereferences the given ptr pointer.
The caller should ensure that pointer is valid.
Sourcepub unsafe fn from_ptr_mut<'a>(ptr: *mut cubeb) -> &'a mut ContextRef
pub unsafe fn from_ptr_mut<'a>(ptr: *mut cubeb) -> &'a mut ContextRef
§Safety
This function is unsafe because it dereferences the given ptr pointer.
The caller should ensure that pointer is valid.
pub fn as_ptr(&self) -> *mut cubeb
Source§impl ContextRef
impl ContextRef
Sourcepub fn backend_id(&self) -> &str
pub fn backend_id(&self) -> &str
Examples found in repository?
examples/common/mod.rs (line 16)
6pub fn init<T: Into<Vec<u8>>>(ctx_name: T) -> Result<Context> {
7 let backend = match env::var("CUBEB_BACKEND") {
8 Ok(s) => Some(s),
9 Err(_) => None,
10 };
11
12 let ctx_name = CString::new(ctx_name).unwrap();
13 let ctx = Context::init(Some(ctx_name.as_c_str()), None);
14 if let Ok(ref ctx) = ctx {
15 if let Some(ref backend) = backend {
16 let ctx_backend = ctx.backend_id();
17 if backend != ctx_backend {
18 let stderr = io::stderr();
19 let mut handle = stderr.lock();
20
21 writeln!(
22 handle,
23 "Requested backend `{}', got `{}'",
24 backend, ctx_backend
25 )
26 .unwrap();
27 }
28 }
29 }
30
31 ctx
32}More examples
examples/devices.rs (line 94)
91fn main() {
92 let ctx = common::init("Cubeb audio test").expect("Failed to create cubeb context");
93
94 println!("Enumerating input devices for backend {}", ctx.backend_id());
95
96 let devices = match ctx.enumerate_devices(DeviceType::INPUT) {
97 Ok(devices) => devices,
98 Err(cubeb::Error::NotSupported) => {
99 println!("Device enumeration not support for this backend.");
100 return;
101 }
102 Err(e) => {
103 println!("Error enumerating devices: {}", e);
104 return;
105 }
106 };
107
108 println!("Found {} input devices", devices.len());
109 for d in devices.iter() {
110 print_device_info(d);
111 }
112
113 println!(
114 "Enumerating output devices for backend {}",
115 ctx.backend_id()
116 );
117
118 let devices = match ctx.enumerate_devices(DeviceType::OUTPUT) {
119 Ok(devices) => devices,
120 Err(e) => {
121 println!("Error enumerating devices: {}", e);
122 return;
123 }
124 };
125
126 println!("Found {} output devices", devices.len());
127 for d in devices.iter() {
128 print_device_info(d);
129 }
130}pub fn backend_id_bytes(&self) -> &[u8] ⓘ
pub fn max_channel_count(&self) -> Result<u32, Error>
pub fn min_latency(&self, params: &StreamParamsRef) -> Result<u32, Error>
pub fn preferred_sample_rate(&self) -> Result<u32, Error>
pub fn supported_input_processing_params( &self, ) -> Result<InputProcessingParams, Error>
Sourcepub unsafe fn stream_init(
&self,
stream_name: Option<&CStr>,
input_device: *const c_void,
input_stream_params: Option<&StreamParamsRef>,
output_device: *const c_void,
output_stream_params: Option<&StreamParamsRef>,
latency_frames: u32,
data_callback: Option<unsafe extern "C" fn(*mut cubeb_stream, *mut c_void, *const c_void, *mut c_void, i64) -> i64>,
state_callback: Option<unsafe extern "C" fn(*mut cubeb_stream, *mut c_void, u32)>,
user_ptr: *mut c_void,
) -> Result<Stream, Error>
pub unsafe fn stream_init( &self, stream_name: Option<&CStr>, input_device: *const c_void, input_stream_params: Option<&StreamParamsRef>, output_device: *const c_void, output_stream_params: Option<&StreamParamsRef>, latency_frames: u32, data_callback: Option<unsafe extern "C" fn(*mut cubeb_stream, *mut c_void, *const c_void, *mut c_void, i64) -> i64>, state_callback: Option<unsafe extern "C" fn(*mut cubeb_stream, *mut c_void, u32)>, user_ptr: *mut c_void, ) -> Result<Stream, Error>
§Safety
This function is unsafe because it dereferences the given data_callback, state_callback, and user_ptr pointers.
The caller should ensure those pointers are valid.
Sourcepub fn enumerate_devices(
&self,
devtype: DeviceType,
) -> Result<DeviceCollection<'_>, Error>
pub fn enumerate_devices( &self, devtype: DeviceType, ) -> Result<DeviceCollection<'_>, Error>
Examples found in repository?
examples/devices.rs (line 96)
91fn main() {
92 let ctx = common::init("Cubeb audio test").expect("Failed to create cubeb context");
93
94 println!("Enumerating input devices for backend {}", ctx.backend_id());
95
96 let devices = match ctx.enumerate_devices(DeviceType::INPUT) {
97 Ok(devices) => devices,
98 Err(cubeb::Error::NotSupported) => {
99 println!("Device enumeration not support for this backend.");
100 return;
101 }
102 Err(e) => {
103 println!("Error enumerating devices: {}", e);
104 return;
105 }
106 };
107
108 println!("Found {} input devices", devices.len());
109 for d in devices.iter() {
110 print_device_info(d);
111 }
112
113 println!(
114 "Enumerating output devices for backend {}",
115 ctx.backend_id()
116 );
117
118 let devices = match ctx.enumerate_devices(DeviceType::OUTPUT) {
119 Ok(devices) => devices,
120 Err(e) => {
121 println!("Error enumerating devices: {}", e);
122 return;
123 }
124 };
125
126 println!("Found {} output devices", devices.len());
127 for d in devices.iter() {
128 print_device_info(d);
129 }
130}Sourcepub unsafe fn register_device_collection_changed(
&self,
devtype: DeviceType,
callback: Option<unsafe extern "C" fn(*mut cubeb, *mut c_void)>,
user_ptr: *mut c_void,
) -> Result<(), Error>
pub unsafe fn register_device_collection_changed( &self, devtype: DeviceType, callback: Option<unsafe extern "C" fn(*mut cubeb, *mut c_void)>, user_ptr: *mut c_void, ) -> Result<(), Error>
§Safety
This function is unsafe because it dereferences the given callback and user_ptr pointers.
The caller should ensure those pointers are valid.
Trait Implementations§
Source§impl AsRef<ContextRef> for Context
impl AsRef<ContextRef> for Context
Source§fn as_ref(&self) -> &ContextRef
fn as_ref(&self) -> &ContextRef
Converts this type into a shared reference of the (usually inferred) input type.
Source§impl Borrow<ContextRef> for Context
impl Borrow<ContextRef> for Context
Source§fn borrow(&self) -> &ContextRef
fn borrow(&self) -> &ContextRef
Immutably borrows from an owned value. Read more
Auto Trait Implementations§
impl !Freeze for ContextRef
impl !RefUnwindSafe for ContextRef
impl Send for ContextRef
impl !Sync for ContextRef
impl Unpin for ContextRef
impl UnwindSafe for ContextRef
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more