2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
4 * 2003 Colin Walters <cwalters@gnome.org>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
25 #include "gst_private.h"
28 #include "gstscheduler.h"
32 static GstElementDetails gst_queue_details = GST_ELEMENT_DETAILS (
36 "Erik Walthinsen <omega@cse.ogi.edu>"
40 /* Queue signals and args */
57 ARG_MIN_THRESHOLD_BYTES,
62 static void gst_queue_base_init (gpointer g_class);
63 static void gst_queue_class_init (gpointer g_class,
65 static void gst_queue_init (GTypeInstance *instance,
67 static void gst_queue_dispose (GObject *object);
69 static void gst_queue_set_property (GObject *object, guint prop_id,
70 const GValue *value, GParamSpec *pspec);
71 static void gst_queue_get_property (GObject *object, guint prop_id,
72 GValue *value, GParamSpec *pspec);
74 static void gst_queue_chain (GstPad *pad, GstData *data);
75 static GstData * gst_queue_get (GstPad *pad);
76 static GstBufferPool* gst_queue_get_bufferpool (GstPad *pad);
78 static gboolean gst_queue_handle_src_event (GstPad *pad, GstEvent *event);
81 static void gst_queue_locked_flush (GstQueue *queue);
83 static GstElementStateReturn gst_queue_change_state (GstElement *element);
84 static gboolean gst_queue_release_locks (GstElement *element);
87 #define GST_TYPE_QUEUE_LEAKY (queue_leaky_get_type())
89 queue_leaky_get_type(void) {
90 static GType queue_leaky_type = 0;
91 static GEnumValue queue_leaky[] = {
92 { GST_QUEUE_NO_LEAK, "0", "Not Leaky" },
93 { GST_QUEUE_LEAK_UPSTREAM, "1", "Leaky on Upstream" },
94 { GST_QUEUE_LEAK_DOWNSTREAM, "2", "Leaky on Downstream" },
97 if (!queue_leaky_type) {
98 queue_leaky_type = g_enum_register_static("GstQueueLeaky", queue_leaky);
100 return queue_leaky_type;
103 static GstElementClass *parent_class = NULL;
104 static guint gst_queue_signals[LAST_SIGNAL] = { 0 };
107 gst_queue_get_type(void)
109 static GType queue_type = 0;
112 static const GTypeInfo queue_info = {
113 sizeof(GstQueueClass),
116 gst_queue_class_init,
124 queue_type = g_type_register_static (GST_TYPE_ELEMENT, "GstQueue", &queue_info, 0);
130 gst_queue_base_init (gpointer g_class)
132 GstElementClass *gstelement_class = GST_ELEMENT_CLASS (g_class);
134 gst_element_class_set_details (gstelement_class, &gst_queue_details);
138 gst_queue_class_init (gpointer g_class, gpointer class_data)
140 GObjectClass *gobject_class = G_OBJECT_CLASS (g_class);
141 GstElementClass *gstelement_class = GST_ELEMENT_CLASS (g_class);
142 GstQueueClass *gstqueue_class = GST_QUEUE_CLASS (g_class);
144 parent_class = g_type_class_peek_parent (g_class);
146 gst_queue_signals[FULL] =
147 g_signal_new ("full", G_TYPE_FROM_CLASS (gstqueue_class), G_SIGNAL_RUN_FIRST,
148 G_STRUCT_OFFSET (GstQueueClass, full), NULL, NULL,
149 g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
150 g_object_class_install_property (G_OBJECT_CLASS (gstqueue_class), ARG_LEAKY,
151 g_param_spec_enum ("leaky", "Leaky", "Where the queue leaks, if at all.",
152 GST_TYPE_QUEUE_LEAKY, GST_QUEUE_NO_LEAK, G_PARAM_READWRITE));
153 g_object_class_install_property (G_OBJECT_CLASS (gstqueue_class), ARG_LEVEL,
154 g_param_spec_int ("level", "Level", "How many buffers are in the queue.",
155 0, G_MAXINT, 0, G_PARAM_READABLE));
156 g_object_class_install_property (G_OBJECT_CLASS (gstqueue_class), ARG_MAX_LEVEL,
157 g_param_spec_int ("max_level", "Maximum Level", "How many buffers the queue holds.",
158 0, G_MAXINT, 100, G_PARAM_READWRITE));
159 g_object_class_install_property (G_OBJECT_CLASS (gstqueue_class), ARG_MIN_THRESHOLD_BYTES,
160 g_param_spec_int ("min_threshold_bytes", "Minimum Threshold",
161 "Minimum bytes required before signalling not_empty to reader.",
162 0, G_MAXINT, 0, G_PARAM_READWRITE));
163 g_object_class_install_property (G_OBJECT_CLASS (gstqueue_class), ARG_MAY_DEADLOCK,
164 g_param_spec_boolean ("may_deadlock", "May Deadlock", "The queue may deadlock if it's full and not PLAYING",
165 TRUE, G_PARAM_READWRITE));
166 g_object_class_install_property (G_OBJECT_CLASS (gstqueue_class), ARG_BLOCK_TIMEOUT,
167 g_param_spec_int ("block_timeout", "Timeout for Block",
168 "Microseconds until blocked queue times out and returns filler event. "
169 "Value of -1 disables timeout",
170 -1, G_MAXINT, -1, G_PARAM_READWRITE));
172 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_queue_dispose);
173 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_queue_set_property);
174 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_queue_get_property);
176 gstelement_class->change_state = GST_DEBUG_FUNCPTR(gst_queue_change_state);
177 gstelement_class->release_locks = GST_DEBUG_FUNCPTR(gst_queue_release_locks);
180 static GstPadLinkReturn
181 gst_queue_link (GstPad *pad, GstCaps *caps)
183 GstQueue *queue = GST_QUEUE (gst_pad_get_parent (pad));
186 if (pad == queue->srcpad)
187 otherpad = queue->sinkpad;
189 otherpad = queue->srcpad;
191 return gst_pad_proxy_link (otherpad, caps);
195 gst_queue_getcaps (GstPad *pad, GstCaps *caps)
197 GstQueue *queue = GST_QUEUE (gst_pad_get_parent (pad));
200 if (pad == queue->srcpad)
201 otherpad = GST_PAD_PEER (queue->sinkpad);
203 otherpad = GST_PAD_PEER (queue->srcpad);
206 return gst_pad_get_caps (otherpad);
212 gst_queue_init (GTypeInstance *instance, gpointer g_class)
214 GstQueue *queue = GST_QUEUE (instance);
216 /* scheduling on this kind of element is, well, interesting */
217 GST_FLAG_SET (queue, GST_ELEMENT_DECOUPLED);
218 GST_FLAG_SET (queue, GST_ELEMENT_EVENT_AWARE);
220 queue->sinkpad = gst_pad_new ("sink", GST_PAD_SINK);
221 gst_pad_set_chain_function (queue->sinkpad, GST_DEBUG_FUNCPTR (gst_queue_chain));
222 gst_element_add_pad (GST_ELEMENT (queue), queue->sinkpad);
223 gst_pad_set_bufferpool_function (queue->sinkpad, GST_DEBUG_FUNCPTR (gst_queue_get_bufferpool));
224 gst_pad_set_link_function (queue->sinkpad, GST_DEBUG_FUNCPTR (gst_queue_link));
225 gst_pad_set_getcaps_function (queue->sinkpad, GST_DEBUG_FUNCPTR (gst_queue_getcaps));
226 gst_pad_set_active (queue->sinkpad, TRUE);
228 queue->srcpad = gst_pad_new ("src", GST_PAD_SRC);
229 gst_pad_set_get_function (queue->srcpad, GST_DEBUG_FUNCPTR (gst_queue_get));
230 gst_element_add_pad (GST_ELEMENT (queue), queue->srcpad);
231 gst_pad_set_link_function (queue->srcpad, GST_DEBUG_FUNCPTR (gst_queue_link));
232 gst_pad_set_getcaps_function (queue->srcpad, GST_DEBUG_FUNCPTR (gst_queue_getcaps));
233 gst_pad_set_event_function (queue->srcpad, GST_DEBUG_FUNCPTR (gst_queue_handle_src_event));
234 gst_pad_set_active (queue->srcpad, TRUE);
236 queue->leaky = GST_QUEUE_NO_LEAK;
238 queue->level_buffers = 0;
239 queue->level_bytes = 0;
240 queue->level_time = G_GINT64_CONSTANT (0);
241 queue->size_buffers = 100; /* 100 buffers */
242 queue->size_bytes = 100 * 1024; /* 100KB */
243 queue->size_time = GST_SECOND; /* 1sec */
244 queue->min_threshold_bytes = 0;
245 queue->may_deadlock = TRUE;
246 queue->block_timeout = -1;
247 queue->interrupt = FALSE;
248 queue->flush = FALSE;
250 queue->qlock = g_mutex_new ();
251 queue->not_empty = g_cond_new ();
252 queue->not_full = g_cond_new ();
253 queue->events = g_async_queue_new();
254 queue->queue = g_queue_new ();
255 GST_CAT_DEBUG_OBJECT (GST_CAT_THREAD, queue, "initialized queue's not_empty & not_full conditions");
259 gst_queue_dispose (GObject *object)
261 GstQueue *queue = GST_QUEUE (object);
263 gst_element_set_state (GST_ELEMENT (queue), GST_STATE_NULL);
265 g_mutex_free (queue->qlock);
266 g_cond_free (queue->not_empty);
267 g_cond_free (queue->not_full);
268 g_queue_free (queue->queue);
270 g_async_queue_unref(queue->events);
272 G_OBJECT_CLASS (parent_class)->dispose (object);
275 static GstBufferPool*
276 gst_queue_get_bufferpool (GstPad *pad)
280 queue = GST_QUEUE (GST_OBJECT_PARENT (pad));
282 return gst_pad_get_bufferpool (queue->srcpad);
286 gst_queue_cleanup_data (gpointer data, const gpointer user_data)
288 GST_CAT_DEBUG_OBJECT (GST_CAT_DATAFLOW, user_data, "cleaning buffer %p", data);
290 gst_data_unref (GST_DATA (data));
294 gst_queue_locked_flush (GstQueue *queue)
298 while ((data = g_queue_pop_head (queue->queue))) {
299 gst_queue_cleanup_data (data, (gpointer) queue);
301 queue->timeval = NULL;
302 queue->level_buffers = 0;
303 queue->level_bytes = 0;
304 queue->level_time = G_GINT64_CONSTANT (0);
305 /* make sure any pending buffers to be added are flushed too */
307 /* signal not_full, since we apparently aren't full anymore */
308 g_cond_signal (queue->not_full);
312 gst_queue_chain (GstPad *pad, GstData *data)
316 g_return_if_fail (pad != NULL);
317 g_return_if_fail (GST_IS_PAD (pad));
318 g_return_if_fail (data != NULL);
320 queue = GST_QUEUE (GST_OBJECT_PARENT (pad));
322 /* check for events to send upstream */
323 g_async_queue_lock(queue->events);
324 while (g_async_queue_length_unlocked(queue->events) > 0){
325 GstEvent *event = (GstEvent*)g_async_queue_pop_unlocked(queue->events);
326 GST_CAT_DEBUG_OBJECT (GST_CAT_DATAFLOW, queue, "sending event upstream\n");
327 gst_pad_event_default (pad, event);
328 GST_CAT_DEBUG_OBJECT (GST_CAT_DATAFLOW, queue, "event sent\n");
330 g_async_queue_unlock(queue->events);
333 /* we have to lock the queue since we span threads */
334 GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, queue, "locking t:%p", g_thread_self ());
335 g_mutex_lock (queue->qlock);
336 GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, queue, "locked t:%p", g_thread_self ());
338 /* assume don't need to flush this buffer when the queue is filled */
339 queue->flush = FALSE;
341 if (GST_IS_EVENT (data)) {
342 switch (GST_EVENT_TYPE (data)) {
343 case GST_EVENT_FLUSH:
344 GST_CAT_DEBUG_OBJECT (GST_CAT_DATAFLOW, queue, "FLUSH event, flushing queue\n");
345 gst_queue_locked_flush (queue);
348 GST_CAT_DEBUG_OBJECT (GST_CAT_DATAFLOW, queue, "eos in on %s %d\n",
349 GST_ELEMENT_NAME (queue), queue->level_buffers);
352 /* we put the event in the queue, we don't have to act ourselves */
357 if (GST_IS_BUFFER (data))
358 GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, queue,
359 "adding buffer %p of size %d", data, GST_BUFFER_SIZE (data));
361 if (queue->level_buffers == queue->size_buffers) {
362 g_mutex_unlock (queue->qlock);
363 g_signal_emit (G_OBJECT (queue), gst_queue_signals[FULL], 0);
364 g_mutex_lock (queue->qlock);
366 /* if this is a leaky queue... */
368 /* FIXME don't want to leak events! */
369 /* if we leak on the upstream side, drop the current buffer */
370 if (queue->leaky == GST_QUEUE_LEAK_UPSTREAM) {
371 GST_CAT_DEBUG_OBJECT (GST_CAT_DATAFLOW, queue, "queue is full, leaking buffer on upstream end");
372 if (GST_IS_EVENT (data))
373 fprintf(stderr, "Error: queue [%s] leaked an event, type:%d\n",
374 GST_ELEMENT_NAME(GST_ELEMENT(queue)),
375 GST_EVENT_TYPE(GST_EVENT(data)));
376 /* now we have to clean up and exit right away */
377 g_mutex_unlock (queue->qlock);
380 /* otherwise we have to push a buffer off the other end */
385 GST_CAT_DEBUG_OBJECT (GST_CAT_DATAFLOW, queue, "queue is full, leaking buffer on downstream end");
387 front = g_queue_pop_head (queue->queue);
388 leak = GST_DATA (front);
390 queue->level_buffers--;
391 if (GST_IS_EVENT (leak)) {
392 fprintf(stderr, "Error: queue [%s] leaked an event, type:%d\n",
393 GST_ELEMENT_NAME(GST_ELEMENT(queue)),
394 GST_EVENT_TYPE(GST_EVENT(leak)));
396 queue->level_bytes -= GST_BUFFER_SIZE(leak);
399 gst_data_unref (leak);
403 GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, queue, "pre full wait, level:%d/%d buffers, %d bytes",
404 queue->level_buffers, queue->size_buffers, queue->level_bytes);
406 while (queue->level_buffers == queue->size_buffers) {
407 /* if there's a pending state change for this queue or its manager, switch */
408 /* back to iterator so bottom half of state change executes */
409 if (queue->interrupt) {
410 GST_CAT_DEBUG_OBJECT (GST_CAT_DATAFLOW, queue, "interrupted!!");
411 g_mutex_unlock (queue->qlock);
412 if (gst_scheduler_interrupt (gst_pad_get_scheduler (queue->sinkpad), GST_ELEMENT (queue)))
414 /* if we got here because we were unlocked after a flush, we don't need
415 * to add the buffer to the queue again */
417 GST_CAT_DEBUG_OBJECT (GST_CAT_DATAFLOW, queue, "not adding pending buffer after flush");
420 GST_CAT_DEBUG_OBJECT (GST_CAT_DATAFLOW, queue, "adding pending buffer after interrupt");
423 if (GST_STATE (queue) != GST_STATE_PLAYING) {
424 /* this means the other end is shut down */
425 /* try to signal to resolve the error */
426 if (!queue->may_deadlock) {
427 g_mutex_unlock (queue->qlock);
428 gst_data_unref (data);
429 gst_element_error (GST_ELEMENT (queue), "deadlock found, source pad elements are shut down");
430 /* we don't want to goto out_unref here, since we want to clean up before calling gst_element_error */
434 g_print ("%s: waiting for the app to restart source pad elements\n", GST_ELEMENT_NAME (queue));
438 GST_CAT_DEBUG_OBJECT (GST_CAT_DATAFLOW, queue, "waiting for not_full, level:%d/%d buffers, %d bytes",
439 queue->level_buffers, queue->size_buffers, queue->level_bytes);
440 g_cond_wait (queue->not_full, queue->qlock);
441 GST_CAT_DEBUG_OBJECT (GST_CAT_DATAFLOW, queue, "got not_full signal");
443 GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, queue, "post full wait, level:%d/%d buffers, %d bytes",
444 queue->level_buffers, queue->size_buffers, queue->level_bytes);
447 /* put the buffer on the tail of the list */
448 g_queue_push_tail (queue->queue, data);
450 queue->level_buffers++;
451 if (GST_IS_BUFFER (data))
452 queue->level_bytes += GST_BUFFER_SIZE (data);
454 /* this assertion _has_ to hold */
455 g_assert (queue->queue->length == queue->level_buffers);
457 GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, queue, "(%s:%s)+ level:%d/%d buffers, %d bytes",
458 GST_DEBUG_PAD_NAME(pad),
459 queue->level_buffers, queue->size_buffers, queue->level_bytes);
461 GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, queue, "signalling not_empty");
462 g_cond_signal (queue->not_empty);
463 g_mutex_unlock (queue->qlock);
468 gst_data_unref (data);
473 gst_queue_get (GstPad *pad)
476 GstData *data = NULL;
479 g_assert(pad != NULL);
480 g_assert(GST_IS_PAD(pad));
481 g_return_val_if_fail (pad != NULL, NULL);
482 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
484 queue = GST_QUEUE (GST_OBJECT_PARENT (pad));
487 /* have to lock for thread-safety */
488 GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, queue, "locking t:%p", g_thread_self ());
489 g_mutex_lock (queue->qlock);
490 GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, queue, "locked t:%p %p", g_thread_self (), queue->not_empty);
492 GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, queue, "pre empty wait, level:%d/%d buffers, %d bytes",
493 queue->level_buffers, queue->size_buffers, queue->level_bytes);
494 while (queue->level_buffers == 0) {
495 /* if there's a pending state change for this queue or its manager, switch
496 * back to iterator so bottom half of state change executes
498 //while (GST_STATE_PENDING (queue) != GST_STATE_VOID_PENDING) {
499 if (queue->interrupt) {
500 GST_CAT_DEBUG_OBJECT (GST_CAT_DATAFLOW, queue, "interrupted!!");
501 g_mutex_unlock (queue->qlock);
502 if (gst_scheduler_interrupt (gst_pad_get_scheduler (queue->srcpad), GST_ELEMENT (queue)))
503 return GST_DATA (gst_event_new (GST_EVENT_INTERRUPT));
506 if (GST_STATE (queue) != GST_STATE_PLAYING) {
507 /* this means the other end is shut down */
508 if (!queue->may_deadlock) {
509 g_mutex_unlock (queue->qlock);
510 gst_element_error (GST_ELEMENT (queue), "deadlock found, sink pad elements are shut down");
514 g_print ("%s: waiting for the app to restart source pad elements\n", GST_ELEMENT_NAME (queue));
518 GST_CAT_DEBUG_OBJECT (GST_CAT_DATAFLOW, queue, "waiting for not_empty, level:%d/%d buffers, %d bytes",
519 queue->level_buffers, queue->size_buffers, queue->level_bytes);
521 /* if (queue->block_timeout > -1){ */
524 g_get_current_time(&timeout);
525 g_time_val_add(&timeout, queue->block_timeout);
526 if (!g_cond_timed_wait (queue->not_empty, queue->qlock, &timeout)){
527 g_mutex_unlock (queue->qlock);
528 g_warning ("filler");
529 return GST_DATA (gst_event_new_filler());
533 g_cond_wait (queue->not_empty, queue->qlock);
535 GST_CAT_DEBUG_OBJECT (GST_CAT_DATAFLOW, queue, "got not_empty signal");
537 GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, queue, "post empty wait, level:%d/%d buffers, %d bytes",
538 queue->level_buffers, queue->size_buffers, queue->level_bytes);
540 front = g_queue_pop_head (queue->queue);
541 data = GST_DATA (front);
542 GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, queue, "retrieved data %p from queue", data);
544 queue->level_buffers--;
545 if (GST_IS_BUFFER (data))
546 queue->level_bytes -= GST_BUFFER_SIZE (data);
548 GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, queue, "(%s:%s)- level:%d/%d buffers, %d bytes",
549 GST_DEBUG_PAD_NAME(pad),
550 queue->level_buffers, queue->size_buffers, queue->level_bytes);
552 /* this assertion _has_ to hold */
553 g_assert (queue->queue->length == queue->level_buffers);
555 GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, queue, "signalling not_full");
556 g_cond_signal (queue->not_full);
558 g_mutex_unlock (queue->qlock);
560 /* FIXME where should this be? locked? */
561 if (GST_IS_EVENT (data)) {
562 GstEvent *event = GST_EVENT (data);
563 switch (GST_EVENT_TYPE(event)) {
565 GST_CAT_DEBUG_OBJECT (GST_CAT_DATAFLOW, queue, "queue \"%s\" eos", GST_ELEMENT_NAME (queue));
566 gst_element_set_eos (GST_ELEMENT (queue));
578 gst_queue_handle_src_event (GstPad *pad, GstEvent *event)
585 queue = GST_QUEUE (GST_OBJECT_PARENT (pad));
587 g_mutex_lock (queue->qlock);
589 if (gst_element_get_state (GST_ELEMENT (queue)) == GST_STATE_PLAYING) {
590 /* push the event to the queue for upstream consumption */
591 g_async_queue_push(queue->events, event);
592 g_warning ("FIXME: sending event in a running queue");
593 /* FIXME wait for delivery of the event here, then return the result
594 * instead of FALSE */
599 event_type = GST_EVENT_TYPE (event);
600 if (event_type == GST_EVENT_SEEK)
601 flag_flush = GST_EVENT_SEEK_FLAGS (event) & GST_SEEK_FLAG_FLUSH;
603 res = gst_pad_event_default (pad, event);
605 switch (event_type) {
606 case GST_EVENT_FLUSH:
607 GST_CAT_DEBUG_OBJECT (GST_CAT_DATAFLOW, queue, "FLUSH event, flushing queue\n");
608 gst_queue_locked_flush (queue);
612 gst_queue_locked_flush (queue);
619 g_mutex_unlock (queue->qlock);
621 /* we have to claim success, but we don't really know */
626 gst_queue_release_locks (GstElement *element)
630 queue = GST_QUEUE (element);
632 g_mutex_lock (queue->qlock);
633 queue->interrupt = TRUE;
634 g_cond_signal (queue->not_full);
635 g_cond_signal (queue->not_empty);
636 g_mutex_unlock (queue->qlock);
641 static GstElementStateReturn
642 gst_queue_change_state (GstElement *element)
645 GstElementStateReturn ret;
647 queue = GST_QUEUE (element);
649 GST_CAT_LOG_OBJECT (GST_CAT_STATES, element, "starting state change");
651 /* lock the queue so another thread (not in sync with this thread's state)
652 * can't call this queue's _get (or whatever)
654 g_mutex_lock (queue->qlock);
656 switch (GST_STATE_TRANSITION (element)) {
657 case GST_STATE_NULL_TO_READY:
658 gst_queue_locked_flush (queue);
660 case GST_STATE_READY_TO_PAUSED:
662 case GST_STATE_PAUSED_TO_PLAYING:
663 if (!GST_PAD_IS_LINKED (queue->sinkpad)) {
664 GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, queue, "queue %s is not linked", GST_ELEMENT_NAME (queue));
665 /* FIXME can this be? */
666 g_cond_signal (queue->not_empty);
668 ret = GST_STATE_FAILURE;
672 GstScheduler *src_sched, *sink_sched;
674 src_sched = gst_pad_get_scheduler (GST_PAD_CAST (queue->srcpad));
675 sink_sched = gst_pad_get_scheduler (GST_PAD_CAST (queue->sinkpad));
677 if (src_sched == sink_sched) {
678 GST_CAT_DEBUG_OBJECT (GST_CAT_STATES, queue, "queue %s does not connect different schedulers",
679 GST_ELEMENT_NAME (queue));
681 g_warning ("queue %s does not connect different schedulers",
682 GST_ELEMENT_NAME (queue));
684 ret = GST_STATE_FAILURE;
688 queue->interrupt = FALSE;
690 case GST_STATE_PLAYING_TO_PAUSED:
692 case GST_STATE_PAUSED_TO_READY:
693 gst_queue_locked_flush (queue);
695 case GST_STATE_READY_TO_NULL:
699 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element);
700 /* this is an ugly hack to make sure our pads are always active. Reason for this is that
701 * pad activation for the queue element depends on 2 schedulers (ugh) */
702 gst_pad_set_active (queue->sinkpad, TRUE);
703 gst_pad_set_active (queue->srcpad, TRUE);
706 g_mutex_unlock (queue->qlock);
708 GST_CAT_LOG_OBJECT (GST_CAT_STATES, element, "done with state change");
714 gst_queue_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
718 /* it's not null if we got it, but it might not be ours */
719 g_return_if_fail (GST_IS_QUEUE (object));
721 queue = GST_QUEUE (object);
725 queue->leaky = g_value_get_enum (value);
728 queue->size_buffers = g_value_get_int (value);
730 case ARG_MIN_THRESHOLD_BYTES:
731 queue->min_threshold_bytes = g_value_get_int (value);
733 case ARG_MAY_DEADLOCK:
734 queue->may_deadlock = g_value_get_boolean (value);
736 case ARG_BLOCK_TIMEOUT:
737 queue->block_timeout = g_value_get_int (value);
740 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
746 gst_queue_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
750 /* it's not null if we got it, but it might not be ours */
751 g_return_if_fail (GST_IS_QUEUE (object));
753 queue = GST_QUEUE (object);
757 g_value_set_enum (value, queue->leaky);
760 g_value_set_int (value, queue->level_buffers);
763 g_value_set_int (value, queue->size_buffers);
765 case ARG_MIN_THRESHOLD_BYTES:
766 g_value_set_int (value, queue->min_threshold_bytes);
768 case ARG_MAY_DEADLOCK:
769 g_value_set_boolean (value, queue->may_deadlock);
771 case ARG_BLOCK_TIMEOUT:
772 g_value_set_int (value, queue->block_timeout);
775 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);