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 * @short_description: manages a set of pads with the purpose of
25 * aggregating their buffers.
26 * @see_also: gstcollectpads for historical reasons.
28 * Manages a set of pads with the purpose of aggregating their buffers.
29 * 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.
36 * When data is queued on all pads, tha aggregate vmethod is called.
39 * One can peek at the data on any given GstAggregatorPad with the
40 * gst_aggregator_pad_get_buffer () method, and take ownership of it
41 * with the gst_aggregator_pad_steal_buffer () method. When a buffer
42 * has been taken with steal_buffer (), a new buffer can be queued
46 * If the subclass wishes to push a buffer downstream in its aggregate
47 * implementation, it should do so through the
48 * gst_aggregator_finish_buffer () method. This method will take care
49 * of sending and ordering mandatory events such as stream start, caps
53 * Same goes for EOS events, which should not be pushed directly by the
54 * subclass, it should instead return GST_FLOW_EOS in its aggregate
58 * Note that the aggregator logic regarding gap event handling is to turn
59 * these into gap buffers with matching PTS and duration. It will also
60 * flag these buffers with GST_BUFFER_FLAG_GAP and GST_BUFFER_FLAG_DROPPABLE
61 * to ease their identification and subsequent processing.
70 #include <string.h> /* strlen */
72 #include "gstaggregator.h"
76 GST_AGGREGATOR_START_TIME_SELECTION_ZERO,
77 GST_AGGREGATOR_START_TIME_SELECTION_FIRST,
78 GST_AGGREGATOR_START_TIME_SELECTION_SET
79 } GstAggregatorStartTimeSelection;
82 gst_aggregator_start_time_selection_get_type (void)
84 static GType gtype = 0;
87 static const GEnumValue values[] = {
88 {GST_AGGREGATOR_START_TIME_SELECTION_ZERO,
89 "Start at 0 running time (default)", "zero"},
90 {GST_AGGREGATOR_START_TIME_SELECTION_FIRST,
91 "Start at first observed input running time", "first"},
92 {GST_AGGREGATOR_START_TIME_SELECTION_SET,
93 "Set start time with start-time property", "set"},
97 gtype = g_enum_register_static ("GstAggregatorStartTimeSelection", values);
102 /* Might become API */
103 static void gst_aggregator_merge_tags (GstAggregator * aggregator,
104 const GstTagList * tags, GstTagMergeMode mode);
105 static void gst_aggregator_set_latency_property (GstAggregator * agg,
107 static gint64 gst_aggregator_get_latency_property (GstAggregator * agg);
110 /* Locking order, locks in this element must always be taken in this order
112 * standard sink pad stream lock -> GST_PAD_STREAM_LOCK (aggpad)
113 * Aggregator pad flush lock -> PAD_FLUSH_LOCK(aggpad)
114 * standard src pad stream lock -> GST_PAD_STREAM_LOCK (srcpad)
115 * Aggregator src lock -> SRC_LOCK(agg) w/ SRC_WAIT/BROADCAST
116 * standard element object lock -> GST_OBJECT_LOCK(agg)
117 * Aggregator pad lock -> PAD_LOCK (aggpad) w/ PAD_WAIT/BROADCAST_EVENT(aggpad)
118 * standard src pad object lock -> GST_OBJECT_LOCK(srcpad)
119 * standard sink pad object lock -> GST_OBJECT_LOCK(aggpad)
123 static GstClockTime gst_aggregator_get_latency_unlocked (GstAggregator * self);
125 GST_DEBUG_CATEGORY_STATIC (aggregator_debug);
126 #define GST_CAT_DEFAULT aggregator_debug
128 /* GstAggregatorPad definitions */
129 #define PAD_LOCK(pad) G_STMT_START { \
130 GST_TRACE_OBJECT (pad, "Taking PAD lock from thread %p", \
132 g_mutex_lock(&pad->priv->lock); \
133 GST_TRACE_OBJECT (pad, "Took PAD lock from thread %p", \
137 #define PAD_UNLOCK(pad) G_STMT_START { \
138 GST_TRACE_OBJECT (pad, "Releasing PAD lock from thread %p", \
140 g_mutex_unlock(&pad->priv->lock); \
141 GST_TRACE_OBJECT (pad, "Release PAD lock from thread %p", \
146 #define PAD_WAIT_EVENT(pad) G_STMT_START { \
147 GST_LOG_OBJECT (pad, "Waiting for buffer to be consumed thread %p", \
149 g_cond_wait(&(((GstAggregatorPad* )pad)->priv->event_cond), \
150 (&((GstAggregatorPad*)pad)->priv->lock)); \
151 GST_LOG_OBJECT (pad, "DONE Waiting for buffer to be consumed on thread %p", \
155 #define PAD_BROADCAST_EVENT(pad) G_STMT_START { \
156 GST_LOG_OBJECT (pad, "Signaling buffer consumed from thread %p", \
158 g_cond_broadcast(&(((GstAggregatorPad* )pad)->priv->event_cond)); \
162 #define PAD_FLUSH_LOCK(pad) G_STMT_START { \
163 GST_TRACE_OBJECT (pad, "Taking lock from thread %p", \
165 g_mutex_lock(&pad->priv->flush_lock); \
166 GST_TRACE_OBJECT (pad, "Took lock from thread %p", \
170 #define PAD_FLUSH_UNLOCK(pad) G_STMT_START { \
171 GST_TRACE_OBJECT (pad, "Releasing lock from thread %p", \
173 g_mutex_unlock(&pad->priv->flush_lock); \
174 GST_TRACE_OBJECT (pad, "Release lock from thread %p", \
178 #define SRC_LOCK(self) G_STMT_START { \
179 GST_TRACE_OBJECT (self, "Taking src lock from thread %p", \
181 g_mutex_lock(&self->priv->src_lock); \
182 GST_TRACE_OBJECT (self, "Took src lock from thread %p", \
186 #define SRC_UNLOCK(self) G_STMT_START { \
187 GST_TRACE_OBJECT (self, "Releasing src lock from thread %p", \
189 g_mutex_unlock(&self->priv->src_lock); \
190 GST_TRACE_OBJECT (self, "Released src lock from thread %p", \
194 #define SRC_WAIT(self) G_STMT_START { \
195 GST_LOG_OBJECT (self, "Waiting for src on thread %p", \
197 g_cond_wait(&(self->priv->src_cond), &(self->priv->src_lock)); \
198 GST_LOG_OBJECT (self, "DONE Waiting for src on thread %p", \
202 #define SRC_BROADCAST(self) G_STMT_START { \
203 GST_LOG_OBJECT (self, "Signaling src from thread %p", \
205 if (self->priv->aggregate_id) \
206 gst_clock_id_unschedule (self->priv->aggregate_id); \
207 g_cond_broadcast(&(self->priv->src_cond)); \
210 struct _GstAggregatorPadPrivate
212 /* Following fields are protected by the PAD_LOCK */
213 GstFlowReturn flow_return;
214 gboolean pending_flush_start;
215 gboolean pending_flush_stop;
216 gboolean pending_eos;
220 GstClockTime head_position;
221 GstClockTime tail_position;
222 GstClockTime head_time;
223 GstClockTime tail_time;
224 GstClockTime time_level;
230 /* This lock prevents a flush start processing happening while
231 * the chain function is also happening.
237 gst_aggregator_pad_flush (GstAggregatorPad * aggpad, GstAggregator * agg)
239 GstAggregatorPadClass *klass = GST_AGGREGATOR_PAD_GET_CLASS (aggpad);
242 aggpad->priv->pending_eos = FALSE;
243 aggpad->priv->eos = FALSE;
244 aggpad->priv->flow_return = GST_FLOW_OK;
245 GST_OBJECT_LOCK (aggpad);
246 gst_segment_init (&aggpad->segment, GST_FORMAT_UNDEFINED);
247 gst_segment_init (&aggpad->clip_segment, GST_FORMAT_UNDEFINED);
248 GST_OBJECT_UNLOCK (aggpad);
249 aggpad->priv->head_position = GST_CLOCK_TIME_NONE;
250 aggpad->priv->tail_position = GST_CLOCK_TIME_NONE;
251 aggpad->priv->head_time = GST_CLOCK_TIME_NONE;
252 aggpad->priv->tail_time = GST_CLOCK_TIME_NONE;
253 aggpad->priv->time_level = 0;
257 return klass->flush (aggpad, agg);
262 /*************************************
263 * GstAggregator implementation *
264 *************************************/
265 static GstElementClass *aggregator_parent_class = NULL;
267 /* All members are protected by the object lock unless otherwise noted */
269 struct _GstAggregatorPrivate
273 /* Our state is >= PAUSED */
274 gboolean running; /* protected by src_lock */
277 gboolean send_stream_start; /* protected by srcpad stream lock */
278 gboolean send_segment;
279 gboolean flush_seeking;
280 gboolean pending_flush_start;
281 gboolean send_eos; /* protected by srcpad stream lock */
283 GstCaps *srccaps; /* protected by the srcpad stream lock */
286 gboolean tags_changed;
288 gboolean peer_latency_live; /* protected by src_lock */
289 GstClockTime peer_latency_min; /* protected by src_lock */
290 GstClockTime peer_latency_max; /* protected by src_lock */
291 gboolean has_peer_latency;
293 GstClockTime sub_latency_min; /* protected by src_lock */
294 GstClockTime sub_latency_max; /* protected by src_lock */
297 GstClockID aggregate_id; /* protected by src_lock */
301 gboolean first_buffer;
302 GstAggregatorStartTimeSelection start_time_selection;
303 GstClockTime start_time;
306 gint64 latency; /* protected by both src_lock and all pad locks */
315 gboolean one_actually_seeked;
318 #define DEFAULT_LATENCY 0
319 #define DEFAULT_START_TIME_SELECTION GST_AGGREGATOR_START_TIME_SELECTION_ZERO
320 #define DEFAULT_START_TIME (-1)
326 PROP_START_TIME_SELECTION,
331 static GstFlowReturn gst_aggregator_pad_chain_internal (GstAggregator * self,
332 GstAggregatorPad * aggpad, GstBuffer * buffer, gboolean head);
335 * gst_aggregator_iterate_sinkpads:
336 * @self: The #GstAggregator
337 * @func: (scope call): The function to call.
338 * @user_data: (closure): The data to pass to @func.
340 * Iterate the sinkpads of aggregator to call a function on them.
342 * This method guarantees that @func will be called only once for each
346 gst_aggregator_iterate_sinkpads (GstAggregator * self,
347 GstAggregatorPadForeachFunc func, gpointer user_data)
349 gboolean result = FALSE;
351 gboolean done = FALSE;
352 GValue item = { 0, };
353 GList *seen_pads = NULL;
355 iter = gst_element_iterate_sink_pads (GST_ELEMENT (self));
361 switch (gst_iterator_next (iter, &item)) {
362 case GST_ITERATOR_OK:
364 GstAggregatorPad *pad;
366 pad = g_value_get_object (&item);
368 /* if already pushed, skip. FIXME, find something faster to tag pads */
369 if (pad == NULL || g_list_find (seen_pads, pad)) {
370 g_value_reset (&item);
374 GST_LOG_OBJECT (pad, "calling function %s on pad",
375 GST_DEBUG_FUNCPTR_NAME (func));
377 result = func (self, pad, user_data);
381 seen_pads = g_list_prepend (seen_pads, pad);
383 g_value_reset (&item);
386 case GST_ITERATOR_RESYNC:
387 gst_iterator_resync (iter);
389 case GST_ITERATOR_ERROR:
390 GST_ERROR_OBJECT (self,
391 "Could not iterate over internally linked pads");
394 case GST_ITERATOR_DONE:
399 g_value_unset (&item);
400 gst_iterator_free (iter);
402 if (seen_pads == NULL) {
403 GST_DEBUG_OBJECT (self, "No pad seen");
407 g_list_free (seen_pads);
414 gst_aggregator_pad_queue_is_empty (GstAggregatorPad * pad)
416 return (g_queue_peek_tail (&pad->priv->buffers) == NULL);
420 gst_aggregator_check_pads_ready (GstAggregator * self)
422 GstAggregatorPad *pad;
425 GST_LOG_OBJECT (self, "checking pads");
427 GST_OBJECT_LOCK (self);
429 sinkpads = GST_ELEMENT_CAST (self)->sinkpads;
430 if (sinkpads == NULL)
433 for (l = sinkpads; l != NULL; l = l->next) {
438 /* In live mode, having a single pad with buffers is enough to
439 * generate a start time from it. In non-live mode all pads need
442 if (self->priv->peer_latency_live &&
443 !gst_aggregator_pad_queue_is_empty (pad))
444 self->priv->first_buffer = FALSE;
446 if (gst_aggregator_pad_queue_is_empty (pad) && !pad->priv->eos) {
454 self->priv->first_buffer = FALSE;
456 GST_OBJECT_UNLOCK (self);
457 GST_LOG_OBJECT (self, "pads are ready");
462 GST_LOG_OBJECT (self, "pads not ready: no sink pads");
463 GST_OBJECT_UNLOCK (self);
468 GST_LOG_OBJECT (pad, "pad not ready to be aggregated yet");
469 GST_OBJECT_UNLOCK (self);
475 gst_aggregator_reset_flow_values (GstAggregator * self)
477 GST_OBJECT_LOCK (self);
478 self->priv->send_stream_start = TRUE;
479 self->priv->send_segment = TRUE;
480 gst_segment_init (&self->segment, GST_FORMAT_TIME);
481 self->priv->first_buffer = TRUE;
482 GST_OBJECT_UNLOCK (self);
486 gst_aggregator_push_mandatory_events (GstAggregator * self)
488 GstAggregatorPrivate *priv = self->priv;
489 GstEvent *segment = NULL;
490 GstEvent *tags = NULL;
492 if (self->priv->send_stream_start) {
495 GST_INFO_OBJECT (self, "pushing stream start");
496 /* stream-start (FIXME: create id based on input ids) */
497 g_snprintf (s_id, sizeof (s_id), "agg-%08x", g_random_int ());
498 if (!gst_pad_push_event (self->srcpad, gst_event_new_stream_start (s_id))) {
499 GST_WARNING_OBJECT (self->srcpad, "Sending stream start event failed");
501 self->priv->send_stream_start = FALSE;
504 if (self->priv->srccaps) {
506 GST_INFO_OBJECT (self, "pushing caps: %" GST_PTR_FORMAT,
507 self->priv->srccaps);
508 if (!gst_pad_push_event (self->srcpad,
509 gst_event_new_caps (self->priv->srccaps))) {
510 GST_WARNING_OBJECT (self->srcpad, "Sending caps event failed");
512 gst_caps_unref (self->priv->srccaps);
513 self->priv->srccaps = NULL;
516 GST_OBJECT_LOCK (self);
517 if (self->priv->send_segment && !self->priv->flush_seeking) {
518 segment = gst_event_new_segment (&self->segment);
520 if (!self->priv->seqnum)
521 self->priv->seqnum = gst_event_get_seqnum (segment);
523 gst_event_set_seqnum (segment, self->priv->seqnum);
524 self->priv->send_segment = FALSE;
526 GST_DEBUG_OBJECT (self, "pushing segment %" GST_PTR_FORMAT, segment);
529 if (priv->tags && priv->tags_changed && !self->priv->flush_seeking) {
530 tags = gst_event_new_tag (gst_tag_list_ref (priv->tags));
531 priv->tags_changed = FALSE;
533 GST_OBJECT_UNLOCK (self);
536 gst_pad_push_event (self->srcpad, segment);
538 gst_pad_push_event (self->srcpad, tags);
543 * gst_aggregator_set_src_caps:
544 * @self: The #GstAggregator
545 * @caps: The #GstCaps to set on the src pad.
547 * Sets the caps to be used on the src pad.
550 gst_aggregator_set_src_caps (GstAggregator * self, GstCaps * caps)
552 GST_PAD_STREAM_LOCK (self->srcpad);
553 gst_caps_replace (&self->priv->srccaps, caps);
554 gst_aggregator_push_mandatory_events (self);
555 GST_PAD_STREAM_UNLOCK (self->srcpad);
559 * gst_aggregator_finish_buffer:
560 * @self: The #GstAggregator
561 * @buffer: (transfer full): the #GstBuffer to push.
563 * This method will push the provided output buffer downstream. If needed,
564 * mandatory events such as stream-start, caps, and segment events will be
565 * sent before pushing the buffer.
568 gst_aggregator_finish_buffer (GstAggregator * self, GstBuffer * buffer)
570 gst_aggregator_push_mandatory_events (self);
572 GST_OBJECT_LOCK (self);
573 if (!self->priv->flush_seeking && gst_pad_is_active (self->srcpad)) {
574 GST_TRACE_OBJECT (self, "pushing buffer %" GST_PTR_FORMAT, buffer);
575 GST_OBJECT_UNLOCK (self);
576 return gst_pad_push (self->srcpad, buffer);
578 GST_INFO_OBJECT (self, "Not pushing (active: %i, flushing: %i)",
579 self->priv->flush_seeking, gst_pad_is_active (self->srcpad));
580 GST_OBJECT_UNLOCK (self);
581 gst_buffer_unref (buffer);
587 gst_aggregator_push_eos (GstAggregator * self)
590 gst_aggregator_push_mandatory_events (self);
592 event = gst_event_new_eos ();
594 GST_OBJECT_LOCK (self);
595 self->priv->send_eos = FALSE;
596 gst_event_set_seqnum (event, self->priv->seqnum);
597 GST_OBJECT_UNLOCK (self);
599 gst_pad_push_event (self->srcpad, event);
603 gst_aggregator_get_next_time (GstAggregator * self)
605 GstAggregatorClass *klass = GST_AGGREGATOR_GET_CLASS (self);
607 if (klass->get_next_time)
608 return klass->get_next_time (self);
610 return GST_CLOCK_TIME_NONE;
614 gst_aggregator_wait_and_check (GstAggregator * self, gboolean * timeout)
616 GstClockTime latency;
624 latency = gst_aggregator_get_latency_unlocked (self);
626 if (gst_aggregator_check_pads_ready (self)) {
627 GST_DEBUG_OBJECT (self, "all pads have data");
633 /* Before waiting, check if we're actually still running */
634 if (!self->priv->running || !self->priv->send_eos) {
640 start = gst_aggregator_get_next_time (self);
642 /* If we're not live, or if we use the running time
643 * of the first buffer as start time, we wait until
644 * all pads have buffers.
645 * Otherwise (i.e. if we are live!), we wait on the clock
646 * and if a pad does not have a buffer in time we ignore
649 if (!GST_CLOCK_TIME_IS_VALID (latency) ||
650 !GST_IS_CLOCK (GST_ELEMENT_CLOCK (self)) ||
651 !GST_CLOCK_TIME_IS_VALID (start) ||
652 (self->priv->first_buffer
653 && self->priv->start_time_selection ==
654 GST_AGGREGATOR_START_TIME_SELECTION_FIRST)) {
655 /* We wake up here when something happened, and below
656 * then check if we're ready now. If we return FALSE,
657 * we will be directly called again.
661 GstClockTime base_time, time;
663 GstClockReturn status;
664 GstClockTimeDiff jitter;
666 GST_DEBUG_OBJECT (self, "got subclass start time: %" GST_TIME_FORMAT,
667 GST_TIME_ARGS (start));
669 GST_OBJECT_LOCK (self);
670 base_time = GST_ELEMENT_CAST (self)->base_time;
671 clock = GST_ELEMENT_CLOCK (self);
673 gst_object_ref (clock);
674 GST_OBJECT_UNLOCK (self);
676 time = base_time + start;
679 GST_DEBUG_OBJECT (self, "possibly waiting for clock to reach %"
680 GST_TIME_FORMAT " (base %" GST_TIME_FORMAT " start %" GST_TIME_FORMAT
681 " latency %" GST_TIME_FORMAT " current %" GST_TIME_FORMAT ")",
682 GST_TIME_ARGS (time),
683 GST_TIME_ARGS (GST_ELEMENT_CAST (self)->base_time),
684 GST_TIME_ARGS (start), GST_TIME_ARGS (latency),
685 GST_TIME_ARGS (gst_clock_get_time (clock)));
687 self->priv->aggregate_id = gst_clock_new_single_shot_id (clock, time);
688 gst_object_unref (clock);
692 status = gst_clock_id_wait (self->priv->aggregate_id, &jitter);
695 if (self->priv->aggregate_id) {
696 gst_clock_id_unref (self->priv->aggregate_id);
697 self->priv->aggregate_id = NULL;
700 GST_DEBUG_OBJECT (self,
701 "clock returned %d (jitter: %s%" GST_TIME_FORMAT ")",
702 status, (jitter < 0 ? "-" : " "),
703 GST_TIME_ARGS ((jitter < 0 ? -jitter : jitter)));
706 if (status == GST_CLOCK_OK || status == GST_CLOCK_EARLY) {
713 res = gst_aggregator_check_pads_ready (self);
720 check_events (GstAggregator * self, GstAggregatorPad * pad, gpointer user_data)
722 GstEvent *event = NULL;
723 GstAggregatorClass *klass = NULL;
724 gboolean *processed_event = user_data;
730 if (gst_aggregator_pad_queue_is_empty (pad) && pad->priv->pending_eos) {
731 pad->priv->pending_eos = FALSE;
732 pad->priv->eos = TRUE;
734 if (GST_IS_EVENT (g_queue_peek_tail (&pad->priv->buffers))) {
735 event = g_queue_pop_tail (&pad->priv->buffers);
736 PAD_BROADCAST_EVENT (pad);
741 *processed_event = TRUE;
743 klass = GST_AGGREGATOR_GET_CLASS (self);
745 GST_LOG_OBJECT (pad, "Processing %" GST_PTR_FORMAT, event);
746 klass->sink_event (self, pad, event);
748 } while (event != NULL);
754 gst_aggregator_pad_set_flushing (GstAggregatorPad * aggpad,
755 GstFlowReturn flow_return, gboolean full)
760 if (flow_return == GST_FLOW_NOT_LINKED)
761 aggpad->priv->flow_return = MIN (flow_return, aggpad->priv->flow_return);
763 aggpad->priv->flow_return = flow_return;
765 item = g_queue_peek_head_link (&aggpad->priv->buffers);
767 GList *next = item->next;
769 /* In partial flush, we do like the pad, we get rid of non-sticky events
772 if (full || GST_IS_BUFFER (item->data) ||
773 GST_EVENT_TYPE (item->data) == GST_EVENT_EOS ||
774 GST_EVENT_TYPE (item->data) == GST_EVENT_SEGMENT ||
775 !GST_EVENT_IS_STICKY (item->data)) {
776 gst_mini_object_unref (item->data);
777 g_queue_delete_link (&aggpad->priv->buffers, item);
781 aggpad->priv->num_buffers = 0;
783 PAD_BROADCAST_EVENT (aggpad);
788 gst_aggregator_aggregate_func (GstAggregator * self)
790 GstAggregatorPrivate *priv = self->priv;
791 GstAggregatorClass *klass = GST_AGGREGATOR_GET_CLASS (self);
792 gboolean timeout = FALSE;
794 if (self->priv->running == FALSE) {
795 GST_DEBUG_OBJECT (self, "Not running anymore");
799 GST_LOG_OBJECT (self, "Checking aggregate");
800 while (priv->send_eos && priv->running) {
801 GstFlowReturn flow_return;
802 gboolean processed_event = FALSE;
804 gst_aggregator_iterate_sinkpads (self, check_events, NULL);
806 if (!gst_aggregator_wait_and_check (self, &timeout))
809 gst_aggregator_iterate_sinkpads (self, check_events, &processed_event);
813 GST_TRACE_OBJECT (self, "Actually aggregating!");
814 flow_return = klass->aggregate (self, timeout);
816 GST_OBJECT_LOCK (self);
817 if (flow_return == GST_FLOW_FLUSHING && priv->flush_seeking) {
818 /* We don't want to set the pads to flushing, but we want to
819 * stop the thread, so just break here */
820 GST_OBJECT_UNLOCK (self);
823 GST_OBJECT_UNLOCK (self);
825 if (flow_return == GST_FLOW_EOS || flow_return == GST_FLOW_ERROR) {
826 gst_aggregator_push_eos (self);
829 GST_LOG_OBJECT (self, "flow return is %s", gst_flow_get_name (flow_return));
831 if (flow_return != GST_FLOW_OK) {
834 GST_OBJECT_LOCK (self);
835 for (item = GST_ELEMENT (self)->sinkpads; item; item = item->next) {
836 GstAggregatorPad *aggpad = GST_AGGREGATOR_PAD (item->data);
838 gst_aggregator_pad_set_flushing (aggpad, flow_return, TRUE);
840 GST_OBJECT_UNLOCK (self);
845 /* Pause the task here, the only ways to get here are:
846 * 1) We're stopping, in which case the task is stopped anyway
847 * 2) We got a flow error above, in which case it might take
848 * some time to forward the flow return upstream and we
849 * would otherwise call the task function over and over
850 * again without doing anything
852 gst_pad_pause_task (self->srcpad);
856 gst_aggregator_start (GstAggregator * self)
858 GstAggregatorClass *klass;
861 self->priv->running = TRUE;
862 self->priv->send_stream_start = TRUE;
863 self->priv->send_segment = TRUE;
864 self->priv->send_eos = TRUE;
865 self->priv->srccaps = NULL;
867 klass = GST_AGGREGATOR_GET_CLASS (self);
870 result = klass->start (self);
878 _check_pending_flush_stop (GstAggregatorPad * pad)
883 res = (!pad->priv->pending_flush_stop && !pad->priv->pending_flush_start);
890 gst_aggregator_stop_srcpad_task (GstAggregator * self, GstEvent * flush_start)
894 GST_INFO_OBJECT (self, "%s srcpad task",
895 flush_start ? "Pausing" : "Stopping");
898 self->priv->running = FALSE;
899 SRC_BROADCAST (self);
903 res = gst_pad_push_event (self->srcpad, flush_start);
906 gst_pad_stop_task (self->srcpad);
912 gst_aggregator_start_srcpad_task (GstAggregator * self)
914 GST_INFO_OBJECT (self, "Starting srcpad task");
916 self->priv->running = TRUE;
917 gst_pad_start_task (GST_PAD (self->srcpad),
918 (GstTaskFunction) gst_aggregator_aggregate_func, self, NULL);
922 gst_aggregator_flush (GstAggregator * self)
924 GstFlowReturn ret = GST_FLOW_OK;
925 GstAggregatorPrivate *priv = self->priv;
926 GstAggregatorClass *klass = GST_AGGREGATOR_GET_CLASS (self);
928 GST_DEBUG_OBJECT (self, "Flushing everything");
929 GST_OBJECT_LOCK (self);
930 priv->send_segment = TRUE;
931 priv->flush_seeking = FALSE;
932 priv->tags_changed = FALSE;
933 GST_OBJECT_UNLOCK (self);
935 ret = klass->flush (self);
941 /* Called with GstAggregator's object lock held */
944 gst_aggregator_all_flush_stop_received_locked (GstAggregator * self)
947 GstAggregatorPad *tmppad;
949 for (tmp = GST_ELEMENT (self)->sinkpads; tmp; tmp = tmp->next) {
950 tmppad = (GstAggregatorPad *) tmp->data;
952 if (_check_pending_flush_stop (tmppad) == FALSE) {
953 GST_DEBUG_OBJECT (tmppad, "Is not last %i -- %i",
954 tmppad->priv->pending_flush_start, tmppad->priv->pending_flush_stop);
963 gst_aggregator_flush_start (GstAggregator * self, GstAggregatorPad * aggpad,
966 GstAggregatorPrivate *priv = self->priv;
967 GstAggregatorPadPrivate *padpriv = aggpad->priv;
969 gst_aggregator_pad_set_flushing (aggpad, GST_FLOW_FLUSHING, FALSE);
971 PAD_FLUSH_LOCK (aggpad);
973 if (padpriv->pending_flush_start) {
974 GST_DEBUG_OBJECT (aggpad, "Expecting FLUSH_STOP now");
976 padpriv->pending_flush_start = FALSE;
977 padpriv->pending_flush_stop = TRUE;
981 GST_OBJECT_LOCK (self);
982 if (priv->flush_seeking) {
983 /* If flush_seeking we forward the first FLUSH_START */
984 if (priv->pending_flush_start) {
985 priv->pending_flush_start = FALSE;
986 GST_OBJECT_UNLOCK (self);
988 GST_INFO_OBJECT (self, "Flushing, pausing srcpad task");
989 gst_aggregator_stop_srcpad_task (self, event);
991 GST_INFO_OBJECT (self, "Getting STREAM_LOCK while seeking");
992 GST_PAD_STREAM_LOCK (self->srcpad);
993 GST_LOG_OBJECT (self, "GOT STREAM_LOCK");
996 GST_OBJECT_UNLOCK (self);
997 gst_event_unref (event);
1000 GST_OBJECT_UNLOCK (self);
1001 gst_event_unref (event);
1003 PAD_FLUSH_UNLOCK (aggpad);
1006 /* Must be called with the the PAD_LOCK held */
1008 update_time_level (GstAggregatorPad * aggpad, gboolean head)
1011 if (GST_CLOCK_TIME_IS_VALID (aggpad->priv->head_position) &&
1012 aggpad->clip_segment.format == GST_FORMAT_TIME)
1013 aggpad->priv->head_time =
1014 gst_segment_to_running_time (&aggpad->clip_segment,
1015 GST_FORMAT_TIME, aggpad->priv->head_position);
1017 aggpad->priv->head_time = GST_CLOCK_TIME_NONE;
1019 if (GST_CLOCK_TIME_IS_VALID (aggpad->priv->tail_position) &&
1020 aggpad->segment.format == GST_FORMAT_TIME)
1021 aggpad->priv->tail_time =
1022 gst_segment_to_running_time (&aggpad->segment,
1023 GST_FORMAT_TIME, aggpad->priv->tail_position);
1025 aggpad->priv->tail_time = aggpad->priv->head_time;
1028 if (aggpad->priv->head_time == GST_CLOCK_TIME_NONE ||
1029 aggpad->priv->tail_time == GST_CLOCK_TIME_NONE) {
1030 aggpad->priv->time_level = 0;
1034 if (aggpad->priv->tail_time > aggpad->priv->head_time)
1035 aggpad->priv->time_level = 0;
1037 aggpad->priv->time_level = aggpad->priv->head_time -
1038 aggpad->priv->tail_time;
1042 /* GstAggregator vmethods default implementations */
1044 gst_aggregator_default_sink_event (GstAggregator * self,
1045 GstAggregatorPad * aggpad, GstEvent * event)
1047 gboolean res = TRUE;
1048 GstPad *pad = GST_PAD (aggpad);
1049 GstAggregatorPrivate *priv = self->priv;
1051 switch (GST_EVENT_TYPE (event)) {
1052 case GST_EVENT_FLUSH_START:
1054 gst_aggregator_flush_start (self, aggpad, event);
1055 /* We forward only in one case: right after flush_seeking */
1059 case GST_EVENT_FLUSH_STOP:
1061 GST_DEBUG_OBJECT (aggpad, "Got FLUSH_STOP");
1063 gst_aggregator_pad_flush (aggpad, self);
1064 GST_OBJECT_LOCK (self);
1065 if (priv->flush_seeking) {
1066 g_atomic_int_set (&aggpad->priv->pending_flush_stop, FALSE);
1067 if (gst_aggregator_all_flush_stop_received_locked (self)) {
1068 GST_OBJECT_UNLOCK (self);
1069 /* That means we received FLUSH_STOP/FLUSH_STOP on
1070 * all sinkpads -- Seeking is Done... sending FLUSH_STOP */
1071 gst_aggregator_flush (self);
1072 gst_pad_push_event (self->srcpad, event);
1075 priv->send_eos = TRUE;
1076 SRC_BROADCAST (self);
1079 GST_INFO_OBJECT (self, "Releasing source pad STREAM_LOCK");
1080 GST_PAD_STREAM_UNLOCK (self->srcpad);
1081 gst_aggregator_start_srcpad_task (self);
1083 GST_OBJECT_UNLOCK (self);
1086 GST_OBJECT_UNLOCK (self);
1089 /* We never forward the event */
1094 GST_DEBUG_OBJECT (aggpad, "EOS");
1096 /* We still have a buffer, and we don't want the subclass to have to
1097 * check for it. Mark pending_eos, eos will be set when steal_buffer is
1102 if (gst_aggregator_pad_queue_is_empty (aggpad)) {
1103 aggpad->priv->eos = TRUE;
1105 aggpad->priv->pending_eos = TRUE;
1107 PAD_UNLOCK (aggpad);
1109 SRC_BROADCAST (self);
1113 case GST_EVENT_SEGMENT:
1116 GST_OBJECT_LOCK (aggpad);
1117 gst_event_copy_segment (event, &aggpad->segment);
1118 update_time_level (aggpad, FALSE);
1119 GST_OBJECT_UNLOCK (aggpad);
1120 PAD_UNLOCK (aggpad);
1122 GST_OBJECT_LOCK (self);
1123 self->priv->seqnum = gst_event_get_seqnum (event);
1124 GST_OBJECT_UNLOCK (self);
1127 case GST_EVENT_STREAM_START:
1133 GstClockTime pts, endpts;
1134 GstClockTime duration;
1137 gst_event_parse_gap (event, &pts, &duration);
1138 gapbuf = gst_buffer_new ();
1140 if (GST_CLOCK_TIME_IS_VALID (duration))
1141 endpts = pts + duration;
1143 endpts = GST_CLOCK_TIME_NONE;
1145 GST_OBJECT_LOCK (aggpad);
1146 res = gst_segment_clip (&aggpad->segment, GST_FORMAT_TIME, pts, endpts,
1148 GST_OBJECT_UNLOCK (aggpad);
1151 GST_WARNING_OBJECT (self, "GAP event outside segment, dropping");
1155 if (GST_CLOCK_TIME_IS_VALID (endpts) && GST_CLOCK_TIME_IS_VALID (pts))
1156 duration = endpts - pts;
1158 duration = GST_CLOCK_TIME_NONE;
1160 GST_BUFFER_PTS (gapbuf) = pts;
1161 GST_BUFFER_DURATION (gapbuf) = duration;
1162 GST_BUFFER_FLAG_SET (gapbuf, GST_BUFFER_FLAG_GAP);
1163 GST_BUFFER_FLAG_SET (gapbuf, GST_BUFFER_FLAG_DROPPABLE);
1165 if (gst_aggregator_pad_chain_internal (self, aggpad, gapbuf, FALSE) !=
1167 GST_WARNING_OBJECT (self, "Failed to chain gap buffer");
1177 gst_event_parse_tag (event, &tags);
1179 if (gst_tag_list_get_scope (tags) == GST_TAG_SCOPE_STREAM) {
1180 gst_aggregator_merge_tags (self, tags, GST_TAG_MERGE_REPLACE);
1181 gst_event_unref (event);
1193 GST_DEBUG_OBJECT (pad, "Forwarding event: %" GST_PTR_FORMAT, event);
1194 return gst_pad_event_default (pad, GST_OBJECT (self), event);
1197 GST_DEBUG_OBJECT (pad, "Eating event: %" GST_PTR_FORMAT, event);
1199 gst_event_unref (event);
1204 static inline gboolean
1205 gst_aggregator_stop_pad (GstAggregator * self, GstAggregatorPad * pad,
1206 gpointer unused_udata)
1208 gst_aggregator_pad_flush (pad, self);
1214 gst_aggregator_stop (GstAggregator * agg)
1216 GstAggregatorClass *klass;
1219 gst_aggregator_reset_flow_values (agg);
1221 gst_aggregator_iterate_sinkpads (agg, gst_aggregator_stop_pad, NULL);
1223 klass = GST_AGGREGATOR_GET_CLASS (agg);
1226 result = klass->stop (agg);
1230 agg->priv->has_peer_latency = FALSE;
1231 agg->priv->peer_latency_live = FALSE;
1232 agg->priv->peer_latency_min = agg->priv->peer_latency_max = FALSE;
1234 if (agg->priv->tags)
1235 gst_tag_list_unref (agg->priv->tags);
1236 agg->priv->tags = NULL;
1241 /* GstElement vmethods implementations */
1242 static GstStateChangeReturn
1243 gst_aggregator_change_state (GstElement * element, GstStateChange transition)
1245 GstStateChangeReturn ret;
1246 GstAggregator *self = GST_AGGREGATOR (element);
1248 switch (transition) {
1249 case GST_STATE_CHANGE_READY_TO_PAUSED:
1250 if (!gst_aggregator_start (self))
1258 GST_ELEMENT_CLASS (aggregator_parent_class)->change_state (element,
1259 transition)) == GST_STATE_CHANGE_FAILURE)
1263 switch (transition) {
1264 case GST_STATE_CHANGE_PAUSED_TO_READY:
1265 if (!gst_aggregator_stop (self)) {
1266 /* What to do in this case? Error out? */
1267 GST_ERROR_OBJECT (self, "Subclass failed to stop.");
1279 GST_ERROR_OBJECT (element, "parent failed state change");
1284 GST_ERROR_OBJECT (element, "Subclass failed to start");
1285 return GST_STATE_CHANGE_FAILURE;
1290 gst_aggregator_release_pad (GstElement * element, GstPad * pad)
1292 GstAggregator *self = GST_AGGREGATOR (element);
1293 GstAggregatorPad *aggpad = GST_AGGREGATOR_PAD (pad);
1295 GST_INFO_OBJECT (pad, "Removing pad");
1298 gst_aggregator_pad_set_flushing (aggpad, GST_FLOW_FLUSHING, TRUE);
1299 gst_element_remove_pad (element, pad);
1301 self->priv->has_peer_latency = FALSE;
1302 SRC_BROADCAST (self);
1307 gst_aggregator_request_new_pad (GstElement * element,
1308 GstPadTemplate * templ, const gchar * req_name, const GstCaps * caps)
1310 GstAggregator *self;
1311 GstAggregatorPad *agg_pad;
1313 GstElementClass *klass = GST_ELEMENT_GET_CLASS (element);
1314 GstAggregatorPrivate *priv = GST_AGGREGATOR (element)->priv;
1316 self = GST_AGGREGATOR (element);
1318 if (templ == gst_element_class_get_pad_template (klass, "sink_%u")) {
1322 GST_OBJECT_LOCK (element);
1323 if (req_name == NULL || strlen (req_name) < 6
1324 || !g_str_has_prefix (req_name, "sink_")) {
1325 /* no name given when requesting the pad, use next available int */
1328 /* parse serial number from requested padname */
1329 serial = g_ascii_strtoull (&req_name[5], NULL, 10);
1330 if (serial >= priv->padcount)
1331 priv->padcount = serial;
1334 name = g_strdup_printf ("sink_%u", priv->padcount);
1335 agg_pad = g_object_new (GST_AGGREGATOR_GET_CLASS (self)->sinkpads_type,
1336 "name", name, "direction", GST_PAD_SINK, "template", templ, NULL);
1339 GST_OBJECT_UNLOCK (element);
1345 GST_DEBUG_OBJECT (element, "Adding pad %s", GST_PAD_NAME (agg_pad));
1346 self->priv->has_peer_latency = FALSE;
1349 gst_pad_set_active (GST_PAD (agg_pad), TRUE);
1351 /* add the pad to the element */
1352 gst_element_add_pad (element, GST_PAD (agg_pad));
1354 return GST_PAD (agg_pad);
1357 /* Must be called with SRC_LOCK held */
1360 gst_aggregator_query_latency_unlocked (GstAggregator * self, GstQuery * query)
1362 gboolean query_ret, live;
1363 GstClockTime our_latency, min, max;
1365 query_ret = gst_pad_query_default (self->srcpad, GST_OBJECT (self), query);
1368 GST_WARNING_OBJECT (self, "Latency query failed");
1372 gst_query_parse_latency (query, &live, &min, &max);
1374 our_latency = self->priv->latency;
1376 if (G_UNLIKELY (!GST_CLOCK_TIME_IS_VALID (min))) {
1377 GST_ERROR_OBJECT (self, "Invalid minimum latency %" GST_TIME_FORMAT
1378 ". Please file a bug at " PACKAGE_BUGREPORT ".", GST_TIME_ARGS (min));
1382 if (min > max && GST_CLOCK_TIME_IS_VALID (max)) {
1383 GST_ELEMENT_WARNING (self, CORE, CLOCK, (NULL),
1384 ("Impossible to configure latency: max %" GST_TIME_FORMAT " < min %"
1385 GST_TIME_FORMAT ". Add queues or other buffering elements.",
1386 GST_TIME_ARGS (max), GST_TIME_ARGS (min)));
1390 self->priv->peer_latency_live = live;
1391 self->priv->peer_latency_min = min;
1392 self->priv->peer_latency_max = max;
1393 self->priv->has_peer_latency = TRUE;
1397 min += self->priv->sub_latency_min;
1398 if (GST_CLOCK_TIME_IS_VALID (self->priv->sub_latency_max)
1399 && GST_CLOCK_TIME_IS_VALID (max))
1400 max += self->priv->sub_latency_max + our_latency;
1402 max = GST_CLOCK_TIME_NONE;
1404 if (live && min > max) {
1405 GST_ELEMENT_WARNING (self, CORE, NEGOTIATION,
1406 ("%s", "Latency too big"),
1407 ("The requested latency value is too big for the current pipeline. "
1408 "Limiting to %" G_GINT64_FORMAT, max));
1410 /* FIXME: This could in theory become negative, but in
1411 * that case all is lost anyway */
1412 self->priv->latency -= min - max;
1413 /* FIXME: shouldn't we g_object_notify() the change here? */
1416 SRC_BROADCAST (self);
1418 GST_DEBUG_OBJECT (self, "configured latency live:%s min:%" G_GINT64_FORMAT
1419 " max:%" G_GINT64_FORMAT, live ? "true" : "false", min, max);
1421 gst_query_set_latency (query, live, min, max);
1427 * MUST be called with the src_lock held.
1429 * See gst_aggregator_get_latency() for doc
1432 gst_aggregator_get_latency_unlocked (GstAggregator * self)
1434 GstClockTime latency;
1436 g_return_val_if_fail (GST_IS_AGGREGATOR (self), 0);
1438 if (!self->priv->has_peer_latency) {
1439 GstQuery *query = gst_query_new_latency ();
1442 ret = gst_aggregator_query_latency_unlocked (self, query);
1443 gst_query_unref (query);
1445 return GST_CLOCK_TIME_NONE;
1448 if (!self->priv->has_peer_latency || !self->priv->peer_latency_live)
1449 return GST_CLOCK_TIME_NONE;
1451 /* latency_min is never GST_CLOCK_TIME_NONE by construction */
1452 latency = self->priv->peer_latency_min;
1455 latency += self->priv->latency;
1456 latency += self->priv->sub_latency_min;
1462 * gst_aggregator_get_latency:
1463 * @self: a #GstAggregator
1465 * Retrieves the latency values reported by @self in response to the latency
1466 * query, or %GST_CLOCK_TIME_NONE if there is not live source connected and the element
1467 * will not wait for the clock.
1469 * Typically only called by subclasses.
1471 * Returns: The latency or %GST_CLOCK_TIME_NONE if the element does not sync
1474 gst_aggregator_get_latency (GstAggregator * self)
1479 ret = gst_aggregator_get_latency_unlocked (self);
1486 gst_aggregator_send_event (GstElement * element, GstEvent * event)
1488 GstAggregator *self = GST_AGGREGATOR (element);
1490 GST_STATE_LOCK (element);
1491 if (GST_EVENT_TYPE (event) == GST_EVENT_SEEK &&
1492 GST_STATE (element) < GST_STATE_PAUSED) {
1496 GstSeekType start_type, stop_type;
1499 gst_event_parse_seek (event, &rate, &fmt, &flags, &start_type,
1500 &start, &stop_type, &stop);
1502 GST_OBJECT_LOCK (self);
1503 gst_segment_do_seek (&self->segment, rate, fmt, flags, start_type, start,
1504 stop_type, stop, NULL);
1505 self->priv->seqnum = gst_event_get_seqnum (event);
1506 self->priv->first_buffer = FALSE;
1507 GST_OBJECT_UNLOCK (self);
1509 GST_DEBUG_OBJECT (element, "Storing segment %" GST_PTR_FORMAT, event);
1511 GST_STATE_UNLOCK (element);
1514 return GST_ELEMENT_CLASS (aggregator_parent_class)->send_event (element,
1519 gst_aggregator_default_src_query (GstAggregator * self, GstQuery * query)
1521 gboolean res = TRUE;
1523 switch (GST_QUERY_TYPE (query)) {
1524 case GST_QUERY_SEEKING:
1528 /* don't pass it along as some (file)sink might claim it does
1529 * whereas with a collectpads in between that will not likely work */
1530 gst_query_parse_seeking (query, &format, NULL, NULL, NULL);
1531 gst_query_set_seeking (query, format, FALSE, 0, -1);
1536 case GST_QUERY_LATENCY:
1538 res = gst_aggregator_query_latency_unlocked (self, query);
1542 return gst_pad_query_default (self->srcpad, GST_OBJECT (self), query);
1549 gst_aggregator_event_forward_func (GstPad * pad, gpointer user_data)
1551 EventData *evdata = user_data;
1552 gboolean ret = TRUE;
1553 GstPad *peer = gst_pad_get_peer (pad);
1554 GstAggregatorPad *aggpad = GST_AGGREGATOR_PAD (pad);
1557 ret = gst_pad_send_event (peer, gst_event_ref (evdata->event));
1558 GST_DEBUG_OBJECT (pad, "return of event push is %d", ret);
1559 gst_object_unref (peer);
1563 if (GST_EVENT_TYPE (evdata->event) == GST_EVENT_SEEK)
1564 GST_ERROR_OBJECT (pad, "Event %" GST_PTR_FORMAT " failed", evdata->event);
1566 if (GST_EVENT_TYPE (evdata->event) == GST_EVENT_SEEK) {
1567 GstQuery *seeking = gst_query_new_seeking (GST_FORMAT_TIME);
1569 if (gst_pad_query (peer, seeking)) {
1572 gst_query_parse_seeking (seeking, NULL, &seekable, NULL, NULL);
1574 if (seekable == FALSE) {
1575 GST_INFO_OBJECT (pad,
1576 "Source not seekable, We failed but it does not matter!");
1581 GST_ERROR_OBJECT (pad, "Query seeking FAILED");
1584 gst_query_unref (seeking);
1587 if (evdata->flush) {
1589 aggpad->priv->pending_flush_start = FALSE;
1590 aggpad->priv->pending_flush_stop = FALSE;
1591 PAD_UNLOCK (aggpad);
1594 evdata->one_actually_seeked = TRUE;
1597 evdata->result &= ret;
1599 /* Always send to all pads */
1604 gst_aggregator_forward_event_to_all_sinkpads (GstAggregator * self,
1605 GstEvent * event, gboolean flush)
1609 evdata.event = event;
1610 evdata.result = TRUE;
1611 evdata.flush = flush;
1612 evdata.one_actually_seeked = FALSE;
1614 /* We first need to set all pads as flushing in a first pass
1615 * as flush_start flush_stop is sometimes sent synchronously
1616 * while we send the seek event */
1620 GST_OBJECT_LOCK (self);
1621 for (l = GST_ELEMENT_CAST (self)->sinkpads; l != NULL; l = l->next) {
1622 GstAggregatorPad *pad = l->data;
1625 pad->priv->pending_flush_start = TRUE;
1626 pad->priv->pending_flush_stop = FALSE;
1629 GST_OBJECT_UNLOCK (self);
1632 gst_pad_forward (self->srcpad, gst_aggregator_event_forward_func, &evdata);
1634 gst_event_unref (event);
1640 gst_aggregator_do_seek (GstAggregator * self, GstEvent * event)
1645 GstSeekType start_type, stop_type;
1649 GstAggregatorPrivate *priv = self->priv;
1651 gst_event_parse_seek (event, &rate, &fmt, &flags, &start_type,
1652 &start, &stop_type, &stop);
1654 GST_INFO_OBJECT (self, "starting SEEK");
1656 flush = flags & GST_SEEK_FLAG_FLUSH;
1658 GST_OBJECT_LOCK (self);
1660 priv->pending_flush_start = TRUE;
1661 priv->flush_seeking = TRUE;
1664 gst_segment_do_seek (&self->segment, rate, fmt, flags, start_type, start,
1665 stop_type, stop, NULL);
1667 /* Seeking sets a position */
1668 self->priv->first_buffer = FALSE;
1669 GST_OBJECT_UNLOCK (self);
1671 /* forward the seek upstream */
1672 evdata = gst_aggregator_forward_event_to_all_sinkpads (self, event, flush);
1675 if (!evdata.result || !evdata.one_actually_seeked) {
1676 GST_OBJECT_LOCK (self);
1677 priv->flush_seeking = FALSE;
1678 priv->pending_flush_start = FALSE;
1679 GST_OBJECT_UNLOCK (self);
1682 GST_INFO_OBJECT (self, "seek done, result: %d", evdata.result);
1684 return evdata.result;
1688 gst_aggregator_default_src_event (GstAggregator * self, GstEvent * event)
1691 gboolean res = TRUE;
1693 switch (GST_EVENT_TYPE (event)) {
1694 case GST_EVENT_SEEK:
1696 gst_event_ref (event);
1697 res = gst_aggregator_do_seek (self, event);
1698 gst_event_unref (event);
1702 case GST_EVENT_NAVIGATION:
1704 /* navigation is rather pointless. */
1706 gst_event_unref (event);
1715 evdata = gst_aggregator_forward_event_to_all_sinkpads (self, event, FALSE);
1716 res = evdata.result;
1723 gst_aggregator_src_pad_event_func (GstPad * pad, GstObject * parent,
1726 GstAggregatorClass *klass = GST_AGGREGATOR_GET_CLASS (parent);
1728 return klass->src_event (GST_AGGREGATOR (parent), event);
1732 gst_aggregator_src_pad_query_func (GstPad * pad, GstObject * parent,
1735 GstAggregatorClass *klass = GST_AGGREGATOR_GET_CLASS (parent);
1737 return klass->src_query (GST_AGGREGATOR (parent), query);
1741 gst_aggregator_src_pad_activate_mode_func (GstPad * pad,
1742 GstObject * parent, GstPadMode mode, gboolean active)
1744 GstAggregator *self = GST_AGGREGATOR (parent);
1745 GstAggregatorClass *klass = GST_AGGREGATOR_GET_CLASS (parent);
1747 if (klass->src_activate) {
1748 if (klass->src_activate (self, mode, active) == FALSE) {
1753 if (active == TRUE) {
1755 case GST_PAD_MODE_PUSH:
1757 GST_INFO_OBJECT (pad, "Activating pad!");
1758 gst_aggregator_start_srcpad_task (self);
1763 GST_ERROR_OBJECT (pad, "Only supported mode is PUSH");
1770 GST_INFO_OBJECT (self, "Deactivating srcpad");
1771 gst_aggregator_stop_srcpad_task (self, FALSE);
1777 gst_aggregator_default_sink_query (GstAggregator * self,
1778 GstAggregatorPad * aggpad, GstQuery * query)
1780 GstPad *pad = GST_PAD (aggpad);
1782 return gst_pad_query_default (pad, GST_OBJECT (self), query);
1786 gst_aggregator_finalize (GObject * object)
1788 GstAggregator *self = (GstAggregator *) object;
1790 g_mutex_clear (&self->priv->src_lock);
1791 g_cond_clear (&self->priv->src_cond);
1793 G_OBJECT_CLASS (aggregator_parent_class)->finalize (object);
1797 * gst_aggregator_set_latency_property:
1798 * @agg: a #GstAggregator
1799 * @latency: the new latency value (in nanoseconds).
1801 * Sets the new latency value to @latency. This value is used to limit the
1802 * amount of time a pad waits for data to appear before considering the pad
1806 gst_aggregator_set_latency_property (GstAggregator * self, gint64 latency)
1810 g_return_if_fail (GST_IS_AGGREGATOR (self));
1811 g_return_if_fail (GST_CLOCK_TIME_IS_VALID (latency));
1814 changed = (self->priv->latency != latency);
1819 GST_OBJECT_LOCK (self);
1820 /* First lock all the pads */
1821 for (item = GST_ELEMENT_CAST (self)->sinkpads; item; item = item->next) {
1822 GstAggregatorPad *aggpad = GST_AGGREGATOR_PAD (item->data);
1826 self->priv->latency = latency;
1828 SRC_BROADCAST (self);
1830 /* Now wake up the pads */
1831 for (item = GST_ELEMENT_CAST (self)->sinkpads; item; item = item->next) {
1832 GstAggregatorPad *aggpad = GST_AGGREGATOR_PAD (item->data);
1833 PAD_BROADCAST_EVENT (aggpad);
1834 PAD_UNLOCK (aggpad);
1836 GST_OBJECT_UNLOCK (self);
1842 gst_element_post_message (GST_ELEMENT_CAST (self),
1843 gst_message_new_latency (GST_OBJECT_CAST (self)));
1847 * gst_aggregator_get_latency_property:
1848 * @agg: a #GstAggregator
1850 * Gets the latency value. See gst_aggregator_set_latency for
1853 * Returns: The time in nanoseconds to wait for data to arrive on a sink pad
1854 * before a pad is deemed unresponsive. A value of -1 means an
1858 gst_aggregator_get_latency_property (GstAggregator * agg)
1862 g_return_val_if_fail (GST_IS_AGGREGATOR (agg), -1);
1864 GST_OBJECT_LOCK (agg);
1865 res = agg->priv->latency;
1866 GST_OBJECT_UNLOCK (agg);
1872 gst_aggregator_set_property (GObject * object, guint prop_id,
1873 const GValue * value, GParamSpec * pspec)
1875 GstAggregator *agg = GST_AGGREGATOR (object);
1879 gst_aggregator_set_latency_property (agg, g_value_get_int64 (value));
1881 case PROP_START_TIME_SELECTION:
1882 agg->priv->start_time_selection = g_value_get_enum (value);
1884 case PROP_START_TIME:
1885 agg->priv->start_time = g_value_get_uint64 (value);
1888 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1894 gst_aggregator_get_property (GObject * object, guint prop_id,
1895 GValue * value, GParamSpec * pspec)
1897 GstAggregator *agg = GST_AGGREGATOR (object);
1901 g_value_set_int64 (value, gst_aggregator_get_latency_property (agg));
1903 case PROP_START_TIME_SELECTION:
1904 g_value_set_enum (value, agg->priv->start_time_selection);
1906 case PROP_START_TIME:
1907 g_value_set_uint64 (value, agg->priv->start_time);
1910 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1915 /* GObject vmethods implementations */
1917 gst_aggregator_class_init (GstAggregatorClass * klass)
1919 GObjectClass *gobject_class = (GObjectClass *) klass;
1920 GstElementClass *gstelement_class = (GstElementClass *) klass;
1922 aggregator_parent_class = g_type_class_peek_parent (klass);
1923 g_type_class_add_private (klass, sizeof (GstAggregatorPrivate));
1925 GST_DEBUG_CATEGORY_INIT (aggregator_debug, "aggregator",
1926 GST_DEBUG_FG_MAGENTA, "GstAggregator");
1928 klass->sinkpads_type = GST_TYPE_AGGREGATOR_PAD;
1930 klass->sink_event = gst_aggregator_default_sink_event;
1931 klass->sink_query = gst_aggregator_default_sink_query;
1933 klass->src_event = gst_aggregator_default_src_event;
1934 klass->src_query = gst_aggregator_default_src_query;
1936 gstelement_class->request_new_pad =
1937 GST_DEBUG_FUNCPTR (gst_aggregator_request_new_pad);
1938 gstelement_class->send_event = GST_DEBUG_FUNCPTR (gst_aggregator_send_event);
1939 gstelement_class->release_pad =
1940 GST_DEBUG_FUNCPTR (gst_aggregator_release_pad);
1941 gstelement_class->change_state =
1942 GST_DEBUG_FUNCPTR (gst_aggregator_change_state);
1944 gobject_class->set_property = gst_aggregator_set_property;
1945 gobject_class->get_property = gst_aggregator_get_property;
1946 gobject_class->finalize = gst_aggregator_finalize;
1948 g_object_class_install_property (gobject_class, PROP_LATENCY,
1949 g_param_spec_int64 ("latency", "Buffer latency",
1950 "Additional latency in live mode to allow upstream "
1951 "to take longer to produce buffers for the current "
1952 "position (in nanoseconds)", 0,
1953 (G_MAXLONG == G_MAXINT64) ? G_MAXINT64 : (G_MAXLONG * GST_SECOND - 1),
1954 DEFAULT_LATENCY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
1956 g_object_class_install_property (gobject_class, PROP_START_TIME_SELECTION,
1957 g_param_spec_enum ("start-time-selection", "Start Time Selection",
1958 "Decides which start time is output",
1959 gst_aggregator_start_time_selection_get_type (),
1960 DEFAULT_START_TIME_SELECTION,
1961 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
1963 g_object_class_install_property (gobject_class, PROP_START_TIME,
1964 g_param_spec_uint64 ("start-time", "Start Time",
1965 "Start time to use if start-time-selection=set", 0,
1967 DEFAULT_START_TIME, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
1969 GST_DEBUG_REGISTER_FUNCPTR (gst_aggregator_stop_pad);
1973 gst_aggregator_init (GstAggregator * self, GstAggregatorClass * klass)
1975 GstPadTemplate *pad_template;
1976 GstAggregatorPrivate *priv;
1978 g_return_if_fail (klass->aggregate != NULL);
1981 G_TYPE_INSTANCE_GET_PRIVATE (self, GST_TYPE_AGGREGATOR,
1982 GstAggregatorPrivate);
1987 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (klass), "src");
1988 g_return_if_fail (pad_template != NULL);
1990 priv->padcount = -1;
1991 priv->tags_changed = FALSE;
1993 self->priv->peer_latency_live = FALSE;
1994 self->priv->peer_latency_min = self->priv->sub_latency_min = 0;
1995 self->priv->peer_latency_max = self->priv->sub_latency_max = 0;
1996 self->priv->has_peer_latency = FALSE;
1997 gst_aggregator_reset_flow_values (self);
1999 self->srcpad = gst_pad_new_from_template (pad_template, "src");
2001 gst_pad_set_event_function (self->srcpad,
2002 GST_DEBUG_FUNCPTR (gst_aggregator_src_pad_event_func));
2003 gst_pad_set_query_function (self->srcpad,
2004 GST_DEBUG_FUNCPTR (gst_aggregator_src_pad_query_func));
2005 gst_pad_set_activatemode_function (self->srcpad,
2006 GST_DEBUG_FUNCPTR (gst_aggregator_src_pad_activate_mode_func));
2008 gst_element_add_pad (GST_ELEMENT (self), self->srcpad);
2010 self->priv->latency = DEFAULT_LATENCY;
2011 self->priv->start_time_selection = DEFAULT_START_TIME_SELECTION;
2012 self->priv->start_time = DEFAULT_START_TIME;
2014 g_mutex_init (&self->priv->src_lock);
2015 g_cond_init (&self->priv->src_cond);
2018 /* we can't use G_DEFINE_ABSTRACT_TYPE because we need the klass in the _init
2019 * method to get to the padtemplates */
2021 gst_aggregator_get_type (void)
2023 static volatile gsize type = 0;
2025 if (g_once_init_enter (&type)) {
2027 static const GTypeInfo info = {
2028 sizeof (GstAggregatorClass),
2031 (GClassInitFunc) gst_aggregator_class_init,
2034 sizeof (GstAggregator),
2036 (GInstanceInitFunc) gst_aggregator_init,
2039 _type = g_type_register_static (GST_TYPE_ELEMENT,
2040 "GstAggregator", &info, G_TYPE_FLAG_ABSTRACT);
2041 g_once_init_leave (&type, _type);
2046 /* Must be called with SRC lock and PAD lock held */
2048 gst_aggregator_pad_has_space (GstAggregator * self, GstAggregatorPad * aggpad)
2050 /* Empty queue always has space */
2051 if (g_queue_get_length (&aggpad->priv->buffers) == 0)
2054 /* We also want at least two buffers, one is being processed and one is ready
2055 * for the next iteration when we operate in live mode. */
2056 if (self->priv->peer_latency_live && aggpad->priv->num_buffers < 2)
2059 /* zero latency, if there is a buffer, it's full */
2060 if (self->priv->latency == 0)
2063 /* Allow no more buffers than the latency */
2064 return (aggpad->priv->time_level <= self->priv->latency);
2067 /* Must be called with the PAD_LOCK held */
2069 apply_buffer (GstAggregatorPad * aggpad, GstBuffer * buffer, gboolean head)
2071 GstClockTime timestamp;
2073 if (GST_BUFFER_DTS_IS_VALID (buffer))
2074 timestamp = GST_BUFFER_DTS (buffer);
2076 timestamp = GST_BUFFER_PTS (buffer);
2078 if (timestamp == GST_CLOCK_TIME_NONE) {
2080 timestamp = aggpad->priv->head_position;
2082 timestamp = aggpad->priv->tail_position;
2086 if (GST_BUFFER_DURATION_IS_VALID (buffer))
2087 timestamp += GST_BUFFER_DURATION (buffer);
2090 aggpad->priv->head_position = timestamp;
2092 aggpad->priv->tail_position = timestamp;
2094 update_time_level (aggpad, head);
2097 static GstFlowReturn
2098 gst_aggregator_pad_chain_internal (GstAggregator * self,
2099 GstAggregatorPad * aggpad, GstBuffer * buffer, gboolean head)
2101 GstBuffer *actual_buf = buffer;
2102 GstAggregatorClass *aggclass = GST_AGGREGATOR_GET_CLASS (self);
2103 GstFlowReturn flow_return;
2104 GstClockTime buf_pts;
2106 GST_DEBUG_OBJECT (aggpad, "Start chaining a buffer %" GST_PTR_FORMAT, buffer);
2108 PAD_FLUSH_LOCK (aggpad);
2111 flow_return = aggpad->priv->flow_return;
2112 if (flow_return != GST_FLOW_OK)
2115 if (aggpad->priv->pending_eos == TRUE)
2118 flow_return = aggpad->priv->flow_return;
2119 if (flow_return != GST_FLOW_OK)
2122 PAD_UNLOCK (aggpad);
2124 if (aggclass->clip && head) {
2125 aggclass->clip (self, aggpad, buffer, &actual_buf);
2128 if (actual_buf == NULL) {
2129 GST_LOG_OBJECT (actual_buf, "Buffer dropped by clip function");
2133 buf_pts = GST_BUFFER_PTS (actual_buf);
2138 if (gst_aggregator_pad_has_space (self, aggpad)
2139 && aggpad->priv->flow_return == GST_FLOW_OK) {
2141 g_queue_push_head (&aggpad->priv->buffers, actual_buf);
2143 g_queue_push_tail (&aggpad->priv->buffers, actual_buf);
2144 apply_buffer (aggpad, actual_buf, head);
2145 aggpad->priv->num_buffers++;
2146 actual_buf = buffer = NULL;
2147 SRC_BROADCAST (self);
2151 flow_return = aggpad->priv->flow_return;
2152 if (flow_return != GST_FLOW_OK) {
2156 GST_DEBUG_OBJECT (aggpad, "Waiting for buffer to be consumed");
2158 PAD_WAIT_EVENT (aggpad);
2160 PAD_UNLOCK (aggpad);
2163 if (self->priv->first_buffer) {
2164 GstClockTime start_time;
2166 switch (self->priv->start_time_selection) {
2167 case GST_AGGREGATOR_START_TIME_SELECTION_ZERO:
2171 case GST_AGGREGATOR_START_TIME_SELECTION_FIRST:
2172 if (aggpad->segment.format == GST_FORMAT_TIME) {
2173 start_time = buf_pts;
2174 if (start_time != -1) {
2175 start_time = MAX (start_time, aggpad->segment.start);
2177 gst_segment_to_running_time (&aggpad->segment, GST_FORMAT_TIME,
2182 GST_WARNING_OBJECT (aggpad,
2183 "Ignoring request of selecting the first start time "
2184 "as the segment is a %s segment instead of a time segment",
2185 gst_format_get_name (aggpad->segment.format));
2188 case GST_AGGREGATOR_START_TIME_SELECTION_SET:
2189 start_time = self->priv->start_time;
2190 if (start_time == -1)
2195 if (start_time != -1) {
2196 if (self->segment.position == -1)
2197 self->segment.position = start_time;
2199 self->segment.position = MIN (start_time, self->segment.position);
2200 self->segment.start = MIN (start_time, self->segment.start);
2201 self->segment.time = MIN (start_time, self->segment.time);
2203 GST_DEBUG_OBJECT (self, "Selecting start time %" GST_TIME_FORMAT,
2204 GST_TIME_ARGS (start_time));
2208 PAD_UNLOCK (aggpad);
2213 PAD_FLUSH_UNLOCK (aggpad);
2215 GST_DEBUG_OBJECT (aggpad, "Done chaining");
2220 PAD_UNLOCK (aggpad);
2221 PAD_FLUSH_UNLOCK (aggpad);
2223 GST_DEBUG_OBJECT (aggpad, "Pad is %s, dropping buffer",
2224 gst_flow_get_name (flow_return));
2226 gst_buffer_unref (buffer);
2231 PAD_UNLOCK (aggpad);
2232 PAD_FLUSH_UNLOCK (aggpad);
2234 gst_buffer_unref (buffer);
2235 GST_DEBUG_OBJECT (aggpad, "We are EOS already...");
2237 return GST_FLOW_EOS;
2240 static GstFlowReturn
2241 gst_aggregator_pad_chain (GstPad * pad, GstObject * object, GstBuffer * buffer)
2243 return gst_aggregator_pad_chain_internal (GST_AGGREGATOR_CAST (object),
2244 GST_AGGREGATOR_PAD_CAST (pad), buffer, TRUE);
2248 gst_aggregator_pad_query_func (GstPad * pad, GstObject * parent,
2251 GstAggregatorPad *aggpad = GST_AGGREGATOR_PAD (pad);
2252 GstAggregatorClass *klass = GST_AGGREGATOR_GET_CLASS (parent);
2254 if (GST_QUERY_IS_SERIALIZED (query)) {
2257 while (!gst_aggregator_pad_queue_is_empty (aggpad)
2258 && aggpad->priv->flow_return == GST_FLOW_OK) {
2259 GST_DEBUG_OBJECT (aggpad, "Waiting for buffer to be consumed");
2260 PAD_WAIT_EVENT (aggpad);
2263 if (aggpad->priv->flow_return != GST_FLOW_OK)
2266 PAD_UNLOCK (aggpad);
2269 return klass->sink_query (GST_AGGREGATOR (parent),
2270 GST_AGGREGATOR_PAD (pad), query);
2273 GST_DEBUG_OBJECT (aggpad, "Pad is %s, dropping query",
2274 gst_flow_get_name (aggpad->priv->flow_return));
2275 PAD_UNLOCK (aggpad);
2280 gst_aggregator_pad_event_func (GstPad * pad, GstObject * parent,
2283 GstAggregator *self = GST_AGGREGATOR (parent);
2284 GstAggregatorPad *aggpad = GST_AGGREGATOR_PAD (pad);
2285 GstAggregatorClass *klass = GST_AGGREGATOR_GET_CLASS (parent);
2287 if (GST_EVENT_IS_SERIALIZED (event) && GST_EVENT_TYPE (event) != GST_EVENT_EOS
2288 /* && GST_EVENT_TYPE (event) != GST_EVENT_SEGMENT_DONE */ ) {
2292 if (aggpad->priv->flow_return != GST_FLOW_OK
2293 && GST_EVENT_TYPE (event) != GST_EVENT_FLUSH_STOP)
2296 if (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) {
2297 GST_OBJECT_LOCK (aggpad);
2298 gst_event_copy_segment (event, &aggpad->clip_segment);
2299 aggpad->priv->head_position = aggpad->clip_segment.position;
2300 update_time_level (aggpad, TRUE);
2301 GST_OBJECT_UNLOCK (aggpad);
2304 if (!gst_aggregator_pad_queue_is_empty (aggpad) &&
2305 GST_EVENT_TYPE (event) != GST_EVENT_FLUSH_STOP) {
2306 GST_DEBUG_OBJECT (aggpad, "Store event in queue: %" GST_PTR_FORMAT,
2308 g_queue_push_head (&aggpad->priv->buffers, event);
2310 SRC_BROADCAST (self);
2312 PAD_UNLOCK (aggpad);
2317 return klass->sink_event (self, aggpad, event);
2322 GST_DEBUG_OBJECT (aggpad, "Pad is %s, dropping event",
2323 gst_flow_get_name (aggpad->priv->flow_return));
2324 PAD_UNLOCK (aggpad);
2326 if (GST_EVENT_IS_STICKY (event))
2327 gst_pad_store_sticky_event (pad, event);
2328 gst_event_unref (event);
2333 gst_aggregator_pad_activate_mode_func (GstPad * pad,
2334 GstObject * parent, GstPadMode mode, gboolean active)
2336 GstAggregator *self = GST_AGGREGATOR (parent);
2337 GstAggregatorPad *aggpad = GST_AGGREGATOR_PAD (pad);
2339 if (active == FALSE) {
2341 gst_aggregator_pad_set_flushing (aggpad, GST_FLOW_FLUSHING, TRUE);
2342 SRC_BROADCAST (self);
2346 aggpad->priv->flow_return = GST_FLOW_OK;
2347 PAD_BROADCAST_EVENT (aggpad);
2348 PAD_UNLOCK (aggpad);
2354 /***********************************
2355 * GstAggregatorPad implementation *
2356 ************************************/
2357 G_DEFINE_TYPE (GstAggregatorPad, gst_aggregator_pad, GST_TYPE_PAD);
2360 gst_aggregator_pad_constructed (GObject * object)
2362 GstPad *pad = GST_PAD (object);
2364 gst_pad_set_chain_function (pad,
2365 GST_DEBUG_FUNCPTR (gst_aggregator_pad_chain));
2366 gst_pad_set_event_function (pad,
2367 GST_DEBUG_FUNCPTR (gst_aggregator_pad_event_func));
2368 gst_pad_set_query_function (pad,
2369 GST_DEBUG_FUNCPTR (gst_aggregator_pad_query_func));
2370 gst_pad_set_activatemode_function (pad,
2371 GST_DEBUG_FUNCPTR (gst_aggregator_pad_activate_mode_func));
2375 gst_aggregator_pad_finalize (GObject * object)
2377 GstAggregatorPad *pad = (GstAggregatorPad *) object;
2379 g_cond_clear (&pad->priv->event_cond);
2380 g_mutex_clear (&pad->priv->flush_lock);
2381 g_mutex_clear (&pad->priv->lock);
2383 G_OBJECT_CLASS (gst_aggregator_pad_parent_class)->finalize (object);
2387 gst_aggregator_pad_dispose (GObject * object)
2389 GstAggregatorPad *pad = (GstAggregatorPad *) object;
2391 gst_aggregator_pad_set_flushing (pad, GST_FLOW_FLUSHING, TRUE);
2393 G_OBJECT_CLASS (gst_aggregator_pad_parent_class)->dispose (object);
2397 gst_aggregator_pad_class_init (GstAggregatorPadClass * klass)
2399 GObjectClass *gobject_class = (GObjectClass *) klass;
2401 g_type_class_add_private (klass, sizeof (GstAggregatorPadPrivate));
2403 gobject_class->constructed = gst_aggregator_pad_constructed;
2404 gobject_class->finalize = gst_aggregator_pad_finalize;
2405 gobject_class->dispose = gst_aggregator_pad_dispose;
2409 gst_aggregator_pad_init (GstAggregatorPad * pad)
2412 G_TYPE_INSTANCE_GET_PRIVATE (pad, GST_TYPE_AGGREGATOR_PAD,
2413 GstAggregatorPadPrivate);
2415 g_queue_init (&pad->priv->buffers);
2416 g_cond_init (&pad->priv->event_cond);
2418 g_mutex_init (&pad->priv->flush_lock);
2419 g_mutex_init (&pad->priv->lock);
2423 * gst_aggregator_pad_steal_buffer:
2424 * @pad: the pad to get buffer from
2426 * Steal the ref to the buffer currently queued in @pad.
2428 * Returns: (transfer full): The buffer in @pad or NULL if no buffer was
2429 * queued. You should unref the buffer after usage.
2432 gst_aggregator_pad_steal_buffer (GstAggregatorPad * pad)
2434 GstBuffer *buffer = NULL;
2437 if (GST_IS_BUFFER (g_queue_peek_tail (&pad->priv->buffers)))
2438 buffer = g_queue_pop_tail (&pad->priv->buffers);
2441 apply_buffer (pad, buffer, FALSE);
2442 pad->priv->num_buffers--;
2443 GST_TRACE_OBJECT (pad, "Consuming buffer");
2444 if (gst_aggregator_pad_queue_is_empty (pad) && pad->priv->pending_eos) {
2445 pad->priv->pending_eos = FALSE;
2446 pad->priv->eos = TRUE;
2448 PAD_BROADCAST_EVENT (pad);
2449 GST_DEBUG_OBJECT (pad, "Consumed: %" GST_PTR_FORMAT, buffer);
2457 * gst_aggregator_pad_drop_buffer:
2458 * @pad: the pad where to drop any pending buffer
2460 * Drop the buffer currently queued in @pad.
2462 * Returns: TRUE if there was a buffer queued in @pad, or FALSE if not.
2465 gst_aggregator_pad_drop_buffer (GstAggregatorPad * pad)
2469 buf = gst_aggregator_pad_steal_buffer (pad);
2474 gst_buffer_unref (buf);
2479 * gst_aggregator_pad_get_buffer:
2480 * @pad: the pad to get buffer from
2482 * Returns: (transfer full): A reference to the buffer in @pad or
2483 * NULL if no buffer was queued. You should unref the buffer after
2487 gst_aggregator_pad_get_buffer (GstAggregatorPad * pad)
2489 GstBuffer *buffer = NULL;
2492 buffer = g_queue_peek_tail (&pad->priv->buffers);
2493 /* The tail should always be a buffer, because if it is an event,
2494 * it will be consumed immeditaly in gst_aggregator_steal_buffer */
2496 if (GST_IS_BUFFER (buffer))
2497 gst_buffer_ref (buffer);
2506 gst_aggregator_pad_is_eos (GstAggregatorPad * pad)
2511 is_eos = pad->priv->eos;
2518 * gst_aggregator_merge_tags:
2519 * @self: a #GstAggregator
2520 * @tags: a #GstTagList to merge
2521 * @mode: the #GstTagMergeMode to use
2523 * Adds tags to so-called pending tags, which will be processed
2524 * before pushing out data downstream.
2526 * Note that this is provided for convenience, and the subclass is
2527 * not required to use this and can still do tag handling on its own.
2532 gst_aggregator_merge_tags (GstAggregator * self,
2533 const GstTagList * tags, GstTagMergeMode mode)
2537 g_return_if_fail (GST_IS_AGGREGATOR (self));
2538 g_return_if_fail (tags == NULL || GST_IS_TAG_LIST (tags));
2540 /* FIXME Check if we can use OBJECT lock here! */
2541 GST_OBJECT_LOCK (self);
2543 GST_DEBUG_OBJECT (self, "merging tags %" GST_PTR_FORMAT, tags);
2544 otags = self->priv->tags;
2545 self->priv->tags = gst_tag_list_merge (self->priv->tags, tags, mode);
2547 gst_tag_list_unref (otags);
2548 self->priv->tags_changed = TRUE;
2549 GST_OBJECT_UNLOCK (self);
2553 * gst_aggregator_set_latency:
2554 * @self: a #GstAggregator
2555 * @min_latency: minimum latency
2556 * @max_latency: maximum latency
2558 * Lets #GstAggregator sub-classes tell the baseclass what their internal
2559 * latency is. Will also post a LATENCY message on the bus so the pipeline
2560 * can reconfigure its global latency.
2563 gst_aggregator_set_latency (GstAggregator * self,
2564 GstClockTime min_latency, GstClockTime max_latency)
2566 gboolean changed = FALSE;
2568 g_return_if_fail (GST_IS_AGGREGATOR (self));
2569 g_return_if_fail (GST_CLOCK_TIME_IS_VALID (min_latency));
2570 g_return_if_fail (max_latency >= min_latency);
2573 if (self->priv->sub_latency_min != min_latency) {
2574 self->priv->sub_latency_min = min_latency;
2577 if (self->priv->sub_latency_max != max_latency) {
2578 self->priv->sub_latency_max = max_latency;
2583 SRC_BROADCAST (self);
2587 gst_element_post_message (GST_ELEMENT_CAST (self),
2588 gst_message_new_latency (GST_OBJECT_CAST (self)));