diff --git a/pinos/gst/gstpinosformat.c b/pinos/gst/gstpinosformat.c index 541a5d31e..8ff1ab68d 100644 --- a/pinos/gst/gstpinosformat.c +++ b/pinos/gst/gstpinosformat.c @@ -25,10 +25,9 @@ #include #include -#include -#include -#include #include +#include +#include #include "gstpinosformat.h" @@ -45,6 +44,7 @@ static SpaMediaSubtypesAudio media_subtypes_audio = { 0, }; static SpaPropVideo prop_video = { 0, }; static SpaPropAudio prop_audio = { 0, }; static SpaVideoFormats video_formats = { 0, }; +static SpaAudioFormats audio_formats = { 0, }; static void ensure_types (void) @@ -56,6 +56,7 @@ ensure_types (void) spa_prop_video_map (spa_id_map_get_default (), &prop_video); spa_prop_audio_map (spa_id_map_get_default (), &prop_audio); spa_video_formats_map (spa_id_map_get_default (), &video_formats); + spa_audio_formats_map (spa_id_map_get_default (), &audio_formats); } static const MediaType media_type_map[] = { @@ -134,6 +135,49 @@ static const uint32_t *video_format_map[] = { &video_formats.VYUY, }; +#if __BYTE_ORDER == __BIG_ENDIAN +#define _FORMAT_LE(fmt) &audio_formats. fmt ## _OE +#define _FORMAT_BE(fmt) &audio_formats. fmt +#elif __BYTE_ORDER == __LITTLE_ENDIAN +#define _FORMAT_LE(fmt) &audio_formats. fmt +#define _FORMAT_BE(fmt) &audio_formats. fmt ## _OE +#endif + +static const uint32_t *audio_format_map[] = { + &audio_formats.UNKNOWN, + &audio_formats.ENCODED, + &audio_formats.S8, + &audio_formats.U8, + _FORMAT_LE (S16), + _FORMAT_BE (S16), + _FORMAT_LE (U16), + _FORMAT_BE (U16), + _FORMAT_LE (S24_32), + _FORMAT_BE (S24_32), + _FORMAT_LE (U24_32), + _FORMAT_BE (U24_32), + _FORMAT_LE (S32), + _FORMAT_BE (S32), + _FORMAT_LE (U32), + _FORMAT_BE (U32), + _FORMAT_LE (S24), + _FORMAT_BE (S24), + _FORMAT_LE (U24), + _FORMAT_BE (U24), + _FORMAT_LE (S20), + _FORMAT_BE (S20), + _FORMAT_LE (U20), + _FORMAT_BE (U20), + _FORMAT_LE (S18), + _FORMAT_BE (S18), + _FORMAT_LE (U18), + _FORMAT_BE (U18), + _FORMAT_LE (F32), + _FORMAT_BE (F32), + _FORMAT_LE (F64), + _FORMAT_BE (F64), +}; + typedef struct { SpaPODBuilder b; const MediaType *type; @@ -379,7 +423,7 @@ handle_audio_fields (ConvertData *d) prop_audio.format, get_range_type (value) | SPA_POD_PROP_FLAG_READWRITE); - spa_pod_builder_int (&d->b, gst_audio_format_from_string (v)); + spa_pod_builder_uri (&d->b, *audio_format_map[gst_video_format_from_string (v)]); } if (i > 1) SPA_POD_BUILDER_DEREF (&d->b, f.ref, SpaPODProp)->body.flags |= SPA_POD_PROP_FLAG_UNSET; @@ -583,8 +627,10 @@ gst_caps_from_format (const SpaFormat *format) return NULL; if (media_subtype == media_subtypes.raw) { + const char * str = spa_id_map_get_uri (spa_id_map_get_default (), f.info.raw.format); + res = gst_caps_new_simple ("audio/x-raw", - "format", G_TYPE_STRING, gst_audio_format_to_string (f.info.raw.format), + "format", G_TYPE_STRING, strstr (str, "#") + 1, "layout", G_TYPE_STRING, "interleaved", "rate", G_TYPE_INT, f.info.raw.rate, "channels", G_TYPE_INT, f.info.raw.channels, diff --git a/spa/include/spa/audio/format-utils.h b/spa/include/spa/audio/format-utils.h new file mode 100644 index 000000000..50b6a5b57 --- /dev/null +++ b/spa/include/spa/audio/format-utils.h @@ -0,0 +1,60 @@ +/* Simple Plugin API + * Copyright (C) 2016 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __SPA_AUDIO_FORMAT_UTILS_H__ +#define __SPA_AUDIO_FORMAT_UTILS_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +typedef struct { + uint32_t format; + uint32_t flags; + uint32_t layout; + uint32_t rate; + uint32_t channels; + uint32_t channel_mask; +} SpaPropAudio; + +static inline void +spa_prop_audio_map (SpaIDMap *map, SpaPropAudio *types) +{ + if (types->format == 0) { + types->format = spa_id_map_get_id (map, SPA_PROP_AUDIO__format); + types->flags = spa_id_map_get_id (map, SPA_PROP_AUDIO__flags); + types->layout = spa_id_map_get_id (map, SPA_PROP_AUDIO__layout); + types->rate = spa_id_map_get_id (map, SPA_PROP_AUDIO__rate); + types->channels = spa_id_map_get_id (map, SPA_PROP_AUDIO__channels); + types->channel_mask = spa_id_map_get_id (map, SPA_PROP_AUDIO__channelMask); + } +} + +SpaResult spa_format_audio_parse (const SpaFormat *format, + SpaAudioInfo *info); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* __SPA_AUDIO_FORMAT_UTILS */ diff --git a/spa/include/spa/audio/format.h b/spa/include/spa/audio/format.h index 305e58606..7acf7d3b2 100644 --- a/spa/include/spa/audio/format.h +++ b/spa/include/spa/audio/format.h @@ -24,7 +24,7 @@ extern "C" { #endif -#include +#include #include typedef struct _SpaAudioInfo SpaAudioInfo; @@ -39,28 +39,6 @@ typedef struct _SpaAudioInfo SpaAudioInfo; #define SPA_PROP_AUDIO__channels SPA_PROP_AUDIO_PREFIX "channels" #define SPA_PROP_AUDIO__channelMask SPA_PROP_AUDIO_PREFIX "channel-mask" -typedef struct { - uint32_t format; - uint32_t flags; - uint32_t layout; - uint32_t rate; - uint32_t channels; - uint32_t channel_mask; -} SpaPropAudio; - -static inline void -spa_prop_audio_map (SpaIDMap *map, SpaPropAudio *types) -{ - if (types->format == 0) { - types->format = spa_id_map_get_id (map, SPA_PROP_AUDIO__format); - types->flags = spa_id_map_get_id (map, SPA_PROP_AUDIO__flags); - types->layout = spa_id_map_get_id (map, SPA_PROP_AUDIO__layout); - types->rate = spa_id_map_get_id (map, SPA_PROP_AUDIO__rate); - types->channels = spa_id_map_get_id (map, SPA_PROP_AUDIO__channels); - types->channel_mask = spa_id_map_get_id (map, SPA_PROP_AUDIO__channelMask); - } -} - struct _SpaAudioInfo { uint32_t media_type; uint32_t media_subtype; @@ -69,9 +47,6 @@ struct _SpaAudioInfo { } info; }; -SpaResult spa_format_audio_parse (const SpaFormat *format, - SpaAudioInfo *info); - #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/spa/include/spa/audio/raw-utils.h b/spa/include/spa/audio/raw-utils.h new file mode 100644 index 000000000..082df307d --- /dev/null +++ b/spa/include/spa/audio/raw-utils.h @@ -0,0 +1,119 @@ +/* Simple Plugin API + * Copyright (C) 2016 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __SPA_AUDIO_RAW_UTILS_H__ +#define __SPA_AUDIO_RAW_UTILS_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#if __BYTE_ORDER == __BIG_ENDIAN +#define _SPA_AUDIO_FORMAT_NE(fmt) SPA_AUDIO_FORMAT_PREFIX fmt "BE" +#define _SPA_AUDIO_FORMAT_OE(fmt) SPA_AUDIO_FORMAT_PREFIX fmt "LE" +#elif __BYTE_ORDER == __LITTLE_ENDIAN +#define _SPA_AUDIO_FORMAT_NE(fmt) SPA_AUDIO_FORMAT_PREFIX fmt "LE" +#define _SPA_AUDIO_FORMAT_OE(fmt) SPA_AUDIO_FORMAT_PREFIX fmt "BE" +#endif + +typedef struct { + uint32_t UNKNOWN; + uint32_t ENCODED; + uint32_t S8; + uint32_t U8; + uint32_t S16; + uint32_t U16; + uint32_t S24_32; + uint32_t U24_32; + uint32_t S32; + uint32_t U32; + uint32_t S24; + uint32_t U24; + uint32_t S20; + uint32_t U20; + uint32_t S18; + uint32_t U18; + uint32_t F32; + uint32_t F64; + uint32_t S16_OE; + uint32_t U16_OE; + uint32_t S24_32_OE; + uint32_t U24_32_OE; + uint32_t S32_OE; + uint32_t U32_OE; + uint32_t S24_OE; + uint32_t U24_OE; + uint32_t S20_OE; + uint32_t U20_OE; + uint32_t S18_OE; + uint32_t U18_OE; + uint32_t F32_OE; + uint32_t F64_OE; +} SpaAudioFormats; + +static inline void +spa_audio_formats_map (SpaIDMap *map, SpaAudioFormats *types) +{ + if (types->ENCODED == 0) { + types->UNKNOWN = 0; + types->ENCODED = spa_id_map_get_id (map, SPA_AUDIO_FORMAT__ENCODED); + + types->S8 = spa_id_map_get_id (map, SPA_AUDIO_FORMAT__S8); + types->U8 = spa_id_map_get_id (map, SPA_AUDIO_FORMAT__U8); + + types->S16 = spa_id_map_get_id (map, _SPA_AUDIO_FORMAT_NE ("S16")); + types->U16 = spa_id_map_get_id (map, _SPA_AUDIO_FORMAT_NE ("U16")); + types->S24_32 = spa_id_map_get_id (map, _SPA_AUDIO_FORMAT_NE ("S24_32")); + types->U24_32 = spa_id_map_get_id (map, _SPA_AUDIO_FORMAT_NE ("U24_32")); + types->S32 = spa_id_map_get_id (map, _SPA_AUDIO_FORMAT_NE ("S32")); + types->U32 = spa_id_map_get_id (map, _SPA_AUDIO_FORMAT_NE ("U32")); + types->S24 = spa_id_map_get_id (map, _SPA_AUDIO_FORMAT_NE ("S24")); + types->U24 = spa_id_map_get_id (map, _SPA_AUDIO_FORMAT_NE ("U24")); + types->S20 = spa_id_map_get_id (map, _SPA_AUDIO_FORMAT_NE ("S20")); + types->U20 = spa_id_map_get_id (map, _SPA_AUDIO_FORMAT_NE ("U20")); + types->S18 = spa_id_map_get_id (map, _SPA_AUDIO_FORMAT_NE ("S18")); + types->U18 = spa_id_map_get_id (map, _SPA_AUDIO_FORMAT_NE ("U18")); + types->F32 = spa_id_map_get_id (map, _SPA_AUDIO_FORMAT_NE ("F32")); + types->F64 = spa_id_map_get_id (map, _SPA_AUDIO_FORMAT_NE ("F64")); + + types->S16_OE = spa_id_map_get_id (map, _SPA_AUDIO_FORMAT_OE ("S16")); + types->U16_OE = spa_id_map_get_id (map, _SPA_AUDIO_FORMAT_OE ("U16")); + types->S24_32_OE = spa_id_map_get_id (map, _SPA_AUDIO_FORMAT_OE ("S24_32")); + types->U24_32_OE = spa_id_map_get_id (map, _SPA_AUDIO_FORMAT_OE ("U24_32")); + types->S32_OE = spa_id_map_get_id (map, _SPA_AUDIO_FORMAT_OE ("S32")); + types->U32_OE = spa_id_map_get_id (map, _SPA_AUDIO_FORMAT_OE ("U32")); + types->S24_OE = spa_id_map_get_id (map, _SPA_AUDIO_FORMAT_OE ("S24")); + types->U24_OE = spa_id_map_get_id (map, _SPA_AUDIO_FORMAT_OE ("U24")); + types->S20_OE = spa_id_map_get_id (map, _SPA_AUDIO_FORMAT_OE ("S20")); + types->U20_OE = spa_id_map_get_id (map, _SPA_AUDIO_FORMAT_OE ("U20")); + types->S18_OE = spa_id_map_get_id (map, _SPA_AUDIO_FORMAT_OE ("S18")); + types->U18_OE = spa_id_map_get_id (map, _SPA_AUDIO_FORMAT_OE ("U18")); + types->F32_OE = spa_id_map_get_id (map, _SPA_AUDIO_FORMAT_OE ("F32")); + types->F64_OE = spa_id_map_get_id (map, _SPA_AUDIO_FORMAT_OE ("F64")); + } +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* __SPA_AUDIO_RAW_UTILS_H__ */ diff --git a/spa/include/spa/audio/raw.h b/spa/include/spa/audio/raw.h index 4bbb1fdc5..e0dd7541f 100644 --- a/spa/include/spa/audio/raw.h +++ b/spa/include/spa/audio/raw.h @@ -28,72 +28,41 @@ typedef struct _SpaAudioInfoRaw SpaAudioInfoRaw; #include -#if __BYTE_ORDER == __BIG_ENDIAN -#define _SPA_AUDIO_FORMAT_NE(fmt) SPA_AUDIO_FORMAT_ ## fmt ## BE -#define _SPA_AUDIO_FORMAT_OE(fmt) SPA_AUDIO_FORMAT_ ## fmt ## LE -#elif __BYTE_ORDER == __LITTLE_ENDIAN -#define _SPA_AUDIO_FORMAT_NE(fmt) SPA_AUDIO_FORMAT_ ## fmt ## LE -#define _SPA_AUDIO_FORMAT_OE(fmt) SPA_AUDIO_FORMAT_ ## fmt ## BE -#endif - -typedef enum { - SPA_AUDIO_FORMAT_UNKNOWN, - SPA_AUDIO_FORMAT_ENCODED, - /* 8 bit */ - SPA_AUDIO_FORMAT_S8, - SPA_AUDIO_FORMAT_U8, - /* 16 bit */ - SPA_AUDIO_FORMAT_S16LE, - SPA_AUDIO_FORMAT_S16BE, - SPA_AUDIO_FORMAT_U16LE, - SPA_AUDIO_FORMAT_U16BE, - /* 24 bit in low 3 bytes of 32 bits*/ - SPA_AUDIO_FORMAT_S24_32LE, - SPA_AUDIO_FORMAT_S24_32BE, - SPA_AUDIO_FORMAT_U24_32LE, - SPA_AUDIO_FORMAT_U24_32BE, - /* 32 bit */ - SPA_AUDIO_FORMAT_S32LE, - SPA_AUDIO_FORMAT_S32BE, - SPA_AUDIO_FORMAT_U32LE, - SPA_AUDIO_FORMAT_U32BE, - /* 24 bit in 3 bytes*/ - SPA_AUDIO_FORMAT_S24LE, - SPA_AUDIO_FORMAT_S24BE, - SPA_AUDIO_FORMAT_U24LE, - SPA_AUDIO_FORMAT_U24BE, - /* 20 bit in 3 bytes*/ - SPA_AUDIO_FORMAT_S20LE, - SPA_AUDIO_FORMAT_S20BE, - SPA_AUDIO_FORMAT_U20LE, - SPA_AUDIO_FORMAT_U20BE, - /* 18 bit in 3 bytes*/ - SPA_AUDIO_FORMAT_S18LE, - SPA_AUDIO_FORMAT_S18BE, - SPA_AUDIO_FORMAT_U18LE, - SPA_AUDIO_FORMAT_U18BE, - /* float */ - SPA_AUDIO_FORMAT_F32LE, - SPA_AUDIO_FORMAT_F32BE, - SPA_AUDIO_FORMAT_F64LE, - SPA_AUDIO_FORMAT_F64BE, - /* native endianness equivalents */ - SPA_AUDIO_FORMAT_S16 = _SPA_AUDIO_FORMAT_NE(S16), - SPA_AUDIO_FORMAT_U16 = _SPA_AUDIO_FORMAT_NE(U16), - SPA_AUDIO_FORMAT_S24_32 = _SPA_AUDIO_FORMAT_NE(S24_32), - SPA_AUDIO_FORMAT_U24_32 = _SPA_AUDIO_FORMAT_NE(U24_32), - SPA_AUDIO_FORMAT_S32 = _SPA_AUDIO_FORMAT_NE(S32), - SPA_AUDIO_FORMAT_U32 = _SPA_AUDIO_FORMAT_NE(U32), - SPA_AUDIO_FORMAT_S24 = _SPA_AUDIO_FORMAT_NE(S24), - SPA_AUDIO_FORMAT_U24 = _SPA_AUDIO_FORMAT_NE(U24), - SPA_AUDIO_FORMAT_S20 = _SPA_AUDIO_FORMAT_NE(S20), - SPA_AUDIO_FORMAT_U20 = _SPA_AUDIO_FORMAT_NE(U20), - SPA_AUDIO_FORMAT_S18 = _SPA_AUDIO_FORMAT_NE(S18), - SPA_AUDIO_FORMAT_U18 = _SPA_AUDIO_FORMAT_NE(U18), - SPA_AUDIO_FORMAT_F32 = _SPA_AUDIO_FORMAT_NE(F32), - SPA_AUDIO_FORMAT_F64 = _SPA_AUDIO_FORMAT_NE(F64) -} SpaAudioFormat; +#define SPA_AUDIO_FORMAT_URI "http://spaplug.in/ns/audio-format" +#define SPA_AUDIO_FORMAT_PREFIX SPA_AUDIO_FORMAT_URI "#" +#define SPA_AUDIO_FORMAT__UNKNOWN SPA_AUDIO_FORMAT_PREFIX "UNKNOWN" +#define SPA_AUDIO_FORMAT__ENCODED SPA_AUDIO_FORMAT_PREFIX "ENCODED" +#define SPA_AUDIO_FORMAT__S8 SPA_AUDIO_FORMAT_PREFIX "S8" +#define SPA_AUDIO_FORMAT__U8 SPA_AUDIO_FORMAT_PREFIX "U8" +#define SPA_AUDIO_FORMAT__S16LE SPA_AUDIO_FORMAT_PREFIX "S16LE" +#define SPA_AUDIO_FORMAT__S16BE SPA_AUDIO_FORMAT_PREFIX "S16BE" +#define SPA_AUDIO_FORMAT__U16LE SPA_AUDIO_FORMAT_PREFIX "U16LE" +#define SPA_AUDIO_FORMAT__U16BE SPA_AUDIO_FORMAT_PREFIX "U16BE" +#define SPA_AUDIO_FORMAT__S24_32LE SPA_AUDIO_FORMAT_PREFIX "S24_32LE" +#define SPA_AUDIO_FORMAT__S24_32BE SPA_AUDIO_FORMAT_PREFIX "S24_32BE" +#define SPA_AUDIO_FORMAT__U24_32LE SPA_AUDIO_FORMAT_PREFIX "U24_32LE" +#define SPA_AUDIO_FORMAT__U24_32BE SPA_AUDIO_FORMAT_PREFIX "U24_32BE" +#define SPA_AUDIO_FORMAT__S32LE SPA_AUDIO_FORMAT_PREFIX "S32LE" +#define SPA_AUDIO_FORMAT__S32BE SPA_AUDIO_FORMAT_PREFIX "S32BE" +#define SPA_AUDIO_FORMAT__U32LE SPA_AUDIO_FORMAT_PREFIX "U32LE" +#define SPA_AUDIO_FORMAT__U32BE SPA_AUDIO_FORMAT_PREFIX "U32BE" +#define SPA_AUDIO_FORMAT__S24LE SPA_AUDIO_FORMAT_PREFIX "S24LE" +#define SPA_AUDIO_FORMAT__S24BE SPA_AUDIO_FORMAT_PREFIX "S24BE" +#define SPA_AUDIO_FORMAT__U24LE SPA_AUDIO_FORMAT_PREFIX "U24LE" +#define SPA_AUDIO_FORMAT__U24BE SPA_AUDIO_FORMAT_PREFIX "U24BE" +#define SPA_AUDIO_FORMAT__S20LE SPA_AUDIO_FORMAT_PREFIX "S20LE" +#define SPA_AUDIO_FORMAT__S20BE SPA_AUDIO_FORMAT_PREFIX "S20BE" +#define SPA_AUDIO_FORMAT__U20LE SPA_AUDIO_FORMAT_PREFIX "U20LE" +#define SPA_AUDIO_FORMAT__U20BE SPA_AUDIO_FORMAT_PREFIX "U20BE" +#define SPA_AUDIO_FORMAT__S18LE SPA_AUDIO_FORMAT_PREFIX "S18LE" +#define SPA_AUDIO_FORMAT__S18BE SPA_AUDIO_FORMAT_PREFIX "S18BE" +#define SPA_AUDIO_FORMAT__U18LE SPA_AUDIO_FORMAT_PREFIX "U18LE" +#define SPA_AUDIO_FORMAT__U18BE SPA_AUDIO_FORMAT_PREFIX "U18BE" +#define SPA_AUDIO_FORMAT__F32LE SPA_AUDIO_FORMAT_PREFIX "F32LE" +#define SPA_AUDIO_FORMAT__F32BE SPA_AUDIO_FORMAT_PREFIX "F32BE" +#define SPA_AUDIO_FORMAT__F64LE SPA_AUDIO_FORMAT_PREFIX "F64LE" +#define SPA_AUDIO_FORMAT__F64BE SPA_AUDIO_FORMAT_PREFIX "F64BE" /** * SpaAudioFlags: @@ -130,7 +99,7 @@ typedef enum { * @channel_mask: the channel mask */ struct _SpaAudioInfoRaw { - SpaAudioFormat format; + uint32_t format; SpaAudioFlags flags; SpaAudioLayout layout; uint32_t rate; diff --git a/spa/include/spa/video/format-utils.h b/spa/include/spa/video/format-utils.h new file mode 100644 index 000000000..433afb1d0 --- /dev/null +++ b/spa/include/spa/video/format-utils.h @@ -0,0 +1,84 @@ +/* Simple Plugin API + * Copyright (C) 2016 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __SPA_VIDEO_FORMAT_UTILS_H__ +#define __SPA_VIDEO_FORMAT_UTILS_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +typedef struct { + uint32_t format; + uint32_t size; + uint32_t framerate; + uint32_t max_framerate; + uint32_t views; + uint32_t interlace_mode; + uint32_t pixel_aspect_ratio; + uint32_t multiview_mode; + uint32_t multiview_flags; + uint32_t chroma_site; + uint32_t color_range; + uint32_t color_matrix; + uint32_t transfer_function; + uint32_t color_primaries; + uint32_t profile; + uint32_t level; + uint32_t stream_format; + uint32_t alignment; +} SpaPropVideo; + +static inline void +spa_prop_video_map (SpaIDMap *map, SpaPropVideo *types) +{ + if (types->format == 0) { + types->format = spa_id_map_get_id (map, SPA_PROP_VIDEO__format); + types->size = spa_id_map_get_id (map, SPA_PROP_VIDEO__size); + types->framerate = spa_id_map_get_id (map, SPA_PROP_VIDEO__framerate); + types->max_framerate = spa_id_map_get_id (map, SPA_PROP_VIDEO__maxFramerate); + types->views = spa_id_map_get_id (map, SPA_PROP_VIDEO__views); + types->interlace_mode = spa_id_map_get_id (map, SPA_PROP_VIDEO__interlaceMode); + types->pixel_aspect_ratio = spa_id_map_get_id (map, SPA_PROP_VIDEO__pixelAspectRatio); + types->multiview_mode = spa_id_map_get_id (map, SPA_PROP_VIDEO__multiviewMode); + types->multiview_flags = spa_id_map_get_id (map, SPA_PROP_VIDEO__multiviewFlags); + types->chroma_site = spa_id_map_get_id (map, SPA_PROP_VIDEO__chromaSite); + types->color_range = spa_id_map_get_id (map, SPA_PROP_VIDEO__colorRange); + types->color_matrix = spa_id_map_get_id (map, SPA_PROP_VIDEO__colorMatrix); + types->transfer_function = spa_id_map_get_id (map, SPA_PROP_VIDEO__transferFunction); + types->color_primaries = spa_id_map_get_id (map, SPA_PROP_VIDEO__colorPrimaries); + types->profile = spa_id_map_get_id (map, SPA_PROP_VIDEO__profile); + types->level = spa_id_map_get_id (map, SPA_PROP_VIDEO__level); + types->stream_format = spa_id_map_get_id (map, SPA_PROP_VIDEO__streamFormat); + types->alignment = spa_id_map_get_id (map, SPA_PROP_VIDEO__alignment); + } +} + +SpaResult spa_format_video_parse (const SpaFormat *format, + SpaVideoInfo *info); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* __SPA_VIDEO_FORMAT_UTILS */ diff --git a/spa/include/spa/video/format.h b/spa/include/spa/video/format.h index 645a1addf..1baf1651f 100644 --- a/spa/include/spa/video/format.h +++ b/spa/include/spa/video/format.h @@ -52,55 +52,6 @@ typedef struct _SpaVideoInfo SpaVideoInfo; #define SPA_PROP_VIDEO__streamFormat SPA_PROP_VIDEO_PREFIX "stream-format" #define SPA_PROP_VIDEO__alignment SPA_PROP_VIDEO_PREFIX "alignment" -typedef struct { - uint32_t format; - uint32_t size; - uint32_t framerate; - uint32_t max_framerate; - uint32_t views; - uint32_t interlace_mode; - uint32_t pixel_aspect_ratio; - uint32_t multiview_mode; - uint32_t multiview_flags; - uint32_t chroma_site; - uint32_t color_range; - uint32_t color_matrix; - uint32_t transfer_function; - uint32_t color_primaries; - uint32_t profile; - uint32_t level; - uint32_t stream_format; - uint32_t alignment; -} SpaPropVideo; - -static inline void -spa_prop_video_map (SpaIDMap *map, SpaPropVideo *types) -{ - if (types->format == 0) { - types->format = spa_id_map_get_id (map, SPA_PROP_VIDEO__format); - types->size = spa_id_map_get_id (map, SPA_PROP_VIDEO__size); - types->framerate = spa_id_map_get_id (map, SPA_PROP_VIDEO__framerate); - types->max_framerate = spa_id_map_get_id (map, SPA_PROP_VIDEO__maxFramerate); - types->views = spa_id_map_get_id (map, SPA_PROP_VIDEO__views); - types->interlace_mode = spa_id_map_get_id (map, SPA_PROP_VIDEO__interlaceMode); - types->pixel_aspect_ratio = spa_id_map_get_id (map, SPA_PROP_VIDEO__pixelAspectRatio); - types->multiview_mode = spa_id_map_get_id (map, SPA_PROP_VIDEO__multiviewMode); - types->multiview_flags = spa_id_map_get_id (map, SPA_PROP_VIDEO__multiviewFlags); - types->chroma_site = spa_id_map_get_id (map, SPA_PROP_VIDEO__chromaSite); - types->color_range = spa_id_map_get_id (map, SPA_PROP_VIDEO__colorRange); - types->color_matrix = spa_id_map_get_id (map, SPA_PROP_VIDEO__colorMatrix); - types->transfer_function = spa_id_map_get_id (map, SPA_PROP_VIDEO__transferFunction); - types->color_primaries = spa_id_map_get_id (map, SPA_PROP_VIDEO__colorPrimaries); - types->profile = spa_id_map_get_id (map, SPA_PROP_VIDEO__profile); - types->level = spa_id_map_get_id (map, SPA_PROP_VIDEO__level); - types->stream_format = spa_id_map_get_id (map, SPA_PROP_VIDEO__streamFormat); - types->alignment = spa_id_map_get_id (map, SPA_PROP_VIDEO__alignment); - } -} - -SpaResult spa_format_video_parse (const SpaFormat *format, - SpaVideoInfo *info); - struct _SpaVideoInfo { uint32_t media_type; uint32_t media_subtype; diff --git a/spa/include/spa/video/raw-utils.h b/spa/include/spa/video/raw-utils.h new file mode 100644 index 000000000..cc326729b --- /dev/null +++ b/spa/include/spa/video/raw-utils.h @@ -0,0 +1,177 @@ +/* Simple Plugin API + * Copyright (C) 2016 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __SPA_VIDEO_RAW_UTILS_H__ +#define __SPA_VIDEO_RAW_UTILS_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct _SpaVideoInfoRaw SpaVideoInfoRaw; + +#include +#include + +typedef struct +{ + uint32_t UNKNOWN; + uint32_t ENCODED; + uint32_t I420; + uint32_t YV12; + uint32_t YUY2; + uint32_t UYVY; + uint32_t AYUV; + uint32_t RGBx; + uint32_t BGRx; + uint32_t xRGB; + uint32_t xBGR; + uint32_t RGBA; + uint32_t BGRA; + uint32_t ARGB; + uint32_t ABGR; + uint32_t RGB; + uint32_t BGR; + uint32_t Y41B; + uint32_t Y42B; + uint32_t YVYU; + uint32_t Y444; + uint32_t v210; + uint32_t v216; + uint32_t NV12; + uint32_t NV21; + uint32_t GRAY8; + uint32_t GRAY16_BE; + uint32_t GRAY16_LE; + uint32_t v308; + uint32_t RGB16; + uint32_t BGR16; + uint32_t RGB15; + uint32_t BGR15; + uint32_t UYVP; + uint32_t A420; + uint32_t RGB8P; + uint32_t YUV9; + uint32_t YVU9; + uint32_t IYU1; + uint32_t ARGB64; + uint32_t AYUV64; + uint32_t r210; + uint32_t I420_10BE; + uint32_t I420_10LE; + uint32_t I422_10BE; + uint32_t I422_10LE; + uint32_t Y444_10BE; + uint32_t Y444_10LE; + uint32_t GBR; + uint32_t GBR_10BE; + uint32_t GBR_10LE; + uint32_t NV16; + uint32_t NV24; + uint32_t NV12_64Z32; + uint32_t A420_10BE; + uint32_t A420_10LE; + uint32_t A422_10BE; + uint32_t A422_10LE; + uint32_t A444_10BE; + uint32_t A444_10LE; + uint32_t NV61; + uint32_t P010_10BE; + uint32_t P010_10LE; + uint32_t IYU2; + uint32_t VYUY; +} SpaVideoFormats; + +static inline void +spa_video_formats_map (SpaIDMap *map, SpaVideoFormats *types) +{ + if (types->ENCODED == 0) { + types->UNKNOWN = 0; + types->ENCODED = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__ENCODED); + types->I420 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__I420); + types->YV12 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__YV12); + types->YUY2 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__YUY2); + types->UYVY = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__UYVY); + types->AYUV = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__AYUV); + types->RGBx = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__RGBx); + types->BGRx = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__BGRx); + types->xRGB = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__xRGB); + types->xBGR = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__xBGR); + types->RGBA = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__RGBA); + types->BGRA = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__BGRA); + types->ARGB = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__ARGB); + types->ABGR = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__ABGR); + types->RGB = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__RGB); + types->BGR = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__BGR); + types->Y41B = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__Y41B); + types->Y42B = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__Y42B); + types->YVYU = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__YVYU); + types->Y444 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__Y444); + types->v210 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__v210); + types->v216 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__v216); + types->NV12 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__NV12); + types->NV21 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__NV21); + types->GRAY8 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__GRAY8); + types->GRAY16_BE = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__GRAY16_BE); + types->GRAY16_LE = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__GRAY16_LE); + types->v308 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__v308); + types->RGB16 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__RGB16); + types->BGR16 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__BGR16); + types->RGB15 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__RGB15); + types->BGR15 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__BGR15); + types->UYVP = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__UYVP); + types->A420 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__A420); + types->RGB8P = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__RGB8P); + types->YUV9 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__YUV9); + types->YVU9 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__YVU9); + types->IYU1 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__IYU1); + types->ARGB64 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__ARGB64); + types->AYUV64 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__AYUV64); + types->r210 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__r210); + types->I420_10BE = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__I420_10BE); + types->I420_10LE = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__I420_10LE); + types->I422_10BE = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__I422_10BE); + types->I422_10LE = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__I422_10LE); + types->Y444_10BE = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__Y444_10BE); + types->Y444_10LE = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__Y444_10LE); + types->GBR = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__GBR); + types->GBR_10BE = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__GBR_10BE); + types->GBR_10LE = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__GBR_10LE); + types->NV16 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__NV16); + types->NV24 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__NV24); + types->NV12_64Z32 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__NV12_64Z32); + types->A420_10BE = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__A420_10BE); + types->A420_10LE = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__A420_10LE); + types->A422_10BE = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__A422_10BE); + types->A422_10LE = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__A422_10LE); + types->A444_10BE = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__A444_10BE); + types->A444_10LE = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__A444_10LE); + types->NV61 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__NV61); + types->P010_10BE = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__P010_10BE); + types->P010_10LE = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__P010_10LE); + types->IYU2 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__IYU2); + types->VYUY = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__VYUY); + } +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* __SPA_VIDEO_RAW_UTILS_H__ */ diff --git a/spa/include/spa/video/raw.h b/spa/include/spa/video/raw.h index 36b6b49cb..be09116f6 100644 --- a/spa/include/spa/video/raw.h +++ b/spa/include/spa/video/raw.h @@ -103,147 +103,6 @@ typedef struct _SpaVideoInfoRaw SpaVideoInfoRaw; #define SPA_VIDEO_FORMAT__IYU2 SPA_VIDEO_FORMAT_PREFIX "IYU2" #define SPA_VIDEO_FORMAT__VYUY SPA_VIDEO_FORMAT_PREFIX "VYUY" -typedef struct -{ - uint32_t UNKNOWN; - uint32_t ENCODED; - uint32_t I420; - uint32_t YV12; - uint32_t YUY2; - uint32_t UYVY; - uint32_t AYUV; - uint32_t RGBx; - uint32_t BGRx; - uint32_t xRGB; - uint32_t xBGR; - uint32_t RGBA; - uint32_t BGRA; - uint32_t ARGB; - uint32_t ABGR; - uint32_t RGB; - uint32_t BGR; - uint32_t Y41B; - uint32_t Y42B; - uint32_t YVYU; - uint32_t Y444; - uint32_t v210; - uint32_t v216; - uint32_t NV12; - uint32_t NV21; - uint32_t GRAY8; - uint32_t GRAY16_BE; - uint32_t GRAY16_LE; - uint32_t v308; - uint32_t RGB16; - uint32_t BGR16; - uint32_t RGB15; - uint32_t BGR15; - uint32_t UYVP; - uint32_t A420; - uint32_t RGB8P; - uint32_t YUV9; - uint32_t YVU9; - uint32_t IYU1; - uint32_t ARGB64; - uint32_t AYUV64; - uint32_t r210; - uint32_t I420_10BE; - uint32_t I420_10LE; - uint32_t I422_10BE; - uint32_t I422_10LE; - uint32_t Y444_10BE; - uint32_t Y444_10LE; - uint32_t GBR; - uint32_t GBR_10BE; - uint32_t GBR_10LE; - uint32_t NV16; - uint32_t NV24; - uint32_t NV12_64Z32; - uint32_t A420_10BE; - uint32_t A420_10LE; - uint32_t A422_10BE; - uint32_t A422_10LE; - uint32_t A444_10BE; - uint32_t A444_10LE; - uint32_t NV61; - uint32_t P010_10BE; - uint32_t P010_10LE; - uint32_t IYU2; - uint32_t VYUY; -} SpaVideoFormats; - -static inline void -spa_video_formats_map (SpaIDMap *map, SpaVideoFormats *types) -{ - if (types->ENCODED == 0) { - types->UNKNOWN = 0; - types->ENCODED = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__ENCODED); - types->I420 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__I420); - types->YV12 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__YV12); - types->YUY2 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__YUY2); - types->UYVY = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__UYVY); - types->AYUV = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__AYUV); - types->RGBx = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__RGBx); - types->BGRx = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__BGRx); - types->xRGB = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__xRGB); - types->xBGR = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__xBGR); - types->RGBA = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__RGBA); - types->BGRA = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__BGRA); - types->ARGB = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__ARGB); - types->ABGR = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__ABGR); - types->RGB = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__RGB); - types->BGR = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__BGR); - types->Y41B = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__Y41B); - types->Y42B = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__Y42B); - types->YVYU = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__YVYU); - types->Y444 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__Y444); - types->v210 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__v210); - types->v216 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__v216); - types->NV12 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__NV12); - types->NV21 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__NV21); - types->GRAY8 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__GRAY8); - types->GRAY16_BE = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__GRAY16_BE); - types->GRAY16_LE = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__GRAY16_LE); - types->v308 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__v308); - types->RGB16 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__RGB16); - types->BGR16 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__BGR16); - types->RGB15 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__RGB15); - types->BGR15 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__BGR15); - types->UYVP = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__UYVP); - types->A420 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__A420); - types->RGB8P = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__RGB8P); - types->YUV9 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__YUV9); - types->YVU9 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__YVU9); - types->IYU1 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__IYU1); - types->ARGB64 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__ARGB64); - types->AYUV64 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__AYUV64); - types->r210 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__r210); - types->I420_10BE = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__I420_10BE); - types->I420_10LE = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__I420_10LE); - types->I422_10BE = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__I422_10BE); - types->I422_10LE = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__I422_10LE); - types->Y444_10BE = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__Y444_10BE); - types->Y444_10LE = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__Y444_10LE); - types->GBR = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__GBR); - types->GBR_10BE = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__GBR_10BE); - types->GBR_10LE = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__GBR_10LE); - types->NV16 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__NV16); - types->NV24 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__NV24); - types->NV12_64Z32 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__NV12_64Z32); - types->A420_10BE = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__A420_10BE); - types->A420_10LE = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__A420_10LE); - types->A422_10BE = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__A422_10BE); - types->A422_10LE = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__A422_10LE); - types->A444_10BE = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__A444_10BE); - types->A444_10LE = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__A444_10LE); - types->NV61 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__NV61); - types->P010_10BE = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__P010_10BE); - types->P010_10LE = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__P010_10LE); - types->IYU2 = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__IYU2); - types->VYUY = spa_id_map_get_id (map, SPA_VIDEO_FORMAT__VYUY); - } -} - /** * SpaVideoFlags: * @SPA_VIDEO_FLAG_NONE: no flags diff --git a/spa/lib/audio-raw.c b/spa/lib/audio-raw.c index 680fe3c54..3f52940cd 100644 --- a/spa/lib/audio-raw.c +++ b/spa/lib/audio-raw.c @@ -23,8 +23,8 @@ #include #include -#include -#include +#include +#include SpaResult spa_format_audio_parse (const SpaFormat *format, @@ -48,7 +48,7 @@ spa_format_audio_parse (const SpaFormat *format, if (info->media_subtype == media_subtypes.raw) { spa_format_query (format, - prop_audio.format, SPA_POD_TYPE_INT, &info->info.raw.format, + prop_audio.format, SPA_POD_TYPE_URI, &info->info.raw.format, prop_audio.flags, SPA_POD_TYPE_INT, &info->info.raw.flags, prop_audio.layout, SPA_POD_TYPE_INT, &info->info.raw.layout, prop_audio.rate, SPA_POD_TYPE_INT, &info->info.raw.rate, diff --git a/spa/lib/video-raw.c b/spa/lib/video-raw.c index 401daa847..292777331 100644 --- a/spa/lib/video-raw.c +++ b/spa/lib/video-raw.c @@ -22,9 +22,8 @@ #include #include -#include -#include #include +#include #include #include diff --git a/spa/plugins/alsa/alsa-sink.c b/spa/plugins/alsa/alsa-sink.c index deed7a1ba..09970de47 100644 --- a/spa/plugins/alsa/alsa-sink.c +++ b/spa/plugins/alsa/alsa-sink.c @@ -326,9 +326,9 @@ next: case 0: spa_pod_builder_format (&b, &f[0], this->uri.media_types.audio, this->uri.media_subtypes.raw, - PROP_U_EN (&f[1], this->uri.prop_audio.format, SPA_POD_TYPE_INT, 3, SPA_AUDIO_FORMAT_S16, - SPA_AUDIO_FORMAT_S16, - SPA_AUDIO_FORMAT_S32), + PROP_U_EN (&f[1], this->uri.prop_audio.format, SPA_POD_TYPE_URI, 3, this->uri.audio_formats.S16, + this->uri.audio_formats.S16, + this->uri.audio_formats.S32), PROP_U_MM (&f[1], this->uri.prop_audio.rate, SPA_POD_TYPE_INT, 44100, 1, INT32_MAX), PROP_U_MM (&f[1], this->uri.prop_audio.channels, SPA_POD_TYPE_INT, 2, 1, INT32_MAX)); break; @@ -799,6 +799,7 @@ alsa_sink_init (const SpaHandleFactory *factory, spa_media_subtypes_map (this->map, &this->uri.media_subtypes); spa_media_subtypes_audio_map (this->map, &this->uri.media_subtypes_audio); spa_prop_audio_map (this->map, &this->uri.prop_audio); + spa_audio_formats_map (this->map, &this->uri.audio_formats); this->node = alsasink_node; this->stream = SND_PCM_STREAM_PLAYBACK; diff --git a/spa/plugins/alsa/alsa-source.c b/spa/plugins/alsa/alsa-source.c index f1c7ce101..63f27413f 100644 --- a/spa/plugins/alsa/alsa-source.c +++ b/spa/plugins/alsa/alsa-source.c @@ -360,9 +360,9 @@ next: case 0: spa_pod_builder_format (&b, &f[0], this->uri.media_types.audio, this->uri.media_subtypes.raw, - PROP_U_EN (&f[1], this->uri.prop_audio.format, SPA_POD_TYPE_INT, 3, SPA_AUDIO_FORMAT_S16, - SPA_AUDIO_FORMAT_S16, - SPA_AUDIO_FORMAT_S32), + PROP_U_EN (&f[1], this->uri.prop_audio.format, SPA_POD_TYPE_URI, 3, this->uri.audio_formats.S16, + this->uri.audio_formats.S16, + this->uri.audio_formats.S32), PROP_U_MM (&f[1], this->uri.prop_audio.rate, SPA_POD_TYPE_INT, 44100, 1, INT32_MAX), PROP_U_MM (&f[1], this->uri.prop_audio.channels, SPA_POD_TYPE_INT, 2, 1, INT32_MAX)); break; @@ -865,6 +865,7 @@ alsa_source_init (const SpaHandleFactory *factory, spa_media_subtypes_map (this->map, &this->uri.media_subtypes); spa_media_subtypes_audio_map (this->map, &this->uri.media_subtypes_audio); spa_prop_audio_map (this->map, &this->uri.prop_audio); + spa_audio_formats_map (this->map, &this->uri.audio_formats); this->node = alsasource_node; this->clock = alsasource_clock; diff --git a/spa/plugins/alsa/alsa-utils.c b/spa/plugins/alsa/alsa-utils.c index 58f83b073..4b38c20e8 100644 --- a/spa/plugins/alsa/alsa-utils.c +++ b/spa/plugins/alsa/alsa-utils.c @@ -56,54 +56,52 @@ spa_alsa_close (SpaALSAState *state) return err; } -static snd_pcm_format_t -spa_alsa_format_to_alsa (SpaAudioFormat format) -{ - switch (format) { - case SPA_AUDIO_FORMAT_S8: - return SND_PCM_FORMAT_S8; - case SPA_AUDIO_FORMAT_U8: - return SND_PCM_FORMAT_U8; - /* 16 bit */ - case SPA_AUDIO_FORMAT_S16LE: - return SND_PCM_FORMAT_S16_LE; - case SPA_AUDIO_FORMAT_S16BE: - return SND_PCM_FORMAT_S16_BE; - case SPA_AUDIO_FORMAT_U16LE: - return SND_PCM_FORMAT_U16_LE; - case SPA_AUDIO_FORMAT_U16BE: - return SND_PCM_FORMAT_U16_BE; - /* 24 bit in low 3 bytes of 32 bits */ - case SPA_AUDIO_FORMAT_S24_32LE: - return SND_PCM_FORMAT_S24_LE; - case SPA_AUDIO_FORMAT_S24_32BE: - return SND_PCM_FORMAT_S24_BE; - case SPA_AUDIO_FORMAT_U24_32LE: - return SND_PCM_FORMAT_U24_LE; - case SPA_AUDIO_FORMAT_U24_32BE: - return SND_PCM_FORMAT_U24_BE; - /* 24 bit in 3 bytes */ - case SPA_AUDIO_FORMAT_S24LE: - return SND_PCM_FORMAT_S24_3LE; - case SPA_AUDIO_FORMAT_S24BE: - return SND_PCM_FORMAT_S24_3BE; - case SPA_AUDIO_FORMAT_U24LE: - return SND_PCM_FORMAT_U24_3LE; - case SPA_AUDIO_FORMAT_U24BE: - return SND_PCM_FORMAT_U24_3BE; - /* 32 bit */ - case SPA_AUDIO_FORMAT_S32LE: - return SND_PCM_FORMAT_S32_LE; - case SPA_AUDIO_FORMAT_S32BE: - return SND_PCM_FORMAT_S32_BE; - case SPA_AUDIO_FORMAT_U32LE: - return SND_PCM_FORMAT_U32_LE; - case SPA_AUDIO_FORMAT_U32BE: - return SND_PCM_FORMAT_U32_BE; - default: - break; - } +typedef struct { + off_t format_offset; + snd_pcm_format_t format; +} FormatInfo; +#if __BYTE_ORDER == __BIG_ENDIAN +#define _FORMAT_LE(fmt) offsetof(URI, audio_formats. fmt ## _OE) +#define _FORMAT_BE(fmt) offsetof(URI, audio_formats. fmt) +#elif __BYTE_ORDER == __LITTLE_ENDIAN +#define _FORMAT_LE(fmt) offsetof(URI, audio_formats. fmt) +#define _FORMAT_BE(fmt) offsetof(URI, audio_formats. fmt ## _OE) +#endif + +static const FormatInfo format_info[] = +{ + { offsetof(URI, audio_formats.UNKNOWN), SND_PCM_FORMAT_UNKNOWN }, + { offsetof(URI, audio_formats.S8), SND_PCM_FORMAT_S8 }, + { offsetof(URI, audio_formats.U8), SND_PCM_FORMAT_U8 }, + { _FORMAT_LE (S16), SND_PCM_FORMAT_S16_LE }, + { _FORMAT_BE (S16), SND_PCM_FORMAT_S16_BE }, + { _FORMAT_LE (U16), SND_PCM_FORMAT_U16_LE }, + { _FORMAT_BE (U16), SND_PCM_FORMAT_U16_BE }, + { _FORMAT_LE (S24_32), SND_PCM_FORMAT_S24_LE }, + { _FORMAT_BE (S24_32), SND_PCM_FORMAT_S24_BE }, + { _FORMAT_LE (U24_32), SND_PCM_FORMAT_U24_LE }, + { _FORMAT_BE (U24_32), SND_PCM_FORMAT_U24_BE }, + { _FORMAT_LE (S24), SND_PCM_FORMAT_S24_3LE }, + { _FORMAT_BE (S24), SND_PCM_FORMAT_S24_3BE }, + { _FORMAT_LE (U24), SND_PCM_FORMAT_U24_3LE }, + { _FORMAT_BE (U24), SND_PCM_FORMAT_U24_3BE }, + { _FORMAT_LE (S32), SND_PCM_FORMAT_S32_LE }, + { _FORMAT_BE (S32), SND_PCM_FORMAT_S32_BE }, + { _FORMAT_LE (U32), SND_PCM_FORMAT_U32_LE }, + { _FORMAT_BE (U32), SND_PCM_FORMAT_U32_BE }, +}; + +static snd_pcm_format_t +spa_alsa_format_to_alsa (URI *uri, uint32_t format) +{ + int i; + + for (i = 0; i < SPA_N_ELEMENTS (format_info); i++) { + uint32_t f = *SPA_MEMBER (uri, format_info[i].format_offset, uint32_t); + if (f == format) + return format_info[i].format; + } return SND_PCM_FORMAT_UNKNOWN; } @@ -134,7 +132,7 @@ spa_alsa_set_format (SpaALSAState *state, SpaAudioInfo *fmt, SpaPortFormatFlags CHECK (snd_pcm_hw_params_set_access(hndl, params, SND_PCM_ACCESS_MMAP_INTERLEAVED), "set_access"); /* set the sample format */ - format = spa_alsa_format_to_alsa (info->format); + format = spa_alsa_format_to_alsa (&state->uri, info->format); spa_log_info (state->log, "Stream parameters are %iHz, %s, %i channels", info->rate, snd_pcm_format_name(format), info->channels); CHECK (snd_pcm_hw_params_set_format (hndl, params, format), "set_format"); diff --git a/spa/plugins/alsa/alsa-utils.h b/spa/plugins/alsa/alsa-utils.h index 6890ac5e8..293c7585d 100644 --- a/spa/plugins/alsa/alsa-utils.h +++ b/spa/plugins/alsa/alsa-utils.h @@ -34,7 +34,7 @@ extern "C" { #include #include #include -#include +#include #include typedef struct _SpaALSAState SpaALSAState; @@ -66,6 +66,7 @@ typedef struct { SpaMediaSubtypes media_subtypes; SpaMediaSubtypesAudio media_subtypes_audio; SpaPropAudio prop_audio; + SpaAudioFormats audio_formats; } URI; struct _SpaALSAState { diff --git a/spa/plugins/audiomixer/audiomixer.c b/spa/plugins/audiomixer/audiomixer.c index 4544691d8..315e2c674 100644 --- a/spa/plugins/audiomixer/audiomixer.c +++ b/spa/plugins/audiomixer/audiomixer.c @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #define MAX_PORTS 128 diff --git a/spa/plugins/audiotestsrc/audiotestsrc.c b/spa/plugins/audiotestsrc/audiotestsrc.c index c366728b7..345b960ef 100644 --- a/spa/plugins/audiotestsrc/audiotestsrc.c +++ b/spa/plugins/audiotestsrc/audiotestsrc.c @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include @@ -42,6 +42,7 @@ typedef struct { SpaMediaTypes media_types; SpaMediaSubtypes media_subtypes; SpaPropAudio prop_audio; + SpaAudioFormats audio_formats; } URI; typedef struct _SpaAudioTestSrc SpaAudioTestSrc; @@ -471,9 +472,9 @@ next: case 0: spa_pod_builder_format (&b, &f[0], this->uri.media_types.audio, this->uri.media_subtypes.raw, - PROP_U_EN (&f[1], this->uri.prop_audio.format, SPA_POD_TYPE_INT, 3, SPA_AUDIO_FORMAT_S16, - SPA_AUDIO_FORMAT_S16, - SPA_AUDIO_FORMAT_S32), + PROP_U_EN (&f[1], this->uri.prop_audio.format, SPA_POD_TYPE_URI, 3, this->uri.audio_formats.S16, + this->uri.audio_formats.S16, + this->uri.audio_formats.S32), PROP_U_MM (&f[1], this->uri.prop_audio.rate, SPA_POD_TYPE_INT, 44100, 1, INT32_MAX), PROP_U_MM (&f[1], this->uri.prop_audio.channels, SPA_POD_TYPE_INT, 2, 1, INT32_MAX)); break; @@ -589,7 +590,7 @@ spa_audiotestsrc_node_port_get_format (SpaNode *node, spa_pod_builder_init (&b, this->format_buffer, sizeof (this->format_buffer)); spa_pod_builder_format (&b, &f[0], this->uri.media_types.audio, this->uri.media_subtypes.raw, - PROP (&f[1], this->uri.prop_audio.format, SPA_POD_TYPE_INT, this->current_format.info.raw.format), + PROP (&f[1], this->uri.prop_audio.format, SPA_POD_TYPE_URI, this->current_format.info.raw.format), PROP (&f[1], this->uri.prop_audio.rate, SPA_POD_TYPE_INT, this->current_format.info.raw.rate), PROP (&f[1], this->uri.prop_audio.channels, SPA_POD_TYPE_INT, this->current_format.info.raw.channels)); @@ -958,6 +959,7 @@ audiotestsrc_init (const SpaHandleFactory *factory, spa_media_types_fill (&this->uri.media_types, this->map); spa_media_subtypes_map (this->map, &this->uri.media_subtypes); spa_prop_audio_map (this->map, &this->uri.prop_audio); + spa_audio_formats_map (this->map, &this->uri.audio_formats); this->node = audiotestsrc_node; this->clock = audiotestsrc_clock; diff --git a/spa/plugins/ffmpeg/ffmpeg-dec.c b/spa/plugins/ffmpeg/ffmpeg-dec.c index 9a0f282f4..129680d37 100644 --- a/spa/plugins/ffmpeg/ffmpeg-dec.c +++ b/spa/plugins/ffmpeg/ffmpeg-dec.c @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include typedef struct _SpaFFMpegDec SpaFFMpegDec; diff --git a/spa/plugins/ffmpeg/ffmpeg-enc.c b/spa/plugins/ffmpeg/ffmpeg-enc.c index ae898e938..50110e40e 100644 --- a/spa/plugins/ffmpeg/ffmpeg-enc.c +++ b/spa/plugins/ffmpeg/ffmpeg-enc.c @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include typedef struct _SpaFFMpegEnc SpaFFMpegEnc; diff --git a/spa/plugins/v4l2/v4l2-source.c b/spa/plugins/v4l2/v4l2-source.c index 6a955b8d1..e95fb5bcc 100644 --- a/spa/plugins/v4l2/v4l2-source.c +++ b/spa/plugins/v4l2/v4l2-source.c @@ -25,7 +25,7 @@ #include #include -#include +#include #include #include #include diff --git a/spa/plugins/videotestsrc/videotestsrc.c b/spa/plugins/videotestsrc/videotestsrc.c index f6cd7eaec..921e8f541 100644 --- a/spa/plugins/videotestsrc/videotestsrc.c +++ b/spa/plugins/videotestsrc/videotestsrc.c @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include diff --git a/spa/plugins/volume/volume.c b/spa/plugins/volume/volume.c index 0c588f76a..e86f9b653 100644 --- a/spa/plugins/volume/volume.c +++ b/spa/plugins/volume/volume.c @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include @@ -66,6 +66,7 @@ typedef struct { SpaMediaTypes media_types; SpaMediaSubtypes media_subtypes; SpaPropAudio prop_audio; + SpaAudioFormats audio_formats; } URI; struct _SpaVolume { @@ -312,10 +313,10 @@ next: case 0: spa_pod_builder_format (&b, &f[0], this->uri.media_types.audio, this->uri.media_subtypes.raw, - PROP_U_EN (&f[1], this->uri.prop_audio.format, SPA_POD_TYPE_INT, 3, - SPA_AUDIO_FORMAT_S16, - SPA_AUDIO_FORMAT_S16, - SPA_AUDIO_FORMAT_S32), + PROP_U_EN (&f[1], this->uri.prop_audio.format, SPA_POD_TYPE_URI, 3, + this->uri.audio_formats.S16, + this->uri.audio_formats.S16, + this->uri.audio_formats.S32), PROP_U_MM (&f[1], this->uri.prop_audio.rate, SPA_POD_TYPE_INT, 44100, 1, INT32_MAX), PROP_U_MM (&f[1], this->uri.prop_audio.channels, SPA_POD_TYPE_INT, 2, 1, INT32_MAX)); @@ -844,6 +845,7 @@ volume_init (const SpaHandleFactory *factory, spa_media_types_fill (&this->uri.media_types, this->map); spa_media_subtypes_map (this->map, &this->uri.media_subtypes); spa_prop_audio_map (this->map, &this->uri.prop_audio); + spa_audio_formats_map (this->map, &this->uri.audio_formats); this->node = volume_node; reset_volume_props (&this->props); diff --git a/spa/plugins/xv/xv-sink.c b/spa/plugins/xv/xv-sink.c index d56acc1ba..a35d937e5 100644 --- a/spa/plugins/xv/xv-sink.c +++ b/spa/plugins/xv/xv-sink.c @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include typedef struct _SpaXvSink SpaXvSink; diff --git a/spa/tests/test-props.c b/spa/tests/test-props.c index fe656cef8..b07c05c3c 100644 --- a/spa/tests/test-props.c +++ b/spa/tests/test-props.c @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include