Struct cubeb::ContextRef

source ·
pub struct ContextRef(/* private fields */);

Implementations§

source§

impl ContextRef

source

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.

source

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.

source

pub fn as_ptr(&self) -> *mut cubeb

source§

impl ContextRef

source

pub fn backend_id(&self) -> &str

Examples found in repository?
examples/common/mod.rs (line 16)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
pub fn init<T: Into<Vec<u8>>>(ctx_name: T) -> Result<Context> {
    let backend = match env::var("CUBEB_BACKEND") {
        Ok(s) => Some(s),
        Err(_) => None,
    };

    let ctx_name = CString::new(ctx_name).unwrap();
    let ctx = Context::init(Some(ctx_name.as_c_str()), None);
    if let Ok(ref ctx) = ctx {
        if let Some(ref backend) = backend {
            let ctx_backend = ctx.backend_id();
            if backend != ctx_backend {
                let stderr = io::stderr();
                let mut handle = stderr.lock();

                writeln!(
                    handle,
                    "Requested backend `{}', got `{}'",
                    backend, ctx_backend
                )
                .unwrap();
            }
        }
    }

    ctx
}
More examples
Hide additional examples
examples/devices.rs (line 94)
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
fn main() {
    let ctx = common::init("Cubeb audio test").expect("Failed to create cubeb context");

    println!("Enumerating input devices for backend {}", ctx.backend_id());

    let devices = match ctx.enumerate_devices(DeviceType::INPUT) {
        Ok(devices) => devices,
        Err(e) if e.code() == cubeb::ErrorCode::NotSupported => {
            println!("Device enumeration not support for this backend.");
            return;
        }
        Err(e) => {
            println!("Error enumerating devices: {}", e);
            return;
        }
    };

    println!("Found {} input devices", devices.len());
    for d in devices.iter() {
        print_device_info(d);
    }

    println!(
        "Enumerating output devices for backend {}",
        ctx.backend_id()
    );

    let devices = match ctx.enumerate_devices(DeviceType::OUTPUT) {
        Ok(devices) => devices,
        Err(e) => {
            println!("Error enumerating devices: {}", e);
            return;
        }
    };

    println!("Found {} output devices", devices.len());
    for d in devices.iter() {
        print_device_info(d);
    }
}
source

pub fn backend_id_bytes(&self) -> &[u8]

source

pub fn max_channel_count(&self) -> Result<u32, Error>

source

pub fn min_latency(&self, params: &StreamParamsRef) -> Result<u32, Error>

source

pub fn preferred_sample_rate(&self) -> Result<u32, Error>

source

pub fn supported_input_processing_params( &self ) -> Result<InputProcessingParams, Error>

source

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.

source

pub fn enumerate_devices( &self, devtype: DeviceType ) -> Result<DeviceCollection<'_>, Error>

Examples found in repository?
examples/devices.rs (line 96)
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
fn main() {
    let ctx = common::init("Cubeb audio test").expect("Failed to create cubeb context");

    println!("Enumerating input devices for backend {}", ctx.backend_id());

    let devices = match ctx.enumerate_devices(DeviceType::INPUT) {
        Ok(devices) => devices,
        Err(e) if e.code() == cubeb::ErrorCode::NotSupported => {
            println!("Device enumeration not support for this backend.");
            return;
        }
        Err(e) => {
            println!("Error enumerating devices: {}", e);
            return;
        }
    };

    println!("Found {} input devices", devices.len());
    for d in devices.iter() {
        print_device_info(d);
    }

    println!(
        "Enumerating output devices for backend {}",
        ctx.backend_id()
    );

    let devices = match ctx.enumerate_devices(DeviceType::OUTPUT) {
        Ok(devices) => devices,
        Err(e) => {
            println!("Error enumerating devices: {}", e);
            return;
        }
    };

    println!("Found {} output devices", devices.len());
    for d in devices.iter() {
        print_device_info(d);
    }
}
source

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

source§

fn as_ref(&self) -> &ContextRef

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Borrow<ContextRef> for Context

source§

fn borrow(&self) -> &ContextRef

Immutably borrows from an owned value. Read more
source§

impl Debug for ContextRef

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.