gstreamer/tests/old/testsuite/clock/clock4.c
Wim Taymans 484d9a3224 Added more docs.
Original commit message from CVS:
* docs/design/part-clocks.txt:
* docs/design/part-events.txt:
* gst/elements/gstfakesrc.c: (gst_fakesrc_get_event_mask),
(gst_fakesrc_event_handler), (gst_fakesrc_loop),
(gst_fakesrc_activate):
* gst/gstclock.c: (gst_clock_id_ref), (gst_clock_id_unref),
(gst_clock_id_compare_func), (gst_clock_id_wait),
(gst_clock_id_wait_async), (gst_clock_init),
(gst_clock_adjust_unlocked), (gst_clock_get_time):
* gst/gstevent.c: (gst_event_new_discontinuous_valist),
(gst_event_discont_get_value), (gst_event_new_segment_seek):
* gst/gstevent.h:
* gst/gstpipeline.c: (gst_pipeline_init), (is_eos),
(pipeline_bus_handler), (gst_pipeline_change_state):
* gst/gstpipeline.h:
* gst/gstsystemclock.c: (gst_system_clock_init),
(gst_system_clock_async_thread),
(gst_system_clock_id_wait_unlocked),
(gst_system_clock_id_wait_async), (gst_system_clock_id_unschedule):
* libs/gst/dataprotocol/dataprotocol.c: (gst_dp_packet_from_event),
(gst_dp_event_from_packet):
* testsuite/clock/Makefile.am:
* testsuite/clock/clock4.c: (gst_clock_debug), (ok_callback),
(error_callback), (main):
Added more docs.
Remove more silly events.
Implement periodic clock notifications.
Add async testsuite.
2005-02-11 15:50:53 +00:00

100 lines
2.5 KiB
C

/*
* 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 <gst/gst.h>
static GstClock *clock = NULL;
void
gst_clock_debug (GstClock * clock)
{
GstClockTime time;
time = gst_clock_get_time (clock);
g_print ("Clock info: time %" G_GUINT64_FORMAT "\n", time);
}
static gboolean
ok_callback (GstClock * clock, GstClockTime time,
GstClockID id, gpointer user_data)
{
g_print ("unlocked async id %p\n", id);
return FALSE;
}
static gboolean
error_callback (GstClock * clock, GstClockTime time,
GstClockID id, gpointer user_data)
{
g_print ("unlocked unscheduled async id %p, this is wrong\n", id);
g_assert_not_reached ();
return FALSE;
}
int
main (int argc, char *argv[])
{
GstClockID id, id2;
GstClockTime base;
GstClockReturn result;
gst_init (&argc, &argv);
clock = gst_system_clock_obtain ();
g_assert (clock != NULL);
gst_clock_debug (clock);
base = gst_clock_get_time (clock);
/* signal every half a second */
id = gst_clock_new_periodic_id (clock, base + GST_SECOND, GST_SECOND / 2);
g_assert (id);
g_print ("waiting one second\n");
result = gst_clock_id_wait (id, NULL);
gst_clock_debug (clock);
g_assert (result == GST_CLOCK_OK);
g_print ("waiting for the next\n");
result = gst_clock_id_wait (id, NULL);
gst_clock_debug (clock);
g_assert (result == GST_CLOCK_OK);
g_print ("waiting for the next async %p\n", id);
result = gst_clock_id_wait_async (id, ok_callback, NULL);
g_assert (result == GST_CLOCK_OK);
g_usleep (2 * G_USEC_PER_SEC);
g_print ("waiting some more for the next async %p\n", id);
result = gst_clock_id_wait_async (id, ok_callback, NULL);
g_assert (result == GST_CLOCK_OK);
g_usleep (2 * G_USEC_PER_SEC);
id2 = gst_clock_new_periodic_id (clock, base + GST_SECOND, GST_SECOND / 2);
g_assert (id2);
g_print ("waiting some more for another async %p\n", id2);
result = gst_clock_id_wait_async (id2, ok_callback, NULL);
g_assert (result == GST_CLOCK_OK);
g_usleep (2 * G_USEC_PER_SEC);
g_print ("unschedule %p\n", id);
gst_clock_id_unschedule (id);
/* entry cannot be used again */
result = gst_clock_id_wait_async (id, error_callback, NULL);
g_assert (result == GST_CLOCK_UNSCHEDULED);
result = gst_clock_id_wait (id, NULL);
g_assert (result == GST_CLOCK_UNSCHEDULED);
g_usleep (2 * G_USEC_PER_SEC);
/* success */
return 0;
}