PipeWire  0.3.64
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
29 extern "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 
41 
42 
48 static inline int
49 spa_format_audio_parse(const struct spa_pod *format, struct spa_audio_info *info)
50 {
51  int res;
52 
53  if ((res = spa_format_parse(format, &info->media_type, &info->media_subtype)) < 0)
54  return res;
55 
56  if (info->media_type != SPA_MEDIA_TYPE_audio)
57  return -EINVAL;
58 
59  switch (info->media_type) {
61  return spa_format_audio_raw_parse(format, &info->info.raw);
63  return spa_format_audio_dsp_parse(format, &info->info.dsp);
65  return spa_format_audio_iec958_parse(format, &info->info.iec958);
67  return spa_format_audio_dsd_parse(format, &info->info.dsd);
68  }
69  return -ENOTSUP;
70 }
71 
72 static inline struct spa_pod *
73 spa_format_audio_build(struct spa_pod_builder *builder, uint32_t id, struct spa_audio_info *info)
74 {
75  switch (info->media_type) {
77  return spa_format_audio_raw_build(builder, id, &info->info.raw);
79  return spa_format_audio_dsp_build(builder, id, &info->info.dsp);
81  return spa_format_audio_iec958_build(builder, id, &info->info.iec958);
83  return spa_format_audio_dsd_build(builder, id, &info->info.dsd);
84  }
85  errno = ENOTSUP;
86  return NULL;
87 }
92 #ifdef __cplusplus
93 } /* extern "C" */
94 #endif
95 
96 #endif /* SPA_PARAM_AUDIO_FORMAT_UTILS_H */
spa/pod/builder.h
static int spa_format_audio_iec958_parse(const struct spa_pod *format, struct spa_audio_info_iec958 *info)
Definition: iec958-utils.h:48
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
static int spa_format_parse(const struct spa_pod *format, uint32_t *media_type, uint32_t *media_subtype)
Definition: format-utils.h:47
static int spa_format_audio_raw_parse(const struct spa_pod *format, struct spa_audio_info_raw *info)
Definition: audio/raw-utils.h:48
static int spa_format_audio_dsd_parse(const struct spa_pod *format, struct spa_audio_info_dsd *info)
Definition: dsd-utils.h:48
static int spa_format_audio_dsp_parse(const struct spa_pod *format, struct spa_audio_info_dsp *info)
Definition: audio/dsp-utils.h:48
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
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:78
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
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
static int spa_format_audio_parse(const struct spa_pod *format, struct spa_audio_info *info)
Definition: audio/format-utils.h:54
@ SPA_MEDIA_TYPE_audio
Definition: param/format.h:47
@ SPA_MEDIA_SUBTYPE_iec958
Definition: param/format.h:60
@ SPA_MEDIA_SUBTYPE_dsp
Definition: param/format.h:59
@ SPA_MEDIA_SUBTYPE_raw
Definition: param/format.h:58
@ SPA_MEDIA_SUBTYPE_dsd
S/PDIF.
Definition: param/format.h:61
spa/param/audio/format.h
spa/pod/parser.h
Definition: param/audio/format.h:48
struct spa_audio_info_dsd dsd
Definition: param/audio/format.h:55
struct spa_audio_info_dsp dsp
Definition: param/audio/format.h:53
union spa_audio_info::@7 info
uint32_t media_subtype
Definition: param/audio/format.h:50
struct spa_audio_info_raw raw
Definition: param/audio/format.h:52
uint32_t media_type
Definition: param/audio/format.h:49
struct spa_audio_info_iec958 iec958
Definition: param/audio/format.h:54
Definition: builder.h:73
Definition: pod/pod.h:63