diff --git a/cubeb-api/src/lib.rs b/cubeb-api/src/lib.rs index ed9912d..06299de 100644 --- a/cubeb-api/src/lib.rs +++ b/cubeb-api/src/lib.rs @@ -30,10 +30,10 @@ mod stream; pub use context::*; // Re-export cubeb_core types pub use cubeb_core::{ - ffi, ChannelLayout, Context, ContextRef, Device, DeviceCollection, DeviceCollectionRef, - DeviceFormat, DeviceId, DeviceInfo, DeviceInfoRef, DeviceRef, DeviceState, DeviceType, Error, - LogLevel, Result, SampleFormat, State, StreamParams, StreamParamsBuilder, StreamParamsRef, - StreamPrefs, StreamRef, + ffi, ChannelLayout, Context, ContextRef, DeviceCollection, DeviceCollectionRef, DeviceFormat, + DeviceId, DeviceInfo, DeviceInfoRef, DeviceState, DeviceType, Error, LogLevel, Result, + SampleFormat, State, StreamParams, StreamParamsBuilder, StreamParamsRef, StreamPrefs, + StreamRef, }; pub use frame::*; pub use sample::*; diff --git a/cubeb-backend/src/capi.rs b/cubeb-backend/src/capi.rs index ba795bb..f81e1d5 100644 --- a/cubeb-backend/src/capi.rs +++ b/cubeb-backend/src/capi.rs @@ -4,7 +4,7 @@ // accompanying file LICENSE for details use cubeb_core::{ - ffi, DeviceInfo, DeviceRef, DeviceType, InputProcessingParams, StreamParams, StreamParamsRef, + ffi, DeviceInfo, DeviceType, InputProcessingParams, StreamParams, StreamParamsRef, }; use std::ffi::CStr; use std::mem; @@ -54,11 +54,9 @@ macro_rules! capi_new( stream_get_input_latency: Some($crate::capi::capi_stream_get_input_latency::<$stm>), stream_set_volume: Some($crate::capi::capi_stream_set_volume::<$stm>), stream_set_name: Some($crate::capi::capi_stream_set_name::<$stm>), - stream_get_current_device: Some($crate::capi::capi_stream_get_current_device::<$stm>), stream_set_input_mute: Some($crate::capi::capi_stream_set_input_mute::<$stm>), stream_set_input_processing_params: Some($crate::capi::capi_stream_set_input_processing_params::<$stm>), - stream_device_destroy: Some($crate::capi::capi_stream_device_destroy::<$stm>), stream_register_device_changed_callback: Some($crate::capi::capi_stream_register_device_changed_callback::<$stm>), register_device_collection_changed: @@ -381,22 +379,6 @@ pub unsafe extern "C" fn capi_stream_set_name( } } -/// # Safety -/// -/// Entry point from C code. -/// -/// This function is unsafe because it dereferences the given `s` and `device` pointers. -/// The caller should ensure those pointers are valid. -pub unsafe extern "C" fn capi_stream_get_current_device( - s: *mut ffi::cubeb_stream, - device: *mut *mut ffi::cubeb_device, -) -> i32 { - let stm = &mut *(s as *mut STM); - - *device = _try!(stm.current_device()).as_ptr(); - ffi::CUBEB_OK -} - /// # Safety /// /// Entry point from C code. @@ -427,25 +409,6 @@ pub unsafe extern "C" fn capi_stream_set_input_processing_params ffi::CUBEB_OK } -/// # Safety -/// -/// Entry point from C code. -/// -/// This function is unsafe because it dereferences the given `s` and `device` pointers. -/// The caller should ensure those pointers are valid. -pub unsafe extern "C" fn capi_stream_device_destroy( - s: *mut ffi::cubeb_stream, - device: *mut ffi::cubeb_device, -) -> c_int { - let stm = &mut *(s as *mut STM); - if device.is_null() { - return ffi::CUBEB_ERROR_INVALID_PARAMETER; - } - let device = DeviceRef::from_ptr(device); - let _ = stm.device_destroy(device); - ffi::CUBEB_OK -} - /// # Safety /// /// Entry point from C code. diff --git a/cubeb-backend/src/ops.rs b/cubeb-backend/src/ops.rs index c819ce6..78a252e 100644 --- a/cubeb-backend/src/ops.rs +++ b/cubeb-backend/src/ops.rs @@ -74,12 +74,6 @@ pub struct Ops { Option c_int>, pub stream_set_name: Option c_int>, - pub stream_get_current_device: Option< - unsafe extern "C" fn( - stream: *mut ffi::cubeb_stream, - device: *mut *mut ffi::cubeb_device, - ) -> c_int, - >, pub stream_set_input_mute: Option c_int>, pub stream_set_input_processing_params: Option< @@ -88,12 +82,6 @@ pub struct Ops { params: ffi::cubeb_input_processing_params, ) -> c_int, >, - pub stream_device_destroy: Option< - unsafe extern "C" fn( - stream: *mut ffi::cubeb_stream, - device: *mut ffi::cubeb_device, - ) -> c_int, - >, pub stream_register_device_changed_callback: Option< unsafe extern "C" fn( stream: *mut ffi::cubeb_stream, diff --git a/cubeb-backend/src/traits.rs b/cubeb-backend/src/traits.rs index 2d42fbc..ee50839 100644 --- a/cubeb-backend/src/traits.rs +++ b/cubeb-backend/src/traits.rs @@ -4,8 +4,8 @@ // accompanying file LICENSE for details. use cubeb_core::{ - DeviceId, DeviceInfo, DeviceRef, DeviceType, InputProcessingParams, Result, Stream, - StreamParams, StreamParamsRef, + DeviceId, DeviceInfo, DeviceType, InputProcessingParams, Result, Stream, StreamParams, + StreamParamsRef, }; use ffi; use std::ffi::CStr; @@ -49,10 +49,8 @@ pub trait StreamOps { fn input_latency(&mut self) -> Result; fn set_volume(&mut self, volume: f32) -> Result<()>; fn set_name(&mut self, name: &CStr) -> Result<()>; - fn current_device(&mut self) -> Result<&DeviceRef>; fn set_input_mute(&mut self, mute: bool) -> Result<()>; fn set_input_processing_params(&mut self, params: InputProcessingParams) -> Result<()>; - fn device_destroy(&mut self, device: &DeviceRef) -> Result<()>; fn register_device_changed_callback( &mut self, device_changed_callback: ffi::cubeb_device_changed_callback, diff --git a/cubeb-backend/tests/test_capi.rs b/cubeb-backend/tests/test_capi.rs index c06ba20..3160313 100644 --- a/cubeb-backend/tests/test_capi.rs +++ b/cubeb-backend/tests/test_capi.rs @@ -9,8 +9,8 @@ extern crate cubeb_backend; use cubeb_backend::{ - ffi, ContextOps, DeviceId, DeviceInfo, DeviceRef, DeviceType, InputProcessingParams, Ops, - Result, Stream, StreamOps, StreamParams, StreamParamsRef, + ffi, ContextOps, DeviceId, DeviceInfo, DeviceType, InputProcessingParams, Ops, Result, Stream, + StreamOps, StreamParams, StreamParamsRef, }; use std::ffi::CStr; use std::mem::ManuallyDrop; @@ -105,9 +105,6 @@ impl StreamOps for TestStream { assert_eq!(name, CStr::from_bytes_with_nul(b"test\0").unwrap()); Ok(()) } - fn current_device(&mut self) -> Result<&DeviceRef> { - Ok(unsafe { DeviceRef::from_ptr(0xDEAD_BEEF as *mut _) }) - } fn set_input_mute(&mut self, mute: bool) -> Result<()> { assert_eq!(mute, true); Ok(()) @@ -116,10 +113,6 @@ impl StreamOps for TestStream { assert_eq!(params, InputProcessingParams::ECHO_CANCELLATION); Ok(()) } - fn device_destroy(&mut self, device: &DeviceRef) -> Result<()> { - assert_eq!(device.as_ptr(), 0xDEAD_BEEF as *mut _); - Ok(()) - } fn register_device_changed_callback( &mut self, _: ffi::cubeb_device_changed_callback, @@ -249,17 +242,6 @@ fn test_ops_stream_set_name() { } } -#[test] -fn test_ops_stream_current_device() { - let s: *mut ffi::cubeb_stream = get_stream(); - let mut device: *mut ffi::cubeb_device = ptr::null_mut(); - assert_eq!( - unsafe { OPS.stream_get_current_device.unwrap()(s, &mut device) }, - ffi::CUBEB_OK - ); - assert_eq!(device, 0xDEAD_BEEF as *mut _); -} - #[test] fn test_ops_stream_set_input_mute() { let s: *mut ffi::cubeb_stream = get_stream(); diff --git a/cubeb-core/src/device.rs b/cubeb-core/src/device.rs index 4854aa2..27b5b29 100644 --- a/cubeb-core/src/device.rs +++ b/cubeb-core/src/device.rs @@ -61,42 +61,6 @@ impl DeviceType { /// across calls. pub type DeviceId = ffi::cubeb_devid; -ffi_type_heap! { - /// Audio device description - type CType = ffi::cubeb_device; - #[derive(Debug)] - pub struct Device; - pub struct DeviceRef; -} - -impl DeviceRef { - fn get_ref(&self) -> &ffi::cubeb_device { - unsafe { &*self.as_ptr() } - } - - /// Gets the output device name. - /// - /// May return `None` if there is no output device. - pub fn output_name(&self) -> Option<&str> { - self.output_name_bytes().map(|b| str::from_utf8(b).unwrap()) - } - - pub fn output_name_bytes(&self) -> Option<&[u8]> { - unsafe { opt_bytes(self.get_ref().output_name) } - } - - /// Gets the input device name. - /// - /// May return `None` if there is no input device. - pub fn input_name(&self) -> Option<&str> { - self.input_name_bytes().map(|b| str::from_utf8(b).unwrap()) - } - - pub fn input_name_bytes(&self) -> Option<&[u8]> { - unsafe { opt_bytes(self.get_ref().input_name) } - } -} - ffi_type_stack! { /// This structure holds the characteristics of an input or output /// audio device. It is obtained using `enumerate_devices`, which @@ -223,17 +187,3 @@ impl DeviceInfoRef { self.get_ref().latency_hi } } - -#[cfg(test)] -mod tests { - use ffi::cubeb_device; - use Device; - - #[test] - fn device_device_ref_same_ptr() { - let ptr: *mut cubeb_device = 0xDEAD_BEEF as *mut _; - let device = unsafe { Device::from_ptr(ptr) }; - assert_eq!(device.as_ptr(), ptr); - assert_eq!(device.as_ptr(), device.as_ref().as_ptr()); - } -} diff --git a/cubeb-core/src/stream.rs b/cubeb-core/src/stream.rs index 403ffb3..ecbb1d4 100644 --- a/cubeb-core/src/stream.rs +++ b/cubeb-core/src/stream.rs @@ -6,8 +6,7 @@ use ffi; use std::ffi::CStr; use std::os::raw::{c_int, c_void}; -use std::ptr; -use {ChannelLayout, DeviceRef, Result, SampleFormat}; +use {ChannelLayout, Result, SampleFormat}; /// Stream states signaled via `state_callback`. #[derive(PartialEq, Eq, Clone, Debug, Copy)] @@ -184,18 +183,6 @@ impl StreamRef { unsafe { call!(ffi::cubeb_stream_set_name(self.as_ptr(), name.as_ptr())) } } - /// Get the current output device for this stream. - pub fn current_device(&self) -> Result<&DeviceRef> { - let mut device: *mut ffi::cubeb_device = ptr::null_mut(); - unsafe { - call!(ffi::cubeb_stream_get_current_device( - self.as_ptr(), - &mut device - ))?; - Ok(DeviceRef::from_ptr(device)) - } - } - /// Set the mute state for an input stream. pub fn set_input_mute(&self, mute: bool) -> Result<()> { let mute: c_int = if mute { 1 } else { 0 }; @@ -212,16 +199,6 @@ impl StreamRef { } } - /// Destroy a cubeb_device structure. - pub fn device_destroy(&self, device: DeviceRef) -> Result<()> { - unsafe { - call!(ffi::cubeb_stream_device_destroy( - self.as_ptr(), - device.as_ptr() - )) - } - } - /// Set a callback to be notified when the output device changes. pub fn register_device_changed_callback( &self, diff --git a/cubeb-sys/src/device.rs b/cubeb-sys/src/device.rs index bac4a86..e3fe919 100644 --- a/cubeb-sys/src/device.rs +++ b/cubeb-sys/src/device.rs @@ -105,28 +105,6 @@ fn fmt_device_type(t: &cubeb_device_type) -> &'static str { pub type cubeb_devid = *const c_void; -#[repr(C)] -pub struct cubeb_device { - pub output_name: *mut c_char, - pub input_name: *mut c_char, -} - -// Explicit Debug impl to work around bug in ctest -impl Default for cubeb_device { - fn default() -> Self { - unsafe { mem::zeroed() } - } -} - -impl fmt::Debug for cubeb_device { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.debug_struct("cubeb_device") - .field("output_name", &self.output_name) - .field("input_name", &self.input_name) - .finish() - } -} - #[repr(C)] pub struct cubeb_device_collection { pub device: *mut cubeb_device_info, diff --git a/cubeb-sys/src/stream.rs b/cubeb-sys/src/stream.rs index 9b16bf2..d85431d 100644 --- a/cubeb-sys/src/stream.rs +++ b/cubeb-sys/src/stream.rs @@ -5,7 +5,6 @@ use callbacks::cubeb_device_changed_callback; use channel::cubeb_channel_layout; -use device::cubeb_device; use format::cubeb_sample_format; use std::os::raw::{c_char, c_float, c_int, c_uint, c_void}; use std::{fmt, mem}; @@ -81,19 +80,11 @@ extern "C" { -> c_int; pub fn cubeb_stream_set_volume(stream: *mut cubeb_stream, volume: c_float) -> c_int; pub fn cubeb_stream_set_name(stream: *mut cubeb_stream, name: *const c_char) -> c_int; - pub fn cubeb_stream_get_current_device( - stream: *mut cubeb_stream, - device: *mut *mut cubeb_device, - ) -> c_int; pub fn cubeb_stream_set_input_mute(stream: *mut cubeb_stream, mute: c_int) -> c_int; pub fn cubeb_stream_set_input_processing_params( stream: *mut cubeb_stream, params: cubeb_input_processing_params, ) -> c_int; - pub fn cubeb_stream_device_destroy( - stream: *mut cubeb_stream, - devices: *mut cubeb_device, - ) -> c_int; pub fn cubeb_stream_register_device_changed_callback( stream: *mut cubeb_stream, device_changed_callback: cubeb_device_changed_callback,