From b172752619b35e5c8b794af1a4ead0a422aa65d8 Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Tue, 23 Apr 2002 19:12:54 +0000 Subject: [PATCH] adding clock example Original commit message from CVS: adding clock example --- tests/old/testsuite/Makefile.am | 4 +- tests/old/testsuite/clock/Makefile.am | 9 ++++ tests/old/testsuite/clock/clock1.c | 70 +++++++++++++++++++++++++++ testsuite/Makefile.am | 4 +- testsuite/clock/Makefile.am | 9 ++++ testsuite/clock/clock1.c | 70 +++++++++++++++++++++++++++ 6 files changed, 162 insertions(+), 4 deletions(-) create mode 100644 tests/old/testsuite/clock/Makefile.am create mode 100644 tests/old/testsuite/clock/clock1.c create mode 100644 testsuite/clock/Makefile.am create mode 100644 testsuite/clock/clock1.c diff --git a/tests/old/testsuite/Makefile.am b/tests/old/testsuite/Makefile.am index 0e41698657..e30ac2432a 100644 --- a/tests/old/testsuite/Makefile.am +++ b/tests/old/testsuite/Makefile.am @@ -1,5 +1,5 @@ # FIXME : refcounting threads bytestream cleanup -SUBDIRS = caps plugin elements ## dynparams +SUBDIRS = caps plugin elements clock ## dynparams testprogs = test_gst_init @@ -12,4 +12,4 @@ LIBS = $(GST_LIBS) CFLAGS = $(GST_CFLAGS) # FIXME : refcounting threadds -DIST_SUBDIRS = caps plugin bytestream cleanup elements dynparams +DIST_SUBDIRS = caps plugin bytestream cleanup elements dynparams clock diff --git a/tests/old/testsuite/clock/Makefile.am b/tests/old/testsuite/clock/Makefile.am new file mode 100644 index 0000000000..1d5ded210b --- /dev/null +++ b/tests/old/testsuite/clock/Makefile.am @@ -0,0 +1,9 @@ +testprogs = clock1 + +TESTS = $(testprogs) + +check_PROGRAMS = $(testprogs) + +LDADD = $(GST_LIBS) +CFLAGS = $(GST_CFLAGS) + diff --git a/tests/old/testsuite/clock/clock1.c b/tests/old/testsuite/clock/clock1.c new file mode 100644 index 0000000000..6590a77c16 --- /dev/null +++ b/tests/old/testsuite/clock/clock1.c @@ -0,0 +1,70 @@ +/* + * testsuite program to test clock behaviour + * + * creates a fakesrc ! identity ! fakesink pipeline + * registers a callback on fakesrc and one on fakesink + * also register a normal GLib timeout which should not be reached + */ + +#include +void +gst_clock_debug (GstClock *clock) +{ + g_print ("Clock info: speed %f, active %s, time %d\n", + gst_clock_get_speed (clock), + gst_clock_is_active (clock) ? "yes" : "no", + (gint) gst_clock_get_time (clock) + ); +} + +int +main (int argc, char *argv[]) +{ + GstElement *src, *id, *sink, *pipeline; + GstClock *clock = NULL; + + gst_init (&argc, &argv); + + if ((src = gst_element_factory_make ("fakesrc", "source")) == NULL) + { + g_print ("Could not create a fakesrc element !\n"); + return 1; + } + if ((id = gst_element_factory_make ("identity", "filter")) == NULL) + { + g_print ("Could not create a identity element !\n"); + return 1; + } + if ((sink = gst_element_factory_make ("fakesink", "sink")) == NULL) + { + g_print ("Could not create a fakesink element !\n"); + return 1; + } + + if ((pipeline = gst_pipeline_new ("pipeline")) == NULL) + { + g_print ("Could not create a pipeline element !\n"); + return 1; + } + + gst_element_connect_many (src, id, sink, NULL); + gst_bin_add_many (GST_BIN (pipeline), src, id, sink, NULL); + + clock = gst_bin_get_clock (GST_BIN (pipeline)); + g_assert (clock != NULL); + gst_clock_debug (clock); + gst_clock_set_active (clock, TRUE); + gst_clock_debug (clock); + //clock = gst_clock_new ("clock"); + //gst_element_set_clock (src, clock); + //clock = gst_element_get_clock (src); + //g_assert (clock != NULL); + + gst_bin_iterate (GST_BIN (pipeline)); + gst_clock_debug (clock); + gst_clock_debug (clock); + gst_clock_debug (clock); + + /* success */ + return 0; +} diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am index 0e41698657..e30ac2432a 100644 --- a/testsuite/Makefile.am +++ b/testsuite/Makefile.am @@ -1,5 +1,5 @@ # FIXME : refcounting threads bytestream cleanup -SUBDIRS = caps plugin elements ## dynparams +SUBDIRS = caps plugin elements clock ## dynparams testprogs = test_gst_init @@ -12,4 +12,4 @@ LIBS = $(GST_LIBS) CFLAGS = $(GST_CFLAGS) # FIXME : refcounting threadds -DIST_SUBDIRS = caps plugin bytestream cleanup elements dynparams +DIST_SUBDIRS = caps plugin bytestream cleanup elements dynparams clock diff --git a/testsuite/clock/Makefile.am b/testsuite/clock/Makefile.am new file mode 100644 index 0000000000..1d5ded210b --- /dev/null +++ b/testsuite/clock/Makefile.am @@ -0,0 +1,9 @@ +testprogs = clock1 + +TESTS = $(testprogs) + +check_PROGRAMS = $(testprogs) + +LDADD = $(GST_LIBS) +CFLAGS = $(GST_CFLAGS) + diff --git a/testsuite/clock/clock1.c b/testsuite/clock/clock1.c new file mode 100644 index 0000000000..6590a77c16 --- /dev/null +++ b/testsuite/clock/clock1.c @@ -0,0 +1,70 @@ +/* + * testsuite program to test clock behaviour + * + * creates a fakesrc ! identity ! fakesink pipeline + * registers a callback on fakesrc and one on fakesink + * also register a normal GLib timeout which should not be reached + */ + +#include +void +gst_clock_debug (GstClock *clock) +{ + g_print ("Clock info: speed %f, active %s, time %d\n", + gst_clock_get_speed (clock), + gst_clock_is_active (clock) ? "yes" : "no", + (gint) gst_clock_get_time (clock) + ); +} + +int +main (int argc, char *argv[]) +{ + GstElement *src, *id, *sink, *pipeline; + GstClock *clock = NULL; + + gst_init (&argc, &argv); + + if ((src = gst_element_factory_make ("fakesrc", "source")) == NULL) + { + g_print ("Could not create a fakesrc element !\n"); + return 1; + } + if ((id = gst_element_factory_make ("identity", "filter")) == NULL) + { + g_print ("Could not create a identity element !\n"); + return 1; + } + if ((sink = gst_element_factory_make ("fakesink", "sink")) == NULL) + { + g_print ("Could not create a fakesink element !\n"); + return 1; + } + + if ((pipeline = gst_pipeline_new ("pipeline")) == NULL) + { + g_print ("Could not create a pipeline element !\n"); + return 1; + } + + gst_element_connect_many (src, id, sink, NULL); + gst_bin_add_many (GST_BIN (pipeline), src, id, sink, NULL); + + clock = gst_bin_get_clock (GST_BIN (pipeline)); + g_assert (clock != NULL); + gst_clock_debug (clock); + gst_clock_set_active (clock, TRUE); + gst_clock_debug (clock); + //clock = gst_clock_new ("clock"); + //gst_element_set_clock (src, clock); + //clock = gst_element_get_clock (src); + //g_assert (clock != NULL); + + gst_bin_iterate (GST_BIN (pipeline)); + gst_clock_debug (clock); + gst_clock_debug (clock); + gst_clock_debug (clock); + + /* success */ + return 0; +}