gst: Don't pass miniobjects to GST_DEBUG_OBJECT() and similar macros
[platform/upstream/gstreamer.git] / tests / benchmarks / gstpoolstress.c
1 /* GStreamer
2  * Copyright (C) <2013> Wim Taymans <wim.taymans@gmail.com>
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <gst/gst.h>
23 #include "gst/glib-compat-private.h"
24
25 #define BUFFER_SIZE (1400)
26
27 gint
28 main (gint argc, gchar * argv[])
29 {
30   gint i;
31   GstBuffer *tmp;
32   GstBufferPool *pool;
33   GstClockTime start, end;
34   GstClockTimeDiff dur1, dur2;
35   guint64 nbuffers;
36   GstStructure *conf;
37
38   gst_init (&argc, &argv);
39
40   if (argc != 2) {
41     g_print ("usage: %s <nbuffers>\n", argv[0]);
42     exit (-1);
43   }
44
45   nbuffers = atoi (argv[1]);
46
47   if (nbuffers <= 0) {
48     g_print ("number of buffers must be greater than 0\n");
49     exit (-3);
50   }
51
52   /* Let's just make sure the GstBufferClass is loaded ... */
53   tmp = gst_buffer_new ();
54   gst_buffer_unref (tmp);
55
56   pool = gst_buffer_pool_new ();
57
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);
61
62   gst_buffer_pool_set_active (pool, TRUE);
63
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);
69   }
70   end = gst_util_get_timestamp ();
71   dur1 = 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 (dur1), GST_TIME_ARGS (dur1 / nbuffers), nbuffers);
75
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);
81   }
82   end = gst_util_get_timestamp ();
83   dur2 = 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 (dur2), GST_TIME_ARGS (dur2 / nbuffers), nbuffers);
87
88   g_print ("*** speedup %6.4lf\n", ((gdouble) dur1 / (gdouble) dur2));
89
90   gst_buffer_pool_set_active (pool, FALSE);
91   gst_object_unref (pool);
92
93   return 0;
94 }