| 1 |
/* Simple Plugin API |
| 2 |
* |
| 3 |
* Copyright © 2018 Wim Taymans |
| 4 |
* |
| 5 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 6 |
* copy of this software and associated documentation files (the "Software"), |
| 7 |
* to deal in the Software without restriction, including without limitation |
| 8 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 10 |
* Software is furnished to do so, subject to the following conditions: |
| 11 |
* |
| 12 |
* The above copyright notice and this permission notice (including the next |
| 13 |
* paragraph) shall be included in all copies or substantial portions of the |
| 14 |
* Software. |
| 15 |
* |
| 16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 21 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 |
* DEALINGS IN THE SOFTWARE. |
| 23 |
*/ |
| 24 |
|
| 25 |
#ifndef SPA_PARAM_AUDIO_FORMAT_UTILS_H |
| 26 |
#define SPA_PARAM_AUDIO_FORMAT_UTILS_H |
| 27 |
|
| 28 |
#ifdef __cplusplus |
| 29 |
extern "C" { |
| 30 |
#endif |
| 31 |
|
| 32 |
|
| 33 |
#include <spa/pod/parser.h> |
| 34 |
#include <spa/pod/builder.h> |
| 35 |
#include <spa/param/audio/format.h> |
| 36 |
#include <spa/param/format-utils.h> |
| 37 |
|
| 38 |
static inline int |
| 39 |
spa_format_audio_raw_parse(const struct spa_pod *format, struct spa_audio_info_raw *info) |
| 40 |
{ |
| 41 |
struct spa_pod *position = NULL; |
| 42 |
int res; |
| 43 |
info->flags = 0; |
| 44 |
res = spa_pod_parse_object(format, |
| 45 |
SPA_TYPE_OBJECT_Format, NULL, |
| 46 |
SPA_FORMAT_AUDIO_format, SPA_POD_Id(&info->format), |
| 47 |
SPA_FORMAT_AUDIO_rate, SPA_POD_Int(&info->rate), |
| 48 |
SPA_FORMAT_AUDIO_channels, SPA_POD_Int(&info->channels), |
| 49 |
SPA_FORMAT_AUDIO_position, SPA_POD_OPT_Pod(&position)); |
| 50 |
if (position == NULL || |
| 51 |
!spa_pod_copy_array(position, SPA_TYPE_Id, info->position, SPA_AUDIO_MAX_CHANNELS)) |
| 52 |
SPA_FLAG_SET(info->flags, SPA_AUDIO_FLAG_UNPOSITIONED); |
| 53 |
|
| 54 |
return res; |
| 55 |
} |
| 56 |
|
| 57 |
static inline int |
| 58 |
spa_format_audio_dsp_parse(const struct spa_pod *format, struct spa_audio_info_dsp *info) |
| 59 |
{ |
| 60 |
int res; |
| 61 |
res = spa_pod_parse_object(format, |
| 62 |
SPA_TYPE_OBJECT_Format, NULL, |
| 63 |
SPA_FORMAT_AUDIO_format, SPA_POD_Id(&info->format)); |
| 64 |
return res; |
| 65 |
} |
| 66 |
|
| 67 |
static inline struct spa_pod * |
| 68 |
spa_format_audio_raw_build(struct spa_pod_builder *builder, uint32_t id, struct spa_audio_info_raw *info) |
| 69 |
{ |
| 70 |
struct spa_pod_frame f; |
| 71 |
spa_pod_builder_push_object(builder, &f, SPA_TYPE_OBJECT_Format, id); |
| 72 |
spa_pod_builder_add(builder, |
| 73 |
SPA_FORMAT_mediaType, SPA_POD_Id(SPA_MEDIA_TYPE_audio), |
| 74 |
SPA_FORMAT_mediaSubtype, SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw), |
| 75 |
0); |
| 76 |
if (info->format != SPA_AUDIO_FORMAT_UNKNOWN) |
| 77 |
spa_pod_builder_add(builder, |
| 78 |
SPA_FORMAT_AUDIO_format, SPA_POD_Id(info->format), 0); |
| 79 |
if (info->rate != 0) |
| 80 |
spa_pod_builder_add(builder, |
| 81 |
SPA_FORMAT_AUDIO_rate, SPA_POD_Int(info->rate), 0); |
| 82 |
if (info->channels != 0) { |
| 83 |
spa_pod_builder_add(builder, |
| 84 |
SPA_FORMAT_AUDIO_channels, SPA_POD_Int(info->channels), 0); |
| 85 |
if (!SPA_FLAG_IS_SET(info->flags, SPA_AUDIO_FLAG_UNPOSITIONED)) { |
| 86 |
spa_pod_builder_add(builder, SPA_FORMAT_AUDIO_position, |
| 87 |
SPA_POD_Array(sizeof(uint32_t), SPA_TYPE_Id, |
| 88 |
info->channels, info->position), 0); |
| 89 |
} |
| 90 |
} |
| 91 |
return (struct spa_pod*)spa_pod_builder_pop(builder, &f); |
| 92 |
} |
| 93 |
|
| 94 |
static inline struct spa_pod * |
| 95 |
spa_format_audio_dsp_build(struct spa_pod_builder *builder, uint32_t id, struct spa_audio_info_dsp *info) |
| 96 |
{ |
| 97 |
struct spa_pod_frame f; |
| 98 |
spa_pod_builder_push_object(builder, &f, SPA_TYPE_OBJECT_Format, id); |
| 99 |
spa_pod_builder_add(builder, |
| 100 |
SPA_FORMAT_mediaType, SPA_POD_Id(SPA_MEDIA_TYPE_audio), |
| 101 |
SPA_FORMAT_mediaSubtype, SPA_POD_Id(SPA_MEDIA_SUBTYPE_dsp), |
| 102 |
0); |
| 103 |
if (info->format != SPA_AUDIO_FORMAT_UNKNOWN) |
| 104 |
spa_pod_builder_add(builder, |
| 105 |
SPA_FORMAT_AUDIO_format, SPA_POD_Id(info->format), 0); |
| 106 |
return (struct spa_pod*)spa_pod_builder_pop(builder, &f); |
| 107 |
} |
| 108 |
|
| 109 |
#ifdef __cplusplus |
| 110 |
} /* extern "C" */ |
| 111 |
#endif |
| 112 |
|
| 113 |
#endif /* SPA_PARAM_AUDIO_FORMAT_UTILS_H */ |