libpulse_sys/
def.rs

1// Copyright 2017 Lyndon Brown
2//
3// This file is part of the PulseAudio Rust language linking library.
4//
5// Licensed under the MIT license or the Apache license (version 2.0), at your option. You may not
6// copy, modify, or distribute this file except in compliance with said license. You can find copies
7// of these licenses either in the LICENSE-MIT and LICENSE-APACHE files, or alternatively at
8// <http://opensource.org/licenses/MIT> and <http://www.apache.org/licenses/LICENSE-2.0>
9// respectively.
10//
11// Portions of documentation are copied from the LGPL 2.1+ licensed PulseAudio C headers on a
12// fair-use basis, as discussed in the overall project readme (available in the git repository).
13
14//! Global definitions.
15
16use std::os::raw::c_void;
17use num_derive::{FromPrimitive, ToPrimitive};
18use crate::timeval::timeval;
19use crate::sample::pa_usec_t;
20
21/// An invalid index.
22pub const PA_INVALID_INDEX: u32 = std::u32::MAX;
23
24pub type pa_free_cb_t = Option<extern "C" fn(p: *mut c_void)>;
25
26/// Device type, source or sink.
27#[repr(C)]
28#[derive(Debug, Copy, Clone, PartialEq, Eq)]
29#[derive(FromPrimitive, ToPrimitive)]
30pub enum pa_device_type_t {
31    /// A sink.
32    Sink,
33    /// A source.
34    Source,
35}
36
37pub const PA_DEVICE_TYPE_SINK:   pa_device_type_t = pa_device_type_t::Sink;
38pub const PA_DEVICE_TYPE_SOURCE: pa_device_type_t = pa_device_type_t::Source;
39
40#[repr(C)]
41pub struct pa_buffer_attr {
42    pub maxlength: u32,
43    pub tlength: u32,
44    pub prebuf: u32,
45    pub minreq: u32,
46    pub fragsize: u32,
47}
48
49#[repr(C)]
50pub struct pa_timing_info {
51    pub timestamp: timeval,
52    pub synchronized_clocks: i32,
53    pub sink_usec: pa_usec_t,
54    pub source_usec: pa_usec_t,
55    pub transport_usec: pa_usec_t,
56    pub playing: i32,
57    pub write_index_corrupt: i32,
58    pub write_index: i64,
59    pub read_index_corrupt: i32,
60    pub read_index: i64,
61    pub configured_sink_usec: pa_usec_t,
62    pub configured_source_usec: pa_usec_t,
63    pub since_underrun: i64,
64}
65
66#[repr(C)]
67#[derive(Debug, Copy, Clone)]
68pub struct pa_spawn_api {
69    pub prefork: Option<extern "C" fn()>,
70    pub postfork: Option<extern "C" fn()>,
71    pub atfork: Option<extern "C" fn()>,
72}
73
74pub type pa_sink_flags_t = u32;
75
76pub use self::sink_flags::*;
77
78/// Special sink flags.
79pub mod sink_flags {
80    use super::pa_sink_flags_t;
81
82    pub const PA_SINK_NOFLAGS:         pa_sink_flags_t = 0;
83    pub const PA_SINK_HW_VOLUME_CTRL:  pa_sink_flags_t = 1 << 0;
84    pub const PA_SINK_LATENCY:         pa_sink_flags_t = 1 << 1;
85    pub const PA_SINK_HARDWARE:        pa_sink_flags_t = 1 << 2;
86    pub const PA_SINK_NETWORK:         pa_sink_flags_t = 1 << 3;
87    pub const PA_SINK_HW_MUTE_CTRL:    pa_sink_flags_t = 1 << 4;
88    pub const PA_SINK_DECIBEL_VOLUME:  pa_sink_flags_t = 1 << 5;
89    pub const PA_SINK_FLAT_VOLUME:     pa_sink_flags_t = 1 << 6;
90    pub const PA_SINK_DYNAMIC_LATENCY: pa_sink_flags_t = 1 << 7;
91    pub const PA_SINK_SET_FORMATS:     pa_sink_flags_t = 1 << 8;
92}
93
94#[repr(C)]
95#[derive(Debug, Copy, Clone, PartialEq, Eq)]
96#[derive(FromPrimitive, ToPrimitive)]
97pub enum pa_sink_state_t {
98    Invalid   = -1,
99    Running   = 0,
100    Idle      = 1,
101    Suspended = 2,
102}
103
104pub const PA_SINK_INVALID_STATE: pa_sink_state_t = pa_sink_state_t::Invalid;
105pub const PA_SINK_RUNNING:       pa_sink_state_t = pa_sink_state_t::Running;
106pub const PA_SINK_IDLE:          pa_sink_state_t = pa_sink_state_t::Idle;
107pub const PA_SINK_SUSPENDED:     pa_sink_state_t = pa_sink_state_t::Suspended;
108
109/// Checks if state is playing, i.e. running or idle (returns `true` if so).
110#[inline(always)]
111pub fn pa_sink_is_opened(state: pa_sink_state_t) -> bool {
112    state == pa_sink_state_t::Running || state == pa_sink_state_t::Idle
113}
114
115/// Checks if state is running (returns `true` if so).
116#[inline(always)]
117pub fn pa_sink_is_running(state: pa_sink_state_t) -> bool {
118    state == pa_sink_state_t::Running
119}
120
121pub type pa_source_flags_t = u32;
122
123pub use self::source_flags::*;
124
125/// Special source flags.
126pub mod source_flags {
127    use super::pa_source_flags_t;
128
129    pub const PA_SOURCE_NOFLAGS:         pa_source_flags_t = 0;
130    pub const PA_SOURCE_HW_VOLUME_CTRL:  pa_source_flags_t = 1 << 0;
131    pub const PA_SOURCE_LATENCY:         pa_source_flags_t = 1 << 1;
132    pub const PA_SOURCE_HARDWARE:        pa_source_flags_t = 1 << 2;
133    pub const PA_SOURCE_NETWORK:         pa_source_flags_t = 1 << 3;
134    pub const PA_SOURCE_HW_MUTE_CTRL:    pa_source_flags_t = 1 << 4;
135    pub const PA_SOURCE_DECIBEL_VOLUME:  pa_source_flags_t = 1 << 5;
136    pub const PA_SOURCE_DYNAMIC_LATENCY: pa_source_flags_t = 1 << 6;
137    pub const PA_SOURCE_FLAT_VOLUME:     pa_source_flags_t = 1 << 7;
138}
139
140#[repr(C)]
141#[derive(Debug, Copy, Clone, PartialEq, Eq)]
142#[derive(FromPrimitive, ToPrimitive)]
143pub enum pa_source_state_t {
144    Invalid   = -1,
145    Running   = 0,
146    Idle      = 1,
147    Suspended = 2,
148}
149
150pub const PA_SOURCE_INVALID_STATE: pa_source_state_t = pa_source_state_t::Invalid;
151pub const PA_SOURCE_RUNNING:       pa_source_state_t = pa_source_state_t::Running;
152pub const PA_SOURCE_IDLE:          pa_source_state_t = pa_source_state_t::Idle;
153pub const PA_SOURCE_SUSPENDED:     pa_source_state_t = pa_source_state_t::Suspended;
154
155#[inline(always)]
156pub fn pa_source_is_opened(state: pa_source_state_t) -> bool {
157    state == pa_source_state_t::Running || state == pa_source_state_t::Idle
158}
159
160#[inline(always)]
161pub fn pa_source_is_running(state: pa_source_state_t) -> bool {
162    state == pa_source_state_t::Running
163}
164
165/// Port availability.
166#[repr(C)]
167#[derive(Debug, Copy, Clone, PartialEq, Eq)]
168#[derive(FromPrimitive, ToPrimitive)]
169pub enum pa_port_available_t {
170    /// This port does not support jack detection.
171    Unknown = 0,
172    /// This port is not available, likely because the jack is not plugged in.
173    No      = 1,
174    /// This port is available, likely because the jack is plugged in.
175    Yes     = 2,
176}
177
178pub const PA_PORT_AVAILABLE_UNKNOWN: pa_port_available_t = pa_port_available_t::Unknown;
179pub const PA_PORT_AVAILABLE_NO:      pa_port_available_t = pa_port_available_t::No;
180pub const PA_PORT_AVAILABLE_YES:     pa_port_available_t = pa_port_available_t::Yes;
181
182/// Port type.
183#[repr(C)]
184#[derive(Debug, Copy, Clone, PartialEq, Eq)]
185#[derive(FromPrimitive, ToPrimitive)]
186#[allow(non_camel_case_types)]
187pub enum pa_device_port_type_t {
188    /// Unknown.
189    Unknown    = 0,
190    /// Auxillary.
191    Aux        = 1,
192    /// Speaker.
193    Speaker    = 2,
194    /// Headphones.
195    Headphones = 3,
196    /// Line.
197    Line       = 4,
198    /// Mic.
199    Mic        = 5,
200    /// Headset.
201    Headset    = 6,
202    /// Handset.
203    Handset    = 7,
204    /// Earpiece.
205    Earpiece   = 8,
206    /// SPDIF.
207    SPDIF      = 9,
208    /// HDMI.
209    HDMI       = 10,
210    /// TV.
211    TV         = 11,
212    /// Radio.
213    Radio      = 12,
214    /// Video.
215    Video      = 13,
216    /// USB.
217    USB        = 14,
218    /// Bluetooth.
219    Bluetooth  = 15,
220    /// Portable.
221    Portable   = 16,
222    /// Handsfree.
223    Handsfree  = 17,
224    /// Car.
225    Car        = 18,
226    /// HiFi.
227    HiFi       = 19,
228    /// Phone.
229    Phone      = 20,
230    /// Network.
231    Network    = 21,
232    /// Analog.
233    Analog     = 22,
234}
235
236pub const PA_DEVICE_PORT_TYPE_UNKNOWN:    pa_device_port_type_t = pa_device_port_type_t::Unknown;
237pub const PA_DEVICE_PORT_TYPE_AUX:        pa_device_port_type_t = pa_device_port_type_t::Aux;
238pub const PA_DEVICE_PORT_TYPE_SPEAKER:    pa_device_port_type_t = pa_device_port_type_t::Speaker;
239pub const PA_DEVICE_PORT_TYPE_HEADPHONES: pa_device_port_type_t = pa_device_port_type_t::Headphones;
240pub const PA_DEVICE_PORT_TYPE_LINE:       pa_device_port_type_t = pa_device_port_type_t::Line;
241pub const PA_DEVICE_PORT_TYPE_MIC:        pa_device_port_type_t = pa_device_port_type_t::Mic;
242pub const PA_DEVICE_PORT_TYPE_HEADSET:    pa_device_port_type_t = pa_device_port_type_t::Headset;
243pub const PA_DEVICE_PORT_TYPE_HANDSET:    pa_device_port_type_t = pa_device_port_type_t::Handset;
244pub const PA_DEVICE_PORT_TYPE_EARPIECE:   pa_device_port_type_t = pa_device_port_type_t::Earpiece;
245pub const PA_DEVICE_PORT_TYPE_SPDIF:      pa_device_port_type_t = pa_device_port_type_t::SPDIF;
246pub const PA_DEVICE_PORT_TYPE_HDMI:       pa_device_port_type_t = pa_device_port_type_t::HDMI;
247pub const PA_DEVICE_PORT_TYPE_TV:         pa_device_port_type_t = pa_device_port_type_t::TV;
248pub const PA_DEVICE_PORT_TYPE_RADIO:      pa_device_port_type_t = pa_device_port_type_t::Radio;
249pub const PA_DEVICE_PORT_TYPE_VIDEO:      pa_device_port_type_t = pa_device_port_type_t::Video;
250pub const PA_DEVICE_PORT_TYPE_USB:        pa_device_port_type_t = pa_device_port_type_t::USB;
251pub const PA_DEVICE_PORT_TYPE_BLUETOOTH:  pa_device_port_type_t = pa_device_port_type_t::Bluetooth;
252pub const PA_DEVICE_PORT_TYPE_PORTABLE:   pa_device_port_type_t = pa_device_port_type_t::Portable;
253pub const PA_DEVICE_PORT_TYPE_HANDSFREE:  pa_device_port_type_t = pa_device_port_type_t::Handsfree;
254pub const PA_DEVICE_PORT_TYPE_CAR:        pa_device_port_type_t = pa_device_port_type_t::Car;
255pub const PA_DEVICE_PORT_TYPE_HIFI:       pa_device_port_type_t = pa_device_port_type_t::HiFi;
256pub const PA_DEVICE_PORT_TYPE_PHONE:      pa_device_port_type_t = pa_device_port_type_t::Phone;
257pub const PA_DEVICE_PORT_TYPE_NETWORK:    pa_device_port_type_t = pa_device_port_type_t::Network;
258pub const PA_DEVICE_PORT_TYPE_ANALOG:     pa_device_port_type_t = pa_device_port_type_t::Analog;