PipeWire 1.5.84
Loading...
Searching...
No Matches
raw-utils.h
Go to the documentation of this file.
1/* Simple Plugin API */
2/* SPDX-FileCopyrightText: Copyright © 2018 Wim Taymans */
3/* SPDX-License-Identifier: MIT */
4
5#ifndef SPA_AUDIO_RAW_UTILS_H
6#define SPA_AUDIO_RAW_UTILS_H
7
8#include <spa/pod/parser.h>
9#include <spa/pod/iter.h>
10#include <spa/pod/builder.h>
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
22
23#ifndef SPA_API_AUDIO_RAW_UTILS
24 #ifdef SPA_API_IMPL
25 #define SPA_API_AUDIO_RAW_UTILS SPA_API_IMPL
26 #else
27 #define SPA_API_AUDIO_RAW_UTILS static inline
28 #endif
29#endif
30
32spa_format_audio_raw_ext_parse(const struct spa_pod *format, struct spa_audio_info_raw *info, size_t size)
33{
34 struct spa_pod *position = NULL;
35 int res;
36 uint32_t max_position = SPA_AUDIO_INFO_RAW_MAX_POSITION(size);
37
39 return -EINVAL;
40
41 info->flags = 0;
48 if (info->channels > max_position)
49 return -ECHRNG;
50 if (position == NULL ||
51 spa_pod_copy_array(position, SPA_TYPE_Id, info->position, max_position) != info->channels) {
53 spa_memzero(info->position, max_position * sizeof(info->position[0]));
54 }
55
56 return res;
57}
58
60spa_format_audio_raw_parse(const struct spa_pod *format, struct spa_audio_info_raw *info)
61{
62 return spa_format_audio_raw_ext_parse(format, info, sizeof(*info));
63}
64
66spa_format_audio_raw_ext_build(struct spa_pod_builder *builder, uint32_t id,
67 const struct spa_audio_info_raw *info, size_t size)
68{
69 struct spa_pod_frame f;
70 uint32_t max_position = SPA_AUDIO_INFO_RAW_MAX_POSITION(size);
71
73 errno = EINVAL;
74 return NULL;
75 }
76
78 spa_pod_builder_add(builder,
81 0);
82 if (info->format != SPA_AUDIO_FORMAT_UNKNOWN)
83 spa_pod_builder_add(builder,
84 SPA_FORMAT_AUDIO_format, SPA_POD_Id(info->format), 0);
85 if (info->rate != 0)
86 spa_pod_builder_add(builder,
87 SPA_FORMAT_AUDIO_rate, SPA_POD_Int(info->rate), 0);
88 if (info->channels != 0) {
89 spa_pod_builder_add(builder,
90 SPA_FORMAT_AUDIO_channels, SPA_POD_Int(info->channels), 0);
91 /* we drop the positions here when we can't read all of them. This is
92 * really a malformed spa_audio_info structure. */
94 info->channels <= max_position) {
96 SPA_POD_Array(sizeof(uint32_t), SPA_TYPE_Id,
97 info->channels, info->position), 0);
98 }
99 }
100 return (struct spa_pod*)spa_pod_builder_pop(builder, &f);
101}
102
104spa_format_audio_raw_build(struct spa_pod_builder *builder, uint32_t id,
105 const struct spa_audio_info_raw *info)
106{
107 return spa_format_audio_raw_ext_build(builder, id, info, sizeof(*info));
108}
109
111 * \}
112 */
113
114#ifdef __cplusplus
115} /* extern "C" */
116#endif
117
118#endif /* SPA_AUDIO_RAW_UTILS_H */
spa/pod/builder.h
uint32_t int int res
Definition core.h:433
#define SPA_AUDIO_FLAG_UNPOSITIONED
Definition raw.h:287
#define SPA_AUDIO_INFO_RAW_MAX_POSITION(size)
Definition raw.h:306
SPA_API_AUDIO_RAW_UTILS int spa_format_audio_raw_parse(const struct spa_pod *format, struct spa_audio_info_raw *info)
Definition raw-utils.h:67
SPA_API_AUDIO_RAW_UTILS struct spa_pod * spa_format_audio_raw_ext_build(struct spa_pod_builder *builder, uint32_t id, const struct spa_audio_info_raw *info, size_t size)
Definition raw-utils.h:73
#define SPA_AUDIO_INFO_RAW_VALID_SIZE(size)
Definition raw.h:309
#define SPA_API_AUDIO_RAW_UTILS
Definition raw-utils.h:34
SPA_API_AUDIO_RAW_UTILS struct spa_pod * spa_format_audio_raw_build(struct spa_pod_builder *builder, uint32_t id, const struct spa_audio_info_raw *info)
Definition raw-utils.h:111
SPA_API_AUDIO_RAW_UTILS int spa_format_audio_raw_ext_parse(const struct spa_pod *format, struct spa_audio_info_raw *info, size_t size)
Definition raw-utils.h:39
@ SPA_MEDIA_TYPE_audio
Definition format.h:27
@ SPA_FORMAT_mediaType
media type (Id enum spa_media_type)
Definition format.h:99
@ SPA_FORMAT_AUDIO_position
channel positions (Id enum spa_audio_position)
Definition format.h:108
@ SPA_FORMAT_AUDIO_rate
sample rate (Int)
Definition format.h:106
@ SPA_FORMAT_mediaSubtype
media subtype (Id enum spa_media_subtype)
Definition format.h:100
@ SPA_FORMAT_AUDIO_format
audio format, (Id enum spa_audio_format)
Definition format.h:104
@ SPA_FORMAT_AUDIO_channels
number of audio channels (Int)
Definition format.h:107
@ SPA_MEDIA_SUBTYPE_raw
Definition format.h:38
@ SPA_AUDIO_FORMAT_UNKNOWN
Definition raw.h:34
SPA_API_POD_BUILDER void * spa_pod_builder_pop(struct spa_pod_builder *builder, struct spa_pod_frame *frame)
Definition builder.h:213
#define SPA_POD_Array(csize, ctype, n_vals, vals)
Definition vararg.h:128
SPA_API_POD_BUILDER int spa_pod_builder_add(struct spa_pod_builder *builder,...)
Definition builder.h:713
#define spa_pod_copy_array(pod, type, values, max_values)
Definition iter.h:226
#define SPA_POD_Id(val)
Definition vararg.h:53
SPA_API_POD_BUILDER int spa_pod_builder_push_object(struct spa_pod_builder *builder, struct spa_pod_frame *frame, uint32_t type, uint32_t id)
Definition builder.h:475
#define SPA_POD_OPT_Int(val)
Definition parser.h:866
#define SPA_POD_OPT_Id(val)
Definition parser.h:864
#define SPA_POD_OPT_Pod(val)
Definition parser.h:890
#define spa_pod_parse_object(pod, type, id,...)
Definition parser.h:935
#define SPA_POD_Int(val)
Definition vararg.h:58
@ SPA_TYPE_Id
Definition type.h:44
@ SPA_TYPE_OBJECT_Format
Definition type.h:87
#define SPA_FLAG_SET(field, flag)
Definition defs.h:93
#define SPA_FLAG_IS_SET(field, flag)
Definition defs.h:90
#define spa_memzero(x, l)
Definition defs.h:511
spa/pod/iter.h
spa/param/audio/format.h
spa/pod/parser.h
Audio information description.
Definition raw.h:291
Definition builder.h:63
Definition body.h:38
Definition pod.h:57
uint32_t size
Definition pod.h:58