Skip to content

Commit e873241

Browse files
committed
Remove cubeb_stream_get_current_device
Following mozilla/cubeb#822 Signed-off-by: Marcin Serwin <[email protected]>
1 parent f2ea00d commit e873241

File tree

9 files changed

+10
-183
lines changed

9 files changed

+10
-183
lines changed

cubeb-api/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ mod stream;
3030
pub use context::*;
3131
// Re-export cubeb_core types
3232
pub use cubeb_core::{
33-
ffi, ChannelLayout, Context, ContextRef, Device, DeviceCollection, DeviceCollectionRef,
34-
DeviceFormat, DeviceId, DeviceInfo, DeviceInfoRef, DeviceRef, DeviceState, DeviceType, Error,
35-
LogLevel, Result, SampleFormat, State, StreamParams, StreamParamsBuilder, StreamParamsRef,
36-
StreamPrefs, StreamRef,
33+
ffi, ChannelLayout, Context, ContextRef, DeviceCollection, DeviceCollectionRef, DeviceFormat,
34+
DeviceId, DeviceInfo, DeviceInfoRef, DeviceState, DeviceType, Error, LogLevel, Result,
35+
SampleFormat, State, StreamParams, StreamParamsBuilder, StreamParamsRef, StreamPrefs,
36+
StreamRef,
3737
};
3838
pub use frame::*;
3939
pub use sample::*;

cubeb-backend/src/capi.rs

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// accompanying file LICENSE for details
55

66
use cubeb_core::{
7-
ffi, DeviceInfo, DeviceRef, DeviceType, InputProcessingParams, StreamParams, StreamParamsRef,
7+
ffi, DeviceInfo, DeviceType, InputProcessingParams, StreamParams, StreamParamsRef,
88
};
99
use std::ffi::CStr;
1010
use std::mem;
@@ -54,11 +54,9 @@ macro_rules! capi_new(
5454
stream_get_input_latency: Some($crate::capi::capi_stream_get_input_latency::<$stm>),
5555
stream_set_volume: Some($crate::capi::capi_stream_set_volume::<$stm>),
5656
stream_set_name: Some($crate::capi::capi_stream_set_name::<$stm>),
57-
stream_get_current_device: Some($crate::capi::capi_stream_get_current_device::<$stm>),
5857
stream_set_input_mute: Some($crate::capi::capi_stream_set_input_mute::<$stm>),
5958
stream_set_input_processing_params:
6059
Some($crate::capi::capi_stream_set_input_processing_params::<$stm>),
61-
stream_device_destroy: Some($crate::capi::capi_stream_device_destroy::<$stm>),
6260
stream_register_device_changed_callback:
6361
Some($crate::capi::capi_stream_register_device_changed_callback::<$stm>),
6462
register_device_collection_changed:
@@ -381,22 +379,6 @@ pub unsafe extern "C" fn capi_stream_set_name<STM: StreamOps>(
381379
}
382380
}
383381

384-
/// # Safety
385-
///
386-
/// Entry point from C code.
387-
///
388-
/// This function is unsafe because it dereferences the given `s` and `device` pointers.
389-
/// The caller should ensure those pointers are valid.
390-
pub unsafe extern "C" fn capi_stream_get_current_device<STM: StreamOps>(
391-
s: *mut ffi::cubeb_stream,
392-
device: *mut *mut ffi::cubeb_device,
393-
) -> i32 {
394-
let stm = &mut *(s as *mut STM);
395-
396-
*device = _try!(stm.current_device()).as_ptr();
397-
ffi::CUBEB_OK
398-
}
399-
400382
/// # Safety
401383
///
402384
/// Entry point from C code.
@@ -427,25 +409,6 @@ pub unsafe extern "C" fn capi_stream_set_input_processing_params<STM: StreamOps>
427409
ffi::CUBEB_OK
428410
}
429411

