From: Tomáš Polomský <1155369-polomsky@users.noreply.gitlab.freedesktop.org> Date: Tue, 26 Nov 2024 05:40:34 +0000 (+0100) Subject: appsink: fix timeout logic for gst_app_sink_try_pull_sample X-Git-Tag: 1.24.10~65 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=97ea1501fd7ed5aafe243ba3b7ea3baeac3a1edd;p=platform%2Fupstream%2Fgstreamer.git appsink: fix timeout logic for gst_app_sink_try_pull_sample In case of gst_app_sink_try_pull_object returns an object instead of a sample, the whole process must be restarted with the reduced timeout, otherwise requested timeout could be easily exceeded. Part-of: --- diff --git a/subprojects/gst-plugins-base/gst-libs/gst/app/gstappsink.c b/subprojects/gst-plugins-base/gst-libs/gst/app/gstappsink.c index eeb6d68c25..506cc36861 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/app/gstappsink.c +++ b/subprojects/gst-plugins-base/gst-libs/gst/app/gstappsink.c @@ -2002,6 +2002,20 @@ not_started: GstSample * gst_app_sink_try_pull_sample (GstAppSink * appsink, GstClockTime timeout) { + gboolean timeout_valid; + gint64 end_time, now; + + /* + * 0 is valid but has a special meaning for gst_app_sink_try_pull_object which fetches + * a sample/event that is available without waiting. For 0, we don't want to deduct + * from the timeout to allow skipping all events and reading a sample directly. + */ + timeout_valid = timeout != 0 && GST_CLOCK_TIME_IS_VALID (timeout); + + if (timeout_valid) + end_time = + g_get_monotonic_time () + timeout / (GST_SECOND / G_TIME_SPAN_SECOND); + while (TRUE) { GstMiniObject *obj; @@ -2013,6 +2027,14 @@ gst_app_sink_try_pull_sample (GstAppSink * appsink, GstClockTime timeout) return GST_SAMPLE_CAST (obj); } else { gst_mini_object_unref (obj); + if (timeout_valid) { + now = g_get_monotonic_time (); + if (now >= end_time) { + /* timeout expired */ + return NULL; + } + timeout = (end_time - now) * (GST_SECOND / G_TIME_SPAN_SECOND); + } } } }