Path: blob/master/thirdparty/linuxbsd_headers/pulse/format.h
9905 views
#ifndef fooformathfoo1#define fooformathfoo23/***4This file is part of PulseAudio.56Copyright 2011 Intel Corporation7Copyright 2011 Collabora Multimedia8Copyright 2011 Arun Raghavan <[email protected]>910PulseAudio is free software; you can redistribute it and/or modify11it under the terms of the GNU Lesser General Public License as published12by the Free Software Foundation; either version 2.1 of the License,13or (at your option) any later version.1415PulseAudio is distributed in the hope that it will be useful, but16WITHOUT ANY WARRANTY; without even the implied warranty of17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU18General Public License for more details.1920You should have received a copy of the GNU Lesser General Public License21along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.22***/2324#include <pulse/cdecl.h>25#include <pulse/gccmacro.h>26#include <pulse/proplist.h>27#include <pulse/sample.h>28#include <pulse/channelmap.h>2930/** \file31* Utility functions for handling a stream or sink format. */3233PA_C_DECL_BEGIN3435/** Represents the type of encoding used in a stream or accepted by a sink. \since 1.0 */36typedef enum pa_encoding {37PA_ENCODING_ANY,38/**< Any encoding format, PCM or compressed */3940PA_ENCODING_PCM,41/**< Any PCM format */4243PA_ENCODING_AC3_IEC61937,44/**< AC3 data encapsulated in IEC 61937 header/padding */4546PA_ENCODING_EAC3_IEC61937,47/**< EAC3 data encapsulated in IEC 61937 header/padding */4849PA_ENCODING_MPEG_IEC61937,50/**< MPEG-1 or MPEG-2 (Part 3, not AAC) data encapsulated in IEC 61937 header/padding */5152PA_ENCODING_DTS_IEC61937,53/**< DTS data encapsulated in IEC 61937 header/padding */5455PA_ENCODING_MPEG2_AAC_IEC61937,56/**< MPEG-2 AAC data encapsulated in IEC 61937 header/padding. \since 4.0 */5758PA_ENCODING_MAX,59/**< Valid encoding types must be less than this value */6061PA_ENCODING_INVALID = -1,62/**< Represents an invalid encoding */63} pa_encoding_t;6465/** \cond fulldocs */66#define PA_ENCODING_ANY PA_ENCODING_ANY67#define PA_ENCODING_PCM PA_ENCODING_PCM68#define PA_ENCODING_AC3_IEC61937 PA_ENCODING_AC3_IEC6193769#define PA_ENCODING_EAC3_IEC61937 PA_ENCODING_EAC3_IEC6193770#define PA_ENCODING_MPEG_IEC61937 PA_ENCODING_MPEG_IEC6193771#define PA_ENCODING_DTS_IEC61937 PA_ENCODING_DTS_IEC6193772#define PA_ENCODING_MPEG2_AAC_IEC61937 PA_ENCODING_MPEG2_AAC_IEC6193773#define PA_ENCODING_MAX PA_ENCODING_MAX74#define PA_ENCODING_INVALID PA_ENCODING_INVALID75/** \endcond */7677/** Returns a printable string representing the given encoding type. \since 1.0 */78const char *pa_encoding_to_string(pa_encoding_t e) PA_GCC_CONST;7980/** Converts a string of the form returned by \a pa_encoding_to_string() back to a \a pa_encoding_t. \since 1.0 */81pa_encoding_t pa_encoding_from_string(const char *encoding);8283/** Represents the format of data provided in a stream or processed by a sink. \since 1.0 */84typedef struct pa_format_info {85pa_encoding_t encoding;86/**< The encoding used for the format */8788pa_proplist *plist;89/**< Additional encoding-specific properties such as sample rate, bitrate, etc. */90} pa_format_info;9192/** Allocates a new \a pa_format_info structure. Clients must initialise at least the encoding field themselves. \since 1.0 */93pa_format_info* pa_format_info_new(void);9495/** Returns a new \a pa_format_info struct and representing the same format as \a src. \since 1.0 */96pa_format_info* pa_format_info_copy(const pa_format_info *src);9798/** Frees a \a pa_format_info structure. \since 1.0 */99void pa_format_info_free(pa_format_info *f);100101/** Returns non-zero when the format info structure is valid. \since 1.0 */102int pa_format_info_valid(const pa_format_info *f);103104/** Returns non-zero when the format info structure represents a PCM (i.e.\ uncompressed data) format. \since 1.0 */105int pa_format_info_is_pcm(const pa_format_info *f);106107/** Returns non-zero if the format represented by \a first is a subset of108* the format represented by \a second. This means that \a second must109* have all the fields that \a first does, but the reverse need not110* be true. This is typically expected to be used to check if a111* stream's format is compatible with a given sink. In such a case,112* \a first would be the sink's format and \a second would be the113* stream's. \since 1.0 */114int pa_format_info_is_compatible(const pa_format_info *first, const pa_format_info *second);115116/** Maximum required string length for117* pa_format_info_snprint(). Please note that this value can change118* with any release without warning and without being considered API119* or ABI breakage. You should not use this definition anywhere where120* it might become part of an ABI. \since 1.0 */121#define PA_FORMAT_INFO_SNPRINT_MAX 256122123/** Return a human-readable string representing the given format. \since 1.0 */124char *pa_format_info_snprint(char *s, size_t l, const pa_format_info *f);125126/** Parse a human-readable string of the form generated by127* \a pa_format_info_snprint() into a pa_format_info structure. \since 1.0 */128pa_format_info* pa_format_info_from_string(const char *str);129130/** Utility function to take a \a pa_sample_spec and generate the corresponding131* \a pa_format_info.132*133* Note that if you want the server to choose some of the stream parameters,134* for example the sample rate, so that they match the device parameters, then135* you shouldn't use this function. In order to allow the server to choose136* a parameter value, that parameter must be left unspecified in the137* pa_format_info object, and this function always specifies all parameters. An138* exception is the channel map: if you pass NULL for the channel map, then the139* channel map will be left unspecified, allowing the server to choose it.140*141* \since 2.0 */142pa_format_info* pa_format_info_from_sample_spec(const pa_sample_spec *ss, const pa_channel_map *map);143144/** Utility function to generate a \a pa_sample_spec and \a pa_channel_map corresponding to a given \a pa_format_info. The145* conversion for PCM formats is straight-forward. For non-PCM formats, if there is a fixed size-time conversion (i.e. all146* IEC61937-encapsulated formats), a "fake" sample spec whose size-time conversion corresponds to this format is provided and147* the channel map argument is ignored. For formats with variable size-time conversion, this function will fail. Returns a148* negative integer if conversion failed and 0 on success. \since 2.0 */149int pa_format_info_to_sample_spec(const pa_format_info *f, pa_sample_spec *ss, pa_channel_map *map);150151/** Represents the type of value type of a property on a \ref pa_format_info. \since 2.0 */152typedef enum pa_prop_type_t {153PA_PROP_TYPE_INT,154/**< Integer property */155156PA_PROP_TYPE_INT_RANGE,157/**< Integer range property */158159PA_PROP_TYPE_INT_ARRAY,160/**< Integer array property */161162PA_PROP_TYPE_STRING,163/**< String property */164165PA_PROP_TYPE_STRING_ARRAY,166/**< String array property */167168PA_PROP_TYPE_INVALID = -1,169/**< Represents an invalid type */170} pa_prop_type_t;171172/** \cond fulldocs */173#define PA_PROP_TYPE_INT PA_PROP_TYPE_INT174#define PA_PROP_TYPE_INT_RANGE PA_PROP_TYPE_INT_RANGE175#define PA_PROP_TYPE_INT_ARRAY PA_PROP_TYPE_INT_ARRAY176#define PA_PROP_TYPE_STRING PA_PROP_TYPE_STRING177#define PA_PROP_TYPE_STRING_ARRAY PA_PROP_TYPE_STRING_ARRAY178#define PA_PROP_TYPE_INVALID PA_PROP_TYPE_INVALID179/** \endcond */180181/** Gets the type of property \a key in a given \ref pa_format_info. \since 2.0 */182pa_prop_type_t pa_format_info_get_prop_type(const pa_format_info *f, const char *key);183184/** Gets an integer property from the given format info. Returns 0 on success and a negative integer on failure. \since 2.0 */185int pa_format_info_get_prop_int(const pa_format_info *f, const char *key, int *v);186/** Gets an integer range property from the given format info. Returns 0 on success and a negative integer on failure.187* \since 2.0 */188int pa_format_info_get_prop_int_range(const pa_format_info *f, const char *key, int *min, int *max);189/** Gets an integer array property from the given format info. \a values contains the values and \a n_values contains the190* number of elements. The caller must free \a values using \ref pa_xfree. Returns 0 on success and a negative integer on191* failure. \since 2.0 */192int pa_format_info_get_prop_int_array(const pa_format_info *f, const char *key, int **values, int *n_values);193/** Gets a string property from the given format info. The caller must free the returned string using \ref pa_xfree. Returns194* 0 on success and a negative integer on failure. \since 2.0 */195int pa_format_info_get_prop_string(const pa_format_info *f, const char *key, char **v);196/** Gets a string array property from the given format info. \a values contains the values and \a n_values contains197* the number of elements. The caller must free \a values using \ref pa_format_info_free_string_array. Returns 0 on success and198* a negative integer on failure. \since 2.0 */199int pa_format_info_get_prop_string_array(const pa_format_info *f, const char *key, char ***values, int *n_values);200201/** Frees a string array returned by \ref pa_format_info_get_prop_string_array. \since 2.0 */202void pa_format_info_free_string_array(char **values, int n_values);203204/** Sets an integer property on the given format info. \since 1.0 */205void pa_format_info_set_prop_int(pa_format_info *f, const char *key, int value);206/** Sets a property with a list of integer values on the given format info. \since 1.0 */207void pa_format_info_set_prop_int_array(pa_format_info *f, const char *key, const int *values, int n_values);208/** Sets a property which can have any value in a given integer range on the given format info. \since 1.0 */209void pa_format_info_set_prop_int_range(pa_format_info *f, const char *key, int min, int max);210/** Sets a string property on the given format info. \since 1.0 */211void pa_format_info_set_prop_string(pa_format_info *f, const char *key, const char *value);212/** Sets a property with a list of string values on the given format info. \since 1.0 */213void pa_format_info_set_prop_string_array(pa_format_info *f, const char *key, const char **values, int n_values);214215/** Convenience method to set the sample format as a property on the given216* format.217*218* Note for PCM: If the sample format is left unspecified in the pa_format_info219* object, then the server will select the stream sample format. In that case220* the stream sample format will most likely match the device sample format,221* meaning that sample format conversion will be avoided.222*223* \since 1.0 */224void pa_format_info_set_sample_format(pa_format_info *f, pa_sample_format_t sf);225226/** Convenience method to set the sampling rate as a property on the given227* format.228*229* Note for PCM: If the sample rate is left unspecified in the pa_format_info230* object, then the server will select the stream sample rate. In that case the231* stream sample rate will most likely match the device sample rate, meaning232* that sample rate conversion will be avoided.233*234* \since 1.0 */235void pa_format_info_set_rate(pa_format_info *f, int rate);236237/** Convenience method to set the number of channels as a property on the given238* format.239*240* Note for PCM: If the channel count is left unspecified in the pa_format_info241* object, then the server will select the stream channel count. In that case242* the stream channel count will most likely match the device channel count,243* meaning that up/downmixing will be avoided.244*245* \since 1.0 */246void pa_format_info_set_channels(pa_format_info *f, int channels);247248/** Convenience method to set the channel map as a property on the given249* format.250*251* Note for PCM: If the channel map is left unspecified in the pa_format_info252* object, then the server will select the stream channel map. In that case the253* stream channel map will most likely match the device channel map, meaning254* that remixing will be avoided.255*256* \since 1.0 */257void pa_format_info_set_channel_map(pa_format_info *f, const pa_channel_map *map);258259PA_C_DECL_END260261#endif262263264