[Kwintv] Playing with v4l plugin...

Dirk Ziegelmeier dziegel at gmx.de
Sun Jan 18 17:29:41 CET 2004


I've been looking a bit into the v4l plugin...

- The internal v4limage object only has got a reference to the original grab 
buffer, NOT an internal copy. This is the main for the crashes we experienced 
before Koos introduced the qApp->lock() calls. When the window is resized, 
the grab buffers are changed in location and/or size. But the v4limage still 
contains a pointer to the old buffer, so the painting into the tv widget form 
the GUI thread segfaults. Locking the GUI thread (no resizes) and doing the 
painting work from the grabber thread ensures buffer consistency.

- I have been experimenting a bit with different approaches to solve the 
problem. I changed v4limage to create private copies of the image, and the 
crashes disappeared, no aquiring of the Qt library mutex is necessary. 
Creating these copies of the image consumes ~7% more CPU time on my box 
(Athlon 2000+). But the playback quality was not satisfactory ("ripping" and 
"jumpy" video playback). So I started experimenting with different approaches 
to do the widget painting:

- everything that involves a ring buffer of more than 2 or 3 v4limage yields a 
noticeable delay between video and audio or "jumpy" video playback.

- Always grabbing into one image (only locking the buffer accesses between the 
threads) and painting using a routine called by a QTimer also has many 
"ripping" and "jumping" problems.
 
So my conclusion is: Painting cannot be done from the GUI thread. It runs to 
"irregular" for streaming applications. We have to do it from another thread 
and lock accesses to the buffer to be painted (that what we do now). If we do 
deinterlacing some day, we also have to do it in that thread.

I'll try to figure out a working solution that does not use the Qt library 
mutex but locks all code parts that influence the grab buffer instead in the 
next days. This will make obsolete the "unelegant" grabber thread shutdown 
code. Maybe I'll create a new plugin for my experiments so I don't break the 
currently quite stable v4l plugin.

Dirk


More information about the kwintv mailing list