PipeWire: format-utils.h Source File

PipeWire 0.3.66

Loading...
Searching...
No Matches
audio/format-utils.h
Go to the documentation of this file.
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
29extern "C" {
30#endif
31
32#include <spa/pod/parser.h>
33#include <spa/pod/builder.h>
34#include <spa/param/audio/format.h>
35#include <spa/param/format-utils.h>
36
37#include <spa/param/audio/raw-utils.h>
38#include <spa/param/audio/dsp-utils.h>
39#include <spa/param/audio/iec958-utils.h>
40#include <spa/param/audio/dsd-utils.h>
41#include <spa/param/audio/mp3-utils.h>
42#include <spa/param/audio/aac-utils.h>
43#include <spa/param/audio/vorbis-utils.h>
44#include <spa/param/audio/wma-utils.h>
45#include <spa/param/audio/ra-utils.h>
46#include <spa/param/audio/amr-utils.h>
47#include <spa/param/audio/alac-utils.h>
48#include <spa/param/audio/flac-utils.h>
49#include <spa/param/audio/ape-utils.h>
50
51
57static inline int
58 spa_format_audio_parse(const struct spa_pod *format, struct spa_audio_info *info)
59{
60 int res;
61
62 if ((res = spa_format_parse(format, &info->media_type, &info->media_subtype)) < 0)
63 return res;
64
65 if (info->media_type != SPA_MEDIA_TYPE_audio)
66 return -EINVAL;
67
68 switch (info->media_subtype) {
69 case SPA_MEDIA_SUBTYPE_raw:
70 return spa_format_audio_raw_parse(format, &info->info.raw);
71 case SPA_MEDIA_SUBTYPE_dsp:
72 return spa_format_audio_dsp_parse(format, &info->info.dsp);
73 case SPA_MEDIA_SUBTYPE_iec958:
74 return spa_format_audio_iec958_parse(format, &info->info.iec958);
75 case SPA_MEDIA_SUBTYPE_dsd:
76 return spa_format_audio_dsd_parse(format, &info->info.dsd);
77 case SPA_MEDIA_SUBTYPE_mp3:
78 return spa_format_audio_mp3_parse(format, &info->info.mp3);
79 case SPA_MEDIA_SUBTYPE_aac:
80 return spa_format_audio_aac_parse(format, &info->info.aac);
81 case SPA_MEDIA_SUBTYPE_vorbis:
82 return spa_format_audio_vorbis_parse(format, &info->info.vorbis);
83 case SPA_MEDIA_SUBTYPE_wma:
84 return spa_format_audio_wma_parse(format, &info->info.wma);
85 case SPA_MEDIA_SUBTYPE_ra:
86 return spa_format_audio_ra_parse(format, &info->info.ra);
87 case SPA_MEDIA_SUBTYPE_amr:
88 return spa_format_audio_amr_parse(format, &info->info.amr);
89 case SPA_MEDIA_SUBTYPE_alac:
90 return spa_format_audio_alac_parse(format, &info->info.alac);
91 case SPA_MEDIA_SUBTYPE_flac:
92 return spa_format_audio_flac_parse(format, &info->info.flac);
93 case SPA_MEDIA_SUBTYPE_ape:
94 return spa_format_audio_ape_parse(format, &info->info.ape);
95 }
96 return -ENOTSUP;
97}
98
99static inline struct spa_pod *
100 spa_format_audio_build(struct spa_pod_builder *builder, uint32_t id, struct spa_audio_info *info)
101{
102 switch (info->media_subtype) {
103 case SPA_MEDIA_SUBTYPE_raw:
104 return spa_format_audio_raw_build(builder, id, &info->info.raw);
105 case SPA_MEDIA_SUBTYPE_dsp:
106 return spa_format_audio_dsp_build(builder, id, &info->info.dsp);
107 case SPA_MEDIA_SUBTYPE_iec958:
108 return spa_format_audio_iec958_build(builder, id, &info->info.iec958);
109 case SPA_MEDIA_SUBTYPE_dsd:
110 return spa_format_audio_dsd_build(builder, id, &info->info.dsd);
111 case SPA_MEDIA_SUBTYPE_mp3:
112 return spa_format_audio_mp3_build(builder, id, &info->info.mp3);
113 case SPA_MEDIA_SUBTYPE_aac:
114 return spa_format_audio_aac_build(builder, id, &info->info.aac);
115 case SPA_MEDIA_SUBTYPE_vorbis:
116 return spa_format_audio_vorbis_build(builder, id, &info->info.vorbis);
117 case SPA_MEDIA_SUBTYPE_wma:
118 return spa_format_audio_wma_build(builder, id, &info->info.wma);
119 case SPA_MEDIA_SUBTYPE_ra:
120 return spa_format_audio_ra_build(builder, id, &info->info.ra);
121 case SPA_MEDIA_SUBTYPE_amr:
122 return spa_format_audio_amr_build(builder, id, &info->info.amr);
123 case SPA_MEDIA_SUBTYPE_alac:
124 return spa_format_audio_alac_build(builder, id, &info->info.alac);
125 case SPA_MEDIA_SUBTYPE_flac:
126 return spa_format_audio_flac_build(builder, id, &info->info.flac);
127 case SPA_MEDIA_SUBTYPE_ape:
128 return spa_format_audio_ape_build(builder, id, &info->info.ape);
129 }
130 errno = ENOTSUP;
131 return NULL;
132}
137#ifdef __cplusplus
138} /* extern "C" */
139#endif
140
141#endif /* SPA_PARAM_AUDIO_FORMAT_UTILS_H */
aac-utils.h
alac-utils.h
amr-utils.h
ape-utils.h
dsp-utils.h
raw-utils.h
builder.h
spa/pod/builder.h
dsd-utils.h
flac-utils.h
format-utils.h
spa_format_audio_iec958_parse
static int spa_format_audio_iec958_parse(const struct spa_pod *format, struct spa_audio_info_iec958 *info)
Definition: iec958-utils.h:48
spa_format_audio_mp3_parse
static int spa_format_audio_mp3_parse(const struct spa_pod *format, struct spa_audio_info_mp3 *info)
Definition: mp3-utils.h:48
spa_format_audio_alac_build
static struct spa_pod * spa_format_audio_alac_build(struct spa_pod_builder *builder, uint32_t id, struct spa_audio_info_alac *info)
Definition: alac-utils.h:59
spa_format_audio_iec958_build
static struct spa_pod * spa_format_audio_iec958_build(struct spa_pod_builder *builder, uint32_t id, struct spa_audio_info_iec958 *info)
Definition: iec958-utils.h:59
spa_format_audio_aac_parse
static int spa_format_audio_aac_parse(const struct spa_pod *format, struct spa_audio_info_aac *info)
Definition: aac-utils.h:48
spa_format_audio_raw_build
static struct spa_pod * spa_format_audio_raw_build(struct spa_pod_builder *builder, uint32_t id, struct spa_audio_info_raw *info)
Definition: audio/raw-utils.h:67
spa_format_parse
static int spa_format_parse(const struct spa_pod *format, uint32_t *media_type, uint32_t *media_subtype)
Definition: format-utils.h:47
spa_format_audio_raw_parse
static int spa_format_audio_raw_parse(const struct spa_pod *format, struct spa_audio_info_raw *info)
Definition: audio/raw-utils.h:48
spa_format_audio_ape_build
static struct spa_pod * spa_format_audio_ape_build(struct spa_pod_builder *builder, uint32_t id, struct spa_audio_info_ape *info)
Definition: ape-utils.h:59
spa_format_audio_ape_parse
static int spa_format_audio_ape_parse(const struct spa_pod *format, struct spa_audio_info_ape *info)
Definition: ape-utils.h:48
spa_format_audio_aac_build
static struct spa_pod * spa_format_audio_aac_build(struct spa_pod_builder *builder, uint32_t id, struct spa_audio_info_aac *info)
Definition: aac-utils.h:62
spa_format_audio_ra_build
static struct spa_pod * spa_format_audio_ra_build(struct spa_pod_builder *builder, uint32_t id, struct spa_audio_info_ra *info)
Definition: ra-utils.h:59
spa_format_audio_dsd_parse
static int spa_format_audio_dsd_parse(const struct spa_pod *format, struct spa_audio_info_dsd *info)
Definition: dsd-utils.h:48
spa_format_audio_amr_parse
static int spa_format_audio_amr_parse(const struct spa_pod *format, struct spa_audio_info_amr *info)
Definition: amr-utils.h:48
spa_format_audio_dsp_build
static struct spa_pod * spa_format_audio_dsp_build(struct spa_pod_builder *builder, uint32_t id, struct spa_audio_info_dsp *info)
Definition: audio/dsp-utils.h:58
spa_format_audio_dsp_parse
static int spa_format_audio_dsp_parse(const struct spa_pod *format, struct spa_audio_info_dsp *info)
Definition: audio/dsp-utils.h:48
spa_format_audio_vorbis_build
static struct spa_pod * spa_format_audio_vorbis_build(struct spa_pod_builder *builder, uint32_t id, struct spa_audio_info_vorbis *info)
Definition: vorbis-utils.h:59
spa_format_audio_flac_parse
static int spa_format_audio_flac_parse(const struct spa_pod *format, struct spa_audio_info_flac *info)
Definition: flac-utils.h:48
spa_format_audio_flac_build
static struct spa_pod * spa_format_audio_flac_build(struct spa_pod_builder *builder, uint32_t id, struct spa_audio_info_flac *info)
Definition: flac-utils.h:59
spa_format_audio_wma_parse
static int spa_format_audio_wma_parse(const struct spa_pod *format, struct spa_audio_info_wma *info)
Definition: wma-utils.h:48
spa_format_audio_wma_build
static struct spa_pod * spa_format_audio_wma_build(struct spa_pod_builder *builder, uint32_t id, struct spa_audio_info_wma *info)
Definition: wma-utils.h:62
spa_format_audio_build
static struct spa_pod * spa_format_audio_build(struct spa_pod_builder *builder, uint32_t id, struct spa_audio_info *info)
Definition: audio/format-utils.h:105
spa_format_audio_dsd_build
static struct spa_pod * spa_format_audio_dsd_build(struct spa_pod_builder *builder, uint32_t id, struct spa_audio_info_dsd *info)
Definition: dsd-utils.h:68
spa_format_audio_amr_build
static struct spa_pod * spa_format_audio_amr_build(struct spa_pod_builder *builder, uint32_t id, struct spa_audio_info_amr *info)
Definition: amr-utils.h:60
spa_format_audio_alac_parse
static int spa_format_audio_alac_parse(const struct spa_pod *format, struct spa_audio_info_alac *info)
Definition: alac-utils.h:48
spa_format_audio_parse
static int spa_format_audio_parse(const struct spa_pod *format, struct spa_audio_info *info)
Definition: audio/format-utils.h:63
spa_format_audio_vorbis_parse
static int spa_format_audio_vorbis_parse(const struct spa_pod *format, struct spa_audio_info_vorbis *info)
Definition: vorbis-utils.h:48
spa_format_audio_mp3_build
static struct spa_pod * spa_format_audio_mp3_build(struct spa_pod_builder *builder, uint32_t id, struct spa_audio_info_mp3 *info)
Definition: mp3-utils.h:59
spa_format_audio_ra_parse
static int spa_format_audio_ra_parse(const struct spa_pod *format, struct spa_audio_info_ra *info)
Definition: ra-utils.h:48
SPA_MEDIA_TYPE_audio
@ SPA_MEDIA_TYPE_audio
Definition: param/format.h:47
SPA_MEDIA_SUBTYPE_alac
@ SPA_MEDIA_SUBTYPE_alac
Definition: param/format.h:76
SPA_MEDIA_SUBTYPE_ra
@ SPA_MEDIA_SUBTYPE_ra
Definition: param/format.h:68
SPA_MEDIA_SUBTYPE_mp3
@ SPA_MEDIA_SUBTYPE_mp3
Definition: param/format.h:64
SPA_MEDIA_SUBTYPE_aac
@ SPA_MEDIA_SUBTYPE_aac
Definition: param/format.h:65
SPA_MEDIA_SUBTYPE_iec958
@ SPA_MEDIA_SUBTYPE_iec958
Definition: param/format.h:60
SPA_MEDIA_SUBTYPE_ape
@ SPA_MEDIA_SUBTYPE_ape
since 0.3.65
Definition: param/format.h:78
SPA_MEDIA_SUBTYPE_wma
@ SPA_MEDIA_SUBTYPE_wma
Definition: param/format.h:67
SPA_MEDIA_SUBTYPE_amr
@ SPA_MEDIA_SUBTYPE_amr
Definition: param/format.h:74
SPA_MEDIA_SUBTYPE_dsp
@ SPA_MEDIA_SUBTYPE_dsp
Definition: param/format.h:59
SPA_MEDIA_SUBTYPE_vorbis
@ SPA_MEDIA_SUBTYPE_vorbis
Definition: param/format.h:66
SPA_MEDIA_SUBTYPE_raw
@ SPA_MEDIA_SUBTYPE_raw
Definition: param/format.h:58
SPA_MEDIA_SUBTYPE_dsd
@ SPA_MEDIA_SUBTYPE_dsd
S/PDIF.
Definition: param/format.h:61
SPA_MEDIA_SUBTYPE_flac
@ SPA_MEDIA_SUBTYPE_flac
since 0.3.65
Definition: param/format.h:77
iec958-utils.h
mp3-utils.h
format.h
spa/param/audio/format.h
parser.h
spa/pod/parser.h
ra-utils.h
spa_audio_info
Definition: param/audio/format.h:57
spa_audio_info::dsd
struct spa_audio_info_dsd dsd
Definition: param/audio/format.h:64
spa_audio_info::vorbis
struct spa_audio_info_vorbis vorbis
Definition: param/audio/format.h:67
spa_audio_info::dsp
struct spa_audio_info_dsp dsp
Definition: param/audio/format.h:62
spa_audio_info::info
union spa_audio_info::@7 info
spa_audio_info::amr
struct spa_audio_info_amr amr
Definition: param/audio/format.h:70
spa_audio_info::media_subtype
uint32_t media_subtype
Definition: param/audio/format.h:59
spa_audio_info::mp3
struct spa_audio_info_mp3 mp3
Definition: param/audio/format.h:65
spa_audio_info::ra
struct spa_audio_info_ra ra
Definition: param/audio/format.h:69
spa_audio_info::raw
struct spa_audio_info_raw raw
Definition: param/audio/format.h:61
spa_audio_info::ape
struct spa_audio_info_ape ape
Definition: param/audio/format.h:73
spa_audio_info::aac
struct spa_audio_info_aac aac
Definition: param/audio/format.h:66
spa_audio_info::media_type
uint32_t media_type
Definition: param/audio/format.h:58
spa_audio_info::iec958
struct spa_audio_info_iec958 iec958
Definition: param/audio/format.h:63
spa_audio_info::wma
struct spa_audio_info_wma wma
Definition: param/audio/format.h:68
spa_audio_info::alac
struct spa_audio_info_alac alac
Definition: param/audio/format.h:71
spa_audio_info::flac
struct spa_audio_info_flac flac
Definition: param/audio/format.h:72
spa_pod_builder
Definition: builder.h:73
spa_pod
Definition: pod/pod.h:63
vorbis-utils.h
wma-utils.h