1pub mod audio;
7pub mod format;
8pub mod format_utils;
9pub mod video;
10
11use std::ffi::CStr;
12use std::fmt::Debug;
13
14#[derive(Copy, Clone, PartialEq, Eq)]
16pub struct ParamType(pub spa_sys::spa_param_type);
17
18#[allow(non_upper_case_globals)]
19impl ParamType {
20 pub const Invalid: Self = Self(spa_sys::SPA_PARAM_Invalid);
22 pub const PropInfo: Self = Self(spa_sys::SPA_PARAM_PropInfo);
24 pub const Props: Self = Self(spa_sys::SPA_PARAM_Props);
26 pub const EnumFormat: Self = Self(spa_sys::SPA_PARAM_EnumFormat);
28 pub const Format: Self = Self(spa_sys::SPA_PARAM_Format);
30 pub const Buffers: Self = Self(spa_sys::SPA_PARAM_Buffers);
32 pub const Meta: Self = Self(spa_sys::SPA_PARAM_Meta);
34 pub const IO: Self = Self(spa_sys::SPA_PARAM_IO);
36 pub const EnumProfile: Self = Self(spa_sys::SPA_PARAM_EnumProfile);
38 pub const Profile: Self = Self(spa_sys::SPA_PARAM_Profile);
40 pub const EnumPortConfig: Self = Self(spa_sys::SPA_PARAM_EnumPortConfig);
42 pub const PortConfig: Self = Self(spa_sys::SPA_PARAM_PortConfig);
44 pub const EnumRoute: Self = Self(spa_sys::SPA_PARAM_EnumRoute);
46 pub const Route: Self = Self(spa_sys::SPA_PARAM_Route);
48 pub const Control: Self = Self(spa_sys::SPA_PARAM_Control);
50 pub const Latency: Self = Self(spa_sys::SPA_PARAM_Latency);
52 pub const ProcessLatency: Self = Self(spa_sys::SPA_PARAM_ProcessLatency);
54
55 pub fn from_raw(raw: spa_sys::spa_param_type) -> Self {
57 Self(raw)
58 }
59
60 pub fn as_raw(&self) -> spa_sys::spa_param_type {
62 self.0
63 }
64}
65
66impl Debug for ParamType {
67 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
68 let c_str = unsafe {
69 let c_buf =
70 spa_sys::spa_debug_type_find_short_name(spa_sys::spa_type_param, self.as_raw());
71 if c_buf.is_null() {
72 return f.write_str("Unknown");
73 }
74 CStr::from_ptr(c_buf)
75 };
76 let name = format!("ParamType::{}", c_str.to_string_lossy());
77 f.write_str(&name)
78 }
79}
80
81bitflags::bitflags! {
82 #[derive(Debug, PartialEq, Eq, Clone, Copy)]
83 pub struct ParamInfoFlags: u32 {
84 const SERIAL = 1<<0;
85 const READ = 1<<1;
86 const WRITE = 1<<2;
87 const READWRITE = Self::READ.bits() | Self::WRITE.bits();
88 }
89}
90
91#[repr(transparent)]
93pub struct ParamInfo(spa_sys::spa_param_info);
94
95impl ParamInfo {
96 pub fn id(&self) -> ParamType {
97 ParamType::from_raw(self.0.id)
98 }
99
100 pub fn flags(&self) -> ParamInfoFlags {
101 ParamInfoFlags::from_bits_truncate(self.0.flags)
102 }
103}
104
105impl Debug for ParamInfo {
106 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
107 f.debug_struct("ParamInfo")
108 .field("id", &self.id())
109 .field("flags", &self.flags())
110 .finish()
111 }
112}