{"id":1181,"date":"2024-01-15T14:26:45","date_gmt":"2024-01-15T06:26:45","guid":{"rendered":"https:\/\/www.fanyamin.com\/wordpress\/?p=1181"},"modified":"2024-01-15T14:30:04","modified_gmt":"2024-01-15T06:30:04","slug":"clocks-and-synchronization-in-gstreamer","status":"publish","type":"post","link":"https:\/\/www.fanyamin.com\/wordpress\/?p=1181","title":{"rendered":"Clocks and synchronization in GStreamer"},"content":{"rendered":"<h2>Synchronization Overivew<\/h2>\n<p>A GstClock returns the absolute-time according to that clock with gst_clock_get_time (). The absolute-time (or clock time) of a clock is monotonically increasing.<\/p>\n<p>A running-time is the difference between a previous snapshot of the absolute-time called the base-time, and any other absolute-time.<\/p>\n<pre><code>running-time = absolute-time - base-time<\/code><\/pre>\n<p>Synchronization is now a matter of making sure that a buffer with a certain running-time is played when the clock reaches the same running-time. <\/p>\n<p>A GStreamer GstPipeline object maintains a GstClock object and a base-time when it goes to the PLAYING state. The pipeline gives a handle to the selected GstClock to each element in the pipeline along with selected base-time. The pipeline will select a base-time in such a way that the running-time reflects the total time spent in the PLAYING state. As a result, when the pipeline is PAUSED, the running-time stands still.<\/p>\n<p>Because all objects in the pipeline have the same clock and base-time, they can thus all calculate the running-time according to the pipeline clock.<\/p>\n<h2>Time overview<\/h2>\n<p>Here is an overview of the various timelines used in GStreamer.<\/p>\n<p>The image below represents the different times in the pipeline when playing a 100ms sample and repeating the part between 50ms and 100m<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.fanyamin.com\/wordpress\/wp-content\/uploads\/2024\/01\/image-1705300002105.png\" alt=\"file\" \/><\/p>\n<p>You can see how the running-time of a buffer always increments monotonically along with the clock-time. Buffers are played when their running-time is equal to the clock-time - base-time. The stream-time represents the position in the stream and jumps backwards when repeating.<\/p>\n<h2>Reference<\/h2>\n<ul>\n<li><a href=\"https:\/\/gstreamer.freedesktop.org\/documentation\/application-development\/advanced\/clocks.html?gi-language=c\">https:\/\/gstreamer.freedesktop.org\/documentation\/application-development\/advanced\/clocks.html?gi-language=c<\/a><\/li>\n<li><a href=\"https:\/\/gstreamer.freedesktop.org\/documentation\/additional\/design\/synchronisation.html?gi-language=c\">https:\/\/gstreamer.freedesktop.org\/documentation\/additional\/design\/synchronisation.html?gi-language=c<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Synchronization Overivew A GstClock returns the absolute-time according to that clock with gst_clock_get_time (). The absolute-time (or clock time) of a clock is monotonically increasing. A running-time is the difference between a previous snapshot of the absolute-time called the base-time, and any other absolute-time. running-time = absolute-time &#8211; base-time Synchronization is now a matter of [&hellip;] <a class=\"read-more\" href=\"https:\/\/www.fanyamin.com\/wordpress\/?p=1181\" title=\"Permanent Link to: Clocks and synchronization in GStreamer\">&rarr;Read&nbsp;more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1181","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1181"}],"collection":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1181"}],"version-history":[{"count":3,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1181\/revisions"}],"predecessor-version":[{"id":1185,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1181\/revisions\/1185"}],"wp:attachment":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1181"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}