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>
5 * 2005 Wim Taymans <wim@fluendo.com>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the
21 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 * Boston, MA 02111-1307, USA.
26 * SECTION:element-queue
28 * Data is queued until one of the limits specified by the
29 * #GstQueue:max-size-buffers, #GstQueue:max-size-bytes and/or
30 * #GstQueue:max-size-time properties has been reached. Any attempt to push
31 * more buffers into the queue will block the pushing thread until more space
34 * The queue will create a new thread on the source pad to decouple the
35 * processing on sink and source pad.
37 * You can query how many buffers are queued by reading the
38 * #GstQueue:current-level-buffers property. You can track changes
39 * by connecting to the notify::current-level-buffers signal (which
40 * like all signals will be emitted from the streaming thread). The same
41 * applies to the #GstQueue:current-level-time and
42 * #GstQueue:current-level-bytes properties.
44 * The default queue size limits are 200 buffers, 10MB of data, or
45 * one second worth of data, whichever is reached first.
47 * As said earlier, the queue blocks by default when one of the specified
48 * maximums (bytes, time, buffers) has been reached. You can set the
49 * #GstQueue:leaky property to specify that instead of blocking it should
50 * leak (drop) new or old buffers.
52 * The #GstQueue::underrun signal is emitted when the queue has less data than
53 * the specified minimum thresholds require (by default: when the queue is
54 * empty). The #GstQueue::overrun signal is emitted when the queue is filled
55 * up. Both signals are emitted from the context of the streaming thread.
58 #include "gst/gst_private.h"
63 #include "../../gst/gst-i18n-lib.h"
64 #include "../../gst/glib-compat-private.h"
66 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
71 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
76 GST_DEBUG_CATEGORY_STATIC (queue_debug);
77 #define GST_CAT_DEFAULT (queue_debug)
78 GST_DEBUG_CATEGORY_STATIC (queue_dataflow);
80 #define STATUS(queue, pad, msg) \
81 GST_CAT_LOG_OBJECT (queue_dataflow, queue, \
82 "(%s:%s) " msg ": %u of %u-%u buffers, %u of %u-%u " \
83 "bytes, %" G_GUINT64_FORMAT " of %" G_GUINT64_FORMAT \
84 "-%" G_GUINT64_FORMAT " ns, %u items", \
85 GST_DEBUG_PAD_NAME (pad), \
86 queue->cur_level.buffers, \
87 queue->min_threshold.buffers, \
88 queue->max_size.buffers, \
89 queue->cur_level.bytes, \
90 queue->min_threshold.bytes, \
91 queue->max_size.bytes, \
92 queue->cur_level.time, \
93 queue->min_threshold.time, \
94 queue->max_size.time, \
97 /* Queue signals and args */
110 /* FIXME: don't we have another way of doing this
111 * "Gstreamer format" (frame/byte/time) queries? */
112 PROP_CUR_LEVEL_BUFFERS,
113 PROP_CUR_LEVEL_BYTES,
115 PROP_MAX_SIZE_BUFFERS,
118 PROP_MIN_THRESHOLD_BUFFERS,
119 PROP_MIN_THRESHOLD_BYTES,
120 PROP_MIN_THRESHOLD_TIME,
125 /* default property values */
126 #define DEFAULT_MAX_SIZE_BUFFERS 200 /* 200 buffers */
127 #define DEFAULT_MAX_SIZE_BYTES (10 * 1024 * 1024) /* 10 MB */
128 #define DEFAULT_MAX_SIZE_TIME GST_SECOND /* 1 second */
130 #define GST_QUEUE_MUTEX_LOCK(q) G_STMT_START { \
131 g_mutex_lock (&q->qlock); \
134 #define GST_QUEUE_MUTEX_LOCK_CHECK(q,label) G_STMT_START { \
135 GST_QUEUE_MUTEX_LOCK (q); \
136 if (q->srcresult != GST_FLOW_OK) \
140 #define GST_QUEUE_MUTEX_UNLOCK(q) G_STMT_START { \
141 g_mutex_unlock (&q->qlock); \
144 #define GST_QUEUE_WAIT_DEL_CHECK(q, label) G_STMT_START { \
145 STATUS (q, q->sinkpad, "wait for DEL"); \
146 q->waiting_del = TRUE; \
147 g_cond_wait (&q->item_del, &q->qlock); \
148 q->waiting_del = FALSE; \
149 if (q->srcresult != GST_FLOW_OK) { \
150 STATUS (q, q->srcpad, "received DEL wakeup"); \
153 STATUS (q, q->sinkpad, "received DEL"); \
156 #define GST_QUEUE_WAIT_ADD_CHECK(q, label) G_STMT_START { \
157 STATUS (q, q->srcpad, "wait for ADD"); \
158 q->waiting_add = TRUE; \
159 g_cond_wait (&q->item_add, &q->qlock); \
160 q->waiting_add = FALSE; \
161 if (q->srcresult != GST_FLOW_OK) { \
162 STATUS (q, q->srcpad, "received ADD wakeup"); \
165 STATUS (q, q->srcpad, "received ADD"); \
168 #define GST_QUEUE_SIGNAL_DEL(q) G_STMT_START { \
169 if (q->waiting_del) { \
170 STATUS (q, q->srcpad, "signal DEL"); \
171 g_cond_signal (&q->item_del); \
175 #define GST_QUEUE_SIGNAL_ADD(q) G_STMT_START { \
176 if (q->waiting_add) { \
177 STATUS (q, q->sinkpad, "signal ADD"); \
178 g_cond_signal (&q->item_add); \
183 GST_DEBUG_CATEGORY_INIT (queue_debug, "queue", 0, "queue element"); \
184 GST_DEBUG_CATEGORY_INIT (queue_dataflow, "queue_dataflow", 0, \
185 "dataflow inside the queue element");
186 #define gst_queue_parent_class parent_class
187 G_DEFINE_TYPE_WITH_CODE (GstQueue, gst_queue, GST_TYPE_ELEMENT, _do_init);
189 static void gst_queue_finalize (GObject * object);
191 static void gst_queue_set_property (GObject * object,
192 guint prop_id, const GValue * value, GParamSpec * pspec);
193 static void gst_queue_get_property (GObject * object,
194 guint prop_id, GValue * value, GParamSpec * pspec);
196 static GstFlowReturn gst_queue_chain (GstPad * pad, GstObject * parent,
198 static GstFlowReturn gst_queue_push_one (GstQueue * queue);
199 static void gst_queue_loop (GstPad * pad);
201 static gboolean gst_queue_handle_sink_event (GstPad * pad, GstObject * parent,
203 static gboolean gst_queue_handle_sink_query (GstPad * pad, GstObject * parent,
206 static gboolean gst_queue_handle_src_event (GstPad * pad, GstObject * parent,
208 static gboolean gst_queue_handle_src_query (GstPad * pad, GstObject * parent,
211 static GstPadLinkReturn gst_queue_link_sink (GstPad * pad, GstPad * peer);
212 static GstPadLinkReturn gst_queue_link_src (GstPad * pad, GstPad * peer);
213 static void gst_queue_locked_flush (GstQueue * queue);
215 static gboolean gst_queue_src_activate_mode (GstPad * pad, GstObject * parent,
216 GstPadMode mode, gboolean active);
217 static gboolean gst_queue_sink_activate_mode (GstPad * pad, GstObject * parent,
218 GstPadMode mode, gboolean active);
220 static gboolean gst_queue_is_empty (GstQueue * queue);
221 static gboolean gst_queue_is_filled (GstQueue * queue);
223 #define GST_TYPE_QUEUE_LEAKY (queue_leaky_get_type ())
226 queue_leaky_get_type (void)
228 static GType queue_leaky_type = 0;
229 static const GEnumValue queue_leaky[] = {
230 {GST_QUEUE_NO_LEAK, "Not Leaky", "no"},
231 {GST_QUEUE_LEAK_UPSTREAM, "Leaky on upstream (new buffers)", "upstream"},
232 {GST_QUEUE_LEAK_DOWNSTREAM, "Leaky on downstream (old buffers)",
237 if (!queue_leaky_type) {
238 queue_leaky_type = g_enum_register_static ("GstQueueLeaky", queue_leaky);
240 return queue_leaky_type;
243 static guint gst_queue_signals[LAST_SIGNAL] = { 0 };
246 gst_queue_class_init (GstQueueClass * klass)
248 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
249 GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
251 gobject_class->set_property = gst_queue_set_property;
252 gobject_class->get_property = gst_queue_get_property;
256 * GstQueue::underrun:
257 * @queue: the queue instance
259 * Reports that the buffer became empty (underrun).
260 * A buffer is empty if the total amount of data inside it (num-buffers, time,
261 * size) is lower than the boundary values which can be set through the
262 * GObject properties.
264 gst_queue_signals[SIGNAL_UNDERRUN] =
265 g_signal_new ("underrun", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_FIRST,
266 G_STRUCT_OFFSET (GstQueueClass, underrun), NULL, NULL,
267 g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
270 * @queue: the queue instance
272 * Reports that enough (min-threshold) data is in the queue. Use this signal
273 * together with the underrun signal to pause the pipeline on underrun and
274 * wait for the queue to fill-up before resume playback.
276 gst_queue_signals[SIGNAL_RUNNING] =
277 g_signal_new ("running", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_FIRST,
278 G_STRUCT_OFFSET (GstQueueClass, running), NULL, NULL,
279 g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
282 * @queue: the queue instance
284 * Reports that the buffer became full (overrun).
285 * A buffer is full if the total amount of data inside it (num-buffers, time,
286 * size) is higher than the boundary values which can be set through the
287 * GObject properties.
289 gst_queue_signals[SIGNAL_OVERRUN] =
290 g_signal_new ("overrun", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_FIRST,
291 G_STRUCT_OFFSET (GstQueueClass, overrun), NULL, NULL,
292 g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
295 * @queue: the queue instance
297 * Reports when the queue has enough data to start pushing data again on the
300 gst_queue_signals[SIGNAL_PUSHING] =
301 g_signal_new ("pushing", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_FIRST,
302 G_STRUCT_OFFSET (GstQueueClass, pushing), NULL, NULL,
303 g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
306 g_object_class_install_property (gobject_class, PROP_CUR_LEVEL_BYTES,
307 g_param_spec_uint ("current-level-bytes", "Current level (kB)",
308 "Current amount of data in the queue (bytes)",
309 0, G_MAXUINT, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
310 g_object_class_install_property (gobject_class, PROP_CUR_LEVEL_BUFFERS,
311 g_param_spec_uint ("current-level-buffers", "Current level (buffers)",
312 "Current number of buffers in the queue",
313 0, G_MAXUINT, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
314 g_object_class_install_property (gobject_class, PROP_CUR_LEVEL_TIME,
315 g_param_spec_uint64 ("current-level-time", "Current level (ns)",
316 "Current amount of data in the queue (in ns)",
317 0, G_MAXUINT64, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
319 g_object_class_install_property (gobject_class, PROP_MAX_SIZE_BYTES,
320 g_param_spec_uint ("max-size-bytes", "Max. size (kB)",
321 "Max. amount of data in the queue (bytes, 0=disable)",
322 0, G_MAXUINT, DEFAULT_MAX_SIZE_BYTES,
323 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
324 g_object_class_install_property (gobject_class, PROP_MAX_SIZE_BUFFERS,
325 g_param_spec_uint ("max-size-buffers", "Max. size (buffers)",
326 "Max. number of buffers in the queue (0=disable)", 0, G_MAXUINT,
327 DEFAULT_MAX_SIZE_BUFFERS,
328 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
329 g_object_class_install_property (gobject_class, PROP_MAX_SIZE_TIME,
330 g_param_spec_uint64 ("max-size-time", "Max. size (ns)",
331 "Max. amount of data in the queue (in ns, 0=disable)", 0, G_MAXUINT64,
332 DEFAULT_MAX_SIZE_TIME, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
334 g_object_class_install_property (gobject_class, PROP_MIN_THRESHOLD_BYTES,
335 g_param_spec_uint ("min-threshold-bytes", "Min. threshold (kB)",
336 "Min. amount of data in the queue to allow reading (bytes, 0=disable)",
337 0, G_MAXUINT, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
338 g_object_class_install_property (gobject_class, PROP_MIN_THRESHOLD_BUFFERS,
339 g_param_spec_uint ("min-threshold-buffers", "Min. threshold (buffers)",
340 "Min. number of buffers in the queue to allow reading (0=disable)",
341 0, G_MAXUINT, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
342 g_object_class_install_property (gobject_class, PROP_MIN_THRESHOLD_TIME,
343 g_param_spec_uint64 ("min-threshold-time", "Min. threshold (ns)",
344 "Min. amount of data in the queue to allow reading (in ns, 0=disable)",
345 0, G_MAXUINT64, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
347 g_object_class_install_property (gobject_class, PROP_LEAKY,
348 g_param_spec_enum ("leaky", "Leaky",
349 "Where the queue leaks, if at all",
350 GST_TYPE_QUEUE_LEAKY, GST_QUEUE_NO_LEAK,
351 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
356 * Don't emit queue signals. Makes queues more lightweight if no signals are
361 g_object_class_install_property (gobject_class, PROP_SILENT,
362 g_param_spec_boolean ("silent", "Silent",
363 "Don't emit queue signals", FALSE,
364 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
366 gobject_class->finalize = gst_queue_finalize;
368 gst_element_class_set_details_simple (gstelement_class,
370 "Generic", "Simple data queue", "Erik Walthinsen <omega@cse.ogi.edu>");
371 gst_element_class_add_pad_template (gstelement_class,
372 gst_static_pad_template_get (&srctemplate));
373 gst_element_class_add_pad_template (gstelement_class,
374 gst_static_pad_template_get (&sinktemplate));
376 /* Registering debug symbols for function pointers */
377 GST_DEBUG_REGISTER_FUNCPTR (gst_queue_src_activate_mode);
378 GST_DEBUG_REGISTER_FUNCPTR (gst_queue_link_sink);
379 GST_DEBUG_REGISTER_FUNCPTR (gst_queue_link_src);
380 GST_DEBUG_REGISTER_FUNCPTR (gst_queue_handle_sink_event);
381 GST_DEBUG_REGISTER_FUNCPTR (gst_queue_handle_sink_query);
382 GST_DEBUG_REGISTER_FUNCPTR (gst_queue_handle_src_event);
383 GST_DEBUG_REGISTER_FUNCPTR (gst_queue_handle_src_query);
384 GST_DEBUG_REGISTER_FUNCPTR (gst_queue_chain);
388 gst_queue_init (GstQueue * queue)
390 queue->sinkpad = gst_pad_new_from_static_template (&sinktemplate, "sink");
392 gst_pad_set_chain_function (queue->sinkpad, gst_queue_chain);
393 gst_pad_set_activatemode_function (queue->sinkpad,
394 gst_queue_sink_activate_mode);
395 gst_pad_set_event_function (queue->sinkpad, gst_queue_handle_sink_event);
396 gst_pad_set_query_function (queue->sinkpad, gst_queue_handle_sink_query);
397 gst_pad_set_link_function (queue->sinkpad, gst_queue_link_sink);
398 GST_PAD_SET_PROXY_CAPS (queue->sinkpad);
399 GST_PAD_SET_PROXY_ALLOCATION (queue->sinkpad);
400 gst_element_add_pad (GST_ELEMENT (queue), queue->sinkpad);
402 queue->srcpad = gst_pad_new_from_static_template (&srctemplate, "src");
404 gst_pad_set_activatemode_function (queue->srcpad,
405 gst_queue_src_activate_mode);
406 gst_pad_set_link_function (queue->srcpad, gst_queue_link_src);
407 gst_pad_set_event_function (queue->srcpad, gst_queue_handle_src_event);
408 gst_pad_set_query_function (queue->srcpad, gst_queue_handle_src_query);
409 GST_PAD_SET_PROXY_CAPS (queue->srcpad);
410 gst_element_add_pad (GST_ELEMENT (queue), queue->srcpad);
412 GST_QUEUE_CLEAR_LEVEL (queue->cur_level);
413 queue->max_size.buffers = DEFAULT_MAX_SIZE_BUFFERS;
414 queue->max_size.bytes = DEFAULT_MAX_SIZE_BYTES;
415 queue->max_size.time = DEFAULT_MAX_SIZE_TIME;
416 GST_QUEUE_CLEAR_LEVEL (queue->min_threshold);
417 GST_QUEUE_CLEAR_LEVEL (queue->orig_min_threshold);
418 gst_segment_init (&queue->sink_segment, GST_FORMAT_TIME);
419 gst_segment_init (&queue->src_segment, GST_FORMAT_TIME);
420 queue->head_needs_discont = queue->tail_needs_discont = FALSE;
422 queue->leaky = GST_QUEUE_NO_LEAK;
423 queue->srcresult = GST_FLOW_WRONG_STATE;
425 g_mutex_init (&queue->qlock);
426 g_cond_init (&queue->item_add);
427 g_cond_init (&queue->item_del);
429 g_queue_init (&queue->queue);
431 queue->sinktime = GST_CLOCK_TIME_NONE;
432 queue->srctime = GST_CLOCK_TIME_NONE;
434 queue->sink_tainted = TRUE;
435 queue->src_tainted = TRUE;
437 queue->newseg_applied_to_src = FALSE;
439 GST_DEBUG_OBJECT (queue,
440 "initialized queue's not_empty & not_full conditions");
443 /* called only once, as opposed to dispose */
445 gst_queue_finalize (GObject * object)
448 GstQueue *queue = GST_QUEUE (object);
450 GST_DEBUG_OBJECT (queue, "finalizing queue");
452 while ((data = g_queue_pop_head (&queue->queue)))
453 gst_mini_object_unref (data);
455 g_queue_clear (&queue->queue);
456 g_mutex_clear (&queue->qlock);
457 g_cond_clear (&queue->item_add);
458 g_cond_clear (&queue->item_del);
460 G_OBJECT_CLASS (parent_class)->finalize (object);
463 static GstPadLinkReturn
464 gst_queue_link_sink (GstPad * pad, GstPad * peer)
466 return GST_PAD_LINK_OK;
469 static GstPadLinkReturn
470 gst_queue_link_src (GstPad * pad, GstPad * peer)
472 GstPadLinkReturn result = GST_PAD_LINK_OK;
475 queue = GST_QUEUE (GST_PAD_PARENT (pad));
477 GST_DEBUG_OBJECT (queue, "queue linking source pad");
479 if (GST_PAD_LINKFUNC (peer)) {
480 result = GST_PAD_LINKFUNC (peer) (peer, pad);
483 if (GST_PAD_LINK_SUCCESSFUL (result)) {
484 GST_QUEUE_MUTEX_LOCK (queue);
485 if (queue->srcresult == GST_FLOW_OK) {
486 queue->push_newsegment = TRUE;
487 gst_pad_start_task (pad, (GstTaskFunction) gst_queue_loop, pad);
488 GST_DEBUG_OBJECT (queue, "starting task as pad is linked");
490 GST_DEBUG_OBJECT (queue, "not starting task reason %s",
491 gst_flow_get_name (queue->srcresult));
493 GST_QUEUE_MUTEX_UNLOCK (queue);
499 /* calculate the diff between running time on the sink and src of the queue.
500 * This is the total amount of time in the queue. */
502 update_time_level (GstQueue * queue)
504 gint64 sink_time, src_time;
506 if (queue->sink_tainted) {
507 GST_LOG_OBJECT (queue, "update sink time");
509 gst_segment_to_running_time (&queue->sink_segment, GST_FORMAT_TIME,
510 queue->sink_segment.position);
511 queue->sink_tainted = FALSE;
513 sink_time = queue->sinktime;
515 if (queue->src_tainted) {
516 GST_LOG_OBJECT (queue, "update src time");
518 gst_segment_to_running_time (&queue->src_segment, GST_FORMAT_TIME,
519 queue->src_segment.position);
520 queue->src_tainted = FALSE;
522 src_time = queue->srctime;
524 GST_LOG_OBJECT (queue, "sink %" GST_TIME_FORMAT ", src %" GST_TIME_FORMAT,
525 GST_TIME_ARGS (sink_time), GST_TIME_ARGS (src_time));
527 if (sink_time >= src_time)
528 queue->cur_level.time = sink_time - src_time;
530 queue->cur_level.time = 0;
533 /* take a SEGMENT event and apply the values to segment, updating the time
536 apply_segment (GstQueue * queue, GstEvent * event, GstSegment * segment,
539 gst_event_copy_segment (event, segment);
541 /* now configure the values, we use these to track timestamps on the
543 if (segment->format != GST_FORMAT_TIME) {
544 /* non-time format, pretent the current time segment is closed with a
545 * 0 start and unknown stop time. */
546 segment->format = GST_FORMAT_TIME;
552 queue->sink_tainted = TRUE;
554 queue->src_tainted = TRUE;
556 GST_DEBUG_OBJECT (queue, "configured SEGMENT %" GST_SEGMENT_FORMAT, segment);
558 /* segment can update the time level of the queue */
559 update_time_level (queue);
562 /* take a buffer and update segment, updating the time level of the queue. */
564 apply_buffer (GstQueue * queue, GstBuffer * buffer, GstSegment * segment,
565 gboolean with_duration, gboolean sink)
567 GstClockTime duration, timestamp;
569 timestamp = GST_BUFFER_TIMESTAMP (buffer);
570 duration = GST_BUFFER_DURATION (buffer);
572 /* if no timestamp is set, assume it's continuous with the previous
574 if (timestamp == GST_CLOCK_TIME_NONE)
575 timestamp = segment->position;
578 if (with_duration && duration != GST_CLOCK_TIME_NONE)
579 timestamp += duration;
581 GST_LOG_OBJECT (queue, "position updated to %" GST_TIME_FORMAT,
582 GST_TIME_ARGS (timestamp));
584 segment->position = timestamp;
586 queue->sink_tainted = TRUE;
588 queue->src_tainted = TRUE;
591 /* calc diff with other end */
592 update_time_level (queue);
596 gst_queue_locked_flush (GstQueue * queue)
600 while ((data = g_queue_pop_head (&queue->queue))) {
601 /* Then lose another reference because we are supposed to destroy that
602 data when flushing */
603 gst_mini_object_unref (data);
605 GST_QUEUE_CLEAR_LEVEL (queue->cur_level);
606 queue->min_threshold.buffers = queue->orig_min_threshold.buffers;
607 queue->min_threshold.bytes = queue->orig_min_threshold.bytes;
608 queue->min_threshold.time = queue->orig_min_threshold.time;
609 gst_segment_init (&queue->sink_segment, GST_FORMAT_TIME);
610 gst_segment_init (&queue->src_segment, GST_FORMAT_TIME);
611 queue->head_needs_discont = queue->tail_needs_discont = FALSE;
613 queue->sinktime = queue->srctime = GST_CLOCK_TIME_NONE;
614 queue->sink_tainted = queue->src_tainted = TRUE;
616 /* we deleted a lot of something */
617 GST_QUEUE_SIGNAL_DEL (queue);
620 /* enqueue an item an update the level stats, with QUEUE_LOCK */
622 gst_queue_locked_enqueue_buffer (GstQueue * queue, gpointer item)
624 GstBuffer *buffer = GST_BUFFER_CAST (item);
626 /* add buffer to the statistics */
627 queue->cur_level.buffers++;
628 queue->cur_level.bytes += gst_buffer_get_size (buffer);
629 apply_buffer (queue, buffer, &queue->sink_segment, TRUE, TRUE);
631 g_queue_push_tail (&queue->queue, item);
632 GST_QUEUE_SIGNAL_ADD (queue);
636 gst_queue_locked_enqueue_event (GstQueue * queue, gpointer item)
638 GstEvent *event = GST_EVENT_CAST (item);
640 switch (GST_EVENT_TYPE (event)) {
642 /* Zero the thresholds, this makes sure the queue is completely
643 * filled and we can read all data from the queue. */
644 GST_QUEUE_CLEAR_LEVEL (queue->min_threshold);
645 /* mark the queue as EOS. This prevents us from accepting more data. */
646 GST_CAT_LOG_OBJECT (queue_dataflow, queue, "got EOS from upstream");
649 case GST_EVENT_SEGMENT:
650 apply_segment (queue, event, &queue->sink_segment, TRUE);
651 /* if the queue is empty, apply sink segment on the source */
652 if (queue->queue.length == 0) {
653 GST_CAT_LOG_OBJECT (queue_dataflow, queue, "Apply segment on srcpad");
654 apply_segment (queue, event, &queue->src_segment, FALSE);
655 queue->newseg_applied_to_src = TRUE;
657 /* a new segment allows us to accept more buffers if we got EOS
659 queue->unexpected = FALSE;
665 g_queue_push_tail (&queue->queue, item);
666 GST_QUEUE_SIGNAL_ADD (queue);
669 /* dequeue an item from the queue and update level stats, with QUEUE_LOCK */
670 static GstMiniObject *
671 gst_queue_locked_dequeue (GstQueue * queue, gboolean * is_buffer)
675 item = g_queue_pop_head (&queue->queue);
679 if (GST_IS_BUFFER (item)) {
680 GstBuffer *buffer = GST_BUFFER_CAST (item);
682 GST_CAT_LOG_OBJECT (queue_dataflow, queue,
683 "retrieved buffer %p from queue", buffer);
685 queue->cur_level.buffers--;
686 queue->cur_level.bytes -= gst_buffer_get_size (buffer);
687 apply_buffer (queue, buffer, &queue->src_segment, TRUE, FALSE);
689 /* if the queue is empty now, update the other side */
690 if (queue->cur_level.buffers == 0)
691 queue->cur_level.time = 0;
694 } else if (GST_IS_EVENT (item)) {
695 GstEvent *event = GST_EVENT_CAST (item);
697 GST_CAT_LOG_OBJECT (queue_dataflow, queue,
698 "retrieved event %p from queue", event);
700 switch (GST_EVENT_TYPE (event)) {
702 /* queue is empty now that we dequeued the EOS */
703 GST_QUEUE_CLEAR_LEVEL (queue->cur_level);
705 case GST_EVENT_SEGMENT:
706 /* apply newsegment if it has not already been applied */
707 if (G_LIKELY (!queue->newseg_applied_to_src)) {
708 apply_segment (queue, event, &queue->src_segment, FALSE);
710 queue->newseg_applied_to_src = FALSE;
720 ("Unexpected item %p dequeued from queue %s (refcounting problem?)",
721 item, GST_OBJECT_NAME (queue));
724 GST_QUEUE_SIGNAL_DEL (queue);
731 GST_CAT_DEBUG_OBJECT (queue_dataflow, queue, "the queue is empty");
737 gst_queue_handle_sink_event (GstPad * pad, GstObject * parent, GstEvent * event)
741 queue = GST_QUEUE (parent);
743 switch (GST_EVENT_TYPE (event)) {
744 case GST_EVENT_FLUSH_START:
746 STATUS (queue, pad, "received flush start event");
748 gst_pad_push_event (queue->srcpad, event);
750 /* now unblock the chain function */
751 GST_QUEUE_MUTEX_LOCK (queue);
752 queue->srcresult = GST_FLOW_WRONG_STATE;
753 /* unblock the loop and chain functions */
754 GST_QUEUE_SIGNAL_ADD (queue);
755 GST_QUEUE_SIGNAL_DEL (queue);
756 GST_QUEUE_MUTEX_UNLOCK (queue);
758 /* make sure it pauses, this should happen since we sent
759 * flush_start downstream. */
760 gst_pad_pause_task (queue->srcpad);
761 GST_CAT_LOG_OBJECT (queue_dataflow, queue, "loop stopped");
764 case GST_EVENT_FLUSH_STOP:
766 STATUS (queue, pad, "received flush stop event");
768 gst_pad_push_event (queue->srcpad, event);
770 GST_QUEUE_MUTEX_LOCK (queue);
771 gst_queue_locked_flush (queue);
772 queue->srcresult = GST_FLOW_OK;
774 queue->unexpected = FALSE;
775 if (gst_pad_is_linked (queue->srcpad)) {
776 gst_pad_start_task (queue->srcpad, (GstTaskFunction) gst_queue_loop,
779 GST_INFO_OBJECT (queue, "not re-starting task as pad is not linked");
781 GST_QUEUE_MUTEX_UNLOCK (queue);
783 STATUS (queue, pad, "after flush");
787 if (GST_EVENT_IS_SERIALIZED (event)) {
788 /* serialized events go in the queue */
789 GST_QUEUE_MUTEX_LOCK_CHECK (queue, out_flushing);
790 /* refuse more events on EOS */
793 gst_queue_locked_enqueue_event (queue, event);
794 GST_QUEUE_MUTEX_UNLOCK (queue);
796 /* non-serialized events are passed upstream. */
797 gst_pad_push_event (queue->srcpad, event);
807 GST_CAT_LOG_OBJECT (queue_dataflow, queue,
808 "refusing event, we are flushing");
809 GST_QUEUE_MUTEX_UNLOCK (queue);
810 gst_event_unref (event);
815 GST_CAT_LOG_OBJECT (queue_dataflow, queue, "refusing event, we are EOS");
816 GST_QUEUE_MUTEX_UNLOCK (queue);
817 gst_event_unref (event);
823 gst_queue_handle_sink_query (GstPad * pad, GstObject * parent, GstQuery * query)
827 switch (GST_QUERY_TYPE (query)) {
829 res = gst_pad_query_default (pad, parent, query);
836 gst_queue_is_empty (GstQueue * queue)
838 if (queue->queue.length == 0)
841 /* It is possible that a max size is reached before all min thresholds are.
842 * Therefore, only consider it empty if it is not filled. */
843 return ((queue->min_threshold.buffers > 0 &&
844 queue->cur_level.buffers < queue->min_threshold.buffers) ||
845 (queue->min_threshold.bytes > 0 &&
846 queue->cur_level.bytes < queue->min_threshold.bytes) ||
847 (queue->min_threshold.time > 0 &&
848 queue->cur_level.time < queue->min_threshold.time)) &&
849 !gst_queue_is_filled (queue);
853 gst_queue_is_filled (GstQueue * queue)
855 return (((queue->max_size.buffers > 0 &&
856 queue->cur_level.buffers >= queue->max_size.buffers) ||
857 (queue->max_size.bytes > 0 &&
858 queue->cur_level.bytes >= queue->max_size.bytes) ||
859 (queue->max_size.time > 0 &&
860 queue->cur_level.time >= queue->max_size.time)));
864 gst_queue_leak_downstream (GstQueue * queue)
866 /* for as long as the queue is filled, dequeue an item and discard it */
867 while (gst_queue_is_filled (queue)) {
871 leak = gst_queue_locked_dequeue (queue, &is_buffer);
872 /* there is nothing to dequeue and the queue is still filled.. This should
874 g_assert (leak != NULL);
876 GST_CAT_DEBUG_OBJECT (queue_dataflow, queue,
877 "queue is full, leaking item %p on downstream end", leak);
878 gst_mini_object_unref (leak);
880 /* last buffer needs to get a DISCONT flag */
881 queue->head_needs_discont = TRUE;
886 gst_queue_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
889 GstClockTime duration, timestamp;
891 queue = GST_QUEUE_CAST (parent);
893 /* we have to lock the queue since we span threads */
894 GST_QUEUE_MUTEX_LOCK_CHECK (queue, out_flushing);
895 /* when we received EOS, we refuse any more data */
898 if (queue->unexpected)
901 timestamp = GST_BUFFER_TIMESTAMP (buffer);
902 duration = GST_BUFFER_DURATION (buffer);
904 GST_CAT_LOG_OBJECT (queue_dataflow, queue, "received buffer %p of size %"
905 G_GSIZE_FORMAT ", time %" GST_TIME_FORMAT ", duration %"
906 GST_TIME_FORMAT, buffer, gst_buffer_get_size (buffer),
907 GST_TIME_ARGS (timestamp), GST_TIME_ARGS (duration));
909 /* We make space available if we're "full" according to whatever
910 * the user defined as "full". Note that this only applies to buffers.
911 * We always handle events and they don't count in our statistics. */
912 while (gst_queue_is_filled (queue)) {
913 if (!queue->silent) {
914 GST_QUEUE_MUTEX_UNLOCK (queue);
915 g_signal_emit (queue, gst_queue_signals[SIGNAL_OVERRUN], 0);
916 GST_QUEUE_MUTEX_LOCK_CHECK (queue, out_flushing);
917 /* we recheck, the signal could have changed the thresholds */
918 if (!gst_queue_is_filled (queue))
922 /* how are we going to make space for this buffer? */
923 switch (queue->leaky) {
924 case GST_QUEUE_LEAK_UPSTREAM:
925 /* next buffer needs to get a DISCONT flag */
926 queue->tail_needs_discont = TRUE;
927 /* leak current buffer */
928 GST_CAT_DEBUG_OBJECT (queue_dataflow, queue,
929 "queue is full, leaking buffer on upstream end");
930 /* now we can clean up and exit right away */
932 case GST_QUEUE_LEAK_DOWNSTREAM:
933 gst_queue_leak_downstream (queue);
936 g_warning ("Unknown leaky type, using default");
938 case GST_QUEUE_NO_LEAK:
940 GST_CAT_DEBUG_OBJECT (queue_dataflow, queue,
941 "queue is full, waiting for free space");
943 /* don't leak. Instead, wait for space to be available */
945 /* for as long as the queue is filled, wait till an item was deleted. */
946 GST_QUEUE_WAIT_DEL_CHECK (queue, out_flushing);
947 } while (gst_queue_is_filled (queue));
949 GST_CAT_DEBUG_OBJECT (queue_dataflow, queue, "queue is not full");
951 if (!queue->silent) {
952 GST_QUEUE_MUTEX_UNLOCK (queue);
953 g_signal_emit (queue, gst_queue_signals[SIGNAL_RUNNING], 0);
954 GST_QUEUE_MUTEX_LOCK_CHECK (queue, out_flushing);
961 if (queue->tail_needs_discont) {
962 GstBuffer *subbuffer = gst_buffer_make_writable (buffer);
966 GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DISCONT);
968 GST_DEBUG_OBJECT (queue, "Could not mark buffer as DISCONT");
970 queue->tail_needs_discont = FALSE;
973 /* put buffer in queue now */
974 gst_queue_locked_enqueue_buffer (queue, buffer);
975 GST_QUEUE_MUTEX_UNLOCK (queue);
979 /* special conditions */
982 GST_QUEUE_MUTEX_UNLOCK (queue);
984 gst_buffer_unref (buffer);
990 GstFlowReturn ret = queue->srcresult;
992 GST_CAT_LOG_OBJECT (queue_dataflow, queue,
993 "exit because task paused, reason: %s", gst_flow_get_name (ret));
994 GST_QUEUE_MUTEX_UNLOCK (queue);
995 gst_buffer_unref (buffer);
1001 GST_CAT_LOG_OBJECT (queue_dataflow, queue, "exit because we received EOS");
1002 GST_QUEUE_MUTEX_UNLOCK (queue);
1004 gst_buffer_unref (buffer);
1006 return GST_FLOW_EOS;
1010 GST_CAT_LOG_OBJECT (queue_dataflow, queue, "exit because we received EOS");
1011 GST_QUEUE_MUTEX_UNLOCK (queue);
1013 gst_buffer_unref (buffer);
1015 return GST_FLOW_EOS;
1020 gst_queue_push_newsegment (GstQueue * queue)
1024 event = gst_event_new_segment (&queue->src_segment);
1025 GST_CAT_LOG_OBJECT (queue_dataflow, queue, "pushing real newsegment event");
1026 gst_pad_push_event (queue->srcpad, event);
1029 /* dequeue an item from the queue an push it downstream. This functions returns
1030 * the result of the push. */
1031 static GstFlowReturn
1032 gst_queue_push_one (GstQueue * queue)
1034 GstFlowReturn result = GST_FLOW_OK;
1035 GstMiniObject *data;
1038 data = gst_queue_locked_dequeue (queue, &is_buffer);
1046 buffer = GST_BUFFER_CAST (data);
1048 if (queue->head_needs_discont) {
1049 GstBuffer *subbuffer = gst_buffer_make_writable (buffer);
1053 GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DISCONT);
1055 GST_DEBUG_OBJECT (queue, "Could not mark buffer as DISCONT");
1057 queue->head_needs_discont = FALSE;
1060 GST_QUEUE_MUTEX_UNLOCK (queue);
1061 if (queue->push_newsegment) {
1062 gst_queue_push_newsegment (queue);
1064 result = gst_pad_push (queue->srcpad, buffer);
1066 /* need to check for srcresult here as well */
1067 GST_QUEUE_MUTEX_LOCK_CHECK (queue, out_flushing);
1069 if (result == GST_FLOW_EOS) {
1070 GST_CAT_LOG_OBJECT (queue_dataflow, queue, "got EOS from downstream");
1071 /* stop pushing buffers, we dequeue all items until we see an item that we
1072 * can push again, which is EOS or SEGMENT. If there is nothing in the
1073 * queue we can push, we set a flag to make the sinkpad refuse more
1074 * buffers with an EOS return value. */
1075 while ((data = gst_queue_locked_dequeue (queue, &is_buffer))) {
1077 GST_CAT_LOG_OBJECT (queue_dataflow, queue,
1078 "dropping EOS buffer %p", data);
1079 gst_buffer_unref (GST_BUFFER_CAST (data));
1081 GstEvent *event = GST_EVENT_CAST (data);
1082 GstEventType type = GST_EVENT_TYPE (event);
1084 if (type == GST_EVENT_EOS || type == GST_EVENT_SEGMENT) {
1085 /* we found a pushable item in the queue, push it out */
1086 GST_CAT_LOG_OBJECT (queue_dataflow, queue,
1087 "pushing pushable event %s after EOS",
1088 GST_EVENT_TYPE_NAME (event));
1091 GST_CAT_LOG_OBJECT (queue_dataflow, queue,
1092 "dropping EOS event %p", event);
1093 gst_event_unref (event);
1096 /* no more items in the queue. Set the unexpected flag so that upstream
1097 * make us refuse any more buffers on the sinkpad. Since we will still
1098 * accept EOS and SEGMENT we return _FLOW_OK to the caller so that the
1099 * task function does not shut down. */
1100 queue->unexpected = TRUE;
1101 result = GST_FLOW_OK;
1104 GstEvent *event = GST_EVENT_CAST (data);
1105 GstEventType type = GST_EVENT_TYPE (event);
1107 GST_QUEUE_MUTEX_UNLOCK (queue);
1109 if (queue->push_newsegment && type != GST_EVENT_SEGMENT) {
1110 gst_queue_push_newsegment (queue);
1112 gst_pad_push_event (queue->srcpad, event);
1114 GST_QUEUE_MUTEX_LOCK_CHECK (queue, out_flushing);
1115 /* if we're EOS, return EOS so that the task pauses. */
1116 if (type == GST_EVENT_EOS) {
1117 GST_CAT_LOG_OBJECT (queue_dataflow, queue,
1118 "pushed EOS event %p, return EOS", event);
1119 result = GST_FLOW_EOS;
1127 GST_CAT_LOG_OBJECT (queue_dataflow, queue,
1128 "exit because we have no item in the queue");
1129 return GST_FLOW_ERROR;
1133 GST_CAT_LOG_OBJECT (queue_dataflow, queue, "exit because we are flushing");
1134 return GST_FLOW_WRONG_STATE;
1139 gst_queue_loop (GstPad * pad)
1144 queue = (GstQueue *) GST_PAD_PARENT (pad);
1146 /* have to lock for thread-safety */
1147 GST_QUEUE_MUTEX_LOCK_CHECK (queue, out_flushing);
1149 while (gst_queue_is_empty (queue)) {
1150 GST_CAT_DEBUG_OBJECT (queue_dataflow, queue, "queue is empty");
1151 if (!queue->silent) {
1152 GST_QUEUE_MUTEX_UNLOCK (queue);
1153 g_signal_emit (queue, gst_queue_signals[SIGNAL_UNDERRUN], 0);
1154 GST_QUEUE_MUTEX_LOCK_CHECK (queue, out_flushing);
1157 /* we recheck, the signal could have changed the thresholds */
1158 while (gst_queue_is_empty (queue)) {
1159 GST_QUEUE_WAIT_ADD_CHECK (queue, out_flushing);
1162 GST_CAT_DEBUG_OBJECT (queue_dataflow, queue, "queue is not empty");
1163 if (!queue->silent) {
1164 GST_QUEUE_MUTEX_UNLOCK (queue);
1165 g_signal_emit (queue, gst_queue_signals[SIGNAL_RUNNING], 0);
1166 g_signal_emit (queue, gst_queue_signals[SIGNAL_PUSHING], 0);
1167 GST_QUEUE_MUTEX_LOCK_CHECK (queue, out_flushing);
1171 ret = gst_queue_push_one (queue);
1172 queue->push_newsegment = FALSE;
1173 queue->srcresult = ret;
1174 if (ret != GST_FLOW_OK)
1177 GST_QUEUE_MUTEX_UNLOCK (queue);
1184 gboolean eos = queue->eos;
1185 GstFlowReturn ret = queue->srcresult;
1187 gst_pad_pause_task (queue->srcpad);
1188 GST_CAT_LOG_OBJECT (queue_dataflow, queue,
1189 "pause task, reason: %s", gst_flow_get_name (ret));
1190 GST_QUEUE_SIGNAL_DEL (queue);
1191 GST_QUEUE_MUTEX_UNLOCK (queue);
1192 /* let app know about us giving up if upstream is not expected to do so */
1193 /* EOS is already taken care of elsewhere */
1194 if (eos && (ret == GST_FLOW_NOT_LINKED || ret < GST_FLOW_EOS)) {
1195 GST_ELEMENT_ERROR (queue, STREAM, FAILED,
1196 (_("Internal data flow error.")),
1197 ("streaming task paused, reason %s (%d)",
1198 gst_flow_get_name (ret), ret));
1199 gst_pad_push_event (queue->srcpad, gst_event_new_eos ());
1206 gst_queue_handle_src_event (GstPad * pad, GstObject * parent, GstEvent * event)
1208 gboolean res = TRUE;
1209 GstQueue *queue = GST_QUEUE (parent);
1211 #ifndef GST_DISABLE_GST_DEBUG
1212 GST_CAT_DEBUG_OBJECT (queue_dataflow, queue, "got event %p (%d)",
1213 event, GST_EVENT_TYPE (event));
1216 res = gst_pad_push_event (queue->sinkpad, event);
1222 gst_queue_handle_src_query (GstPad * pad, GstObject * parent, GstQuery * query)
1224 GstQueue *queue = GST_QUEUE (parent);
1227 res = gst_pad_peer_query (queue->sinkpad, query);
1231 switch (GST_QUERY_TYPE (query)) {
1232 case GST_QUERY_POSITION:
1237 /* get peer position */
1238 gst_query_parse_position (query, &format, &peer_pos);
1240 /* FIXME: this code assumes that there's no discont in the queue */
1242 case GST_FORMAT_BYTES:
1243 peer_pos -= queue->cur_level.bytes;
1245 case GST_FORMAT_TIME:
1246 peer_pos -= queue->cur_level.time;
1249 GST_DEBUG_OBJECT (queue, "Can't adjust query in %s format, don't "
1250 "know how to adjust value", gst_format_get_name (format));
1253 /* set updated position */
1254 gst_query_set_position (query, format, peer_pos);
1257 case GST_QUERY_LATENCY:
1260 GstClockTime min, max;
1262 gst_query_parse_latency (query, &live, &min, &max);
1264 /* we can delay up to the limit of the queue in time. If we have no time
1265 * limit, the best thing we can do is to return an infinite delay. In
1266 * reality a better estimate would be the byte/buffer rate but that is not
1267 * possible right now. */
1268 if (queue->max_size.time > 0 && max != -1)
1269 max += queue->max_size.time;
1273 /* adjust for min-threshold */
1274 if (queue->min_threshold.time > 0 && min != -1)
1275 min += queue->min_threshold.time;
1277 gst_query_set_latency (query, live, min, max);
1281 /* peer handled other queries */
1289 gst_queue_sink_activate_mode (GstPad * pad, GstObject * parent, GstPadMode mode,
1295 queue = GST_QUEUE (parent);
1298 case GST_PAD_MODE_PUSH:
1300 GST_QUEUE_MUTEX_LOCK (queue);
1301 queue->srcresult = GST_FLOW_OK;
1303 queue->unexpected = FALSE;
1304 GST_QUEUE_MUTEX_UNLOCK (queue);
1306 /* step 1, unblock chain function */
1307 GST_QUEUE_MUTEX_LOCK (queue);
1308 queue->srcresult = GST_FLOW_WRONG_STATE;
1309 gst_queue_locked_flush (queue);
1310 GST_QUEUE_MUTEX_UNLOCK (queue);
1322 gst_queue_src_activate_mode (GstPad * pad, GstObject * parent, GstPadMode mode,
1328 queue = GST_QUEUE (parent);
1331 case GST_PAD_MODE_PUSH:
1333 GST_QUEUE_MUTEX_LOCK (queue);
1334 queue->srcresult = GST_FLOW_OK;
1336 queue->unexpected = FALSE;
1337 /* we do not start the task yet if the pad is not connected */
1338 if (gst_pad_is_linked (pad))
1340 gst_pad_start_task (pad, (GstTaskFunction) gst_queue_loop, pad);
1342 GST_INFO_OBJECT (queue, "not starting task as pad is not linked");
1345 GST_QUEUE_MUTEX_UNLOCK (queue);
1347 /* step 1, unblock loop function */
1348 GST_QUEUE_MUTEX_LOCK (queue);
1349 queue->srcresult = GST_FLOW_WRONG_STATE;
1350 /* the item add signal will unblock */
1351 g_cond_signal (&queue->item_add);
1352 GST_QUEUE_MUTEX_UNLOCK (queue);
1354 /* step 2, make sure streaming finishes */
1355 result = gst_pad_stop_task (pad);
1366 queue_capacity_change (GstQueue * queue)
1368 if (queue->leaky == GST_QUEUE_LEAK_DOWNSTREAM) {
1369 gst_queue_leak_downstream (queue);
1372 /* changing the capacity of the queue must wake up
1373 * the _chain function, it might have more room now
1374 * to store the buffer/event in the queue */
1375 GST_QUEUE_SIGNAL_DEL (queue);
1378 /* Changing the minimum required fill level must
1379 * wake up the _loop function as it might now
1380 * be able to preceed.
1382 #define QUEUE_THRESHOLD_CHANGE(q)\
1383 GST_QUEUE_SIGNAL_ADD (q);
1386 gst_queue_set_property (GObject * object,
1387 guint prop_id, const GValue * value, GParamSpec * pspec)
1389 GstQueue *queue = GST_QUEUE (object);
1391 /* someone could change levels here, and since this
1392 * affects the get/put funcs, we need to lock for safety. */
1393 GST_QUEUE_MUTEX_LOCK (queue);
1396 case PROP_MAX_SIZE_BYTES:
1397 queue->max_size.bytes = g_value_get_uint (value);
1398 queue_capacity_change (queue);
1400 case PROP_MAX_SIZE_BUFFERS:
1401 queue->max_size.buffers = g_value_get_uint (value);
1402 queue_capacity_change (queue);
1404 case PROP_MAX_SIZE_TIME:
1405 queue->max_size.time = g_value_get_uint64 (value);
1406 queue_capacity_change (queue);
1408 case PROP_MIN_THRESHOLD_BYTES:
1409 queue->min_threshold.bytes = g_value_get_uint (value);
1410 queue->orig_min_threshold.bytes = queue->min_threshold.bytes;
1411 QUEUE_THRESHOLD_CHANGE (queue);
1413 case PROP_MIN_THRESHOLD_BUFFERS:
1414 queue->min_threshold.buffers = g_value_get_uint (value);
1415 queue->orig_min_threshold.buffers = queue->min_threshold.buffers;
1416 QUEUE_THRESHOLD_CHANGE (queue);
1418 case PROP_MIN_THRESHOLD_TIME:
1419 queue->min_threshold.time = g_value_get_uint64 (value);
1420 queue->orig_min_threshold.time = queue->min_threshold.time;
1421 QUEUE_THRESHOLD_CHANGE (queue);
1424 queue->leaky = g_value_get_enum (value);
1427 queue->silent = g_value_get_boolean (value);
1430 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1434 GST_QUEUE_MUTEX_UNLOCK (queue);
1438 gst_queue_get_property (GObject * object,
1439 guint prop_id, GValue * value, GParamSpec * pspec)
1441 GstQueue *queue = GST_QUEUE (object);
1443 GST_QUEUE_MUTEX_LOCK (queue);
1446 case PROP_CUR_LEVEL_BYTES:
1447 g_value_set_uint (value, queue->cur_level.bytes);
1449 case PROP_CUR_LEVEL_BUFFERS:
1450 g_value_set_uint (value, queue->cur_level.buffers);
1452 case PROP_CUR_LEVEL_TIME:
1453 g_value_set_uint64 (value, queue->cur_level.time);
1455 case PROP_MAX_SIZE_BYTES:
1456 g_value_set_uint (value, queue->max_size.bytes);
1458 case PROP_MAX_SIZE_BUFFERS:
1459 g_value_set_uint (value, queue->max_size.buffers);
1461 case PROP_MAX_SIZE_TIME:
1462 g_value_set_uint64 (value, queue->max_size.time);
1464 case PROP_MIN_THRESHOLD_BYTES:
1465 g_value_set_uint (value, queue->min_threshold.bytes);
1467 case PROP_MIN_THRESHOLD_BUFFERS:
1468 g_value_set_uint (value, queue->min_threshold.buffers);
1470 case PROP_MIN_THRESHOLD_TIME:
1471 g_value_set_uint64 (value, queue->min_threshold.time);
1474 g_value_set_enum (value, queue->leaky);
1477 g_value_set_boolean (value, queue->silent);
1480 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1484 GST_QUEUE_MUTEX_UNLOCK (queue);