| 1 |
Time in Gstreamer |
| 2 |
|
| 3 |
When talking about time in streams (or "clocking"), people often confuse 3 |
| 4 |
different things that need to be treated separately. Older designs in GStreamer |
| 5 |
confused those and this made it difficult to design solutions for time |
| 6 |
management. |
| 7 |
|
| 8 |
1) clock time |
| 9 |
There are many clock providers in GStreamer. In normal circumstances there is |
| 10 |
only one clock, commonly referred to as the system clock. But in the GStreamer |
| 11 |
case there are others - like a sound card. If a sound card claims to output |
| 12 |
44100 samples/sec, one second in the sound cards clock has elapsed when 44100 |
| 13 |
samples have been processed. If a webcam claims to deliver 25 pictures/sec a |
| 14 |
second has elapsed after processing 25 pictures. This concept is useful in |
| 15 |
starvation cases - when you use the clock of the sound card and due to high |
| 16 |
load (or the hard disc of your laptop needing to start spinning again to read |
| 17 |
in an mp3) no samples are processed, the clock does not advance. A system clock |
| 18 |
would merrily go on ticking and make your song jump. |
| 19 |
|
| 20 |
2) element time |
| 21 |
Some elements need to know when to output a buffer. Therefore buffers have |
| 22 |
timestamps. But there needs to be a way those timestamps to the time reported by |
| 23 |
clocks. This is were element time comes in. GStreamer takes transparently care |
| 24 |
of this by remembering at what clock time you set your element to PLAYING and |
| 25 |
computes the time that has passed since then automatically. It takes care of the |
| 26 |
PAUSE state, too. There is even a way to adjust the time in the case of a |
| 27 |
discontinuity event (which most likely happens after seeking). |
| 28 |
|
| 29 |
3) synchronization |
| 30 |
It is a common case (especially in video playback) that people want to |
| 31 |
synchronize two elements (audio and video output), so that they report the same |
| 32 |
time. This is an unsolved problem in GStreamer and is only handled implicitly. |
| 33 |
To aid in this, clocks have "clock events". An event happens when an element |
| 34 |
does something, for example changing states. Because people want to set the |
| 35 |
states of multiple elements at once, but computers serialize everything, the |
| 36 |
actual state setting on the elements is serialized, too. If however such events |
| 37 |
happen shortly after each other, GStreamer assumes they were meant to happen at |
| 38 |
the same time and handles this as such. |
| 39 |
|