2 * Copyright (C) 2005 Wim Taymans <wim@fluendo.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
24 * @short_description: Base class for sink elements
25 * @see_also: #GstBaseTransform, #GstBaseSource
27 * This class is for elements that do output operations.
30 * <listitem><para>one sinkpad</para></listitem>
31 * <listitem><para>handles state changes</para></listitem>
32 * <listitem><para>pull/push mode</para></listitem>
33 * <listitem><para>handles seeking/query</para></listitem>
34 * <listitem><para>handles preroll</para></listitem>
35 * <listitem><para>EOS handling</para></listitem>
43 #include "gstbasesink.h"
44 #include <gst/gstmarshal.h>
45 #include <gst/gst-i18n-lib.h>
47 GST_DEBUG_CATEGORY_STATIC (gst_base_sink_debug);
48 #define GST_CAT_DEFAULT gst_base_sink_debug
50 /* BaseSink signals and properties */
58 #define DEFAULT_SIZE 1024
59 #define DEFAULT_CAN_ACTIVATE_PULL FALSE /* fixme: enable me */
60 #define DEFAULT_CAN_ACTIVATE_PUSH TRUE
62 #define DEFAULT_SYNC TRUE
67 PROP_PREROLL_QUEUE_LEN,
71 static GstElementClass *parent_class = NULL;
73 static void gst_base_sink_base_init (gpointer g_class);
74 static void gst_base_sink_class_init (GstBaseSinkClass * klass);
75 static void gst_base_sink_init (GstBaseSink * trans, gpointer g_class);
76 static void gst_base_sink_finalize (GObject * object);
79 gst_base_sink_get_type (void)
81 static GType base_sink_type = 0;
83 if (!base_sink_type) {
84 static const GTypeInfo base_sink_info = {
85 sizeof (GstBaseSinkClass),
86 (GBaseInitFunc) gst_base_sink_base_init,
88 (GClassInitFunc) gst_base_sink_class_init,
93 (GInstanceInitFunc) gst_base_sink_init,
96 base_sink_type = g_type_register_static (GST_TYPE_ELEMENT,
97 "GstBaseSink", &base_sink_info, G_TYPE_FLAG_ABSTRACT);
99 return base_sink_type;
102 static void gst_base_sink_set_clock (GstElement * element, GstClock * clock);
104 static void gst_base_sink_set_property (GObject * object, guint prop_id,
105 const GValue * value, GParamSpec * pspec);
106 static void gst_base_sink_get_property (GObject * object, guint prop_id,
107 GValue * value, GParamSpec * pspec);
109 static gboolean gst_base_sink_send_event (GstElement * element,
111 static gboolean gst_base_sink_query (GstElement * element, GstQuery * query);
113 static GstCaps *gst_base_sink_get_caps (GstBaseSink * sink);
114 static gboolean gst_base_sink_set_caps (GstBaseSink * sink, GstCaps * caps);
115 static GstFlowReturn gst_base_sink_buffer_alloc (GstBaseSink * sink,
116 guint64 offset, guint size, GstCaps * caps, GstBuffer ** buf);
117 static void gst_base_sink_get_times (GstBaseSink * basesink, GstBuffer * buffer,
118 GstClockTime * start, GstClockTime * end);
120 static GstStateChangeReturn gst_base_sink_change_state (GstElement * element,
121 GstStateChange transition);
123 static GstFlowReturn gst_base_sink_chain (GstPad * pad, GstBuffer * buffer);
124 static void gst_base_sink_loop (GstPad * pad);
125 static gboolean gst_base_sink_activate (GstPad * pad);
126 static gboolean gst_base_sink_activate_push (GstPad * pad, gboolean active);
127 static gboolean gst_base_sink_activate_pull (GstPad * pad, gboolean active);
128 static gboolean gst_base_sink_event (GstPad * pad, GstEvent * event);
129 static inline GstFlowReturn gst_base_sink_handle_buffer (GstBaseSink * basesink,
131 static inline gboolean gst_base_sink_handle_event (GstBaseSink * basesink,
135 gst_base_sink_base_init (gpointer g_class)
137 GST_DEBUG_CATEGORY_INIT (gst_base_sink_debug, "basesink", 0,
142 gst_base_sink_class_init (GstBaseSinkClass * klass)
144 GObjectClass *gobject_class;
145 GstElementClass *gstelement_class;
147 gobject_class = (GObjectClass *) klass;
148 gstelement_class = (GstElementClass *) klass;
150 parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
152 gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_base_sink_finalize);
153 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_base_sink_set_property);
154 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_base_sink_get_property);
156 /* FIXME, this next value should be configured using an event from the
157 * upstream element */
158 g_object_class_install_property (G_OBJECT_CLASS (klass),
159 PROP_PREROLL_QUEUE_LEN,
160 g_param_spec_uint ("preroll-queue-len", "preroll-queue-len",
161 "Number of buffers to queue during preroll", 0, G_MAXUINT, 0,
162 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
163 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_SYNC,
164 g_param_spec_boolean ("sync", "Sync", "Sync on the clock", DEFAULT_SYNC,
167 gstelement_class->set_clock = GST_DEBUG_FUNCPTR (gst_base_sink_set_clock);
168 gstelement_class->change_state =
169 GST_DEBUG_FUNCPTR (gst_base_sink_change_state);
170 gstelement_class->send_event = GST_DEBUG_FUNCPTR (gst_base_sink_send_event);
171 gstelement_class->query = GST_DEBUG_FUNCPTR (gst_base_sink_query);
173 klass->get_caps = GST_DEBUG_FUNCPTR (gst_base_sink_get_caps);
174 klass->set_caps = GST_DEBUG_FUNCPTR (gst_base_sink_set_caps);
175 klass->buffer_alloc = GST_DEBUG_FUNCPTR (gst_base_sink_buffer_alloc);
176 klass->get_times = GST_DEBUG_FUNCPTR (gst_base_sink_get_times);
180 gst_base_sink_pad_getcaps (GstPad * pad)
182 GstBaseSinkClass *bclass;
184 GstCaps *caps = NULL;
186 bsink = GST_BASE_SINK (gst_pad_get_parent (pad));
187 bclass = GST_BASE_SINK_GET_CLASS (bsink);
188 if (bclass->get_caps)
189 caps = bclass->get_caps (bsink);
192 GstPadTemplate *pad_template;
195 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (bclass), "sink");
196 if (pad_template != NULL) {
197 caps = gst_caps_ref (gst_pad_template_get_caps (pad_template));
200 gst_object_unref (bsink);
206 gst_base_sink_pad_setcaps (GstPad * pad, GstCaps * caps)
208 GstBaseSinkClass *bclass;
210 gboolean res = FALSE;
212 bsink = GST_BASE_SINK (gst_pad_get_parent (pad));
213 bclass = GST_BASE_SINK_GET_CLASS (bsink);
215 if (bclass->set_caps)
216 res = bclass->set_caps (bsink, caps);
218 gst_object_unref (bsink);
224 gst_base_sink_pad_buffer_alloc (GstPad * pad, guint64 offset, guint size,
225 GstCaps * caps, GstBuffer ** buf)
227 GstBaseSinkClass *bclass;
229 GstFlowReturn result = GST_FLOW_OK;
231 bsink = GST_BASE_SINK (gst_pad_get_parent (pad));
232 bclass = GST_BASE_SINK_GET_CLASS (bsink);
234 if (bclass->buffer_alloc)
235 result = bclass->buffer_alloc (bsink, offset, size, caps, buf);
237 *buf = NULL; /* fallback in gstpad.c will allocate generic buffer */
239 gst_object_unref (bsink);
245 gst_base_sink_init (GstBaseSink * basesink, gpointer g_class)
247 GstPadTemplate *pad_template;
250 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (g_class), "sink");
251 g_return_if_fail (pad_template != NULL);
253 basesink->sinkpad = gst_pad_new_from_template (pad_template, "sink");
255 gst_pad_set_getcaps_function (basesink->sinkpad,
256 GST_DEBUG_FUNCPTR (gst_base_sink_pad_getcaps));
257 gst_pad_set_setcaps_function (basesink->sinkpad,
258 GST_DEBUG_FUNCPTR (gst_base_sink_pad_setcaps));
259 gst_pad_set_bufferalloc_function (basesink->sinkpad,
260 GST_DEBUG_FUNCPTR (gst_base_sink_pad_buffer_alloc));
261 gst_pad_set_activate_function (basesink->sinkpad,
262 GST_DEBUG_FUNCPTR (gst_base_sink_activate));
263 gst_pad_set_activatepush_function (basesink->sinkpad,
264 GST_DEBUG_FUNCPTR (gst_base_sink_activate_push));
265 gst_pad_set_activatepull_function (basesink->sinkpad,
266 GST_DEBUG_FUNCPTR (gst_base_sink_activate_pull));
267 gst_pad_set_event_function (basesink->sinkpad,
268 GST_DEBUG_FUNCPTR (gst_base_sink_event));
269 gst_pad_set_chain_function (basesink->sinkpad,
270 GST_DEBUG_FUNCPTR (gst_base_sink_chain));
271 gst_element_add_pad (GST_ELEMENT (basesink), basesink->sinkpad);
273 basesink->pad_mode = GST_ACTIVATE_NONE;
274 GST_PAD_TASK (basesink->sinkpad) = NULL;
275 basesink->preroll_queue = g_queue_new ();
277 basesink->can_activate_push = DEFAULT_CAN_ACTIVATE_PUSH;
278 basesink->can_activate_pull = DEFAULT_CAN_ACTIVATE_PULL;
280 basesink->sync = DEFAULT_SYNC;
282 GST_OBJECT_FLAG_SET (basesink, GST_ELEMENT_IS_SINK);
286 gst_base_sink_finalize (GObject * object)
288 GstBaseSink *basesink;
290 basesink = GST_BASE_SINK (object);
292 g_queue_free (basesink->preroll_queue);
294 G_OBJECT_CLASS (parent_class)->finalize (object);
298 gst_base_sink_set_clock (GstElement * element, GstClock * clock)
302 sink = GST_BASE_SINK (element);
308 gst_base_sink_set_property (GObject * object, guint prop_id,
309 const GValue * value, GParamSpec * pspec)
311 GstBaseSink *sink = GST_BASE_SINK (object);
314 case PROP_PREROLL_QUEUE_LEN:
315 /* preroll lock necessary to serialize with finish_preroll */
316 GST_PREROLL_LOCK (sink->sinkpad);
317 sink->preroll_queue_max_len = g_value_get_uint (value);
318 GST_PREROLL_UNLOCK (sink->sinkpad);
321 sink->sync = g_value_get_boolean (value);
324 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
330 gst_base_sink_get_property (GObject * object, guint prop_id, GValue * value,
333 GstBaseSink *sink = GST_BASE_SINK (object);
337 case PROP_PREROLL_QUEUE_LEN:
338 g_value_set_uint (value, sink->preroll_queue_max_len);
341 g_value_set_boolean (value, sink->sync);
344 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
351 gst_base_sink_get_caps (GstBaseSink * sink)
357 gst_base_sink_set_caps (GstBaseSink * sink, GstCaps * caps)
363 gst_base_sink_buffer_alloc (GstBaseSink * sink, guint64 offset, guint size,
364 GstCaps * caps, GstBuffer ** buf)
370 /* with PREROLL_LOCK */
372 gst_base_sink_preroll_queue_empty (GstBaseSink * basesink, GstPad * pad)
375 GQueue *q = basesink->preroll_queue;
381 GST_DEBUG_OBJECT (basesink, "emptying queue");
382 while ((obj = g_queue_pop_head (q))) {
385 is_buffer = GST_IS_BUFFER (obj);
387 basesink->preroll_queued--;
388 basesink->buffers_queued--;
390 switch (GST_EVENT_TYPE (obj)) {
392 basesink->preroll_queued--;
397 basesink->events_queued--;
399 /* we release the preroll lock while pushing so that we
400 * can still flush it while blocking on the clock or
401 * inside the element. */
402 GST_PREROLL_UNLOCK (pad);
405 GST_DEBUG_OBJECT (basesink, "popped buffer %p", obj);
406 ret = gst_base_sink_handle_buffer (basesink, GST_BUFFER (obj));
408 GST_DEBUG_OBJECT (basesink, "popped event %p", obj);
409 gst_base_sink_handle_event (basesink, GST_EVENT (obj));
413 GST_PREROLL_LOCK (pad);
415 GST_DEBUG_OBJECT (basesink, "queue empty");
420 /* with PREROLL_LOCK */
422 gst_base_sink_preroll_queue_flush (GstBaseSink * basesink, GstPad * pad)
425 GQueue *q = basesink->preroll_queue;
427 GST_DEBUG_OBJECT (basesink, "flushing queue %p", basesink);
429 while ((obj = g_queue_pop_head (q))) {
430 GST_DEBUG_OBJECT (basesink, "popped %p", obj);
431 gst_mini_object_unref (obj);
434 /* we can't have EOS anymore now */
435 basesink->eos = FALSE;
436 basesink->eos_queued = FALSE;
437 basesink->preroll_queued = 0;
438 basesink->buffers_queued = 0;
439 basesink->events_queued = 0;
440 basesink->have_preroll = FALSE;
441 /* and signal any waiters now */
442 GST_PREROLL_SIGNAL (pad);
445 /* with PREROLL_LOCK */
447 gst_base_sink_commit_state (GstBaseSink * basesink)
449 /* commit state and proceed to next pending state */
451 GstState current, next, pending, post_pending;
453 gboolean post_paused = FALSE;
454 gboolean post_playing = FALSE;
457 current = GST_STATE (basesink);
458 next = GST_STATE_NEXT (basesink);
459 pending = GST_STATE_PENDING (basesink);
460 post_pending = pending;
463 case GST_STATE_PLAYING:
464 basesink->need_preroll = FALSE;
466 /* post PAUSED too when we were READY */
467 if (current == GST_STATE_READY) {
471 case GST_STATE_PAUSED:
472 basesink->need_preroll = TRUE;
474 post_pending = GST_STATE_VOID_PENDING;
476 case GST_STATE_READY:
482 if (pending != GST_STATE_VOID_PENDING) {
483 GST_STATE (basesink) = pending;
484 GST_STATE_NEXT (basesink) = GST_STATE_VOID_PENDING;
485 GST_STATE_PENDING (basesink) = GST_STATE_VOID_PENDING;
486 GST_STATE_RETURN (basesink) = GST_STATE_CHANGE_SUCCESS;
488 GST_UNLOCK (basesink);
491 message = gst_message_new_state_changed (GST_OBJECT_CAST (basesink),
492 current, next, post_pending);
493 gst_element_post_message (GST_ELEMENT_CAST (basesink), message);
496 message = gst_message_new_state_changed (GST_OBJECT_CAST (basesink),
497 next, pending, GST_STATE_VOID_PENDING);
498 gst_element_post_message (GST_ELEMENT_CAST (basesink), message);
501 if (post_paused || post_playing) {
502 gst_element_post_message (GST_ELEMENT_CAST (basesink),
503 gst_message_new_state_dirty (GST_OBJECT_CAST (basesink)));
506 GST_STATE_BROADCAST (basesink);
512 /* app is going to READY */
513 GST_UNLOCK (basesink);
518 /* with STREAM_LOCK */
520 gst_base_sink_handle_object (GstBaseSink * basesink, GstPad * pad,
526 GST_PREROLL_LOCK (pad);
527 /* push object on the queue */
528 GST_DEBUG_OBJECT (basesink, "push %p on preroll_queue", obj);
529 g_queue_push_tail (basesink->preroll_queue, obj);
531 have_event = GST_IS_EVENT (obj);
533 GstEvent *event = GST_EVENT (obj);
535 switch (GST_EVENT_TYPE (obj)) {
537 basesink->preroll_queued++;
538 basesink->eos = TRUE;
539 basesink->eos_queued = TRUE;
541 case GST_EVENT_NEWSEGMENT:
546 gint64 segment_start;
549 GstClockTime duration;
552 /* the newsegment event is needed to bring the buffer timestamps to the
553 * stream time and to drop samples outside of the playback segment. */
554 gst_event_parse_newsegment (event, &update, &rate, &format,
555 &segment_start, &segment_stop, &segment_time);
557 basesink->have_newsegment = TRUE;
559 /* any other format with 0 also gives time 0, the other values are
560 * invalid as time though. */
561 if (format != GST_FORMAT_TIME && segment_start == 0) {
562 GST_DEBUG_OBJECT (basesink,
563 "non-time newsegment with start 0, coaxing into FORMAT_TIME");
564 format = GST_FORMAT_TIME;
569 if (format != GST_FORMAT_TIME) {
570 GST_DEBUG_OBJECT (basesink,
571 "received non time %d NEW_SEGMENT %" G_GINT64_FORMAT
572 " -- %" G_GINT64_FORMAT ", time %" G_GINT64_FORMAT,
573 format, segment_start, segment_stop, segment_time);
575 /* this means this sink will not be able to clip or drop samples
576 * and timestamps have to start from 0. */
577 basesink->segment_start = -1;
578 basesink->segment_stop = -1;
579 basesink->segment_time = -1;
580 goto done_newsegment;
582 /* check if we really have a new segment or the previous one is
585 /* the new segment has to be aligned with the old segment.
586 * We first update the accumulated time of the previous
587 * segment. the accumulated time is used when syncing to the
588 * clock. A flush event sets the accumulated time back to 0
590 if (GST_CLOCK_TIME_IS_VALID (basesink->segment_stop)) {
591 duration = basesink->segment_stop - basesink->segment_start;
592 } else if (GST_CLOCK_TIME_IS_VALID (basesink->current_end)) {
593 /* else use last seen timestamp as segment stop */
594 duration = basesink->current_end - basesink->segment_start;
599 duration = segment_start - basesink->segment_start;
602 /* use previous rate to calculate duration */
603 basesink->segment_accum += gst_gdouble_to_guint64 (
604 (gst_guint64_to_gdouble (duration) / ABS (basesink->segment_rate)));
605 /* then update the current segment */
606 basesink->segment_rate = rate;
607 basesink->segment_start = segment_start;
608 basesink->segment_stop = segment_stop;
609 basesink->segment_time = segment_time;
611 GST_DEBUG_OBJECT (basesink,
612 "received NEWSEGMENT %" GST_TIME_FORMAT " -- %"
613 GST_TIME_FORMAT ", time %" GST_TIME_FORMAT ", accum %"
615 GST_TIME_ARGS (basesink->segment_start),
616 GST_TIME_ARGS (basesink->segment_stop),
617 GST_TIME_ARGS (basesink->segment_time),
618 GST_TIME_ARGS (basesink->segment_accum));
625 basesink->events_queued++;
627 GstBuffer *buf = GST_BUFFER (obj);
629 if (!basesink->have_newsegment) {
630 GST_ELEMENT_WARNING (basesink, STREAM, FAILED,
631 (_("Internal data flow problem.")),
632 ("Received buffer without a new-segment. Cannot sync to clock."));
633 basesink->have_newsegment = TRUE;
634 /* this means this sink will not be able to sync to the clock */
635 basesink->segment_start = -1;
636 basesink->segment_stop = -1;
639 /* check if the buffer needs to be dropped */
641 GstClockTime start = -1, end = -1;
643 /* we don't use the subclassed method as it may not return
644 * valid values for our purpose here */
645 gst_base_sink_get_times (basesink, buf, &start, &end);
647 GST_DEBUG_OBJECT (basesink, "got times start: %" GST_TIME_FORMAT
648 ", end: %" GST_TIME_FORMAT, GST_TIME_ARGS (start),
649 GST_TIME_ARGS (end));
651 /* need to drop if the timestamp is not between segment_start and
652 * segment_stop. we check if the complete sample is outside of the
653 * range since the sink might be able to clip the sample. */
654 if (GST_CLOCK_TIME_IS_VALID (end) &&
655 GST_CLOCK_TIME_IS_VALID (basesink->segment_start)) {
656 if (end <= basesink->segment_start) {
657 GST_DEBUG_OBJECT (basesink,
658 "buffer end %" GST_TIME_FORMAT " <= segment start %"
659 GST_TIME_FORMAT ", dropping buffer", GST_TIME_ARGS (end),
660 GST_TIME_ARGS (basesink->segment_start));
664 if (GST_CLOCK_TIME_IS_VALID (start) &&
665 GST_CLOCK_TIME_IS_VALID (basesink->segment_stop)) {
666 if (basesink->segment_stop <= start) {
667 GST_DEBUG_OBJECT (basesink,
668 "buffer start %" GST_TIME_FORMAT " >= segment stop %"
669 GST_TIME_FORMAT ", dropping buffer", GST_TIME_ARGS (start),
670 GST_TIME_ARGS (basesink->segment_stop));
675 basesink->preroll_queued++;
676 basesink->buffers_queued++;
679 GST_DEBUG_OBJECT (basesink,
680 "now %d preroll, %d buffers, %d events on queue",
681 basesink->preroll_queued,
682 basesink->buffers_queued, basesink->events_queued);
684 /* check if we are prerolling */
685 if (!basesink->need_preroll)
688 /* there is a buffer queued */
689 if (basesink->buffers_queued == 1) {
690 GST_DEBUG_OBJECT (basesink, "do preroll %p", obj);
692 /* if it's a buffer, we need to call the preroll method */
693 if (GST_IS_BUFFER (obj)) {
694 GstBaseSinkClass *bclass;
696 GstBuffer *buf = GST_BUFFER (obj);
698 GST_DEBUG_OBJECT (basesink, "preroll buffer %" GST_TIME_FORMAT,
699 GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)));
701 bclass = GST_BASE_SINK_GET_CLASS (basesink);
703 if ((pres = bclass->preroll (basesink, buf)) != GST_FLOW_OK)
707 length = basesink->preroll_queued;
708 GST_DEBUG_OBJECT (basesink, "prerolled length %d", length);
712 basesink->have_preroll = TRUE;
715 if (!gst_base_sink_commit_state (basesink))
719 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
723 /* it is possible that commiting the state made us go to PLAYING
724 * now in which case we don't need to block anymore. */
725 if (!basesink->need_preroll)
728 length = basesink->preroll_queued;
730 /* FIXME: a pad probe could have made us lose the buffer, according
731 * to one of the python tests */
733 GST_ERROR_OBJECT (basesink,
734 "preroll_queued dropped from 1 to 0 while committing state change");
736 g_assert (length <= 1);
739 /* see if we need to block now. We cannot block on events, only
740 * on buffers, the reason is that events can be sent from the
741 * application thread and we don't want to block there. */
742 if (length > basesink->preroll_queue_max_len && !have_event) {
743 /* block until the state changes, or we get a flush, or something */
744 GST_DEBUG_OBJECT (basesink, "waiting to finish preroll");
745 GST_PREROLL_WAIT (pad);
746 GST_DEBUG_OBJECT (basesink, "done preroll");
748 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
752 GST_PREROLL_UNLOCK (pad);
760 GST_DEBUG_OBJECT (basesink, "no preroll needed");
761 /* maybe it was another sink that blocked in preroll, need to check for
763 basesink->have_preroll = FALSE;
764 ret = gst_base_sink_preroll_queue_empty (basesink, pad);
765 GST_PREROLL_UNLOCK (pad);
773 buf = GST_BUFFER (g_queue_pop_tail (basesink->preroll_queue));
775 gst_buffer_unref (buf);
776 GST_PREROLL_UNLOCK (pad);
783 gst_base_sink_preroll_queue_flush (basesink, pad);
784 GST_PREROLL_UNLOCK (pad);
785 GST_DEBUG_OBJECT (basesink, "pad is flushing");
787 return GST_FLOW_WRONG_STATE;
791 GST_PREROLL_UNLOCK (pad);
792 GST_DEBUG_OBJECT (basesink, "stopping");
794 return GST_FLOW_WRONG_STATE;
798 GST_DEBUG_OBJECT (basesink, "preroll failed");
799 gst_base_sink_preroll_queue_flush (basesink, pad);
801 GST_DEBUG_OBJECT (basesink, "abort state");
802 gst_element_abort_state (GST_ELEMENT (basesink));
804 return GST_FLOW_ERROR;
809 gst_base_sink_event (GstPad * pad, GstEvent * event)
811 GstBaseSink *basesink;
812 gboolean result = TRUE;
813 GstBaseSinkClass *bclass;
815 basesink = GST_BASE_SINK (gst_pad_get_parent (pad));
817 bclass = GST_BASE_SINK_GET_CLASS (basesink);
819 GST_DEBUG_OBJECT (basesink, "event %p", event);
821 switch (GST_EVENT_TYPE (event)) {
826 GST_STREAM_LOCK (pad);
827 /* EOS also finishes the preroll */
829 gst_base_sink_handle_object (basesink, pad, GST_MINI_OBJECT (event));
830 GST_STREAM_UNLOCK (pad);
833 case GST_EVENT_NEWSEGMENT:
837 GST_STREAM_LOCK (pad);
839 gst_base_sink_handle_object (basesink, pad, GST_MINI_OBJECT (event));
840 GST_STREAM_UNLOCK (pad);
843 case GST_EVENT_FLUSH_START:
844 /* make sure we are not blocked on the clock also clear any pending
847 bclass->event (basesink, event);
850 basesink->flushing = TRUE;
851 if (basesink->clock_id) {
852 gst_clock_id_unschedule (basesink->clock_id);
854 GST_UNLOCK (basesink);
856 GST_PREROLL_LOCK (pad);
857 /* we need preroll after the flush */
858 GST_DEBUG_OBJECT (basesink, "flushing, need preroll after flush");
859 basesink->need_preroll = TRUE;
860 /* unlock from a possible state change/preroll */
861 gst_base_sink_preroll_queue_flush (basesink, pad);
862 GST_PREROLL_UNLOCK (pad);
864 /* and we need to commit our state again on the next
865 * prerolled buffer */
866 GST_STREAM_LOCK (pad);
867 gst_element_lost_state (GST_ELEMENT (basesink));
868 GST_STREAM_UNLOCK (pad);
869 GST_DEBUG_OBJECT (basesink, "event unref %p %p", basesink, event);
870 gst_event_unref (event);
872 case GST_EVENT_FLUSH_STOP:
874 bclass->event (basesink, event);
876 /* now we are completely unblocked and the _chain method
878 GST_STREAM_LOCK (pad);
880 basesink->flushing = FALSE;
881 GST_UNLOCK (basesink);
882 /* we need new segment info after the flush. */
883 basesink->segment_start = -1;
884 basesink->segment_stop = -1;
885 basesink->current_start = -1;
886 basesink->current_end = -1;
887 GST_DEBUG_OBJECT (basesink, "reset accum %" GST_TIME_FORMAT,
888 GST_TIME_ARGS (basesink->segment_accum));
889 basesink->segment_accum = 0;
890 GST_STREAM_UNLOCK (pad);
892 GST_DEBUG_OBJECT (basesink, "event unref %p %p", basesink, event);
893 gst_event_unref (event);
896 gst_event_unref (event);
899 gst_object_unref (basesink);
904 /* default implementation to calculate the start and end
905 * timestamps on a buffer, subclasses can override
908 gst_base_sink_get_times (GstBaseSink * basesink, GstBuffer * buffer,
909 GstClockTime * start, GstClockTime * end)
911 GstClockTime timestamp, duration;
913 timestamp = GST_BUFFER_TIMESTAMP (buffer);
914 if (GST_CLOCK_TIME_IS_VALID (timestamp)) {
916 /* get duration to calculate end time */
917 duration = GST_BUFFER_DURATION (buffer);
918 if (GST_CLOCK_TIME_IS_VALID (duration)) {
919 *end = timestamp + duration;
925 /* with STREAM_LOCK and LOCK*/
926 static GstClockReturn
927 gst_base_sink_wait (GstBaseSink * basesink, GstClockTime time)
932 /* no need to attempt a clock wait if we are flushing */
933 if (basesink->flushing) {
934 return GST_CLOCK_UNSCHEDULED;
937 /* clock_id should be NULL outside of this function */
938 g_assert (basesink->clock_id == NULL);
939 g_assert (GST_CLOCK_TIME_IS_VALID (time));
941 id = gst_clock_new_single_shot_id (basesink->clock, time);
943 basesink->clock_id = id;
944 /* release the object lock while waiting */
945 GST_UNLOCK (basesink);
947 ret = gst_clock_id_wait (id, NULL);
950 gst_clock_id_unref (id);
951 basesink->clock_id = NULL;
956 /* perform synchronisation on a buffer
958 * 1) check if we have a clock, if not, do nothing
959 * 2) calculate the start and end time of the buffer
960 * 3) create a single shot notification to wait on
961 * the clock, save the entry so we can unlock it
962 * 4) wait on the clock, this blocks
963 * 5) unref the clockid again
965 static GstClockReturn
966 gst_base_sink_do_sync (GstBaseSink * basesink, GstBuffer * buffer)
968 GstClockReturn result = GST_CLOCK_OK;
969 GstClockTime start, end;
970 GstClockTimeDiff stream_start, stream_end;
971 GstBaseSinkClass *bclass;
972 gboolean start_valid, end_valid;
974 bclass = GST_BASE_SINK_GET_CLASS (basesink);
977 if (bclass->get_times)
978 bclass->get_times (basesink, buffer, &start, &end);
980 start_valid = GST_CLOCK_TIME_IS_VALID (start);
981 end_valid = GST_CLOCK_TIME_IS_VALID (end);
983 GST_DEBUG_OBJECT (basesink, "got times start: %" GST_TIME_FORMAT
984 ", end: %" GST_TIME_FORMAT, GST_TIME_ARGS (start), GST_TIME_ARGS (end));
986 /* if we don't have a timestamp, we don't sync */
988 GST_DEBUG_OBJECT (basesink, "start not valid");
992 /* save last times seen. */
993 basesink->current_start = start;
995 basesink->current_end = end;
997 basesink->current_end = start;
999 if (GST_CLOCK_TIME_IS_VALID (basesink->segment_stop)) {
1000 /* check if not outside of the segment range, start is
1001 * always valid here. */
1002 if (start > basesink->segment_stop)
1003 goto out_of_segment;
1006 /* bring timestamp to stream time using last segment offset. */
1007 if (GST_CLOCK_TIME_IS_VALID (basesink->segment_start)) {
1008 /* check if not outside of the segment range */
1009 if (end_valid && end < basesink->segment_start)
1010 goto out_of_segment;
1012 stream_start = (gint64) start - basesink->segment_start;
1013 stream_end = (gint64) end - basesink->segment_start;
1015 stream_start = (gint64) start;
1016 stream_end = (gint64) end;
1019 /* correct for rate */
1020 if (basesink->segment_rate != 0.0) {
1021 stream_start /= ABS (basesink->segment_rate);
1023 stream_end /= ABS (basesink->segment_rate);
1026 stream_start += basesink->segment_accum;
1028 stream_end += basesink->segment_accum;
1030 /* now do clocking */
1031 if (basesink->clock && basesink->sync) {
1032 GstClockTime base_time;
1034 GST_LOCK (basesink);
1036 base_time = GST_ELEMENT (basesink)->base_time;
1038 GST_LOG_OBJECT (basesink,
1039 "waiting for clock, base time %" GST_TIME_FORMAT
1040 "stream_start %" GST_TIME_FORMAT,
1041 GST_TIME_ARGS (base_time), GST_TIME_ARGS (stream_start));
1043 /* also save end_time of this buffer so that we can wait
1046 basesink->end_time = stream_end + base_time;
1048 basesink->end_time = GST_CLOCK_TIME_NONE;
1050 result = gst_base_sink_wait (basesink, stream_start + base_time);
1052 GST_UNLOCK (basesink);
1054 GST_LOG_OBJECT (basesink, "clock entry done: %d", result);
1056 GST_DEBUG_OBJECT (basesink, "no clock, not syncing");
1064 GST_LOG_OBJECT (basesink, "buffer skipped, not in segment");
1065 return GST_CLOCK_UNSCHEDULED;
1072 * 2) render the event
1073 * 3) unref the event
1075 static inline gboolean
1076 gst_base_sink_handle_event (GstBaseSink * basesink, GstEvent * event)
1078 GstBaseSinkClass *bclass;
1081 switch (GST_EVENT_TYPE (event)) {
1083 GST_LOCK (basesink);
1084 if (basesink->clock) {
1085 /* wait for last buffer to finish if we have a valid end time */
1086 if (GST_CLOCK_TIME_IS_VALID (basesink->end_time)) {
1087 gst_base_sink_wait (basesink, basesink->end_time);
1088 basesink->end_time = GST_CLOCK_TIME_NONE;
1091 GST_UNLOCK (basesink);
1097 bclass = GST_BASE_SINK_GET_CLASS (basesink);
1099 ret = bclass->event (basesink, event);
1103 switch (GST_EVENT_TYPE (event)) {
1105 GST_PREROLL_LOCK (basesink->sinkpad);
1106 /* if we are still EOS, we can post the EOS message */
1107 if (basesink->eos) {
1108 /* ok, now we can post the message */
1109 GST_DEBUG_OBJECT (basesink, "Now posting EOS");
1110 gst_element_post_message (GST_ELEMENT (basesink),
1111 gst_message_new_eos (GST_OBJECT (basesink)));
1112 basesink->eos_queued = FALSE;
1114 GST_PREROLL_UNLOCK (basesink->sinkpad);
1120 GST_DEBUG_OBJECT (basesink, "event unref %p %p", basesink, event);
1121 gst_event_unref (event);
1128 * 1) first sync on the buffer
1129 * 2) render the buffer
1130 * 3) unref the buffer
1132 static inline GstFlowReturn
1133 gst_base_sink_handle_buffer (GstBaseSink * basesink, GstBuffer * buf)
1135 GstFlowReturn ret = GST_FLOW_OK;
1136 GstClockReturn status;
1138 status = gst_base_sink_do_sync (basesink, buf);
1140 case GST_CLOCK_EARLY:
1141 GST_DEBUG_OBJECT (basesink, "buffer too late!, rendering anyway");
1142 /* fallthrough for now */
1145 GstBaseSinkClass *bclass;
1147 bclass = GST_BASE_SINK_GET_CLASS (basesink);
1149 ret = bclass->render (basesink, buf);
1153 GST_DEBUG_OBJECT (basesink, "clock returned %d, not rendering", status);
1157 GST_DEBUG_OBJECT (basesink, "buffer unref after render %p", basesink, buf);
1158 gst_buffer_unref (buf);
1163 static GstFlowReturn
1164 gst_base_sink_chain (GstPad * pad, GstBuffer * buf)
1166 GstBaseSink *basesink;
1167 GstFlowReturn result;
1169 basesink = GST_BASE_SINK (gst_pad_get_parent (pad));
1171 if (!(basesink->pad_mode == GST_ACTIVATE_PUSH)) {
1173 g_warning ("Push on pad %s:%s, but it was not activated in push mode",
1174 GST_DEBUG_PAD_NAME (pad));
1176 result = GST_FLOW_UNEXPECTED;
1180 result = gst_base_sink_handle_object (basesink, pad, GST_MINI_OBJECT (buf));
1183 gst_object_unref (basesink);
1189 gst_base_sink_loop (GstPad * pad)
1191 GstBaseSink *basesink;
1192 GstBuffer *buf = NULL;
1193 GstFlowReturn result;
1195 basesink = GST_BASE_SINK (gst_pad_get_parent (pad));
1197 g_assert (basesink->pad_mode == GST_ACTIVATE_PULL);
1199 result = gst_pad_pull_range (pad, basesink->offset, DEFAULT_SIZE, &buf);
1200 if (result != GST_FLOW_OK)
1203 result = gst_base_sink_handle_object (basesink, pad, GST_MINI_OBJECT (buf));
1204 if (result != GST_FLOW_OK)
1207 gst_object_unref (basesink);
1214 gst_base_sink_event (pad, gst_event_new_eos ());
1215 gst_object_unref (basesink);
1216 gst_pad_pause_task (pad);
1222 gst_base_sink_deactivate (GstBaseSink * basesink, GstPad * pad)
1224 gboolean result = FALSE;
1225 GstBaseSinkClass *bclass;
1227 bclass = GST_BASE_SINK_GET_CLASS (basesink);
1229 /* step 1, unblock clock sync (if any) or any other blocking thing */
1230 GST_PREROLL_LOCK (pad);
1231 GST_LOCK (basesink);
1232 if (basesink->clock_id) {
1233 gst_clock_id_unschedule (basesink->clock_id);
1235 GST_UNLOCK (basesink);
1237 /* unlock any subclasses */
1239 bclass->unlock (basesink);
1241 /* flush out the data thread if it's locked in finish_preroll */
1242 GST_DEBUG_OBJECT (basesink,
1243 "flushing out data thread, need preroll to FALSE");
1244 basesink->need_preroll = FALSE;
1245 gst_base_sink_preroll_queue_flush (basesink, pad);
1246 GST_PREROLL_SIGNAL (pad);
1247 GST_PREROLL_UNLOCK (pad);
1249 /* step 2, make sure streaming finishes */
1250 result = gst_pad_stop_task (pad);
1256 gst_base_sink_activate (GstPad * pad)
1258 gboolean result = FALSE;
1259 GstBaseSink *basesink;
1261 basesink = GST_BASE_SINK (gst_pad_get_parent (pad));
1263 GST_DEBUG_OBJECT (basesink, "Trying pull mode first");
1265 if (basesink->can_activate_pull && gst_pad_check_pull_range (pad)
1266 && gst_pad_activate_pull (pad, TRUE)) {
1267 GST_DEBUG_OBJECT (basesink, "Success activating pull mode");
1270 GST_DEBUG_OBJECT (basesink, "Falling back to push mode");
1271 if (gst_pad_activate_push (pad, TRUE)) {
1272 GST_DEBUG_OBJECT (basesink, "Success activating push mode");
1278 GST_WARNING_OBJECT (basesink, "Could not activate pad in either mode");
1281 gst_object_unref (basesink);
1287 gst_base_sink_activate_push (GstPad * pad, gboolean active)
1290 GstBaseSink *basesink;
1292 basesink = GST_BASE_SINK (gst_pad_get_parent (pad));
1295 if (!basesink->can_activate_push) {
1297 basesink->pad_mode = GST_ACTIVATE_NONE;
1300 basesink->pad_mode = GST_ACTIVATE_PUSH;
1303 if (G_UNLIKELY (basesink->pad_mode != GST_ACTIVATE_PUSH)) {
1304 g_warning ("Internal GStreamer activation error!!!");
1307 result = gst_base_sink_deactivate (basesink, pad);
1308 basesink->pad_mode = GST_ACTIVATE_NONE;
1312 gst_object_unref (basesink);
1317 /* this won't get called until we implement an activate function */
1319 gst_base_sink_activate_pull (GstPad * pad, gboolean active)
1321 gboolean result = FALSE;
1322 GstBaseSink *basesink;
1324 basesink = GST_BASE_SINK (gst_pad_get_parent (pad));
1327 if (!basesink->can_activate_pull) {
1329 basesink->pad_mode = GST_ACTIVATE_NONE;
1331 GstPad *peer = gst_pad_get_peer (pad);
1333 if (G_UNLIKELY (peer == NULL)) {
1334 g_warning ("Trying to activate pad in pull mode, but no peer");
1336 basesink->pad_mode = GST_ACTIVATE_NONE;
1338 if (gst_pad_activate_pull (peer, TRUE)) {
1339 basesink->have_newsegment = TRUE;
1340 basesink->segment_start = basesink->segment_stop = 0;
1342 /* set the pad mode before starting the task so that it's in the
1343 correct state for the new thread... */
1344 basesink->pad_mode = GST_ACTIVATE_PULL;
1346 gst_pad_start_task (pad, (GstTaskFunction) gst_base_sink_loop,
1348 /* but if starting the thread fails, set it back */
1350 basesink->pad_mode = GST_ACTIVATE_NONE;
1352 GST_DEBUG_OBJECT (pad, "Failed to activate peer in pull mode");
1354 basesink->pad_mode = GST_ACTIVATE_NONE;
1356 gst_object_unref (peer);
1360 if (G_UNLIKELY (basesink->pad_mode != GST_ACTIVATE_PULL)) {
1361 g_warning ("Internal GStreamer activation error!!!");
1364 basesink->have_newsegment = FALSE;
1365 result = gst_base_sink_deactivate (basesink, pad);
1366 basesink->pad_mode = GST_ACTIVATE_NONE;
1370 gst_object_unref (basesink);
1376 gst_base_sink_send_event (GstElement * element, GstEvent * event)
1379 GstBaseSink *basesink = GST_BASE_SINK (element);
1383 pad = basesink->sinkpad;
1384 gst_object_ref (pad);
1385 GST_UNLOCK (element);
1387 result = gst_pad_push_event (pad, event);
1389 gst_object_unref (pad);
1395 gst_base_sink_peer_query (GstBaseSink * sink, GstQuery * query)
1398 gboolean res = FALSE;
1400 if ((peer = gst_pad_get_peer (sink->sinkpad))) {
1401 res = gst_pad_query (peer, query);
1402 gst_object_unref (peer);
1408 gst_base_sink_get_position (GstBaseSink * basesink, GstFormat format,
1412 gboolean res = FALSE;
1415 case GST_FORMAT_TIME:
1417 /* we can answer time format */
1418 GST_LOCK (basesink);
1419 if ((clock = GST_ELEMENT_CLOCK (basesink))) {
1421 gint64 segment_time;
1423 gst_object_ref (clock);
1424 GST_UNLOCK (basesink);
1426 now = gst_clock_get_time (clock);
1428 GST_LOCK (basesink);
1429 if (GST_CLOCK_TIME_IS_VALID (basesink->segment_time))
1430 segment_time = basesink->segment_time;
1434 *cur = now - GST_ELEMENT_CAST (basesink)->base_time + segment_time;
1436 GST_DEBUG_OBJECT (basesink,
1437 "now %" GST_TIME_FORMAT " + segment_time %" GST_TIME_FORMAT " = %"
1438 GST_TIME_FORMAT, GST_TIME_ARGS (now),
1439 GST_TIME_ARGS (segment_time), GST_TIME_ARGS (*cur));
1441 gst_object_unref (clock);
1445 GST_UNLOCK (basesink);
1454 gst_base_sink_query (GstElement * element, GstQuery * query)
1456 gboolean res = FALSE;
1458 GstBaseSink *basesink = GST_BASE_SINK (element);
1460 switch (GST_QUERY_TYPE (query)) {
1461 case GST_QUERY_POSITION:
1467 GST_PREROLL_LOCK (basesink->sinkpad);
1468 eos = basesink->eos;
1469 GST_PREROLL_UNLOCK (basesink->sinkpad);
1472 res = gst_base_sink_peer_query (basesink, query);
1474 gst_query_parse_position (query, &format, NULL);
1476 GST_DEBUG_OBJECT (basesink, "current position format %d", format);
1478 if ((res = gst_base_sink_get_position (basesink, format, &cur))) {
1479 gst_query_set_position (query, format, cur);
1481 res = gst_base_sink_peer_query (basesink, query);
1486 case GST_QUERY_DURATION:
1487 res = gst_base_sink_peer_query (basesink, query);
1489 case GST_QUERY_LATENCY:
1491 case GST_QUERY_JITTER:
1493 case GST_QUERY_RATE:
1494 //gst_query_set_rate (query, basesink->segment_rate);
1497 case GST_QUERY_SEGMENT:
1499 /* FIXME, bring start/stop to stream time */
1500 gst_query_set_segment (query, basesink->segment_rate,
1501 GST_FORMAT_TIME, basesink->segment_start, basesink->segment_stop);
1504 case GST_QUERY_SEEKING:
1505 case GST_QUERY_CONVERT:
1506 case GST_QUERY_FORMATS:
1508 res = gst_base_sink_peer_query (basesink, query);
1514 static GstStateChangeReturn
1515 gst_base_sink_change_state (GstElement * element, GstStateChange transition)
1517 GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
1518 GstBaseSink *basesink = GST_BASE_SINK (element);
1519 GstBaseSinkClass *bclass;
1521 bclass = GST_BASE_SINK_GET_CLASS (basesink);
1523 switch (transition) {
1524 case GST_STATE_CHANGE_NULL_TO_READY:
1526 if (!bclass->start (basesink))
1529 case GST_STATE_CHANGE_READY_TO_PAUSED:
1530 /* need to complete preroll before this state change completes, there
1531 * is no data flow in READY so we can safely assume we need to preroll. */
1532 basesink->offset = 0;
1533 GST_PREROLL_LOCK (basesink->sinkpad);
1534 basesink->have_preroll = FALSE;
1535 GST_DEBUG_OBJECT (basesink, "READY to PAUSED, need preroll to FALSE");
1536 basesink->need_preroll = TRUE;
1537 GST_PREROLL_UNLOCK (basesink->sinkpad);
1538 basesink->have_newsegment = FALSE;
1539 basesink->segment_rate = 1.0;
1540 basesink->segment_start = 0;
1541 basesink->segment_stop = 0;
1542 basesink->segment_time = 0;
1543 basesink->segment_accum = 0;
1544 ret = GST_STATE_CHANGE_ASYNC;
1546 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
1547 GST_PREROLL_LOCK (basesink->sinkpad);
1548 /* no preroll needed */
1549 basesink->need_preroll = FALSE;
1551 /* if we have EOS, we should empty the queue now as there will
1552 * be no more data received in the chain function.
1553 * FIXME, this could block the state change function too long when
1554 * we are pushing and syncing the buffers, better start a new
1555 * thread to do this. */
1556 if (basesink->eos) {
1557 gboolean do_eos = !basesink->eos_queued;
1559 gst_base_sink_preroll_queue_empty (basesink, basesink->sinkpad);
1561 /* need to post EOS message here if it was not in the preroll queue we
1564 GST_DEBUG_OBJECT (basesink, "Now posting EOS");
1565 gst_element_post_message (GST_ELEMENT (basesink),
1566 gst_message_new_eos (GST_OBJECT (basesink)));
1568 } else if (!basesink->have_preroll) {
1569 /* queue a commit_state */
1570 basesink->need_preroll = TRUE;
1571 GST_DEBUG_OBJECT (basesink,
1572 "PAUSED to PLAYING, !eos, !have_preroll, need preroll to FALSE");
1573 ret = GST_STATE_CHANGE_ASYNC;
1574 /* we know it's not waiting, no need to signal */
1576 GST_DEBUG_OBJECT (basesink,
1577 "PAUSED to PLAYING, !eos, have_preroll, need preroll to FALSE");
1578 /* now let it play */
1579 GST_PREROLL_SIGNAL (basesink->sinkpad);
1581 GST_PREROLL_UNLOCK (basesink->sinkpad);
1588 GstStateChangeReturn bret;
1590 bret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
1591 if (bret == GST_STATE_CHANGE_FAILURE)
1592 goto activate_failed;
1595 switch (transition) {
1596 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
1598 GstBaseSinkClass *bclass;
1600 bclass = GST_BASE_SINK_GET_CLASS (basesink);
1602 GST_PREROLL_LOCK (basesink->sinkpad);
1603 GST_LOCK (basesink);
1604 /* unlock clock wait if any */
1605 if (basesink->clock_id) {
1606 gst_clock_id_unschedule (basesink->clock_id);
1608 GST_UNLOCK (basesink);
1610 /* unlock any subclasses */
1612 bclass->unlock (basesink);
1614 /* if we don't have a preroll buffer and we have not received EOS,
1615 * we need to wait for a preroll */
1616 GST_DEBUG_OBJECT (basesink, "have_preroll: %d, EOS: %d",
1617 basesink->have_preroll, basesink->eos);
1618 if (!basesink->have_preroll && !basesink->eos
1619 && GST_STATE_PENDING (basesink) == GST_STATE_PAUSED) {
1620 GST_DEBUG_OBJECT (basesink, "PLAYING to PAUSED, need preroll to TRUE");
1621 basesink->need_preroll = TRUE;
1622 ret = GST_STATE_CHANGE_ASYNC;
1624 GST_PREROLL_UNLOCK (basesink->sinkpad);
1627 case GST_STATE_CHANGE_PAUSED_TO_READY:
1629 case GST_STATE_CHANGE_READY_TO_NULL:
1631 if (!bclass->stop (basesink)) {
1632 GST_WARNING ("failed to stop");
1644 GST_DEBUG_OBJECT (basesink, "failed to start");
1645 return GST_STATE_CHANGE_FAILURE;
1649 GST_DEBUG_OBJECT (basesink,
1650 "element failed to change states -- activation problem?");
1651 return GST_STATE_CHANGE_FAILURE;