From c3839c76377ea7662f29364ae66718e8ac6233af Mon Sep 17 00:00:00 2001 From: Arun Raghavan Date: Fri, 25 Feb 2011 12:35:14 +0530 Subject: core: Add a pa_format_info structure This will be used to represent the format of data provided by the client for both compressed and PCM formats in a new extended API. --- src/pulse/format.h | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 src/pulse/format.h (limited to 'src/pulse/format.h') diff --git a/src/pulse/format.h b/src/pulse/format.h new file mode 100644 index 00000000..fdf4f377 --- /dev/null +++ b/src/pulse/format.h @@ -0,0 +1,79 @@ +#ifndef fooformathfoo +#define fooformathfoo + +/*** + This file is part of PulseAudio. + + Copyright 2011 Intel Corporation + Copyright 2011 Collabora Multimedia + Copyright 2011 Arun Raghavan + + PulseAudio is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published + by the Free Software Foundation; either version 2.1 of the License, + or (at your option) any later version. + + PulseAudio is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with PulseAudio; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA. +***/ + +#include +#include + +PA_C_DECL_BEGIN + +/**< Represents the type of encoding used in a stream or accepted by a sink. \since 1.0 */ +typedef enum pa_encoding { + PA_ENCODING_ANY, + /**< Any encoding format, PCM or compressed */ + + PA_ENCODING_PCM, + /**< Any PCM format */ + + PA_ENCODING_AC3_IEC61937, + /**< AC3 data encapsulated in IEC 61937 header/padding */ + + PA_ENCODING_EAC3_IEC61937, + /**< EAC3 data encapsulated in IEC 61937 header/padding */ + + PA_ENCODING_MPEG_IEC61937, + /**< MPEG-1 or MPEG-2 (Part 3, not AAC) data encapsulated in IEC 61937 header/padding */ + + PA_ENCODING_MAX, + /**< Valid encoding types must be less than this value */ + + PA_ENCODING_INVALID = -1, + /**< Represents an invalid encoding */ +} pa_encoding_t; + +/**< Represents the format of data provided in a stream or processed by a sink. \since 1.0 */ +typedef struct pa_format_info { + pa_encoding_t encoding; + /**< The encoding used for the format */ + + pa_proplist *plist; + /**< Additional encoding-specific properties such as sample rate, bitrate, etc. */ +} pa_format_info; + +/**< Allocates a new \a pa_format_info structure. Clients must initialise at least the encoding field themselves. */ +pa_format_info* pa_format_info_new(void); + +/**< Returns a new \a pa_format_info struct and representing the same format as \a src */ +pa_format_info* pa_format_info_copy(const pa_format_info *src); + +/**< Frees a \a pa_format_info structure */ +void pa_format_info_free(pa_format_info *f); + +/** Returns non-zero when the format info structure is valid */ +int pa_format_info_valid(pa_format_info *f); + +PA_C_DECL_END + +#endif -- cgit From 54c391e6db550c5519df0ebb37f2197eed440c92 Mon Sep 17 00:00:00 2001 From: Arun Raghavan Date: Tue, 1 Mar 2011 16:34:06 +0530 Subject: format: Add convenience API to check if a format is PCM or not --- src/pulse/format.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/pulse/format.h') diff --git a/src/pulse/format.h b/src/pulse/format.h index fdf4f377..7e3ab08d 100644 --- a/src/pulse/format.h +++ b/src/pulse/format.h @@ -74,6 +74,9 @@ void pa_format_info_free(pa_format_info *f); /** Returns non-zero when the format info structure is valid */ int pa_format_info_valid(pa_format_info *f); +/** Returns non-zero when the format info structure represents a PCM (i.e. uncompressed data) format */ +int pa_format_info_is_pcm(pa_format_info *f); + PA_C_DECL_END #endif -- cgit From a3a004214404c6f91a82c1e2164444e5e08c26cf Mon Sep 17 00:00:00 2001 From: Arun Raghavan Date: Tue, 8 Mar 2011 20:14:46 +0530 Subject: format: Const-ify some parameters --- src/pulse/format.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/pulse/format.h') diff --git a/src/pulse/format.h b/src/pulse/format.h index 7e3ab08d..03b34059 100644 --- a/src/pulse/format.h +++ b/src/pulse/format.h @@ -72,10 +72,10 @@ pa_format_info* pa_format_info_copy(const pa_format_info *src); void pa_format_info_free(pa_format_info *f); /** Returns non-zero when the format info structure is valid */ -int pa_format_info_valid(pa_format_info *f); +int pa_format_info_valid(const pa_format_info *f); /** Returns non-zero when the format info structure represents a PCM (i.e. uncompressed data) format */ -int pa_format_info_is_pcm(pa_format_info *f); +int pa_format_info_is_pcm(const pa_format_info *f); PA_C_DECL_END -- cgit From 8631f4e2c44b47db76795bebdbab54914a1f3ea0 Mon Sep 17 00:00:00 2001 From: Arun Raghavan Date: Tue, 8 Mar 2011 20:15:36 +0530 Subject: format: Add some convenience functions for printing --- src/pulse/format.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/pulse/format.h') diff --git a/src/pulse/format.h b/src/pulse/format.h index 03b34059..51c9426c 100644 --- a/src/pulse/format.h +++ b/src/pulse/format.h @@ -53,6 +53,9 @@ typedef enum pa_encoding { /**< Represents an invalid encoding */ } pa_encoding_t; +/** Returns a printable string representing the given encoding type. \since 1.0 */ +const char *pa_encoding_to_string(pa_encoding_t e) PA_GCC_CONST; + /**< Represents the format of data provided in a stream or processed by a sink. \since 1.0 */ typedef struct pa_format_info { pa_encoding_t encoding; @@ -77,6 +80,16 @@ int pa_format_info_valid(const pa_format_info *f); /** Returns non-zero when the format info structure represents a PCM (i.e. uncompressed data) format */ int pa_format_info_is_pcm(const pa_format_info *f); +/** Maximum required string length for + * pa_format_info_snprint(). Please note that this value can change + * with any release without warning and without being considered API + * or ABI breakage. You should not use this definition anywhere where + * it might become part of an ABI. \since 1.0 */ +#define PA_FORMAT_INFO_SNPRINT_MAX 256 + +/** Return a human-readable string representing the given format. \since 1.0 */ +char *pa_format_info_snprint(char *s, size_t l, const pa_format_info *f); + PA_C_DECL_END #endif -- cgit From 9a39a3df10c3874bf0b5b091f721a6d8ab8750a5 Mon Sep 17 00:00:00 2001 From: Arun Raghavan Date: Wed, 9 Mar 2011 20:50:25 +0530 Subject: format: Add a type for DTS --- src/pulse/format.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/pulse/format.h') diff --git a/src/pulse/format.h b/src/pulse/format.h index 51c9426c..bd32ba92 100644 --- a/src/pulse/format.h +++ b/src/pulse/format.h @@ -46,6 +46,9 @@ typedef enum pa_encoding { PA_ENCODING_MPEG_IEC61937, /**< MPEG-1 or MPEG-2 (Part 3, not AAC) data encapsulated in IEC 61937 header/padding */ + PA_ENCODING_DTS_IEC61937, + /**< DTS data encapsulated in IEC 61937 header/padding */ + PA_ENCODING_MAX, /**< Valid encoding types must be less than this value */ -- cgit From 13a33abf45f31417076f283ca7da9d9f74892286 Mon Sep 17 00:00:00 2001 From: Arun Raghavan Date: Tue, 29 Mar 2011 17:16:08 +0530 Subject: format: Export pa_format_info_is_compatible in API This allows clients to perform checks between formats as well. --- src/pulse/format.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/pulse/format.h') diff --git a/src/pulse/format.h b/src/pulse/format.h index bd32ba92..b0efe502 100644 --- a/src/pulse/format.h +++ b/src/pulse/format.h @@ -83,6 +83,15 @@ int pa_format_info_valid(const pa_format_info *f); /** Returns non-zero when the format info structure represents a PCM (i.e. uncompressed data) format */ int pa_format_info_is_pcm(const pa_format_info *f); +/** Returns non-zero if the format represented \a first is a subset of + * the format represented by \second. This means that \a second must + * have all the fields that \a first does, but the reverse need not + * be true. This is typically expected to be used to check if a + * stream's format is compatible with a given sink. In such a case, + * \a first would be the sink's format and \a second would be the + * stream's.*/ +int pa_format_info_is_compatible(pa_format_info *first, pa_format_info *second); + /** Maximum required string length for * pa_format_info_snprint(). Please note that this value can change * with any release without warning and without being considered API -- cgit From 8d076d09902fe618e69f3d71e42299bffe2af437 Mon Sep 17 00:00:00 2001 From: Arun Raghavan Date: Wed, 13 Apr 2011 14:05:18 +0530 Subject: format: Extend properties to handle lists/ranges This replaces the simple string used by pa_format_info's proplist with a JSON string (accessed via new API only). This allows us to express lists and ranges more cleanly, and embed type information for future extensibility. We use json-c for JSON parsing. This is a lightweight depdency (32 KB on my system) and avoids the hassle of having to reinvent a JSON parser. Also included is a test which verifies functionality and is valgrind-clean. --- src/pulse/format.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/pulse/format.h') diff --git a/src/pulse/format.h b/src/pulse/format.h index b0efe502..0498e68a 100644 --- a/src/pulse/format.h +++ b/src/pulse/format.h @@ -102,6 +102,17 @@ int pa_format_info_is_compatible(pa_format_info *first, pa_format_info *second); /** Return a human-readable string representing the given format. \since 1.0 */ char *pa_format_info_snprint(char *s, size_t l, const pa_format_info *f); +/** Sets an integer property on the given format info */ +void pa_format_info_set_prop_int(pa_format_info *f, const char *key, int value); +/** Sets a property with a list of integer values on the given format info */ +void pa_format_info_set_prop_int_array(pa_format_info *f, const char *key, const int *values, int n_values); +/** Sets a property which can have any value in a given integer range on the given format info */ +void pa_format_info_set_prop_int_range(pa_format_info *f, const char *key, int min, int max); +/** Sets a string property on the given format info */ +void pa_format_info_set_prop_string(pa_format_info *f, const char *key, const char *value); +/** Sets a property with a list of string values on the given format info */ +void pa_format_info_set_prop_string_array(pa_format_info *f, const char *key, const char **values, int n_values); + PA_C_DECL_END #endif -- cgit From 1404db3d47c77ef3a360feed4ae8932cc8e443a0 Mon Sep 17 00:00:00 2001 From: Arun Raghavan Date: Wed, 13 Apr 2011 15:37:25 +0530 Subject: format: Add some convenience API for setting properties Adds functions to set sample format, rate, channels and channel map on a format to make life easier for users of the API. --- src/pulse/format.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/pulse/format.h') diff --git a/src/pulse/format.h b/src/pulse/format.h index 0498e68a..06e1fe62 100644 --- a/src/pulse/format.h +++ b/src/pulse/format.h @@ -26,6 +26,8 @@ #include #include +#include +#include PA_C_DECL_BEGIN @@ -113,6 +115,15 @@ void pa_format_info_set_prop_string(pa_format_info *f, const char *key, const ch /** Sets a property with a list of string values on the given format info */ void pa_format_info_set_prop_string_array(pa_format_info *f, const char *key, const char **values, int n_values); +/** Convenience method to set the sample format as a property on the given format */ +void pa_format_info_set_sample_format(pa_format_info *f, pa_sample_format_t sf); +/** Convenience method to set the sampling rate as a property on the given format */ +void pa_format_info_set_rate(pa_format_info *f, int rate); +/** Convenience method to set the number of channels as a property on the given format */ +void pa_format_info_set_channels(pa_format_info *f, int channels); +/** Convenience method to set the channel map as a property on the given format */ +void pa_format_info_set_channel_map(pa_format_info *f, const pa_channel_map *map); + PA_C_DECL_END #endif -- cgit