Quantcast

GST system clock question

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

GST system clock question

smaynard
My project used to use 0.10.22 and assumed the system clock was always GST_CLOCK_TYPE_REALTIME.

We have recently updated to 0.10.35 and found that the default clock type is now GST_CLOCK_TYPE_MONOTONIC.

We were able to leave our code alone on Linux by simply setting the clock-type of the system clock to be GST_CLOCK_TYPE_REALTIME.  However, on win32, it appears to still behave in a monotonic fashion. Is this expected?  i.e. will we have to rewrite our code to work with a monotonic system clock so that it operates properly on both Linux and Win32?

Thanks.

GstClock* gstSystemClk = gst_system_clock_obtain();
g_object_set(gstSystemClk, "clock-type", GST_CLOCK_TYPE_REALTIME, NULL);
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: GST system clock question

smaynard
I believe this is the answer to my question (please correct me if I am wrong):

Switching the clock to REALTIME on Linux results in an accurate (as far as your RTC is set) systicks since epoch.  Performing the same action on Win32 (XP or 7) results in essentially not change from MONOTONIC unless you set the clock.  Therefore, when a REALTIME GST clock is desired on Win32 you need to set the calibration with a calculated systicks (which you can obtain by gettimeofday() and some math).

Below is a piece of my start-up code that handles this (and by the way doesn't perturb Linux):

+    GstClockTime tmp, internal, external, rate_num, rate_denom;
+    GstClockType clockType;
+    struct timeval tv;
+
+    g_object_get(gstSystemClk, "clock-type", &clockType, NULL);
+    GST_INFO("GST clockType: %s", clockType == 0? "REALTIME" : "MONOTONIC");
+    gst_clock_get_calibration(gstSystemClk,
+                              &internal, &external, &rate_num, &rate_denom);
+    GST_INFO("GST int: %llu, ext: %llu, num: %llu, denom: %llu",
+                              internal, external, rate_num, rate_denom);
+    internal = gst_clock_get_time(gstSystemClk);
+    GST_INFO("GST clockTime: %llu", internal);
+    gettimeofday(&tv, NULL);
+    external = tv.tv_sec;
+    external *= 1000000000;
+    tmp = tv.tv_usec;
+    tmp *= 1000;
+    external += tmp;
+    GST_INFO("GST external: %llu", external);
+    gst_clock_set_calibration(gstSystemClk,
+                              internal, external, rate_num, rate_denom);
+    GST_INFO("GST clockTime: %llu", gst_clock_get_time(gstSystemClk));

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: GST system clock question

Nicolas Dufresne
In reply to this post by smaynard
Le vendredi 30 mars 2012 à 13:26 -0700, smaynard a écrit :

> My project used to use 0.10.22 and assumed the system clock was always
> GST_CLOCK_TYPE_REALTIME.
>
> We have recently updated to 0.10.35 and found that the default clock type is
> now GST_CLOCK_TYPE_MONOTONIC.
>
> We were able to leave our code alone on Linux by simply setting the
> clock-type of the system clock to be GST_CLOCK_TYPE_REALTIME.  However, on
> win32, it appears to still behave in a monotonic fashion. Is this expected?
> i.e. will we have to rewrite our code to work with a monotonic system clock
> so that it operates properly on both Linux and Win32?

I'm not sure what you refer too by rewriting code, it depends on what
this code is. Monotonic time source is a clock that is never adjusted,
thus always goes forward. While the real time is (most of the time)
synchronized with time server, and frequently adjusted (can jump
backward). If you have code that handle time jump, it should just work
with a clock that is monotonic.

cheers,
Nicolas

_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Loading...