Merge branch 'master' into 0.11
[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_allocator_alloc (NULL, priv->size,
171           align));
172
173   return GST_FLOW_OK;
174 }
175
176 /* the default implementation for preallocating the buffers
177  * in the pool */
178 static gboolean
179 default_start (GstBufferPool * pool)
180 {
181   guint i;
182   GstBufferPoolPrivate *priv = pool->priv;
183   GstBufferPoolClass *pclass;
184
185   pclass = GST_BUFFER_POOL_GET_CLASS (pool);
186
187   /* no alloc function, error */
188   if (G_UNLIKELY (pclass->alloc_buffer == NULL))
189     goto no_alloc;
190
191   /* we need to prealloc buffers */
192   for (i = 0; i < priv->min_buffers; i++) {
193     GstBuffer *buffer;
194
195     if (pclass->alloc_buffer (pool, &buffer, NULL) != GST_FLOW_OK)
196       goto alloc_failed;
197
198     GST_LOG_OBJECT (pool, "prealloced buffer %d: %p", i, buffer);
199     /* store in the queue */
200     gst_atomic_queue_push (pool->queue, buffer);
201     gst_poll_write_control (pool->poll);
202   }
203   return TRUE;
204
205   /* ERRORS */
206 no_alloc:
207   {
208     GST_WARNING_OBJECT (pool, "no alloc function");
209     return FALSE;
210   }
211 alloc_failed:
212   {
213     GST_WARNING_OBJECT (pool, "alloc function failed");
214     return FALSE;
215   }
216 }
217
218 /* must be called with the lock */
219 static gboolean
220 do_start (GstBufferPool * pool)
221 {
222   if (!pool->started) {
223     GstBufferPoolClass *pclass;
224
225     pclass = GST_BUFFER_POOL_GET_CLASS (pool);
226
227     GST_LOG_OBJECT (pool, "starting");
228     /* start the pool, subclasses should allocate buffers and put them
229      * in the queue */
230     if (G_LIKELY (pclass->start)) {
231       if (!pclass->start (pool))
232         return FALSE;
233     }
234     pool->started = TRUE;
235   }
236   return TRUE;
237 }
238
239
240 static void
241 default_free_buffer (GstBufferPool * pool, GstBuffer * buffer)
242 {
243   gst_buffer_unref (buffer);
244 }
245
246 /* must be called with the lock */
247 static gboolean
248 default_stop (GstBufferPool * pool)
249 {
250   GstBuffer *buffer;
251   GstBufferPoolClass *pclass;
252
253   pclass = GST_BUFFER_POOL_GET_CLASS (pool);
254
255   /* clear the pool */
256   while ((buffer = gst_atomic_queue_pop (pool->queue))) {
257     gst_poll_read_control (pool->poll);
258
259     if (G_LIKELY (pclass->free_buffer))
260       pclass->free_buffer (pool, buffer);
261   }
262   return TRUE;
263 }
264
265 /* must be called with the lock */
266 static gboolean
267 do_stop (GstBufferPool * pool)
268 {
269   if (pool->started) {
270     GstBufferPoolClass *pclass;
271
272     pclass = GST_BUFFER_POOL_GET_CLASS (pool);
273
274     GST_LOG_OBJECT (pool, "stopping");
275     if (G_LIKELY (pclass->stop)) {
276       if (!pclass->stop (pool))
277         return FALSE;
278     }
279     pool->started = FALSE;
280   }
281   return TRUE;
282 }
283
284 /**
285  * gst_buffer_pool_set_active:
286  * @pool: a #GstBufferPool
287  * @active: the new active state
288  *
289  * Control the active state of @pool. When the pool is active, new calls to
290  * gst_buffer_pool_acquire_buffer() will return with GST_FLOW_WRONG_STATE.
291  *
292  * Returns: %FALSE when the pool was not configured or when preallocation of the
293  * buffers failed.
294  */
295 gboolean
296 gst_buffer_pool_set_active (GstBufferPool * pool, gboolean active)
297 {
298   gboolean res = TRUE;
299
300   g_return_val_if_fail (GST_IS_BUFFER_POOL (pool), FALSE);
301
302   GST_LOG_OBJECT (pool, "active %d", active);
303
304   GST_BUFFER_POOL_LOCK (pool);
305   /* just return if we are already in the right state */
306   if (pool->active == active)
307     goto was_ok;
308
309   /* we need to be configured */
310   if (!pool->configured)
311     goto not_configured;
312
313   if (active) {
314     if (!do_start (pool))
315       goto start_failed;
316
317     /* unset the flushing state now */
318     gst_poll_read_control (pool->poll);
319     g_atomic_int_set (&pool->flushing, FALSE);
320   } else {
321     /* set to flushing first */
322     g_atomic_int_set (&pool->flushing, TRUE);
323     gst_poll_write_control (pool->poll);
324
325     /* when all buffers are in the pool, free them. Else they will be
326      * freed when they are released */
327     if (g_atomic_int_get (&pool->outstanding) == 0) {
328       if (!do_stop (pool))
329         goto stop_failed;
330     }
331   }
332   pool->active = active;
333   GST_BUFFER_POOL_UNLOCK (pool);
334
335   return res;
336
337 was_ok:
338   {
339     GST_DEBUG_OBJECT (pool, "pool was in the right state");
340     GST_BUFFER_POOL_UNLOCK (pool);
341     return TRUE;
342   }
343 not_configured:
344   {
345     GST_ERROR_OBJECT (pool, "pool was not configured");
346     GST_BUFFER_POOL_UNLOCK (pool);
347     return FALSE;
348   }
349 start_failed:
350   {
351     GST_ERROR_OBJECT (pool, "start failed");
352     GST_BUFFER_POOL_UNLOCK (pool);
353     return FALSE;
354   }
355 stop_failed:
356   {
357     GST_WARNING_OBJECT (pool, "stop failed");
358     GST_BUFFER_POOL_UNLOCK (pool);
359     return FALSE;
360   }
361 }
362
363 static gboolean
364 default_set_config (GstBufferPool * pool, GstStructure * config)
365 {
366   GstBufferPoolPrivate *priv = pool->priv;
367   const GstCaps *caps;
368   guint size, min_buffers, max_buffers;
369   guint prefix, postfix, align;
370
371   /* parse the config and keep around */
372   if (!gst_buffer_pool_config_get (config, &caps, &size, &min_buffers,
373           &max_buffers, &prefix, &postfix, &align))
374     goto wrong_config;
375
376   GST_DEBUG_OBJECT (pool, "config %" GST_PTR_FORMAT, config);
377
378   priv->size = size;
379   priv->min_buffers = min_buffers;
380   priv->max_buffers = max_buffers;
381   priv->prefix = prefix;
382   priv->postfix = postfix;
383   priv->align = align;
384
385   return TRUE;
386
387 wrong_config:
388   {
389     GST_WARNING_OBJECT (pool, "invalid config %" GST_PTR_FORMAT, config);
390     return FALSE;
391   }
392 }
393
394 /**
395  * gst_buffer_pool_set_config:
396  * @pool: a #GstBufferPool
397  * @config: a #GstStructure
398  *
399  * Set the configuration of the pool. The pool must be inactive and all buffers
400  * allocated form this pool must be returned or else this function will do
401  * nothing and return FALSE.
402  *
403  * @condfig is a #GstStructure that contains the configuration parameters for
404  * the pool. A default and mandatory set of parameters can be configured with
405  * gst_buffer_pool_config_set(). This function takes ownership of @config.
406  *
407  * Returns: TRUE when the configuration could be set.
408  */
409 gboolean
410 gst_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
411 {
412   gboolean result;
413   GstBufferPoolClass *pclass;
414
415   g_return_val_if_fail (GST_IS_BUFFER_POOL (pool), FALSE);
416   g_return_val_if_fail (config != NULL, FALSE);
417
418   GST_BUFFER_POOL_LOCK (pool);
419   /* can't change the settings when active */
420   if (pool->active)
421     goto was_active;
422
423   /* we can't change when outstanding buffers */
424   if (g_atomic_int_get (&pool->outstanding) != 0)
425     goto have_outstanding;
426
427   pclass = GST_BUFFER_POOL_GET_CLASS (pool);
428
429   /* set the new config */
430   if (G_LIKELY (pclass->set_config))
431     result = pclass->set_config (pool, config);
432   else
433     result = FALSE;
434
435   if (result) {
436     if (pool->config)
437       gst_structure_free (pool->config);
438     pool->config = config;
439
440     /* now we are configured */
441     pool->configured = TRUE;
442   }
443   GST_BUFFER_POOL_UNLOCK (pool);
444
445   return result;
446
447   /* ERRORS */
448 was_active:
449   {
450     GST_WARNING_OBJECT (pool, "can't change config, we are active");
451     GST_BUFFER_POOL_UNLOCK (pool);
452     return FALSE;
453   }
454 have_outstanding:
455   {
456     GST_WARNING_OBJECT (pool, "can't change config, have outstanding buffers");
457     GST_BUFFER_POOL_UNLOCK (pool);
458     return FALSE;
459   }
460 }
461
462 /**
463  * gst_buffer_pool_get_config:
464  * @pool: a #GstBufferPool
465  *
466  * Get a copy of the current configuration of the pool. This configuration
467  * can either be modified and used for the gst_buffer_pool_set_config() call
468  * or it must be freed after usage.
469  *
470  * Returns: a copy of the current configuration of @pool. use
471  * gst_structure_free() after usage or gst_buffer_pool_set_config().
472  */
473 GstStructure *
474 gst_buffer_pool_get_config (GstBufferPool * pool)
475 {
476   GstStructure *result;
477
478   g_return_val_if_fail (GST_IS_BUFFER_POOL (pool), NULL);
479
480   GST_BUFFER_POOL_UNLOCK (pool);
481   result = gst_structure_copy (pool->config);
482   GST_BUFFER_POOL_UNLOCK (pool);
483
484   return result;
485 }
486
487 /**
488  * gst_buffer_pool_config_set:
489  * @config: a #GstBufferPool
490  * @caps: caps for the buffers
491  * @size: the size of each buffer, not including pre and post fix
492  * @min_buffers: the minimum amount of buffers to allocate.
493  * @max_buffers: the maximum amount of buffers to allocate or 0 for unlimited.
494  * @prefix: prefix each buffer with this many bytes
495  * @postfix: postfix each buffer with this many bytes
496  * @align: alignment of the buffer data.
497  *
498  * Configure @config with the given parameters.
499  */
500 void
501 gst_buffer_pool_config_set (GstStructure * config, const GstCaps * caps,
502     guint size, guint min_buffers, guint max_buffers, guint prefix,
503     guint postfix, guint align)
504 {
505   g_return_if_fail (config != NULL);
506
507   gst_structure_id_set (config,
508       GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
509       GST_QUARK (SIZE), G_TYPE_UINT, size,
510       GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, min_buffers,
511       GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, max_buffers,
512       GST_QUARK (PREFIX), G_TYPE_UINT, prefix,
513       GST_QUARK (POSTFIX), G_TYPE_UINT, postfix,
514       GST_QUARK (ALIGN), G_TYPE_UINT, align, NULL);
515 }
516
517 /**
518  * gst_buffer_pool_config_get:
519  * @config: a #GstBufferPool
520  * @caps: the caps of buffers
521  * @size: the size of each buffer, not including pre and post fix
522  * @min_buffers: the minimum amount of buffers to allocate.
523  * @max_buffers: the maximum amount of buffers to allocate or 0 for unlimited.
524  * @prefix: prefix each buffer with this many bytes
525  * @postfix: postfix each buffer with this many bytes
526  * @align: alignment of the buffer data.
527  *
528  * Get the configuration values from @config.
529  */
530 gboolean
531 gst_buffer_pool_config_get (GstStructure * config, const GstCaps ** caps,
532     guint * size, guint * min_buffers, guint * max_buffers, guint * prefix,
533     guint * postfix, guint * align)
534 {
535   g_return_val_if_fail (config != NULL, FALSE);
536
537   return gst_structure_id_get (config,
538       GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
539       GST_QUARK (SIZE), G_TYPE_UINT, size,
540       GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, min_buffers,
541       GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, max_buffers,
542       GST_QUARK (PREFIX), G_TYPE_UINT, prefix,
543       GST_QUARK (POSTFIX), G_TYPE_UINT, postfix,
544       GST_QUARK (ALIGN), G_TYPE_UINT, align, NULL);
545 }
546
547 static GstFlowReturn
548 default_acquire_buffer (GstBufferPool * pool, GstBuffer ** buffer,
549     GstBufferPoolParams * params)
550 {
551   GstFlowReturn result;
552   GstBufferPoolClass *pclass;
553   GstBufferPoolPrivate *priv = pool->priv;
554
555   pclass = GST_BUFFER_POOL_GET_CLASS (pool);
556
557   while (TRUE) {
558     if (G_UNLIKELY (g_atomic_int_get (&pool->flushing)))
559       goto flushing;
560
561     /* try to get a buffer from the queue */
562     *buffer = gst_atomic_queue_pop (pool->queue);
563     if (G_LIKELY (*buffer)) {
564       gst_poll_read_control (pool->poll);
565       result = GST_FLOW_OK;
566       GST_LOG_OBJECT (pool, "acquired buffer %p", *buffer);
567       break;
568     }
569
570     /* no buffer */
571     if (priv->max_buffers == 0) {
572       /* no max_buffers, we allocate some more */
573       if (G_LIKELY (pclass->alloc_buffer)) {
574         result = pclass->alloc_buffer (pool, buffer, params);
575       } else
576         result = GST_FLOW_NOT_SUPPORTED;
577       GST_LOG_OBJECT (pool, "alloc buffer %p", *buffer);
578       break;
579     }
580
581     /* check if we need to wait */
582     if (params && (params->flags & GST_BUFFER_POOL_FLAG_DONTWAIT)) {
583       GST_LOG_OBJECT (pool, "no more buffers");
584       result = GST_FLOW_UNEXPECTED;
585       break;
586     }
587
588     /* now wait */
589     GST_LOG_OBJECT (pool, "waiting for free buffers");
590     gst_poll_wait (pool->poll, GST_CLOCK_TIME_NONE);
591   }
592
593   return result;
594
595   /* ERRORS */
596 flushing:
597   {
598     GST_DEBUG_OBJECT (pool, "we are flushing");
599     return GST_FLOW_WRONG_STATE;
600   }
601 }
602
603 static inline void
604 dec_outstanding (GstBufferPool * pool)
605 {
606   if (g_atomic_int_dec_and_test (&pool->outstanding)) {
607     /* all buffers are returned to the pool, see if we need to free them */
608     if (g_atomic_int_get (&pool->flushing)) {
609       /* take the lock so that set_active is not run concurrently */
610       GST_BUFFER_POOL_LOCK (pool);
611       /* recheck the flushing state in the lock, the pool could have been
612        * set to active again */
613       if (g_atomic_int_get (&pool->flushing))
614         do_stop (pool);
615
616       GST_BUFFER_POOL_UNLOCK (pool);
617     }
618   }
619 }
620
621 /**
622  * gst_buffer_pool_acquire_buffer:
623  * @pool: a #GstBufferPool
624  * @buffer: a location for a #GstBuffer
625  * @params: parameters.
626  *
627  * Acquire a buffer from @pool. @buffer should point to a memory location that
628  * can hold a pointer to the new buffer.
629  *
630  * @params can be NULL or contain optional parameters to influence the allocation.
631  *
632  * Returns: a #GstFlowReturn such as GST_FLOW_WRONG_STATE when the pool is
633  * inactive.
634  */
635 GstFlowReturn
636 gst_buffer_pool_acquire_buffer (GstBufferPool * pool, GstBuffer ** buffer,
637     GstBufferPoolParams * params)
638 {
639   GstBufferPoolClass *pclass;
640   GstFlowReturn result;
641
642   g_return_val_if_fail (GST_IS_BUFFER_POOL (pool), GST_FLOW_ERROR);
643   g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
644
645   pclass = GST_BUFFER_POOL_GET_CLASS (pool);
646
647   /* assume we'll have one more outstanding buffer we need to do that so
648    * that concurrent set_active doesn't clear the buffers */
649   g_atomic_int_inc (&pool->outstanding);
650
651   if (G_LIKELY (pclass->acquire_buffer))
652     result = pclass->acquire_buffer (pool, buffer, params);
653   else
654     result = GST_FLOW_NOT_SUPPORTED;
655
656   if (G_LIKELY (result == GST_FLOW_OK)) {
657     /* all buffers from the pool point to the pool and have the refcount of the
658      * pool incremented */
659     (*buffer)->pool = gst_object_ref (pool);
660   } else {
661     dec_outstanding (pool);
662   }
663
664   return result;
665 }
666
667 static void
668 default_release_buffer (GstBufferPool * pool, GstBuffer * buffer)
669 {
670   /* keep it around in our queue */
671   GST_LOG_OBJECT (pool, "released buffer %p", buffer);
672   gst_atomic_queue_push (pool->queue, buffer);
673   gst_poll_write_control (pool->poll);
674 }
675
676 /**
677  * gst_buffer_pool_release_buffer:
678  * @pool: a #GstBufferPool
679  * @buffer: a #GstBuffer
680  *
681  * Release @buffer to @pool. @buffer should have previously been allocated from
682  * @pool with gst_buffer_pool_acquire_buffer().
683  *
684  * This function is usually called automatically when the last ref on @buffer
685  * disappears.
686  */
687 void
688 gst_buffer_pool_release_buffer (GstBufferPool * pool, GstBuffer * buffer)
689 {
690   GstBufferPoolClass *pclass;
691
692   g_return_if_fail (GST_IS_BUFFER_POOL (pool));
693   g_return_if_fail (buffer != NULL);
694
695   /* check that the buffer is ours, all buffers returned to the pool have the
696    * pool member set to NULL and the pool refcount decreased */
697   if (!g_atomic_pointer_compare_and_exchange ((gpointer *) & buffer->pool,
698           pool, NULL))
699     return;
700
701   pclass = GST_BUFFER_POOL_GET_CLASS (pool);
702
703   if (G_LIKELY (pclass->release_buffer))
704     pclass->release_buffer (pool, buffer);
705
706   dec_outstanding (pool);
707
708   /* decrease the refcount that the buffer had to us */
709   gst_object_unref (pool);
710 }