From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- third_party/rust/cubeb-sys/src/callbacks.rs | 23 ++++ third_party/rust/cubeb-sys/src/channel.rs | 72 ++++++++++++ third_party/rust/cubeb-sys/src/context.rs | 41 +++++++ third_party/rust/cubeb-sys/src/device.rs | 174 ++++++++++++++++++++++++++++ third_party/rust/cubeb-sys/src/error.rs | 13 +++ third_party/rust/cubeb-sys/src/format.rs | 22 ++++ third_party/rust/cubeb-sys/src/internal.rs | 29 +++++ third_party/rust/cubeb-sys/src/lib.rs | 31 +++++ third_party/rust/cubeb-sys/src/log.rs | 29 +++++ third_party/rust/cubeb-sys/src/macros.rs | 27 +++++ third_party/rust/cubeb-sys/src/mixer.rs | 31 +++++ third_party/rust/cubeb-sys/src/resampler.rs | 49 ++++++++ third_party/rust/cubeb-sys/src/stream.rs | 85 ++++++++++++++ 13 files changed, 626 insertions(+) create mode 100644 third_party/rust/cubeb-sys/src/callbacks.rs create mode 100644 third_party/rust/cubeb-sys/src/channel.rs create mode 100644 third_party/rust/cubeb-sys/src/context.rs create mode 100644 third_party/rust/cubeb-sys/src/device.rs create mode 100644 third_party/rust/cubeb-sys/src/error.rs create mode 100644 third_party/rust/cubeb-sys/src/format.rs create mode 100644 third_party/rust/cubeb-sys/src/internal.rs create mode 100644 third_party/rust/cubeb-sys/src/lib.rs create mode 100644 third_party/rust/cubeb-sys/src/log.rs create mode 100644 third_party/rust/cubeb-sys/src/macros.rs create mode 100644 third_party/rust/cubeb-sys/src/mixer.rs create mode 100644 third_party/rust/cubeb-sys/src/resampler.rs create mode 100644 third_party/rust/cubeb-sys/src/stream.rs (limited to 'third_party/rust/cubeb-sys/src') diff --git a/third_party/rust/cubeb-sys/src/callbacks.rs b/third_party/rust/cubeb-sys/src/callbacks.rs new file mode 100644 index 0000000000..72e4e84554 --- /dev/null +++ b/third_party/rust/cubeb-sys/src/callbacks.rs @@ -0,0 +1,23 @@ +// Copyright © 2017-2018 Mozilla Foundation +// +// This program is made available under an ISC-style license. See the +// accompanying file LICENSE for details. + +use context::cubeb; +use std::os::raw::{c_long, c_void}; +use stream::{cubeb_state, cubeb_stream}; + +pub type cubeb_data_callback = Option< + unsafe extern "C" fn( + *mut cubeb_stream, + *mut c_void, + *const c_void, + *mut c_void, + c_long, + ) -> c_long, +>; +pub type cubeb_state_callback = + Option; +pub type cubeb_device_changed_callback = Option; +pub type cubeb_device_collection_changed_callback = + Option; diff --git a/third_party/rust/cubeb-sys/src/channel.rs b/third_party/rust/cubeb-sys/src/channel.rs new file mode 100644 index 0000000000..231d719cdd --- /dev/null +++ b/third_party/rust/cubeb-sys/src/channel.rs @@ -0,0 +1,72 @@ +// Copyright © 2017-2018 Mozilla Foundation +// +// This program is made available under an ISC-style license. See the +// accompanying file LICENSE for details. + +#[cfg(all(windows, not(target_env = "gnu")))] +use std::os::raw::c_int as c_enum; +#[cfg(any(not(windows), all(windows, target_env = "gnu")))] +use std::os::raw::c_uint as c_enum; + +cubeb_enum! { + pub enum cubeb_channel : c_enum { + CHANNEL_UNKNOWN = 0, + CHANNEL_FRONT_LEFT = 1 << 0, + CHANNEL_FRONT_RIGHT = 1 << 1, + CHANNEL_FRONT_CENTER = 1 << 2, + CHANNEL_LOW_FREQUENCY = 1 << 3, + CHANNEL_BACK_LEFT = 1 << 4, + CHANNEL_BACK_RIGHT = 1 << 5, + CHANNEL_FRONT_LEFT_OF_CENTER = 1 << 6, + CHANNEL_FRONT_RIGHT_OF_CENTER = 1 << 7, + CHANNEL_BACK_CENTER = 1 << 8, + CHANNEL_SIDE_LEFT = 1 << 9, + CHANNEL_SIDE_RIGHT = 1 << 10, + CHANNEL_TOP_CENTER = 1 << 11, + CHANNEL_TOP_FRONT_LEFT = 1 << 12, + CHANNEL_TOP_FRONT_CENTER = 1 << 13, + CHANNEL_TOP_FRONT_RIGHT = 1 << 14, + CHANNEL_TOP_BACK_LEFT = 1 << 15, + CHANNEL_TOP_BACK_CENTER = 1 << 16, + CHANNEL_TOP_BACK_RIGHT = 1 << 17, + } +} + +cubeb_enum! { + pub enum cubeb_channel_layout : c_enum { + CUBEB_LAYOUT_UNDEFINED = 0, + CUBEB_LAYOUT_MONO = CHANNEL_FRONT_CENTER, + CUBEB_LAYOUT_MONO_LFE = CUBEB_LAYOUT_MONO | CHANNEL_LOW_FREQUENCY, + CUBEB_LAYOUT_STEREO = CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT, + CUBEB_LAYOUT_STEREO_LFE = CUBEB_LAYOUT_STEREO | CHANNEL_LOW_FREQUENCY, + CUBEB_LAYOUT_3F = CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT | + CHANNEL_FRONT_CENTER, + CUBEB_LAYOUT_3F_LFE = CUBEB_LAYOUT_3F | CHANNEL_LOW_FREQUENCY, + CUBEB_LAYOUT_2F1 = CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT | + CHANNEL_BACK_CENTER, + CUBEB_LAYOUT_2F1_LFE = CUBEB_LAYOUT_2F1 | CHANNEL_LOW_FREQUENCY, + CUBEB_LAYOUT_3F1 = CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT | + CHANNEL_FRONT_CENTER | CHANNEL_BACK_CENTER, + CUBEB_LAYOUT_3F1_LFE = CUBEB_LAYOUT_3F1 | CHANNEL_LOW_FREQUENCY, + CUBEB_LAYOUT_2F2 = CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT | + CHANNEL_SIDE_LEFT | CHANNEL_SIDE_RIGHT, + CUBEB_LAYOUT_2F2_LFE = CUBEB_LAYOUT_2F2 | CHANNEL_LOW_FREQUENCY, + CUBEB_LAYOUT_QUAD = CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT | + CHANNEL_BACK_LEFT | CHANNEL_BACK_RIGHT, + CUBEB_LAYOUT_QUAD_LFE = CUBEB_LAYOUT_QUAD | CHANNEL_LOW_FREQUENCY, + CUBEB_LAYOUT_3F2 = CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT | + CHANNEL_FRONT_CENTER | CHANNEL_SIDE_LEFT | + CHANNEL_SIDE_RIGHT, + CUBEB_LAYOUT_3F2_LFE = CUBEB_LAYOUT_3F2 | CHANNEL_LOW_FREQUENCY, + CUBEB_LAYOUT_3F2_BACK = CUBEB_LAYOUT_QUAD | CHANNEL_FRONT_CENTER, + CUBEB_LAYOUT_3F2_LFE_BACK = CUBEB_LAYOUT_3F2_BACK | CHANNEL_LOW_FREQUENCY, + CUBEB_LAYOUT_3F3R_LFE = CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT | + CHANNEL_FRONT_CENTER | CHANNEL_LOW_FREQUENCY | + CHANNEL_BACK_CENTER | CHANNEL_SIDE_LEFT | + CHANNEL_SIDE_RIGHT, + CUBEB_LAYOUT_3F4_LFE = CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT | + CHANNEL_FRONT_CENTER | CHANNEL_LOW_FREQUENCY | + CHANNEL_BACK_LEFT | CHANNEL_BACK_RIGHT | + CHANNEL_SIDE_LEFT | CHANNEL_SIDE_RIGHT, + } +} diff --git a/third_party/rust/cubeb-sys/src/context.rs b/third_party/rust/cubeb-sys/src/context.rs new file mode 100644 index 0000000000..b7f6e1193e --- /dev/null +++ b/third_party/rust/cubeb-sys/src/context.rs @@ -0,0 +1,41 @@ +// Copyright © 2017-2018 Mozilla Foundation +// +// This program is made available under an ISC-style license. See the +// accompanying file LICENSE for details. + +use callbacks::{cubeb_data_callback, cubeb_state_callback}; +use device::cubeb_devid; +use std::os::raw::{c_char, c_int, c_uint, c_void}; +use stream::{cubeb_stream, cubeb_stream_params}; + +pub enum cubeb {} + +extern "C" { + pub fn cubeb_init( + context: *mut *mut cubeb, + context_name: *const c_char, + backend_name: *const c_char, + ) -> c_int; + pub fn cubeb_get_backend_id(context: *mut cubeb) -> *const c_char; + pub fn cubeb_get_max_channel_count(context: *mut cubeb, max_channels: *mut c_uint) -> c_int; + pub fn cubeb_get_min_latency( + context: *mut cubeb, + params: *mut cubeb_stream_params, + latency_frames: *mut c_uint, + ) -> c_int; + pub fn cubeb_get_preferred_sample_rate(context: *mut cubeb, rate: *mut c_uint) -> c_int; + pub fn cubeb_destroy(context: *mut cubeb); + pub fn cubeb_stream_init( + context: *mut cubeb, + stream: *mut *mut cubeb_stream, + stream_name: *const c_char, + input_device: cubeb_devid, + input_stream_params: *mut cubeb_stream_params, + output_device: cubeb_devid, + output_stream_params: *mut cubeb_stream_params, + latency_frames: c_uint, + data_callback: cubeb_data_callback, + state_callback: cubeb_state_callback, + user_ptr: *mut c_void, + ) -> c_int; +} diff --git a/third_party/rust/cubeb-sys/src/device.rs b/third_party/rust/cubeb-sys/src/device.rs new file mode 100644 index 0000000000..4672a94ecb --- /dev/null +++ b/third_party/rust/cubeb-sys/src/device.rs @@ -0,0 +1,174 @@ +// Copyright © 2017-2018 Mozilla Foundation +// +// This program is made available under an ISC-style license. See the +// accompanying file LICENSE for details. + +use callbacks::cubeb_device_collection_changed_callback; +use context::cubeb; +use std::os::raw::{c_char, c_int, c_uint, c_void}; +use std::{fmt, mem}; + +cubeb_enum! { + pub enum cubeb_device_fmt { + CUBEB_DEVICE_FMT_S16LE = 0x0010, + CUBEB_DEVICE_FMT_S16BE = 0x0020, + CUBEB_DEVICE_FMT_F32LE = 0x1000, + CUBEB_DEVICE_FMT_F32BE = 0x2000, + } +} + +#[cfg(target_endian = "big")] +pub const CUBEB_DEVICE_FMT_S16NE: cubeb_device_fmt = CUBEB_DEVICE_FMT_S16BE; +#[cfg(target_endian = "big")] +pub const CUBEB_DEVICE_FMT_F32NE: cubeb_device_fmt = CUBEB_DEVICE_FMT_F32BE; +#[cfg(target_endian = "little")] +pub const CUBEB_DEVICE_FMT_S16NE: cubeb_device_fmt = CUBEB_DEVICE_FMT_S16LE; +#[cfg(target_endian = "little")] +pub const CUBEB_DEVICE_FMT_F32NE: cubeb_device_fmt = CUBEB_DEVICE_FMT_F32LE; + +pub const CUBEB_DEVICE_FMT_S16_MASK: cubeb_device_fmt = + CUBEB_DEVICE_FMT_S16LE | CUBEB_DEVICE_FMT_S16BE; +pub const CUBEB_DEVICE_FMT_F32_MASK: cubeb_device_fmt = + CUBEB_DEVICE_FMT_F32LE | CUBEB_DEVICE_FMT_F32BE; +pub const CUBEB_DEVICE_FMT_ALL: cubeb_device_fmt = + CUBEB_DEVICE_FMT_S16_MASK | CUBEB_DEVICE_FMT_F32_MASK; + +cubeb_enum! { + pub enum cubeb_device_pref { + CUBEB_DEVICE_PREF_NONE = 0x00, + CUBEB_DEVICE_PREF_MULTIMEDIA = 0x01, + CUBEB_DEVICE_PREF_VOICE = 0x02, + CUBEB_DEVICE_PREF_NOTIFICATION = 0x04, + CUBEB_DEVICE_PREF_ALL = 0x0F, + } +} + +cubeb_enum! { + pub enum cubeb_device_state { + CUBEB_DEVICE_STATE_DISABLED, + CUBEB_DEVICE_STATE_UNPLUGGED, + CUBEB_DEVICE_STATE_ENABLED, + } +} +cubeb_enum! { + pub enum cubeb_device_type { + CUBEB_DEVICE_TYPE_UNKNOWN, + CUBEB_DEVICE_TYPE_INPUT, + CUBEB_DEVICE_TYPE_OUTPUT, + } +} + +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, + pub count: usize, +} + +impl Default for cubeb_device_collection { + fn default() -> Self { + unsafe { mem::zeroed() } + } +} + +impl fmt::Debug for cubeb_device_collection { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("cubeb_device_collection") + .field("device", &self.device) + .field("count", &self.count) + .finish() + } +} + +#[repr(C)] +pub struct cubeb_device_info { + pub devid: cubeb_devid, + pub device_id: *const c_char, + pub friendly_name: *const c_char, + pub group_id: *const c_char, + pub vendor_name: *const c_char, + + pub device_type: cubeb_device_type, + pub state: cubeb_device_state, + pub preferred: cubeb_device_pref, + + pub format: cubeb_device_fmt, + pub default_format: cubeb_device_fmt, + pub max_channels: c_uint, + pub default_rate: c_uint, + pub max_rate: c_uint, + pub min_rate: c_uint, + + pub latency_lo: c_uint, + pub latency_hi: c_uint, +} + +impl Default for cubeb_device_info { + fn default() -> Self { + unsafe { mem::zeroed() } + } +} + +impl fmt::Debug for cubeb_device_info { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("cubeb_device_info") + .field("devid", &self.devid) + .field("device_id", &self.device_id) + .field("friendly_name", &self.friendly_name) + .field("group_id", &self.group_id) + .field("vendor_name", &self.vendor_name) + .field("device_type", &self.device_type) + .field("state", &self.state) + .field("preferred", &self.preferred) + .field("format", &self.format) + .field("default_format", &self.default_format) + .field("max_channels", &self.max_channels) + .field("default_rate", &self.default_rate) + .field("max_rate", &self.max_rate) + .field("min_rate", &self.min_rate) + .field("latency_lo", &self.latency_lo) + .field("latency_hi", &self.latency_hi) + .finish() + } +} + +extern "C" { + pub fn cubeb_enumerate_devices( + context: *mut cubeb, + devtype: cubeb_device_type, + collection: *mut cubeb_device_collection, + ) -> c_int; + pub fn cubeb_device_collection_destroy( + context: *mut cubeb, + collection: *mut cubeb_device_collection, + ) -> c_int; + pub fn cubeb_register_device_collection_changed( + context: *mut cubeb, + devtype: cubeb_device_type, + callback: cubeb_device_collection_changed_callback, + user_ptr: *mut c_void, + ) -> c_int; +} diff --git a/third_party/rust/cubeb-sys/src/error.rs b/third_party/rust/cubeb-sys/src/error.rs new file mode 100644 index 0000000000..5b93604d20 --- /dev/null +++ b/third_party/rust/cubeb-sys/src/error.rs @@ -0,0 +1,13 @@ +// Copyright © 2017-2018 Mozilla Foundation +// +// This program is made available under an ISC-style license. See the +// accompanying file LICENSE for details. + +use std::os::raw::c_int; + +pub const CUBEB_OK: c_int = 0; +pub const CUBEB_ERROR: c_int = -1; +pub const CUBEB_ERROR_INVALID_FORMAT: c_int = -2; +pub const CUBEB_ERROR_INVALID_PARAMETER: c_int = -3; +pub const CUBEB_ERROR_NOT_SUPPORTED: c_int = -4; +pub const CUBEB_ERROR_DEVICE_UNAVAILABLE: c_int = -5; diff --git a/third_party/rust/cubeb-sys/src/format.rs b/third_party/rust/cubeb-sys/src/format.rs new file mode 100644 index 0000000000..f9ae7d520b --- /dev/null +++ b/third_party/rust/cubeb-sys/src/format.rs @@ -0,0 +1,22 @@ +// Copyright © 2017-2018 Mozilla Foundation +// +// This program is made available under an ISC-style license. See the +// accompanying file LICENSE for details. + +cubeb_enum! { + pub enum cubeb_sample_format { + CUBEB_SAMPLE_S16LE, + CUBEB_SAMPLE_S16BE, + CUBEB_SAMPLE_FLOAT32LE, + CUBEB_SAMPLE_FLOAT32BE, + } +} + +#[cfg(target_endian = "big")] +pub const CUBEB_SAMPLE_S16NE: cubeb_sample_format = CUBEB_SAMPLE_S16BE; +#[cfg(target_endian = "big")] +pub const CUBEB_SAMPLE_FLOAT32NE: cubeb_sample_format = CUBEB_SAMPLE_FLOAT32BE; +#[cfg(target_endian = "little")] +pub const CUBEB_SAMPLE_S16NE: cubeb_sample_format = CUBEB_SAMPLE_S16LE; +#[cfg(target_endian = "little")] +pub const CUBEB_SAMPLE_FLOAT32NE: cubeb_sample_format = CUBEB_SAMPLE_FLOAT32LE; diff --git a/third_party/rust/cubeb-sys/src/internal.rs b/third_party/rust/cubeb-sys/src/internal.rs new file mode 100644 index 0000000000..92c90a24d0 --- /dev/null +++ b/third_party/rust/cubeb-sys/src/internal.rs @@ -0,0 +1,29 @@ +// Copyright © 2017-2018 Mozilla Foundation +// +// This program is made available under an ISC-style license. See the +// accompanying file LICENSE for details. + +use std::{fmt, mem}; +use std::os::raw::{c_char, c_uint}; + +#[repr(C)] +pub struct cubeb_layout_map { + name: *const c_char, + channels: c_uint, + layout: cubeb_channel_layout, +} + +impl Default for cubeb_layout_map { + fn default() -> Self { unsafe { mem::zeroed() } } +} + +// Explicit Debug impl to work around bug in ctest +impl fmt::Debug for cubeb_layout_map { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("cubeb_layout_map") + .field("name", &self.name) + .field("channels", &self.channels) + .field("layout", &self.layout) + .finish() + } +} diff --git a/third_party/rust/cubeb-sys/src/lib.rs b/third_party/rust/cubeb-sys/src/lib.rs new file mode 100644 index 0000000000..7767910ff6 --- /dev/null +++ b/third_party/rust/cubeb-sys/src/lib.rs @@ -0,0 +1,31 @@ +// Copyright © 2017-2018 Mozilla Foundation +// +// This program is made available under an ISC-style license. See the +// accompanying file LICENSE for details. + +#![allow(non_camel_case_types)] + +#[macro_use] +mod macros; + +mod callbacks; +mod channel; +mod context; +mod device; +mod error; +mod format; +mod log; +mod mixer; +mod resampler; +mod stream; + +pub use callbacks::*; +pub use channel::*; +pub use context::*; +pub use device::*; +pub use error::*; +pub use format::*; +pub use log::*; +pub use mixer::*; +pub use resampler::*; +pub use stream::*; diff --git a/third_party/rust/cubeb-sys/src/log.rs b/third_party/rust/cubeb-sys/src/log.rs new file mode 100644 index 0000000000..d1a1c4e448 --- /dev/null +++ b/third_party/rust/cubeb-sys/src/log.rs @@ -0,0 +1,29 @@ +// Copyright © 2017-2018 Mozilla Foundation +// +// This program is made available under an ISC-style license. See the +// accompanying file LICENSE for details. + +use std::os::raw::{c_char, c_int, c_void}; + +cubeb_enum! { + pub enum cubeb_log_level { + CUBEB_LOG_DISABLED = 0, + CUBEB_LOG_NORMAL = 1, + CUBEB_LOG_VERBOSE = 2, + } +} + +pub type cubeb_log_callback = Option; + +extern "C" { + pub fn cubeb_set_log_callback( + log_level: cubeb_log_level, + log_callback: cubeb_log_callback, + ) -> c_int; + + pub fn cubeb_log_get_callback() -> cubeb_log_callback; + pub fn cubeb_log_get_level() -> cubeb_log_level; + + pub fn cubeb_async_log_reset_threads(_: c_void); + pub fn cubeb_async_log(msg: *const c_char, ...); +} diff --git a/third_party/rust/cubeb-sys/src/macros.rs b/third_party/rust/cubeb-sys/src/macros.rs new file mode 100644 index 0000000000..02f1b7a8af --- /dev/null +++ b/third_party/rust/cubeb-sys/src/macros.rs @@ -0,0 +1,27 @@ +// Copyright © 2017-2018 Mozilla Foundation +// +// This program is made available under an ISC-style license. See the +// accompanying file LICENSE for details. + +macro_rules! cubeb_enum { + (pub enum $name:ident { $($variants:tt)* }) => { + #[cfg(target_env = "msvc")] + pub type $name = i32; + #[cfg(not(target_env = "msvc"))] + pub type $name = u32; + cubeb_enum!(gen, $name, 0, $($variants)*); + }; + (pub enum $name:ident: $t:ty { $($variants:tt)* }) => { + pub type $name = $t; + cubeb_enum!(gen, $name, 0, $($variants)*); + }; + (gen, $name:ident, $val:expr, $variant:ident, $($rest:tt)*) => { + pub const $variant: $name = $val; + cubeb_enum!(gen, $name, $val+1, $($rest)*); + }; + (gen, $name:ident, $val:expr, $variant:ident = $e:expr, $($rest:tt)*) => { + pub const $variant: $name = $e; + cubeb_enum!(gen, $name, $e+1, $($rest)*); + }; + (gen, $name:ident, $val:expr, ) => {} +} diff --git a/third_party/rust/cubeb-sys/src/mixer.rs b/third_party/rust/cubeb-sys/src/mixer.rs new file mode 100644 index 0000000000..d0452036bf --- /dev/null +++ b/third_party/rust/cubeb-sys/src/mixer.rs @@ -0,0 +1,31 @@ +// Copyright © 2017-2018 Mozilla Foundation +// +// This program is made available under an ISC-style license. See the +// accompanying file LICENSE for details. + +use channel::cubeb_channel_layout; +use format::cubeb_sample_format; +use std::os::raw::{c_int, c_uint, c_void}; + +pub enum cubeb_mixer {} + +extern "C" { + pub fn cubeb_mixer_create( + format: cubeb_sample_format, + in_channels: u32, + in_layout: cubeb_channel_layout, + out_channels: u32, + out_layout: cubeb_channel_layout, + ) -> *mut cubeb_mixer; + pub fn cubeb_mixer_destroy(mixer: *mut cubeb_mixer); + pub fn cubeb_mixer_mix( + mixer: *mut cubeb_mixer, + frames: usize, + input_buffer: *const c_void, + input_buffer_length: usize, + output_buffer: *mut c_void, + output_buffer_length: usize, + ) -> c_int; + + pub fn cubeb_channel_layout_nb_channels(channel_layout: cubeb_channel_layout) -> c_uint; +} diff --git a/third_party/rust/cubeb-sys/src/resampler.rs b/third_party/rust/cubeb-sys/src/resampler.rs new file mode 100644 index 0000000000..58cf811ce3 --- /dev/null +++ b/third_party/rust/cubeb-sys/src/resampler.rs @@ -0,0 +1,49 @@ +// Copyright © 2017-2018 Mozilla Foundation +// +// This program is made available under an ISC-style license. See the +// accompanying file LICENSE for details. + +use callbacks::cubeb_data_callback; +use std::os::raw::{c_long, c_uint, c_void}; +use stream::{cubeb_stream, cubeb_stream_params}; + +pub enum cubeb_resampler {} + +cubeb_enum! { + pub enum cubeb_resampler_quality { + CUBEB_RESAMPLER_QUALITY_VOIP, + CUBEB_RESAMPLER_QUALITY_DEFAULT, + CUBEB_RESAMPLER_QUALITY_DESKTOP, + } +} + +cubeb_enum! { + pub enum cubeb_resampler_reclock { + CUBEB_RESAMPLER_RECLOCK_NONE, + CUBEB_RESAMPLER_RECLOCK_INPUT, + } +} + +extern "C" { + pub fn cubeb_resampler_create( + stream: *mut cubeb_stream, + input_params: *mut cubeb_stream_params, + output_params: *mut cubeb_stream_params, + target_rate: c_uint, + callback: cubeb_data_callback, + user_ptr: *mut c_void, + quality: cubeb_resampler_quality, + reclock: cubeb_resampler_reclock, + ) -> *mut cubeb_resampler; + + pub fn cubeb_resampler_fill( + resampler: *mut cubeb_resampler, + input_buffer: *mut c_void, + input_frame_count: *mut c_long, + output_buffer: *mut c_void, + output_frames_needed: c_long, + ) -> c_long; + + pub fn cubeb_resampler_destroy(resampler: *mut cubeb_resampler); + pub fn cubeb_resampler_latency(resampler: *mut cubeb_resampler) -> c_long; +} diff --git a/third_party/rust/cubeb-sys/src/stream.rs b/third_party/rust/cubeb-sys/src/stream.rs new file mode 100644 index 0000000000..113cc025ac --- /dev/null +++ b/third_party/rust/cubeb-sys/src/stream.rs @@ -0,0 +1,85 @@ +// Copyright © 2017-2018 Mozilla Foundation +// +// This program is made available under an ISC-style license. See the +// accompanying file LICENSE for details. + +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}; + +cubeb_enum! { + pub enum cubeb_stream_prefs { + CUBEB_STREAM_PREF_NONE = 0x00, + CUBEB_STREAM_PREF_LOOPBACK = 0x01, + CUBEB_STREAM_PREF_DISABLE_DEVICE_SWITCHING = 0x02, + CUBEB_STREAM_PREF_VOICE = 0x04, + } +} + +cubeb_enum! { + pub enum cubeb_state { + CUBEB_STATE_STARTED, + CUBEB_STATE_STOPPED, + CUBEB_STATE_DRAINED, + CUBEB_STATE_ERROR, + } +} + +pub enum cubeb_stream {} + +#[repr(C)] +#[derive(Clone, Copy)] +pub struct cubeb_stream_params { + pub format: cubeb_sample_format, + pub rate: c_uint, + pub channels: c_uint, + pub layout: cubeb_channel_layout, + pub prefs: cubeb_stream_prefs, +} + +impl Default for cubeb_stream_params { + fn default() -> Self { + unsafe { mem::zeroed() } + } +} + +// Explicit Debug impl to work around bug in ctest +impl fmt::Debug for cubeb_stream_params { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("cubeb_stream_params") + .field("format", &self.format) + .field("rate", &self.rate) + .field("channels", &self.channels) + .field("layout", &self.layout) + .field("prefs", &self.prefs) + .finish() + } +} + +extern "C" { + pub fn cubeb_stream_destroy(stream: *mut cubeb_stream); + pub fn cubeb_stream_start(stream: *mut cubeb_stream) -> c_int; + pub fn cubeb_stream_stop(stream: *mut cubeb_stream) -> c_int; + pub fn cubeb_stream_get_position(stream: *mut cubeb_stream, position: *mut u64) -> c_int; + pub fn cubeb_stream_get_latency(stream: *mut cubeb_stream, latency: *mut c_uint) -> c_int; + pub fn cubeb_stream_get_input_latency(stream: *mut cubeb_stream, latency: *mut c_uint) + -> 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_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, + ) -> c_int; + pub fn cubeb_stream_user_ptr(stream: *mut cubeb_stream) -> *mut c_void; +} -- cgit v1.2.3