From 0e0caaf16a98d999c09811afb651528f4fa559b8 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 28 Nov 2007 10:58:39 +0000 Subject: [PATCH] Start merging in the easy bits of #361155, the monotonic clock patch. Original commit message from CVS: * docs/gst/gstreamer-sections.txt: * gst/gstclock.h: * tests/check/gst/gstsystemclock.c: (GST_START_TEST), (gst_systemclock_suite): Start merging in the easy bits of #361155, the monotonic clock patch. This one adds a few handy macros with docs and a testsuite. --- ChangeLog | 9 ++++++++ docs/gst/gstreamer-sections.txt | 4 ++++ gst/gstclock.h | 35 ++++++++++++++++++++++++++++++++ tests/check/gst/gstsystemclock.c | 21 +++++++++++++++++++ 4 files changed, 69 insertions(+) diff --git a/ChangeLog b/ChangeLog index 15b86ee133..e06c65ab8f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2007-11-28 Wim Taymans + + * docs/gst/gstreamer-sections.txt: + * gst/gstclock.h: + * tests/check/gst/gstsystemclock.c: (GST_START_TEST), + (gst_systemclock_suite): + Start merging in the easy bits of #361155, the monotonic clock patch. + This one adds a few handy macros with docs and a testsuite. + 2007-11-27 Wim Taymans * plugins/elements/gstfilesink.c: (gst_file_sink_event): diff --git a/docs/gst/gstreamer-sections.txt b/docs/gst/gstreamer-sections.txt index ceda146c7d..04de83741a 100644 --- a/docs/gst/gstreamer-sections.txt +++ b/docs/gst/gstreamer-sections.txt @@ -311,6 +311,10 @@ GST_SECOND GST_MSECOND GST_USECOND GST_NSECOND +GST_TIME_AS_SECONDS +GST_TIME_AS_MSECONDS +GST_TIME_AS_USECONDS +GST_TIME_AS_NSECONDS GST_CLOCK_DIFF GST_TIMEVAL_TO_TIME GST_TIME_TO_TIMEVAL diff --git a/gst/gstclock.h b/gst/gstclock.h index bc7a9aa92b..3c07d044ce 100644 --- a/gst/gstclock.h +++ b/gst/gstclock.h @@ -106,6 +106,41 @@ typedef gpointer GstClockID; */ #define GST_NSECOND (GST_SECOND / G_GINT64_CONSTANT (1000000000)) + +/** + * GST_TIME_AS_SECONDS: + * @time: the time + * + * Convert a #GstClockTime to seconds. + * + * Since: 0.10.16 + */ +#define GST_TIME_AS_SECONDS(time) ((time) / GST_SECOND) +/** + * GST_TIME_AS_MSECONDS: + * + * Convert a #GstClockTime to milliseconds (1/1000 of a second). + * + * Since: 0.10.16 + */ +#define GST_TIME_AS_MSECONDS(time) ((time) / G_GINT64_CONSTANT (1000000)) +/** + * GST_TIME_TO_USECONDS: + * + * Convert a #GstClockTime to microseconds (1/1000000 of a second). + * + * Since: 0.10.16 + */ +#define GST_TIME_AS_USECONDS(time) ((time) / G_GINT64_CONSTANT (1000)) +/** + * GST_TIME_TO_NSECONDS: + * + * Convert a #GstClockTime to nanoseconds (1/1000000000 of a second). + * + * Since: 0.10.16 + */ +#define GST_TIME_AS_NSECONDS(time) (time) + /** * GST_CLOCK_DIFF: * @s: the first time diff --git a/tests/check/gst/gstsystemclock.c b/tests/check/gst/gstsystemclock.c index 68cc0c5df1..299c9cade3 100644 --- a/tests/check/gst/gstsystemclock.c +++ b/tests/check/gst/gstsystemclock.c @@ -21,6 +21,26 @@ #include +/* see if the defines make sense */ +GST_START_TEST (test_range) +{ + GstClockTime time, time2; + + time = GST_SECOND; + fail_unless (time == G_GUINT64_CONSTANT (1000000000)); + + time2 = time / 1000; + fail_unless (time2 == 1000000); + fail_unless (time2 == GST_MSECOND); + fail_unless (time2 == GST_TIME_AS_USECONDS (time)); + + time2 = time / 1000000; + fail_unless (time2 == 1000); + fail_unless (time2 == GST_USECOND); + fail_unless (time2 == GST_TIME_AS_MSECONDS (time)); +} + +GST_END_TEST GST_START_TEST (test_signedness) { GstClockTime time[] = { 0, 1, G_MAXUINT64 / GST_SECOND }; @@ -386,6 +406,7 @@ gst_systemclock_suite (void) TCase *tc_chain = tcase_create ("waiting"); suite_add_tcase (s, tc_chain); + tcase_add_test (tc_chain, test_range); tcase_add_test (tc_chain, test_signedness); tcase_add_test (tc_chain, test_single_shot); tcase_add_test (tc_chain, test_periodic_shot);