v4l2src: need maintain the caps order in caps compare when fixate

if the calculated "distance" of caps A and B from the preference are
equal, need to keep the original order instead of swap them

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6451>
This commit is contained in:
Haihua Hu 2024-03-27 15:21:56 +09:00 committed by GStreamer Marge Bot
parent d0cfada15e
commit 37e3a38ba9

View file

@ -448,6 +448,7 @@ gst_v4l2src_fixed_caps_compare (GstCaps * caps_a, GstCaps * caps_b,
gint a_fps_n = G_MAXINT, a_fps_d = 1;
gint b_fps_n = G_MAXINT, b_fps_d = 1;
gint a_distance, b_distance;
gint ret = 0;
a = gst_caps_get_structure (caps_a, 0);
b = gst_caps_get_structure (caps_b, 0);
@ -468,7 +469,11 @@ gst_v4l2src_fixed_caps_compare (GstCaps * caps_a, GstCaps * caps_b,
a_distance = ABS (aw * ah - pref->width * pref->height);
b_distance = ABS (bw * bh - pref->width * pref->height);
gint ret = a_distance - b_distance;
/* If the distance are equivalent, maintain the order */
if (a_distance == b_distance)
ret = 1;
else
ret = a_distance - b_distance;
GST_TRACE ("Placing %" GST_PTR_FORMAT " %s %" GST_PTR_FORMAT,
caps_a, ret > 0 ? "after" : "before", caps_b);