Loading...
Searching...
No Matches
raw-utils.h
Go to the documentation of this file.
/* Simple Plugin API */
/* SPDX-FileCopyrightText: Copyright © 2018 Wim Taymans */
/* SPDX-License-Identifier: MIT */
#ifndef SPA_VIDEO_RAW_UTILS_H
#define SPA_VIDEO_RAW_UTILS_H
#include <spa/pod/iter.h>
#include <spa/pod/parser.h>
#include <spa/pod/builder.h>
#include <spa/param/video/raw.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef SPA_API_VIDEO_RAW_UTILS
#ifdef SPA_API_IMPL
#define SPA_API_VIDEO_RAW_UTILS SPA_API_IMPL
#else
#define SPA_API_VIDEO_RAW_UTILS static inline
#endif
#endif
SPA_API_VIDEO_RAW_UTILS int
spa_format_video_raw_parse(const struct spa_pod *format,
struct spa_video_info_raw *info)
{
info->flags = SPA_VIDEO_FLAG_NONE;
const struct spa_pod_prop *mod_prop;
if ((mod_prop = spa_pod_find_prop (format, NULL, SPA_FORMAT_VIDEO_modifier)) != NULL) {
info->flags |= SPA_VIDEO_FLAG_MODIFIER;
if ((mod_prop->flags & SPA_POD_PROP_FLAG_DONT_FIXATE) == SPA_POD_PROP_FLAG_DONT_FIXATE)
info->flags |= SPA_VIDEO_FLAG_MODIFIER_FIXATION_REQUIRED;
}
return spa_pod_parse_object(format,
SPA_TYPE_OBJECT_Format, NULL,
SPA_FORMAT_VIDEO_format, SPA_POD_OPT_Id(&info->format),
SPA_FORMAT_VIDEO_modifier, SPA_POD_OPT_Long(&info->modifier),
SPA_FORMAT_VIDEO_size, SPA_POD_OPT_Rectangle(&info->size),
SPA_FORMAT_VIDEO_framerate, SPA_POD_OPT_Fraction(&info->framerate),
SPA_FORMAT_VIDEO_maxFramerate, SPA_POD_OPT_Fraction(&info->max_framerate),
SPA_FORMAT_VIDEO_views, SPA_POD_OPT_Int(&info->views),
SPA_FORMAT_VIDEO_interlaceMode, SPA_POD_OPT_Id(&info->interlace_mode),
SPA_FORMAT_VIDEO_pixelAspectRatio, SPA_POD_OPT_Fraction(&info->pixel_aspect_ratio),
SPA_FORMAT_VIDEO_multiviewMode, SPA_POD_OPT_Id(&info->multiview_mode),
SPA_FORMAT_VIDEO_multiviewFlags, SPA_POD_OPT_Id(&info->multiview_flags),
SPA_FORMAT_VIDEO_chromaSite, SPA_POD_OPT_Id(&info->chroma_site),
SPA_FORMAT_VIDEO_colorRange, SPA_POD_OPT_Id(&info->color_range),
SPA_FORMAT_VIDEO_colorMatrix, SPA_POD_OPT_Id(&info->color_matrix),
SPA_FORMAT_VIDEO_transferFunction, SPA_POD_OPT_Id(&info->transfer_function),
SPA_FORMAT_VIDEO_colorPrimaries, SPA_POD_OPT_Id(&info->color_primaries));
}
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)
{
struct spa_pod_frame f;
spa_pod_builder_push_object(builder, &f, SPA_TYPE_OBJECT_Format, id);
spa_pod_builder_add(builder,
SPA_FORMAT_mediaType, SPA_POD_Id(SPA_MEDIA_TYPE_video),
SPA_FORMAT_mediaSubtype, SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw),
0);
if (info->format != SPA_VIDEO_FORMAT_UNKNOWN)
spa_pod_builder_add(builder,
SPA_FORMAT_VIDEO_format, SPA_POD_Id(info->format), 0);
if (info->size.width != 0 && info->size.height != 0)
spa_pod_builder_add(builder,
SPA_FORMAT_VIDEO_size, SPA_POD_Rectangle(&info->size), 0);
if (info->framerate.denom != 0)
spa_pod_builder_add(builder,
SPA_FORMAT_VIDEO_framerate, SPA_POD_Fraction(&info->framerate), 0);
if (info->modifier != 0 || info->flags & SPA_VIDEO_FLAG_MODIFIER) {
spa_pod_builder_prop(builder,
SPA_FORMAT_VIDEO_modifier, SPA_POD_PROP_FLAG_MANDATORY);
spa_pod_builder_long(builder, info->modifier);
}
if (info->max_framerate.denom != 0)
spa_pod_builder_add(builder,
SPA_FORMAT_VIDEO_maxFramerate, SPA_POD_Fraction(&info->max_framerate), 0);
if (info->views != 0)
spa_pod_builder_add(builder,
SPA_FORMAT_VIDEO_views, SPA_POD_Int(info->views), 0);
if (info->interlace_mode != 0)
spa_pod_builder_add(builder,
SPA_FORMAT_VIDEO_interlaceMode, SPA_POD_Id(info->interlace_mode), 0);
if (info->pixel_aspect_ratio.denom != 0)
spa_pod_builder_add(builder,
SPA_FORMAT_VIDEO_pixelAspectRatio, SPA_POD_Fraction(&info->pixel_aspect_ratio), 0);
if (info->multiview_mode != 0)
spa_pod_builder_add(builder,
SPA_FORMAT_VIDEO_multiviewMode, SPA_POD_Id(info->multiview_mode), 0);
if (info->multiview_flags != 0)
spa_pod_builder_add(builder,
SPA_FORMAT_VIDEO_multiviewFlags,SPA_POD_Id(info->multiview_flags), 0);
if (info->chroma_site != 0)
spa_pod_builder_add(builder,
SPA_FORMAT_VIDEO_chromaSite, SPA_POD_Id(info->chroma_site), 0);
if (info->color_range != 0)
spa_pod_builder_add(builder,
SPA_FORMAT_VIDEO_colorRange, SPA_POD_Id(info->color_range), 0);
if (info->color_matrix != 0)
spa_pod_builder_add(builder,
SPA_FORMAT_VIDEO_colorMatrix, SPA_POD_Id(info->color_matrix), 0);
if (info->transfer_function != 0)
spa_pod_builder_add(builder,
SPA_FORMAT_VIDEO_transferFunction,SPA_POD_Id(info->transfer_function), 0);
if (info->color_primaries != 0)
spa_pod_builder_add(builder,
SPA_FORMAT_VIDEO_colorPrimaries,SPA_POD_Id(info->color_primaries), 0);
return (struct spa_pod*)spa_pod_builder_pop(builder, &f);
}
static inline bool
spa_format_video_is_rgb(enum spa_video_format format)
{
switch (format) {
case SPA_VIDEO_FORMAT_RGBx:
case SPA_VIDEO_FORMAT_BGRx:
case SPA_VIDEO_FORMAT_xRGB:
case SPA_VIDEO_FORMAT_xBGR:
case SPA_VIDEO_FORMAT_RGBA:
case SPA_VIDEO_FORMAT_BGRA:
case SPA_VIDEO_FORMAT_ARGB:
case SPA_VIDEO_FORMAT_ABGR:
case SPA_VIDEO_FORMAT_RGB:
case SPA_VIDEO_FORMAT_BGR:
case SPA_VIDEO_FORMAT_GRAY8:
case SPA_VIDEO_FORMAT_GRAY16_BE:
case SPA_VIDEO_FORMAT_GRAY16_LE:
case SPA_VIDEO_FORMAT_RGB16:
case SPA_VIDEO_FORMAT_BGR16:
case SPA_VIDEO_FORMAT_RGB15:
case SPA_VIDEO_FORMAT_BGR15:
case SPA_VIDEO_FORMAT_RGB8P:
case SPA_VIDEO_FORMAT_ARGB64:
case SPA_VIDEO_FORMAT_r210:
case SPA_VIDEO_FORMAT_GBR:
case SPA_VIDEO_FORMAT_GBR_10BE:
case SPA_VIDEO_FORMAT_GBR_10LE:
case SPA_VIDEO_FORMAT_GBRA:
case SPA_VIDEO_FORMAT_GBRA_10BE:
case SPA_VIDEO_FORMAT_GBRA_10LE:
case SPA_VIDEO_FORMAT_GBR_12BE:
case SPA_VIDEO_FORMAT_GBR_12LE:
case SPA_VIDEO_FORMAT_GBRA_12BE:
case SPA_VIDEO_FORMAT_GBRA_12LE:
case SPA_VIDEO_FORMAT_RGBA_F16:
case SPA_VIDEO_FORMAT_RGBA_F32:
case SPA_VIDEO_FORMAT_xRGB_210LE:
case SPA_VIDEO_FORMAT_xBGR_210LE:
case SPA_VIDEO_FORMAT_RGBx_102LE:
case SPA_VIDEO_FORMAT_BGRx_102LE:
case SPA_VIDEO_FORMAT_ARGB_210LE:
case SPA_VIDEO_FORMAT_ABGR_210LE:
case SPA_VIDEO_FORMAT_RGBA_102LE:
case SPA_VIDEO_FORMAT_BGRA_102LE:
return true;
default:
return false;
}
}
#ifdef __cplusplus
} /* extern "C" */
#endif
#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