[Kwintv] Re: v4l fix

Koos Vriezen koos.vriezen at xs4all.nl
Sun Dec 14 23:08:19 CET 2003


Dirk wrote:
> On Sunday 14 December 2003 22:33, Koos Vriezen wrote:
> > Dirk wrote:
> > > I'm familiar with races and locking concepts, but I currently have no
> > > idea _why_ the qApp->lock() fixes the v4l plugin. All painting is now
> > > done in the grabber thread with the event loop waiting. But what's the
> > > difference between posting events (thread-safe) and copying a permanent
> > > buffer into a widget from the event loop? And where is a race condition
> > > in there???
> >
> > Note that in both cases painting is done while the event loop is waiting.
> Errr... why? The old postEvent() _queues_ the event in the event queue, and 
> the Qt event loop takes it from the queue and processes it. So painting is 
> done in Qt's event loop. sendEvent() processes the event immediately, so 
> painting is done in the grabber thread.

Yes, but in both cases the qt event loop is blocked, no? Old case, qt event
thread paint (and blocks during that). New case, grabber thread locks qApp and
paints (and blocks qt event queue during that)
 
> > My analyses was that the fatal io error occurs while doing
> > a ioctl in V4LDev::grab or V4LDev::initGrabbing by the grabber thread and
> > the main thread doing XvPutImage in KXvDevice::displayImage at the same
> > time. I guess that the race is in accessing XVideo or v4l kernel module.
> > (to really track this down would be to add a mutex on these I suppose and
> > see if it helps - if so, async grabbing and painting will never work)
> Hmmm. But why does it only happen on resize? The situation you describe should 
> nearly always happen during normal playback. It must have something to do 
> with the widget size change (the clipping was my favourite candidate until 
> today, but it was not the cause).

For me, it often crashed immediately until I added the mutex lock in
QtVisionV4L::event too. First I had the impression it crashed when doing
ioctl(_fd, VIDIOCSYNC, &nextFrame);, but later I saw it on other ioctl 
too. Maybe it's just that these ioctl's take longer when the size changes
and are more likely too happen, dunno.

Koos


More information about the kwintv mailing list