use std::os::raw::c_void;
use bitflags::bitflags;
use num_derive::{FromPrimitive, ToPrimitive};
use crate::time::{MicroSeconds, UnixTs};
pub use capi::PA_INVALID_INDEX as INVALID_INDEX;
pub use capi::pa_device_type_t as Device;
pub use capi::pa_port_available_t as PortAvailable;
pub use capi::pa_device_port_type_t as DevicePortType;
pub type FreeCb = extern "C" fn(p: *mut c_void);
pub type RetvalActual = i32;
#[repr(transparent)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct Retval(pub RetvalActual);
#[repr(C)]
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)]
pub struct BufferAttr {
pub maxlength: u32,
pub tlength: u32,
pub prebuf: u32,
pub minreq: u32,
pub fragsize: u32,
}
#[test]
fn bufferattr_compare_capi() {
assert_eq!(std::mem::size_of::<BufferAttr>(), std::mem::size_of::<capi::pa_buffer_attr>());
assert_eq!(std::mem::align_of::<BufferAttr>(), std::mem::align_of::<capi::pa_buffer_attr>());
}
impl AsRef<capi::pa_buffer_attr> for BufferAttr {
#[inline]
fn as_ref(&self) -> &capi::pa_buffer_attr {
unsafe { &*(self as *const Self as *const capi::pa_buffer_attr) }
}
}
impl AsRef<BufferAttr> for capi::pa_buffer_attr {
#[inline]
fn as_ref(&self) -> &BufferAttr {
unsafe { &*(self as *const Self as *const BufferAttr) }
}
}
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct TimingInfo {
pub timestamp: UnixTs,
pub synchronized_clocks: i32,
pub sink_usec: MicroSeconds,
pub source_usec: MicroSeconds,
pub transport_usec: MicroSeconds,
pub playing: i32,
pub write_index_corrupt: i32,
pub write_index: i64,
pub read_index_corrupt: i32,
pub read_index: i64,
pub configured_sink_usec: MicroSeconds,
pub configured_source_usec: MicroSeconds,
pub since_underrun: i64,
}
#[test]
fn timinginfo_compare_capi() {
assert_eq!(std::mem::size_of::<TimingInfo>(), std::mem::size_of::<capi::pa_timing_info>());
assert_eq!(std::mem::align_of::<TimingInfo>(), std::mem::align_of::<capi::pa_timing_info>());
}
impl AsRef<TimingInfo> for capi::pa_timing_info {
#[inline]
fn as_ref(&self) -> &TimingInfo {
unsafe { &*(self as *const Self as *const TimingInfo) }
}
}
#[repr(C)]
#[derive(Debug)]
pub struct SpawnApi {
pub prefork: Option<extern "C" fn()>,
pub postfork: Option<extern "C" fn()>,
pub atfork: Option<extern "C" fn()>,
}
#[test]
fn spawnapi_compare_capi() {
assert_eq!(std::mem::size_of::<SpawnApi>(), std::mem::size_of::<capi::pa_spawn_api>());
assert_eq!(std::mem::align_of::<SpawnApi>(), std::mem::align_of::<capi::pa_spawn_api>());
}
impl AsRef<capi::pa_spawn_api> for SpawnApi {
#[inline]
fn as_ref(&self) -> &capi::pa_spawn_api {
unsafe { &*(self as *const Self as *const capi::pa_spawn_api) }
}
}
bitflags! {
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[repr(transparent)]
pub struct SinkFlagSet: u32 {
const NOFLAGS = capi::PA_SINK_NOFLAGS;
const HW_VOLUME_CTRL = capi::PA_SINK_HW_VOLUME_CTRL;
const LATENCY = capi::PA_SINK_LATENCY;
const HARDWARE = capi::PA_SINK_HARDWARE;
const NETWORK = capi::PA_SINK_NETWORK;
const HW_MUTE_CTRL = capi::PA_SINK_HW_MUTE_CTRL;
const DECIBEL_VOLUME = capi::PA_SINK_DECIBEL_VOLUME;
const FLAT_VOLUME = capi::PA_SINK_FLAT_VOLUME;
const DYNAMIC_LATENCY = capi::PA_SINK_DYNAMIC_LATENCY;
const SET_FORMATS = capi::PA_SINK_SET_FORMATS;
}
}
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[derive(FromPrimitive, ToPrimitive)]
pub enum SinkState {
Invalid = -1,
Running = 0,
Idle = 1,
Suspended = 2,
}
#[test]
fn sink_state_compare_capi() {
assert_eq!(std::mem::size_of::<SinkState>(), std::mem::size_of::<capi::pa_sink_state_t>());
assert_eq!(std::mem::align_of::<SinkState>(), std::mem::align_of::<capi::pa_sink_state_t>());
assert_eq!(SinkState::Invalid, SinkState::from(capi::pa_sink_state_t::Invalid));
assert_eq!(SinkState::Running, SinkState::from(capi::pa_sink_state_t::Running));
assert_eq!(SinkState::Idle, SinkState::from(capi::pa_sink_state_t::Idle));
assert_eq!(SinkState::Suspended, SinkState::from(capi::pa_sink_state_t::Suspended));
}
impl From<SinkState> for capi::pa_sink_state_t {
#[inline]
fn from(s: SinkState) -> Self {
unsafe { std::mem::transmute(s) }
}
}
impl From<capi::pa_sink_state_t> for SinkState {
#[inline]
fn from(s: capi::pa_sink_state_t) -> Self {
unsafe { std::mem::transmute(s) }
}
}
impl SinkState {
#[inline]
pub fn is_opened(self) -> bool {
self == SinkState::Running || self == SinkState::Idle
}
#[inline]
pub fn is_running(self) -> bool {
self == SinkState::Running
}
}
bitflags! {
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[repr(transparent)]
pub struct SourceFlagSet: u32 {
const NOFLAGS = capi::PA_SOURCE_NOFLAGS;
const HW_VOLUME_CTRL = capi::PA_SOURCE_HW_VOLUME_CTRL;
const LATENCY = capi::PA_SOURCE_LATENCY;
const HARDWARE = capi::PA_SOURCE_HARDWARE;
const NETWORK = capi::PA_SOURCE_NETWORK;
const HW_MUTE_CTRL = capi::PA_SOURCE_HW_MUTE_CTRL;
const DECIBEL_VOLUME = capi::PA_SOURCE_DECIBEL_VOLUME;
const DYNAMIC_LATENCY = capi::PA_SOURCE_DYNAMIC_LATENCY;
const FLAT_VOLUME = capi::PA_SOURCE_FLAT_VOLUME;
}
}
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[derive(FromPrimitive, ToPrimitive)]
pub enum SourceState {
Invalid = -1,
Running = 0,
Idle = 1,
Suspended = 2,
}
#[test]
fn source_state_compare_capi() {
assert_eq!(std::mem::size_of::<SourceState>(), std::mem::size_of::<capi::pa_source_state_t>());
assert_eq!(std::mem::align_of::<SourceState>(), std::mem::align_of::<capi::pa_source_state_t>());
assert_eq!(SourceState::Invalid, SourceState::from(capi::pa_source_state_t::Invalid));
assert_eq!(SourceState::Running, SourceState::from(capi::pa_source_state_t::Running));
assert_eq!(SourceState::Idle, SourceState::from(capi::pa_source_state_t::Idle));
assert_eq!(SourceState::Suspended, SourceState::from(capi::pa_source_state_t::Suspended));
}
impl From<SourceState> for capi::pa_source_state_t {
#[inline]
fn from(s: SourceState) -> Self {
unsafe { std::mem::transmute(s) }
}
}
impl From<capi::pa_source_state_t> for SourceState {
#[inline]
fn from(s: capi::pa_source_state_t) -> Self {
unsafe { std::mem::transmute(s) }
}
}
impl SourceState {
#[inline]
pub fn is_opened(self) -> bool {
self == SourceState::Running || self == SourceState::Idle
}
#[inline]
pub fn is_running(self) -> bool {
self == SourceState::Running
}
}