pub mod audio;
pub mod format;
pub mod format_utils;
pub mod video;
use std::ffi::CStr;
use std::fmt::Debug;
#[derive(Copy, Clone, PartialEq, Eq)]
pub struct ParamType(pub spa_sys::spa_param_type);
#[allow(non_upper_case_globals)]
impl ParamType {
pub const Invalid: Self = Self(spa_sys::SPA_PARAM_Invalid);
pub const PropInfo: Self = Self(spa_sys::SPA_PARAM_PropInfo);
pub const Props: Self = Self(spa_sys::SPA_PARAM_Props);
pub const EnumFormat: Self = Self(spa_sys::SPA_PARAM_EnumFormat);
pub const Format: Self = Self(spa_sys::SPA_PARAM_Format);
pub const Buffers: Self = Self(spa_sys::SPA_PARAM_Buffers);
pub const Meta: Self = Self(spa_sys::SPA_PARAM_Meta);
pub const IO: Self = Self(spa_sys::SPA_PARAM_IO);
pub const EnumProfile: Self = Self(spa_sys::SPA_PARAM_EnumProfile);
pub const Profile: Self = Self(spa_sys::SPA_PARAM_Profile);
pub const EnumPortConfig: Self = Self(spa_sys::SPA_PARAM_EnumPortConfig);
pub const PortConfig: Self = Self(spa_sys::SPA_PARAM_PortConfig);
pub const EnumRoute: Self = Self(spa_sys::SPA_PARAM_EnumRoute);
pub const Route: Self = Self(spa_sys::SPA_PARAM_Route);
pub const Control: Self = Self(spa_sys::SPA_PARAM_Control);
pub const Latency: Self = Self(spa_sys::SPA_PARAM_Latency);
pub const ProcessLatency: Self = Self(spa_sys::SPA_PARAM_ProcessLatency);
pub fn from_raw(raw: spa_sys::spa_param_type) -> Self {
Self(raw)
}
pub fn as_raw(&self) -> spa_sys::spa_param_type {
self.0
}
}
impl Debug for ParamType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let c_str = unsafe {
let c_buf =
spa_sys::spa_debug_type_find_short_name(spa_sys::spa_type_param, self.as_raw());
if c_buf.is_null() {
return f.write_str("Unknown");
}
CStr::from_ptr(c_buf)
};
let name = format!("ParamType::{}", c_str.to_string_lossy());
f.write_str(&name)
}
}
bitflags::bitflags! {
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub struct ParamInfoFlags: u32 {
const SERIAL = 1<<0;
const READ = 1<<1;
const WRITE = 1<<2;
const READWRITE = Self::READ.bits() | Self::WRITE.bits();
}
}
#[repr(transparent)]
pub struct ParamInfo(spa_sys::spa_param_info);
impl ParamInfo {
pub fn id(&self) -> ParamType {
ParamType::from_raw(self.0.id)
}
pub fn flags(&self) -> ParamInfoFlags {
ParamInfoFlags::from_bits_truncate(self.0.flags)
}
}
impl Debug for ParamInfo {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ParamInfo")
.field("id", &self.id())
.field("flags", &self.flags())
.finish()
}
}