+ +
2da5fe7 OpenAVX v0.2.0 - High-performance open-standard IP audio and video transport suite
saifmukhtar · 2026-11-24
main
| 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 |
| 14 | extern "C" { |
| 15 | #endif |
| 16 | |
| 17 | /** |
| 18 | * \addtogroup spa_param |
| 19 | * \{ |
| 20 | */ |
| 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 | |
| 121 | static 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 | |
| 171 | /** |
| 172 | * \} |
| 173 | */ |
| 174 | |
| 175 | #ifdef __cplusplus |
| 176 | } /* extern "C" */ |
| 177 | #endif |
| 178 | |
| 179 | #endif /* SPA_VIDEO_RAW_UTILS_H */ |