PipeWire 0.3.65
video/format-utils.h
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_VIDEO_FORMAT_UTILS_H
26#define SPA_PARAM_VIDEO_FORMAT_UTILS_H
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
38
39static inline int
40spa_format_video_parse(const struct spa_pod *format, struct spa_video_info *info)
41{
42 int res;
43
44 if ((res = spa_format_parse(format, &info->media_type, &info->media_subtype)) < 0)
45 return res;
46
48 return -EINVAL;
49
50 switch (info->media_subtype) {
52 return spa_format_video_raw_parse(format, &info->info.raw);
54 return spa_format_video_dsp_parse(format, &info->info.dsp);
56 return spa_format_video_h264_parse(format, &info->info.h264);
58 return spa_format_video_mjpg_parse(format, &info->info.mjpg);
59 }
60 return -ENOTSUP;
61}
62
63static inline struct spa_pod *
64spa_format_video_build(struct spa_pod_builder *builder, uint32_t id, struct spa_video_info *info)
65{
66 switch (info->media_subtype) {
68 return spa_format_video_raw_build(builder, id, &info->info.raw);
70 return spa_format_video_dsp_build(builder, id, &info->info.dsp);
72 return spa_format_video_h264_build(builder, id, &info->info.h264);
74 return spa_format_video_mjpg_build(builder, id, &info->info.mjpg);
75 }
76 errno = ENOTSUP;
77 return NULL;
78}
79
80#ifdef __cplusplus
81} /* extern "C" */
82#endif
83
84#endif /* SPA_PARAM_VIDEO_FORMAT_UTILS_H */
static int spa_format_parse(const struct spa_pod *format, uint32_t *media_type, uint32_t *media_subtype)
Definition: format-utils.h:47
static struct spa_pod * spa_format_video_h264_build(struct spa_pod_builder *builder, uint32_t id, struct spa_video_info_h264 *info)
Definition: h264-utils.h:60
static struct spa_pod * spa_format_video_dsp_build(struct spa_pod_builder *builder, uint32_t id, struct spa_video_info_dsp *info)
Definition: video/dsp-utils.h:62
static int spa_format_video_dsp_parse(const struct spa_pod *format, struct spa_video_info_dsp *info)
Definition: video/dsp-utils.h:47
static struct spa_pod * spa_format_video_raw_build(struct spa_pod_builder *builder, uint32_t id, struct spa_video_info_raw *info)
Definition: video/raw-utils.h:75
static int spa_format_video_raw_parse(const struct spa_pod *format, struct spa_video_info_raw *info)
Definition: video/raw-utils.h:47
static struct spa_pod * spa_format_video_mjpg_build(struct spa_pod_builder *builder, uint32_t id, struct spa_video_info_mjpg *info)
Definition: mjpg-utils.h:58
static int spa_format_video_h264_parse(const struct spa_pod *format, struct spa_video_info_h264 *info)
Definition: h264-utils.h:47
static int spa_format_video_mjpg_parse(const struct spa_pod *format, struct spa_video_info_mjpg *info)
Definition: mjpg-utils.h:47
@ SPA_MEDIA_TYPE_video
Definition: param/format.h:48
@ SPA_MEDIA_SUBTYPE_h264
Definition: param/format.h:81
@ SPA_MEDIA_SUBTYPE_mjpg
Definition: param/format.h:82
@ SPA_MEDIA_SUBTYPE_dsp
Definition: param/format.h:59
@ SPA_MEDIA_SUBTYPE_raw
Definition: param/format.h:58
spa/param/video/format.h
Definition: builder.h:73
Definition: pod/pod.h:63
Definition: param/video/format.h:47
struct spa_video_info_mjpg mjpg
Definition: param/video/format.h:54
uint32_t media_subtype
Definition: param/video/format.h:49
struct spa_video_info_raw raw
Definition: param/video/format.h:51
uint32_t media_type
Definition: param/video/format.h:48
struct spa_video_info_h264 h264
Definition: param/video/format.h:53
union spa_video_info::@8 info
struct spa_video_info_dsp dsp
Definition: param/video/format.h:52