PipeWire: format-utils.h Source File

PipeWire 0.3.66

Loading...
Searching...
No Matches
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
32#include <spa/param/format-utils.h>
33#include <spa/param/video/format.h>
34#include <spa/param/video/raw-utils.h>
35#include <spa/param/video/dsp-utils.h>
36#include <spa/param/video/h264-utils.h>
37#include <spa/param/video/mjpg-utils.h>
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
47 if (info->media_type != SPA_MEDIA_TYPE_video)
48 return -EINVAL;
49
50 switch (info->media_subtype) {
51 case SPA_MEDIA_SUBTYPE_raw:
52 return spa_format_video_raw_parse(format, &info->info.raw);
53 case SPA_MEDIA_SUBTYPE_dsp:
54 return spa_format_video_dsp_parse(format, &info->info.dsp);
55 case SPA_MEDIA_SUBTYPE_h264:
56 return spa_format_video_h264_parse(format, &info->info.h264);
57 case SPA_MEDIA_SUBTYPE_mjpg:
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) {
67 case SPA_MEDIA_SUBTYPE_raw:
68 return spa_format_video_raw_build(builder, id, &info->info.raw);
69 case SPA_MEDIA_SUBTYPE_dsp:
70 return spa_format_video_dsp_build(builder, id, &info->info.dsp);
71 case SPA_MEDIA_SUBTYPE_h264:
72 return spa_format_video_h264_build(builder, id, &info->info.h264);
73 case SPA_MEDIA_SUBTYPE_mjpg:
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 */
format-utils.h
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_video_h264_build
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
spa_format_video_dsp_build
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
spa_format_video_dsp_parse
static int spa_format_video_dsp_parse(const struct spa_pod *format, struct spa_video_info_dsp *info)
Definition: video/dsp-utils.h:47
spa_format_video_raw_build
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
spa_format_video_raw_parse
static int spa_format_video_raw_parse(const struct spa_pod *format, struct spa_video_info_raw *info)
Definition: video/raw-utils.h:47
spa_format_video_mjpg_build
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
spa_format_video_h264_parse
static int spa_format_video_h264_parse(const struct spa_pod *format, struct spa_video_info_h264 *info)
Definition: h264-utils.h:47
spa_format_video_mjpg_parse
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
@ SPA_MEDIA_TYPE_video
Definition: param/format.h:48
SPA_MEDIA_SUBTYPE_h264
@ SPA_MEDIA_SUBTYPE_h264
Definition: param/format.h:81
SPA_MEDIA_SUBTYPE_mjpg
@ SPA_MEDIA_SUBTYPE_mjpg
Definition: param/format.h:82
SPA_MEDIA_SUBTYPE_dsp
@ SPA_MEDIA_SUBTYPE_dsp
Definition: param/format.h:59
SPA_MEDIA_SUBTYPE_raw
@ SPA_MEDIA_SUBTYPE_raw
Definition: param/format.h:58
h264-utils.h
mjpg-utils.h
format.h
spa/param/video/format.h
spa_pod_builder
Definition: builder.h:73
spa_pod
Definition: pod/pod.h:63
spa_video_info
Definition: param/video/format.h:47
spa_video_info::mjpg
struct spa_video_info_mjpg mjpg
Definition: param/video/format.h:54
spa_video_info::media_subtype
uint32_t media_subtype
Definition: param/video/format.h:49
spa_video_info::raw
struct spa_video_info_raw raw
Definition: param/video/format.h:51
spa_video_info::media_type
uint32_t media_type
Definition: param/video/format.h:48
spa_video_info::h264
struct spa_video_info_h264 h264
Definition: param/video/format.h:53
spa_video_info::info
union spa_video_info::@8 info
spa_video_info::dsp
struct spa_video_info_dsp dsp
Definition: param/video/format.h:52
dsp-utils.h
raw-utils.h