pool: debug the config
[platform/upstream/gstreamer.git] / gst / gstbufferpool.c
1 /* GStreamer
2  * Copyright (C) 2010 Wim Taymans <wim.taymans@gmail.com>
3  *
4  * gstbufferpool.c: GstBufferPool baseclass
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21
22 /**
23  * SECTION:gstbufferpool
24  * @short_description: Pool for buffers
25  * @see_also: #GstBuffer
26  *
27  */
28
29 #include "gst_private.h"
30
31 #include <errno.h>
32 #ifdef HAVE_UNISTD_H
33 #  include <unistd.h>
34 #endif
35 #include <sys/types.h>
36
37 #include "gstinfo.h"
38 #include "gstquark.h"
39
40 #include "gstbufferpool.h"
41
42 GST_DEBUG_CATEGORY_STATIC (gst_buffer_pool_debug);
43 #define GST_CAT_DEFAULT gst_buffer_pool_debug
44
45 #define GST_BUFFER_POOL_GET_PRIVATE(obj)  \
46    (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_BUFFER_POOL, GstBufferPoolPrivate))
47
48 #define GST_BUFFER_POOL_LOCK(pool)   (g_static_rec_mutex_lock(&pool->priv->rec_lock))
49 #define GST_BUFFER_POOL_UNLOCK(pool) (g_static_rec_mutex_unlock(&pool->priv->rec_lock))
50
51 struct _GstBufferPoolPrivate
52 {
53   GStaticRecMutex rec_lock;
54   guint size;
55   guint min_buffers;
56   guint max_buffers;
57   guint prefix;
58   guint postfix;
59   guint align;
60 };
61
62 enum
63 {
64   /* add more above */
65   LAST_SIGNAL
66 };
67
68 static void gst_buffer_pool_finalize (GObject * object);
69
70 G_DEFINE_TYPE (GstBufferPool, gst_buffer_pool, GST_TYPE_OBJECT);
71
72 static gboolean default_start (GstBufferPool * pool);
73 static gboolean default_stop (GstBufferPool * pool);
74 static gboolean default_set_config (GstBufferPool * pool,
75     GstStructure * config);
76 static GstFlowReturn default_alloc_buffer (GstBufferPool * pool,
77     GstBuffer ** buffer, GstBufferPoolParams * params);
78 static GstFlowReturn default_acquire_buffer (GstBufferPool * pool,
79     GstBuffer ** buffer, GstBufferPoolParams * params);
80 static void default_free_buffer (GstBufferPool * pool, GstBuffer * buffer);
81 static void default_release_buffer (GstBufferPool * pool, GstBuffer * buffer);
82
83 static void
84 gst_buffer_pool_class_init (GstBufferPoolClass * klass)
85 {
86   GObjectClass *gobject_class = (GObjectClass *) klass;
87
88   g_type_class_add_private (klass, sizeof (GstBufferPoolPrivate));
89
90   gobject_class->finalize = gst_buffer_pool_finalize;
91
92   klass->start = default_start;
93   klass->stop = default_stop;
94   klass->set_config = default_set_config;
95   klass->acquire_buffer = default_acquire_buffer;
96   klass->alloc_buffer = default_alloc_buffer;
97   klass->release_buffer = default_release_buffer;
98   klass->free_buffer = default_free_buffer;
99
100   GST_DEBUG_CATEGORY_INIT (gst_buffer_pool_debug, "bufferpool", 0,
101       "bufferpool debug");
102 }
103
104 static void
105 gst_buffer_pool_init (GstBufferPool * pool)
106 {
107   pool->priv = GST_BUFFER_POOL_GET_PRIVATE (pool);
108
109   g_static_rec_mutex_init (&pool->priv->rec_lock);
110
111   pool->poll = gst_poll_new_timer ();
112   pool->queue = gst_atomic_queue_new (10);
113   pool->flushing = TRUE;
114   pool->active = FALSE;
115   pool->configured = FALSE;
116   pool->started = FALSE;
117   pool->config = gst_structure_id_empty_new (GST_QUARK (BUFFER_POOL_CONFIG));
118   gst_buffer_pool_config_set (pool->config, NULL, 0, 0, 0, 0, 0, 1);
119
120   GST_DEBUG_OBJECT (pool, "created");
121 }
122
123 static void
124 gst_buffer_pool_finalize (GObject * object)
125 {
126   GstBufferPool *pool;
127
128   pool = GST_BUFFER_POOL_CAST (object);
129
130   GST_DEBUG_OBJECT (pool, "finalize");
131
132   gst_buffer_pool_set_active (pool, FALSE);
133   gst_atomic_queue_unref (pool->queue);
134   gst_poll_free (pool->poll);
135   gst_structure_free (pool->config);
136   g_static_rec_mutex_free (&pool->priv->rec_lock);
137
138   G_OBJECT_CLASS (gst_buffer_pool_parent_class)->finalize (object);
139 }
140
141 /**
142  * gst_buffer_pool_new:
143  *
144  * Creates a new #GstBufferPool instance.
145  *
146  * Returns: a new #GstBufferPool instance
147  */
148 GstBufferPool *
149 gst_buffer_pool_new (void)
150 {
151   GstBufferPool *result;
152
153   result = g_object_newv (GST_TYPE_BUFFER_POOL, 0, NULL);
154   GST_DEBUG_OBJECT (result, "created new buffer pool");
155
156   return result;
157 }
158
159 static GstFlowReturn
160 default_alloc_buffer (GstBufferPool * pool, GstBuffer ** buffer,
161     GstBufferPoolParams * params)
162 {
163   guint align;
164   GstBufferPoolPrivate *priv = pool->priv;
165
166   *buffer = gst_buffer_new ();
167
168   align = priv->align - 1;
169
170   gst_buffer_take_memory (*buffer, gst_memory_new_alloc (priv->size, align));
171
172   return GST_FLOW_OK;
173 }
174
175 /* the default implementation for preallocating the buffers
176  * in the pool */
177 static gboolean
178 default_start (GstBufferPool * pool)
179 {
180   guint i;
181   GstBufferPoolPrivate *priv = pool->priv;
182   GstBufferPoolClass *pclass;
183
184   pclass = GST_BUFFER_POOL_GET_CLASS (pool);
185
186   /* no alloc function, error */
187   if (G_UNLIKELY (pclass->alloc_buffer == NULL))
188     goto no_alloc;
189
190   /* we need to prealloc buffers */
191   for (i = 0; i < priv->min_buffers; i++) {
192     GstBuffer *buffer;
193
194     if (pclass->alloc_buffer (pool, &buffer, NULL) != GST_FLOW_OK)
195       goto alloc_failed;
196
197     GST_LOG_OBJECT (pool, "prealloced buffer %d: %p", i, buffer);
198     /* store in the queue */
199     gst_atomic_queue_push (pool->queue, buffer);
200     gst_poll_write_control (pool->poll);
201   }
202   return TRUE;
203
204   /* ERRORS */
205 no_alloc:
206   {
207     GST_WARNING_OBJECT (pool, "no alloc function");
208     return FALSE;
209   }
210 alloc_failed:
211   {
212     GST_WARNING_OBJECT (pool, "alloc function failed");
213     return FALSE;
214   }
215 }
216
217 /* must be called with the lock */
218 static gboolean
219 do_start (GstBufferPool * pool)
220 {
221   if (!pool->started) {
222     GstBufferPoolClass *pclass;
223
224     pclass = GST_BUFFER_POOL_GET_CLASS (pool);
225
226     GST_LOG_OBJECT (pool, "starting");
227     /* start the pool, subclasses should allocate buffers and put them
228      * in the queue */
229     if (G_LIKELY (pclass->start)) {
230       if (!pclass->start (pool))
231         return FALSE;
232     }
233     pool->started = TRUE;
234   }
235   return TRUE;
236 }
237
238
239 static void
240 default_free_buffer (GstBufferPool * pool, GstBuffer * buffer)
241 {
242   gst_buffer_unref (buffer);
243 }
244
245 /* must be called with the lock */
246 static gboolean
247 default_stop (GstBufferPool * pool)
248 {
249   GstBuffer *buffer;
250   GstBufferPoolClass *pclass;
251
252   pclass = GST_BUFFER_POOL_GET_CLASS (pool);
253
254   /* clear the pool */
255   while ((buffer = gst_atomic_queue_pop (pool->queue))) {
256     gst_poll_read_control (pool->poll);
257
258     if (G_LIKELY (pclass->free_buffer))
259       pclass->free_buffer (pool, buffer);
260   }
261   return TRUE;
262 }
263
264 /* must be called with the lock */
265 static gboolean
266 do_stop (GstBufferPool * pool)
267 {
268   if (pool->started) {
269     GstBufferPoolClass *pclass;
270
271     pclass = GST_BUFFER_POOL_GET_CLASS (pool);
272
273     GST_LOG_OBJECT (pool, "stopping");
274     if (G_LIKELY (pclass->stop)) {
275       if (!pclass->stop (pool))
276         return FALSE;
277     }
278     pool->started = FALSE;
279   }
280   return TRUE;
281 }
282
283 /**
284  * gst_buffer_pool_set_active:
285  * @pool: a #GstBufferPool
286  * @active: the new active state
287  *
288  * Control the active state of @pool. When the pool is active, new calls to
289  * gst_buffer_pool_acquire_buffer() will return with GST_FLOW_WRONG_STATE.
290  *
291  * Returns: %FALSE when the pool was not configured or when preallocation of the
292  * buffers failed.
293  */
294 gboolean
295 gst_buffer_pool_set_active (GstBufferPool * pool, gboolean active)
296 {
297   gboolean res = TRUE;
298
299   g_return_val_if_fail (GST_IS_BUFFER_POOL (pool), FALSE);
300
301   GST_LOG_OBJECT (pool, "active %d", active);
302
303   GST_BUFFER_POOL_LOCK (pool);
304   /* just return if we are already in the right state */
305   if (pool->active == active)
306     goto was_ok;
307
308   /* we need to be configured */
309   if (!pool->configured)
310     goto not_configured;
311
312   if (active) {
313     if (!do_start (pool))
314       goto start_failed;
315
316     /* unset the flushing state now */
317     gst_poll_read_control (pool->poll);
318     g_atomic_int_set (&pool->flushing, FALSE);
319   } else {
320     /* set to flushing first */
321     g_atomic_int_set (&pool->flushing, TRUE);
322     gst_poll_write_control (pool->poll);
323
324     /* when all buffers are in the pool, free them. Else they will be
325      * freed when they are released */
326     if (g_atomic_int_get (&pool->outstanding) == 0) {
327       if (!do_stop (pool))
328         goto stop_failed;
329     }
330   }
331   pool->active = active;
332   GST_BUFFER_POOL_UNLOCK (pool);
333
334   return res;
335
336 was_ok:
337   {
338     GST_DEBUG_OBJECT (pool, "pool was in the right state");
339     GST_BUFFER_POOL_UNLOCK (pool);
340     return TRUE;
341   }
342 not_configured:
343   {
344     GST_ERROR_OBJECT (pool, "pool was not configured");
345     GST_BUFFER_POOL_UNLOCK (pool);
346     return FALSE;
347   }
348 start_failed:
349   {
350     GST_ERROR_OBJECT (pool, "start failed");
351     GST_BUFFER_POOL_UNLOCK (pool);
352     return FALSE;
353   }
354 stop_failed:
355   {
356     GST_WARNING_OBJECT (pool, "stop failed");
357     GST_BUFFER_POOL_UNLOCK (pool);
358     return FALSE;
359   }
360 }
361
362 static gboolean
363 default_set_config (GstBufferPool * pool, GstStructure * config)
364 {
365   GstBufferPoolPrivate *priv = pool->priv;
366   const GstCaps *caps;
367   guint size, min_buffers, max_buffers;
368   guint prefix, postfix, align;
369
370   /* parse the config and keep around */
371   if (!gst_buffer_pool_config_get (config, &caps, &size, &min_buffers,
372           &max_buffers, &prefix, &postfix, &align))
373     goto wrong_config;
374
375   GST_DEBUG_OBJECT (pool, "config %" GST_PTR_FORMAT, config);
376
377   priv->size = size;
378   priv->min_buffers = min_buffers;
379   priv->max_buffers = max_buffers;
380   priv->prefix = prefix;
381   priv->postfix = postfix;
382   priv->align = align;
383
384   return TRUE;
385
386 wrong_config:
387   {
388     GST_WARNING_OBJECT (pool, "invalid config %" GST_PTR_FORMAT, config);
389     return FALSE;
390   }
391 }
392
393 /**
394  * gst_buffer_pool_set_config:
395  * @pool: a #GstBufferPool
396  * @config: a #GstStructure
397  *
398  * Set the configuration of the pool. The pool must be inactive and all buffers
399  * allocated form this pool must be returned or else this function will do
400  * nothing and return FALSE.
401  *
402  * @condfig is a #GstStructure that contains the configuration parameters for
403  * the pool. A default and mandatory set of parameters can be configured with
404  * gst_buffer_pool_config_set(). This function takes ownership of @config.
405  *
406  * Returns: TRUE when the configuration could be set.
407  */
408 gboolean
409 gst_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
410 {
411   gboolean result;
412   GstBufferPoolClass *pclass;
413
414   g_return_val_if_fail (GST_IS_BUFFER_POOL (pool), FALSE);
415   g_return_val_if_fail (config != NULL, FALSE);
416
417   GST_BUFFER_POOL_LOCK (pool);
418   /* can't change the settings when active */
419   if (pool->active)
420     goto was_active;
421
422   /* we can't change when outstanding buffers */
423   if (g_atomic_int_get (&pool->outstanding) != 0)
424     goto have_outstanding;
425
426   pclass = GST_BUFFER_POOL_GET_CLASS (pool);
427
428   /* set the new config */
429   if (G_LIKELY (pclass->set_config))
430     result = pclass->set_config (pool, config);
431   else
432     result = FALSE;
433
434   if (result) {
435     if (pool->config)
436       gst_structure_free (pool->config);
437     pool->config = config;
438
439     /* now we are configured */
440     pool->configured = TRUE;
441   }
442   GST_BUFFER_POOL_UNLOCK (pool);
443
444   return result;
445
446   /* ERRORS */
447 was_active:
448   {
449     GST_WARNING_OBJECT (pool, "can't change config, we are active");
450     GST_BUFFER_POOL_UNLOCK (pool);
451     return FALSE;
452   }
453 have_outstanding:
454   {
455     GST_WARNING_OBJECT (pool, "can't change config, have outstanding buffers");
456     GST_BUFFER_POOL_UNLOCK (pool);
457     return FALSE;
458   }
459 }
460
461 /**
462  * gst_buffer_pool_get_config:
463  * @pool: a #GstBufferPool
464  *
465  * Get a copy of the current configuration of the pool. This configuration
466  * can either be modified and used for the gst_buffer_pool_set_config() call
467  * or it must be freed after usage.
468  *
469  * Returns: a copy of the current configuration of @pool. use
470  * gst_structure_free() after usage or gst_buffer_pool_set_config().
471  */
472 GstStructure *
473 gst_buffer_pool_get_config (GstBufferPool * pool)
474 {
475   GstStructure *result;
476
477   g_return_val_if_fail (GST_IS_BUFFER_POOL (pool), NULL);
478
479   GST_BUFFER_POOL_UNLOCK (pool);
480   result = gst_structure_copy (pool->config);
481   GST_BUFFER_POOL_UNLOCK (pool);
482
483   return result;
484 }
485
486 /**
487  * gst_buffer_pool_config_set:
488  * @config: a #GstBufferPool
489  * @caps: caps for the buffers
490  * @size: the size of each buffer, not including pre and post fix
491  * @min_buffers: the minimum amount of buffers to allocate.
492  * @max_buffers: the maximum amount of buffers to allocate or 0 for unlimited.
493  * @prefix: prefix each buffer with this many bytes
494  * @postfix: postfix each buffer with this many bytes
495  * @align: alignment of the buffer data.
496  *
497  * Configure @config with the given parameters.
498  */
499 void
500 gst_buffer_pool_config_set (GstStructure * config, const GstCaps * caps,
501     guint size, guint min_buffers, guint max_buffers, guint prefix,
502     guint postfix, guint align)
503 {
504   g_return_if_fail (config != NULL);
505
506   gst_structure_id_set (config,
507       GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
508       GST_QUARK (SIZE), G_TYPE_UINT, size,
509       GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, min_buffers,
510       GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, max_buffers,
511       GST_QUARK (PREFIX), G_TYPE_UINT, prefix,
512       GST_QUARK (POSTFIX), G_TYPE_UINT, postfix,
513       GST_QUARK (ALIGN), G_TYPE_UINT, align, NULL);
514 }
515
516 /**
517  * gst_buffer_pool_config_get:
518  * @config: a #GstBufferPool
519  * @caps: the caps of buffers
520  * @size: the size of each buffer, not including pre and post fix
521  * @min_buffers: the minimum amount of buffers to allocate.
522  * @max_buffers: the maximum amount of buffers to allocate or 0 for unlimited.
523  * @prefix: prefix each buffer with this many bytes
524  * @postfix: postfix each buffer with this many bytes
525  * @align: alignment of the buffer data.
526  *
527  * Get the configuration values from @config.
528  */
529 gboolean
530 gst_buffer_pool_config_get (GstStructure * config, const GstCaps ** caps,
531     guint * size, guint * min_buffers, guint * max_buffers, guint * prefix,
532     guint * postfix, guint * align)
533 {
534   g_return_val_if_fail (config != NULL, FALSE);
535
536   return gst_structure_id_get (config,
537       GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
538       GST_QUARK (SIZE), G_TYPE_UINT, size,
539       GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, min_buffers,
540       GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, max_buffers,
541       GST_QUARK (PREFIX), G_TYPE_UINT, prefix,
542       GST_QUARK (POSTFIX), G_TYPE_UINT, postfix,
543       GST_QUARK (ALIGN), G_TYPE_UINT, align, NULL);
544 }
545
546 static GstFlowReturn
547 default_acquire_buffer (GstBufferPool * pool, GstBuffer ** buffer,
548     GstBufferPoolParams * params)
549 {
550   GstFlowReturn result;
551   GstBufferPoolClass *pclass;
552   GstBufferPoolPrivate *priv = pool->priv;
553
554   pclass = GST_BUFFER_POOL_GET_CLASS (pool);
555
556   while (TRUE) {
557     if (G_UNLIKELY (g_atomic_int_get (&pool->flushing)))
558       goto flushing;
559
560     /* try to get a buffer from the queue */
561     *buffer = gst_atomic_queue_pop (pool->queue);
562     if (G_LIKELY (*buffer)) {
563       gst_poll_read_control (pool->poll);
564       result = GST_FLOW_OK;
565       GST_LOG_OBJECT (pool, "acquired buffer %p", *buffer);
566       break;
567     }
568
569     /* no buffer */
570     if (priv->max_buffers == 0) {
571       /* no max_buffers, we allocate some more */
572       if (G_LIKELY (pclass->alloc_buffer)) {
573         result = pclass->alloc_buffer (pool, buffer, params);
574       } else
575         result = GST_FLOW_NOT_SUPPORTED;
576       GST_LOG_OBJECT (pool, "alloc buffer %p", *buffer);
577       break;
578     }
579
580     /* check if we need to wait */
581     if (params && !(params->flags & GST_BUFFER_POOL_FLAG_WAIT)) {
582       GST_LOG_OBJECT (pool, "no more buffers");
583       result = GST_FLOW_UNEXPECTED;
584       break;
585     }
586
587     /* now wait */
588     GST_LOG_OBJECT (pool, "waiting for free buffers");
589     gst_poll_wait (pool->poll, GST_CLOCK_TIME_NONE);
590   }
591
592   return result;
593
594   /* ERRORS */
595 flushing:
596   {
597     GST_DEBUG_OBJECT (pool, "we are flushing");
598     return GST_FLOW_WRONG_STATE;
599   }
600 }
601
602 static inline void
603 dec_outstanding (GstBufferPool * pool)
604 {
605   if (g_atomic_int_dec_and_test (&pool->outstanding)) {
606     /* all buffers are returned to the pool, see if we need to free them */
607     if (g_atomic_int_get (&pool->flushing)) {
608       /* take the lock so that set_active is not run concurrently */
609       GST_BUFFER_POOL_LOCK (pool);
610       /* recheck the flushing state in the lock, the pool could have been
611        * set to active again */
612       if (g_atomic_int_get (&pool->flushing))
613         do_stop (pool);
614
615       GST_BUFFER_POOL_UNLOCK (pool);
616     }
617   }
618 }
619
620 /**
621  * gst_buffer_pool_acquire_buffer:
622  * @pool: a #GstBufferPool
623  * @buffer: a location for a #GstBuffer
624  * @params: parameters.
625  *
626  * Acquire a buffer from @pool. @buffer should point to a memory location that
627  * can hold a pointer to the new buffer.
628  *
629  * @params can be NULL or contain optional parameters to influence the allocation.
630  *
631  * Returns: a #GstFlowReturn such as GST_FLOW_WRONG_STATE when the pool is
632  * inactive.
633  */
634 GstFlowReturn
635 gst_buffer_pool_acquire_buffer (GstBufferPool * pool, GstBuffer ** buffer,
636     GstBufferPoolParams * params)
637 {
638   GstBufferPoolClass *pclass;
639   GstFlowReturn result;
640
641   g_return_val_if_fail (GST_IS_BUFFER_POOL (pool), GST_FLOW_ERROR);
642   g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
643
644   pclass = GST_BUFFER_POOL_GET_CLASS (pool);
645
646   /* assume we'll have one more outstanding buffer we need to do that so
647    * that concurrent set_active doesn't clear the buffers */
648   g_atomic_int_inc (&pool->outstanding);
649
650   if (G_LIKELY (pclass->acquire_buffer))
651     result = pclass->acquire_buffer (pool, buffer, params);
652   else
653     result = GST_FLOW_NOT_SUPPORTED;
654
655   if (G_LIKELY (result == GST_FLOW_OK)) {
656     /* all buffers from the pool point to the pool and have the refcount of the
657      * pool incremented */
658     (*buffer)->pool = gst_object_ref (pool);
659   } else {
660     dec_outstanding (pool);
661   }
662
663   return result;
664 }
665
666 static void
667 default_release_buffer (GstBufferPool * pool, GstBuffer * buffer)
668 {
669   /* keep it around in our queue */
670   GST_LOG_OBJECT (pool, "released buffer %p", buffer);
671   gst_atomic_queue_push (pool->queue, buffer);
672   gst_poll_write_control (pool->poll);
673 }
674
675 /**
676  * gst_buffer_pool_release_buffer:
677  * @pool: a #GstBufferPool
678  * @buffer: a #GstBuffer
679  *
680  * Release @buffer to @pool. @buffer should have previously been allocated from
681  * @pool with gst_buffer_pool_acquire_buffer().
682  *
683  * This function is usually called automatically when the last ref on @buffer
684  * disappears.
685  */
686 void
687 gst_buffer_pool_release_buffer (GstBufferPool * pool, GstBuffer * buffer)
688 {
689   GstBufferPoolClass *pclass;
690
691   g_return_if_fail (GST_IS_BUFFER_POOL (pool));
692   g_return_if_fail (buffer != NULL);
693
694   /* check that the buffer is ours, all buffers returned to the pool have the
695    * pool member set to NULL and the pool refcount decreased */
696   if (!g_atomic_pointer_compare_and_exchange ((gpointer *) & buffer->pool,
697           pool, NULL))
698     return;
699
700   pclass = GST_BUFFER_POOL_GET_CLASS (pool);
701
702   if (G_LIKELY (pclass->release_buffer))
703     pclass->release_buffer (pool, buffer);
704
705   dec_outstanding (pool);
706
707   /* decrease the refcount that the buffer had to us */
708   gst_object_unref (pool);
709 }