gstreamer/tests/examples/adapter/adapter_test.c

140 lines
3.3 KiB
C
Raw Normal View History

#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/times.h>
#include <gst/gst.h>
#include <gst/base/gstadapter.h>
struct TestParams
{
gint tot_size;
gint read_size;
gint write_size;
};
/* This test pushes 'n' buffers of 'write size' into an adapter, then reads
* them out in 'read size' sized pieces, using take and then take_buffer,
* and prints the timings */
Correct all relevant warnings found by the sparse semantic code analyzer. This include marking several symbols static... Original commit message from CVS: * gst/gstconfig.h.in: * libs/gst/base/gstcollectpads.c: (gst_collect_pads_read_buffer): * libs/gst/check/gstcheck.c: (gst_check_log_message_func), (gst_check_log_critical_func), (gst_check_drop_buffers), (gst_check_element_push_buffer_list): * libs/gst/controller/gstcontroller.c: (gst_controller_get), (gst_controller_get_type): * libs/gst/controller/gsthelper.c: (gst_object_control_properties), (gst_object_get_controller), (gst_object_get_control_source): * libs/gst/controller/gstinterpolationcontrolsource.c: (gst_interpolation_control_source_new): * libs/gst/controller/gstlfocontrolsource.c: (gst_lfo_control_source_new): * libs/gst/dataprotocol/dataprotocol.c: (gst_dp_event_from_packet_0_2): * plugins/elements/gstfdsrc.c: * plugins/elements/gstmultiqueue.c: * plugins/elements/gsttee.c: * plugins/elements/gsttypefindelement.c: * plugins/indexers/gstfileindex.c: (_file_index_id_save_xml), (gst_file_index_add_association): * plugins/indexers/gstmemindex.c: * tests/benchmarks/gstpollstress.c: (mess_some_more): * tests/check/elements/queue.c: (setup_queue): * tests/check/gst/gstpipeline.c: * tests/check/libs/collectpads.c: (setup), (teardown), (gst_collect_pads_suite): * tests/examples/adapter/adapter_test.c: * tests/examples/metadata/read-metadata.c: (make_pipeline): * tests/examples/xml/createxml.c: * tests/examples/xml/runxml.c: * tools/gst-inspect.c: * tools/gst-run.c: Correct all relevant warnings found by the sparse semantic code analyzer. This include marking several symbols static, using NULL instead of 0 for pointers, not using variable sized arrays on the stack, moving variable declarations to the beginning of a block and using "foo (void)" instead of "foo ()" for declarations.
2008-02-29 12:41:33 +00:00
static struct TestParams param_sets[] = {
/* These values put ~256MB in 1MB chunks in an adapter, then reads them out
* in 250kb blocks */
{256000000, 250000, 1000000},
/* These values put ~256MB in 1000 byte chunks in an adapter, then reads them
* out in 200 byte blocks */
{25600000, 200, 1000},
/* These values put ~256MB in 200 chunks in an adapter, then reads them out
* in 1000 byte blocks */
{25600000, 1000, 200}
};
Correct all relevant warnings found by the sparse semantic code analyzer. This include marking several symbols static... Original commit message from CVS: * gst/gstconfig.h.in: * libs/gst/base/gstcollectpads.c: (gst_collect_pads_read_buffer): * libs/gst/check/gstcheck.c: (gst_check_log_message_func), (gst_check_log_critical_func), (gst_check_drop_buffers), (gst_check_element_push_buffer_list): * libs/gst/controller/gstcontroller.c: (gst_controller_get), (gst_controller_get_type): * libs/gst/controller/gsthelper.c: (gst_object_control_properties), (gst_object_get_controller), (gst_object_get_control_source): * libs/gst/controller/gstinterpolationcontrolsource.c: (gst_interpolation_control_source_new): * libs/gst/controller/gstlfocontrolsource.c: (gst_lfo_control_source_new): * libs/gst/dataprotocol/dataprotocol.c: (gst_dp_event_from_packet_0_2): * plugins/elements/gstfdsrc.c: * plugins/elements/gstmultiqueue.c: * plugins/elements/gsttee.c: * plugins/elements/gsttypefindelement.c: * plugins/indexers/gstfileindex.c: (_file_index_id_save_xml), (gst_file_index_add_association): * plugins/indexers/gstmemindex.c: * tests/benchmarks/gstpollstress.c: (mess_some_more): * tests/check/elements/queue.c: (setup_queue): * tests/check/gst/gstpipeline.c: * tests/check/libs/collectpads.c: (setup), (teardown), (gst_collect_pads_suite): * tests/examples/adapter/adapter_test.c: * tests/examples/metadata/read-metadata.c: (make_pipeline): * tests/examples/xml/createxml.c: * tests/examples/xml/runxml.c: * tools/gst-inspect.c: * tools/gst-run.c: Correct all relevant warnings found by the sparse semantic code analyzer. This include marking several symbols static, using NULL instead of 0 for pointers, not using variable sized arrays on the stack, moving variable declarations to the beginning of a block and using "foo (void)" instead of "foo ()" for declarations.
2008-02-29 12:41:33 +00:00
static const gint n_tests = sizeof (param_sets) / sizeof (struct TestParams);
Correct all relevant warnings found by the sparse semantic code analyzer. This include marking several symbols static... Original commit message from CVS: * gst/gstconfig.h.in: * libs/gst/base/gstcollectpads.c: (gst_collect_pads_read_buffer): * libs/gst/check/gstcheck.c: (gst_check_log_message_func), (gst_check_log_critical_func), (gst_check_drop_buffers), (gst_check_element_push_buffer_list): * libs/gst/controller/gstcontroller.c: (gst_controller_get), (gst_controller_get_type): * libs/gst/controller/gsthelper.c: (gst_object_control_properties), (gst_object_get_controller), (gst_object_get_control_source): * libs/gst/controller/gstinterpolationcontrolsource.c: (gst_interpolation_control_source_new): * libs/gst/controller/gstlfocontrolsource.c: (gst_lfo_control_source_new): * libs/gst/dataprotocol/dataprotocol.c: (gst_dp_event_from_packet_0_2): * plugins/elements/gstfdsrc.c: * plugins/elements/gstmultiqueue.c: * plugins/elements/gsttee.c: * plugins/elements/gsttypefindelement.c: * plugins/indexers/gstfileindex.c: (_file_index_id_save_xml), (gst_file_index_add_association): * plugins/indexers/gstmemindex.c: * tests/benchmarks/gstpollstress.c: (mess_some_more): * tests/check/elements/queue.c: (setup_queue): * tests/check/gst/gstpipeline.c: * tests/check/libs/collectpads.c: (setup), (teardown), (gst_collect_pads_suite): * tests/examples/adapter/adapter_test.c: * tests/examples/metadata/read-metadata.c: (make_pipeline): * tests/examples/xml/createxml.c: * tests/examples/xml/runxml.c: * tools/gst-inspect.c: * tools/gst-run.c: Correct all relevant warnings found by the sparse semantic code analyzer. This include marking several symbols static, using NULL instead of 0 for pointers, not using variable sized arrays on the stack, moving variable declarations to the beginning of a block and using "foo (void)" instead of "foo ()" for declarations.
2008-02-29 12:41:33 +00:00
static gint ticks_per_sec;
static void
run_test_take (struct TestParams *params)
{
/* Create an adapter and feed it data of fixed size, then retrieve it in
* a different size */
GstAdapter *adapter = gst_adapter_new ();
guint8 *data;
GstBuffer *buf;
int i;
gint ntimes = params->tot_size / params->write_size;
for (i = 0; i < ntimes; i++) {
buf = gst_buffer_new_and_alloc (params->write_size);
data = gst_buffer_map (buf, NULL, NULL, GST_MAP_WRITE);
memset (data, 0, params->write_size);
gst_buffer_unmap (buf, data, params->write_size);
gst_adapter_push (adapter, buf);
}
do {
data = gst_adapter_take (adapter, params->read_size);
if (data == NULL)
break;
g_free (data);
} while (TRUE);
g_object_unref (adapter);
}
static void
run_test_take_buffer (struct TestParams *params)
{
/* Create an adapter and feed it data of fixed size, then retrieve it in
* a different size
*/
GstAdapter *adapter = gst_adapter_new ();
GstBuffer *buf;
int i;
gint ntimes = params->tot_size / params->write_size;
guint8 *data;
for (i = 0; i < ntimes; i++) {
buf = gst_buffer_new_and_alloc (params->write_size);
data = gst_buffer_map (buf, NULL, NULL, GST_MAP_WRITE);
memset (data, 0, params->write_size);
gst_buffer_unmap (buf, data, params->write_size);
gst_adapter_push (adapter, buf);
}
do {
buf = gst_adapter_take_buffer (adapter, params->read_size);
if (buf == NULL)
break;
gst_buffer_unref (buf);
} while (TRUE);
g_object_unref (adapter);
}
Correct all relevant warnings found by the sparse semantic code analyzer. This include marking several symbols static... Original commit message from CVS: * gst/gstconfig.h.in: * libs/gst/base/gstcollectpads.c: (gst_collect_pads_read_buffer): * libs/gst/check/gstcheck.c: (gst_check_log_message_func), (gst_check_log_critical_func), (gst_check_drop_buffers), (gst_check_element_push_buffer_list): * libs/gst/controller/gstcontroller.c: (gst_controller_get), (gst_controller_get_type): * libs/gst/controller/gsthelper.c: (gst_object_control_properties), (gst_object_get_controller), (gst_object_get_control_source): * libs/gst/controller/gstinterpolationcontrolsource.c: (gst_interpolation_control_source_new): * libs/gst/controller/gstlfocontrolsource.c: (gst_lfo_control_source_new): * libs/gst/dataprotocol/dataprotocol.c: (gst_dp_event_from_packet_0_2): * plugins/elements/gstfdsrc.c: * plugins/elements/gstmultiqueue.c: * plugins/elements/gsttee.c: * plugins/elements/gsttypefindelement.c: * plugins/indexers/gstfileindex.c: (_file_index_id_save_xml), (gst_file_index_add_association): * plugins/indexers/gstmemindex.c: * tests/benchmarks/gstpollstress.c: (mess_some_more): * tests/check/elements/queue.c: (setup_queue): * tests/check/gst/gstpipeline.c: * tests/check/libs/collectpads.c: (setup), (teardown), (gst_collect_pads_suite): * tests/examples/adapter/adapter_test.c: * tests/examples/metadata/read-metadata.c: (make_pipeline): * tests/examples/xml/createxml.c: * tests/examples/xml/runxml.c: * tools/gst-inspect.c: * tools/gst-run.c: Correct all relevant warnings found by the sparse semantic code analyzer. This include marking several symbols static, using NULL instead of 0 for pointers, not using variable sized arrays on the stack, moving variable declarations to the beginning of a block and using "foo (void)" instead of "foo ()" for declarations.
2008-02-29 12:41:33 +00:00
static void
run_tests (struct TestParams *params)
{
struct tms time_data;
gdouble start;
gdouble dur;
g_print ("Running on %d bytes, writing %d bytes/buf, reading %d bytes/buf\n",
params->tot_size, params->write_size, params->read_size);
start = 0.0;
run_test_take (params);
times (&time_data);
dur = (gdouble) (time_data.tms_utime + time_data.tms_stime) / ticks_per_sec;
g_print ("Time for take test: %g secs\n", dur - start);
start = dur;
run_test_take_buffer (params);
times (&time_data);
dur = (gdouble) (time_data.tms_utime + time_data.tms_stime) / ticks_per_sec;
g_print ("Time for TakeBuffer test: %g secs\n", dur - start);
g_print ("\n");
}
int
main (int argc, char **argv)
{
gint i;
ticks_per_sec = sysconf (_SC_CLK_TCK);
gst_init (&argc, &argv);
for (i = 0; i < n_tests; i++)
run_tests (param_sets + i);
return 0;
}