PipeWire: spa/param/video/raw-utils.h Source File

PipeWire 1.6.8

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_VIDEO_RAW_UTILS_H
6#define SPA_VIDEO_RAW_UTILS_H
7
8#include <spa/pod/iter.h>
9#include <spa/pod/parser.h>
10#include <spa/pod/builder.h>
11#include <spa/param/video/raw.h>
12
13#ifdef __cplusplus
14extern "C" {
15#endif
16
21
22#ifndef SPA_API_VIDEO_RAW_UTILS
23 #ifdef SPA_API_IMPL
24 #define SPA_API_VIDEO_RAW_UTILS SPA_API_IMPL
25 #else
26 #define SPA_API_VIDEO_RAW_UTILS static inline
27 #endif
28#endif
29
30 SPA_API_VIDEO_RAW_UTILS int
31 spa_format_video_raw_parse(const struct spa_pod *format,
32 struct spa_video_info_raw *info)
33{
34 info->flags = SPA_VIDEO_FLAG_NONE;
35 const struct spa_pod_prop *mod_prop;
36 if ((mod_prop = spa_pod_find_prop (format, NULL, SPA_FORMAT_VIDEO_modifier)) != NULL) {
37 info->flags |= SPA_VIDEO_FLAG_MODIFIER;
38 if ((mod_prop->flags & SPA_POD_PROP_FLAG_DONT_FIXATE) == SPA_POD_PROP_FLAG_DONT_FIXATE)
39 info->flags |= SPA_VIDEO_FLAG_MODIFIER_FIXATION_REQUIRED;
40 }
41
42 return spa_pod_parse_object(format,
43 SPA_TYPE_OBJECT_Format, NULL,
44 SPA_FORMAT_VIDEO_format, SPA_POD_OPT_Id(&info->format),
45 SPA_FORMAT_VIDEO_modifier, SPA_POD_OPT_Long(&info->modifier),
46 SPA_FORMAT_VIDEO_size, SPA_POD_OPT_Rectangle(&info->size),
47 SPA_FORMAT_VIDEO_framerate, SPA_POD_OPT_Fraction(&info->framerate),
48 SPA_FORMAT_VIDEO_maxFramerate, SPA_POD_OPT_Fraction(&info->max_framerate),
49 SPA_FORMAT_VIDEO_views, SPA_POD_OPT_Int(&info->views),
50 SPA_FORMAT_VIDEO_interlaceMode, SPA_POD_OPT_Id(&info->interlace_mode),
51 SPA_FORMAT_VIDEO_pixelAspectRatio, SPA_POD_OPT_Fraction(&info->pixel_aspect_ratio),
52 SPA_FORMAT_VIDEO_multiviewMode, SPA_POD_OPT_Id(&info->multiview_mode),
53 SPA_FORMAT_VIDEO_multiviewFlags, SPA_POD_OPT_Id(&info->multiview_flags),
54 SPA_FORMAT_VIDEO_chromaSite, SPA_POD_OPT_Id(&info->chroma_site),
55 SPA_FORMAT_VIDEO_colorRange, SPA_POD_OPT_Id(&info->color_range),
56 SPA_FORMAT_VIDEO_colorMatrix, SPA_POD_OPT_Id(&info->color_matrix),
57 SPA_FORMAT_VIDEO_transferFunction, SPA_POD_OPT_Id(&info->transfer_function),
58 SPA_FORMAT_VIDEO_colorPrimaries, SPA_POD_OPT_Id(&info->color_primaries));
59}
60
61 SPA_API_VIDEO_RAW_UTILS struct spa_pod *
62 spa_format_video_raw_build(struct spa_pod_builder *builder, uint32_t id,
63 const struct spa_video_info_raw *info)
64{
65 struct spa_pod_frame f;
66 spa_pod_builder_push_object(builder, &f, SPA_TYPE_OBJECT_Format, id);
67 spa_pod_builder_add(builder,
68 SPA_FORMAT_mediaType, SPA_POD_Id(SPA_MEDIA_TYPE_video),
69 SPA_FORMAT_mediaSubtype, SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw),
70 0);
71 if (info->format != SPA_VIDEO_FORMAT_UNKNOWN)
72 spa_pod_builder_add(builder,
73 SPA_FORMAT_VIDEO_format, SPA_POD_Id(info->format), 0);
74 if (info->size.width != 0 && info->size.height != 0)
75 spa_pod_builder_add(builder,
76 SPA_FORMAT_VIDEO_size, SPA_POD_Rectangle(&info->size), 0);
77 if (info->framerate.denom != 0)
78 spa_pod_builder_add(builder,
79 SPA_FORMAT_VIDEO_framerate, SPA_POD_Fraction(&info->framerate), 0);
80 if (info->modifier != 0 || info->flags & SPA_VIDEO_FLAG_MODIFIER) {
81 spa_pod_builder_prop(builder,
82 SPA_FORMAT_VIDEO_modifier, SPA_POD_PROP_FLAG_MANDATORY);
83 spa_pod_builder_long(builder, info->modifier);
84 }
85 if (info->max_framerate.denom != 0)
86 spa_pod_builder_add(builder,
87 SPA_FORMAT_VIDEO_maxFramerate, SPA_POD_Fraction(&info->max_framerate), 0);
88 if (info->views != 0)
89 spa_pod_builder_add(builder,
90 SPA_FORMAT_VIDEO_views, SPA_POD_Int(info->views), 0);
91 if (info->interlace_mode != 0)
92 spa_pod_builder_add(builder,
93 SPA_FORMAT_VIDEO_interlaceMode, SPA_POD_Id(info->interlace_mode), 0);
94 if (info->pixel_aspect_ratio.denom != 0)
95 spa_pod_builder_add(builder,
96 SPA_FORMAT_VIDEO_pixelAspectRatio, SPA_POD_Fraction(&info->pixel_aspect_ratio), 0);
97 if (info->multiview_mode != 0)
98 spa_pod_builder_add(builder,
99 SPA_FORMAT_VIDEO_multiviewMode, SPA_POD_Id(info->multiview_mode), 0);
100 if (info->multiview_flags != 0)
101 spa_pod_builder_add(builder,
102 SPA_FORMAT_VIDEO_multiviewFlags,SPA_POD_Id(info->multiview_flags), 0);
103 if (info->chroma_site != 0)
104 spa_pod_builder_add(builder,
105 SPA_FORMAT_VIDEO_chromaSite, SPA_POD_Id(info->chroma_site), 0);
106 if (info->color_range != 0)
107 spa_pod_builder_add(builder,
108 SPA_FORMAT_VIDEO_colorRange, SPA_POD_Id(info->color_range), 0);
109 if (info->color_matrix != 0)
110 spa_pod_builder_add(builder,
111 SPA_FORMAT_VIDEO_colorMatrix, SPA_POD_Id(info->color_matrix), 0);
112 if (info->transfer_function != 0)
113 spa_pod_builder_add(builder,
114 SPA_FORMAT_VIDEO_transferFunction,SPA_POD_Id(info->transfer_function), 0);
115 if (info->color_primaries != 0)
116 spa_pod_builder_add(builder,
117 SPA_FORMAT_VIDEO_colorPrimaries,SPA_POD_Id(info->color_primaries), 0);
118 return (struct spa_pod*)spa_pod_builder_pop(builder, &f);
119}
120
121static inline bool
122 spa_format_video_is_rgb(enum spa_video_format format)
123{
124 switch (format) {
125 case SPA_VIDEO_FORMAT_RGBx:
126 case SPA_VIDEO_FORMAT_BGRx:
127 case SPA_VIDEO_FORMAT_xRGB:
128 case SPA_VIDEO_FORMAT_xBGR:
129 case SPA_VIDEO_FORMAT_RGBA:
130 case SPA_VIDEO_FORMAT_BGRA:
131 case SPA_VIDEO_FORMAT_ARGB:
132 case SPA_VIDEO_FORMAT_ABGR:
133 case SPA_VIDEO_FORMAT_RGB:
134 case SPA_VIDEO_FORMAT_BGR:
135 case SPA_VIDEO_FORMAT_GRAY8:
136 case SPA_VIDEO_FORMAT_GRAY16_BE:
137 case SPA_VIDEO_FORMAT_GRAY16_LE:
138 case SPA_VIDEO_FORMAT_RGB16:
139 case SPA_VIDEO_FORMAT_BGR16:
140 case SPA_VIDEO_FORMAT_RGB15:
141 case SPA_VIDEO_FORMAT_BGR15:
142 case SPA_VIDEO_FORMAT_RGB8P:
143 case SPA_VIDEO_FORMAT_ARGB64:
144 case SPA_VIDEO_FORMAT_r210:
145 case SPA_VIDEO_FORMAT_GBR:
146 case SPA_VIDEO_FORMAT_GBR_10BE:
147 case SPA_VIDEO_FORMAT_GBR_10LE:
148 case SPA_VIDEO_FORMAT_GBRA:
149 case SPA_VIDEO_FORMAT_GBRA_10BE:
150 case SPA_VIDEO_FORMAT_GBRA_10LE:
151 case SPA_VIDEO_FORMAT_GBR_12BE:
152 case SPA_VIDEO_FORMAT_GBR_12LE:
153 case SPA_VIDEO_FORMAT_GBRA_12BE:
154 case SPA_VIDEO_FORMAT_GBRA_12LE:
155 case SPA_VIDEO_FORMAT_RGBA_F16:
156 case SPA_VIDEO_FORMAT_RGBA_F32:
157 case SPA_VIDEO_FORMAT_xRGB_210LE:
158 case SPA_VIDEO_FORMAT_xBGR_210LE:
159 case SPA_VIDEO_FORMAT_RGBx_102LE:
160 case SPA_VIDEO_FORMAT_BGRx_102LE:
161 case SPA_VIDEO_FORMAT_ARGB_210LE:
162 case SPA_VIDEO_FORMAT_ABGR_210LE:
163 case SPA_VIDEO_FORMAT_RGBA_102LE:
164 case SPA_VIDEO_FORMAT_BGRA_102LE:
165 return true;
166 default:
167 return false;
168 }
169}
170
174
175#ifdef __cplusplus
176} /* extern "C" */
177#endif
178
179#endif /* SPA_VIDEO_RAW_UTILS_H */
builder.h
spa/pod/builder.h
spa_format_video_raw_parse
SPA_API_VIDEO_RAW_UTILS int spa_format_video_raw_parse(const struct spa_pod *format, struct spa_video_info_raw *info)
Definition raw-utils.h:38
spa_video_format
spa_video_format
Video formats.
Definition raw.h:43
spa_format_video_raw_build
SPA_API_VIDEO_RAW_UTILS struct spa_pod * spa_format_video_raw_build(struct spa_pod_builder *builder, uint32_t id, const struct spa_video_info_raw *info)
Definition raw-utils.h:69
SPA_API_VIDEO_RAW_UTILS
#define SPA_API_VIDEO_RAW_UTILS
Definition raw-utils.h:33
spa_format_video_is_rgb
static bool spa_format_video_is_rgb(enum spa_video_format format)
Definition raw-utils.h:129
SPA_MEDIA_TYPE_video
@ SPA_MEDIA_TYPE_video
Definition format.h:28
SPA_VIDEO_FLAG_MODIFIER_FIXATION_REQUIRED
@ SPA_VIDEO_FLAG_MODIFIER_FIXATION_REQUIRED
format modifier was not fixated yet
Definition raw.h:149
SPA_VIDEO_FLAG_MODIFIER
@ SPA_VIDEO_FLAG_MODIFIER
use the format modifier
Definition raw.h:148
SPA_VIDEO_FLAG_NONE
@ SPA_VIDEO_FLAG_NONE
no flags
Definition raw.h:144
SPA_FORMAT_VIDEO_framerate
@ SPA_FORMAT_VIDEO_framerate
frame rate (Fraction)
Definition format.h:134
SPA_FORMAT_mediaType
@ SPA_FORMAT_mediaType
media type (Id enum spa_media_type)
Definition format.h:99
SPA_FORMAT_VIDEO_size
@ SPA_FORMAT_VIDEO_size
size (Rectangle)
Definition format.h:133
SPA_FORMAT_VIDEO_modifier
@ SPA_FORMAT_VIDEO_modifier
format modifier (Long) use only with DMA-BUF and omit for other buffer types
Definition format.h:131
SPA_FORMAT_VIDEO_multiviewMode
@ SPA_FORMAT_VIDEO_multiviewMode
(Id enum spa_video_multiview_mode)
Definition format.h:139
SPA_FORMAT_VIDEO_interlaceMode
@ SPA_FORMAT_VIDEO_interlaceMode
(Id enum spa_video_interlace_mode)
Definition format.h:137
SPA_FORMAT_VIDEO_maxFramerate
@ SPA_FORMAT_VIDEO_maxFramerate
maximum frame rate (Fraction)
Definition format.h:135
SPA_FORMAT_VIDEO_pixelAspectRatio
@ SPA_FORMAT_VIDEO_pixelAspectRatio
(Rectangle)
Definition format.h:138
SPA_FORMAT_VIDEO_colorMatrix
@ SPA_FORMAT_VIDEO_colorMatrix
/Id enum spa_video_color_matrix)
Definition format.h:143
SPA_FORMAT_VIDEO_format
@ SPA_FORMAT_VIDEO_format
video format (Id enum spa_video_format)
Definition format.h:130
SPA_FORMAT_mediaSubtype
@ SPA_FORMAT_mediaSubtype
media subtype (Id enum spa_media_subtype)
Definition format.h:100
SPA_FORMAT_VIDEO_chromaSite
@ SPA_FORMAT_VIDEO_chromaSite
/Id enum spa_video_chroma_site)
Definition format.h:141
SPA_FORMAT_VIDEO_views
@ SPA_FORMAT_VIDEO_views
number of views (Int)
Definition format.h:136
SPA_FORMAT_VIDEO_colorPrimaries
@ SPA_FORMAT_VIDEO_colorPrimaries
/Id enum spa_video_color_primaries)
Definition format.h:145
SPA_FORMAT_VIDEO_transferFunction
@ SPA_FORMAT_VIDEO_transferFunction
/Id enum spa_video_transfer_function)
Definition format.h:144
SPA_FORMAT_VIDEO_colorRange
@ SPA_FORMAT_VIDEO_colorRange
/Id enum spa_video_color_range)
Definition format.h:142
SPA_FORMAT_VIDEO_multiviewFlags
@ SPA_FORMAT_VIDEO_multiviewFlags
(Id enum spa_video_multiview_flags)
Definition format.h:140
SPA_MEDIA_SUBTYPE_raw
@ SPA_MEDIA_SUBTYPE_raw
Definition format.h:38
SPA_VIDEO_FORMAT_RGBA_102LE
@ SPA_VIDEO_FORMAT_RGBA_102LE
32-bit R:G:B:A 10:10:10:2 little endian
Definition raw.h:133
SPA_VIDEO_FORMAT_GRAY8
@ SPA_VIDEO_FORMAT_GRAY8
Definition raw.h:70
SPA_VIDEO_FORMAT_GBR_10LE
@ SPA_VIDEO_FORMAT_GBR_10LE
Definition raw.h:95
SPA_VIDEO_FORMAT_GBRA_12LE
@ SPA_VIDEO_FORMAT_GBRA_12LE
Definition raw.h:116
SPA_VIDEO_FORMAT_ABGR_210LE
@ SPA_VIDEO_FORMAT_ABGR_210LE
32-bit A:B:G:R 2:10:10:10 little endian
Definition raw.h:132
SPA_VIDEO_FORMAT_xRGB
@ SPA_VIDEO_FORMAT_xRGB
Definition raw.h:54
SPA_VIDEO_FORMAT_GRAY16_LE
@ SPA_VIDEO_FORMAT_GRAY16_LE
Definition raw.h:72
SPA_VIDEO_FORMAT_GBR_10BE
@ SPA_VIDEO_FORMAT_GBR_10BE
Definition raw.h:94
SPA_VIDEO_FORMAT_RGB16
@ SPA_VIDEO_FORMAT_RGB16
Definition raw.h:74
SPA_VIDEO_FORMAT_UNKNOWN
@ SPA_VIDEO_FORMAT_UNKNOWN
Definition raw.h:44
SPA_VIDEO_FORMAT_ARGB
@ SPA_VIDEO_FORMAT_ARGB
Definition raw.h:58
SPA_VIDEO_FORMAT_RGB15
@ SPA_VIDEO_FORMAT_RGB15
Definition raw.h:76
SPA_VIDEO_FORMAT_RGBx_102LE
@ SPA_VIDEO_FORMAT_RGBx_102LE
32-bit R:G:B:x 10:10:10:2 little endian
Definition raw.h:129
SPA_VIDEO_FORMAT_RGBA
@ SPA_VIDEO_FORMAT_RGBA
Definition raw.h:56
SPA_VIDEO_FORMAT_ABGR
@ SPA_VIDEO_FORMAT_ABGR
Definition raw.h:59
SPA_VIDEO_FORMAT_BGR15
@ SPA_VIDEO_FORMAT_BGR15
Definition raw.h:77
SPA_VIDEO_FORMAT_RGBA_F16
@ SPA_VIDEO_FORMAT_RGBA_F16
Definition raw.h:124
SPA_VIDEO_FORMAT_xBGR
@ SPA_VIDEO_FORMAT_xBGR
Definition raw.h:55
SPA_VIDEO_FORMAT_ARGB64
@ SPA_VIDEO_FORMAT_ARGB64
Definition raw.h:84
SPA_VIDEO_FORMAT_BGR
@ SPA_VIDEO_FORMAT_BGR
Definition raw.h:61
SPA_VIDEO_FORMAT_ARGB_210LE
@ SPA_VIDEO_FORMAT_ARGB_210LE
32-bit A:R:G:B 2:10:10:10 little endian
Definition raw.h:131
SPA_VIDEO_FORMAT_RGBx
@ SPA_VIDEO_FORMAT_RGBx
Definition raw.h:52
SPA_VIDEO_FORMAT_BGRx
@ SPA_VIDEO_FORMAT_BGRx
Definition raw.h:53
SPA_VIDEO_FORMAT_GBR_12BE
@ SPA_VIDEO_FORMAT_GBR_12BE
Definition raw.h:113
SPA_VIDEO_FORMAT_GBRA_10LE
@ SPA_VIDEO_FORMAT_GBRA_10LE
Definition raw.h:112
SPA_VIDEO_FORMAT_GRAY16_BE
@ SPA_VIDEO_FORMAT_GRAY16_BE
Definition raw.h:71
SPA_VIDEO_FORMAT_BGR16
@ SPA_VIDEO_FORMAT_BGR16
Definition raw.h:75
SPA_VIDEO_FORMAT_BGRA_102LE
@ SPA_VIDEO_FORMAT_BGRA_102LE
32-bit B:G:R:A 10:10:10:2 little endian
Definition raw.h:134
SPA_VIDEO_FORMAT_GBR
@ SPA_VIDEO_FORMAT_GBR
Definition raw.h:93
SPA_VIDEO_FORMAT_GBRA_12BE
@ SPA_VIDEO_FORMAT_GBRA_12BE
Definition raw.h:115
SPA_VIDEO_FORMAT_BGRx_102LE
@ SPA_VIDEO_FORMAT_BGRx_102LE
32-bit B:G:R:x 10:10:10:2 little endian
Definition raw.h:130
SPA_VIDEO_FORMAT_xRGB_210LE
@ SPA_VIDEO_FORMAT_xRGB_210LE
32-bit x:R:G:B 2:10:10:10 little endian
Definition raw.h:127
SPA_VIDEO_FORMAT_GBRA_10BE
@ SPA_VIDEO_FORMAT_GBRA_10BE
Definition raw.h:111
SPA_VIDEO_FORMAT_RGBA_F32
@ SPA_VIDEO_FORMAT_RGBA_F32
Definition raw.h:125
SPA_VIDEO_FORMAT_BGRA
@ SPA_VIDEO_FORMAT_BGRA
Definition raw.h:57
SPA_VIDEO_FORMAT_RGB8P
@ SPA_VIDEO_FORMAT_RGB8P
Definition raw.h:80
SPA_VIDEO_FORMAT_GBRA
@ SPA_VIDEO_FORMAT_GBRA
Definition raw.h:110
SPA_VIDEO_FORMAT_xBGR_210LE
@ SPA_VIDEO_FORMAT_xBGR_210LE
32-bit x:B:G:R 2:10:10:10 little endian
Definition raw.h:128
SPA_VIDEO_FORMAT_GBR_12LE
@ SPA_VIDEO_FORMAT_GBR_12LE
Definition raw.h:114
SPA_VIDEO_FORMAT_r210
@ SPA_VIDEO_FORMAT_r210
Definition raw.h:86
SPA_VIDEO_FORMAT_RGB
@ SPA_VIDEO_FORMAT_RGB
Definition raw.h:60
spa_pod_builder_pop
SPA_API_POD_BUILDER void * spa_pod_builder_pop(struct spa_pod_builder *builder, struct spa_pod_frame *frame)
Definition builder.h:213
spa_pod_builder_long
SPA_API_POD_BUILDER int spa_pod_builder_long(struct spa_pod_builder *builder, int64_t val)
Definition builder.h:305
SPA_POD_Fraction
#define SPA_POD_Fraction(val)
Definition vararg.h:119
SPA_POD_OPT_Rectangle
#define SPA_POD_OPT_Rectangle(val)
Definition parser.h:880
spa_pod_find_prop
SPA_API_POD_ITER const struct spa_pod_prop * spa_pod_find_prop(const struct spa_pod *pod, const struct spa_pod_prop *start, uint32_t key)
Definition iter.h:274
SPA_POD_PROP_FLAG_MANDATORY
#define SPA_POD_PROP_FLAG_MANDATORY
is mandatory, when filtering, both sides need this property or filtering fails.
Definition pod.h:241
SPA_POD_OPT_Fraction
#define SPA_POD_OPT_Fraction(val)
Definition parser.h:882
spa_pod_builder_add
SPA_API_POD_BUILDER int spa_pod_builder_add(struct spa_pod_builder *builder,...)
Definition builder.h:713
SPA_POD_Id
#define SPA_POD_Id(val)
Definition vararg.h:53
spa_pod_builder_push_object
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
SPA_POD_PROP_FLAG_DONT_FIXATE
#define SPA_POD_PROP_FLAG_DONT_FIXATE
choices need no fixation
Definition pod.h:244
SPA_POD_OPT_Int
#define SPA_POD_OPT_Int(val)
Definition parser.h:866
SPA_POD_OPT_Id
#define SPA_POD_OPT_Id(val)
Definition parser.h:864
SPA_POD_Rectangle
#define SPA_POD_Rectangle(val)
Definition vararg.h:110
spa_pod_parse_object
#define spa_pod_parse_object(pod, type, id,...)
Definition parser.h:935
SPA_POD_Int
#define SPA_POD_Int(val)
Definition vararg.h:58
SPA_POD_OPT_Long
#define SPA_POD_OPT_Long(val)
Definition parser.h:868
spa_pod_builder_prop
SPA_API_POD_BUILDER int spa_pod_builder_prop(struct spa_pod_builder *builder, uint32_t key, uint32_t flags)
Definition builder.h:490
SPA_TYPE_OBJECT_Format
@ SPA_TYPE_OBJECT_Format
Definition type.h:87
iter.h
spa/pod/iter.h
parser.h
spa/pod/parser.h
spa_pod_builder
Definition builder.h:63
spa_pod_frame
Definition body.h:38
spa_pod_prop
Definition pod.h:227
spa_pod_prop::flags
uint32_t flags
flags for property
Definition pod.h:248
spa_pod
Definition pod.h:57
spa_video_info_raw
Definition raw.h:176
raw.h
spa/param/video/raw.h