mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-03-13 23:22:54 +00:00
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: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/7962>
This commit is contained in:
parent
b433d72a4d
commit
fa1ed5d210
1 changed files with 22 additions and 0 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue