A replacement for the experimental AV sync algorithm currently in
MythTV.

Ordinarilly, MythTV uses the audio as the timebase - it plays the
audio at a constant rate and adjusts the video timing if it drifts out
of sync. This patch adds a "Use video as timebase" option,
which displays the video at a constant rate and dynamically warps the
audio speed to correct drift.

For systems synchronising with the vertical blanking interval of the,
graphics card in situations where the VBI is occurring at the same
frequency as the video's frame rate, adjusting the video timing
involves keeping a frame on screen for twice as long as it should be,
or dropping a frame entirely. This patch guarantees exactly one frame
per frame period (as much as can be guaranteed), which produces smoother
video.

For systems not synchronising with the VBI, the benefits are debatable.
If there is no vsync support available, /dev/rtc will be used as the
timebase, and if that isn't available then usleep() will be used as a
last resort.

The amount of audio warping needed to keep the audio and video in sync
is averaged over a 10 minute period and recorded in the settings. Next
time a video is played the audio warping is initialised to that value.
The hope is that on the same system, the A/V drift rate will always be
similar so the audio can be warped right from the start to keep it
synchronised.

The current version of this patch is obsolete as of MythTV
0.14. It has now been included in the official MythTV
release.

Change Log

2 January 2004

Buffers for the warped audio are nolonger allocated for each chunk of
audio, they are allocated once and grown if they are too small.

The amount audio can be warped is now clipped to slightly more sane
limits and this is now a #define called WARPCLIP.

If audio gets more than MAXDIVERGE (20) frames out of sync then frames
will now be dropped or extended to try and get the sync back by
brute-force (since large divergences cannot be corrected within a
reasonable time by warping the audio).

Vsync tollerance reduced to 1/4 of the refresh rate instead of 1/2 since
it could be possible to get 2 vsyncs per refresh when running in an
interlaced mode.

Nolonger calculates a new warpfactor or corrects divergence when the
video isn't playing at normal speed as this was breaking when
playing the video at high speed.

Removed some code for the /dev/rtc support that was left in there by
mistake and would never get executed anyway.