From 05298b3093ae840b293d5dadc1dd85335d6659c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Cr=C3=AAte?= Date: Sat, 5 May 2018 10:46:09 +0200 Subject: [PATCH] aggregator: Add get_next_time function for live streams Add a function to do the right thing for live streams. https://bugzilla.gnome.org/show_bug.cgi?id=795486 --- docs/libs/gstreamer-libs-sections.txt | 1 + libs/gst/base/gstaggregator.c | 37 +++++++++++++++++++++++++++ libs/gst/base/gstaggregator.h | 4 +++ 3 files changed, 42 insertions(+) diff --git a/docs/libs/gstreamer-libs-sections.txt b/docs/libs/gstreamer-libs-sections.txt index 19b331a85d..f9f051b672 100644 --- a/docs/libs/gstreamer-libs-sections.txt +++ b/docs/libs/gstreamer-libs-sections.txt @@ -231,6 +231,7 @@ gst_aggregator_get_latency gst_aggregator_set_latency gst_aggregator_get_buffer_pool gst_aggregator_get_allocator +gst_aggregator_simple_get_next_time GST_IS_AGGREGATOR GST_IS_AGGREGATOR_CLASS diff --git a/libs/gst/base/gstaggregator.c b/libs/gst/base/gstaggregator.c index 84f34081fb..d057b877e1 100644 --- a/libs/gst/base/gstaggregator.c +++ b/libs/gst/base/gstaggregator.c @@ -3114,3 +3114,40 @@ gst_aggregator_get_allocator (GstAggregator * self, if (params) *params = self->priv->allocation_params; } + +/** + * gst_aggregator_simple_get_next_time: + * @self: A #GstAggregator + * + * This is a simple #GstAggregator::get_next_time implementation that + * just looks at the #GstSegment on the srcpad of the aggregator and bases + * the next time on the running there there. + * + * This is the desired behaviour in most cases where you have a live source + * and you have a dead line based aggregator subclass. + * + * Returns: The running time based on the position + * + * Since: 1.16 + */ +GstClockTime +gst_aggregator_simple_get_next_time (GstAggregator * self) +{ + GstClockTime next_time; + GstAggregatorPad *srcpad = GST_AGGREGATOR_PAD (self->srcpad); + GstSegment *segment = &srcpad->segment; + + GST_OBJECT_LOCK (self); + if (segment->position == -1 || segment->position < segment->start) + next_time = segment->start; + else + next_time = segment->position; + + if (segment->stop != -1 && next_time > segment->stop) + next_time = segment->stop; + + next_time = gst_segment_to_running_time (segment, GST_FORMAT_TIME, next_time); + GST_OBJECT_UNLOCK (self); + + return next_time; +} diff --git a/libs/gst/base/gstaggregator.h b/libs/gst/base/gstaggregator.h index 122ee3e57e..681abeec6e 100644 --- a/libs/gst/base/gstaggregator.h +++ b/libs/gst/base/gstaggregator.h @@ -348,6 +348,10 @@ void gst_aggregator_get_allocator (GstAggregator GstAllocator ** allocator, GstAllocationParams * params); +GST_BASE_API +GstClockTime gst_aggregator_simple_get_next_time (GstAggregator * self); + + G_END_DECLS #endif /* __GST_AGGREGATOR_H__ */