libpulse_sys/
format.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//! Utility functions for handling a stream or sink format.
15
16use std::os::raw::c_char;
17use num_derive::{FromPrimitive, ToPrimitive};
18use crate::sample::{pa_sample_spec, pa_sample_format_t};
19use crate::{proplist::pa_proplist, channelmap::pa_channel_map};
20
21#[repr(C)]
22#[non_exhaustive]
23#[derive(Debug, Copy, Clone, PartialEq, Eq)]
24#[derive(FromPrimitive, ToPrimitive)]
25#[allow(non_camel_case_types)]
26pub enum pa_encoding_t {
27    Any,
28    PCM,
29    AC3_IEC61937,
30    EAC3_IEC61937,
31    MPEG_IEC61937,
32    DTS_IEC61937,
33    MPEG2_AAC_IEC61937,
34    #[cfg(any(doc, feature = "pa_v13"))]
35    #[cfg_attr(docsrs, doc(cfg(feature = "pa_v13")))]
36    TRUEHD_IEC61937,
37    #[cfg(any(doc, feature = "pa_v13"))]
38    #[cfg_attr(docsrs, doc(cfg(feature = "pa_v13")))]
39    DTSHD_IEC61937,
40
41    Invalid = -1,
42}
43
44pub const PA_ENCODING_MAX: usize = 7;
45
46pub const PA_ENCODING_ANY:                pa_encoding_t = pa_encoding_t::Any;
47pub const PA_ENCODING_PCM:                pa_encoding_t = pa_encoding_t::PCM;
48pub const PA_ENCODING_AC3_IEC61937:       pa_encoding_t = pa_encoding_t::AC3_IEC61937;
49pub const PA_ENCODING_EAC3_IEC61937:      pa_encoding_t = pa_encoding_t::EAC3_IEC61937;
50pub const PA_ENCODING_MPEG_IEC61937:      pa_encoding_t = pa_encoding_t::MPEG_IEC61937;
51pub const PA_ENCODING_DTS_IEC61937:       pa_encoding_t = pa_encoding_t::DTS_IEC61937;
52pub const PA_ENCODING_MPEG2_AAC_IEC61937: pa_encoding_t = pa_encoding_t::MPEG2_AAC_IEC61937;
53#[cfg(any(doc, feature = "pa_v13"))]
54#[cfg_attr(docsrs, doc(cfg(feature = "pa_v13")))]
55pub const PA_ENCODING_TRUEHD_IEC61937:    pa_encoding_t = pa_encoding_t::TRUEHD_IEC61937;
56#[cfg(any(doc, feature = "pa_v13"))]
57#[cfg_attr(docsrs, doc(cfg(feature = "pa_v13")))]
58pub const PA_ENCODING_DTSHD_IEC61937:     pa_encoding_t = pa_encoding_t::DTSHD_IEC61937;
59pub const PA_ENCODING_INVALID:            pa_encoding_t = pa_encoding_t::Invalid;
60
61impl Default for pa_encoding_t {
62    fn default() -> Self {
63        pa_encoding_t::Invalid
64    }
65}
66
67/// Represents the format of data provided in a stream or processed by a sink.
68#[repr(C)]
69pub struct pa_format_info {
70    pub encoding: pa_encoding_t,
71    pub plist: *mut pa_proplist,
72}
73
74/// The maximum length of strings returned by [`pa_format_info_snprint()`].
75///
76/// Please note that this value can change with any release without warning and without being
77/// considered API or ABI breakage. You should not use this definition anywhere where it might
78/// become part of an ABI.
79pub const PA_FORMAT_INFO_SNPRINT_MAX: usize = 256;
80
81/// Represents the type of value of a property.
82#[repr(C)]
83#[derive(Debug, Copy, Clone, PartialEq, Eq)]
84#[derive(FromPrimitive, ToPrimitive)]
85pub enum pa_prop_type_t {
86    /// Integer.
87    Int,
88    /// Integer range.
89    IntRange,
90    /// Integer array.
91    IntArray,
92    /// String.
93    String,
94    /// String array.
95    StringArray,
96
97    /// Invalid.
98    Invalid = -1,
99}
100
101pub const PA_PROP_TYPE_INT:          pa_prop_type_t = pa_prop_type_t::Int;
102pub const PA_PROP_TYPE_INT_RANGE:    pa_prop_type_t = pa_prop_type_t::IntRange;
103pub const PA_PROP_TYPE_INT_ARRAY:    pa_prop_type_t = pa_prop_type_t::IntArray;
104pub const PA_PROP_TYPE_STRING:       pa_prop_type_t = pa_prop_type_t::String;
105pub const PA_PROP_TYPE_STRING_ARRAY: pa_prop_type_t = pa_prop_type_t::StringArray;
106pub const PA_PROP_TYPE_INVALID:      pa_prop_type_t = pa_prop_type_t::Invalid;
107
108impl Default for pa_prop_type_t {
109    fn default() -> Self {
110        pa_prop_type_t::Invalid
111    }
112}
113
114#[rustfmt::skip]
115#[link(name = "pulse")]
116extern "C" {
117    pub fn pa_encoding_to_string(e: pa_encoding_t) -> *const c_char;
118    #[cfg(any(doc, feature = "pa_v12"))]
119    #[cfg_attr(docsrs, doc(cfg(feature = "pa_v12")))]
120    pub fn pa_encoding_from_string(encoding: *const c_char) -> pa_encoding_t;
121
122    pub fn pa_format_info_new() -> *mut pa_format_info;
123    pub fn pa_format_info_copy(src: *const pa_format_info) -> *mut pa_format_info;
124    pub fn pa_format_info_free(f: *mut pa_format_info);
125    pub fn pa_format_info_valid(f: *const pa_format_info) -> i32;
126    pub fn pa_format_info_is_pcm(f: *const pa_format_info) -> i32;
127    pub fn pa_format_info_is_compatible(first: *const pa_format_info, second: *const pa_format_info) -> i32;
128    pub fn pa_format_info_snprint(s: *mut c_char, l: usize, f: *const pa_format_info) -> *mut c_char;
129    pub fn pa_format_info_from_string(s: *const c_char) -> *mut pa_format_info;
130    pub fn pa_format_info_from_sample_spec(ss: *const pa_sample_spec, map: *const pa_channel_map) -> *mut pa_format_info;
131    pub fn pa_format_info_to_sample_spec(f: *const pa_format_info, ss: *mut pa_sample_spec, map: *mut pa_channel_map) -> i32;
132    pub fn pa_format_info_get_prop_type(f: *const pa_format_info, key: *const c_char) -> pa_prop_type_t;
133    pub fn pa_format_info_get_prop_int(f: *const pa_format_info, key: *const c_char, v: *mut i32) -> i32;
134    pub fn pa_format_info_get_prop_int_range(f: *const pa_format_info, key: *const c_char, min: *mut i32, max: *mut i32) -> i32;
135    pub fn pa_format_info_get_prop_int_array(f: *const pa_format_info, key: *const c_char, values: *mut *mut i32, n_values: *mut i32) -> i32;
136    pub fn pa_format_info_get_prop_string(f: *const pa_format_info, key: *const c_char, v: *mut *mut c_char) -> i32;
137    pub fn pa_format_info_get_prop_string_array(f: *const pa_format_info, key: *const c_char, values: *mut *mut *mut c_char, n_values: *mut i32) -> i32;
138    pub fn pa_format_info_free_string_array(values: *mut *mut c_char, n_values: i32);
139    #[cfg(any(doc, feature = "pa_v13"))]
140    #[cfg_attr(docsrs, doc(cfg(feature = "pa_v13")))]
141    pub fn pa_format_info_get_sample_format(f: *const pa_format_info, sf: *mut pa_sample_format_t) -> i32;
142    #[cfg(any(doc, feature = "pa_v13"))]
143    #[cfg_attr(docsrs, doc(cfg(feature = "pa_v13")))]
144    pub fn pa_format_info_get_rate(f: *const pa_format_info, rate: *mut u32) -> i32;
145    #[cfg(any(doc, feature = "pa_v13"))]
146    #[cfg_attr(docsrs, doc(cfg(feature = "pa_v13")))]
147    pub fn pa_format_info_get_channels(f: *const pa_format_info, channels: *mut u8) -> i32;
148    #[cfg(any(doc, feature = "pa_v13"))]
149    #[cfg_attr(docsrs, doc(cfg(feature = "pa_v13")))]
150    pub fn pa_format_info_get_channel_map(f: *const pa_format_info, map: *const pa_channel_map) -> i32;
151    pub fn pa_format_info_set_prop_int(f: *mut pa_format_info, key: *const c_char, value: i32);
152    pub fn pa_format_info_set_prop_int_array(f: *mut pa_format_info, key: *const c_char, values: *const i32, n_values: i32);
153    pub fn pa_format_info_set_prop_int_range(f: *mut pa_format_info, key: *const c_char, min: i32, max: i32);
154    pub fn pa_format_info_set_prop_string(f: *mut pa_format_info, key: *const c_char, value: *const c_char);
155    pub fn pa_format_info_set_prop_string_array(f: *mut pa_format_info, key: *const c_char, values: *const *const c_char, n_values: i32);
156    pub fn pa_format_info_set_sample_format(f: *mut pa_format_info, sf: pa_sample_format_t);
157    pub fn pa_format_info_set_rate(f: *mut pa_format_info, rate: i32);
158    pub fn pa_format_info_set_channels(f: *mut pa_format_info, channels: i32);
159    pub fn pa_format_info_set_channel_map(f: *mut pa_format_info, map: *const pa_channel_map);
160}