video: Add extra field indicating if modifier value is valid

The drm format modifier value `0` is actually `DRM_FORMAT_MOD_LINEAR`,
a commonly used modifier. Unfortunately there appears to be no value
that can savely used as placeholder for "no value", as e.g.
`DRM_FORMAT_MOD_INVALID` is often used to indicate an implicit modifier.

Thus add an extra field that clearly indicates whether the modifier
value is set or not, add it to the util fuctions and use it for the
current only user, the libcamera backend.

Fixes 5a6da7d5e1

Closes https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/2943
This commit is contained in:
Robert Mader 2023-01-10 21:53:55 +01:00
parent cab3e3c1ce
commit 1e6920c33b
3 changed files with 25 additions and 7 deletions

View file

@ -42,7 +42,9 @@ static inline int
spa_format_video_raw_parse(const struct spa_pod *format,
struct spa_video_info_raw *info)
{
return spa_pod_parse_object(format,
int res;
res = 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),
@ -59,16 +61,26 @@ spa_format_video_raw_parse(const struct spa_pod *format,
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));
info->use_modifier = spa_pod_find_prop (format, NULL, SPA_FORMAT_VIDEO_modifier) ? true : false;
return res;
}
static inline int
spa_format_video_dsp_parse(const struct spa_pod *format,
struct spa_video_info_dsp *info)
{
return spa_pod_parse_object(format,
int res;
res = 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));
info->use_modifier = spa_pod_find_prop (format, NULL, SPA_FORMAT_VIDEO_modifier) ? true : false;
return res;
}
static inline struct spa_pod *
@ -90,7 +102,7 @@ spa_format_video_raw_build(struct spa_pod_builder *builder, uint32_t id,
if (info->framerate.denom != 0)
spa_pod_builder_add(builder,
SPA_FORMAT_VIDEO_framerate, SPA_POD_Fraction(&info->framerate), 0);
if (info->modifier != 0)
if (info->use_modifier)
spa_pod_builder_add(builder,
SPA_FORMAT_VIDEO_modifier, SPA_POD_Long(info->modifier), 0);
if (info->max_framerate.denom != 0)
@ -142,7 +154,7 @@ spa_format_video_dsp_build(struct spa_pod_builder *builder, uint32_t id,
if (info->format != SPA_VIDEO_FORMAT_UNKNOWN)
spa_pod_builder_add(builder,
SPA_FORMAT_VIDEO_format, SPA_POD_Id(info->format), 0);
if (info->modifier)
if (info->use_modifier)
spa_pod_builder_add(builder,
SPA_FORMAT_VIDEO_modifier, SPA_POD_Long(info->modifier), 0);
return (struct spa_pod*)spa_pod_builder_pop(builder, &f);

View file

@ -186,7 +186,9 @@ enum spa_video_interlace_mode {
*/
struct spa_video_info_raw {
enum spa_video_format format; /**< the format */
int64_t modifier; /**< format modifier
bool use_modifier; /**< whether the modifier field has a valid value */
uint64_t modifier; /**< format modifier
* only used with DMA-BUF */
struct spa_rectangle size; /**< the frame size of the video */
struct spa_fraction framerate; /**< the framerate of the video, 0/1 means variable rate */
@ -210,7 +212,8 @@ struct spa_video_info_raw {
struct spa_video_info_dsp {
enum spa_video_format format;
int64_t modifier;
bool use_modifier;
uint64_t modifier;
};
#define SPA_VIDEO_INFO_DSP_INIT(...) ((struct spa_video_info_dsp) { __VA_ARGS__ })