[gst-devel] Clocks

Wim Taymans wim.taymans at tvd.be
Tue Apr 4 00:11:05 CEST 2000


I was thinking about really synchronizing audio and video for
the mpeg player. I came up with something like this:

a new object called gstclock would be placed in the core library.

Waiting for a specific time would be handled by the superclock 
instead of the current code all over the elements (just the video
sink for now but..). 

All elements in the stream should register themselves to the clock
if they wish to use the clock. using gst_clock_register(GstElement *);

The clock then knows who has to be synchronised.

Now the tricky part: when do we start the clock? We can only start
the clock if we know that all elements are ready and the stream is
setup correctly. three options:

1. if all elements are succesfully changed to the PLAYING state the
   clock will start ticking. Since the buffers will start to flow
   whenever you do gst_source_push() some time could pass between
   the clock start and the first buffer reaching an element. This
   would result in no sync for the first few buffers depending on
   how much time would pass between PLAYING state change and source
   push.

2. the clock would be set to 0 if all the registered elements are
   waiting for the clock. At this time we know the elements are
   correctly setup and PLAYING. A typical MPEG player would have 
   the audiosink and videosink waiting for clock time 0 before they
   process the first buffer. If we then start the clock those two
   buffers would be released at the same time and we have a 
   perfect sync. This would not work off course if two elements in
   the same thread would be registered to the clock since the
   second element would never wait for the clock because the first 
   element is waiting and blocking the stream.

3. We could solve the problem of 2. by only letting sink elements 
   to block the clock. This could cause sync problems in the middle 
   of the stream (but only for the first frame).

4. We could solve problem 3. by finding dependencies in the stream.
   This sounds more difficult.

Also some elements know the time better than the clock itself like
the audiosink. It will become a master that can adjust the clock.

My plan:

 a gst_clock is needed with simple gst_clock_wait_for_time();
 implement gst_clock_register().
 implement option 3.
 implement gst_clock_register_master() and gst_clock_set_time();
 
Erik, does this come close to what you thought?

Wim


-- 
They use different words for things in America.
For instance they say elevator and we say lift.
They say drapes and we say curtains.
They say president and we say brain damaged git.
		-- Alexie Sayle




More information about the gstreamer-devel mailing list