codectimestamper: Fix gint wraparound in pts_compare_func
authorPeter Stensson <petest@axis.com>
Wed, 23 Oct 2024 12:28:30 +0000 (14:28 +0200)
committerBackport Bot <gitlab-backport-bot@gstreamer-foundation.org>
Fri, 25 Oct 2024 09:18:56 +0000 (10:18 +0100)
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>

subprojects/gst-plugins-bad/gst/codectimestamper/gstcodectimestamper.c
subprojects/gst-plugins-bad/tests/check/elements/h264timestamper.c

index 14ac71580b0f5c9bddce7e82fc85d7fb0673bfdf..94cefc6458b5183c33bd5ce22ec9190adfe5b421 100644 (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
index b7206bae6bba9ac6d369c504fe6bf72661078321..df69e525b36231bc752372e57e24d0e9823ed092 100644 (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));