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;
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);
462 case GST_STATE_PLAYING:
463 basesink->need_preroll = FALSE;
465 /* post PAUSED too when we were READY */
466 if (current == GST_STATE_READY)
469 case GST_STATE_PAUSED:
470 basesink->need_preroll = TRUE;
473 case GST_STATE_READY:
479 if (pending != GST_STATE_VOID_PENDING) {
480 GST_STATE (basesink) = pending;
481 GST_STATE_NEXT (basesink) = GST_STATE_VOID_PENDING;
482 GST_STATE_PENDING (basesink) = GST_STATE_VOID_PENDING;
483 GST_STATE_RETURN (basesink) = GST_STATE_CHANGE_SUCCESS;
485 GST_UNLOCK (basesink);
488 message = gst_message_new_state_changed (GST_OBJECT_CAST (basesink),
489 current, next, GST_STATE_VOID_PENDING);
490 gst_element_post_message (GST_ELEMENT_CAST (basesink), message);
493 message = gst_message_new_state_changed (GST_OBJECT_CAST (basesink),
494 next, pending, GST_STATE_VOID_PENDING);
495 gst_element_post_message (GST_ELEMENT_CAST (basesink), message);
498 if (post_paused || post_playing) {
499 gst_element_post_message (GST_ELEMENT_CAST (basesink),
500 gst_message_new_state_dirty (GST_OBJECT_CAST (basesink)));
503 GST_STATE_BROADCAST (basesink);
509 /* app is going to READY */
510 GST_UNLOCK (basesink);
515 /* with STREAM_LOCK */
517 gst_base_sink_handle_object (GstBaseSink * basesink, GstPad * pad,
523 GST_PREROLL_LOCK (pad);
524 /* push object on the queue */
525 GST_DEBUG_OBJECT (basesink, "push %p on preroll_queue", obj);
526 g_queue_push_tail (basesink->preroll_queue, obj);
528 have_event = GST_IS_EVENT (obj);
530 GstEvent *event = GST_EVENT (obj);
532 switch (GST_EVENT_TYPE (obj)) {
534 basesink->preroll_queued++;
535 basesink->eos = TRUE;
536 basesink->eos_queued = TRUE;
538 case GST_EVENT_NEWSEGMENT:
543 gint64 segment_start;
546 GstClockTime duration;
549 /* the newsegment event is needed to bring the buffer timestamps to the
550 * stream time and to drop samples outside of the playback segment. */
551 gst_event_parse_newsegment (event, &update, &rate, &format,
552 &segment_start, &segment_stop, &segment_time);
554 basesink->have_newsegment = TRUE;
556 /* any other format with 0 also gives time 0, the other values are
557 * invalid as time though. */
558 if (format != GST_FORMAT_TIME && segment_start == 0) {
559 GST_DEBUG_OBJECT (basesink,
560 "non-time newsegment with start 0, coaxing into FORMAT_TIME");
561 format = GST_FORMAT_TIME;
566 if (format != GST_FORMAT_TIME) {
567 GST_DEBUG_OBJECT (basesink,
568 "received non time %d NEW_SEGMENT %" G_GINT64_FORMAT
569 " -- %" G_GINT64_FORMAT ", time %" G_GINT64_FORMAT,
570 format, segment_start, segment_stop, segment_time);
572 /* this means this sink will not be able to clip or drop samples
573 * and timestamps have to start from 0. */
574 basesink->segment_start = -1;
575 basesink->segment_stop = -1;
576 basesink->segment_time = -1;
577 goto done_newsegment;
579 /* check if we really have a new segment or the previous one is
582 /* the new segment has to be aligned with the old segment.
583 * We first update the accumulated time of the previous
584 * segment. the accumulated time is used when syncing to the
585 * clock. A flush event sets the accumulated time back to 0
587 if (GST_CLOCK_TIME_IS_VALID (basesink->segment_stop)) {
588 duration = basesink->segment_stop - basesink->segment_start;
589 } else if (GST_CLOCK_TIME_IS_VALID (basesink->current_end)) {
590 /* else use last seen timestamp as segment stop */
591 duration = basesink->current_end - basesink->segment_start;
596 duration = segment_start - basesink->segment_start;
599 /* use previous rate to calculate duration */
600 basesink->segment_accum += gst_gdouble_to_guint64 (
601 (gst_guint64_to_gdouble (duration) / ABS (basesink->segment_rate)));
602 /* then update the current segment */
603 basesink->segment_rate = rate;
604 basesink->segment_start = segment_start;
605 basesink->segment_stop = segment_stop;
606 basesink->segment_time = segment_time;
608 GST_DEBUG_OBJECT (basesink,
609 "received NEWSEGMENT %" GST_TIME_FORMAT " -- %"
610 GST_TIME_FORMAT ", time %" GST_TIME_FORMAT ", accum %"
612 GST_TIME_ARGS (basesink->segment_start),
613 GST_TIME_ARGS (basesink->segment_stop),
614 GST_TIME_ARGS (basesink->segment_time),
615 GST_TIME_ARGS (basesink->segment_accum));
622 basesink->events_queued++;
624 GstBuffer *buf = GST_BUFFER (obj);
626 if (!basesink->have_newsegment) {
627 GST_ELEMENT_WARNING (basesink, STREAM, FAILED,
628 (_("Internal data flow problem.")),
629 ("Received buffer without a new-segment. Cannot sync to clock."));
630 basesink->have_newsegment = TRUE;
631 /* this means this sink will not be able to sync to the clock */
632 basesink->segment_start = -1;
633 basesink->segment_stop = -1;
636 /* check if the buffer needs to be dropped */
638 GstClockTime start = -1, end = -1;
640 /* we don't use the subclassed method as it may not return
641 * valid values for our purpose here */
642 gst_base_sink_get_times (basesink, buf, &start, &end);
644 GST_DEBUG_OBJECT (basesink, "got times start: %" GST_TIME_FORMAT
645 ", end: %" GST_TIME_FORMAT, GST_TIME_ARGS (start),
646 GST_TIME_ARGS (end));
648 /* need to drop if the timestamp is not between segment_start and
649 * segment_stop. we check if the complete sample is outside of the
650 * range since the sink might be able to clip the sample. */
651 if (GST_CLOCK_TIME_IS_VALID (end) &&
652 GST_CLOCK_TIME_IS_VALID (basesink->segment_start)) {
653 if (end <= basesink->segment_start) {
654 GST_DEBUG_OBJECT (basesink,
655 "buffer end %" GST_TIME_FORMAT " <= segment start %"
656 GST_TIME_FORMAT ", dropping buffer", GST_TIME_ARGS (end),
657 GST_TIME_ARGS (basesink->segment_start));
661 if (GST_CLOCK_TIME_IS_VALID (start) &&
662 GST_CLOCK_TIME_IS_VALID (basesink->segment_stop)) {
663 if (basesink->segment_stop <= start) {
664 GST_DEBUG_OBJECT (basesink,
665 "buffer start %" GST_TIME_FORMAT " >= segment stop %"
666 GST_TIME_FORMAT ", dropping buffer", GST_TIME_ARGS (start),
667 GST_TIME_ARGS (basesink->segment_stop));
672 basesink->preroll_queued++;
673 basesink->buffers_queued++;
676 GST_DEBUG_OBJECT (basesink,
677 "now %d preroll, %d buffers, %d events on queue",
678 basesink->preroll_queued,
679 basesink->buffers_queued, basesink->events_queued);
681 /* check if we are prerolling */
682 if (!basesink->need_preroll)
685 /* there is a buffer queued */
686 if (basesink->buffers_queued == 1) {
687 GST_DEBUG_OBJECT (basesink, "do preroll %p", obj);
689 /* if it's a buffer, we need to call the preroll method */
690 if (GST_IS_BUFFER (obj)) {
691 GstBaseSinkClass *bclass;
693 GstBuffer *buf = GST_BUFFER (obj);
695 GST_DEBUG_OBJECT (basesink, "preroll buffer %" GST_TIME_FORMAT,
696 GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)));
698 bclass = GST_BASE_SINK_GET_CLASS (basesink);
700 if ((pres = bclass->preroll (basesink, buf)) != GST_FLOW_OK)
704 length = basesink->preroll_queued;
705 GST_DEBUG_OBJECT (basesink, "prerolled length %d", length);
709 basesink->have_preroll = TRUE;
712 if (!gst_base_sink_commit_state (basesink))
716 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
720 /* it is possible that commiting the state made us go to PLAYING
721 * now in which case we don't need to block anymore. */
722 if (!basesink->need_preroll)
725 length = basesink->preroll_queued;
727 /* FIXME: a pad probe could have made us lose the buffer, according
728 * to one of the python tests */
730 GST_ERROR_OBJECT (basesink,
731 "preroll_queued dropped from 1 to 0 while committing state change");
733 g_assert (length <= 1);
736 /* see if we need to block now. We cannot block on events, only
737 * on buffers, the reason is that events can be sent from the
738 * application thread and we don't want to block there. */
739 if (length > basesink->preroll_queue_max_len && !have_event) {
740 /* block until the state changes, or we get a flush, or something */
741 GST_DEBUG_OBJECT (basesink, "waiting to finish preroll");
742 GST_PREROLL_WAIT (pad);
743 GST_DEBUG_OBJECT (basesink, "done preroll");
745 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
749 GST_PREROLL_UNLOCK (pad);
757 GST_DEBUG_OBJECT (basesink, "no preroll needed");
758 /* maybe it was another sink that blocked in preroll, need to check for
760 basesink->have_preroll = FALSE;
761 ret = gst_base_sink_preroll_queue_empty (basesink, pad);
762 GST_PREROLL_UNLOCK (pad);
770 buf = GST_BUFFER (g_queue_pop_tail (basesink->preroll_queue));
772 gst_buffer_unref (buf);
773 GST_PREROLL_UNLOCK (pad);
780 gst_base_sink_preroll_queue_flush (basesink, pad);
781 GST_PREROLL_UNLOCK (pad);
782 GST_DEBUG_OBJECT (basesink, "pad is flushing");
784 return GST_FLOW_WRONG_STATE;
788 GST_PREROLL_UNLOCK (pad);
789 GST_DEBUG_OBJECT (basesink, "stopping");
791 return GST_FLOW_WRONG_STATE;
795 GST_DEBUG_OBJECT (basesink, "preroll failed");
796 gst_base_sink_preroll_queue_flush (basesink, pad);
798 GST_DEBUG_OBJECT (basesink, "abort state");
799 gst_element_abort_state (GST_ELEMENT (basesink));
801 return GST_FLOW_ERROR;
806 gst_base_sink_event (GstPad * pad, GstEvent * event)
808 GstBaseSink *basesink;
809 gboolean result = TRUE;
810 GstBaseSinkClass *bclass;
812 basesink = GST_BASE_SINK (gst_pad_get_parent (pad));
814 bclass = GST_BASE_SINK_GET_CLASS (basesink);
816 GST_DEBUG_OBJECT (basesink, "event %p", event);
818 switch (GST_EVENT_TYPE (event)) {
823 GST_STREAM_LOCK (pad);
824 /* EOS also finishes the preroll */
826 gst_base_sink_handle_object (basesink, pad, GST_MINI_OBJECT (event));
827 GST_STREAM_UNLOCK (pad);
830 case GST_EVENT_NEWSEGMENT:
834 GST_STREAM_LOCK (pad);
836 gst_base_sink_handle_object (basesink, pad, GST_MINI_OBJECT (event));
837 GST_STREAM_UNLOCK (pad);
840 case GST_EVENT_FLUSH_START:
841 /* make sure we are not blocked on the clock also clear any pending
844 bclass->event (basesink, event);
847 basesink->flushing = TRUE;
848 if (basesink->clock_id) {
849 gst_clock_id_unschedule (basesink->clock_id);
851 GST_UNLOCK (basesink);
853 GST_PREROLL_LOCK (pad);
854 /* we need preroll after the flush */
855 GST_DEBUG_OBJECT (basesink, "flushing, need preroll after flush");
856 basesink->need_preroll = TRUE;
857 /* unlock from a possible state change/preroll */
858 gst_base_sink_preroll_queue_flush (basesink, pad);
859 GST_PREROLL_UNLOCK (pad);
861 /* and we need to commit our state again on the next
862 * prerolled buffer */
863 GST_STREAM_LOCK (pad);
864 gst_element_lost_state (GST_ELEMENT (basesink));
865 GST_STREAM_UNLOCK (pad);
866 GST_DEBUG_OBJECT (basesink, "event unref %p %p", basesink, event);
867 gst_event_unref (event);
869 case GST_EVENT_FLUSH_STOP:
871 bclass->event (basesink, event);
873 /* now we are completely unblocked and the _chain method
875 GST_STREAM_LOCK (pad);
877 basesink->flushing = FALSE;
878 GST_UNLOCK (basesink);
879 /* we need new segment info after the flush. */
880 basesink->segment_start = -1;
881 basesink->segment_stop = -1;
882 basesink->current_start = -1;
883 basesink->current_end = -1;
884 GST_DEBUG_OBJECT (basesink, "reset accum %" GST_TIME_FORMAT,
885 GST_TIME_ARGS (basesink->segment_accum));
886 basesink->segment_accum = 0;
887 GST_STREAM_UNLOCK (pad);
889 GST_DEBUG_OBJECT (basesink, "event unref %p %p", basesink, event);
890 gst_event_unref (event);
893 gst_event_unref (event);
896 gst_object_unref (basesink);
901 /* default implementation to calculate the start and end
902 * timestamps on a buffer, subclasses can override
905 gst_base_sink_get_times (GstBaseSink * basesink, GstBuffer * buffer,
906 GstClockTime * start, GstClockTime * end)
908 GstClockTime timestamp, duration;
910 timestamp = GST_BUFFER_TIMESTAMP (buffer);
911 if (GST_CLOCK_TIME_IS_VALID (timestamp)) {
913 /* get duration to calculate end time */
914 duration = GST_BUFFER_DURATION (buffer);
915 if (GST_CLOCK_TIME_IS_VALID (duration)) {
916 *end = timestamp + duration;
922 /* with STREAM_LOCK and LOCK*/
923 static GstClockReturn
924 gst_base_sink_wait (GstBaseSink * basesink, GstClockTime time)
929 /* no need to attempt a clock wait if we are flushing */
930 if (basesink->flushing) {
931 return GST_CLOCK_UNSCHEDULED;
934 /* clock_id should be NULL outside of this function */
935 g_assert (basesink->clock_id == NULL);
936 g_assert (GST_CLOCK_TIME_IS_VALID (time));
938 id = gst_clock_new_single_shot_id (basesink->clock, time);
940 basesink->clock_id = id;
941 /* release the object lock while waiting */
942 GST_UNLOCK (basesink);
944 ret = gst_clock_id_wait (id, NULL);
947 gst_clock_id_unref (id);
948 basesink->clock_id = NULL;
953 /* perform synchronisation on a buffer
955 * 1) check if we have a clock, if not, do nothing
956 * 2) calculate the start and end time of the buffer
957 * 3) create a single shot notification to wait on
958 * the clock, save the entry so we can unlock it
959 * 4) wait on the clock, this blocks
960 * 5) unref the clockid again
962 static GstClockReturn
963 gst_base_sink_do_sync (GstBaseSink * basesink, GstBuffer * buffer)
965 GstClockReturn result = GST_CLOCK_OK;
966 GstClockTime start, end;
967 GstClockTimeDiff stream_start, stream_end;
968 GstBaseSinkClass *bclass;
969 gboolean start_valid, end_valid;
971 bclass = GST_BASE_SINK_GET_CLASS (basesink);
974 if (bclass->get_times)
975 bclass->get_times (basesink, buffer, &start, &end);
977 start_valid = GST_CLOCK_TIME_IS_VALID (start);
978 end_valid = GST_CLOCK_TIME_IS_VALID (end);
980 GST_DEBUG_OBJECT (basesink, "got times start: %" GST_TIME_FORMAT
981 ", end: %" GST_TIME_FORMAT, GST_TIME_ARGS (start), GST_TIME_ARGS (end));
983 /* if we don't have a timestamp, we don't sync */
985 GST_DEBUG_OBJECT (basesink, "start not valid");
989 /* save last times seen. */
990 basesink->current_start = start;
992 basesink->current_end = end;
994 basesink->current_end = start;
996 if (GST_CLOCK_TIME_IS_VALID (basesink->segment_stop)) {
997 /* check if not outside of the segment range, start is
998 * always valid here. */
999 if (start > basesink->segment_stop)
1000 goto out_of_segment;
1003 /* bring timestamp to stream time using last segment offset. */
1004 if (GST_CLOCK_TIME_IS_VALID (basesink->segment_start)) {
1005 /* check if not outside of the segment range */
1006 if (end_valid && end < basesink->segment_start)
1007 goto out_of_segment;
1009 stream_start = (gint64) start - basesink->segment_start;
1010 stream_end = (gint64) end - basesink->segment_start;
1012 stream_start = (gint64) start;
1013 stream_end = (gint64) end;
1016 /* correct for rate */
1017 if (basesink->segment_rate != 0.0) {
1018 stream_start /= ABS (basesink->segment_rate);
1020 stream_end /= ABS (basesink->segment_rate);
1023 stream_start += basesink->segment_accum;
1025 stream_end += basesink->segment_accum;
1027 /* now do clocking */
1028 if (basesink->clock && basesink->sync) {
1029 GstClockTime base_time;
1031 GST_LOCK (basesink);
1033 base_time = GST_ELEMENT (basesink)->base_time;
1035 GST_LOG_OBJECT (basesink,
1036 "waiting for clock, base time %" GST_TIME_FORMAT
1037 "stream_start %" GST_TIME_FORMAT,
1038 GST_TIME_ARGS (base_time), GST_TIME_ARGS (stream_start));
1040 /* also save end_time of this buffer so that we can wait
1043 basesink->end_time = stream_end + base_time;
1045 basesink->end_time = GST_CLOCK_TIME_NONE;
1047 result = gst_base_sink_wait (basesink, stream_start + base_time);
1049 GST_UNLOCK (basesink);
1051 GST_LOG_OBJECT (basesink, "clock entry done: %d", result);
1053 GST_DEBUG_OBJECT (basesink, "no clock, not syncing");
1061 GST_LOG_OBJECT (basesink, "buffer skipped, not in segment");
1062 return GST_CLOCK_UNSCHEDULED;
1069 * 2) render the event
1070 * 3) unref the event
1072 static inline gboolean
1073 gst_base_sink_handle_event (GstBaseSink * basesink, GstEvent * event)
1075 GstBaseSinkClass *bclass;
1078 switch (GST_EVENT_TYPE (event)) {
1080 GST_LOCK (basesink);
1081 if (basesink->clock) {
1082 /* wait for last buffer to finish if we have a valid end time */
1083 if (GST_CLOCK_TIME_IS_VALID (basesink->end_time)) {
1084 gst_base_sink_wait (basesink, basesink->end_time);
1085 basesink->end_time = GST_CLOCK_TIME_NONE;
1088 GST_UNLOCK (basesink);
1094 bclass = GST_BASE_SINK_GET_CLASS (basesink);
1096 ret = bclass->event (basesink, event);
1100 switch (GST_EVENT_TYPE (event)) {
1102 GST_PREROLL_LOCK (basesink->sinkpad);
1103 /* if we are still EOS, we can post the EOS message */
1104 if (basesink->eos) {
1105 /* ok, now we can post the message */
1106 GST_DEBUG_OBJECT (basesink, "Now posting EOS");
1107 gst_element_post_message (GST_ELEMENT (basesink),
1108 gst_message_new_eos (GST_OBJECT (basesink)));
1109 basesink->eos_queued = FALSE;
1111 GST_PREROLL_UNLOCK (basesink->sinkpad);
1117 GST_DEBUG_OBJECT (basesink, "event unref %p %p", basesink, event);
1118 gst_event_unref (event);
1125 * 1) first sync on the buffer
1126 * 2) render the buffer
1127 * 3) unref the buffer
1129 static inline GstFlowReturn
1130 gst_base_sink_handle_buffer (GstBaseSink * basesink, GstBuffer * buf)
1132 GstFlowReturn ret = GST_FLOW_OK;
1133 GstClockReturn status;
1135 status = gst_base_sink_do_sync (basesink, buf);
1137 case GST_CLOCK_EARLY:
1138 GST_DEBUG_OBJECT (basesink, "buffer too late!, rendering anyway");
1139 /* fallthrough for now */
1142 GstBaseSinkClass *bclass;
1144 bclass = GST_BASE_SINK_GET_CLASS (basesink);
1146 ret = bclass->render (basesink, buf);
1150 GST_DEBUG_OBJECT (basesink, "clock returned %d, not rendering", status);
1154 GST_DEBUG_OBJECT (basesink, "buffer unref after render %p", basesink, buf);
1155 gst_buffer_unref (buf);
1160 static GstFlowReturn
1161 gst_base_sink_chain (GstPad * pad, GstBuffer * buf)
1163 GstBaseSink *basesink;
1164 GstFlowReturn result;
1166 basesink = GST_BASE_SINK (gst_pad_get_parent (pad));
1168 if (!(basesink->pad_mode == GST_ACTIVATE_PUSH)) {
1170 g_warning ("Push on pad %s:%s, but it was not activated in push mode",
1171 GST_DEBUG_PAD_NAME (pad));
1173 result = GST_FLOW_UNEXPECTED;
1177 result = gst_base_sink_handle_object (basesink, pad, GST_MINI_OBJECT (buf));
1180 gst_object_unref (basesink);
1186 gst_base_sink_loop (GstPad * pad)
1188 GstBaseSink *basesink;
1189 GstBuffer *buf = NULL;
1190 GstFlowReturn result;
1192 basesink = GST_BASE_SINK (gst_pad_get_parent (pad));
1194 g_assert (basesink->pad_mode == GST_ACTIVATE_PULL);
1196 result = gst_pad_pull_range (pad, basesink->offset, DEFAULT_SIZE, &buf);
1197 if (result != GST_FLOW_OK)
1200 result = gst_base_sink_handle_object (basesink, pad, GST_MINI_OBJECT (buf));
1201 if (result != GST_FLOW_OK)
1204 gst_object_unref (basesink);
1211 gst_base_sink_event (pad, gst_event_new_eos ());
1212 gst_object_unref (basesink);
1213 gst_pad_pause_task (pad);
1219 gst_base_sink_deactivate (GstBaseSink * basesink, GstPad * pad)
1221 gboolean result = FALSE;
1222 GstBaseSinkClass *bclass;
1224 bclass = GST_BASE_SINK_GET_CLASS (basesink);
1226 /* step 1, unblock clock sync (if any) or any other blocking thing */
1227 GST_PREROLL_LOCK (pad);
1228 GST_LOCK (basesink);
1229 if (basesink->clock_id) {
1230 gst_clock_id_unschedule (basesink->clock_id);
1232 GST_UNLOCK (basesink);
1234 /* unlock any subclasses */
1236 bclass->unlock (basesink);
1238 /* flush out the data thread if it's locked in finish_preroll */
1239 GST_DEBUG_OBJECT (basesink,
1240 "flushing out data thread, need preroll to FALSE");
1241 basesink->need_preroll = FALSE;
1242 gst_base_sink_preroll_queue_flush (basesink, pad);
1243 GST_PREROLL_SIGNAL (pad);
1244 GST_PREROLL_UNLOCK (pad);
1246 /* step 2, make sure streaming finishes */
1247 result = gst_pad_stop_task (pad);
1253 gst_base_sink_activate (GstPad * pad)
1255 gboolean result = FALSE;
1256 GstBaseSink *basesink;
1258 basesink = GST_BASE_SINK (gst_pad_get_parent (pad));
1260 GST_DEBUG_OBJECT (basesink, "Trying pull mode first");
1262 if (basesink->can_activate_pull && gst_pad_check_pull_range (pad)
1263 && gst_pad_activate_pull (pad, TRUE)) {
1264 GST_DEBUG_OBJECT (basesink, "Success activating pull mode");
1267 GST_DEBUG_OBJECT (basesink, "Falling back to push mode");
1268 if (gst_pad_activate_push (pad, TRUE)) {
1269 GST_DEBUG_OBJECT (basesink, "Success activating push mode");
1275 GST_WARNING_OBJECT (basesink, "Could not activate pad in either mode");
1278 gst_object_unref (basesink);
1284 gst_base_sink_activate_push (GstPad * pad, gboolean active)
1287 GstBaseSink *basesink;
1289 basesink = GST_BASE_SINK (gst_pad_get_parent (pad));
1292 if (!basesink->can_activate_push) {
1294 basesink->pad_mode = GST_ACTIVATE_NONE;
1297 basesink->pad_mode = GST_ACTIVATE_PUSH;
1300 if (G_UNLIKELY (basesink->pad_mode != GST_ACTIVATE_PUSH)) {
1301 g_warning ("Internal GStreamer activation error!!!");
1304 result = gst_base_sink_deactivate (basesink, pad);
1305 basesink->pad_mode = GST_ACTIVATE_NONE;
1309 gst_object_unref (basesink);
1314 /* this won't get called until we implement an activate function */
1316 gst_base_sink_activate_pull (GstPad * pad, gboolean active)
1318 gboolean result = FALSE;
1319 GstBaseSink *basesink;
1321 basesink = GST_BASE_SINK (gst_pad_get_parent (pad));
1324 if (!basesink->can_activate_pull) {
1326 basesink->pad_mode = GST_ACTIVATE_NONE;
1328 GstPad *peer = gst_pad_get_peer (pad);
1330 if (G_UNLIKELY (peer == NULL)) {
1331 g_warning ("Trying to activate pad in pull mode, but no peer");
1333 basesink->pad_mode = GST_ACTIVATE_NONE;
1335 if (gst_pad_activate_pull (peer, TRUE)) {
1336 basesink->have_newsegment = TRUE;
1337 basesink->segment_start = basesink->segment_stop = 0;
1339 /* set the pad mode before starting the task so that it's in the
1340 correct state for the new thread... */
1341 basesink->pad_mode = GST_ACTIVATE_PULL;
1343 gst_pad_start_task (pad, (GstTaskFunction) gst_base_sink_loop,
1345 /* but if starting the thread fails, set it back */
1347 basesink->pad_mode = GST_ACTIVATE_NONE;
1349 GST_DEBUG_OBJECT (pad, "Failed to activate peer in pull mode");
1351 basesink->pad_mode = GST_ACTIVATE_NONE;
1353 gst_object_unref (peer);
1357 if (G_UNLIKELY (basesink->pad_mode != GST_ACTIVATE_PULL)) {
1358 g_warning ("Internal GStreamer activation error!!!");
1361 basesink->have_newsegment = FALSE;
1362 result = gst_base_sink_deactivate (basesink, pad);
1363 basesink->pad_mode = GST_ACTIVATE_NONE;
1367 gst_object_unref (basesink);
1373 gst_base_sink_send_event (GstElement * element, GstEvent * event)
1376 GstBaseSink *basesink = GST_BASE_SINK (element);
1380 pad = basesink->sinkpad;
1381 gst_object_ref (pad);
1382 GST_UNLOCK (element);
1384 result = gst_pad_push_event (pad, event);
1386 gst_object_unref (pad);
1392 gst_base_sink_peer_query (GstBaseSink * sink, GstQuery * query)
1395 gboolean res = FALSE;
1397 if ((peer = gst_pad_get_peer (sink->sinkpad))) {
1398 res = gst_pad_query (peer, query);
1399 gst_object_unref (peer);
1405 gst_base_sink_get_position (GstBaseSink * basesink, GstFormat format,
1409 gboolean res = FALSE;
1412 case GST_FORMAT_TIME:
1414 /* we can answer time format */
1415 GST_LOCK (basesink);
1416 if ((clock = GST_ELEMENT_CLOCK (basesink))) {
1418 gint64 segment_time;
1420 gst_object_ref (clock);
1421 GST_UNLOCK (basesink);
1423 now = gst_clock_get_time (clock);
1425 GST_LOCK (basesink);
1426 if (GST_CLOCK_TIME_IS_VALID (basesink->segment_time))
1427 segment_time = basesink->segment_time;
1431 *cur = now - GST_ELEMENT_CAST (basesink)->base_time + segment_time;
1433 GST_DEBUG_OBJECT (basesink,
1434 "now %" GST_TIME_FORMAT " + segment_time %" GST_TIME_FORMAT " = %"
1435 GST_TIME_FORMAT, GST_TIME_ARGS (now),
1436 GST_TIME_ARGS (segment_time), GST_TIME_ARGS (*cur));
1438 gst_object_unref (clock);
1442 GST_UNLOCK (basesink);
1451 gst_base_sink_query (GstElement * element, GstQuery * query)
1453 gboolean res = FALSE;
1455 GstBaseSink *basesink = GST_BASE_SINK (element);
1457 switch (GST_QUERY_TYPE (query)) {
1458 case GST_QUERY_POSITION:
1464 GST_PREROLL_LOCK (basesink->sinkpad);
1465 eos = basesink->eos;
1466 GST_PREROLL_UNLOCK (basesink->sinkpad);
1469 res = gst_base_sink_peer_query (basesink, query);
1471 gst_query_parse_position (query, &format, NULL);
1473 GST_DEBUG_OBJECT (basesink, "current position format %d", format);
1475 if ((res = gst_base_sink_get_position (basesink, format, &cur))) {
1476 gst_query_set_position (query, format, cur);
1478 res = gst_base_sink_peer_query (basesink, query);
1483 case GST_QUERY_DURATION:
1484 res = gst_base_sink_peer_query (basesink, query);
1486 case GST_QUERY_LATENCY:
1488 case GST_QUERY_JITTER:
1490 case GST_QUERY_RATE:
1491 //gst_query_set_rate (query, basesink->segment_rate);
1494 case GST_QUERY_SEGMENT:
1496 /* FIXME, bring start/stop to stream time */
1497 gst_query_set_segment (query, basesink->segment_rate,
1498 GST_FORMAT_TIME, basesink->segment_start, basesink->segment_stop);
1501 case GST_QUERY_SEEKING:
1502 case GST_QUERY_CONVERT:
1503 case GST_QUERY_FORMATS:
1505 res = gst_base_sink_peer_query (basesink, query);
1511 static GstStateChangeReturn
1512 gst_base_sink_change_state (GstElement * element, GstStateChange transition)
1514 GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
1515 GstBaseSink *basesink = GST_BASE_SINK (element);
1516 GstBaseSinkClass *bclass;
1518 bclass = GST_BASE_SINK_GET_CLASS (basesink);
1520 switch (transition) {
1521 case GST_STATE_CHANGE_NULL_TO_READY:
1523 if (!bclass->start (basesink))
1526 case GST_STATE_CHANGE_READY_TO_PAUSED:
1527 /* need to complete preroll before this state change completes, there
1528 * is no data flow in READY so we can safely assume we need to preroll. */
1529 basesink->offset = 0;
1530 GST_PREROLL_LOCK (basesink->sinkpad);
1531 basesink->have_preroll = FALSE;
1532 GST_DEBUG_OBJECT (basesink, "READY to PAUSED, need preroll to FALSE");
1533 basesink->need_preroll = TRUE;
1534 GST_PREROLL_UNLOCK (basesink->sinkpad);
1535 basesink->have_newsegment = FALSE;
1536 basesink->segment_rate = 1.0;
1537 basesink->segment_start = 0;
1538 basesink->segment_stop = 0;
1539 basesink->segment_time = 0;
1540 basesink->segment_accum = 0;
1541 ret = GST_STATE_CHANGE_ASYNC;
1543 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
1544 GST_PREROLL_LOCK (basesink->sinkpad);
1545 /* no preroll needed */
1546 basesink->need_preroll = FALSE;
1548 /* if we have EOS, we should empty the queue now as there will
1549 * be no more data received in the chain function.
1550 * FIXME, this could block the state change function too long when
1551 * we are pushing and syncing the buffers, better start a new
1552 * thread to do this. */
1553 if (basesink->eos) {
1554 gboolean do_eos = !basesink->eos_queued;
1556 gst_base_sink_preroll_queue_empty (basesink, basesink->sinkpad);
1558 /* need to post EOS message here if it was not in the preroll queue we
1561 GST_DEBUG_OBJECT (basesink, "Now posting EOS");
1562 gst_element_post_message (GST_ELEMENT (basesink),
1563 gst_message_new_eos (GST_OBJECT (basesink)));
1565 } else if (!basesink->have_preroll) {
1566 /* queue a commit_state */
1567 basesink->need_preroll = TRUE;
1568 GST_DEBUG_OBJECT (basesink,
1569 "PAUSED to PLAYING, !eos, !have_preroll, need preroll to FALSE");
1570 ret = GST_STATE_CHANGE_ASYNC;
1571 /* we know it's not waiting, no need to signal */
1573 GST_DEBUG_OBJECT (basesink,
1574 "PAUSED to PLAYING, !eos, have_preroll, need preroll to FALSE");
1575 /* now let it play */
1576 GST_PREROLL_SIGNAL (basesink->sinkpad);
1578 GST_PREROLL_UNLOCK (basesink->sinkpad);
1585 GstStateChangeReturn bret;
1587 bret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
1588 if (bret == GST_STATE_CHANGE_FAILURE)
1589 goto activate_failed;
1592 switch (transition) {
1593 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
1595 GstBaseSinkClass *bclass;
1597 bclass = GST_BASE_SINK_GET_CLASS (basesink);
1599 GST_PREROLL_LOCK (basesink->sinkpad);
1600 GST_LOCK (basesink);
1601 /* unlock clock wait if any */
1602 if (basesink->clock_id) {
1603 gst_clock_id_unschedule (basesink->clock_id);
1605 GST_UNLOCK (basesink);
1607 /* unlock any subclasses */
1609 bclass->unlock (basesink);
1611 /* if we don't have a preroll buffer and we have not received EOS,
1612 * we need to wait for a preroll */
1613 GST_DEBUG_OBJECT (basesink, "have_preroll: %d, EOS: %d",
1614 basesink->have_preroll, basesink->eos);
1615 if (!basesink->have_preroll && !basesink->eos
1616 && GST_STATE_PENDING (basesink) == GST_STATE_PAUSED) {
1617 GST_DEBUG_OBJECT (basesink, "PLAYING to PAUSED, need preroll to TRUE");
1618 basesink->need_preroll = TRUE;
1619 ret = GST_STATE_CHANGE_ASYNC;
1621 GST_PREROLL_UNLOCK (basesink->sinkpad);
1624 case GST_STATE_CHANGE_PAUSED_TO_READY:
1626 case GST_STATE_CHANGE_READY_TO_NULL:
1628 if (!bclass->stop (basesink)) {
1629 GST_WARNING ("failed to stop");
1641 GST_DEBUG_OBJECT (basesink, "failed to start");
1642 return GST_STATE_CHANGE_FAILURE;
1646 GST_DEBUG_OBJECT (basesink,
1647 "element failed to change states -- activation problem?");
1648 return GST_STATE_CHANGE_FAILURE;