From 06d4629521f182062d12f26cb3c17cb6dac56d32 Mon Sep 17 00:00:00 2001 From: Peter Stensson Date: Wed, 23 Oct 2024 14:28:30 +0200 Subject: [PATCH] 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: --- .../gst/codectimestamper/gstcodectimestamper.c | 7 ++++++- .../gst-plugins-bad/tests/check/elements/h264timestamper.c | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/subprojects/gst-plugins-bad/gst/codectimestamper/gstcodectimestamper.c b/subprojects/gst-plugins-bad/gst/codectimestamper/gstcodectimestamper.c index 5c93f8d564..ea75561860 100644 --- a/subprojects/gst-plugins-bad/gst/codectimestamper/gstcodectimestamper.c +++ b/subprojects/gst-plugins-bad/gst/codectimestamper/gstcodectimestamper.c @@ -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 diff --git a/subprojects/gst-plugins-bad/tests/check/elements/h264timestamper.c b/subprojects/gst-plugins-bad/tests/check/elements/h264timestamper.c index b7206bae6b..df69e525b3 100644 --- a/subprojects/gst-plugins-bad/tests/check/elements/h264timestamper.c +++ b/subprojects/gst-plugins-bad/tests/check/elements/h264timestamper.c @@ -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));