[MPlayer-dev-eng] [PATCH][RESEND] XV page flipping synchronization
Piotr Neuman
sikkh at wp.pl
Mon Mar 22 22:58:14 CET 2004
On my desktop machine (Athlon XP 2000+, Gigabyte VIA VT266a, Radeon 9000,
XFree 4.3, kernel 2.6.4-ck1) there were some problems in synchronization of
video output (XV driver) - I could see for example 'tearing' (when double
buffering was used).
After some investigaton into it with help of Con Kolivas we were able to
conclude that on my kernel/hw configuration, there is priviledge inversion
issue (mplayer niced to +1 would work just fine). Such problems are usually
caused by how programs are written.
This problem may not have been apparent to others since most linux distros
ship w X window niced to -10 by default. I do not nice X (nice value 0)
becose nicing to -10 is just a poor scheduler workaround (X is no special app
and generally shouldn't need to be niced), and becose scheduler is much
inproved in 2.6 version of linux kernel.
It boils down to the usage of XFlush() in libvo/vo_xv.c . The problem is that
when synchronizing mplayer video buffer with X display, this function can't
ensure that X server will be given timeslice soon enough.
Mplayer can continue rendering of next frame/frames (when page flipping is
used) after calling XFlush but X server may not be able to update screen on
time, so few pages may be 'lost' (flipped at wrong time intervals beetween
each other).
My patch changes XFlush() call into XSync() which ensures that page will be
flipped properly on time (ie. when using -double switch), becose this call
waits till X has reported completion and gives free hand for system scheduler
to assing timeslice for X (thanks to blocking mplayer - preempting it).
Performance degradation is neglible, according to my limited testing. For
example for Matrix mirage trailer (matrix_tr_mirage_480.mov) (sound output
thru alsa1x):
before patching:
BENCHMARKs: VC: 13,746s VO: 1,344s A: 0,954s Sys: 43,573s = 59,617s
BENCHMARK%: VC: 23,0570% VO: 2,2551% A: 1,5997% Sys: 73,0882% = 100,0000%
after:
BENCHMARKs: VC: 11,691s VO: 4,802s A: 0,912s Sys: 42,216s = 59,621s
BENCHMARK%: VC: 19,6089% VO: 8,0539% A: 1,5296% Sys: 70,8077% = 100,0000%
With this change the output is synchronized very well, even though mplayer
uses usleep() timing (note that 2.6 kernels have clock set to 1000Hz, so
using rtc is uneceseary - A-V sync is ~ +- 0,005 at worst). The issue of
prority inversion is gone.
The patch also contains removal of unneceseary calls to XFlush function just
before XSync is called (XSync() alone suffices).
Regards.
Piotr Neuman
More information about the MPlayer-dev-eng
mailing list