v4l2codecs: Sort caps pixel formats

Sort caps pixels formats given their order in format_map array.
This commit is contained in:
Benjamin Gaignard 2023-06-21 14:54:41 +02:00
parent 94eaa2d885
commit 6261a583fa
3 changed files with 36 additions and 1 deletions

View file

@ -524,7 +524,7 @@ gst_v4l2_decoder_enum_src_formats (GstV4l2Decoder * self,
GST_DEBUG_OBJECT (self, "Probed caps: %" GST_PTR_FORMAT, caps);
return caps;
return gst_v4l2_sort_caps (caps);
}
gboolean

View file

@ -77,6 +77,19 @@ lookup_gst_fmt (GstVideoFormat gst_fmt)
return ret;
}
static int
gst_fmt_index (GstVideoFormat gst_fmt)
{
gint i;
for (i = 0; format_map[i].v4l2_pix_fmt; i++) {
if (format_map[i].gst_fmt == gst_fmt)
return i;
}
return i;
}
static void
set_stride (GstVideoInfo * info, gint plane, gint stride)
{
@ -203,3 +216,23 @@ gst_v4l2_format_from_video_format (GstVideoFormat format, guint32 * out_pix_fmt)
*out_pix_fmt = entry->v4l2_pix_fmt;
return TRUE;
}
static gint
gst_v4l2_caps_compare_structures (const GstStructure * a,
const GstStructure * b)
{
const GValue *formata = gst_structure_get_value (a, "format");
const GValue *formatb = gst_structure_get_value (b, "format");
GstVideoFormat vformata =
gst_video_format_from_string (g_value_get_string (formata));
GstVideoFormat vformatb =
gst_video_format_from_string (g_value_get_string (formatb));
return gst_fmt_index (vformata) - gst_fmt_index (vformatb);
}
GstCaps *
gst_v4l2_sort_caps (GstCaps * caps)
{
return gst_caps_sort (caps, gst_v4l2_caps_compare_structures);
}

View file

@ -38,4 +38,6 @@ gboolean gst_v4l2_format_to_video_format (guint32 pix_fmt,
gboolean gst_v4l2_format_from_video_format (GstVideoFormat format,
guint32 * out_pix_fmt);
GstCaps * gst_v4l2_sort_caps (GstCaps * caps);
#endif /* __GST_V4L2_FORMAT_H__ */