added taaz's threading patch, including queue events
[platform/upstream/gstreamer.git] / gst / gstqueue.c
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2000 Wim Taymans <wtay@chello.be>
4  *
5  * gstqueue.c:
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 //#define DEBUG_ENABLED
24 //#define STATUS_ENABLED
25 #ifdef STATUS_ENABLED
26 #define STATUS(A) GST_DEBUG(GST_CAT_DATAFLOW, A, GST_ELEMENT_NAME(queue))
27 #else
28 #define STATUS(A)
29 #endif
30
31 #include <pthread.h>
32
33 #include "config.h"
34 #include "gst_private.h"
35
36 #include "gstqueue.h"
37 #include "gstscheduler.h"
38
39 GstElementDetails gst_queue_details = {
40   "Queue",
41   "Connection",
42   "Simple data queue",
43   VERSION,
44   "Erik Walthinsen <omega@cse.ogi.edu>",
45   "(C) 1999",
46 };
47
48
49 /* Queue signals and args */
50 enum {
51   LOW_WATERMARK,
52   HIGH_WATERMARK,
53   LAST_SIGNAL
54 };
55
56 enum {
57   ARG_0,
58   ARG_LEVEL_BUFFERS,
59   ARG_LEVEL_BYTES,
60   ARG_LEVEL_TIME,
61   ARG_SIZE_BUFFERS,
62   ARG_SIZE_BYTES,
63   ARG_SIZE_TIME,
64   ARG_LEAKY,
65   ARG_LEVEL,
66   ARG_MAX_LEVEL,
67 };
68
69
70 static void                     gst_queue_class_init            (GstQueueClass *klass);
71 static void                     gst_queue_init                  (GstQueue *queue);
72
73 static void                     gst_queue_set_property          (GObject *object, guint prop_id, 
74                                                                  const GValue *value, GParamSpec *pspec);
75 static void                     gst_queue_get_property          (GObject *object, guint prop_id, 
76                                                                  GValue *value, GParamSpec *pspec);
77
78 static GstPadNegotiateReturn    gst_queue_handle_negotiate_src  (GstPad *pad, GstCaps **caps, gpointer *data);
79 static GstPadNegotiateReturn    gst_queue_handle_negotiate_sink (GstPad *pad, GstCaps **caps, gpointer *data);
80 static void                     gst_queue_chain                 (GstPad *pad, GstBuffer *buf);
81 static GstBuffer *              gst_queue_get                   (GstPad *pad);
82 static GstBufferPool*           gst_queue_get_bufferpool        (GstPad *pad);
83         
84 static void                     gst_queue_locked_flush                  (GstQueue *queue);
85 static void                     gst_queue_flush                 (GstQueue *queue);
86
87 static GstElementStateReturn    gst_queue_change_state          (GstElement *element);
88
89   
90 #define GST_TYPE_QUEUE_LEAKY (queue_leaky_get_type())
91 static GType
92 queue_leaky_get_type(void) {
93   static GType queue_leaky_type = 0;
94   static GEnumValue queue_leaky[] = {
95     { GST_QUEUE_NO_LEAK,                "0", "Not Leaky" },
96     { GST_QUEUE_LEAK_UPSTREAM,          "1", "Leaky on Upstream" },
97     { GST_QUEUE_LEAK_DOWNSTREAM,        "2", "Leaky on Downstream" },
98     { 0, NULL, NULL },
99   };
100   if (!queue_leaky_type) {
101     queue_leaky_type = g_enum_register_static("GstQueueLeaky", queue_leaky);
102   }
103   return queue_leaky_type;
104 }
105
106 static GstElementClass *parent_class = NULL;
107 //static guint gst_queue_signals[LAST_SIGNAL] = { 0 };
108
109 GType
110 gst_queue_get_type(void) 
111 {
112   static GType queue_type = 0;
113
114   if (!queue_type) {
115     static const GTypeInfo queue_info = {
116       sizeof(GstQueueClass),
117       NULL,
118       NULL,
119       (GClassInitFunc)gst_queue_class_init,
120       NULL,
121       NULL,
122       sizeof(GstQueue),
123       4,
124       (GInstanceInitFunc)gst_queue_init,
125       NULL
126     };
127     queue_type = g_type_register_static (GST_TYPE_ELEMENT, "GstQueue", &queue_info, 0);
128   }
129   return queue_type;
130 }
131
132 static void
133 gst_queue_class_init (GstQueueClass *klass)
134 {
135   GObjectClass *gobject_class;
136   GstElementClass *gstelement_class;
137
138   gobject_class = (GObjectClass*)klass;
139   gstelement_class = (GstElementClass*)klass;
140
141   parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
142
143   g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_LEAKY,
144     g_param_spec_enum("leaky","Leaky","Where the queue leaks, if at all.",
145                       GST_TYPE_QUEUE_LEAKY,GST_QUEUE_NO_LEAK,G_PARAM_READWRITE));
146   g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_LEVEL,
147     g_param_spec_int("level","Level","How many buffers are in the queue.",
148                      0,G_MAXINT,0,G_PARAM_READABLE));
149   g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_MAX_LEVEL,
150     g_param_spec_int("max_level","Maximum Level","How many buffers the queue holds.",
151                      0,G_MAXINT,100,G_PARAM_READWRITE));
152
153   gobject_class->set_property = GST_DEBUG_FUNCPTR(gst_queue_set_property);
154   gobject_class->get_property = GST_DEBUG_FUNCPTR(gst_queue_get_property);
155
156   gstelement_class->change_state = GST_DEBUG_FUNCPTR(gst_queue_change_state);
157 }
158
159 static void
160 gst_queue_init (GstQueue *queue)
161 {
162   // scheduling on this kind of element is, well, interesting
163   GST_FLAG_SET (queue, GST_ELEMENT_DECOUPLED);
164
165   queue->sinkpad = gst_pad_new ("sink", GST_PAD_SINK);
166   gst_pad_set_chain_function (queue->sinkpad, GST_DEBUG_FUNCPTR(gst_queue_chain));
167   gst_element_add_pad (GST_ELEMENT (queue), queue->sinkpad);
168   gst_pad_set_negotiate_function (queue->sinkpad, GST_DEBUG_FUNCPTR(gst_queue_handle_negotiate_sink));
169   gst_pad_set_bufferpool_function (queue->sinkpad, GST_DEBUG_FUNCPTR(gst_queue_get_bufferpool));
170
171   queue->srcpad = gst_pad_new ("src", GST_PAD_SRC);
172   gst_pad_set_get_function (queue->srcpad, GST_DEBUG_FUNCPTR(gst_queue_get));
173   gst_element_add_pad (GST_ELEMENT (queue), queue->srcpad);
174   gst_pad_set_negotiate_function (queue->srcpad, GST_DEBUG_FUNCPTR(gst_queue_handle_negotiate_src));
175
176   queue->queue = NULL;
177   queue->level_buffers = 0;
178   queue->level_bytes = 0;
179   queue->level_time = 0LL;
180   queue->size_buffers = 100;            // 100 buffers
181   queue->size_bytes = 100 * 1024;       // 100KB
182   queue->size_time = 1000000000LL;      // 1sec
183
184   queue->qlock = g_mutex_new ();
185   queue->reader = FALSE;
186   queue->writer = FALSE;
187   queue->not_empty = g_cond_new ();
188   queue->not_full = g_cond_new ();
189   GST_DEBUG_ELEMENT (GST_CAT_THREAD, queue, "initialized queue's not_empty & not_full conditions\n");
190 }
191
192 static GstBufferPool*
193 gst_queue_get_bufferpool (GstPad *pad)
194 {
195   GstQueue *queue;
196
197   queue = GST_QUEUE (GST_OBJECT_PARENT (pad));
198
199   return gst_pad_get_bufferpool (queue->srcpad);
200 }
201
202 static GstPadNegotiateReturn
203 gst_queue_handle_negotiate_src (GstPad *pad, GstCaps **caps, gpointer *data)
204 {
205   GstQueue *queue;
206
207   queue = GST_QUEUE (GST_OBJECT_PARENT (pad));
208
209   return gst_pad_negotiate_proxy (pad, queue->sinkpad, caps);
210 }
211
212 static GstPadNegotiateReturn
213 gst_queue_handle_negotiate_sink (GstPad *pad, GstCaps **caps, gpointer *data)
214 {
215   GstQueue *queue;
216
217   queue = GST_QUEUE (GST_OBJECT_PARENT (pad));
218
219   return gst_pad_negotiate_proxy (pad, queue->srcpad, caps);
220 }
221
222 static void
223 gst_queue_cleanup_buffers (gpointer data, const gpointer user_data)
224 {
225   GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, user_data, "cleaning buffer %p\n", data);
226   gst_buffer_unref (GST_BUFFER (data));
227 }
228
229 static void
230 gst_queue_locked_flush (GstQueue *queue)
231 {
232   g_slist_foreach (queue->queue, gst_queue_cleanup_buffers,
233                   (gpointer) queue);
234   g_slist_free (queue->queue);
235
236   queue->queue = NULL;
237   queue->level_buffers = 0;
238   queue->timeval = NULL;
239 }
240
241 static void
242 gst_queue_flush (GstQueue *queue)
243 {
244   g_mutex_lock (queue->qlock);
245   gst_queue_locked_flush (queue);
246   g_mutex_unlock (queue->qlock);
247 }
248
249 static void
250 gst_queue_chain (GstPad *pad, GstBuffer *buf)
251 {
252   GstQueue *queue;
253   gboolean reader;
254
255   g_return_if_fail (pad != NULL);
256   g_return_if_fail (GST_IS_PAD (pad));
257   g_return_if_fail (buf != NULL);
258
259   queue = GST_QUEUE (GST_OBJECT_PARENT (pad));
260
261   reader = FALSE;
262
263   /* we have to lock the queue since we span threads */
264
265   GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "locking t:%ld\n", pthread_self ());
266   g_mutex_lock (queue->qlock);
267   GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "locked t:%ld\n", pthread_self ());
268
269   if (GST_IS_EVENT(buf)) {
270     GstEvent *event = GST_EVENT(buf);
271     switch (GST_EVENT_TYPE(event)) {
272       case GST_EVENT_FLUSH:
273         GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "flushing queue\n");
274         gst_queue_locked_flush (queue);
275         break;
276       default:
277         break;
278     }
279   }
280
281   GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "adding buffer %p of size %d\n",buf,GST_BUFFER_SIZE(buf));
282
283   if (queue->level_buffers == queue->size_buffers) {
284     // if this is a leaky queue...
285     if (queue->leaky) {
286       // FIXME don't want to leak events!
287       // if we leak on the upstream side, drop the current buffer
288       if (queue->leaky == GST_QUEUE_LEAK_UPSTREAM) {
289         GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "queue is full, leaking buffer on upstream end\n");
290         if (GST_IS_EVENT (buf))
291           fprintf(stderr, "Error: queue [%s] leaked an event, type:%d\n",
292               GST_ELEMENT_NAME(GST_ELEMENT(queue)),
293               GST_EVENT_TYPE(GST_EVENT(buf)));
294           GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "queue is full, leaking buffer on upstream end\n");
295         gst_buffer_unref(buf);
296         // now we have to clean up and exit right away
297         g_mutex_unlock (queue->qlock);
298         return;
299       }
300       // otherwise we have to push a buffer off the other end
301       else {
302         GSList *front;
303         GstBuffer *leakbuf;
304         GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "queue is full, leaking buffer on downstream end\n");
305         front = queue->queue;
306         leakbuf = (GstBuffer *)(front->data);
307         if (GST_IS_EVENT (leakbuf))
308           fprintf(stderr, "Error: queue [%s] leaked an event, type:%d\n",
309               GST_ELEMENT_NAME(GST_ELEMENT(queue)),
310               GST_EVENT_TYPE(GST_EVENT(leakbuf)));
311         queue->level_buffers--;
312         queue->level_bytes -= GST_BUFFER_SIZE(leakbuf);
313         gst_buffer_unref(leakbuf);
314         queue->queue = g_slist_remove_link (queue->queue, front);
315         g_slist_free (front);
316       }
317     }
318
319     GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "pre full wait, level:%d/%d\n",
320         queue->level_buffers, queue->size_buffers);
321     while (queue->level_buffers == queue->size_buffers) {
322       // if there's a pending state change for this queue or its manager, switch
323       // back to iterator so bottom half of state change executes
324       if (GST_STATE_PENDING(queue) != GST_STATE_VOID_PENDING ||
325 //          GST_STATE_PENDING(GST_SCHEDULE(GST_ELEMENT(queue)->sched)->parent) != GST_STATE_VOID_PENDING)
326 GST_STATE_PENDING(GST_SCHED_PARENT(GST_ELEMENT_SCHED(GST_PAD_PARENT(GST_PAD_PEER(queue->sinkpad))))) != 
327 GST_STATE_VOID_PENDING)
328       {
329         GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "interrupted!!\n");
330         if (GST_STATE_PENDING(queue) != GST_STATE_VOID_PENDING)
331           GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "GST_STATE_PENDING(queue) != GST_STATE_VOID_PENDING)\n");
332         if (GST_STATE_PENDING(GST_SCHEDULE(GST_ELEMENT(queue)->sched)->parent) != GST_STATE_VOID_PENDING)
333           GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "GST_STATE_PENDING(GST_SCHEDULE(GST_ELEMENT(queue)->sched)->parent) != GST_STATE_VOID_PENDING\n");
334         g_mutex_unlock (queue->qlock);
335         cothread_switch(cothread_current_main());
336       }
337
338       GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "waiting for not_full, level:%d/%d\n", queue->level_buffers, queue->size_buffers);
339       if (queue->writer)
340         GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "WARNING: multiple writers on queue!\n");
341       queue->writer = TRUE;
342       g_cond_wait (queue->not_full, queue->qlock);
343       queue->writer = FALSE;
344       GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "got not_full signal\n");
345     }
346     GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "post full wait, level:%d/%d\n",
347         queue->level_buffers, queue->size_buffers);
348   }
349
350   /* put the buffer on the tail of the list */
351   queue->queue = g_slist_append (queue->queue, buf);
352   queue->level_buffers++;
353   queue->level_bytes += GST_BUFFER_SIZE(buf);
354   GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "(%s:%s)+ level:%d/%d\n",
355       GST_DEBUG_PAD_NAME(pad),
356       queue->level_buffers, queue->size_buffers);
357
358   /* reader waiting on an empty queue */
359   reader = queue->reader;
360
361   g_mutex_unlock (queue->qlock);
362
363   if (reader)
364   {
365     GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "signalling not_empty\n");
366     g_cond_signal (queue->not_empty);
367   }
368 }
369
370 static GstBuffer *
371 gst_queue_get (GstPad *pad)
372 {
373   GstQueue *queue;
374   GstBuffer *buf = NULL;
375   GSList *front;
376   gboolean writer;
377
378   g_assert(pad != NULL);
379   g_assert(GST_IS_PAD(pad));
380   g_return_val_if_fail (pad != NULL, NULL);
381   g_return_val_if_fail (GST_IS_PAD (pad), NULL);
382
383   queue = GST_QUEUE (GST_OBJECT_PARENT (pad));
384
385   writer = FALSE;
386
387   /* have to lock for thread-safety */
388   GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "locking t:%ld\n", pthread_self ());
389   g_mutex_lock (queue->qlock);
390   GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "locked t:%ld %p\n", pthread_self (), queue->not_empty);
391
392   GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "pre empty wait, level:%d/%d\n", queue->level_buffers, queue->size_buffers);
393   while (queue->level_buffers == 0) {
394     // if there's a pending state change for this queue or its manager, switch
395     // back to iterator so bottom half of state change executes
396     if (GST_STATE_PENDING(queue) != GST_STATE_VOID_PENDING ||
397 //        GST_STATE_PENDING(GST_SCHEDULE(GST_ELEMENT(queue)->sched)->parent) != GST_STATE_VOID_PENDING)
398 GST_STATE_PENDING(GST_SCHED_PARENT(GST_ELEMENT_SCHED(GST_PAD_PARENT(GST_PAD_PEER(queue->srcpad))))) != 
399 GST_STATE_VOID_PENDING)
400     {
401       GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "interrupted!!\n");
402       if (GST_STATE_PENDING(queue) != GST_STATE_VOID_PENDING)
403         GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "GST_STATE_PENDING(queue) != GST_STATE_VOID_PENDING)\n");
404       if (GST_STATE_PENDING(GST_SCHEDULE(GST_ELEMENT(queue)->sched)->parent) != GST_STATE_VOID_PENDING)
405         GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "GST_STATE_PENDING(GST_SCHEDULE(GST_ELEMENT(queue)->sched)->parent) != GST_STATE_VOID_PENDING\n");
406       g_mutex_unlock (queue->qlock);
407       cothread_switch(cothread_current_main());
408     }
409
410     GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "waiting for not_empty, level:%d/%d\n", queue->level_buffers, queue->size_buffers);
411     if (queue->reader)
412       GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "WARNING: multiple readers on queue!\n");
413     queue->reader = TRUE;
414     g_cond_wait (queue->not_empty, queue->qlock);
415     queue->reader = FALSE;
416     GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "got not_empty signal\n");
417   }
418   GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "post empty wait, level:%d/%d\n", queue->level_buffers, queue->size_buffers);
419
420   front = queue->queue;
421   buf = (GstBuffer *)(front->data);
422   GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "retrieved buffer %p from queue\n", buf);
423   queue->queue = g_slist_remove_link (queue->queue, front);
424   g_slist_free (front);
425
426   queue->level_buffers--;
427   queue->level_bytes -= GST_BUFFER_SIZE(buf);
428   GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "(%s:%s)- level:%d/%d\n",
429       GST_DEBUG_PAD_NAME(pad),
430       queue->level_buffers, queue->size_buffers);
431
432   /* writer waiting on a full queue */
433   writer = queue->writer;
434
435   g_mutex_unlock (queue->qlock);
436
437   if (writer)
438   {
439     GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "signalling not_full\n");
440     g_cond_signal (queue->not_full);
441   }
442
443   // FIXME where should this be? locked?
444   if (GST_IS_EVENT(buf)) {
445     GstEvent *event = GST_EVENT(buf);
446     switch (GST_EVENT_TYPE(event)) {
447       case GST_EVENT_EOS:
448         GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "queue eos\n");
449         gst_element_set_state (GST_ELEMENT (queue), GST_STATE_PAUSED);
450         break;
451       default:
452         break;
453     }
454   }
455
456   return buf;
457 }
458
459 static GstElementStateReturn
460 gst_queue_change_state (GstElement *element)
461 {
462   GstQueue *queue;
463   GstElementStateReturn ret;
464   g_return_val_if_fail (GST_IS_QUEUE (element), GST_STATE_FAILURE);
465
466   queue = GST_QUEUE (element);
467
468   // lock the queue so another thread (not in sync with this thread's state)
469   // can't call this queue's _get (or whatever)
470   GST_LOCK (queue);
471
472   /* if going down into NULL state, clear out buffers*/
473   if (GST_STATE_PENDING (element) == GST_STATE_READY) {
474     /* otherwise (READY or higher) we need to open the file */
475     gst_queue_flush (queue);
476   }
477
478   // if we haven't failed already, give the parent class a chance to ;-)
479   if (GST_ELEMENT_CLASS (parent_class)->change_state)
480   {
481     gboolean valid_handler = FALSE;
482     guint state_change_id = g_signal_lookup("state_change", G_OBJECT_TYPE(element));
483
484     // determine whether we need to block the parent (element) class'
485     // STATE_CHANGE signal so we can UNLOCK before returning.  we block
486     // it if we could find the state_change signal AND there's a signal
487     // handler attached to it.
488     //
489     // note: this assumes that change_state() *only* emits state_change signal.
490     // if element change_state() emits other signals, they need to be blocked
491     // as well.
492     if (state_change_id &&
493         g_signal_has_handler_pending(G_OBJECT(element), state_change_id, 0, FALSE))
494       valid_handler = TRUE;
495     if (valid_handler)
496       g_signal_handler_block(G_OBJECT(element), state_change_id);
497
498     ret = GST_ELEMENT_CLASS (parent_class)->change_state (element);
499
500     if (valid_handler)
501       g_signal_handler_unblock(G_OBJECT(element), state_change_id);
502
503     // UNLOCK, *then* emit signal (if there's one there)
504     GST_UNLOCK(queue);
505     if (valid_handler)
506       g_signal_emit(G_OBJECT (element), state_change_id, 0, GST_STATE(element));
507   }
508   else
509   {
510     ret = GST_STATE_SUCCESS;
511     GST_UNLOCK(queue);
512   }
513
514   return ret;
515 }
516
517
518 static void
519 gst_queue_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
520 {
521   GstQueue *queue;
522
523   /* it's not null if we got it, but it might not be ours */
524   g_return_if_fail (GST_IS_QUEUE (object));
525
526   queue = GST_QUEUE (object);
527
528   switch (prop_id) {
529     case ARG_LEAKY:
530       queue->leaky = g_value_get_int(value);
531       break;
532     case ARG_MAX_LEVEL:
533       queue->size_buffers = g_value_get_int(value);
534       break;
535     default:
536       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
537       break;
538   }
539 }
540
541 static void
542 gst_queue_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
543 {
544   GstQueue *queue;
545
546   /* it's not null if we got it, but it might not be ours */
547   g_return_if_fail (GST_IS_QUEUE (object));
548
549   queue = GST_QUEUE (object);
550
551   switch (prop_id) {
552     case ARG_LEAKY:
553       g_value_set_int(value, queue->leaky);
554       break;
555     case ARG_LEVEL:
556       g_value_set_int(value, queue->level_buffers);
557       break;
558     case ARG_MAX_LEVEL:
559       g_value_set_int(value, queue->size_buffers);
560       break;
561     default:
562       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
563       break;
564   }
565 }