430-
/// # Safety
431-
///
432-
/// Entry point from C code.
433-
///
434-
/// This function is unsafe because it dereferences the given `s` and `device` pointers.
435-
/// The caller should ensure those pointers are valid.
436-
pub unsafe extern "C" fn capi_stream_device_destroy<STM: StreamOps>(
437-
s: *mut ffi::cubeb_stream,
438-
device: *mut ffi::cubeb_device,
439-
) -> c_int {
440-
let stm = &mut *(s as *mut STM);
441-
if device.is_null() {
442-
return ffi::CUBEB_ERROR_INVALID_PARAMETER;
443-
}
444-
let device = DeviceRef::from_ptr(device);
445-
let _ = stm.device_destroy(device);
446-
ffi::CUBEB_OK
447-
}
448-
449412
/// # Safety
450413
///
451414
/// Entry point from C code.

cubeb-backend/src/ops.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,6 @@ pub struct Ops {
7474
Option<unsafe extern "C" fn(stream: *mut ffi::cubeb_stream, volumes: c_float) -> c_int>,
7575
pub stream_set_name:
7676
Option<unsafe extern "C" fn(stream: *mut ffi::cubeb_stream, name: *const c_char) -> c_int>,
77-
pub stream_get_current_device: Option<
78-
unsafe extern "C" fn(
79-
stream: *mut ffi::cubeb_stream,
80-
device: *mut *mut ffi::cubeb_device,
81-
) -> c_int,
82-
>,
8377
pub stream_set_input_mute:
8478
Option<unsafe extern "C" fn(stream: *mut ffi::cubeb_stream, mute: c_int) -> c_int>,
8579
pub stream_set_input_processing_params: Option<
@@ -88,12 +82,6 @@ pub struct Ops {
8882
params: ffi::cubeb_input_processing_params,
8983
) -> c_int,
9084
>,
91-
pub stream_device_destroy: Option<
92-
unsafe extern "C" fn(
93-
stream: *mut ffi::cubeb_stream,
94-
device: *mut ffi::cubeb_device,
95-
) -> c_int,
96-
>,
9785
pub stream_register_device_changed_callback: Option<
9886
unsafe extern "C" fn(
9987
stream: *mut ffi::cubeb_stream,

cubeb-backend/src/traits.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
// accompanying file LICENSE for details.
55

66
use cubeb_core::{
7-
DeviceId, DeviceInfo, DeviceRef, DeviceType, InputProcessingParams, Result, Stream,
8-
StreamParams, StreamParamsRef,
7+
DeviceId, DeviceInfo, DeviceType, InputProcessingParams, Result, Stream, StreamParams,
8+
StreamParamsRef,
99
};
1010
use ffi;
1111
use std::ffi::CStr;
@@ -49,10 +49,8 @@ pub trait StreamOps {
4949
fn input_latency(&mut self) -> Result<u32>;
5050
fn set_volume(&mut self, volume: f32) -> Result<()>;
5151
fn set_name(&mut self, name: &CStr) -> Result<()>;
52-
fn current_device(&mut self) -> Result<&DeviceRef>;
5352
fn set_input_mute(&mut self, mute: bool) -> Result<()>;
5453
fn set_input_processing_params(&mut self, params: InputProcessingParams) -> Result<()>;
55-
fn device_destroy(&mut self, device: &DeviceRef) -> Result<()>;
5654
fn register_device_changed_callback(
5755
&mut self,
5856
device_changed_callback: ffi::cubeb_device_changed_callback,

cubeb-backend/tests/test_capi.rs

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
extern crate cubeb_backend;
1010

1111
use cubeb_backend::{
12-
ffi, ContextOps, DeviceId, DeviceInfo, DeviceRef, DeviceType, InputProcessingParams, Ops,
13-
Result, Stream, StreamOps, StreamParams, StreamParamsRef,
12+
ffi, ContextOps, DeviceId, DeviceInfo, DeviceType, InputProcessingParams, Ops, Result, Stream,
13+
StreamOps, StreamParams, StreamParamsRef,
1414
};
1515
use std::ffi::CStr;
1616
use std::mem::ManuallyDrop;
@@ -105,9 +105,6 @@ impl StreamOps for TestStream {
105105
assert_eq!(name, CStr::from_bytes_with_nul(b"test\0").unwrap());
106106
Ok(())
107107
}
108-
fn current_device(&mut self) -> Result<&DeviceRef> {
109-
Ok(unsafe { DeviceRef::from_ptr(0xDEAD_BEEF as *mut _) })
110-
}
111108
fn set_input_mute(&mut self, mute: bool) -> Result<()> {
112109
assert_eq!(mute, true);
113110
Ok(())
@@ -116,10 +113,6 @@ impl StreamOps for TestStream {
116113
assert_eq!(params, InputProcessingParams::ECHO_CANCELLATION);
117114
Ok(())
118115
}
119-
fn device_destroy(&mut self, device: &DeviceRef) -> Result<()> {
120-
assert_eq!(device.as_ptr(), 0xDEAD_BEEF as *mut _);
121-
Ok(())
122-
}
123116
fn register_device_changed_callback(
124117
&mut self,
125118
_: ffi::cubeb_device_changed_callback,
@@ -249,17 +242,6 @@ fn test_ops_stream_set_name() {
249242
}
250243
}
251244

252-
#[test]
253-
fn test_ops_stream_current_device() {
254-
let s: *mut ffi::cubeb_stream = get_stream();
255-
let mut device: *mut ffi::cubeb_device = ptr::null_mut();
256-
assert_eq!(
257-
unsafe { OPS.stream_get_current_device.unwrap()(s, &mut device) },
258-
ffi::CUBEB_OK
259-
);
260-
assert_eq!(device, 0xDEAD_BEEF as *mut _);
261-
}
262-
263245
#[test]
264246
fn test_ops_stream_set_input_mute() {
265247
let s: *mut ffi::cubeb_stream = get_stream();

cubeb-core/src/device.rs

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -61,42 +61,6 @@ impl DeviceType {
6161
/// across calls.
6262
pub type DeviceId = ffi::cubeb_devid;
6363

64-
ffi_type_heap! {
65-
/// Audio device description
66-
type CType = ffi::cubeb_device;
67-
#[derive(Debug)]
68-
pub struct Device;
69-
pub struct DeviceRef;
70-
}
71-
72-
impl DeviceRef {
73-
fn get_ref(&self) -> &ffi::cubeb_device {
74-
unsafe { &*self.as_ptr() }
75-
}
76-
77-
/// Gets the output device name.
78-
///
79-
/// May return `None` if there is no output device.
80-
pub fn output_name(&self) -> Option<&str> {
81-
self.output_name_bytes().map(|b| str::from_utf8(b).unwrap())
82-
}
83-
84-
pub fn output_name_bytes(&self) -> Option<&[u8]> {
85-
unsafe { opt_bytes(self.get_ref().output_name) }
86-
}
87-
88-
/// Gets the input device name.
89-
///
90-
/// May return `None` if there is no input device.
91-
pub fn input_name(&self) -> Option<&str> {
92-
self.input_name_bytes().map(|b| str::from_utf8(b).unwrap())
93-
}
94-
95-
pub fn input_name_bytes(&self) -> Option<&[u8]> {
96-
unsafe { opt_bytes(self.get_ref().input_name) }
97-
}
98-
}
99-
10064
ffi_type_stack! {
10165
/// This structure holds the characteristics of an input or output
10266
/// audio device. It is obtained using `enumerate_devices`, which
@@ -223,17 +187,3 @@ impl DeviceInfoRef {
223187
self.get_ref().latency_hi
224188
}
225189
}
226-
227-
#[cfg(test)]
228-
mod tests {
229-
use ffi::cubeb_device;
230-
use Device;
231-
232-
#[test]
233-
fn device_device_ref_same_ptr() {
234-
let ptr: *mut cubeb_device = 0xDEAD_BEEF as *mut _;
235-
let device = unsafe { Device::from_ptr(ptr) };
236-
assert_eq!(device.as_ptr(), ptr);
237-
assert_eq!(device.as_ptr(), device.as_ref().as_ptr());
238-
}
239-
}

cubeb-core/src/stream.rs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
use ffi;
77
use std::ffi::CStr;
88
use std::os::raw::{c_int, c_void};
9-
use std::ptr;
10-
use {ChannelLayout, DeviceRef, Result, SampleFormat};
9+
use {ChannelLayout, Result, SampleFormat};
1110

1211
/// Stream states signaled via `state_callback`.
1312
#[derive(PartialEq, Eq, Clone, Debug, Copy)]
@@ -184,18 +183,6 @@ impl StreamRef {
184183
unsafe { call!(ffi::cubeb_stream_set_name(self.as_ptr(), name.as_ptr())) }
185184
}
186185

187-
/// Get the current output device for this stream.
188-
pub fn current_device(&self) -> Result<&DeviceRef> {
189-
let mut device: *mut ffi::cubeb_device = ptr::null_mut();
190-
unsafe {
191-
call!(ffi::cubeb_stream_get_current_device(
192-
self.as_ptr(),
193-
&mut device
194-
))?;
195-
Ok(DeviceRef::from_ptr(device))
196-
}
197-
}
198-
199186
/// Set the mute state for an input stream.
200187
pub fn set_input_mute(&self, mute: bool) -> Result<()> {
201188
let mute: c_int = if mute { 1 } else { 0 };
@@ -212,16 +199,6 @@ impl StreamRef {
212199
}
213200
}
214201

215-
/// Destroy a cubeb_device structure.
216-
pub fn device_destroy(&self, device: DeviceRef) -> Result<()> {
217-
unsafe {
218-
call!(ffi::cubeb_stream_device_destroy(
219-
self.as_ptr(),
220-
device.as_ptr()
221-
))
222-
}
223-
}
224-
225202
/// Set a callback to be notified when the output device changes.
226203
pub fn register_device_changed_callback(
227204
&self,

cubeb-sys/src/device.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -105,28 +105,6 @@ fn fmt_device_type(t: &cubeb_device_type) -> &'static str {
105105

106106
pub type cubeb_devid = *const c_void;
107107

108-
#[repr(C)]
109-
pub struct cubeb_device {
110-
pub output_name: *mut c_char,
111-
pub input_name: *mut c_char,
112-
}
113-
114-
// Explicit Debug impl to work around bug in ctest
115-
impl Default for cubeb_device {
116-
fn default() -> Self {
117-
unsafe { mem::zeroed() }
118-
}
119-
}
120-
121-
impl fmt::Debug for cubeb_device {
122-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
123-
f.debug_struct("cubeb_device")
124-
.field("output_name", &self.output_name)
125-
.field("input_name", &self.input_name)
126-
.finish()
127-
}
128-
}
129-
130108
#[repr(C)]
131109
pub struct cubeb_device_collection {
132110
pub device: *mut cubeb_device_info,

cubeb-sys/src/stream.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
use callbacks::cubeb_device_changed_callback;
77
use channel::cubeb_channel_layout;
8-
use device::cubeb_device;
98
use format::cubeb_sample_format;
109
use std::os::raw::{c_char, c_float, c_int, c_uint, c_void};
1110
use std::{fmt, mem};
@@ -81,19 +80,11 @@ extern "C" {
8180
-> c_int;
8281
pub fn cubeb_stream_set_volume(stream: *mut cubeb_stream, volume: c_float) -> c_int;
8382
pub fn cubeb_stream_set_name(stream: *mut cubeb_stream, name: *const c_char) -> c_int;
84-
pub fn cubeb_stream_get_current_device(
85-
stream: *mut cubeb_stream,
86-
device: *mut *mut cubeb_device,
87-
) -> c_int;
8883
pub fn cubeb_stream_set_input_mute(stream: *mut cubeb_stream, mute: c_int) -> c_int;
8984
pub fn cubeb_stream_set_input_processing_params(
9085
stream: *mut cubeb_stream,
9186
params: cubeb_input_processing_params,
9287
) -> c_int;
93-
pub fn cubeb_stream_device_destroy(
94-
stream: *mut cubeb_stream,
95-
devices: *mut cubeb_device,
96-
) -> c_int;
9788
pub fn cubeb_stream_register_device_changed_callback(
9889
stream: *mut cubeb_stream,
9990
device_changed_callback: cubeb_device_changed_callback,

0 commit comments

Comments
 (0)