2 * Copyright (C) 2010 Wim Taymans <wim.taymans@gmail.com>
4 * gstbufferpool.c: GstBufferPool baseclass
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.
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.
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.
23 * SECTION:gstbufferpool
24 * @short_description: Pool for buffers
25 * @see_also: #GstBuffer
29 #include "gst_private.h"
30 #include "glib-compat-private.h"
36 #include <sys/types.h>
41 #include "gstbufferpool.h"
43 GST_DEBUG_CATEGORY_STATIC (gst_buffer_pool_debug);
44 #define GST_CAT_DEFAULT gst_buffer_pool_debug
46 #define GST_BUFFER_POOL_GET_PRIVATE(obj) \
47 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_BUFFER_POOL, GstBufferPoolPrivate))
49 #define GST_BUFFER_POOL_LOCK(pool) (g_static_rec_mutex_lock(&pool->priv->rec_lock))
50 #define GST_BUFFER_POOL_UNLOCK(pool) (g_static_rec_mutex_unlock(&pool->priv->rec_lock))
52 struct _GstBufferPoolPrivate
54 GStaticRecMutex rec_lock;
68 static void gst_buffer_pool_finalize (GObject * object);
70 G_DEFINE_TYPE (GstBufferPool, gst_buffer_pool, GST_TYPE_OBJECT);
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_reset_buffer (GstBufferPool * pool, GstBuffer * buffer,
81 GstBufferPoolParams * params);
82 static void default_free_buffer (GstBufferPool * pool, GstBuffer * buffer);
83 static void default_release_buffer (GstBufferPool * pool, GstBuffer * buffer);
86 gst_buffer_pool_class_init (GstBufferPoolClass * klass)
88 GObjectClass *gobject_class = (GObjectClass *) klass;
90 g_type_class_add_private (klass, sizeof (GstBufferPoolPrivate));
92 gobject_class->finalize = gst_buffer_pool_finalize;
94 klass->start = default_start;
95 klass->stop = default_stop;
96 klass->set_config = default_set_config;
97 klass->acquire_buffer = default_acquire_buffer;
98 klass->reset_buffer = default_reset_buffer;
99 klass->alloc_buffer = default_alloc_buffer;
100 klass->release_buffer = default_release_buffer;
101 klass->free_buffer = default_free_buffer;
103 GST_DEBUG_CATEGORY_INIT (gst_buffer_pool_debug, "bufferpool", 0,
108 gst_buffer_pool_init (GstBufferPool * pool)
110 pool->priv = GST_BUFFER_POOL_GET_PRIVATE (pool);
112 g_static_rec_mutex_init (&pool->priv->rec_lock);
114 pool->poll = gst_poll_new_timer ();
115 pool->queue = gst_atomic_queue_new (10);
116 pool->flushing = TRUE;
117 pool->active = FALSE;
118 pool->configured = FALSE;
119 pool->started = FALSE;
120 pool->config = gst_structure_new_id_empty (GST_QUARK (BUFFER_POOL_CONFIG));
121 gst_buffer_pool_config_set (pool->config, NULL, 0, 0, 0, 0, 0);
122 gst_poll_write_control (pool->poll);
124 GST_DEBUG_OBJECT (pool, "created");
128 gst_buffer_pool_finalize (GObject * object)
132 pool = GST_BUFFER_POOL_CAST (object);
134 GST_DEBUG_OBJECT (pool, "finalize");
136 gst_buffer_pool_set_active (pool, FALSE);
137 gst_atomic_queue_unref (pool->queue);
138 gst_poll_free (pool->poll);
139 gst_structure_free (pool->config);
140 g_static_rec_mutex_free (&pool->priv->rec_lock);
142 G_OBJECT_CLASS (gst_buffer_pool_parent_class)->finalize (object);
146 * gst_buffer_pool_new:
148 * Creates a new #GstBufferPool instance.
150 * Returns: (transfer full): a new #GstBufferPool instance
153 gst_buffer_pool_new (void)
155 GstBufferPool *result;
157 result = g_object_newv (GST_TYPE_BUFFER_POOL, 0, NULL);
158 GST_DEBUG_OBJECT (result, "created new buffer pool");
164 default_alloc_buffer (GstBufferPool * pool, GstBuffer ** buffer,
165 GstBufferPoolParams * params)
167 GstBufferPoolPrivate *priv = pool->priv;
170 *buffer = gst_buffer_new ();
172 mem = gst_allocator_alloc (NULL, priv->size + priv->prefix, priv->align);
173 gst_memory_resize (mem, priv->prefix, priv->size);
174 gst_buffer_take_memory (*buffer, -1, mem);
179 /* the default implementation for preallocating the buffers
182 default_start (GstBufferPool * pool)
185 GstBufferPoolPrivate *priv = pool->priv;
186 GstBufferPoolClass *pclass;
188 pclass = GST_BUFFER_POOL_GET_CLASS (pool);
190 /* no alloc function, error */
191 if (G_UNLIKELY (pclass->alloc_buffer == NULL))
194 /* we need to prealloc buffers */
195 for (i = 0; i < priv->min_buffers; i++) {
198 if (pclass->alloc_buffer (pool, &buffer, NULL) != GST_FLOW_OK)
201 GST_LOG_OBJECT (pool, "prealloced buffer %d: %p", i, buffer);
202 /* release to the queue, we call the vmethod directly, we don't need to do
203 * the other refcount handling right now. */
204 if (G_LIKELY (pclass->release_buffer))
205 pclass->release_buffer (pool, buffer);
212 GST_WARNING_OBJECT (pool, "no alloc function");
217 GST_WARNING_OBJECT (pool, "alloc function failed");
222 /* must be called with the lock */
224 do_start (GstBufferPool * pool)
226 if (!pool->started) {
227 GstBufferPoolClass *pclass;
229 pclass = GST_BUFFER_POOL_GET_CLASS (pool);
231 GST_LOG_OBJECT (pool, "starting");
232 /* start the pool, subclasses should allocate buffers and put them
234 if (G_LIKELY (pclass->start)) {
235 if (!pclass->start (pool))
238 pool->started = TRUE;
245 default_free_buffer (GstBufferPool * pool, GstBuffer * buffer)
247 gst_buffer_unref (buffer);
250 /* must be called with the lock */
252 default_stop (GstBufferPool * pool)
255 GstBufferPoolClass *pclass;
257 pclass = GST_BUFFER_POOL_GET_CLASS (pool);
260 while ((buffer = gst_atomic_queue_pop (pool->queue))) {
261 GST_LOG_OBJECT (pool, "freeing %p", buffer);
262 gst_poll_read_control (pool->poll);
264 if (G_LIKELY (pclass->free_buffer))
265 pclass->free_buffer (pool, buffer);
270 /* must be called with the lock */
272 do_stop (GstBufferPool * pool)
275 GstBufferPoolClass *pclass;
277 pclass = GST_BUFFER_POOL_GET_CLASS (pool);
279 GST_LOG_OBJECT (pool, "stopping");
280 if (G_LIKELY (pclass->stop)) {
281 if (!pclass->stop (pool))
284 pool->started = FALSE;
290 * gst_buffer_pool_set_active:
291 * @pool: a #GstBufferPool
292 * @active: the new active state
294 * Control the active state of @pool. When the pool is active, new calls to
295 * gst_buffer_pool_acquire_buffer() will return with GST_FLOW_WRONG_STATE.
297 * Activating the bufferpool will preallocate all resources in the pool based on
298 * the configuration of the pool.
300 * Deactivating will free the resources again when there are no outstanding
301 * buffers. When there are outstanding buffers, they will be freed as soon as
302 * they are all returned to the pool.
304 * Returns: %FALSE when the pool was not configured or when preallocation of the
308 gst_buffer_pool_set_active (GstBufferPool * pool, gboolean active)
312 g_return_val_if_fail (GST_IS_BUFFER_POOL (pool), FALSE);
314 GST_LOG_OBJECT (pool, "active %d", active);
316 GST_BUFFER_POOL_LOCK (pool);
317 /* just return if we are already in the right state */
318 if (pool->active == active)
321 /* we need to be configured */
322 if (!pool->configured)
326 if (!do_start (pool))
329 /* unset the flushing state now */
330 gst_poll_read_control (pool->poll);
331 g_atomic_int_set (&pool->flushing, FALSE);
335 /* set to flushing first */
336 g_atomic_int_set (&pool->flushing, TRUE);
337 gst_poll_write_control (pool->poll);
339 /* when all buffers are in the pool, free them. Else they will be
340 * freed when they are released */
341 outstanding = g_atomic_int_get (&pool->outstanding);
342 GST_LOG_OBJECT (pool, "outstanding buffers %d", outstanding);
343 if (outstanding == 0) {
348 pool->active = active;
349 GST_BUFFER_POOL_UNLOCK (pool);
355 GST_DEBUG_OBJECT (pool, "pool was in the right state");
356 GST_BUFFER_POOL_UNLOCK (pool);
361 GST_ERROR_OBJECT (pool, "pool was not configured");
362 GST_BUFFER_POOL_UNLOCK (pool);
367 GST_ERROR_OBJECT (pool, "start failed");
368 GST_BUFFER_POOL_UNLOCK (pool);
373 GST_WARNING_OBJECT (pool, "stop failed");
374 GST_BUFFER_POOL_UNLOCK (pool);
380 * gst_buffer_pool_is_active:
381 * @pool: a #GstBufferPool
383 * Check if @pool is active. A pool can be activated with the
384 * gst_buffer_pool_set_active() call.
386 * Returns: %TRUE when the pool is active.
389 gst_buffer_pool_is_active (GstBufferPool * pool)
393 GST_BUFFER_POOL_LOCK (pool);
395 GST_BUFFER_POOL_UNLOCK (pool);
401 default_set_config (GstBufferPool * pool, GstStructure * config)
403 GstBufferPoolPrivate *priv = pool->priv;
405 guint size, min_buffers, max_buffers;
408 /* parse the config and keep around */
409 if (!gst_buffer_pool_config_get (config, &caps, &size, &min_buffers,
410 &max_buffers, &prefix, &align))
413 GST_DEBUG_OBJECT (pool, "config %" GST_PTR_FORMAT, config);
416 priv->min_buffers = min_buffers;
417 priv->max_buffers = max_buffers;
418 priv->prefix = prefix;
425 GST_WARNING_OBJECT (pool, "invalid config %" GST_PTR_FORMAT, config);
431 * gst_buffer_pool_set_config:
432 * @pool: a #GstBufferPool
433 * @config: (transfer full): a #GstStructure
435 * Set the configuration of the pool. The pool must be inactive and all buffers
436 * allocated form this pool must be returned or else this function will do
437 * nothing and return FALSE.
439 * @config is a #GstStructure that contains the configuration parameters for
440 * the pool. A default and mandatory set of parameters can be configured with
441 * gst_buffer_pool_config_set(). This function takes ownership of @config.
443 * Returns: TRUE when the configuration could be set.
446 gst_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
449 GstBufferPoolClass *pclass;
451 g_return_val_if_fail (GST_IS_BUFFER_POOL (pool), FALSE);
452 g_return_val_if_fail (config != NULL, FALSE);
454 GST_BUFFER_POOL_LOCK (pool);
455 /* can't change the settings when active */
459 /* we can't change when outstanding buffers */
460 if (g_atomic_int_get (&pool->outstanding) != 0)
461 goto have_outstanding;
463 pclass = GST_BUFFER_POOL_GET_CLASS (pool);
465 /* set the new config */
466 if (G_LIKELY (pclass->set_config))
467 result = pclass->set_config (pool, config);
473 gst_structure_free (pool->config);
474 pool->config = config;
476 /* now we are configured */
477 pool->configured = TRUE;
479 GST_BUFFER_POOL_UNLOCK (pool);
486 GST_WARNING_OBJECT (pool, "can't change config, we are active");
487 GST_BUFFER_POOL_UNLOCK (pool);
492 GST_WARNING_OBJECT (pool, "can't change config, have outstanding buffers");
493 GST_BUFFER_POOL_UNLOCK (pool);
499 * gst_buffer_pool_get_config:
500 * @pool: a #GstBufferPool
502 * Get a copy of the current configuration of the pool. This configuration
503 * can either be modified and used for the gst_buffer_pool_set_config() call
504 * or it must be freed after usage.
506 * Returns: (transfer full): a copy of the current configuration of @pool. use
507 * gst_structure_free() after usage or gst_buffer_pool_set_config().
510 gst_buffer_pool_get_config (GstBufferPool * pool)
512 GstStructure *result;
514 g_return_val_if_fail (GST_IS_BUFFER_POOL (pool), NULL);
516 GST_BUFFER_POOL_UNLOCK (pool);
517 result = gst_structure_copy (pool->config);
518 GST_BUFFER_POOL_UNLOCK (pool);
523 static const gchar *empty_option[] = { NULL };
526 * gst_buffer_pool_get_options:
527 * @pool: a #GstBufferPool
529 * Get a NULL terminated array of string with supported bufferpool options for
530 * @pool. An option would typically be enabled with
531 * gst_buffer_pool_config_add_option().
533 * Returns: (array zero-terminated=1) (transfer none): a NULL terminated array of strings.
536 gst_buffer_pool_get_options (GstBufferPool * pool)
538 GstBufferPoolClass *pclass;
539 const gchar **result;
541 g_return_val_if_fail (GST_IS_BUFFER_POOL (pool), NULL);
543 pclass = GST_BUFFER_POOL_GET_CLASS (pool);
545 if (G_LIKELY (pclass->get_options)) {
546 if ((result = pclass->get_options (pool)) == NULL)
549 result = empty_option;
556 g_warning ("bufferpool subclass returned NULL options");
562 * gst_buffer_pool_has_option:
563 * @pool: a #GstBufferPool
566 * Check if the bufferpool supports @option.
568 * Returns: a NULL terminated array of strings.
571 gst_buffer_pool_has_option (GstBufferPool * pool, const gchar * option)
574 const gchar **options;
576 g_return_val_if_fail (GST_IS_BUFFER_POOL (pool), FALSE);
577 g_return_val_if_fail (option != NULL, FALSE);
579 options = gst_buffer_pool_get_options (pool);
581 for (i = 0; options[i]; i++) {
582 if (g_str_equal (options[i], option))
589 * gst_buffer_pool_config_set:
590 * @config: a #GstBufferPool configuration
591 * @caps: caps for the buffers
592 * @size: the size of each buffer, not including prefix
593 * @min_buffers: the minimum amount of buffers to allocate.
594 * @max_buffers: the maximum amount of buffers to allocate or 0 for unlimited.
595 * @prefix: prefix each buffer with this many bytes
596 * @align: alignment of the buffer data.
598 * Configure @config with the given parameters.
601 gst_buffer_pool_config_set (GstStructure * config, const GstCaps * caps,
602 guint size, guint min_buffers, guint max_buffers, guint prefix, guint align)
604 g_return_if_fail (config != NULL);
606 gst_structure_id_set (config,
607 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
608 GST_QUARK (SIZE), G_TYPE_UINT, size,
609 GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, min_buffers,
610 GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, max_buffers,
611 GST_QUARK (PREFIX), G_TYPE_UINT, prefix,
612 GST_QUARK (ALIGN), G_TYPE_UINT, align, NULL);
616 * gst_buffer_pool_config_add_option:
617 * @config: a #GstBufferPool configuration
618 * @option: an option to add
620 * Enabled the option in @config. This will instruct the @bufferpool to enable
621 * the specified option on the buffers that it allocates.
623 * The supported options by @pool can be retrieved with gst_buffer_pool_get_options().
626 gst_buffer_pool_config_add_option (GstStructure * config, const gchar * option)
630 GValue option_value = { 0 };
633 g_return_if_fail (config != NULL);
635 value = gst_structure_id_get_value (config, GST_QUARK (OPTIONS));
637 array = (GValueArray *) g_value_get_boxed (value);
639 GValue new_array_val = { 0, };
641 array = g_value_array_new (0);
643 g_value_init (&new_array_val, G_TYPE_VALUE_ARRAY);
644 g_value_take_boxed (&new_array_val, array);
646 gst_structure_id_take_value (config, GST_QUARK (OPTIONS), &new_array_val);
648 for (i = 0; i < array->n_values; i++) {
649 value = g_value_array_get_nth (array, i);
650 if (g_str_equal (option, g_value_get_string (value)))
653 g_value_init (&option_value, G_TYPE_STRING);
654 g_value_set_string (&option_value, option);
655 g_value_array_append (array, &option_value);
656 g_value_unset (&option_value);
660 * gst_buffer_pool_config_n_options:
661 * @config: a #GstBufferPool configuration
663 * Retrieve the number of values currently stored in the
664 * options array of the @config structure.
666 * Returns: the options array size as a #guint.
669 gst_buffer_pool_config_n_options (GstStructure * config)
675 g_return_val_if_fail (config != NULL, 0);
677 value = gst_structure_id_get_value (config, GST_QUARK (OPTIONS));
679 array = (GValueArray *) g_value_get_boxed (value);
680 size = array->n_values;
686 * gst_buffer_pool_config_get_option:
687 * @config: a #GstBufferPool configuration
688 * @index: position in the option array to read
690 * Parse an available @config and get the option
691 * at @index of the options API array.
693 * Returns: a #gchar of the option at @index.
696 gst_buffer_pool_config_get_option (GstStructure * config, guint index)
699 const gchar *ret = NULL;
701 g_return_val_if_fail (config != NULL, 0);
703 value = gst_structure_id_get_value (config, GST_QUARK (OPTIONS));
706 GValue *option_value;
708 array = (GValueArray *) g_value_get_boxed (value);
709 option_value = g_value_array_get_nth (array, index);
712 ret = g_value_get_string (option_value);
718 * gst_buffer_pool_config_has_option:
719 * @config: a #GstBufferPool configuration
722 * Check if @config contains @option
724 * Returns: TRUE if the options array contains @option.
727 gst_buffer_pool_config_has_option (GstStructure * config, const gchar * option)
731 g_return_val_if_fail (config != NULL, 0);
733 value = gst_structure_id_get_value (config, GST_QUARK (OPTIONS));
736 GValue *option_value;
739 array = (GValueArray *) g_value_get_boxed (value);
740 for (i = 0; i < array->n_values; i++) {
741 option_value = g_value_array_get_nth (array, i);
742 if (g_str_equal (option, g_value_get_string (option_value)))
750 * gst_buffer_pool_config_get:
751 * @config: (transfer none): a #GstBufferPool configuration
752 * @caps: (out): the caps of buffers
753 * @size: (out): the size of each buffer, not including prefix
754 * @min_buffers: (out): the minimum amount of buffers to allocate.
755 * @max_buffers: (out): the maximum amount of buffers to allocate or 0 for unlimited.
756 * @prefix: (out): prefix each buffer with this many bytes
757 * @align: (out): alignment of the buffer data.
759 * Get the configuration values from @config.
762 gst_buffer_pool_config_get (GstStructure * config, const GstCaps ** caps,
763 guint * size, guint * min_buffers, guint * max_buffers, guint * prefix,
766 g_return_val_if_fail (config != NULL, FALSE);
768 return gst_structure_id_get (config,
769 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
770 GST_QUARK (SIZE), G_TYPE_UINT, size,
771 GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, min_buffers,
772 GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, max_buffers,
773 GST_QUARK (PREFIX), G_TYPE_UINT, prefix,
774 GST_QUARK (ALIGN), G_TYPE_UINT, align, NULL);
778 default_acquire_buffer (GstBufferPool * pool, GstBuffer ** buffer,
779 GstBufferPoolParams * params)
781 GstFlowReturn result;
782 GstBufferPoolClass *pclass;
783 GstBufferPoolPrivate *priv = pool->priv;
785 pclass = GST_BUFFER_POOL_GET_CLASS (pool);
788 if (G_UNLIKELY (g_atomic_int_get (&pool->flushing)))
791 /* try to get a buffer from the queue */
792 *buffer = gst_atomic_queue_pop (pool->queue);
793 if (G_LIKELY (*buffer)) {
794 gst_poll_read_control (pool->poll);
795 result = GST_FLOW_OK;
796 GST_LOG_OBJECT (pool, "acquired buffer %p", *buffer);
801 if (priv->max_buffers == 0) {
802 /* no max_buffers, we allocate some more */
803 if (G_LIKELY (pclass->alloc_buffer)) {
804 result = pclass->alloc_buffer (pool, buffer, params);
806 result = GST_FLOW_NOT_SUPPORTED;
807 GST_LOG_OBJECT (pool, "alloc buffer %p", *buffer);
811 /* check if we need to wait */
812 if (params && (params->flags & GST_BUFFER_POOL_FLAG_DONTWAIT)) {
813 GST_LOG_OBJECT (pool, "no more buffers");
814 result = GST_FLOW_EOS;
819 GST_LOG_OBJECT (pool, "waiting for free buffers");
820 gst_poll_wait (pool->poll, GST_CLOCK_TIME_NONE);
828 GST_DEBUG_OBJECT (pool, "we are flushing");
829 return GST_FLOW_WRONG_STATE;
834 dec_outstanding (GstBufferPool * pool)
836 if (g_atomic_int_dec_and_test (&pool->outstanding)) {
837 /* all buffers are returned to the pool, see if we need to free them */
838 if (g_atomic_int_get (&pool->flushing)) {
839 /* take the lock so that set_active is not run concurrently */
840 GST_BUFFER_POOL_LOCK (pool);
841 /* recheck the flushing state in the lock, the pool could have been
842 * set to active again */
843 if (g_atomic_int_get (&pool->flushing))
846 GST_BUFFER_POOL_UNLOCK (pool);
852 default_reset_buffer (GstBufferPool * pool, GstBuffer * buffer,
853 GstBufferPoolParams * params)
855 GST_BUFFER_FLAGS (buffer) = 0;
857 GST_BUFFER_PTS (buffer) = GST_CLOCK_TIME_NONE;
858 GST_BUFFER_DTS (buffer) = GST_CLOCK_TIME_NONE;
859 GST_BUFFER_DURATION (buffer) = GST_CLOCK_TIME_NONE;
860 GST_BUFFER_OFFSET (buffer) = GST_BUFFER_OFFSET_NONE;
861 GST_BUFFER_OFFSET_END (buffer) = GST_BUFFER_OFFSET_NONE;
865 * gst_buffer_pool_acquire_buffer:
866 * @pool: a #GstBufferPool
867 * @buffer: (out): a location for a #GstBuffer
868 * @params: (transfer none) (allow-none) parameters.
870 * Acquire a buffer from @pool. @buffer should point to a memory location that
871 * can hold a pointer to the new buffer.
873 * @params can be NULL or contain optional parameters to influence the allocation.
875 * Returns: a #GstFlowReturn such as GST_FLOW_WRONG_STATE when the pool is
879 gst_buffer_pool_acquire_buffer (GstBufferPool * pool, GstBuffer ** buffer,
880 GstBufferPoolParams * params)
882 GstBufferPoolClass *pclass;
883 GstFlowReturn result;
885 g_return_val_if_fail (GST_IS_BUFFER_POOL (pool), GST_FLOW_ERROR);
886 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
888 pclass = GST_BUFFER_POOL_GET_CLASS (pool);
890 /* assume we'll have one more outstanding buffer we need to do that so
891 * that concurrent set_active doesn't clear the buffers */
892 g_atomic_int_inc (&pool->outstanding);
894 if (G_LIKELY (pclass->acquire_buffer))
895 result = pclass->acquire_buffer (pool, buffer, params);
897 result = GST_FLOW_NOT_SUPPORTED;
899 if (G_LIKELY (result == GST_FLOW_OK)) {
900 /* all buffers from the pool point to the pool and have the refcount of the
901 * pool incremented */
902 (*buffer)->pool = gst_object_ref (pool);
903 /* now reset the buffer when needed */
904 if (G_LIKELY (pclass->reset_buffer))
905 pclass->reset_buffer (pool, *buffer, params);
907 dec_outstanding (pool);
914 default_release_buffer (GstBufferPool * pool, GstBuffer * buffer)
916 /* keep it around in our queue */
917 GST_LOG_OBJECT (pool, "released buffer %p", buffer);
918 gst_atomic_queue_push (pool->queue, buffer);
919 gst_poll_write_control (pool->poll);
923 * gst_buffer_pool_release_buffer:
924 * @pool: a #GstBufferPool
925 * @buffer: (transfer none): a #GstBuffer
927 * Release @buffer to @pool. @buffer should have previously been allocated from
928 * @pool with gst_buffer_pool_acquire_buffer().
930 * This function is usually called automatically when the last ref on @buffer
934 gst_buffer_pool_release_buffer (GstBufferPool * pool, GstBuffer * buffer)
936 GstBufferPoolClass *pclass;
938 g_return_if_fail (GST_IS_BUFFER_POOL (pool));
939 g_return_if_fail (buffer != NULL);
941 /* check that the buffer is ours, all buffers returned to the pool have the
942 * pool member set to NULL and the pool refcount decreased */
943 if (!G_ATOMIC_POINTER_COMPARE_AND_EXCHANGE (&buffer->pool, pool, NULL))
946 pclass = GST_BUFFER_POOL_GET_CLASS (pool);
948 if (G_LIKELY (pclass->release_buffer))
949 pclass->release_buffer (pool, buffer);
951 dec_outstanding (pool);
953 /* decrease the refcount that the buffer had to us */
954 gst_object_unref (pool);