1 /* GStreamer concat element
3 * Copyright (c) 2014 Sebastian Dröge <sebastian@centricular.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
22 * SECTION:element-concat
24 * @see_also: #GstFunnel
26 * Concatenates streams together to one continuous stream.
28 * All streams but the current one are blocked until the current one
29 * finished with %GST_EVENT_EOS. Then the next stream is enabled, while
30 * keeping the running time continuous for %GST_FORMAT_TIME segments or
31 * keeping the segment continuous for %GST_FORMAT_BYTES segments.
33 * Streams are switched in the order in which the sinkpads were requested.
35 * By default, the stream segment's base values are adjusted to ensure
36 * the segment transitions between streams are continuous. In some cases,
37 * it may be desirable to turn off these adjustments (for example, because
38 * another downstream element like a streamsynchronizer adjusts the base
39 * values on its own). The adjust-base property can be used for this purpose.
41 * ## Example launch line
43 * gst-launch-1.0 concat name=c ! xvimagesink videotestsrc num-buffers=100 ! c. videotestsrc num-buffers=100 pattern=ball ! c.
44 * ]| Plays two video streams one after another.
52 #include "gstconcat.h"
54 GST_DEBUG_CATEGORY_STATIC (gst_concat_debug);
55 #define GST_CAT_DEFAULT gst_concat_debug
57 G_GNUC_INTERNAL GType gst_concat_pad_get_type (void);
59 #define GST_TYPE_CONCAT_PAD (gst_concat_pad_get_type())
60 #define GST_CONCAT_PAD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_CONCAT_PAD, GstConcatPad))
61 #define GST_CONCAT_PAD_CAST(obj) ((GstConcatPad *)(obj))
62 #define GST_CONCAT_PAD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_CONCAT_PAD, GstConcatPadClass))
63 #define GST_IS_CONCAT_PAD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_CONCAT_PAD))
64 #define GST_IS_CONCAT_PAD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_CONCAT_PAD))
66 typedef struct _GstConcatPad GstConcatPad;
67 typedef struct _GstConcatPadClass GstConcatPadClass;
75 /* Protected by the concat lock */
79 struct _GstConcatPadClass
84 G_DEFINE_TYPE (GstConcatPad, gst_concat_pad, GST_TYPE_PAD);
87 gst_concat_pad_class_init (GstConcatPadClass * klass)
92 gst_concat_pad_init (GstConcatPad * self)
94 gst_segment_init (&self->segment, GST_FORMAT_UNDEFINED);
95 self->flushing = FALSE;
98 static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink_%u",
101 GST_STATIC_CAPS_ANY);
103 static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
106 GST_STATIC_CAPS_ANY);
115 #define DEFAULT_ADJUST_BASE TRUE
118 GST_DEBUG_CATEGORY_INIT (gst_concat_debug, "concat", 0, "concat element");
119 #define gst_concat_parent_class parent_class
120 G_DEFINE_TYPE_WITH_CODE (GstConcat, gst_concat, GST_TYPE_ELEMENT, _do_init);
122 static void gst_concat_dispose (GObject * object);
123 static void gst_concat_finalize (GObject * object);
124 static void gst_concat_get_property (GObject * object,
125 guint prop_id, GValue * value, GParamSpec * pspec);
126 static void gst_concat_set_property (GObject * object,
127 guint prop_id, const GValue * value, GParamSpec * pspec);
129 static GstStateChangeReturn gst_concat_change_state (GstElement * element,
130 GstStateChange transition);
131 static GstPad *gst_concat_request_new_pad (GstElement * element,
132 GstPadTemplate * templ, const gchar * name, const GstCaps * caps);
133 static void gst_concat_release_pad (GstElement * element, GstPad * pad);
135 static GstFlowReturn gst_concat_sink_chain (GstPad * pad, GstObject * parent,
137 static gboolean gst_concat_sink_event (GstPad * pad, GstObject * parent,
139 static gboolean gst_concat_sink_query (GstPad * pad, GstObject * parent,
142 static gboolean gst_concat_src_event (GstPad * pad, GstObject * parent,
144 static gboolean gst_concat_src_query (GstPad * pad, GstObject * parent,
147 static gboolean gst_concat_switch_pad (GstConcat * self);
149 static void gst_concat_notify_active_pad (GstConcat * self);
151 static GParamSpec *pspec_active_pad = NULL;
154 gst_concat_class_init (GstConcatClass * klass)
156 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
157 GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
159 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_concat_dispose);
160 gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_concat_finalize);
162 gobject_class->get_property = gst_concat_get_property;
163 gobject_class->set_property = gst_concat_set_property;
165 pspec_active_pad = g_param_spec_object ("active-pad", "Active pad",
166 "Currently active src pad", GST_TYPE_PAD, G_PARAM_READABLE |
167 G_PARAM_STATIC_STRINGS);
168 g_object_class_install_property (gobject_class, PROP_ACTIVE_PAD,
170 g_object_class_install_property (gobject_class, PROP_ADJUST_BASE,
171 g_param_spec_boolean ("adjust-base", "Adjust segment base",
172 "Adjust the base value of segments to ensure they are adjacent",
173 DEFAULT_ADJUST_BASE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
175 gst_element_class_set_static_metadata (gstelement_class,
176 "Concat", "Generic", "Concatenate multiple streams",
177 "Sebastian Dröge <sebastian@centricular.com>");
179 gst_element_class_add_static_pad_template (gstelement_class, &sink_template);
180 gst_element_class_add_static_pad_template (gstelement_class, &src_template);
182 gstelement_class->request_new_pad =
183 GST_DEBUG_FUNCPTR (gst_concat_request_new_pad);
184 gstelement_class->release_pad = GST_DEBUG_FUNCPTR (gst_concat_release_pad);
185 gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_concat_change_state);
189 gst_concat_init (GstConcat * self)
191 g_mutex_init (&self->lock);
192 g_cond_init (&self->cond);
194 self->srcpad = gst_pad_new_from_static_template (&src_template, "src");
195 gst_pad_set_event_function (self->srcpad,
196 GST_DEBUG_FUNCPTR (gst_concat_src_event));
197 gst_pad_set_query_function (self->srcpad,
198 GST_DEBUG_FUNCPTR (gst_concat_src_query));
199 gst_pad_use_fixed_caps (self->srcpad);
201 gst_element_add_pad (GST_ELEMENT (self), self->srcpad);
203 self->adjust_base = DEFAULT_ADJUST_BASE;
207 gst_concat_dispose (GObject * object)
209 GstConcat *self = GST_CONCAT (object);
212 gst_object_replace ((GstObject **) & self->current_sinkpad, NULL);
215 for (item = GST_ELEMENT_PADS (object); item; item = g_list_next (item)) {
216 GstPad *pad = GST_PAD (item->data);
218 if (GST_PAD_IS_SINK (pad)) {
219 gst_element_release_request_pad (GST_ELEMENT (object), pad);
224 G_OBJECT_CLASS (parent_class)->dispose (object);
228 gst_concat_finalize (GObject * object)
230 GstConcat *self = GST_CONCAT (object);
232 g_mutex_clear (&self->lock);
233 g_cond_clear (&self->cond);
235 G_OBJECT_CLASS (parent_class)->finalize (object);
239 gst_concat_get_property (GObject * object, guint prop_id, GValue * value,
242 GstConcat *self = GST_CONCAT (object);
245 case PROP_ACTIVE_PAD:{
246 g_mutex_lock (&self->lock);
247 g_value_set_object (value, self->current_sinkpad);
248 g_mutex_unlock (&self->lock);
251 case PROP_ADJUST_BASE:{
252 g_mutex_lock (&self->lock);
253 g_value_set_boolean (value, self->adjust_base);
254 g_mutex_unlock (&self->lock);
258 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
264 gst_concat_set_property (GObject * object, guint prop_id, const GValue * value,
267 GstConcat *self = GST_CONCAT (object);
270 case PROP_ADJUST_BASE:{
271 g_mutex_lock (&self->lock);
272 self->adjust_base = g_value_get_boolean (value);
273 g_mutex_unlock (&self->lock);
277 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
283 gst_concat_request_new_pad (GstElement * element, GstPadTemplate * templ,
284 const gchar * name, const GstCaps * caps)
286 GstConcat *self = GST_CONCAT (element);
289 gboolean do_notify = FALSE;
291 GST_DEBUG_OBJECT (element, "requesting pad");
293 g_mutex_lock (&self->lock);
294 pad_name = g_strdup_printf ("sink_%u", self->pad_count);
296 g_mutex_unlock (&self->lock);
298 sinkpad = GST_PAD_CAST (g_object_new (GST_TYPE_CONCAT_PAD,
299 "name", pad_name, "direction", templ->direction, "template", templ,
303 gst_pad_set_chain_function (sinkpad,
304 GST_DEBUG_FUNCPTR (gst_concat_sink_chain));
305 gst_pad_set_event_function (sinkpad,
306 GST_DEBUG_FUNCPTR (gst_concat_sink_event));
307 gst_pad_set_query_function (sinkpad,
308 GST_DEBUG_FUNCPTR (gst_concat_sink_query));
309 GST_OBJECT_FLAG_SET (sinkpad, GST_PAD_FLAG_PROXY_CAPS);
310 GST_OBJECT_FLAG_SET (sinkpad, GST_PAD_FLAG_PROXY_ALLOCATION);
312 gst_pad_set_active (sinkpad, TRUE);
314 g_mutex_lock (&self->lock);
315 self->sinkpads = g_list_prepend (self->sinkpads, gst_object_ref (sinkpad));
316 if (!self->current_sinkpad) {
318 self->current_sinkpad = gst_object_ref (sinkpad);
320 g_mutex_unlock (&self->lock);
322 gst_element_add_pad (element, sinkpad);
325 gst_concat_notify_active_pad (self);
327 GST_DEBUG_OBJECT (sinkpad, "requested pad");
333 gst_concat_release_pad (GstElement * element, GstPad * pad)
335 GstConcat *self = GST_CONCAT (element);
336 GstConcatPad *spad = GST_CONCAT_PAD_CAST (pad);
338 gboolean current_pad_removed = FALSE;
339 gboolean eos = FALSE;
340 gboolean do_notify = FALSE;
342 GST_DEBUG_OBJECT (pad, "releasing pad");
344 g_mutex_lock (&self->lock);
345 spad->flushing = TRUE;
346 g_cond_broadcast (&self->cond);
347 g_mutex_unlock (&self->lock);
349 gst_pad_set_active (pad, FALSE);
351 /* Now the pad is definitely not running anymore */
353 g_mutex_lock (&self->lock);
354 if (self->current_sinkpad == GST_PAD_CAST (spad)) {
355 eos = !gst_concat_switch_pad (self);
356 current_pad_removed = TRUE;
360 for (l = self->sinkpads; l; l = l->next) {
361 if ((gpointer) spad == l->data) {
362 gst_object_unref (spad);
363 self->sinkpads = g_list_delete_link (self->sinkpads, l);
367 g_mutex_unlock (&self->lock);
369 gst_element_remove_pad (GST_ELEMENT_CAST (self), pad);
372 gst_concat_notify_active_pad (self);
374 if (GST_STATE (self) > GST_STATE_READY) {
375 if (current_pad_removed && !eos)
376 gst_element_post_message (GST_ELEMENT_CAST (self),
377 gst_message_new_duration_changed (GST_OBJECT_CAST (self)));
379 /* FIXME: Sending EOS from application thread */
381 gst_pad_push_event (self->srcpad, gst_event_new_eos ());
385 /* Returns FALSE if flushing
386 * Must be called from the pad's streaming thread
389 gst_concat_pad_wait (GstConcatPad * spad, GstConcat * self)
391 g_mutex_lock (&self->lock);
392 if (spad->flushing) {
393 g_mutex_unlock (&self->lock);
394 GST_DEBUG_OBJECT (spad, "Flushing");
398 while (spad != GST_CONCAT_PAD_CAST (self->current_sinkpad)) {
399 GST_TRACE_OBJECT (spad, "Not the current sinkpad - waiting");
400 if (self->current_sinkpad == NULL && g_list_length (self->sinkpads) == 1) {
401 GST_LOG_OBJECT (spad, "Sole pad waiting, switching");
402 /* If we are the only sinkpad, take active pad ownership */
403 self->current_sinkpad = gst_object_ref (self->sinkpads->data);
406 g_cond_wait (&self->cond, &self->lock);
407 if (spad->flushing) {
408 g_mutex_unlock (&self->lock);
409 GST_DEBUG_OBJECT (spad, "Flushing");
413 /* This pad can only become not the current sinkpad from
414 * a) This streaming thread (we hold the stream lock)
415 * b) Releasing the pad (takes the stream lock, see above)
417 * Unlocking here is thus safe and we can safely push
418 * serialized data to our srcpad
420 GST_DEBUG_OBJECT (spad, "Now the current sinkpad");
421 g_mutex_unlock (&self->lock);
427 gst_concat_sink_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
430 GstConcat *self = GST_CONCAT (parent);
431 GstConcatPad *spad = GST_CONCAT_PAD (pad);
433 GST_LOG_OBJECT (pad, "received buffer %p", buffer);
435 if (!gst_concat_pad_wait (spad, self))
436 return GST_FLOW_FLUSHING;
438 if (self->last_stop == GST_CLOCK_TIME_NONE)
439 self->last_stop = spad->segment.start;
441 if (self->format == GST_FORMAT_TIME) {
442 GstClockTime start_time = GST_BUFFER_TIMESTAMP (buffer);
443 GstClockTime end_time = GST_CLOCK_TIME_NONE;
445 if (start_time != GST_CLOCK_TIME_NONE)
446 end_time = start_time;
447 if (GST_BUFFER_DURATION_IS_VALID (buffer))
448 end_time += GST_BUFFER_DURATION (buffer);
450 if (end_time != GST_CLOCK_TIME_NONE && end_time > self->last_stop)
451 self->last_stop = end_time;
453 self->last_stop += gst_buffer_get_size (buffer);
456 ret = gst_pad_push (self->srcpad, buffer);
458 GST_LOG_OBJECT (pad, "handled buffer %s", gst_flow_get_name (ret));
463 /* Returns FALSE if no further pad, must be called with concat lock */
465 gst_concat_switch_pad (GstConcat * self)
472 segment = GST_CONCAT_PAD (self->current_sinkpad)->segment;
474 last_stop = self->last_stop;
475 if (last_stop == GST_CLOCK_TIME_NONE)
476 last_stop = segment.stop;
477 if (last_stop == GST_CLOCK_TIME_NONE)
478 last_stop = segment.start;
479 g_assert (last_stop != GST_CLOCK_TIME_NONE);
481 if (last_stop > segment.stop)
482 last_stop = segment.stop;
484 if (segment.format == GST_FORMAT_TIME)
486 gst_segment_to_running_time (&segment, segment.format, last_stop);
488 last_stop += segment.start;
490 self->current_start_offset += last_stop;
492 for (l = self->sinkpads; l; l = l->next) {
493 if ((gpointer) self->current_sinkpad == l->data) {
495 GST_DEBUG_OBJECT (self,
496 "Switching from pad %" GST_PTR_FORMAT " to %" GST_PTR_FORMAT,
497 self->current_sinkpad, l ? l->data : NULL);
498 gst_object_unref (self->current_sinkpad);
499 self->current_sinkpad = l ? gst_object_ref (l->data) : NULL;
500 g_cond_broadcast (&self->cond);
505 next = self->current_sinkpad != NULL;
507 self->last_stop = GST_CLOCK_TIME_NONE;
513 gst_concat_notify_active_pad (GstConcat * self)
515 g_object_notify_by_pspec ((GObject *) self, pspec_active_pad);
519 gst_concat_sink_event (GstPad * pad, GstObject * parent, GstEvent * event)
521 GstConcat *self = GST_CONCAT (parent);
522 GstConcatPad *spad = GST_CONCAT_PAD_CAST (pad);
525 GST_LOG_OBJECT (pad, "received event %" GST_PTR_FORMAT, event);
527 switch (GST_EVENT_TYPE (event)) {
528 case GST_EVENT_STREAM_START:{
529 if (!gst_concat_pad_wait (spad, self)) {
531 gst_event_unref (event);
533 ret = gst_pad_event_default (pad, parent, event);
537 case GST_EVENT_SEGMENT:{
538 gboolean adjust_base;
540 /* Drop segment event, we create our own one */
541 gst_event_copy_segment (event, &spad->segment);
542 gst_event_unref (event);
544 g_mutex_lock (&self->lock);
545 adjust_base = self->adjust_base;
546 if (self->format == GST_FORMAT_UNDEFINED) {
547 if (spad->segment.format != GST_FORMAT_TIME
548 && spad->segment.format != GST_FORMAT_BYTES) {
549 g_mutex_unlock (&self->lock);
550 GST_ELEMENT_ERROR (self, CORE, FAILED, (NULL),
551 ("Can only operate in TIME or BYTES format"));
555 self->format = spad->segment.format;
556 GST_DEBUG_OBJECT (self, "Operating in %s format",
557 gst_format_get_name (self->format));
558 g_mutex_unlock (&self->lock);
559 } else if (self->format != spad->segment.format) {
560 g_mutex_unlock (&self->lock);
561 GST_ELEMENT_ERROR (self, CORE, FAILED, (NULL),
562 ("Operating in %s format but new pad has %s",
563 gst_format_get_name (self->format),
564 gst_format_get_name (spad->segment.format)));
567 g_mutex_unlock (&self->lock);
570 if (!gst_concat_pad_wait (spad, self)) {
573 GstSegment segment = spad->segment;
577 /* We know no duration */
578 segment.duration = -1;
580 /* Update segment values to be continuous with last stream */
581 if (self->format == GST_FORMAT_TIME) {
582 segment.base += self->current_start_offset;
584 /* Shift start/stop byte position */
585 segment.start += self->current_start_offset;
586 if (segment.stop != -1)
587 segment.stop += self->current_start_offset;
590 topush = gst_event_new_segment (&segment);
591 gst_event_set_seqnum (topush, gst_event_get_seqnum (event));
593 gst_pad_push_event (self->srcpad, topush);
598 gst_event_unref (event);
600 if (!gst_concat_pad_wait (spad, self)) {
605 g_mutex_lock (&self->lock);
606 next = gst_concat_switch_pad (self);
607 g_mutex_unlock (&self->lock);
610 gst_concat_notify_active_pad (self);
613 gst_pad_push_event (self->srcpad, gst_event_new_eos ());
615 gst_element_post_message (GST_ELEMENT_CAST (self),
616 gst_message_new_duration_changed (GST_OBJECT_CAST (self)));
621 case GST_EVENT_FLUSH_START:{
624 g_mutex_lock (&self->lock);
625 spad->flushing = TRUE;
626 g_cond_broadcast (&self->cond);
627 forward = (self->current_sinkpad == GST_PAD_CAST (spad));
628 if (!forward && g_list_length (self->sinkpads) == 1)
630 g_mutex_unlock (&self->lock);
633 ret = gst_pad_event_default (pad, parent, event);
635 gst_event_unref (event);
638 case GST_EVENT_FLUSH_STOP:{
641 gst_segment_init (&spad->segment, GST_FORMAT_UNDEFINED);
642 spad->flushing = FALSE;
644 g_mutex_lock (&self->lock);
645 forward = (self->current_sinkpad == GST_PAD_CAST (spad));
646 if (!forward && g_list_length (self->sinkpads) == 1)
648 g_mutex_unlock (&self->lock);
653 gst_event_parse_flush_stop (event, &reset_time);
655 GST_DEBUG_OBJECT (self,
656 "resetting start offset to 0 after flushing with reset_time = TRUE");
657 self->current_start_offset = 0;
659 ret = gst_pad_event_default (pad, parent, event);
661 gst_event_unref (event);
666 /* Wait for other serialized events before forwarding */
667 if (GST_EVENT_IS_SERIALIZED (event) && !gst_concat_pad_wait (spad, self)) {
668 gst_event_unref (event);
671 ret = gst_pad_event_default (pad, parent, event);
681 gst_concat_sink_query (GstPad * pad, GstObject * parent, GstQuery * query)
683 GstConcat *self = GST_CONCAT (parent);
684 GstConcatPad *spad = GST_CONCAT_PAD_CAST (pad);
687 GST_LOG_OBJECT (pad, "received query %" GST_PTR_FORMAT, query);
689 switch (GST_QUERY_TYPE (query)) {
691 /* Wait for other serialized queries before forwarding */
692 if (GST_QUERY_IS_SERIALIZED (query) && !gst_concat_pad_wait (spad, self)) {
695 ret = gst_pad_query_default (pad, parent, query);
704 gst_concat_src_event (GstPad * pad, GstObject * parent, GstEvent * event)
706 GstConcat *self = GST_CONCAT (parent);
709 GST_LOG_OBJECT (pad, "received event %" GST_PTR_FORMAT, event);
711 switch (GST_EVENT_TYPE (event)) {
712 case GST_EVENT_SEEK:{
713 GstPad *sinkpad = NULL;
715 g_mutex_lock (&self->lock);
716 if ((sinkpad = self->current_sinkpad))
717 gst_object_ref (sinkpad);
718 /* If no current active sinkpad but only one sinkpad, try reactivating that pad */
719 if (sinkpad == NULL && g_list_length (self->sinkpads) == 1) {
720 sinkpad = gst_object_ref (self->sinkpads->data);
722 g_mutex_unlock (&self->lock);
724 ret = gst_pad_push_event (sinkpad, event);
725 gst_object_unref (sinkpad);
727 gst_event_unref (event);
734 GstClockTimeDiff diff;
735 GstClockTime timestamp;
737 GstPad *sinkpad = NULL;
739 g_mutex_lock (&self->lock);
740 if ((sinkpad = self->current_sinkpad))
741 gst_object_ref (sinkpad);
742 g_mutex_unlock (&self->lock);
745 gst_event_parse_qos (event, &type, &proportion, &diff, ×tamp);
746 gst_event_unref (event);
748 if (timestamp != GST_CLOCK_TIME_NONE
749 && timestamp > self->current_start_offset) {
750 timestamp -= self->current_start_offset;
751 event = gst_event_new_qos (type, proportion, diff, timestamp);
752 ret = gst_pad_push_event (self->current_sinkpad, event);
756 gst_object_unref (sinkpad);
758 gst_event_unref (event);
763 case GST_EVENT_FLUSH_STOP:{
766 gst_event_parse_flush_stop (event, &reset_time);
768 GST_DEBUG_OBJECT (self,
769 "resetting start offset to 0 after flushing with reset_time = TRUE");
770 self->current_start_offset = 0;
773 ret = gst_pad_event_default (pad, parent, event);
777 ret = gst_pad_event_default (pad, parent, event);
785 gst_concat_src_query (GstPad * pad, GstObject * parent, GstQuery * query)
789 GST_LOG_OBJECT (pad, "received query %" GST_PTR_FORMAT, query);
791 switch (GST_QUERY_TYPE (query)) {
793 ret = gst_pad_query_default (pad, parent, query);
801 reset_pad (const GValue * data, gpointer user_data)
803 GstPad *pad = g_value_get_object (data);
804 GstConcatPad *spad = GST_CONCAT_PAD_CAST (pad);
806 gst_segment_init (&spad->segment, GST_FORMAT_UNDEFINED);
807 spad->flushing = FALSE;
811 unblock_pad (const GValue * data, gpointer user_data)
813 GstPad *pad = g_value_get_object (data);
814 GstConcatPad *spad = GST_CONCAT_PAD_CAST (pad);
816 spad->flushing = TRUE;
819 static GstStateChangeReturn
820 gst_concat_change_state (GstElement * element, GstStateChange transition)
822 GstConcat *self = GST_CONCAT (element);
823 GstStateChangeReturn ret;
825 switch (transition) {
826 case GST_STATE_CHANGE_READY_TO_PAUSED:{
827 GstIterator *iter = gst_element_iterate_sink_pads (element);
828 GstIteratorResult res;
830 self->format = GST_FORMAT_UNDEFINED;
831 self->current_start_offset = 0;
832 self->last_stop = GST_CLOCK_TIME_NONE;
835 gst_iterator_foreach (iter, reset_pad,
836 NULL)) == GST_ITERATOR_RESYNC)
837 gst_iterator_resync (iter);
838 gst_iterator_free (iter);
840 if (res == GST_ITERATOR_ERROR)
841 return GST_STATE_CHANGE_FAILURE;
844 case GST_STATE_CHANGE_PAUSED_TO_READY:{
845 GstIterator *iter = gst_element_iterate_sink_pads (element);
846 GstIteratorResult res;
848 g_mutex_lock (&self->lock);
850 gst_iterator_foreach (iter, unblock_pad,
851 NULL)) == GST_ITERATOR_RESYNC)
852 gst_iterator_resync (iter);
853 gst_iterator_free (iter);
854 g_cond_broadcast (&self->cond);
855 g_mutex_unlock (&self->lock);
857 if (res == GST_ITERATOR_ERROR)
858 return GST_STATE_CHANGE_FAILURE;
866 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);