1 /* GStreamer aggregator base class
2 * Copyright (C) 2014 Mathieu Duponchelle <mathieu.duponchelle@opencreed.com>
3 * Copyright (C) 2014 Thibault Saunier <tsaunier@gnome.org>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
23 * SECTION: gstaggregator
24 * @title: GstAggregator
25 * @short_description: Base class for mixers and muxers, manages a set of input
26 * pads and aggregates their streams
27 * @see_also: gstcollectpads for historical reasons.
29 * Manages a set of pads with the purpose of aggregating their buffers.
30 * Control is given to the subclass when all pads have data.
32 * * Base class for mixers and muxers. Subclasses should at least implement
33 * the #GstAggregatorClass::aggregate virtual method.
35 * * Installs a #GstPadChainFunction, a #GstPadEventFullFunction and a
36 * #GstPadQueryFunction to queue all serialized data packets per sink pad.
37 * Subclasses should not overwrite those, but instead implement
38 * #GstAggregatorClass::sink_event and #GstAggregatorClass::sink_query as
41 * * When data is queued on all pads, the aggregate vmethod is called.
43 * * One can peek at the data on any given GstAggregatorPad with the
44 * gst_aggregator_pad_peek_buffer() method, and remove it from the pad
45 * with the gst_aggregator_pad_pop_buffer () method. When a buffer
46 * has been taken with pop_buffer (), a new buffer can be queued
49 * * When gst_aggregator_pad_peek_buffer() or gst_aggregator_pad_has_buffer()
50 * are called, a reference is taken to the returned buffer, which stays
53 * - gst_aggregator_pad_pop_buffer() is called, in which case the caller
54 * is guaranteed that the buffer they receive is the same as the peeked
56 * - gst_aggregator_pad_drop_buffer() is called, in which case the caller
57 * is guaranteed that the dropped buffer is the one that was peeked.
58 * - the subclass implementation of #GstAggregatorClass.aggregate returns.
60 * Subsequent calls to gst_aggregator_pad_peek_buffer() or
61 * gst_aggregator_pad_has_buffer() return / check the same buffer that was
62 * returned / checked, until one of the conditions listed above is met.
64 * Subclasses are only allowed to call these methods from the aggregate
67 * * If the subclass wishes to push a buffer downstream in its aggregate
68 * implementation, it should do so through the
69 * gst_aggregator_finish_buffer() method. This method will take care
70 * of sending and ordering mandatory events such as stream start, caps
71 * and segment. Buffer lists can also be pushed out with
72 * gst_aggregator_finish_buffer_list().
74 * * Same goes for EOS events, which should not be pushed directly by the
75 * subclass, it should instead return GST_FLOW_EOS in its aggregate
78 * * Note that the aggregator logic regarding gap event handling is to turn
79 * these into gap buffers with matching PTS and duration. It will also
80 * flag these buffers with GST_BUFFER_FLAG_GAP and GST_BUFFER_FLAG_DROPPABLE
81 * to ease their identification and subsequent processing.
82 * In addition, if the gap event was flagged with GST_GAP_FLAG_MISSING_DATA,
83 * a custom meta is added to the resulting gap buffer (GstAggregatorMissingDataMeta).
85 * * Subclasses must use (a subclass of) #GstAggregatorPad for both their
86 * sink and source pads.
87 * See gst_element_class_add_static_pad_template_with_gtype().
89 * This class used to live in gst-plugins-bad and was moved to core.
95 * SECTION: gstaggregatorpad
96 * @title: GstAggregatorPad
97 * @short_description: #GstPad subclass for pads managed by #GstAggregator
98 * @see_also: gstcollectpads for historical reasons.
100 * Pads managed by a #GstAggregator subclass.
102 * This class used to live in gst-plugins-bad and was moved to core.
111 #include <string.h> /* strlen */
113 #include "gstaggregator.h"
116 gst_aggregator_start_time_selection_get_type (void)
118 static GType gtype = 0;
120 if (g_once_init_enter (>ype)) {
121 static const GEnumValue values[] = {
122 {GST_AGGREGATOR_START_TIME_SELECTION_ZERO,
123 "GST_AGGREGATOR_START_TIME_SELECTION_ZERO", "zero"},
124 {GST_AGGREGATOR_START_TIME_SELECTION_FIRST,
125 "GST_AGGREGATOR_START_TIME_SELECTION_FIRST", "first"},
126 {GST_AGGREGATOR_START_TIME_SELECTION_SET,
127 "GST_AGGREGATOR_START_TIME_SELECTION_SET", "set"},
131 g_enum_register_static ("GstAggregatorStartTimeSelection", values);
133 g_once_init_leave (>ype, new_type);
138 /* Might become API */
140 static void gst_aggregator_merge_tags (GstAggregator * aggregator,
141 const GstTagList * tags, GstTagMergeMode mode);
143 static void gst_aggregator_set_latency_property (GstAggregator * agg,
144 GstClockTime latency);
145 static GstClockTime gst_aggregator_get_latency_property (GstAggregator * agg);
147 static GstClockTime gst_aggregator_get_latency_unlocked (GstAggregator * self);
149 static void gst_aggregator_pad_buffer_consumed (GstAggregatorPad * pad,
150 GstBuffer * buffer, gboolean dequeued);
152 GST_DEBUG_CATEGORY_STATIC (aggregator_debug);
153 #define GST_CAT_DEFAULT aggregator_debug
155 /* Locking order, locks in this element must always be taken in this order
157 * standard sink pad stream lock -> GST_PAD_STREAM_LOCK (aggpad)
158 * Aggregator pad flush lock -> PAD_FLUSH_LOCK(aggpad)
159 * standard src pad stream lock -> GST_PAD_STREAM_LOCK (srcpad)
160 * Aggregator src lock -> SRC_LOCK(agg) w/ SRC_WAIT/BROADCAST
161 * standard element object lock -> GST_OBJECT_LOCK(agg)
162 * Aggregator pad lock -> PAD_LOCK (aggpad) w/ PAD_WAIT/BROADCAST_EVENT(aggpad)
163 * standard src pad object lock -> GST_OBJECT_LOCK(srcpad)
164 * standard sink pad object lock -> GST_OBJECT_LOCK(aggpad)
167 /* GstAggregatorPad definitions */
168 #define PAD_LOCK(pad) G_STMT_START { \
169 GST_TRACE_OBJECT (pad, "Taking PAD lock from thread %p", \
171 g_mutex_lock(&pad->priv->lock); \
172 GST_TRACE_OBJECT (pad, "Took PAD lock from thread %p", \
176 #define PAD_UNLOCK(pad) G_STMT_START { \
177 GST_TRACE_OBJECT (pad, "Releasing PAD lock from thread %p", \
179 g_mutex_unlock(&pad->priv->lock); \
180 GST_TRACE_OBJECT (pad, "Release PAD lock from thread %p", \
185 #define PAD_WAIT_EVENT(pad) G_STMT_START { \
186 GST_LOG_OBJECT (pad, "Waiting for buffer to be consumed thread %p", \
188 g_cond_wait(&(((GstAggregatorPad* )pad)->priv->event_cond), \
189 (&((GstAggregatorPad*)pad)->priv->lock)); \
190 GST_LOG_OBJECT (pad, "DONE Waiting for buffer to be consumed on thread %p", \
194 #define PAD_BROADCAST_EVENT(pad) G_STMT_START { \
195 GST_LOG_OBJECT (pad, "Signaling buffer consumed from thread %p", \
197 g_cond_broadcast(&(((GstAggregatorPad* )pad)->priv->event_cond)); \
201 #define PAD_FLUSH_LOCK(pad) G_STMT_START { \
202 GST_TRACE_OBJECT (pad, "Taking lock from thread %p", \
204 g_mutex_lock(&pad->priv->flush_lock); \
205 GST_TRACE_OBJECT (pad, "Took lock from thread %p", \
209 #define PAD_FLUSH_UNLOCK(pad) G_STMT_START { \
210 GST_TRACE_OBJECT (pad, "Releasing lock from thread %p", \
212 g_mutex_unlock(&pad->priv->flush_lock); \
213 GST_TRACE_OBJECT (pad, "Release lock from thread %p", \
217 #define SRC_LOCK(self) G_STMT_START { \
218 GST_TRACE_OBJECT (self, "Taking src lock from thread %p", \
220 g_mutex_lock(&self->priv->src_lock); \
221 GST_TRACE_OBJECT (self, "Took src lock from thread %p", \
225 #define SRC_UNLOCK(self) G_STMT_START { \
226 GST_TRACE_OBJECT (self, "Releasing src lock from thread %p", \
228 g_mutex_unlock(&self->priv->src_lock); \
229 GST_TRACE_OBJECT (self, "Released src lock from thread %p", \
233 #define SRC_WAIT(self) G_STMT_START { \
234 GST_LOG_OBJECT (self, "Waiting for src on thread %p", \
236 g_cond_wait(&(self->priv->src_cond), &(self->priv->src_lock)); \
237 GST_LOG_OBJECT (self, "DONE Waiting for src on thread %p", \
241 #define SRC_BROADCAST(self) G_STMT_START { \
242 GST_LOG_OBJECT (self, "Signaling src from thread %p", \
244 if (self->priv->aggregate_id) \
245 gst_clock_id_unschedule (self->priv->aggregate_id); \
246 g_cond_broadcast(&(self->priv->src_cond)); \
249 struct _GstAggregatorPadPrivate
251 /* Following fields are protected by the PAD_LOCK */
252 GstFlowReturn flow_return;
254 guint32 last_flush_start_seqnum;
255 guint32 last_flush_stop_seqnum;
257 /* Whether the pad hasn't received a first buffer yet */
258 gboolean first_buffer;
259 /* Whether we waited once for the pad's first buffer */
260 gboolean waited_once;
262 GQueue data; /* buffers, events and queries */
263 GstBuffer *clipped_buffer;
265 GstBuffer *peeked_buffer;
267 /* used to track fill state of queues, only used with live-src and when
268 * latency property is set to > 0 */
269 GstClockTime head_position;
270 GstClockTime tail_position;
271 GstClockTime head_time; /* running time */
272 GstClockTime tail_time;
273 GstClockTime time_level; /* how much head is ahead of tail */
274 GstSegment head_segment; /* segment before the queue */
282 /* This lock prevents a flush start processing happening while
283 * the chain function is also happening.
288 gboolean emit_signals;
291 /* Must be called with PAD_LOCK held */
293 gst_aggregator_pad_reset_unlocked (GstAggregatorPad * aggpad)
295 aggpad->priv->eos = FALSE;
296 aggpad->priv->flow_return = GST_FLOW_OK;
297 GST_OBJECT_LOCK (aggpad);
298 gst_segment_init (&aggpad->segment, GST_FORMAT_UNDEFINED);
299 gst_segment_init (&aggpad->priv->head_segment, GST_FORMAT_UNDEFINED);
300 GST_OBJECT_UNLOCK (aggpad);
301 aggpad->priv->head_position = GST_CLOCK_TIME_NONE;
302 aggpad->priv->tail_position = GST_CLOCK_TIME_NONE;
303 aggpad->priv->head_time = GST_CLOCK_TIME_NONE;
304 aggpad->priv->tail_time = GST_CLOCK_TIME_NONE;
305 aggpad->priv->time_level = 0;
306 aggpad->priv->first_buffer = TRUE;
307 aggpad->priv->waited_once = FALSE;
311 gst_aggregator_pad_flush (GstAggregatorPad * aggpad, GstAggregator * agg)
313 GstAggregatorPadClass *klass = GST_AGGREGATOR_PAD_GET_CLASS (aggpad);
316 gst_aggregator_pad_reset_unlocked (aggpad);
320 return (klass->flush (aggpad, agg) == GST_FLOW_OK);
326 * gst_aggregator_peek_next_sample:
328 * Use this function to determine what input buffers will be aggregated
329 * to produce the next output buffer. This should only be called from
330 * a #GstAggregator::samples-selected handler, and can be used to precisely
331 * control aggregating parameters for a given set of input samples.
333 * Returns: (nullable) (transfer full): The sample that is about to be aggregated. It may hold a #GstBuffer
334 * or a #GstBufferList. The contents of its info structure is subclass-dependent,
335 * and documented on a subclass basis. The buffers held by the sample are
340 gst_aggregator_peek_next_sample (GstAggregator * agg, GstAggregatorPad * aggpad)
342 GstAggregatorClass *klass = GST_AGGREGATOR_GET_CLASS (agg);
344 if (klass->peek_next_sample)
345 return (klass->peek_next_sample (agg, aggpad));
350 /*************************************
351 * GstAggregator implementation *
352 *************************************/
353 static GstElementClass *aggregator_parent_class = NULL;
354 static gint aggregator_private_offset = 0;
356 /* All members are protected by the object lock unless otherwise noted */
358 struct _GstAggregatorPrivate
362 /* Our state is >= PAUSED */
363 gboolean running; /* protected by src_lock */
365 /* seqnum from last seek or common seqnum to flush start events received
366 * on all pads, for flushing without a seek */
368 /* seqnum to apply to synthetic segment/eos events */
370 gboolean send_stream_start; /* protected by srcpad stream lock */
371 gboolean send_segment;
373 gboolean send_eos; /* protected by srcpad stream lock */
374 gboolean got_eos_event; /* protected by srcpad stream lock */
376 GstCaps *srccaps; /* protected by the srcpad stream lock */
379 gboolean tags_changed;
381 gboolean peer_latency_live; /* protected by src_lock */
382 GstClockTime peer_latency_min; /* protected by src_lock */
383 GstClockTime peer_latency_max; /* protected by src_lock */
384 gboolean has_peer_latency; /* protected by src_lock */
386 GstClockTime sub_latency_min; /* protected by src_lock */
387 GstClockTime sub_latency_max; /* protected by src_lock */
388 /* Tracks whether the latency message was posted at least once */
389 gboolean posted_latency_msg;
391 GstClockTime upstream_latency_min; /* protected by src_lock */
394 GstClockID aggregate_id; /* protected by src_lock */
395 gboolean selected_samples_called_or_warned; /* protected by src_lock */
399 gboolean first_buffer; /* protected by object lock */
400 GstAggregatorStartTimeSelection start_time_selection;
401 GstClockTime start_time;
403 /* protected by the object lock */
404 GstQuery *allocation_query;
405 GstAllocator *allocator;
407 GstAllocationParams allocation_params;
410 gint64 latency; /* protected by both src_lock and all pad locks */
411 gboolean emit_signals;
412 gboolean ignore_inactive_pads;
413 gboolean force_live; /* Construct only, doesn't need any locking */
418 is_live_unlocked (GstAggregator * self)
420 return self->priv->peer_latency_live || self->priv->force_live;
423 /* Seek event forwarding helper */
429 gboolean only_to_active_pads;
433 gboolean one_actually_seeked;
436 #define DEFAULT_LATENCY 0
437 #define DEFAULT_MIN_UPSTREAM_LATENCY 0
438 #define DEFAULT_START_TIME_SELECTION GST_AGGREGATOR_START_TIME_SELECTION_ZERO
439 #define DEFAULT_START_TIME (-1)
440 #define DEFAULT_EMIT_SIGNALS FALSE
441 #define DEFAULT_FORCE_LIVE FALSE
447 PROP_MIN_UPSTREAM_LATENCY,
448 PROP_START_TIME_SELECTION,
456 SIGNAL_SAMPLES_SELECTED,
460 static guint gst_aggregator_signals[LAST_SIGNAL] = { 0 };
462 static GstFlowReturn gst_aggregator_pad_chain_internal (GstAggregator * self,
463 GstAggregatorPad * aggpad, GstBuffer * buffer, gboolean head);
466 gst_aggregator_pad_queue_is_empty (GstAggregatorPad * pad)
468 return (g_queue_peek_tail (&pad->priv->data) == NULL &&
469 pad->priv->clipped_buffer == NULL);
472 /* Will return FALSE if there's no buffer available on every non-EOS pad, or
473 * if at least one of the pads has an event or query at the top of its queue.
475 * Only returns TRUE if all non-EOS pads have a buffer available at the top of
476 * their queue or a clipped buffer already.
479 gst_aggregator_check_pads_ready (GstAggregator * self,
480 gboolean * have_event_or_query_ret)
482 GstAggregatorPad *pad = NULL;
484 gboolean have_buffer = TRUE;
485 gboolean have_event_or_query = FALSE;
488 GST_LOG_OBJECT (self, "checking pads");
490 GST_OBJECT_LOCK (self);
492 sinkpads = GST_ELEMENT_CAST (self)->sinkpads;
493 if (sinkpads == NULL)
496 for (l = sinkpads; l != NULL; l = l->next) {
501 /* If there's an event or query at the top of the queue and we don't yet
502 * have taken the top buffer out and stored it as clip_buffer, remember
503 * that and exit the loop. We first have to handle all events/queries
504 * before we handle any buffers. */
505 if (!pad->priv->clipped_buffer
506 && (GST_IS_EVENT (g_queue_peek_tail (&pad->priv->data))
507 || GST_IS_QUERY (g_queue_peek_tail (&pad->priv->data)))) {
509 have_event_or_query = TRUE;
510 GST_LOG_OBJECT (pad, "Have pending serialized query/event");
514 if (self->priv->ignore_inactive_pads && is_live_unlocked (self) &&
515 pad->priv->waited_once && pad->priv->first_buffer && !pad->priv->eos) {
517 GST_LOG_OBJECT (pad, "Ignoring inactive pad");
521 /* Otherwise check if we have a clipped buffer or a buffer at the top of
522 * the queue, and if not then this pad is not ready unless it is also EOS */
523 if (!pad->priv->clipped_buffer
524 && !GST_IS_BUFFER (g_queue_peek_tail (&pad->priv->data))) {
525 /* We must not have any buffers at all in this pad then as otherwise we
526 * would've had an event/query at the top of the queue */
527 g_assert (pad->priv->num_buffers == 0);
529 /* Only consider this pad as worth waiting for if it's not already EOS.
530 * There's no point in waiting for buffers on EOS pads */
531 if (!pad->priv->eos) {
532 GST_LOG_OBJECT (pad, "Have no buffer and not EOS yet");
535 GST_LOG_OBJECT (pad, "Have no buffer and already EOS");
539 GST_TRACE_OBJECT (pad, "Have %" GST_TIME_FORMAT " queued in %u buffers",
540 GST_TIME_ARGS (pad->priv->time_level), pad->priv->num_buffers);
541 if (is_live_unlocked (self)) {
542 /* In live mode, having a single pad with buffers is enough to
543 * generate a start time from it. In non-live mode all pads need
546 self->priv->first_buffer = FALSE;
554 if (self->priv->ignore_inactive_pads && is_live_unlocked (self)
558 if (have_event_or_query)
559 goto pad_not_ready_but_event_or_query;
565 self->priv->first_buffer = FALSE;
567 GST_OBJECT_UNLOCK (self);
568 GST_LOG_OBJECT (self, "pads are ready");
570 if (have_event_or_query_ret)
571 *have_event_or_query_ret = have_event_or_query;
577 GST_LOG_OBJECT (self, "pads not ready: no sink pads");
578 GST_OBJECT_UNLOCK (self);
580 if (have_event_or_query_ret)
581 *have_event_or_query_ret = have_event_or_query;
587 GST_LOG_OBJECT (self, "pad not ready to be aggregated yet");
588 GST_OBJECT_UNLOCK (self);
590 if (have_event_or_query_ret)
591 *have_event_or_query_ret = have_event_or_query;
595 pad_not_ready_but_event_or_query:
597 GST_LOG_OBJECT (self,
598 "pad not ready to be aggregated yet, need to handle serialized event or query first");
599 GST_OBJECT_UNLOCK (self);
601 if (have_event_or_query_ret)
602 *have_event_or_query_ret = have_event_or_query;
609 gst_aggregator_reset_flow_values (GstAggregator * self)
611 GST_OBJECT_LOCK (self);
612 self->priv->send_stream_start = TRUE;
613 self->priv->send_segment = TRUE;
614 gst_segment_init (&GST_AGGREGATOR_PAD (self->srcpad)->segment,
616 /* Initialize to -1 so we set it to the start position once the first buffer
617 * is handled in gst_aggregator_pad_chain_internal() */
618 GST_AGGREGATOR_PAD (self->srcpad)->segment.position = -1;
619 self->priv->first_buffer = TRUE;
620 GST_OBJECT_UNLOCK (self);
624 gst_aggregator_push_mandatory_events (GstAggregator * self, gboolean up_to_caps)
626 GstAggregatorPrivate *priv = self->priv;
627 GstEvent *segment = NULL;
628 GstEvent *tags = NULL;
630 if (self->priv->send_stream_start) {
633 GST_INFO_OBJECT (self, "pushing stream start");
634 /* stream-start (FIXME: create id based on input ids) */
635 g_snprintf (s_id, sizeof (s_id), "agg-%08x", g_random_int ());
636 if (!gst_pad_push_event (GST_PAD (self->srcpad),
637 gst_event_new_stream_start (s_id))) {
638 GST_WARNING_OBJECT (self->srcpad, "Sending stream start event failed");
640 self->priv->send_stream_start = FALSE;
643 if (self->priv->srccaps) {
644 GST_INFO_OBJECT (self, "pushing caps: %" GST_PTR_FORMAT,
645 self->priv->srccaps);
646 if (!gst_pad_push_event (GST_PAD (self->srcpad),
647 gst_event_new_caps (self->priv->srccaps))) {
648 GST_WARNING_OBJECT (self->srcpad, "Sending caps event failed");
650 gst_caps_unref (self->priv->srccaps);
651 self->priv->srccaps = NULL;
657 GST_OBJECT_LOCK (self);
658 if (self->priv->send_segment && !self->priv->flushing) {
660 gst_event_new_segment (&GST_AGGREGATOR_PAD (self->srcpad)->segment);
662 if (!self->priv->seqnum)
663 /* This code-path is in preparation to be able to run without a source
664 * connected. Then we won't have a seq-num from a segment event. */
665 self->priv->seqnum = gst_event_get_seqnum (segment);
667 gst_event_set_seqnum (segment, self->priv->seqnum);
668 self->priv->send_segment = FALSE;
670 GST_DEBUG_OBJECT (self, "pushing segment %" GST_PTR_FORMAT, segment);
673 if (priv->tags && priv->tags_changed && !self->priv->flushing) {
674 tags = gst_event_new_tag (gst_tag_list_ref (priv->tags));
675 priv->tags_changed = FALSE;
677 GST_OBJECT_UNLOCK (self);
680 gst_pad_push_event (self->srcpad, segment);
682 gst_pad_push_event (self->srcpad, tags);
686 * gst_aggregator_set_src_caps:
687 * @self: The #GstAggregator
688 * @caps: The #GstCaps to set on the src pad.
690 * Sets the caps to be used on the src pad.
693 gst_aggregator_set_src_caps (GstAggregator * self, GstCaps * caps)
697 GST_PAD_STREAM_LOCK (self->srcpad);
699 if (caps && (old_caps = gst_pad_get_current_caps (self->srcpad))) {
700 if (gst_caps_is_equal (caps, old_caps)) {
701 GST_DEBUG_OBJECT (self,
702 "New caps are the same as the previously set caps %" GST_PTR_FORMAT,
704 gst_caps_unref (old_caps);
705 GST_PAD_STREAM_UNLOCK (self->srcpad);
708 gst_caps_unref (old_caps);
711 gst_caps_replace (&self->priv->srccaps, caps);
712 gst_aggregator_push_mandatory_events (self, TRUE);
713 GST_PAD_STREAM_UNLOCK (self->srcpad);
717 gst_aggregator_default_finish_buffer (GstAggregator * self, GstBuffer * buffer)
719 gst_aggregator_push_mandatory_events (self, FALSE);
721 GST_OBJECT_LOCK (self);
722 if (!self->priv->flushing && gst_pad_is_active (self->srcpad)) {
723 GST_TRACE_OBJECT (self, "pushing buffer %" GST_PTR_FORMAT, buffer);
724 GST_OBJECT_UNLOCK (self);
725 return gst_pad_push (self->srcpad, buffer);
727 GST_INFO_OBJECT (self, "Not pushing (active: %i, flushing: %i)",
728 gst_pad_is_active (self->srcpad), self->priv->flushing);
729 GST_OBJECT_UNLOCK (self);
730 gst_buffer_unref (buffer);
736 * gst_aggregator_finish_buffer:
737 * @aggregator: The #GstAggregator
738 * @buffer: (transfer full): the #GstBuffer to push.
740 * This method will push the provided output buffer downstream. If needed,
741 * mandatory events such as stream-start, caps, and segment events will be
742 * sent before pushing the buffer.
745 gst_aggregator_finish_buffer (GstAggregator * aggregator, GstBuffer * buffer)
747 GstAggregatorClass *klass = GST_AGGREGATOR_GET_CLASS (aggregator);
749 g_assert (klass->finish_buffer != NULL);
751 return klass->finish_buffer (aggregator, buffer);
755 gst_aggregator_default_finish_buffer_list (GstAggregator * self,
756 GstBufferList * bufferlist)
758 gst_aggregator_push_mandatory_events (self, FALSE);
760 GST_OBJECT_LOCK (self);
761 if (!self->priv->flushing && gst_pad_is_active (self->srcpad)) {
762 GST_TRACE_OBJECT (self, "pushing bufferlist%" GST_PTR_FORMAT, bufferlist);
763 GST_OBJECT_UNLOCK (self);
764 return gst_pad_push_list (self->srcpad, bufferlist);
766 GST_INFO_OBJECT (self, "Not pushing (active: %i, flushing: %i)",
767 gst_pad_is_active (self->srcpad), self->priv->flushing);
768 GST_OBJECT_UNLOCK (self);
769 gst_buffer_list_unref (bufferlist);
775 * gst_aggregator_finish_buffer_list:
776 * @aggregator: The #GstAggregator
777 * @bufferlist: (transfer full): the #GstBufferList to push.
779 * This method will push the provided output buffer list downstream. If needed,
780 * mandatory events such as stream-start, caps, and segment events will be
781 * sent before pushing the buffer.
786 gst_aggregator_finish_buffer_list (GstAggregator * aggregator,
787 GstBufferList * bufferlist)
789 GstAggregatorClass *klass = GST_AGGREGATOR_GET_CLASS (aggregator);
791 g_assert (klass->finish_buffer_list != NULL);
793 return klass->finish_buffer_list (aggregator, bufferlist);
797 gst_aggregator_push_eos (GstAggregator * self)
800 gst_aggregator_push_mandatory_events (self, FALSE);
802 event = gst_event_new_eos ();
804 GST_OBJECT_LOCK (self);
805 self->priv->send_eos = FALSE;
806 gst_event_set_seqnum (event, self->priv->seqnum);
807 GST_OBJECT_UNLOCK (self);
809 gst_pad_push_event (self->srcpad, event);
813 gst_aggregator_get_next_time (GstAggregator * self)
815 GstAggregatorClass *klass = GST_AGGREGATOR_GET_CLASS (self);
817 if (klass->get_next_time)
818 return klass->get_next_time (self);
820 return GST_CLOCK_TIME_NONE;
824 gst_aggregator_wait_and_check (GstAggregator * self, gboolean * timeout)
826 GstClockTime latency;
829 gboolean have_event_or_query = FALSE;
835 latency = gst_aggregator_get_latency_unlocked (self);
837 if (gst_aggregator_check_pads_ready (self, &have_event_or_query)) {
838 GST_DEBUG_OBJECT (self, "all pads have data");
844 /* If we have an event or query, immediately return FALSE instead of waiting
845 * and handle it immediately */
846 if (have_event_or_query) {
847 GST_DEBUG_OBJECT (self, "Have serialized event or query to handle first");
852 /* Before waiting, check if we're actually still running */
853 if (!self->priv->running || !self->priv->send_eos) {
859 start = gst_aggregator_get_next_time (self);
861 /* If we're not live, or if we use the running time
862 * of the first buffer as start time, we wait until
863 * all pads have buffers.
864 * Otherwise (i.e. if we are live!), we wait on the clock
865 * and if a pad does not have a buffer in time we ignore
868 GST_OBJECT_LOCK (self);
869 if (!GST_CLOCK_TIME_IS_VALID (latency) ||
870 !GST_IS_CLOCK (GST_ELEMENT_CLOCK (self)) ||
871 !GST_CLOCK_TIME_IS_VALID (start) ||
872 (self->priv->first_buffer
873 && self->priv->start_time_selection ==
874 GST_AGGREGATOR_START_TIME_SELECTION_FIRST)) {
875 /* We wake up here when something happened, and below
876 * then check if we're ready now. If we return FALSE,
877 * we will be directly called again.
879 GST_OBJECT_UNLOCK (self);
882 GstClockTime base_time, time;
884 GstClockReturn status;
885 GstClockTimeDiff jitter;
887 GST_DEBUG_OBJECT (self, "got subclass start time: %" GST_TIME_FORMAT,
888 GST_TIME_ARGS (start));
890 base_time = GST_ELEMENT_CAST (self)->base_time;
891 clock = gst_object_ref (GST_ELEMENT_CLOCK (self));
892 GST_OBJECT_UNLOCK (self);
894 time = base_time + start;
897 GST_DEBUG_OBJECT (self, "possibly waiting for clock to reach %"
898 GST_TIME_FORMAT " (base %" GST_TIME_FORMAT " start %" GST_TIME_FORMAT
899 " latency %" GST_TIME_FORMAT " current %" GST_TIME_FORMAT ")",
900 GST_TIME_ARGS (time),
901 GST_TIME_ARGS (base_time),
902 GST_TIME_ARGS (start), GST_TIME_ARGS (latency),
903 GST_TIME_ARGS (gst_clock_get_time (clock)));
905 self->priv->aggregate_id = gst_clock_new_single_shot_id (clock, time);
906 gst_object_unref (clock);
910 status = gst_clock_id_wait (self->priv->aggregate_id, &jitter);
913 if (self->priv->aggregate_id) {
914 gst_clock_id_unref (self->priv->aggregate_id);
915 self->priv->aggregate_id = NULL;
918 GST_DEBUG_OBJECT (self,
919 "clock returned %d (jitter: %" GST_STIME_FORMAT ")",
920 status, GST_STIME_ARGS (jitter));
923 if (status == GST_CLOCK_OK || status == GST_CLOCK_EARLY) {
926 GST_OBJECT_LOCK (self);
927 for (l = GST_ELEMENT_CAST (self)->sinkpads; l != NULL; l = l->next) {
928 GstAggregatorPad *pad = GST_AGGREGATOR_PAD (l->data);
931 pad->priv->waited_once = TRUE;
934 GST_OBJECT_UNLOCK (self);
942 res = gst_aggregator_check_pads_ready (self, NULL);
950 gboolean processed_event;
951 GstFlowReturn flow_ret;
952 } DoHandleEventsAndQueriesData;
955 gst_aggregator_do_events_and_queries (GstElement * self, GstPad * epad,
958 GstAggregatorPad *pad = GST_AGGREGATOR_PAD_CAST (epad);
959 GstAggregator *aggregator = GST_AGGREGATOR_CAST (self);
960 GstEvent *event = NULL;
961 GstQuery *query = NULL;
962 GstAggregatorClass *klass = NULL;
963 DoHandleEventsAndQueriesData *data = user_data;
970 if (pad->priv->clipped_buffer == NULL &&
971 !GST_IS_BUFFER (g_queue_peek_tail (&pad->priv->data))) {
972 if (GST_IS_EVENT (g_queue_peek_tail (&pad->priv->data)))
973 event = gst_event_ref (g_queue_peek_tail (&pad->priv->data));
974 if (GST_IS_QUERY (g_queue_peek_tail (&pad->priv->data)))
975 query = g_queue_peek_tail (&pad->priv->data);
978 if (event || query) {
981 data->processed_event = TRUE;
983 klass = GST_AGGREGATOR_GET_CLASS (self);
986 GST_LOG_OBJECT (pad, "Processing %" GST_PTR_FORMAT, event);
987 gst_event_ref (event);
988 ret = klass->sink_event (aggregator, pad, event);
991 if (GST_EVENT_TYPE (event) == GST_EVENT_CAPS) {
992 pad->priv->negotiated = ret;
994 if (g_queue_peek_tail (&pad->priv->data) == event)
995 gst_event_unref (g_queue_pop_tail (&pad->priv->data));
996 gst_event_unref (event);
998 GST_LOG_OBJECT (pad, "Processing %" GST_PTR_FORMAT, query);
999 ret = klass->sink_query (aggregator, pad, query);
1002 if (g_queue_peek_tail (&pad->priv->data) == query) {
1005 s = gst_query_writable_structure (query);
1006 gst_structure_set (s, "gst-aggregator-retval", G_TYPE_BOOLEAN, ret,
1008 g_queue_pop_tail (&pad->priv->data);
1012 PAD_BROADCAST_EVENT (pad);
1015 } while (event || query);
1021 gst_aggregator_pad_skip_buffers (GstElement * self, GstPad * epad,
1025 GstAggregatorPad *aggpad = (GstAggregatorPad *) epad;
1026 GstAggregator *agg = (GstAggregator *) self;
1027 GstAggregatorPadClass *klass = GST_AGGREGATOR_PAD_GET_CLASS (aggpad);
1029 if (!klass->skip_buffer)
1034 item = g_queue_peek_tail_link (&aggpad->priv->data);
1036 GList *prev = item->prev;
1038 if (GST_IS_BUFFER (item->data)
1039 && klass->skip_buffer (aggpad, agg, item->data)) {
1040 GST_LOG_OBJECT (aggpad, "Skipping %" GST_PTR_FORMAT, item->data);
1041 gst_aggregator_pad_buffer_consumed (aggpad, GST_BUFFER (item->data),
1043 gst_buffer_unref (item->data);
1044 g_queue_delete_link (&aggpad->priv->data, item);
1052 PAD_UNLOCK (aggpad);
1058 gst_aggregator_pad_reset_peeked_buffer (GstElement * self, GstPad * epad,
1061 GstAggregatorPad *aggpad = (GstAggregatorPad *) epad;
1065 gst_buffer_replace (&aggpad->priv->peeked_buffer, NULL);
1067 PAD_UNLOCK (aggpad);
1074 gst_aggregator_pad_set_flushing (GstAggregatorPad * aggpad,
1075 GstFlowReturn flow_return, gboolean full)
1080 if (flow_return == GST_FLOW_NOT_LINKED)
1081 aggpad->priv->flow_return = MIN (flow_return, aggpad->priv->flow_return);
1083 aggpad->priv->flow_return = flow_return;
1085 item = g_queue_peek_head_link (&aggpad->priv->data);
1087 GList *next = item->next;
1089 /* In partial flush, we do like the pad, we get rid of non-sticky events
1092 if (full || GST_IS_BUFFER (item->data) ||
1093 GST_EVENT_TYPE (item->data) == GST_EVENT_EOS ||
1094 GST_EVENT_TYPE (item->data) == GST_EVENT_SEGMENT ||
1095 !GST_EVENT_IS_STICKY (item->data)) {
1096 if (!GST_IS_QUERY (item->data))
1097 gst_mini_object_unref (item->data);
1098 g_queue_delete_link (&aggpad->priv->data, item);
1102 aggpad->priv->num_buffers = 0;
1103 gst_buffer_replace (&aggpad->priv->clipped_buffer, NULL);
1105 PAD_BROADCAST_EVENT (aggpad);
1106 PAD_UNLOCK (aggpad);
1109 static GstFlowReturn
1110 gst_aggregator_default_update_src_caps (GstAggregator * agg, GstCaps * caps,
1113 *ret = gst_caps_ref (caps);
1119 gst_aggregator_default_fixate_src_caps (GstAggregator * agg, GstCaps * caps)
1121 caps = gst_caps_fixate (caps);
1127 gst_aggregator_default_negotiated_src_caps (GstAggregator * agg, GstCaps * caps)
1133 /* takes ownership of the pool, allocator and query */
1135 gst_aggregator_set_allocation (GstAggregator * self,
1136 GstBufferPool * pool, GstAllocator * allocator,
1137 const GstAllocationParams * params, GstQuery * query)
1139 GstAllocator *oldalloc;
1140 GstBufferPool *oldpool;
1143 GST_DEBUG ("storing allocation query");
1145 GST_OBJECT_LOCK (self);
1146 oldpool = self->priv->pool;
1147 self->priv->pool = pool;
1149 oldalloc = self->priv->allocator;
1150 self->priv->allocator = allocator;
1152 oldquery = self->priv->allocation_query;
1153 self->priv->allocation_query = query;
1156 self->priv->allocation_params = *params;
1158 gst_allocation_params_init (&self->priv->allocation_params);
1159 GST_OBJECT_UNLOCK (self);
1162 GST_DEBUG_OBJECT (self, "deactivating old pool %p", oldpool);
1163 gst_buffer_pool_set_active (oldpool, FALSE);
1164 gst_object_unref (oldpool);
1167 gst_object_unref (oldalloc);
1170 gst_query_unref (oldquery);
1177 gst_aggregator_decide_allocation (GstAggregator * self, GstQuery * query)
1179 GstAggregatorClass *aggclass = GST_AGGREGATOR_GET_CLASS (self);
1181 if (aggclass->decide_allocation)
1182 if (!aggclass->decide_allocation (self, query))
1189 gst_aggregator_do_allocation (GstAggregator * self, GstCaps * caps)
1192 gboolean result = TRUE;
1193 GstBufferPool *pool = NULL;
1194 GstAllocator *allocator;
1195 GstAllocationParams params;
1197 /* find a pool for the negotiated caps now */
1198 GST_DEBUG_OBJECT (self, "doing allocation query");
1199 query = gst_query_new_allocation (caps, TRUE);
1200 if (!gst_pad_peer_query (self->srcpad, query)) {
1201 /* not a problem, just debug a little */
1202 GST_DEBUG_OBJECT (self, "peer ALLOCATION query failed");
1205 GST_DEBUG_OBJECT (self, "calling decide_allocation");
1206 result = gst_aggregator_decide_allocation (self, query);
1208 GST_DEBUG_OBJECT (self, "ALLOCATION (%d) params: %" GST_PTR_FORMAT, result,
1212 goto no_decide_allocation;
1214 /* we got configuration from our peer or the decide_allocation method,
1216 if (gst_query_get_n_allocation_params (query) > 0) {
1217 gst_query_parse_nth_allocation_param (query, 0, &allocator, ¶ms);
1220 gst_allocation_params_init (¶ms);
1223 if (gst_query_get_n_allocation_pools (query) > 0)
1224 gst_query_parse_nth_allocation_pool (query, 0, &pool, NULL, NULL, NULL);
1228 gst_aggregator_set_allocation (self, pool, allocator, ¶ms, query);
1233 no_decide_allocation:
1235 GST_WARNING_OBJECT (self, "Failed to decide allocation");
1236 gst_query_unref (query);
1244 gst_aggregator_default_negotiate (GstAggregator * self)
1246 GstAggregatorClass *agg_klass = GST_AGGREGATOR_GET_CLASS (self);
1247 GstCaps *downstream_caps, *template_caps, *caps = NULL;
1248 GstFlowReturn ret = GST_FLOW_OK;
1250 template_caps = gst_pad_get_pad_template_caps (self->srcpad);
1251 downstream_caps = gst_pad_peer_query_caps (self->srcpad, template_caps);
1253 if (gst_caps_is_empty (downstream_caps)) {
1254 GST_INFO_OBJECT (self, "Downstream caps (%"
1255 GST_PTR_FORMAT ") not compatible with pad template caps (%"
1256 GST_PTR_FORMAT ")", downstream_caps, template_caps);
1257 ret = GST_FLOW_NOT_NEGOTIATED;
1261 g_assert (agg_klass->update_src_caps);
1262 GST_DEBUG_OBJECT (self, "updating caps from %" GST_PTR_FORMAT,
1264 ret = agg_klass->update_src_caps (self, downstream_caps, &caps);
1265 if (ret < GST_FLOW_OK) {
1266 GST_WARNING_OBJECT (self, "Subclass failed to update provided caps");
1268 } else if (ret == GST_AGGREGATOR_FLOW_NEED_DATA) {
1269 GST_DEBUG_OBJECT (self, "Subclass needs more data to decide on caps");
1272 if ((caps == NULL || gst_caps_is_empty (caps)) && ret >= GST_FLOW_OK) {
1273 ret = GST_FLOW_NOT_NEGOTIATED;
1276 GST_DEBUG_OBJECT (self, " to %" GST_PTR_FORMAT, caps);
1278 #ifdef GST_ENABLE_EXTRA_CHECKS
1279 if (!gst_caps_is_subset (caps, template_caps)) {
1280 GstCaps *intersection;
1282 GST_ERROR_OBJECT (self,
1283 "update_src_caps returned caps %" GST_PTR_FORMAT
1284 " which are not a real subset of the template caps %"
1285 GST_PTR_FORMAT, caps, template_caps);
1286 g_warning ("%s: update_src_caps returned caps which are not a real "
1287 "subset of the filter caps", GST_ELEMENT_NAME (self));
1290 gst_caps_intersect_full (template_caps, caps, GST_CAPS_INTERSECT_FIRST);
1291 gst_caps_unref (caps);
1292 caps = intersection;
1296 if (gst_caps_is_any (caps)) {
1300 if (!gst_caps_is_fixed (caps)) {
1301 g_assert (agg_klass->fixate_src_caps);
1303 GST_DEBUG_OBJECT (self, "fixate caps from %" GST_PTR_FORMAT, caps);
1304 if (!(caps = agg_klass->fixate_src_caps (self, caps))) {
1305 GST_WARNING_OBJECT (self, "Subclass failed to fixate provided caps");
1306 ret = GST_FLOW_NOT_NEGOTIATED;
1309 GST_DEBUG_OBJECT (self, " to %" GST_PTR_FORMAT, caps);
1312 if (agg_klass->negotiated_src_caps) {
1313 if (!agg_klass->negotiated_src_caps (self, caps)) {
1314 GST_WARNING_OBJECT (self, "Subclass failed to accept negotiated caps");
1315 ret = GST_FLOW_NOT_NEGOTIATED;
1320 gst_aggregator_set_src_caps (self, caps);
1322 if (!gst_aggregator_do_allocation (self, caps)) {
1323 GST_WARNING_OBJECT (self, "Allocation negotiation failed");
1324 ret = GST_FLOW_NOT_NEGOTIATED;
1328 gst_caps_unref (downstream_caps);
1329 gst_caps_unref (template_caps);
1332 gst_caps_unref (caps);
1334 return ret >= GST_FLOW_OK || ret == GST_AGGREGATOR_FLOW_NEED_DATA;
1337 /* WITH SRC_LOCK held */
1339 gst_aggregator_negotiate_unlocked (GstAggregator * self)
1341 GstAggregatorClass *agg_klass = GST_AGGREGATOR_GET_CLASS (self);
1343 if (agg_klass->negotiate)
1344 return agg_klass->negotiate (self);
1350 * gst_aggregator_negotiate:
1351 * @self: a #GstAggregator
1353 * Negotiates src pad caps with downstream elements.
1354 * Unmarks GST_PAD_FLAG_NEED_RECONFIGURE in any case. But marks it again
1355 * if #GstAggregatorClass::negotiate fails.
1357 * Returns: %TRUE if the negotiation succeeded, else %FALSE.
1362 gst_aggregator_negotiate (GstAggregator * self)
1364 gboolean ret = TRUE;
1366 g_return_val_if_fail (GST_IS_AGGREGATOR (self), FALSE);
1368 GST_PAD_STREAM_LOCK (GST_AGGREGATOR_SRC_PAD (self));
1369 gst_pad_check_reconfigure (GST_AGGREGATOR_SRC_PAD (self));
1370 ret = gst_aggregator_negotiate_unlocked (self);
1372 gst_pad_mark_reconfigure (GST_AGGREGATOR_SRC_PAD (self));
1373 GST_PAD_STREAM_UNLOCK (GST_AGGREGATOR_SRC_PAD (self));
1379 gst_aggregator_aggregate_func (GstAggregator * self)
1381 GstAggregatorPrivate *priv = self->priv;
1382 GstAggregatorClass *klass = GST_AGGREGATOR_GET_CLASS (self);
1383 gboolean timeout = FALSE;
1385 if (self->priv->running == FALSE) {
1386 GST_DEBUG_OBJECT (self, "Not running anymore");
1390 GST_LOG_OBJECT (self, "Checking aggregate");
1391 while (priv->send_eos && priv->running) {
1392 GstFlowReturn flow_return = GST_FLOW_OK;
1393 DoHandleEventsAndQueriesData events_query_data = { FALSE, GST_FLOW_OK };
1395 gst_element_foreach_sink_pad (GST_ELEMENT_CAST (self),
1396 gst_aggregator_do_events_and_queries, &events_query_data);
1398 if ((flow_return = events_query_data.flow_ret) != GST_FLOW_OK)
1401 if (is_live_unlocked (self))
1402 gst_element_foreach_sink_pad (GST_ELEMENT_CAST (self),
1403 gst_aggregator_pad_skip_buffers, NULL);
1405 if (self->priv->got_eos_event) {
1406 gst_aggregator_push_eos (self);
1410 /* Ensure we have buffers ready (either in clipped_buffer or at the head of
1412 if (!gst_aggregator_wait_and_check (self, &timeout)) {
1413 gst_element_foreach_sink_pad (GST_ELEMENT_CAST (self),
1414 gst_aggregator_pad_reset_peeked_buffer, NULL);
1418 if (gst_pad_check_reconfigure (GST_AGGREGATOR_SRC_PAD (self))) {
1419 if (!gst_aggregator_negotiate_unlocked (self)) {
1420 gst_pad_mark_reconfigure (GST_AGGREGATOR_SRC_PAD (self));
1421 if (GST_PAD_IS_FLUSHING (GST_AGGREGATOR_SRC_PAD (self))) {
1422 flow_return = GST_FLOW_FLUSHING;
1424 flow_return = GST_FLOW_NOT_NEGOTIATED;
1429 if (timeout || flow_return >= GST_FLOW_OK) {
1430 GST_LOG_OBJECT (self, "Actually aggregating, timeout: %d", timeout);
1431 flow_return = klass->aggregate (self, timeout);
1434 gst_element_foreach_sink_pad (GST_ELEMENT_CAST (self),
1435 gst_aggregator_pad_reset_peeked_buffer, NULL);
1437 if (!priv->selected_samples_called_or_warned) {
1438 GST_FIXME_OBJECT (self,
1439 "Subclass should call gst_aggregator_selected_samples() from its "
1440 "aggregate implementation.");
1441 priv->selected_samples_called_or_warned = TRUE;
1444 if (flow_return == GST_AGGREGATOR_FLOW_NEED_DATA)
1447 GST_OBJECT_LOCK (self);
1448 if (flow_return == GST_FLOW_FLUSHING && priv->flushing) {
1449 /* We don't want to set the pads to flushing, but we want to
1450 * stop the thread, so just break here */
1451 GST_OBJECT_UNLOCK (self);
1454 GST_OBJECT_UNLOCK (self);
1456 if (flow_return == GST_FLOW_EOS || flow_return == GST_FLOW_ERROR) {
1457 gst_aggregator_push_eos (self);
1461 GST_LOG_OBJECT (self, "flow return is %s", gst_flow_get_name (flow_return));
1463 if (flow_return != GST_FLOW_OK) {
1466 GST_OBJECT_LOCK (self);
1467 for (item = GST_ELEMENT (self)->sinkpads; item; item = item->next) {
1468 GstAggregatorPad *aggpad = GST_AGGREGATOR_PAD (item->data);
1470 gst_aggregator_pad_set_flushing (aggpad, flow_return, TRUE);
1472 GST_OBJECT_UNLOCK (self);
1477 /* Pause the task here, the only ways to get here are:
1478 * 1) We're stopping, in which case the task is stopped anyway
1479 * 2) We got a flow error above, in which case it might take
1480 * some time to forward the flow return upstream and we
1481 * would otherwise call the task function over and over
1482 * again without doing anything
1484 gst_pad_pause_task (self->srcpad);
1488 gst_aggregator_start (GstAggregator * self)
1490 GstAggregatorClass *klass;
1493 self->priv->send_stream_start = TRUE;
1494 self->priv->send_segment = TRUE;
1495 self->priv->send_eos = TRUE;
1496 self->priv->got_eos_event = FALSE;
1497 self->priv->srccaps = NULL;
1499 self->priv->has_peer_latency = FALSE;
1500 self->priv->peer_latency_live = FALSE;
1501 self->priv->peer_latency_min = self->priv->peer_latency_max = 0;
1503 gst_aggregator_set_allocation (self, NULL, NULL, NULL, NULL);
1505 klass = GST_AGGREGATOR_GET_CLASS (self);
1508 result = klass->start (self);
1516 gst_aggregator_stop_srcpad_task (GstAggregator * self, GstEvent * flush_start)
1518 gboolean res = TRUE;
1520 GST_INFO_OBJECT (self, "%s srcpad task",
1521 flush_start ? "Pausing" : "Stopping");
1524 self->priv->running = FALSE;
1525 SRC_BROADCAST (self);
1529 res = gst_pad_push_event (self->srcpad, flush_start);
1532 gst_pad_stop_task (self->srcpad);
1538 gst_aggregator_start_srcpad_task (GstAggregator * self)
1540 GST_INFO_OBJECT (self, "Starting srcpad task");
1542 self->priv->running = TRUE;
1543 gst_pad_start_task (GST_PAD (self->srcpad),
1544 (GstTaskFunction) gst_aggregator_aggregate_func, self, NULL);
1547 static GstFlowReturn
1548 gst_aggregator_flush (GstAggregator * self)
1550 GstFlowReturn ret = GST_FLOW_OK;
1551 GstAggregatorPrivate *priv = self->priv;
1552 GstAggregatorClass *klass = GST_AGGREGATOR_GET_CLASS (self);
1554 GST_DEBUG_OBJECT (self, "Flushing everything");
1555 GST_OBJECT_LOCK (self);
1556 priv->send_segment = TRUE;
1557 priv->flushing = FALSE;
1558 priv->tags_changed = FALSE;
1559 GST_OBJECT_UNLOCK (self);
1561 ret = klass->flush (self);
1567 /* Called with GstAggregator's object lock held */
1570 gst_aggregator_all_flush_stop_received (GstAggregator * self, guint32 seqnum)
1573 GstAggregatorPad *tmppad;
1575 for (tmp = GST_ELEMENT (self)->sinkpads; tmp; tmp = tmp->next) {
1576 tmppad = (GstAggregatorPad *) tmp->data;
1578 if (tmppad->priv->last_flush_stop_seqnum != seqnum)
1585 /* Called with GstAggregator's object lock held */
1588 gst_aggregator_all_flush_start_received (GstAggregator * self, guint32 seqnum)
1591 GstAggregatorPad *tmppad;
1593 for (tmp = GST_ELEMENT (self)->sinkpads; tmp; tmp = tmp->next) {
1594 tmppad = (GstAggregatorPad *) tmp->data;
1596 if (tmppad->priv->last_flush_start_seqnum != seqnum) {
1605 gst_aggregator_flush_start (GstAggregator * self, GstAggregatorPad * aggpad,
1608 GstAggregatorPrivate *priv = self->priv;
1609 GstAggregatorPadPrivate *padpriv = aggpad->priv;
1610 guint32 seqnum = gst_event_get_seqnum (event);
1612 gst_aggregator_pad_set_flushing (aggpad, GST_FLOW_FLUSHING, FALSE);
1614 PAD_FLUSH_LOCK (aggpad);
1616 padpriv->last_flush_start_seqnum = seqnum;
1617 PAD_UNLOCK (aggpad);
1619 GST_OBJECT_LOCK (self);
1621 if (!priv->flushing && gst_aggregator_all_flush_start_received (self, seqnum)) {
1622 /* Make sure we don't forward more than one FLUSH_START */
1623 priv->flushing = TRUE;
1624 priv->next_seqnum = seqnum;
1625 GST_OBJECT_UNLOCK (self);
1627 GST_INFO_OBJECT (self, "Flushing, pausing srcpad task");
1628 gst_aggregator_stop_srcpad_task (self, event);
1632 gst_event_unref (event);
1633 GST_OBJECT_UNLOCK (self);
1636 PAD_FLUSH_UNLOCK (aggpad);
1639 /* Must be called with the PAD_LOCK and OBJECT_LOCK held */
1641 update_time_level (GstAggregatorPad * aggpad, gboolean head)
1643 GstAggregatorPadPrivate *priv = aggpad->priv;
1646 if (GST_CLOCK_TIME_IS_VALID (priv->head_position) &&
1647 priv->head_segment.format == GST_FORMAT_TIME)
1648 priv->head_time = gst_segment_to_running_time (&priv->head_segment,
1649 GST_FORMAT_TIME, priv->head_position);
1651 priv->head_time = GST_CLOCK_TIME_NONE;
1653 if (!GST_CLOCK_TIME_IS_VALID (priv->tail_time))
1654 priv->tail_time = priv->head_time;
1656 if (GST_CLOCK_TIME_IS_VALID (priv->tail_position) &&
1657 aggpad->segment.format == GST_FORMAT_TIME)
1658 priv->tail_time = gst_segment_to_running_time (&aggpad->segment,
1659 GST_FORMAT_TIME, priv->tail_position);
1661 priv->tail_time = priv->head_time;
1664 if (priv->head_time == GST_CLOCK_TIME_NONE ||
1665 priv->tail_time == GST_CLOCK_TIME_NONE) {
1666 priv->time_level = 0;
1670 if (priv->tail_time > priv->head_time)
1671 priv->time_level = 0;
1673 priv->time_level = priv->head_time - priv->tail_time;
1677 /* GstAggregator vmethods default implementations */
1679 gst_aggregator_default_sink_event (GstAggregator * self,
1680 GstAggregatorPad * aggpad, GstEvent * event)
1682 gboolean res = TRUE;
1683 GstPad *pad = GST_PAD (aggpad);
1684 GstAggregatorPrivate *priv = self->priv;
1686 GST_DEBUG_OBJECT (aggpad, "Got event: %" GST_PTR_FORMAT, event);
1688 switch (GST_EVENT_TYPE (event)) {
1689 case GST_EVENT_FLUSH_START:
1691 gst_aggregator_flush_start (self, aggpad, event);
1692 /* We forward only in one case: right after flushing */
1696 case GST_EVENT_FLUSH_STOP:
1698 guint32 seqnum = gst_event_get_seqnum (event);
1700 PAD_FLUSH_LOCK (aggpad);
1702 aggpad->priv->last_flush_stop_seqnum = seqnum;
1703 PAD_UNLOCK (aggpad);
1705 gst_aggregator_pad_flush (aggpad, self);
1707 GST_OBJECT_LOCK (self);
1709 && gst_aggregator_all_flush_stop_received (self, seqnum)) {
1710 GST_OBJECT_UNLOCK (self);
1711 /* That means we received FLUSH_STOP/FLUSH_STOP on
1712 * all sinkpads -- Seeking is Done... sending FLUSH_STOP */
1713 gst_aggregator_flush (self);
1714 gst_pad_push_event (self->srcpad, event);
1717 priv->send_eos = TRUE;
1718 priv->got_eos_event = FALSE;
1719 SRC_BROADCAST (self);
1722 GST_INFO_OBJECT (self, "Flush stopped");
1724 gst_aggregator_start_srcpad_task (self);
1726 GST_OBJECT_UNLOCK (self);
1729 PAD_FLUSH_UNLOCK (aggpad);
1731 /* We never forward the event */
1738 aggpad->priv->eos = TRUE;
1739 PAD_UNLOCK (aggpad);
1740 SRC_BROADCAST (self);
1744 case GST_EVENT_SEGMENT:
1747 GST_OBJECT_LOCK (aggpad);
1748 gst_event_copy_segment (event, &aggpad->segment);
1749 /* We've got a new segment, tail_position is now meaningless
1750 * and may interfere with the time_level calculation
1752 aggpad->priv->tail_position = GST_CLOCK_TIME_NONE;
1753 update_time_level (aggpad, FALSE);
1754 GST_OBJECT_UNLOCK (aggpad);
1755 PAD_UNLOCK (aggpad);
1757 GST_OBJECT_LOCK (self);
1758 self->priv->seqnum = gst_event_get_seqnum (event);
1759 GST_OBJECT_UNLOCK (self);
1762 case GST_EVENT_STREAM_START:
1765 aggpad->priv->eos = FALSE;
1766 PAD_UNLOCK (aggpad);
1771 GstClockTime pts, endpts;
1772 GstClockTime duration;
1774 GstGapFlags flags = 0;
1776 gst_event_parse_gap (event, &pts, &duration);
1778 if (GST_CLOCK_TIME_IS_VALID (duration))
1779 endpts = pts + duration;
1781 endpts = GST_CLOCK_TIME_NONE;
1783 GST_OBJECT_LOCK (aggpad);
1784 res = gst_segment_clip (&aggpad->segment, GST_FORMAT_TIME, pts, endpts,
1786 GST_OBJECT_UNLOCK (aggpad);
1789 GST_WARNING_OBJECT (self, "GAP event outside segment, dropping");
1793 if (GST_CLOCK_TIME_IS_VALID (endpts) && GST_CLOCK_TIME_IS_VALID (pts))
1794 duration = endpts - pts;
1796 duration = GST_CLOCK_TIME_NONE;
1798 gapbuf = gst_buffer_new ();
1799 GST_BUFFER_PTS (gapbuf) = pts;
1800 GST_BUFFER_DURATION (gapbuf) = duration;
1801 GST_BUFFER_FLAG_SET (gapbuf, GST_BUFFER_FLAG_GAP);
1802 GST_BUFFER_FLAG_SET (gapbuf, GST_BUFFER_FLAG_DROPPABLE);
1804 gst_event_parse_gap_flags (event, &flags);
1805 if (flags & GST_GAP_FLAG_MISSING_DATA) {
1806 gst_buffer_add_custom_meta (gapbuf, "GstAggregatorMissingDataMeta");
1809 /* Remove GAP event so we can replace it with the buffer */
1811 if (g_queue_peek_tail (&aggpad->priv->data) == event)
1812 gst_event_unref (g_queue_pop_tail (&aggpad->priv->data));
1813 PAD_UNLOCK (aggpad);
1815 if (gst_aggregator_pad_chain_internal (self, aggpad, gapbuf, FALSE) !=
1817 GST_WARNING_OBJECT (self, "Failed to chain gap buffer");
1831 GST_DEBUG_OBJECT (pad, "Forwarding event: %" GST_PTR_FORMAT, event);
1832 return gst_pad_event_default (pad, GST_OBJECT (self), event);
1835 GST_DEBUG_OBJECT (pad, "Eating event: %" GST_PTR_FORMAT, event);
1837 gst_event_unref (event);
1842 /* Queue serialized events and let the others go through directly.
1843 * The queued events with be handled from the src-pad task in
1844 * gst_aggregator_do_events_and_queries().
1846 static GstFlowReturn
1847 gst_aggregator_default_sink_event_pre_queue (GstAggregator * self,
1848 GstAggregatorPad * aggpad, GstEvent * event)
1850 GstFlowReturn ret = GST_FLOW_OK;
1852 if (GST_EVENT_IS_SERIALIZED (event)
1853 && GST_EVENT_TYPE (event) != GST_EVENT_FLUSH_STOP) {
1857 if (aggpad->priv->flow_return != GST_FLOW_OK)
1860 if (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) {
1861 GST_OBJECT_LOCK (aggpad);
1862 gst_event_copy_segment (event, &aggpad->priv->head_segment);
1863 aggpad->priv->head_position = aggpad->priv->head_segment.position;
1864 update_time_level (aggpad, TRUE);
1865 GST_OBJECT_UNLOCK (aggpad);
1868 GST_DEBUG_OBJECT (aggpad, "Store event in queue: %" GST_PTR_FORMAT, event);
1869 g_queue_push_head (&aggpad->priv->data, event);
1870 SRC_BROADCAST (self);
1871 PAD_UNLOCK (aggpad);
1874 GstAggregatorClass *klass = GST_AGGREGATOR_GET_CLASS (self);
1876 if (!klass->sink_event (self, aggpad, event)) {
1877 /* Copied from GstPad to convert boolean to a GstFlowReturn in
1878 * the event handling func */
1879 ret = GST_FLOW_ERROR;
1886 GST_DEBUG_OBJECT (aggpad, "Pad is %s, dropping event",
1887 gst_flow_get_name (aggpad->priv->flow_return));
1888 PAD_UNLOCK (aggpad);
1890 if (GST_EVENT_IS_STICKY (event))
1891 gst_pad_store_sticky_event (GST_PAD (aggpad), event);
1892 gst_event_unref (event);
1894 return aggpad->priv->flow_return;
1898 gst_aggregator_stop_pad (GstElement * self, GstPad * epad, gpointer user_data)
1900 GstAggregatorPad *pad = GST_AGGREGATOR_PAD_CAST (epad);
1901 GstAggregator *agg = GST_AGGREGATOR_CAST (self);
1903 gst_aggregator_pad_flush (pad, agg);
1906 pad->priv->flow_return = GST_FLOW_FLUSHING;
1907 pad->priv->negotiated = FALSE;
1908 PAD_BROADCAST_EVENT (pad);
1915 gst_aggregator_stop (GstAggregator * agg)
1917 GstAggregatorClass *klass;
1920 gst_aggregator_reset_flow_values (agg);
1922 /* Application needs to make sure no pads are added while it shuts us down */
1923 gst_element_foreach_sink_pad (GST_ELEMENT_CAST (agg),
1924 gst_aggregator_stop_pad, NULL);
1926 klass = GST_AGGREGATOR_GET_CLASS (agg);
1929 result = klass->stop (agg);
1933 agg->priv->has_peer_latency = FALSE;
1934 agg->priv->peer_latency_live = FALSE;
1935 agg->priv->peer_latency_min = agg->priv->peer_latency_max = 0;
1936 agg->priv->posted_latency_msg = FALSE;
1938 if (agg->priv->tags)
1939 gst_tag_list_unref (agg->priv->tags);
1940 agg->priv->tags = NULL;
1942 gst_aggregator_set_allocation (agg, NULL, NULL, NULL, NULL);
1944 if (agg->priv->running) {
1945 /* As sinkpads get deactivated after the src pad, we
1946 * may have restarted the source pad task after receiving
1947 * flush events on one of our sinkpads. Stop our src pad
1948 * task again if that is the case */
1949 gst_aggregator_stop_srcpad_task (agg, NULL);
1955 /* GstElement vmethods implementations */
1956 static GstStateChangeReturn
1957 gst_aggregator_change_state (GstElement * element, GstStateChange transition)
1959 GstStateChangeReturn ret;
1960 GstAggregator *self = GST_AGGREGATOR (element);
1962 switch (transition) {
1963 case GST_STATE_CHANGE_READY_TO_PAUSED:
1964 if (!gst_aggregator_start (self))
1967 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
1968 /* Wake up any waiting as now we have a clock and can do
1969 * proper waiting on the clock if necessary */
1971 SRC_BROADCAST (self);
1979 GST_ELEMENT_CLASS (aggregator_parent_class)->change_state (element,
1980 transition)) == GST_STATE_CHANGE_FAILURE)
1984 switch (transition) {
1985 case GST_STATE_CHANGE_PAUSED_TO_READY:
1986 if (!gst_aggregator_stop (self)) {
1987 /* What to do in this case? Error out? */
1988 GST_ERROR_OBJECT (self, "Subclass failed to stop.");
1991 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
1992 /* Wake up any waiting as now clock might be gone and we might
1993 * need to wait on the condition variable again */
1995 SRC_BROADCAST (self);
1997 if (self->priv->force_live) {
1998 ret = GST_STATE_CHANGE_NO_PREROLL;
2001 case GST_STATE_CHANGE_READY_TO_PAUSED:
2002 if (self->priv->force_live) {
2003 ret = GST_STATE_CHANGE_NO_PREROLL;
2015 GST_ERROR_OBJECT (element, "parent failed state change");
2020 GST_ERROR_OBJECT (element, "Subclass failed to start");
2021 return GST_STATE_CHANGE_FAILURE;
2026 gst_aggregator_release_pad (GstElement * element, GstPad * pad)
2028 GstAggregator *self = GST_AGGREGATOR (element);
2029 GstAggregatorPad *aggpad = GST_AGGREGATOR_PAD (pad);
2031 GST_INFO_OBJECT (pad, "Removing pad");
2034 gst_aggregator_pad_set_flushing (aggpad, GST_FLOW_FLUSHING, TRUE);
2036 gst_buffer_replace (&aggpad->priv->peeked_buffer, NULL);
2037 gst_buffer_replace (&aggpad->priv->clipped_buffer, NULL);
2038 PAD_UNLOCK (aggpad);
2039 gst_element_remove_pad (element, pad);
2041 self->priv->has_peer_latency = FALSE;
2042 SRC_BROADCAST (self);
2046 static GstAggregatorPad *
2047 gst_aggregator_default_create_new_pad (GstAggregator * self,
2048 GstPadTemplate * templ, const gchar * req_name, const GstCaps * caps)
2050 GstAggregatorPad *agg_pad;
2051 GstAggregatorPrivate *priv = self->priv;
2055 GST_PAD_TEMPLATE_GTYPE (templ) ==
2056 G_TYPE_NONE ? GST_TYPE_AGGREGATOR_PAD : GST_PAD_TEMPLATE_GTYPE (templ);
2058 if (templ->direction != GST_PAD_SINK)
2061 if (templ->presence != GST_PAD_REQUEST)
2064 GST_OBJECT_LOCK (self);
2065 if (req_name == NULL || strlen (req_name) < 6
2066 || !g_str_has_prefix (req_name, "sink_")
2067 || strrchr (req_name, '%') != NULL) {
2068 /* no name given when requesting the pad, use next available int */
2069 serial = ++priv->max_padserial;
2071 gchar *endptr = NULL;
2073 /* parse serial number from requested padname */
2074 serial = g_ascii_strtoull (&req_name[5], &endptr, 10);
2075 if (endptr != NULL && *endptr == '\0') {
2076 if (serial > priv->max_padserial) {
2077 priv->max_padserial = serial;
2080 serial = ++priv->max_padserial;
2084 name = g_strdup_printf ("sink_%u", serial);
2085 g_assert (g_type_is_a (pad_type, GST_TYPE_AGGREGATOR_PAD));
2086 agg_pad = g_object_new (pad_type,
2087 "name", name, "direction", GST_PAD_SINK, "template", templ, NULL);
2090 GST_OBJECT_UNLOCK (self);
2097 GST_WARNING_OBJECT (self, "request new pad that is not a SINK pad");
2102 GST_WARNING_OBJECT (self, "request new pad that is not a REQUEST pad");
2108 gst_aggregator_request_new_pad (GstElement * element,
2109 GstPadTemplate * templ, const gchar * req_name, const GstCaps * caps)
2111 GstAggregator *self;
2112 GstAggregatorPad *agg_pad;
2113 GstAggregatorClass *klass = GST_AGGREGATOR_GET_CLASS (element);
2114 GstAggregatorPrivate *priv = GST_AGGREGATOR (element)->priv;
2116 self = GST_AGGREGATOR (element);
2118 agg_pad = klass->create_new_pad (self, templ, req_name, caps);
2120 GST_ERROR_OBJECT (element, "Couldn't create new pad");
2124 GST_DEBUG_OBJECT (element, "Adding pad %s", GST_PAD_NAME (agg_pad));
2127 gst_pad_set_active (GST_PAD (agg_pad), TRUE);
2129 /* add the pad to the element */
2130 gst_element_add_pad (element, GST_PAD (agg_pad));
2132 return GST_PAD (agg_pad);
2135 /* Must be called with SRC_LOCK held, temporarily releases it! */
2138 gst_aggregator_query_latency_unlocked (GstAggregator * self, GstQuery * query)
2140 gboolean query_ret, live;
2141 GstClockTime our_latency, min, max;
2143 /* Temporarily release the lock to do the query. */
2145 query_ret = gst_pad_query_default (self->srcpad, GST_OBJECT (self), query);
2149 GST_WARNING_OBJECT (self, "Latency query failed");
2153 gst_query_parse_latency (query, &live, &min, &max);
2155 if (G_UNLIKELY (!GST_CLOCK_TIME_IS_VALID (min))) {
2156 GST_ERROR_OBJECT (self, "Invalid minimum latency %" GST_TIME_FORMAT
2157 ". Please file a bug at " PACKAGE_BUGREPORT ".", GST_TIME_ARGS (min));
2161 if (self->priv->upstream_latency_min > min) {
2162 GstClockTimeDiff diff =
2163 GST_CLOCK_DIFF (min, self->priv->upstream_latency_min);
2166 if (GST_CLOCK_TIME_IS_VALID (max)) {
2171 if (min > max && GST_CLOCK_TIME_IS_VALID (max)) {
2173 GST_ELEMENT_WARNING (self, CORE, CLOCK, (NULL),
2174 ("Impossible to configure latency: max %" GST_TIME_FORMAT " < min %"
2175 GST_TIME_FORMAT ". Add queues or other buffering elements.",
2176 GST_TIME_ARGS (max), GST_TIME_ARGS (min)));
2181 our_latency = self->priv->latency;
2183 self->priv->peer_latency_live = live;
2184 self->priv->peer_latency_min = min;
2185 self->priv->peer_latency_max = max;
2186 self->priv->has_peer_latency = TRUE;
2190 min += self->priv->sub_latency_min;
2191 if (GST_CLOCK_TIME_IS_VALID (self->priv->sub_latency_max)
2192 && GST_CLOCK_TIME_IS_VALID (max))
2193 max += self->priv->sub_latency_max + our_latency;
2195 max = GST_CLOCK_TIME_NONE;
2197 SRC_BROADCAST (self);
2199 GST_DEBUG_OBJECT (self, "configured latency live:%s min:%" G_GINT64_FORMAT
2200 " max:%" G_GINT64_FORMAT, live ? "true" : "false", min, max);
2202 gst_query_set_latency (query, live, min, max);
2208 * MUST be called with the src_lock held. Temporarily releases the lock inside
2209 * gst_aggregator_query_latency_unlocked() to do the actual query!
2211 * See gst_aggregator_get_latency() for doc
2214 gst_aggregator_get_latency_unlocked (GstAggregator * self)
2216 GstClockTime latency;
2218 g_return_val_if_fail (GST_IS_AGGREGATOR (self), 0);
2220 if (!self->priv->has_peer_latency) {
2221 GstQuery *query = gst_query_new_latency ();
2224 ret = gst_aggregator_query_latency_unlocked (self, query);
2225 gst_query_unref (query);
2226 /* If we've been set to live, we don't wait for a peer latency, we will
2227 * simply query it again next time around */
2228 if (!ret && !self->priv->force_live)
2229 return GST_CLOCK_TIME_NONE;
2232 /* If we've been set to live, we don't wait for a peer latency, we will
2233 * simply query it again next time around */
2234 if (!self->priv->force_live) {
2235 if (!self->priv->has_peer_latency || !self->priv->peer_latency_live)
2236 return GST_CLOCK_TIME_NONE;
2239 /* latency_min is never GST_CLOCK_TIME_NONE by construction */
2240 latency = self->priv->peer_latency_min;
2243 latency += self->priv->latency;
2244 latency += self->priv->sub_latency_min;
2250 * gst_aggregator_get_latency:
2251 * @self: a #GstAggregator
2253 * Retrieves the latency values reported by @self in response to the latency
2254 * query, or %GST_CLOCK_TIME_NONE if there is not live source connected and the element
2255 * will not wait for the clock.
2257 * Typically only called by subclasses.
2259 * Returns: The latency or %GST_CLOCK_TIME_NONE if the element does not sync
2262 gst_aggregator_get_latency (GstAggregator * self)
2267 ret = gst_aggregator_get_latency_unlocked (self);
2274 gst_aggregator_send_event (GstElement * element, GstEvent * event)
2276 GstAggregator *self = GST_AGGREGATOR (element);
2278 GST_STATE_LOCK (element);
2279 if (GST_EVENT_TYPE (event) == GST_EVENT_SEEK &&
2280 GST_STATE (element) < GST_STATE_PAUSED) {
2284 GstSeekType start_type, stop_type;
2287 gst_event_parse_seek (event, &rate, &fmt, &flags, &start_type,
2288 &start, &stop_type, &stop);
2290 GST_OBJECT_LOCK (self);
2291 gst_segment_do_seek (&GST_AGGREGATOR_PAD (self->srcpad)->segment, rate, fmt,
2292 flags, start_type, start, stop_type, stop, NULL);
2293 self->priv->next_seqnum = gst_event_get_seqnum (event);
2294 self->priv->first_buffer = FALSE;
2295 GST_OBJECT_UNLOCK (self);
2297 GST_DEBUG_OBJECT (element, "Storing segment %" GST_PTR_FORMAT, event);
2300 GST_STATE_UNLOCK (element);
2303 if (GST_EVENT_TYPE (event) == GST_EVENT_EOS) {
2305 self->priv->got_eos_event = TRUE;
2306 SRC_BROADCAST (self);
2310 return GST_ELEMENT_CLASS (aggregator_parent_class)->send_event (element,
2315 gst_aggregator_default_src_query (GstAggregator * self, GstQuery * query)
2317 gboolean res = TRUE;
2319 switch (GST_QUERY_TYPE (query)) {
2320 case GST_QUERY_SEEKING:
2324 /* don't pass it along as some (file)sink might claim it does
2325 * whereas with a collectpads in between that will not likely work */
2326 gst_query_parse_seeking (query, &format, NULL, NULL, NULL);
2327 gst_query_set_seeking (query, format, FALSE, 0, -1);
2332 case GST_QUERY_LATENCY:
2334 res = gst_aggregator_query_latency_unlocked (self, query);
2338 return gst_pad_query_default (self->srcpad, GST_OBJECT (self), query);
2345 gst_aggregator_event_forward_func (GstPad * pad, gpointer user_data)
2347 EventData *evdata = user_data;
2348 gboolean ret = TRUE;
2349 GstPad *peer = gst_pad_get_peer (pad);
2350 GstAggregatorPad *aggpad = GST_AGGREGATOR_PAD (pad);
2353 if (evdata->only_to_active_pads && aggpad->priv->first_buffer) {
2354 GST_DEBUG_OBJECT (pad, "not sending event to inactive pad");
2357 ret = gst_pad_send_event (peer, gst_event_ref (evdata->event));
2358 GST_DEBUG_OBJECT (pad, "return of event push is %d", ret);
2363 if (GST_EVENT_TYPE (evdata->event) == GST_EVENT_SEEK) {
2364 GstQuery *seeking = gst_query_new_seeking (GST_FORMAT_TIME);
2366 GST_DEBUG_OBJECT (pad, "Event %" GST_PTR_FORMAT " failed", evdata->event);
2368 if (gst_pad_query (peer, seeking)) {
2371 gst_query_parse_seeking (seeking, NULL, &seekable, NULL, NULL);
2373 if (seekable == FALSE) {
2374 GST_INFO_OBJECT (pad,
2375 "Source not seekable, We failed but it does not matter!");
2380 GST_ERROR_OBJECT (pad, "Query seeking FAILED");
2383 gst_query_unref (seeking);
2386 evdata->one_actually_seeked = TRUE;
2389 evdata->result &= ret;
2392 gst_object_unref (peer);
2394 /* Always send to all pads */
2399 gst_aggregator_forward_event_to_all_sinkpads (GstAggregator * self,
2402 evdata->result = TRUE;
2403 evdata->one_actually_seeked = FALSE;
2405 gst_pad_forward (self->srcpad, gst_aggregator_event_forward_func, evdata);
2407 gst_event_unref (evdata->event);
2411 gst_aggregator_do_seek (GstAggregator * self, GstEvent * event)
2416 GstSeekType start_type, stop_type;
2419 EventData evdata = { 0, };
2420 GstAggregatorPrivate *priv = self->priv;
2422 gst_event_parse_seek (event, &rate, &fmt, &flags, &start_type,
2423 &start, &stop_type, &stop);
2425 GST_INFO_OBJECT (self, "starting SEEK");
2427 flush = flags & GST_SEEK_FLAG_FLUSH;
2429 GST_OBJECT_LOCK (self);
2431 if (gst_event_get_seqnum (event) == self->priv->next_seqnum) {
2432 evdata.result = TRUE;
2433 GST_DEBUG_OBJECT (self, "Dropping duplicated seek event with seqnum %d",
2434 self->priv->next_seqnum);
2435 GST_OBJECT_UNLOCK (self);
2439 self->priv->next_seqnum = gst_event_get_seqnum (event);
2441 gst_segment_do_seek (&GST_AGGREGATOR_PAD (self->srcpad)->segment, rate, fmt,
2442 flags, start_type, start, stop_type, stop, NULL);
2444 /* Seeking sets a position */
2445 self->priv->first_buffer = FALSE;
2448 priv->flushing = TRUE;
2450 GST_OBJECT_UNLOCK (self);
2453 GstEvent *event = gst_event_new_flush_start ();
2455 gst_event_set_seqnum (event, self->priv->next_seqnum);
2456 gst_aggregator_stop_srcpad_task (self, event);
2459 /* forward the seek upstream */
2460 evdata.event = event;
2461 evdata.flush = flush;
2462 evdata.only_to_active_pads = FALSE;
2463 gst_aggregator_forward_event_to_all_sinkpads (self, &evdata);
2466 if (!evdata.result || !evdata.one_actually_seeked) {
2467 GST_OBJECT_LOCK (self);
2468 priv->flushing = FALSE;
2469 GST_OBJECT_UNLOCK (self);
2471 /* No flush stop is inbound for us to forward */
2473 GstEvent *event = gst_event_new_flush_stop (TRUE);
2475 gst_event_set_seqnum (event, self->priv->next_seqnum);
2476 gst_pad_push_event (self->srcpad, event);
2481 GST_INFO_OBJECT (self, "seek done, result: %d", evdata.result);
2483 return evdata.result;
2487 gst_aggregator_default_src_event (GstAggregator * self, GstEvent * event)
2489 EventData evdata = { 0, };
2491 switch (GST_EVENT_TYPE (event)) {
2492 case GST_EVENT_SEEK:
2493 /* _do_seek() unrefs the event. */
2494 return gst_aggregator_do_seek (self, event);
2495 case GST_EVENT_NAVIGATION:
2496 /* specific handling has to be implemented in subclasses */
2497 gst_event_unref (event);
2499 case GST_EVENT_RECONFIGURE:
2500 /* We will renegotiate with downstream, we don't
2501 * need to forward this further */
2502 gst_event_unref (event);
2508 /* Don't forward QOS events to pads that had no active buffer yet. Otherwise
2509 * they will receive a QOS event that has earliest_time=0 (because we can't
2510 * have negative timestamps), and consider their buffer as too late */
2511 evdata.event = event;
2512 evdata.flush = FALSE;
2513 evdata.only_to_active_pads = GST_EVENT_TYPE (event) == GST_EVENT_QOS;
2514 gst_aggregator_forward_event_to_all_sinkpads (self, &evdata);
2515 return evdata.result;
2519 gst_aggregator_src_pad_event_func (GstPad * pad, GstObject * parent,
2522 GstAggregatorClass *klass = GST_AGGREGATOR_GET_CLASS (parent);
2524 return klass->src_event (GST_AGGREGATOR (parent), event);
2528 gst_aggregator_src_pad_query_func (GstPad * pad, GstObject * parent,
2531 GstAggregatorClass *klass = GST_AGGREGATOR_GET_CLASS (parent);
2533 return klass->src_query (GST_AGGREGATOR (parent), query);
2537 gst_aggregator_src_pad_activate_mode_func (GstPad * pad,
2538 GstObject * parent, GstPadMode mode, gboolean active)
2540 GstAggregator *self = GST_AGGREGATOR (parent);
2541 GstAggregatorClass *klass = GST_AGGREGATOR_GET_CLASS (parent);
2543 if (klass->src_activate) {
2544 if (klass->src_activate (self, mode, active) == FALSE) {
2549 if (active == TRUE) {
2551 case GST_PAD_MODE_PUSH:
2553 GST_INFO_OBJECT (pad, "Activating pad!");
2554 gst_aggregator_start_srcpad_task (self);
2559 GST_ERROR_OBJECT (pad, "Only supported mode is PUSH");
2566 GST_INFO_OBJECT (self, "Deactivating srcpad");
2568 gst_aggregator_stop_srcpad_task (self, FALSE);
2574 gst_aggregator_default_sink_query (GstAggregator * self,
2575 GstAggregatorPad * aggpad, GstQuery * query)
2577 GstPad *pad = GST_PAD (aggpad);
2579 if (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION) {
2580 GstQuery *decide_query = NULL;
2581 GstAggregatorClass *agg_class;
2584 GST_OBJECT_LOCK (self);
2586 if (G_UNLIKELY (!aggpad->priv->negotiated)) {
2587 GST_DEBUG_OBJECT (self,
2588 "not negotiated yet, can't answer ALLOCATION query");
2589 PAD_UNLOCK (aggpad);
2590 GST_OBJECT_UNLOCK (self);
2595 if ((decide_query = self->priv->allocation_query))
2596 gst_query_ref (decide_query);
2597 PAD_UNLOCK (aggpad);
2598 GST_OBJECT_UNLOCK (self);
2600 GST_DEBUG_OBJECT (self,
2601 "calling propose allocation with query %" GST_PTR_FORMAT, decide_query);
2603 agg_class = GST_AGGREGATOR_GET_CLASS (self);
2605 /* pass the query to the propose_allocation vmethod if any */
2606 if (agg_class->propose_allocation)
2607 ret = agg_class->propose_allocation (self, aggpad, decide_query, query);
2612 gst_query_unref (decide_query);
2614 GST_DEBUG_OBJECT (self, "ALLOCATION ret %d, %" GST_PTR_FORMAT, ret, query);
2618 return gst_pad_query_default (pad, GST_OBJECT (self), query);
2622 gst_aggregator_default_sink_query_pre_queue (GstAggregator * self,
2623 GstAggregatorPad * aggpad, GstQuery * query)
2625 if (GST_QUERY_IS_SERIALIZED (query)) {
2627 gboolean ret = FALSE;
2632 if (aggpad->priv->flow_return != GST_FLOW_OK) {
2637 g_queue_push_head (&aggpad->priv->data, query);
2638 SRC_BROADCAST (self);
2641 while (!gst_aggregator_pad_queue_is_empty (aggpad)
2642 && aggpad->priv->flow_return == GST_FLOW_OK) {
2643 GST_DEBUG_OBJECT (aggpad, "Waiting for buffer to be consumed");
2644 PAD_WAIT_EVENT (aggpad);
2647 s = gst_query_writable_structure (query);
2648 if (gst_structure_get_boolean (s, "gst-aggregator-retval", &ret))
2649 gst_structure_remove_field (s, "gst-aggregator-retval");
2651 g_queue_remove (&aggpad->priv->data, query);
2653 if (aggpad->priv->flow_return != GST_FLOW_OK)
2656 PAD_UNLOCK (aggpad);
2660 GstAggregatorClass *klass = GST_AGGREGATOR_GET_CLASS (self);
2662 return klass->sink_query (self, aggpad, query);
2666 GST_DEBUG_OBJECT (aggpad, "Pad is %s, dropping query",
2667 gst_flow_get_name (aggpad->priv->flow_return));
2668 PAD_UNLOCK (aggpad);
2674 gst_aggregator_constructed (GObject * object)
2676 GstAggregator *agg = GST_AGGREGATOR (object);
2678 if (agg->priv->force_live) {
2679 GST_OBJECT_FLAG_SET (agg, GST_ELEMENT_FLAG_SOURCE);
2684 gst_aggregator_finalize (GObject * object)
2686 GstAggregator *self = (GstAggregator *) object;
2688 g_mutex_clear (&self->priv->src_lock);
2689 g_cond_clear (&self->priv->src_cond);
2691 G_OBJECT_CLASS (aggregator_parent_class)->finalize (object);
2695 * gst_aggregator_set_latency_property:
2696 * @agg: a #GstAggregator
2697 * @latency: the new latency value (in nanoseconds).
2699 * Sets the new latency value to @latency. This value is used to limit the
2700 * amount of time a pad waits for data to appear before considering the pad
2704 gst_aggregator_set_latency_property (GstAggregator * self, GstClockTime latency)
2708 g_return_if_fail (GST_IS_AGGREGATOR (self));
2709 g_return_if_fail (GST_CLOCK_TIME_IS_VALID (latency));
2712 changed = (self->priv->latency != latency);
2717 GST_OBJECT_LOCK (self);
2718 /* First lock all the pads */
2719 for (item = GST_ELEMENT_CAST (self)->sinkpads; item; item = item->next) {
2720 GstAggregatorPad *aggpad = GST_AGGREGATOR_PAD (item->data);
2724 self->priv->latency = latency;
2726 SRC_BROADCAST (self);
2728 /* Now wake up the pads */
2729 for (item = GST_ELEMENT_CAST (self)->sinkpads; item; item = item->next) {
2730 GstAggregatorPad *aggpad = GST_AGGREGATOR_PAD (item->data);
2731 PAD_BROADCAST_EVENT (aggpad);
2732 PAD_UNLOCK (aggpad);
2734 GST_OBJECT_UNLOCK (self);
2740 gst_element_post_message (GST_ELEMENT_CAST (self),
2741 gst_message_new_latency (GST_OBJECT_CAST (self)));
2745 * gst_aggregator_get_latency_property:
2746 * @agg: a #GstAggregator
2748 * Gets the latency value. See gst_aggregator_set_latency for
2751 * Returns: The time in nanoseconds to wait for data to arrive on a sink pad
2752 * before a pad is deemed unresponsive. A value of -1 means an
2756 gst_aggregator_get_latency_property (GstAggregator * agg)
2760 g_return_val_if_fail (GST_IS_AGGREGATOR (agg), GST_CLOCK_TIME_NONE);
2762 GST_OBJECT_LOCK (agg);
2763 res = agg->priv->latency;
2764 GST_OBJECT_UNLOCK (agg);
2770 gst_aggregator_set_property (GObject * object, guint prop_id,
2771 const GValue * value, GParamSpec * pspec)
2773 GstAggregator *agg = GST_AGGREGATOR (object);
2777 gst_aggregator_set_latency_property (agg, g_value_get_uint64 (value));
2779 case PROP_MIN_UPSTREAM_LATENCY:
2781 agg->priv->upstream_latency_min = g_value_get_uint64 (value);
2784 case PROP_START_TIME_SELECTION:
2785 agg->priv->start_time_selection = g_value_get_enum (value);
2787 case PROP_START_TIME:
2788 agg->priv->start_time = g_value_get_uint64 (value);
2790 case PROP_EMIT_SIGNALS:
2791 agg->priv->emit_signals = g_value_get_boolean (value);
2794 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2800 gst_aggregator_get_property (GObject * object, guint prop_id,
2801 GValue * value, GParamSpec * pspec)
2803 GstAggregator *agg = GST_AGGREGATOR (object);
2807 g_value_set_uint64 (value, gst_aggregator_get_latency_property (agg));
2809 case PROP_MIN_UPSTREAM_LATENCY:
2811 g_value_set_uint64 (value, agg->priv->upstream_latency_min);
2814 case PROP_START_TIME_SELECTION:
2815 g_value_set_enum (value, agg->priv->start_time_selection);
2817 case PROP_START_TIME:
2818 g_value_set_uint64 (value, agg->priv->start_time);
2820 case PROP_EMIT_SIGNALS:
2821 g_value_set_boolean (value, agg->priv->emit_signals);
2824 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2829 /* GObject vmethods implementations */
2831 gst_aggregator_class_init (GstAggregatorClass * klass)
2833 GObjectClass *gobject_class = (GObjectClass *) klass;
2834 GstElementClass *gstelement_class = (GstElementClass *) klass;
2835 static const gchar *meta_tags[] = { NULL };
2837 aggregator_parent_class = g_type_class_peek_parent (klass);
2839 GST_DEBUG_CATEGORY_INIT (aggregator_debug, "aggregator",
2840 GST_DEBUG_FG_MAGENTA, "GstAggregator");
2842 if (aggregator_private_offset != 0)
2843 g_type_class_adjust_private_offset (klass, &aggregator_private_offset);
2845 klass->finish_buffer = gst_aggregator_default_finish_buffer;
2846 klass->finish_buffer_list = gst_aggregator_default_finish_buffer_list;
2848 klass->sink_event = gst_aggregator_default_sink_event;
2849 klass->sink_query = gst_aggregator_default_sink_query;
2851 klass->src_event = gst_aggregator_default_src_event;
2852 klass->src_query = gst_aggregator_default_src_query;
2854 klass->create_new_pad = gst_aggregator_default_create_new_pad;
2855 klass->update_src_caps = gst_aggregator_default_update_src_caps;
2856 klass->fixate_src_caps = gst_aggregator_default_fixate_src_caps;
2857 klass->negotiated_src_caps = gst_aggregator_default_negotiated_src_caps;
2859 klass->negotiate = gst_aggregator_default_negotiate;
2861 klass->sink_event_pre_queue = gst_aggregator_default_sink_event_pre_queue;
2862 klass->sink_query_pre_queue = gst_aggregator_default_sink_query_pre_queue;
2864 gstelement_class->request_new_pad =
2865 GST_DEBUG_FUNCPTR (gst_aggregator_request_new_pad);
2866 gstelement_class->send_event = GST_DEBUG_FUNCPTR (gst_aggregator_send_event);
2867 gstelement_class->release_pad =
2868 GST_DEBUG_FUNCPTR (gst_aggregator_release_pad);
2869 gstelement_class->change_state =
2870 GST_DEBUG_FUNCPTR (gst_aggregator_change_state);
2872 gobject_class->set_property = gst_aggregator_set_property;
2873 gobject_class->get_property = gst_aggregator_get_property;
2874 gobject_class->constructed = gst_aggregator_constructed;
2875 gobject_class->finalize = gst_aggregator_finalize;
2877 g_object_class_install_property (gobject_class, PROP_LATENCY,
2878 g_param_spec_uint64 ("latency", "Buffer latency",
2879 "Additional latency in live mode to allow upstream "
2880 "to take longer to produce buffers for the current "
2881 "position (in nanoseconds)", 0, G_MAXUINT64,
2882 DEFAULT_LATENCY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2885 * GstAggregator:min-upstream-latency:
2887 * Force minimum upstream latency (in nanoseconds). When sources with a
2888 * higher latency are expected to be plugged in dynamically after the
2889 * aggregator has started playing, this allows overriding the minimum
2890 * latency reported by the initial source(s). This is only taken into
2891 * account when larger than the actually reported minimum latency.
2895 g_object_class_install_property (gobject_class, PROP_MIN_UPSTREAM_LATENCY,
2896 g_param_spec_uint64 ("min-upstream-latency", "Buffer latency",
2897 "When sources with a higher latency are expected to be plugged "
2898 "in dynamically after the aggregator has started playing, "
2899 "this allows overriding the minimum latency reported by the "
2900 "initial source(s). This is only taken into account when larger "
2901 "than the actually reported minimum latency. (nanoseconds)",
2903 DEFAULT_LATENCY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2905 g_object_class_install_property (gobject_class, PROP_START_TIME_SELECTION,
2906 g_param_spec_enum ("start-time-selection", "Start Time Selection",
2907 "Decides which start time is output",
2908 gst_aggregator_start_time_selection_get_type (),
2909 DEFAULT_START_TIME_SELECTION,
2910 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2912 g_object_class_install_property (gobject_class, PROP_START_TIME,
2913 g_param_spec_uint64 ("start-time", "Start Time",
2914 "Start time to use if start-time-selection=set", 0,
2916 DEFAULT_START_TIME, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2919 * GstAggregator:emit-signals:
2921 * Enables the emission of signals such as #GstAggregator::samples-selected
2925 g_object_class_install_property (gobject_class, PROP_EMIT_SIGNALS,
2926 g_param_spec_boolean ("emit-signals", "Emit signals",
2927 "Send signals", DEFAULT_EMIT_SIGNALS,
2928 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
2931 * GstAggregator::samples-selected:
2932 * @aggregator: The #GstAggregator that emitted the signal
2933 * @segment: The #GstSegment the next output buffer is part of
2934 * @pts: The presentation timestamp of the next output buffer
2935 * @dts: The decoding timestamp of the next output buffer
2936 * @duration: The duration of the next output buffer
2937 * @info: (nullable): a #GstStructure containing additional information
2939 * Signals that the #GstAggregator subclass has selected the next set
2940 * of input samples it will aggregate. Handlers may call
2941 * gst_aggregator_peek_next_sample() at that point.
2945 gst_aggregator_signals[SIGNAL_SAMPLES_SELECTED] =
2946 g_signal_new ("samples-selected", G_TYPE_FROM_CLASS (klass),
2947 G_SIGNAL_RUN_FIRST, 0, NULL, NULL, NULL, G_TYPE_NONE, 5,
2948 GST_TYPE_SEGMENT | G_SIGNAL_TYPE_STATIC_SCOPE, GST_TYPE_CLOCK_TIME,
2949 GST_TYPE_CLOCK_TIME, GST_TYPE_CLOCK_TIME,
2950 GST_TYPE_STRUCTURE | G_SIGNAL_TYPE_STATIC_SCOPE);
2952 gst_meta_register_custom ("GstAggregatorMissingDataMeta", meta_tags, NULL,
2956 static inline gpointer
2957 gst_aggregator_get_instance_private (GstAggregator * self)
2959 return (G_STRUCT_MEMBER_P (self, aggregator_private_offset));
2963 gst_aggregator_init (GstAggregator * self, GstAggregatorClass * klass)
2965 GstPadTemplate *pad_template;
2966 GstAggregatorPrivate *priv;
2969 g_return_if_fail (klass->aggregate != NULL);
2971 self->priv = gst_aggregator_get_instance_private (self);
2976 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (klass), "src");
2977 g_return_if_fail (pad_template != NULL);
2979 priv->max_padserial = -1;
2980 priv->tags_changed = FALSE;
2981 priv->ignore_inactive_pads = FALSE;
2983 self->priv->peer_latency_live = FALSE;
2984 self->priv->peer_latency_min = self->priv->sub_latency_min = 0;
2985 self->priv->peer_latency_max = self->priv->sub_latency_max = 0;
2986 self->priv->has_peer_latency = FALSE;
2989 GST_PAD_TEMPLATE_GTYPE (pad_template) ==
2990 G_TYPE_NONE ? GST_TYPE_AGGREGATOR_PAD :
2991 GST_PAD_TEMPLATE_GTYPE (pad_template);
2992 g_assert (g_type_is_a (pad_type, GST_TYPE_AGGREGATOR_PAD));
2994 g_object_new (pad_type, "name", "src", "direction", GST_PAD_SRC,
2995 "template", pad_template, NULL);
2997 gst_aggregator_reset_flow_values (self);
2999 gst_pad_set_event_function (self->srcpad,
3000 GST_DEBUG_FUNCPTR (gst_aggregator_src_pad_event_func));
3001 gst_pad_set_query_function (self->srcpad,
3002 GST_DEBUG_FUNCPTR (gst_aggregator_src_pad_query_func));
3003 gst_pad_set_activatemode_function (self->srcpad,
3004 GST_DEBUG_FUNCPTR (gst_aggregator_src_pad_activate_mode_func));
3006 gst_element_add_pad (GST_ELEMENT (self), self->srcpad);
3008 self->priv->upstream_latency_min = DEFAULT_MIN_UPSTREAM_LATENCY;
3009 self->priv->latency = DEFAULT_LATENCY;
3010 self->priv->start_time_selection = DEFAULT_START_TIME_SELECTION;
3011 self->priv->start_time = DEFAULT_START_TIME;
3012 self->priv->force_live = DEFAULT_FORCE_LIVE;
3014 g_mutex_init (&self->priv->src_lock);
3015 g_cond_init (&self->priv->src_cond);
3018 /* we can't use G_DEFINE_ABSTRACT_TYPE because we need the klass in the _init
3019 * method to get to the padtemplates */
3021 gst_aggregator_get_type (void)
3023 static gsize type = 0;
3025 if (g_once_init_enter (&type)) {
3027 static const GTypeInfo info = {
3028 sizeof (GstAggregatorClass),
3031 (GClassInitFunc) gst_aggregator_class_init,
3034 sizeof (GstAggregator),
3036 (GInstanceInitFunc) gst_aggregator_init,
3039 _type = g_type_register_static (GST_TYPE_ELEMENT,
3040 "GstAggregator", &info, G_TYPE_FLAG_ABSTRACT);
3042 aggregator_private_offset =
3043 g_type_add_instance_private (_type, sizeof (GstAggregatorPrivate));
3045 g_once_init_leave (&type, _type);
3050 /* Must be called with SRC lock and PAD lock held */
3052 gst_aggregator_pad_has_space (GstAggregator * self, GstAggregatorPad * aggpad)
3054 guint64 max_time_level;
3056 GST_TRACE_OBJECT (aggpad, "Have %" GST_TIME_FORMAT " queued in %u buffers",
3057 GST_TIME_ARGS (aggpad->priv->time_level), aggpad->priv->num_buffers);
3059 /* Empty queue always has space */
3060 if (aggpad->priv->num_buffers == 0 && aggpad->priv->clipped_buffer == NULL)
3063 /* We also want at least two buffers, one is being processed and one is ready
3064 * for the next iteration when we operate in live mode. */
3065 if (is_live_unlocked (self) && aggpad->priv->num_buffers < 2)
3068 /* On top of our latency, we also want to allow buffering up to the
3069 * minimum upstream latency to allow queue free sources with lower then
3070 * upstream latency. */
3071 max_time_level = self->priv->latency + self->priv->peer_latency_min;
3073 /* zero latency, if there is a buffer, it's full */
3074 if (max_time_level == 0)
3077 GST_TRACE_OBJECT (aggpad, "Maximum queue level %" GST_TIME_FORMAT,
3078 GST_TIME_ARGS (max_time_level));
3080 /* Allow no more buffers than the latency */
3081 return (aggpad->priv->time_level <= max_time_level);
3084 /* Must be called with the PAD_LOCK held */
3086 apply_buffer (GstAggregatorPad * aggpad, GstBuffer * buffer, gboolean head)
3088 GstClockTime timestamp;
3090 if (GST_BUFFER_DTS_IS_VALID (buffer))
3091 timestamp = GST_BUFFER_DTS (buffer);
3093 timestamp = GST_BUFFER_PTS (buffer);
3095 if (timestamp == GST_CLOCK_TIME_NONE) {
3097 timestamp = aggpad->priv->head_position;
3099 timestamp = aggpad->priv->tail_position;
3103 if (GST_BUFFER_DURATION_IS_VALID (buffer))
3104 timestamp += GST_BUFFER_DURATION (buffer);
3107 aggpad->priv->head_position = timestamp;
3109 aggpad->priv->tail_position = timestamp;
3111 GST_OBJECT_LOCK (aggpad);
3112 update_time_level (aggpad, head);
3113 GST_OBJECT_UNLOCK (aggpad);
3117 * Can be called either from the sinkpad's chain function or from the srcpad's
3118 * thread in the case of a buffer synthetized from a GAP event.
3119 * Because of this second case, FLUSH_LOCK can't be used here.
3122 static GstFlowReturn
3123 gst_aggregator_pad_chain_internal (GstAggregator * self,
3124 GstAggregatorPad * aggpad, GstBuffer * buffer, gboolean head)
3126 GstFlowReturn flow_return;
3127 GstClockTime buf_pts;
3129 GST_TRACE_OBJECT (aggpad,
3130 "entering chain internal with %" GST_PTR_FORMAT, buffer);
3133 flow_return = aggpad->priv->flow_return;
3134 if (flow_return != GST_FLOW_OK)
3137 PAD_UNLOCK (aggpad);
3139 buf_pts = GST_BUFFER_PTS (buffer);
3143 GST_OBJECT_LOCK (self);
3146 if (aggpad->priv->first_buffer) {
3147 self->priv->has_peer_latency = FALSE;
3148 aggpad->priv->first_buffer = FALSE;
3151 if ((gst_aggregator_pad_has_space (self, aggpad) || !head)
3152 && aggpad->priv->flow_return == GST_FLOW_OK) {
3154 GST_DEBUG_OBJECT (aggpad, "Enqueuing %" GST_PTR_FORMAT, buffer);
3155 g_queue_push_head (&aggpad->priv->data, buffer);
3157 g_queue_push_tail (&aggpad->priv->data, buffer);
3159 apply_buffer (aggpad, buffer, head);
3160 aggpad->priv->num_buffers++;
3162 SRC_BROADCAST (self);
3166 flow_return = aggpad->priv->flow_return;
3167 if (flow_return != GST_FLOW_OK) {
3168 GST_OBJECT_UNLOCK (self);
3172 GST_DEBUG_OBJECT (aggpad,
3173 "Waiting for buffer to be consumed (chain) before enqueueing %"
3174 GST_PTR_FORMAT, buffer);
3175 GST_OBJECT_UNLOCK (self);
3177 PAD_WAIT_EVENT (aggpad);
3179 PAD_UNLOCK (aggpad);
3182 if (self->priv->first_buffer) {
3183 GstClockTime start_time;
3184 GstAggregatorPad *srcpad = GST_AGGREGATOR_PAD (self->srcpad);
3186 switch (self->priv->start_time_selection) {
3187 case GST_AGGREGATOR_START_TIME_SELECTION_ZERO:
3191 case GST_AGGREGATOR_START_TIME_SELECTION_FIRST:
3192 GST_OBJECT_LOCK (aggpad);
3193 if (aggpad->priv->head_segment.format == GST_FORMAT_TIME) {
3194 start_time = buf_pts;
3195 if (start_time != -1) {
3196 start_time = MAX (start_time, aggpad->priv->head_segment.start);
3198 gst_segment_to_running_time (&aggpad->priv->head_segment,
3199 GST_FORMAT_TIME, start_time);
3203 GST_WARNING_OBJECT (aggpad,
3204 "Ignoring request of selecting the first start time "
3205 "as the segment is a %s segment instead of a time segment",
3206 gst_format_get_name (aggpad->priv->head_segment.format));
3208 GST_OBJECT_UNLOCK (aggpad);
3210 case GST_AGGREGATOR_START_TIME_SELECTION_SET:
3211 start_time = self->priv->start_time;
3212 if (start_time == -1)
3217 if (start_time != -1) {
3218 if (srcpad->segment.position == -1)
3219 srcpad->segment.position = start_time;
3221 srcpad->segment.position = MIN (start_time, srcpad->segment.position);
3223 GST_DEBUG_OBJECT (self, "Selecting start time %" GST_TIME_FORMAT,
3224 GST_TIME_ARGS (start_time));
3228 PAD_UNLOCK (aggpad);
3229 GST_OBJECT_UNLOCK (self);
3232 GST_TRACE_OBJECT (aggpad, "Done chaining");
3237 PAD_UNLOCK (aggpad);
3239 GST_DEBUG_OBJECT (aggpad, "Pad is %s, dropping buffer",
3240 gst_flow_get_name (flow_return));
3242 gst_buffer_unref (buffer);
3247 static GstFlowReturn
3248 gst_aggregator_pad_chain (GstPad * pad, GstObject * object, GstBuffer * buffer)
3251 GstAggregatorPad *aggpad = GST_AGGREGATOR_PAD (pad);
3253 GST_TRACE_OBJECT (aggpad, "entering chain");
3255 PAD_FLUSH_LOCK (aggpad);
3257 ret = gst_aggregator_pad_chain_internal (GST_AGGREGATOR_CAST (object),
3258 aggpad, buffer, TRUE);
3260 PAD_FLUSH_UNLOCK (aggpad);
3266 gst_aggregator_pad_query_func (GstPad * pad, GstObject * parent,
3269 GstAggregator *self = GST_AGGREGATOR (parent);
3270 GstAggregatorClass *klass = GST_AGGREGATOR_GET_CLASS (self);
3271 GstAggregatorPad *aggpad = GST_AGGREGATOR_PAD (pad);
3273 g_assert (klass->sink_query_pre_queue);
3274 return klass->sink_query_pre_queue (self, aggpad, query);
3277 static GstFlowReturn
3278 gst_aggregator_pad_event_func (GstPad * pad, GstObject * parent,
3281 GstAggregator *self = GST_AGGREGATOR (parent);
3282 GstAggregatorClass *klass = GST_AGGREGATOR_GET_CLASS (self);
3283 GstAggregatorPad *aggpad = GST_AGGREGATOR_PAD (pad);
3285 g_assert (klass->sink_event_pre_queue);
3286 return klass->sink_event_pre_queue (self, aggpad, event);
3290 gst_aggregator_pad_activate_mode_func (GstPad * pad,
3291 GstObject * parent, GstPadMode mode, gboolean active)
3293 GstAggregator *self = GST_AGGREGATOR (parent);
3294 GstAggregatorPad *aggpad = GST_AGGREGATOR_PAD (pad);
3296 if (active == FALSE) {
3298 gst_aggregator_pad_set_flushing (aggpad, GST_FLOW_FLUSHING, TRUE);
3299 SRC_BROADCAST (self);
3303 aggpad->priv->flow_return = GST_FLOW_OK;
3304 PAD_BROADCAST_EVENT (aggpad);
3305 PAD_UNLOCK (aggpad);
3311 /***********************************
3312 * GstAggregatorPad implementation *
3313 ************************************/
3314 G_DEFINE_TYPE_WITH_PRIVATE (GstAggregatorPad, gst_aggregator_pad, GST_TYPE_PAD);
3316 #define DEFAULT_PAD_EMIT_SIGNALS FALSE
3321 PAD_PROP_EMIT_SIGNALS,
3326 PAD_SIGNAL_BUFFER_CONSUMED,
3330 static guint gst_aggregator_pad_signals[PAD_LAST_SIGNAL] = { 0 };
3333 gst_aggregator_pad_constructed (GObject * object)
3335 GstPad *pad = GST_PAD (object);
3337 if (GST_PAD_IS_SINK (pad)) {
3338 gst_pad_set_chain_function (pad,
3339 GST_DEBUG_FUNCPTR (gst_aggregator_pad_chain));
3340 gst_pad_set_event_full_function_full (pad,
3341 GST_DEBUG_FUNCPTR (gst_aggregator_pad_event_func), NULL, NULL);
3342 gst_pad_set_query_function (pad,
3343 GST_DEBUG_FUNCPTR (gst_aggregator_pad_query_func));
3344 gst_pad_set_activatemode_function (pad,
3345 GST_DEBUG_FUNCPTR (gst_aggregator_pad_activate_mode_func));
3350 gst_aggregator_pad_finalize (GObject * object)
3352 GstAggregatorPad *pad = (GstAggregatorPad *) object;
3354 gst_buffer_replace (&pad->priv->peeked_buffer, NULL);
3355 g_cond_clear (&pad->priv->event_cond);
3356 g_mutex_clear (&pad->priv->flush_lock);
3357 g_mutex_clear (&pad->priv->lock);
3359 G_OBJECT_CLASS (gst_aggregator_pad_parent_class)->finalize (object);
3363 gst_aggregator_pad_dispose (GObject * object)
3365 GstAggregatorPad *pad = (GstAggregatorPad *) object;
3367 gst_aggregator_pad_set_flushing (pad, GST_FLOW_FLUSHING, TRUE);
3369 G_OBJECT_CLASS (gst_aggregator_pad_parent_class)->dispose (object);
3373 gst_aggregator_pad_set_property (GObject * object, guint prop_id,
3374 const GValue * value, GParamSpec * pspec)
3376 GstAggregatorPad *pad = GST_AGGREGATOR_PAD (object);
3379 case PAD_PROP_EMIT_SIGNALS:
3380 pad->priv->emit_signals = g_value_get_boolean (value);
3383 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3389 gst_aggregator_pad_get_property (GObject * object, guint prop_id,
3390 GValue * value, GParamSpec * pspec)
3392 GstAggregatorPad *pad = GST_AGGREGATOR_PAD (object);
3395 case PAD_PROP_EMIT_SIGNALS:
3396 g_value_set_boolean (value, pad->priv->emit_signals);
3399 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3405 gst_aggregator_pad_class_init (GstAggregatorPadClass * klass)
3407 GObjectClass *gobject_class = (GObjectClass *) klass;
3409 gobject_class->constructed = gst_aggregator_pad_constructed;
3410 gobject_class->finalize = gst_aggregator_pad_finalize;
3411 gobject_class->dispose = gst_aggregator_pad_dispose;
3412 gobject_class->set_property = gst_aggregator_pad_set_property;
3413 gobject_class->get_property = gst_aggregator_pad_get_property;
3416 * GstAggregatorPad:buffer-consumed:
3417 * @aggregator: The #GstAggregator that emitted the signal
3418 * @buffer: The buffer that was consumed
3420 * Signals that a buffer was consumed. As aggregator pads store buffers
3421 * in an internal queue, there is no direct match between input and output
3422 * buffers at any given time. This signal can be useful to forward metas
3423 * such as #GstVideoTimeCodeMeta or #GstVideoCaptionMeta at the right time.
3427 gst_aggregator_pad_signals[PAD_SIGNAL_BUFFER_CONSUMED] =
3428 g_signal_new ("buffer-consumed", G_TYPE_FROM_CLASS (klass),
3429 G_SIGNAL_RUN_FIRST, 0, NULL, NULL, NULL, G_TYPE_NONE, 1, GST_TYPE_BUFFER);
3432 * GstAggregatorPad:emit-signals:
3434 * Enables the emission of signals such as #GstAggregatorPad::buffer-consumed
3438 g_object_class_install_property (gobject_class, PAD_PROP_EMIT_SIGNALS,
3439 g_param_spec_boolean ("emit-signals", "Emit signals",
3440 "Send signals to signal data consumption", DEFAULT_PAD_EMIT_SIGNALS,
3441 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
3445 gst_aggregator_pad_init (GstAggregatorPad * pad)
3447 pad->priv = gst_aggregator_pad_get_instance_private (pad);
3449 g_queue_init (&pad->priv->data);
3450 g_cond_init (&pad->priv->event_cond);
3452 g_mutex_init (&pad->priv->flush_lock);
3453 g_mutex_init (&pad->priv->lock);
3455 gst_aggregator_pad_reset_unlocked (pad);
3456 pad->priv->negotiated = FALSE;
3457 pad->priv->emit_signals = DEFAULT_PAD_EMIT_SIGNALS;
3460 /* Must be called with the PAD_LOCK held */
3462 gst_aggregator_pad_buffer_consumed (GstAggregatorPad * pad, GstBuffer * buffer,
3466 pad->priv->num_buffers--;
3468 if (buffer && pad->priv->emit_signals) {
3469 g_signal_emit (pad, gst_aggregator_pad_signals[PAD_SIGNAL_BUFFER_CONSUMED],
3472 PAD_BROADCAST_EVENT (pad);
3475 /* Must be called with the PAD_LOCK held */
3477 gst_aggregator_pad_clip_buffer_unlocked (GstAggregatorPad * pad)
3479 GstAggregator *self = NULL;
3480 GstAggregatorClass *aggclass = NULL;
3481 GstBuffer *buffer = NULL;
3483 while (pad->priv->clipped_buffer == NULL &&
3484 GST_IS_BUFFER (g_queue_peek_tail (&pad->priv->data))) {
3485 buffer = g_queue_pop_tail (&pad->priv->data);
3487 apply_buffer (pad, buffer, FALSE);
3489 /* We only take the parent here so that it's not taken if the buffer is
3490 * already clipped or if the queue is empty.
3493 self = GST_AGGREGATOR (gst_pad_get_parent_element (GST_PAD (pad)));
3495 gst_buffer_unref (buffer);
3499 aggclass = GST_AGGREGATOR_GET_CLASS (self);
3502 if (aggclass->clip) {
3503 GST_TRACE_OBJECT (pad, "Clipping: %" GST_PTR_FORMAT, buffer);
3505 buffer = aggclass->clip (self, pad, buffer);
3507 if (buffer == NULL) {
3508 gst_aggregator_pad_buffer_consumed (pad, buffer, TRUE);
3509 GST_TRACE_OBJECT (pad, "Clipping consumed the buffer");
3513 pad->priv->clipped_buffer = buffer;
3517 gst_object_unref (self);
3521 * gst_aggregator_pad_pop_buffer:
3522 * @pad: the pad to get buffer from
3524 * Steal the ref to the buffer currently queued in @pad.
3526 * Returns: (nullable) (transfer full): The buffer in @pad or NULL if no buffer was
3527 * queued. You should unref the buffer after usage.
3530 gst_aggregator_pad_pop_buffer (GstAggregatorPad * pad)
3532 GstBuffer *buffer = NULL;
3536 /* If the subclass has already peeked a buffer, we guarantee
3537 * that it receives the same buffer, no matter if the pad has
3538 * errored out / been flushed in the meantime.
3540 if (pad->priv->peeked_buffer) {
3541 buffer = pad->priv->peeked_buffer;
3545 if (pad->priv->flow_return != GST_FLOW_OK)
3548 gst_aggregator_pad_clip_buffer_unlocked (pad);
3549 buffer = pad->priv->clipped_buffer;
3553 if (pad->priv->clipped_buffer != NULL) {
3554 /* Here we still hold a reference to both the clipped buffer
3555 * and possibly the peeked buffer, we transfer the first and
3556 * potentially release the second
3558 gst_aggregator_pad_buffer_consumed (pad, buffer, TRUE);
3559 pad->priv->clipped_buffer = NULL;
3560 gst_buffer_replace (&pad->priv->peeked_buffer, NULL);
3562 /* Here our clipped buffer has already been released, for
3563 * example because of a flush. We thus transfer the reference
3564 * to the peeked buffer to the caller, and we don't decrement
3565 * pad.num_buffers as it has already been done elsewhere
3567 gst_aggregator_pad_buffer_consumed (pad, buffer, FALSE);
3568 pad->priv->peeked_buffer = NULL;
3570 GST_DEBUG_OBJECT (pad, "Consumed: %" GST_PTR_FORMAT, buffer);
3579 * gst_aggregator_pad_drop_buffer:
3580 * @pad: the pad where to drop any pending buffer
3582 * Drop the buffer currently queued in @pad.
3584 * Returns: TRUE if there was a buffer queued in @pad, or FALSE if not.
3587 gst_aggregator_pad_drop_buffer (GstAggregatorPad * pad)
3591 buf = gst_aggregator_pad_pop_buffer (pad);
3596 gst_buffer_unref (buf);
3601 * gst_aggregator_pad_peek_buffer:
3602 * @pad: the pad to get buffer from
3604 * Returns: (nullable) (transfer full): A reference to the buffer in @pad or
3605 * NULL if no buffer was queued. You should unref the buffer after
3609 gst_aggregator_pad_peek_buffer (GstAggregatorPad * pad)
3611 GstBuffer *buffer = NULL;
3615 if (pad->priv->peeked_buffer) {
3616 buffer = gst_buffer_ref (pad->priv->peeked_buffer);
3620 if (pad->priv->flow_return != GST_FLOW_OK)
3623 gst_aggregator_pad_clip_buffer_unlocked (pad);
3625 if (pad->priv->clipped_buffer) {
3626 buffer = gst_buffer_ref (pad->priv->clipped_buffer);
3627 pad->priv->peeked_buffer = gst_buffer_ref (buffer);
3638 * gst_aggregator_pad_has_buffer:
3639 * @pad: the pad to check the buffer on
3641 * This checks if a pad has a buffer available that will be returned by
3642 * a call to gst_aggregator_pad_peek_buffer() or
3643 * gst_aggregator_pad_pop_buffer().
3645 * Returns: %TRUE if the pad has a buffer available as the next thing.
3650 gst_aggregator_pad_has_buffer (GstAggregatorPad * pad)
3652 gboolean has_buffer;
3656 if (pad->priv->peeked_buffer) {
3659 gst_aggregator_pad_clip_buffer_unlocked (pad);
3660 has_buffer = (pad->priv->clipped_buffer != NULL);
3662 pad->priv->peeked_buffer = gst_buffer_ref (pad->priv->clipped_buffer);
3670 * gst_aggregator_pad_is_eos:
3671 * @pad: an aggregator pad
3673 * Returns: %TRUE if the pad is EOS, otherwise %FALSE.
3676 gst_aggregator_pad_is_eos (GstAggregatorPad * pad)
3681 is_eos = pad->priv->eos;
3688 * gst_aggregator_pad_is_inactive:
3689 * @pad: an aggregator pad
3691 * It is only valid to call this method from #GstAggregatorClass::aggregate()
3693 * Returns: %TRUE if the pad is inactive, %FALSE otherwise.
3694 * See gst_aggregator_ignore_inactive_pads() for more info.
3698 gst_aggregator_pad_is_inactive (GstAggregatorPad * pad)
3700 GstAggregator *self;
3703 self = GST_AGGREGATOR (gst_pad_get_parent_element (GST_PAD (pad)));
3705 g_assert_nonnull (self);
3708 inactive = self->priv->ignore_inactive_pads && is_live_unlocked (self)
3709 && pad->priv->first_buffer;
3712 gst_object_unref (self);
3719 * gst_aggregator_merge_tags:
3720 * @self: a #GstAggregator
3721 * @tags: a #GstTagList to merge
3722 * @mode: the #GstTagMergeMode to use
3724 * Adds tags to so-called pending tags, which will be processed
3725 * before pushing out data downstream.
3727 * Note that this is provided for convenience, and the subclass is
3728 * not required to use this and can still do tag handling on its own.
3733 gst_aggregator_merge_tags (GstAggregator * self,
3734 const GstTagList * tags, GstTagMergeMode mode)
3738 g_return_if_fail (GST_IS_AGGREGATOR (self));
3739 g_return_if_fail (tags == NULL || GST_IS_TAG_LIST (tags));
3741 /* FIXME Check if we can use OBJECT lock here! */
3742 GST_OBJECT_LOCK (self);
3744 GST_DEBUG_OBJECT (self, "merging tags %" GST_PTR_FORMAT, tags);
3745 otags = self->priv->tags;
3746 self->priv->tags = gst_tag_list_merge (self->priv->tags, tags, mode);
3748 gst_tag_list_unref (otags);
3749 self->priv->tags_changed = TRUE;
3750 GST_OBJECT_UNLOCK (self);
3755 * gst_aggregator_set_latency:
3756 * @self: a #GstAggregator
3757 * @min_latency: minimum latency
3758 * @max_latency: maximum latency
3760 * Lets #GstAggregator sub-classes tell the baseclass what their internal
3761 * latency is. Will also post a LATENCY message on the bus so the pipeline
3762 * can reconfigure its global latency if the values changed.
3765 gst_aggregator_set_latency (GstAggregator * self,
3766 GstClockTime min_latency, GstClockTime max_latency)
3768 gboolean changed = FALSE;
3770 g_return_if_fail (GST_IS_AGGREGATOR (self));
3771 g_return_if_fail (GST_CLOCK_TIME_IS_VALID (min_latency));
3772 g_return_if_fail (max_latency >= min_latency);
3775 if (self->priv->sub_latency_min != min_latency) {
3776 self->priv->sub_latency_min = min_latency;
3779 if (self->priv->sub_latency_max != max_latency) {
3780 self->priv->sub_latency_max = max_latency;
3783 if (!self->priv->posted_latency_msg) {
3784 self->priv->posted_latency_msg = TRUE;
3789 SRC_BROADCAST (self);
3793 gst_element_post_message (GST_ELEMENT_CAST (self),
3794 gst_message_new_latency (GST_OBJECT_CAST (self)));
3799 * gst_aggregator_get_buffer_pool:
3800 * @self: a #GstAggregator
3802 * Returns: (transfer full) (nullable): the instance of the #GstBufferPool used
3803 * by @trans; free it after use it
3806 gst_aggregator_get_buffer_pool (GstAggregator * self)
3808 GstBufferPool *pool;
3810 g_return_val_if_fail (GST_IS_AGGREGATOR (self), NULL);
3812 GST_OBJECT_LOCK (self);
3813 pool = self->priv->pool;
3815 gst_object_ref (pool);
3816 GST_OBJECT_UNLOCK (self);
3822 * gst_aggregator_get_allocator:
3823 * @self: a #GstAggregator
3824 * @allocator: (out) (optional) (nullable) (transfer full): the #GstAllocator
3826 * @params: (out caller-allocates) (optional): the
3827 * #GstAllocationParams of @allocator
3829 * Lets #GstAggregator sub-classes get the memory @allocator
3830 * acquired by the base class and its @params.
3832 * Unref the @allocator after use it.
3835 gst_aggregator_get_allocator (GstAggregator * self,
3836 GstAllocator ** allocator, GstAllocationParams * params)
3838 g_return_if_fail (GST_IS_AGGREGATOR (self));
3841 *allocator = self->priv->allocator ?
3842 gst_object_ref (self->priv->allocator) : NULL;
3845 *params = self->priv->allocation_params;
3849 * gst_aggregator_simple_get_next_time:
3850 * @self: A #GstAggregator
3852 * This is a simple #GstAggregatorClass::get_next_time implementation that
3853 * just looks at the #GstSegment on the srcpad of the aggregator and bases
3854 * the next time on the running time there.
3856 * This is the desired behaviour in most cases where you have a live source
3857 * and you have a dead line based aggregator subclass.
3859 * Returns: The running time based on the position
3864 gst_aggregator_simple_get_next_time (GstAggregator * self)
3866 GstClockTime next_time;
3867 GstAggregatorPad *srcpad = GST_AGGREGATOR_PAD (self->srcpad);
3868 GstSegment *segment = &srcpad->segment;
3870 GST_OBJECT_LOCK (self);
3871 if (segment->position == -1 || segment->position < segment->start)
3872 next_time = segment->start;
3874 next_time = segment->position;
3876 if (segment->stop != -1 && next_time > segment->stop)
3877 next_time = segment->stop;
3879 next_time = gst_segment_to_running_time (segment, GST_FORMAT_TIME, next_time);
3880 GST_OBJECT_UNLOCK (self);
3886 * gst_aggregator_update_segment:
3888 * Subclasses should use this to update the segment on their
3889 * source pad, instead of directly pushing new segment events
3892 * Subclasses MUST call this before gst_aggregator_selected_samples(),
3893 * if it is used at all.
3898 gst_aggregator_update_segment (GstAggregator * self, const GstSegment * segment)
3900 g_return_if_fail (GST_IS_AGGREGATOR (self));
3901 g_return_if_fail (segment != NULL);
3903 GST_INFO_OBJECT (self, "Updating srcpad segment: %" GST_SEGMENT_FORMAT,
3906 GST_OBJECT_LOCK (self);
3907 GST_AGGREGATOR_PAD (self->srcpad)->segment = *segment;
3908 self->priv->send_segment = TRUE;
3909 /* we have a segment from the subclass now and really shouldn't override
3910 * anything in that segment anymore, like the segment.position */
3911 self->priv->first_buffer = FALSE;
3912 GST_OBJECT_UNLOCK (self);
3916 * gst_aggregator_selected_samples:
3917 * @pts: The presentation timestamp of the next output buffer
3918 * @dts: The decoding timestamp of the next output buffer
3919 * @duration: The duration of the next output buffer
3920 * @info: (nullable): a #GstStructure containing additional information
3922 * Subclasses should call this when they have prepared the
3923 * buffers they will aggregate for each of their sink pads, but
3924 * before using any of the properties of the pads that govern
3925 * *how* aggregation should be performed, for example z-index
3926 * for video aggregators.
3928 * If gst_aggregator_update_segment() is used by the subclass,
3929 * it MUST be called before gst_aggregator_selected_samples().
3931 * This function MUST only be called from the #GstAggregatorClass::aggregate()
3937 gst_aggregator_selected_samples (GstAggregator * self,
3938 GstClockTime pts, GstClockTime dts, GstClockTime duration,
3939 GstStructure * info)
3941 g_return_if_fail (GST_IS_AGGREGATOR (self));
3943 if (self->priv->emit_signals) {
3944 g_signal_emit (self, gst_aggregator_signals[SIGNAL_SAMPLES_SELECTED], 0,
3945 &GST_AGGREGATOR_PAD (self->srcpad)->segment, pts, dts, duration, info);
3948 self->priv->selected_samples_called_or_warned = TRUE;
3952 * gst_aggregator_set_ignore_inactive_pads:
3953 * @ignore: whether inactive pads should not be waited on
3955 * Subclasses should call this when they don't want to time out
3956 * waiting for a pad that hasn't yet received any buffers in live
3959 * #GstAggregator will still wait once on each newly-added pad, making
3960 * sure upstream has had a fair chance to start up.
3965 gst_aggregator_set_ignore_inactive_pads (GstAggregator * self, gboolean ignore)
3967 g_return_if_fail (GST_IS_AGGREGATOR (self));
3969 GST_OBJECT_LOCK (self);
3970 self->priv->ignore_inactive_pads = ignore;
3971 GST_OBJECT_UNLOCK (self);
3975 * gst_aggregator_get_ignore_inactive_pads:
3977 * Returns: whether inactive pads will not be waited on
3981 gst_aggregator_get_ignore_inactive_pads (GstAggregator * self)
3985 g_return_val_if_fail (GST_IS_AGGREGATOR (self), FALSE);
3987 GST_OBJECT_LOCK (self);
3988 ret = self->priv->ignore_inactive_pads;
3989 GST_OBJECT_UNLOCK (self);
3995 * gst_aggregator_get_force_live:
3997 * Subclasses may use the return value to inform whether they should return
3998 * %GST_FLOW_EOS from their aggregate implementation.
4000 * Returns: whether live status was forced on @self.
4005 gst_aggregator_get_force_live (GstAggregator * self)
4007 return self->priv->force_live;
4011 * gst_aggregator_set_force_live:
4013 * Subclasses should call this at construction time in order for @self to
4014 * aggregate on a timeout even when no live source is connected.
4019 gst_aggregator_set_force_live (GstAggregator * self, gboolean force_live)
4021 self->priv->force_live = force_live;