View Single Post
Old 03-01-04, 03:49 AM   #1
Registered User
Join Date: Mar 2004
Posts: 5
Default Xvideo and syncing to Vblank


I'm working on a project that uses high-resolution video (1280x720 at 30 fps), which pretty much makes Xvideo a "must" -- doing YUV->RGB in software isn't really an option, because we're already doing some image processing on the video that just about maxes out a 2.8 GHz Pentium 4 at this frame rate.

I've done a few experiments and concluded that Xvideo does sync to the vblank -- I'm not getting any tearing -- but apparently XvPutImage/XFlush don't block but return immediately. At the moment, I'm using usleep to schedule my redraws, which is OK, but it does mean that I may get slight stutter in the output -- say I'm running at a refresh rate of 60 Hz, so I would want every frame to be displayed for exactly two refreshes, but since I'm not synced to the actual refresh, it can happen that, every so often, a frame gets displayed for three refreshes or only one refresh. Since our project is about measuring the eye movements that people make in response to visual cues, we obviously want our video to be as smooth as possible.

I know that under OpenGL, I can sync to the vblank in glXSwapBuffers by setting the __GL_SYNC_TO_VBLANK environment variable to 1; I'd like to be able to do something similar under Xvideo. (OpenGL is too slow for our purposes because, as explained above, we'd have to do YUV->RGB in software.) I've even tried "hijacking" OpenGL to do my synchronization by calling glXSwapBuffers (to wait for the vertical retrace) before calling XvPutImage/XFlush, but that didn't work -- my application did sync to the refresh rate, but I got some tearing in the Xvideo window that wasn't there before (guess that serves me right for attempting such an ugly hack... ;-) ).

Is there any way of getting what I want? I would have no qualms about doing something that's Nvidia-specific or even specific for a certain driver version -- this app is only going to run on our own hardware. If syncing to the vblank isn't possible with the current driver version, is there any chance of this being implemented in the future?


Martin Boehme
mboehme is offline   Reply With Quote