can someone fix this better than me and remove FIXME's ?
[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 #include "gstevent.h"
39
40 GstElementDetails gst_queue_details = {
41   "Queue",
42   "Connection",
43   "Simple data queue",
44   VERSION,
45   "Erik Walthinsen <omega@cse.ogi.edu>",
46   "(C) 1999",
47 };
48
49
50 /* Queue signals and args */
51 enum {
52   LOW_WATERMARK,
53   HIGH_WATERMARK,
54   LAST_SIGNAL
55 };
56
57 enum {
58   ARG_0,
59   ARG_LEVEL_BUFFERS,
60   ARG_LEVEL_BYTES,
61   ARG_LEVEL_TIME,
62   ARG_SIZE_BUFFERS,
63   ARG_SIZE_BYTES,
64   ARG_SIZE_TIME,
65   ARG_LEAKY,
66   ARG_LEVEL,
67   ARG_MAX_LEVEL,
68   ARG_MAY_DEADLOCK,
69 };
70
71
72 static void                     gst_queue_class_init            (GstQueueClass *klass);
73 static void                     gst_queue_init                  (GstQueue *queue);
74 static void                     gst_queue_dispose               (GObject *object);
75
76 static void                     gst_queue_set_property          (GObject *object, guint prop_id, 
77                                                                  const GValue *value, GParamSpec *pspec);
78 static void                     gst_queue_get_property          (GObject *object, guint prop_id, 
79                                                                  GValue *value, GParamSpec *pspec);
80
81 static GstPadNegotiateReturn    gst_queue_handle_negotiate_src  (GstPad *pad, GstCaps **caps, gpointer *data);
82 static GstPadNegotiateReturn    gst_queue_handle_negotiate_sink (GstPad *pad, GstCaps **caps, gpointer *data);
83 static void                     gst_queue_chain                 (GstPad *pad, GstBuffer *buf);
84 static GstBuffer *              gst_queue_get                   (GstPad *pad);
85 static GstBufferPool*           gst_queue_get_bufferpool        (GstPad *pad);
86         
87 static void                     gst_queue_locked_flush                  (GstQueue *queue);
88 static void                     gst_queue_flush                 (GstQueue *queue);
89
90 static GstElementStateReturn    gst_queue_change_state          (GstElement *element);
91
92   
93 #define GST_TYPE_QUEUE_LEAKY (queue_leaky_get_type())
94 static GType
95 queue_leaky_get_type(void) {
96   static GType queue_leaky_type = 0;
97   static GEnumValue queue_leaky[] = {
98     { GST_QUEUE_NO_LEAK,                "0", "Not Leaky" },
99     { GST_QUEUE_LEAK_UPSTREAM,          "1", "Leaky on Upstream" },
100     { GST_QUEUE_LEAK_DOWNSTREAM,        "2", "Leaky on Downstream" },
101     { 0, NULL, NULL },
102   };
103   if (!queue_leaky_type) {
104     queue_leaky_type = g_enum_register_static("GstQueueLeaky", queue_leaky);
105   }
106   return queue_leaky_type;
107 }
108
109 static GstElementClass *parent_class = NULL;
110 /* static guint gst_queue_signals[LAST_SIGNAL] = { 0 }; */
111
112 GType
113 gst_queue_get_type(void) 
114 {
115   static GType queue_type = 0;
116
117   if (!queue_type) {
118     static const GTypeInfo queue_info = {
119       sizeof(GstQueueClass),
120       NULL,
121       NULL,
122       (GClassInitFunc)gst_queue_class_init,
123       NULL,
124       NULL,
125       sizeof(GstQueue),
126       4,
127       (GInstanceInitFunc)gst_queue_init,
128       NULL
129     };
130     queue_type = g_type_register_static (GST_TYPE_ELEMENT, "GstQueue", &queue_info, 0);
131   }
132   return queue_type;
133 }
134
135 static void
136 gst_queue_class_init (GstQueueClass *klass)
137 {
138   GObjectClass *gobject_class;
139   GstElementClass *gstelement_class;
140
141   gobject_class = (GObjectClass*)klass;
142   gstelement_class = (GstElementClass*)klass;
143
144   parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
145
146   g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_LEAKY,
147     g_param_spec_enum ("leaky", "Leaky", "Where the queue leaks, if at all.",
148                        GST_TYPE_QUEUE_LEAKY, GST_QUEUE_NO_LEAK, G_PARAM_READWRITE));
149   g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_LEVEL,
150     g_param_spec_int ("level", "Level", "How many buffers are in the queue.",
151                       0, G_MAXINT, 0, G_PARAM_READABLE));
152   g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MAX_LEVEL,
153     g_param_spec_int ("max_level", "Maximum Level", "How many buffers the queue holds.",
154                       0, G_MAXINT, 100, G_PARAM_READWRITE));
155   g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MAY_DEADLOCK,
156     g_param_spec_boolean ("may_deadlock", "May Deadlock", "The queue may deadlock if it's full and not PLAYING",
157                       TRUE, G_PARAM_READWRITE));
158
159   gobject_class->dispose                = GST_DEBUG_FUNCPTR (gst_queue_dispose);
160   gobject_class->set_property           = GST_DEBUG_FUNCPTR (gst_queue_set_property);
161   gobject_class->get_property           = GST_DEBUG_FUNCPTR (gst_queue_get_property);
162
163   gstelement_class->change_state = GST_DEBUG_FUNCPTR(gst_queue_change_state);
164 }
165
166 static void
167 gst_queue_init (GstQueue *queue)
168 {
169   /* scheduling on this kind of element is, well, interesting */
170   GST_FLAG_SET (queue, GST_ELEMENT_DECOUPLED);
171   GST_FLAG_SET (queue, GST_ELEMENT_EVENT_AWARE);
172
173   queue->sinkpad = gst_pad_new ("sink", GST_PAD_SINK);
174   gst_pad_set_chain_function (queue->sinkpad, GST_DEBUG_FUNCPTR(gst_queue_chain));
175   gst_element_add_pad (GST_ELEMENT (queue), queue->sinkpad);
176   gst_pad_set_negotiate_function (queue->sinkpad, GST_DEBUG_FUNCPTR(gst_queue_handle_negotiate_sink));
177   gst_pad_set_bufferpool_function (queue->sinkpad, GST_DEBUG_FUNCPTR(gst_queue_get_bufferpool));
178
179   queue->srcpad = gst_pad_new ("src", GST_PAD_SRC);
180   gst_pad_set_get_function (queue->srcpad, GST_DEBUG_FUNCPTR(gst_queue_get));
181   gst_element_add_pad (GST_ELEMENT (queue), queue->srcpad);
182   gst_pad_set_negotiate_function (queue->srcpad, GST_DEBUG_FUNCPTR(gst_queue_handle_negotiate_src));
183
184   queue->leaky = GST_QUEUE_NO_LEAK;
185   queue->queue = NULL;
186   queue->level_buffers = 0;
187   queue->level_bytes = 0;
188   queue->level_time = 0LL;
189   queue->size_buffers = 100;            /* 100 buffers */
190   queue->size_bytes = 100 * 1024;       /* 100KB */
191   queue->size_time = 1000000000LL;      /* 1sec */
192   queue->may_deadlock = TRUE;
193
194   queue->qlock = g_mutex_new ();
195   queue->reader = FALSE;
196   queue->writer = FALSE;
197   queue->not_empty = g_cond_new ();
198   queue->not_full = g_cond_new ();
199   GST_DEBUG_ELEMENT (GST_CAT_THREAD, queue, "initialized queue's not_empty & not_full conditions\n");
200 }
201
202 static void
203 gst_queue_dispose (GObject *object)
204 {
205   GstQueue *queue = GST_QUEUE (object);
206
207   g_mutex_free (queue->qlock);
208   g_cond_free (queue->not_empty);
209   g_cond_free (queue->not_full);
210
211   G_OBJECT_CLASS (parent_class)->dispose (object);
212 }
213
214 static GstBufferPool*
215 gst_queue_get_bufferpool (GstPad *pad)
216 {
217   GstQueue *queue;
218
219   queue = GST_QUEUE (GST_OBJECT_PARENT (pad));
220
221   return gst_pad_get_bufferpool (queue->srcpad);
222 }
223
224 static GstPadNegotiateReturn
225 gst_queue_handle_negotiate_src (GstPad *pad, GstCaps **caps, gpointer *data)
226 {
227   GstQueue *queue;
228
229   queue = GST_QUEUE (GST_OBJECT_PARENT (pad));
230
231   return gst_pad_negotiate_proxy (pad, queue->sinkpad, caps);
232 }
233
234 static GstPadNegotiateReturn
235 gst_queue_handle_negotiate_sink (GstPad *pad, GstCaps **caps, gpointer *data)
236 {
237   GstQueue *queue;
238
239   queue = GST_QUEUE (GST_OBJECT_PARENT (pad));
240
241   return gst_pad_negotiate_proxy (pad, queue->srcpad, caps);
242 }
243
244 static void
245 gst_queue_cleanup_buffers (gpointer data, const gpointer user_data)
246 {
247   GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, user_data, "cleaning buffer %p\n", data);
248
249   if (GST_IS_BUFFER (data)) {
250     gst_buffer_unref (GST_BUFFER (data));
251   }
252   else {
253     gst_event_free (GST_EVENT (data));
254   }
255 }
256
257 static void
258 gst_queue_locked_flush (GstQueue *queue)
259 {
260   g_list_foreach (queue->queue, gst_queue_cleanup_buffers,
261                   (gpointer) queue);
262   g_list_free (queue->queue);
263
264   queue->queue = NULL;
265   queue->level_buffers = 0;
266   queue->timeval = NULL;
267 }
268
269 static void
270 gst_queue_flush (GstQueue *queue)
271 {
272   g_mutex_lock (queue->qlock);
273   gst_queue_locked_flush (queue);
274   g_mutex_unlock (queue->qlock);
275 }
276
277
278 static void
279 gst_queue_chain (GstPad *pad, GstBuffer *buf)
280 {
281   GstQueue *queue;
282   gboolean reader;
283
284   g_return_if_fail (pad != NULL);
285   g_return_if_fail (GST_IS_PAD (pad));
286   g_return_if_fail (buf != NULL);
287
288   queue = GST_QUEUE (GST_OBJECT_PARENT (pad));
289
290 restart:
291   /* we have to lock the queue since we span threads */
292   GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "locking t:%ld\n", pthread_self ());
293   g_mutex_lock (queue->qlock);
294   GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "locked t:%ld\n", pthread_self ());
295
296   if (GST_IS_EVENT (buf)) {
297     switch (GST_EVENT_TYPE (buf)) {
298       case GST_EVENT_FLUSH:
299         GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "FLUSH event, flushing queue\n");
300         gst_queue_locked_flush (queue);
301         break;
302       case GST_EVENT_EOS:
303         GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "eos in on %s %d\n", 
304                            GST_ELEMENT_NAME (queue), queue->level_buffers);
305         break;
306       default:
307         //gst_pad_event_default (pad, GST_EVENT (buf));
308         break;
309     }
310   }
311
312   GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "adding buffer %p of size %d\n",buf,GST_BUFFER_SIZE(buf));
313
314   if (queue->level_buffers == queue->size_buffers) {
315     /* if this is a leaky queue... */
316     if (queue->leaky) {
317       /* FIXME don't want to leak events! */
318       /* if we leak on the upstream side, drop the current buffer */
319       if (queue->leaky == GST_QUEUE_LEAK_UPSTREAM) {
320         GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "queue is full, leaking buffer on upstream end\n");
321         if (GST_IS_EVENT (buf))
322           fprintf(stderr, "Error: queue [%s] leaked an event, type:%d\n",
323               GST_ELEMENT_NAME(GST_ELEMENT(queue)),
324               GST_EVENT_TYPE(GST_EVENT(buf)));
325           GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "queue is full, leaking buffer on upstream end\n");
326         gst_buffer_unref(buf);
327         /* now we have to clean up and exit right away */
328         g_mutex_unlock (queue->qlock);
329         return;
330       }
331       /* otherwise we have to push a buffer off the other end */
332       else {
333         GList *front;
334         GstBuffer *leakbuf;
335         GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "queue is full, leaking buffer on downstream end\n");
336         front = queue->queue;
337         leakbuf = (GstBuffer *)(front->data);
338         if (GST_IS_EVENT (leakbuf))
339           fprintf(stderr, "Error: queue [%s] leaked an event, type:%d\n",
340               GST_ELEMENT_NAME(GST_ELEMENT(queue)),
341               GST_EVENT_TYPE(GST_EVENT(leakbuf)));
342         queue->level_buffers--;
343         queue->level_bytes -= GST_BUFFER_SIZE(leakbuf);
344         gst_buffer_unref(leakbuf);
345         queue->queue = g_list_remove_link (queue->queue, front);
346         g_list_free (front);
347       }
348     }
349
350     GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "pre full wait, level:%d/%d\n",
351         queue->level_buffers, queue->size_buffers);
352     while (queue->level_buffers == queue->size_buffers) {
353       /* if there's a pending state change for this queue or its manager, switch */
354       /* back to iterator so bottom half of state change executes */
355       while (GST_STATE_PENDING (queue) != GST_STATE_VOID_PENDING) {
356         GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "interrupted!!\n");
357         g_mutex_unlock (queue->qlock);
358         /* FIXME: gst_element_interrupt doesn't return anything
359         if (gst_element_interrupt (GST_ELEMENT (queue)))
360           return;
361         */
362         gst_element_interrupt (GST_ELEMENT (queue));
363         goto restart;
364       }
365       if (GST_STATE (queue) != GST_STATE_PLAYING) {
366         /* this means the other end is shut down */
367         /* try to signal to resolve the error */
368         if (!queue->may_deadlock) {
369           if (GST_IS_BUFFER (buf)) gst_buffer_unref (buf);
370           else gst_event_free (GST_EVENT (buf));
371           g_mutex_unlock (queue->qlock);
372           gst_element_error (GST_ELEMENT (queue), "deadlock found, source pad elements are shut down");
373           return;
374         }
375         else {
376           gst_element_info (GST_ELEMENT (queue), "waiting for the app to restart source pad elements");
377         }
378       }
379
380       GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "waiting for not_full, level:%d/%d\n", queue->level_buffers, queue->size_buffers);
381       if (queue->writer)
382         GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "WARNING: multiple writers on queue!\n");
383       queue->writer = TRUE;
384       g_cond_wait (queue->not_full, queue->qlock);
385       queue->writer = FALSE;
386       GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "got not_full signal\n");
387     }
388     GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "post full wait, level:%d/%d\n",
389         queue->level_buffers, queue->size_buffers);
390   }
391
392   /* put the buffer on the tail of the list */
393   queue->queue = g_list_append (queue->queue, buf);
394   queue->level_buffers++;
395   queue->level_bytes += GST_BUFFER_SIZE(buf);
396
397   GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "(%s:%s)+ level:%d/%d\n",
398       GST_DEBUG_PAD_NAME(pad),
399       queue->level_buffers, queue->size_buffers);
400
401   /* this assertion _has_ to hold */
402   /* g_assert (g_list_length (queue->queue) == queue->level_buffers); */
403
404   /* reader waiting on an empty queue */
405   reader = queue->reader;
406
407   g_mutex_unlock (queue->qlock);
408
409   if (reader)
410   {
411     GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "signalling not_empty\n");
412     g_cond_signal (queue->not_empty);
413   }
414 }
415
416 static GstBuffer *
417 gst_queue_get (GstPad *pad)
418 {
419   GstQueue *queue;
420   GstBuffer *buf = NULL;
421   GList *front;
422   gboolean writer;
423
424   g_assert(pad != NULL);
425   g_assert(GST_IS_PAD(pad));
426   g_return_val_if_fail (pad != NULL, NULL);
427   g_return_val_if_fail (GST_IS_PAD (pad), NULL);
428
429   queue = GST_QUEUE (GST_OBJECT_PARENT (pad));
430
431 restart:
432   /* have to lock for thread-safety */
433   GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "locking t:%ld\n", pthread_self ());
434   g_mutex_lock (queue->qlock);
435   GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "locked t:%ld %p\n", pthread_self (), queue->not_empty);
436
437   GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "pre empty wait, level:%d/%d\n", queue->level_buffers, queue->size_buffers);
438   while (queue->level_buffers == 0) {
439     /* if there's a pending state change for this queue or its manager, switch
440      * back to iterator so bottom half of state change executes
441      */ 
442     while (GST_STATE_PENDING (queue) != GST_STATE_VOID_PENDING) {
443       GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "interrupted!!\n");
444       g_mutex_unlock (queue->qlock);
445         /* FIXME: gst_element_interrupt doesn't return anything
446         if (gst_element_interrupt (GST_ELEMENT (queue)))
447           return;
448         */
449       gst_element_interrupt (GST_ELEMENT (queue));
450       goto restart;
451     }
452     if (GST_STATE (queue) != GST_STATE_PLAYING) {
453       /* this means the other end is shut down */
454       if (!queue->may_deadlock) {
455         g_mutex_unlock (queue->qlock);
456         gst_element_error (GST_ELEMENT (queue), "deadlock found, sink pad elements are shut down");
457         goto restart;
458       }
459       else {
460         gst_element_info (GST_ELEMENT (queue), "waiting for the app to restart sink pad elements");
461       }
462     }
463
464     GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "waiting for not_empty, level:%d/%d\n", queue->level_buffers, queue->size_buffers);
465     if (queue->reader)
466       GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "WARNING: multiple readers on queue!\n");
467     queue->reader = TRUE;
468     g_cond_wait (queue->not_empty, queue->qlock);
469     queue->reader = FALSE;
470     GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "got not_empty signal\n");
471   }
472   GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "post empty wait, level:%d/%d\n", queue->level_buffers, queue->size_buffers);
473
474   front = queue->queue;
475   buf = (GstBuffer *)(front->data);
476   GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "retrieved buffer %p from queue\n", buf);
477   queue->queue = g_list_remove_link (queue->queue, front);
478   g_list_free (front);
479
480   queue->level_buffers--;
481   queue->level_bytes -= GST_BUFFER_SIZE(buf);
482
483   GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "(%s:%s)- level:%d/%d\n",
484       GST_DEBUG_PAD_NAME(pad),
485       queue->level_buffers, queue->size_buffers);
486
487   /* this assertion _has_ to hold */
488   /* g_assert (g_list_length (queue->queue) == queue->level_buffers); */
489
490   /* writer waiting on a full queue */
491   writer = queue->writer;
492
493   g_mutex_unlock (queue->qlock);
494
495   if (writer)
496   {
497     GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "signalling not_full\n");
498     g_cond_signal (queue->not_full);
499   }
500
501   /* FIXME where should this be? locked? */
502   if (GST_IS_EVENT(buf)) {
503     GstEvent *event = GST_EVENT(buf);
504     switch (GST_EVENT_TYPE(event)) {
505       case GST_EVENT_EOS:
506         GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "queue \"%s\" eos\n", GST_ELEMENT_NAME (queue));
507         gst_element_set_eos (GST_ELEMENT (queue));
508         break;
509       default:
510         break;
511     }
512   }
513
514   return buf;
515 }
516
517 static GstElementStateReturn
518 gst_queue_change_state (GstElement *element)
519 {
520   GstQueue *queue;
521   GstElementStateReturn ret;
522   GstElementState new_state;
523   g_return_val_if_fail (GST_IS_QUEUE (element), GST_STATE_FAILURE);
524
525   queue = GST_QUEUE (element);
526
527   GST_DEBUG_ENTER("('%s')", GST_ELEMENT_NAME (element));
528
529   /* lock the queue so another thread (not in sync with this thread's state)
530    * can't call this queue's _get (or whatever)
531    */
532   g_mutex_lock (queue->qlock);
533
534   new_state = GST_STATE_PENDING (element);
535
536   if (new_state == GST_STATE_PAUSED) {
537     //g_cond_signal (queue->not_full);
538     //g_cond_signal (queue->not_empty);
539   }
540   else if (new_state == GST_STATE_READY) {
541     gst_queue_locked_flush (queue);
542   }
543   else if (new_state == GST_STATE_PLAYING) {
544     if (!GST_PAD_CONNECTED (queue->sinkpad)) {
545       /* FIXME can this be? */
546       if (queue->reader)
547         g_cond_signal (queue->not_empty);
548       g_mutex_unlock (queue->qlock);
549
550       return GST_STATE_FAILURE;
551     }
552   }
553
554   ret = GST_ELEMENT_CLASS (parent_class)->change_state (element);
555   g_mutex_unlock (queue->qlock);
556
557   GST_DEBUG_LEAVE("('%s')", GST_ELEMENT_NAME (element));
558   return ret;
559 }
560
561
562 static void
563 gst_queue_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
564 {
565   GstQueue *queue;
566
567   /* it's not null if we got it, but it might not be ours */
568   g_return_if_fail (GST_IS_QUEUE (object));
569
570   queue = GST_QUEUE (object);
571
572   switch (prop_id) {
573     case ARG_LEAKY:
574       queue->leaky = g_value_get_int (value);
575       break;
576     case ARG_MAX_LEVEL:
577       queue->size_buffers = g_value_get_int (value);
578       break;
579     case ARG_MAY_DEADLOCK:
580       queue->may_deadlock = g_value_get_boolean (value);
581       break;
582     default:
583       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
584       break;
585   }
586 }
587
588 static void
589 gst_queue_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
590 {
591   GstQueue *queue;
592
593   /* it's not null if we got it, but it might not be ours */
594   g_return_if_fail (GST_IS_QUEUE (object));
595
596   queue = GST_QUEUE (object);
597
598   switch (prop_id) {
599     case ARG_LEAKY:
600       g_value_set_int (value, queue->leaky);
601       break;
602     case ARG_LEVEL:
603       g_value_set_int (value, queue->level_buffers);
604       break;
605     case ARG_MAX_LEVEL:
606       g_value_set_int (value, queue->size_buffers);
607       break;
608     case ARG_MAY_DEADLOCK:
609       g_value_set_boolean (value, queue->may_deadlock);
610       break;
611     default:
612       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
613       break;
614   }
615 }