AVSync

From Gnash Project Wiki

Jump to: navigation, search

There's an old standing bug preventing Audio and Video to be in sync when audio comes from embedded streams. This is usually due to missing synchronization mechanisms between the animation playhead thread and the audio mixer thread.

Generally speaking, when both audio and video use the same clock source, which is the case in gnash, everything should be in sync, except when one or the audio can't handle to go as fast as required by the SWF. Most of the time it's the renderer not being able to keep up, due to slowness of operations. Improving the renderer usually makes this less of a problem.


Contents

Examples of movies with good A/V sync

Examples of movies with bad A/V sync

The movie above runs fine as of revision 10916 on a dual-core. On lower-end machines it might still be a problem.

The movie above is focused on AV sync. It's music shown as a tracker-like timeline.

The most out-of-sync movie I've found online is the u2_has.swf one, attached in bug 19832. In this case AGG spends a lot of time rendering some animations, due to the distribution of changes on stage which force full redraw at every frame, and to some very poor performance in rendering something (gradients? TOCHECK).

Frame dropping effectively "fixes" the u2_has.swf case but makes other kind of animation, namely when A/V sync isn't important (unsynced sound during a videogame for instance).

NOTE: this movie plays out of sync with flashplayer 10 from adobe too on lower-end machines (no frames droppin seems implemented)

The frame dropping mechanism is discussed below.

Frame dropping

Gnash has a compile-time option to turn on frame-dropping. When enabled, rendering is skipped when it's time to advance the timelines again. The effect of this is that the average FPS is closer to the nominal one, at the cost of missing intermediate renderings.

The mechanism needs some kind of euristic to decide when it's not good to drop frames, some kind of limit on the number of frames that can be dropped. This is needed to avoid the user starving while waiting for another frame being drawed while gnash tries to catch up with the missed time.

References