Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cubeb-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down
39 changes: 1 addition & 38 deletions cubeb-backend/src/capi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -381,22 +379,6 @@ pub unsafe extern "C" fn capi_stream_set_name<STM: StreamOps>(
}
}

/// # 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<STM: StreamOps>(
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.
Expand Down Expand Up @@ -427,25 +409,6 @@ pub unsafe extern "C" fn capi_stream_set_input_processing_params<STM: StreamOps>
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<STM: StreamOps>(
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.
Expand Down
12 changes: 0 additions & 12 deletions cubeb-backend/src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,6 @@ pub struct Ops {
Option<unsafe extern "C" fn(stream: *mut ffi::cubeb_stream, volumes: c_float) -> c_int>,
pub stream_set_name:
Option<unsafe extern "C" fn(stream: *mut ffi::cubeb_stream, name: *const c_char) -> 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<unsafe extern "C" fn(stream: *mut ffi::cubeb_stream, mute: c_int) -> c_int>,
pub stream_set_input_processing_params: Option<
Expand All @@ -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,
Expand Down
6 changes: 2 additions & 4 deletions cubeb-backend/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -49,10 +49,8 @@ pub trait StreamOps {
fn input_latency(&mut self) -> Result<u32>;
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,
Expand Down
22 changes: 2 additions & 20 deletions cubeb-backend/tests/test_capi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(())
Expand All @@ -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,
Expand Down Expand Up @@ -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();
Expand Down
50 changes: 0 additions & 50 deletions cubeb-core/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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());
}
}
25 changes: 1 addition & 24 deletions cubeb-core/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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 };
Expand All @@ -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,
Expand Down
22 changes: 0 additions & 22 deletions cubeb-sys/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 0 additions & 9 deletions cubeb-sys/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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,
Expand Down