cubeb_backend/
traits.rs

1// Copyright © 2017 Mozilla Foundation
2//
3// This program is made available under an ISC-style license.  See the
4// accompanying file LICENSE for details.
5
6use cubeb_core::{
7    Context, DeviceCollectionRef, DeviceId, DeviceRef, DeviceType, InputProcessingParams, Result,
8    Stream, StreamParams, StreamParamsRef,
9};
10use ffi;
11use std::ffi::CStr;
12use std::os::raw::c_void;
13
14pub trait ContextOps {
15    fn init(context_name: Option<&CStr>) -> Result<Context>;
16    fn backend_id(&mut self) -> &CStr;
17    fn max_channel_count(&mut self) -> Result<u32>;
18    fn min_latency(&mut self, params: StreamParams) -> Result<u32>;
19    fn preferred_sample_rate(&mut self) -> Result<u32>;
20    fn supported_input_processing_params(&mut self) -> Result<InputProcessingParams>;
21    fn enumerate_devices(
22        &mut self,
23        devtype: DeviceType,
24        collection: &DeviceCollectionRef,
25    ) -> Result<()>;
26    fn device_collection_destroy(&mut self, collection: &mut DeviceCollectionRef) -> Result<()>;
27    #[allow(clippy::too_many_arguments)]
28    fn stream_init(
29        &mut self,
30        stream_name: Option<&CStr>,
31        input_device: DeviceId,
32        input_stream_params: Option<&StreamParamsRef>,
33        output_device: DeviceId,
34        output_stream_params: Option<&StreamParamsRef>,
35        latency_frames: u32,
36        data_callback: ffi::cubeb_data_callback,
37        state_callback: ffi::cubeb_state_callback,
38        user_ptr: *mut c_void,
39    ) -> Result<Stream>;
40    fn register_device_collection_changed(
41        &mut self,
42        devtype: DeviceType,
43        cb: ffi::cubeb_device_collection_changed_callback,
44        user_ptr: *mut c_void,
45    ) -> Result<()>;
46}
47
48pub trait StreamOps {
49    fn start(&mut self) -> Result<()>;
50    fn stop(&mut self) -> Result<()>;
51    fn position(&mut self) -> Result<u64>;
52    fn latency(&mut self) -> Result<u32>;
53    fn input_latency(&mut self) -> Result<u32>;
54    fn set_volume(&mut self, volume: f32) -> Result<()>;
55    fn set_name(&mut self, name: &CStr) -> Result<()>;
56    fn current_device(&mut self) -> Result<&DeviceRef>;
57    fn set_input_mute(&mut self, mute: bool) -> Result<()>;
58    fn set_input_processing_params(&mut self, params: InputProcessingParams) -> Result<()>;
59    fn device_destroy(&mut self, device: &DeviceRef) -> Result<()>;
60    fn register_device_changed_callback(
61        &mut self,
62        device_changed_callback: ffi::cubeb_device_changed_callback,
63    ) -> Result<()>;
64}