2 * Copyright (C) <2013> Wim Taymans <wim.taymans@gmail.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
23 #include "gst/glib-compat-private.h"
25 #define BUFFER_SIZE (1400)
28 main (gint argc, gchar * argv[])
33 GstClockTime start, end;
38 gst_init (&argc, &argv);
41 g_print ("usage: %s <nbuffers>\n", argv[0]);
45 nbuffers = atoi (argv[1]);
48 g_print ("number of buffers must be greater than 0\n");
52 /* Let's just make sure the GstBufferClass is loaded ... */
53 tmp = gst_buffer_new ();
54 gst_buffer_unref (tmp);
56 pool = gst_buffer_pool_new ();
58 conf = gst_buffer_pool_get_config (pool);
59 gst_buffer_pool_config_set_params (conf, NULL, BUFFER_SIZE, 0, 0);
60 gst_buffer_pool_set_config (pool, conf);
62 gst_buffer_pool_set_active (pool, TRUE);
64 /* allocate buffers directly */
65 start = gst_util_get_timestamp ();
66 for (i = 0; i < nbuffers; i++) {
67 tmp = gst_buffer_new_allocate (NULL, BUFFER_SIZE, NULL);
68 gst_buffer_unref (tmp);
70 end = gst_util_get_timestamp ();
71 dur = GST_CLOCK_DIFF (start, end);
72 g_print ("*** total %" GST_TIME_FORMAT " - average %" GST_TIME_FORMAT
73 " - Done creating %" G_GUINT64_FORMAT " fresh buffers\n",
74 GST_TIME_ARGS (dur), GST_TIME_ARGS (dur / nbuffers), nbuffers);
76 /* allocate buffers from the pool */
77 start = gst_util_get_timestamp ();
78 for (i = 0; i < nbuffers; i++) {
79 gst_buffer_pool_acquire_buffer (pool, &tmp, NULL);
80 gst_buffer_unref (tmp);
82 end = gst_util_get_timestamp ();
83 dur = GST_CLOCK_DIFF (start, end);
84 g_print ("*** total %" GST_TIME_FORMAT " - average %" GST_TIME_FORMAT
85 " - Done creating %" G_GUINT64_FORMAT " pooled buffers\n",
86 GST_TIME_ARGS (dur), GST_TIME_ARGS (dur / nbuffers), nbuffers);
88 gst_buffer_pool_set_active (pool, FALSE);
89 gst_object_unref (pool);