codectimestamper: Fix gint wraparound in pts_compare_func

The diff between compared timestamps might be outside the gint range
resulting in wrong sorting results. This patch corrects that by
comparing the timestamps and then returning -1, 0 or 1 depending on the
result.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/7737>
This commit is contained in:
Peter Stensson 2024-10-23 14:28:30 +02:00 committed by Backport Bot
parent 908b79d168
commit 516e422231
2 changed files with 9 additions and 1 deletions

View file

@ -506,7 +506,12 @@ gst_codec_timestamper_drain (GstCodecTimestamper * self)
static gint
pts_compare_func (const GstClockTime * a, const GstClockTime * b)
{
return (*a) - (*b);
if (*a < *b)
return -1;
else if (*a > *b)
return 1;
else
return 0;
}
static GstFlowReturn

View file

@ -128,6 +128,9 @@ GST_START_TEST (test_input_pts_none)
GST_BUFFER_PTS (buffer) = 0;
fail_unless_equals_int (gst_harness_push (h, buffer), GST_FLOW_OK);;
buffer = gst_buffer_new_memdup (h264_idrframe, G_N_ELEMENTS (h264_idrframe));
GST_BUFFER_PTS (buffer) = 3 * GST_SECOND;
fail_unless_equals_int (gst_harness_push (h, buffer), GST_FLOW_OK);;
buffer = gst_buffer_new_memdup (h264_idrframe, G_N_ELEMENTS (h264_idrframe));
GST_BUFFER_PTS (buffer) = GST_CLOCK_TIME_NONE;
fail_unless_equals_int (gst_harness_push (h, buffer), GST_FLOW_OK);;
buffer = gst_buffer_new_memdup (h264_idrframe, G_N_ELEMENTS (h264_idrframe));