[Live-devel] Synchrnozing video and audio using OnDemandServerMediaSubsessions

Ross Finlayson finlayson at live555.com
Thu Oct 2 17:16:13 PDT 2008


>void CH263plusVideoDXFrameSource::setPresentationTime()
>{
>         // Check if this is the first frame we send
>         if (fPresentationTime.tv_sec == 0 && fPresentationTime.tv_usec == 0)
>         {
>                 // This is the first frame, so we set the current time
>                 gettimeofday(&this->fPresentationTime, NULL);
>         }
>         else
>         {
>                 // These are the following  frames, so we set the previous
>presentation time plus the frame duration
>                 fPresentationTime.tv_usec += this->fDurationInMicroseconds;
>
>                 if(fPresentationTime.tv_usec>=1000000)
>                 {
>                         fPresentationTime.tv_sec++;
>                         fPresentationTime.tv_usec =
>fPresentationTime.tv_usec -                     1000000;
>                 }
>         }
>}

Where does your H.263+ video data come from?  If it comes from a live 
source (i.e., an encoder), then you may run into problems (clock 
drift) by calling "gettimeofday()" just once, and then incrementing 
the time by what you think is the duration of each frame.  Instead, 
you should set the presentation time by calling "gettimeofday()" 
*each time* you get a frame from the encoder, because then you'll be 
giving the frame a time that you know is accurate.

You should do the same thing for audio (again, if it comes from a live source).

(If, however, you're reading audio+video data from a file, you should 
call "gettimeofday()" just once (but you still need to be careful 
about giving both audio and video accurate (i.e., synchronized) 
presentation times.)



	Ross Finlayson
	Live Networks, Inc. (LIVE555.COM)
	<http://www.live555.com/>



More information about the live-devel mailing list