From: Stefan Kost Date: Thu, 15 Apr 2010 10:09:45 +0000 (+0300) Subject: examples: add a test for difference position formats X-Git-Tag: RELEASE-0.10.30~230 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8690945e35001fe640eeb447f9423b9879e37b5d;p=platform%2Fupstream%2Fgst-plugins-base.git examples: add a test for difference position formats The test runs position and duration queries on the pipeline in all formats. --- diff --git a/tests/icles/.gitignore b/tests/icles/.gitignore index ae231a1..72ace73 100644 --- a/tests/icles/.gitignore +++ b/tests/icles/.gitignore @@ -1,5 +1,6 @@ audio-trickplay playbin-text +position-formats stress-playbin stress-xoverlay test-textoverlay diff --git a/tests/icles/Makefile.am b/tests/icles/Makefile.am index ce3c6a1..3608224 100644 --- a/tests/icles/Makefile.am +++ b/tests/icles/Makefile.am @@ -46,6 +46,10 @@ playbin_text_SOURCES = playbin-text.c playbin_text_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS) playbin_text_LDADD = $(GST_LIBS) $(LIBM) +position_formats_SOURCES = position-formats.c +position_formats_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS) +position_formats_LDADD = $(GST_LIBS) $(LIBM) + stress_playbin_SOURCES = stress-playbin.c stress_playbin_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS) stress_playbin_LDADD = $(GST_LIBS) $(LIBM) @@ -59,4 +63,5 @@ test_box_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS) test_box_LDADD = $(GST_LIBS) $(LIBM) noinst_PROGRAMS = $(X_TESTS) $(PANGO_TESTS) \ - audio-trickplay playbin-text stress-playbin test-scale test-box + audio-trickplay playbin-text position-formats stress-playbin \ + test-scale test-box diff --git a/tests/icles/position-formats.c b/tests/icles/position-formats.c new file mode 100644 index 0000000..5ca815e --- /dev/null +++ b/tests/icles/position-formats.c @@ -0,0 +1,149 @@ +/* + * position-formats.c + * + * we mostly use GST_FORMAT_TIME in queries and seeks. Test the other ones to + * know what works and what not. + */ + +#include + +#include + +static gboolean +bus_message (GstBus * bus, GstMessage * message, gpointer user_data) +{ + GMainLoop *loop = (GMainLoop *) user_data; + + switch (GST_MESSAGE_TYPE (message)) { + case GST_MESSAGE_ERROR: + { + GError *gerror; + gchar *debug; + + gst_message_parse_error (message, &gerror, &debug); + gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug); + g_error_free (gerror); + g_free (debug); + + g_main_loop_quit (loop); + break; + } + case GST_MESSAGE_WARNING: + { + GError *gerror; + gchar *debug; + + gst_message_parse_warning (message, &gerror, &debug); + gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug); + g_error_free (gerror); + g_free (debug); + + g_main_loop_quit (loop); + break; + } + case GST_MESSAGE_EOS: + g_main_loop_quit (loop); + break; + default: + break; + } + return TRUE; +} + +static void +print_value (gboolean res, GstFormat fmt, gint64 val) +{ + if (res) { + switch (fmt) { + case GST_FORMAT_TIME: + printf ("%" GST_TIME_FORMAT, GST_TIME_ARGS (val)); + break; + case GST_FORMAT_PERCENT: + printf ("%8.4lf%%", (gdouble) val / GST_FORMAT_PERCENT_SCALE); + break; + case GST_FORMAT_DEFAULT: + case GST_FORMAT_BYTES: + case GST_FORMAT_BUFFERS: + default: + printf ("%" G_GINT64_FORMAT, val); + break; + } + } else { + printf ("-"); + } +} + +static gboolean +run_queries (gpointer user_data) +{ + GstElement *bin = (GstElement *) user_data; + GstFormat i, fmt; + gint64 pos, dur; + gboolean pres, dres; + + for (i = GST_FORMAT_DEFAULT; i <= GST_FORMAT_PERCENT; i++) { + fmt = i; + pres = gst_element_query_position (bin, &fmt, &pos); + fmt = i; + dres = gst_element_query_duration (bin, &fmt, &dur); + printf ("%-8s : ", gst_format_get_name (i)); + print_value (pres, fmt, pos); + printf (" / "); + print_value (dres, fmt, dur); + printf ("\n"); + } + printf ("\n"); + + return TRUE; +} + +gint +main (gint argc, gchar ** argv) +{ + gint res = 1; + GstElement *bin; + GstBus *bus; + GMainLoop *loop; + const gchar *uri; + + gst_init (&argc, &argv); + + if (argc < 2) { + printf ("Usage: %s \n", argv[0]); + goto Error; + } + uri = argv[1]; + + /* build pipeline */ + bin = gst_element_factory_make ("playbin2", NULL); + if (!bin) { + GST_WARNING ("need playbin2 from gst-plugins-base"); + goto Error; + } + + g_object_set (bin, "uri", uri, NULL); + + loop = g_main_loop_new (NULL, TRUE); + + /* add watch for messages */ + bus = gst_pipeline_get_bus (GST_PIPELINE (bin)); + gst_bus_add_watch (bus, (GstBusFunc) bus_message, (gpointer) loop); + gst_object_unref (bus); + + /* add timeout for queries */ + g_timeout_add (1000, (GSourceFunc) run_queries, (gpointer) bin); + + /* run the show */ + if (gst_element_set_state (bin, + GST_STATE_PLAYING) != GST_STATE_CHANGE_FAILURE) { + g_main_loop_run (loop); + gst_element_set_state (bin, GST_STATE_NULL); + } + + /* cleanup */ + g_main_loop_unref (loop); + gst_object_unref (G_OBJECT (bin)); + res = 0; +Error: + return (res); +}