[Kwintv] Re: V4L Plugin - new success

Koos Vriezen koos.vriezen at xs4all.nl
Sun Dec 14 20:33:40 CET 2003


On Sun, Dec 14, 2003 at 01:04:58PM -0500, George Staikos wrote:
> On Sunday 14 December 2003 11:34, Koos Vriezen wrote:
> > > But please note that reading the image and displaying it, all runs in the
> > > grabber thread now (breaking the ring buffer idea).
> > > Also I've now some trouble closing qtvision..
> >
> > ...., I see my patch is wrong. It deadlocks in QtVisionV4L::stopVideo
> > g->wait() if the grabber is trying qApp->lock(). As a quick fix I tried the
> > attached patch and that works for switching between bttv device and XVideo,
> > but can fail if qtvision is closing and thread waiting for qApp->lock()
> > Grrr :-/
> 
>    Well your patch significantly improved performance.  If you want to hack at 
> this plugin, please feel free to commit as you see fit.  I think it's almost 
> possible to ship a beta with this!  I would appreciate some reports from 
> users who experienced "ripping" or other problems with V4L.  Does this fix 
> it?  I have 11.5% CPU usage in total over the three processes here.

Well, I have a better fix (although I consider it a dirty hack). Problem is
solved by temporary unlocking qApp and then wait for the grabber thread. It 
will exit on the second test for the _stopSem after retrieving the lock.
However if another thread does a qApp->lock() it can fail miserably :-(, but
that isn't done anyware afaics (but might be a time bomb of course).

Alternatively, qtvision should be aware of async stopping threads and wait
for it after the event loop has ended in main(). And maybe add some
QTimer::singleShot here and there for closing/starting stuff..

There is still a deadlock somewhere when grabbing is on and showing the channel
wizard. I guess it should stop grabbing first, no?

>   Koos: great work!

Thanks, and I'm happy it works for me now too. Great application!

Koos
-------------- next part --------------
Index: qtvision/plugins/video/v4l/qtvision_v4l.cpp
===================================================================
RCS file: /home/kde/kdenonbeta/kwintv3/qtvision/plugins/video/v4l/qtvision_v4l.cpp,v
retrieving revision 1.64
diff -u -3 -p -r1.64 qtvision_v4l.cpp
--- qtvision/plugins/video/v4l/qtvision_v4l.cpp	14 Dec 2003 09:16:16 -0000	1.64
+++ qtvision/plugins/video/v4l/qtvision_v4l.cpp	14 Dec 2003 18:42:24 -0000
@@ -153,6 +153,10 @@ _errors = 0;
 			<< " time: " << tv3.tv_sec << "."
 			<< tv3.tv_usec << endl; */
                         qApp->lock();
+                        if (_stopSem.available() == 0) {
+                            qApp->unlock();
+                            break;
+                        }
                         BLTEvent event(BLTEvent::BLTImage,_buf[bl],_gsn);
                         QApplication::sendEvent(_owner, &event);
                         qApp->unlock();
@@ -621,8 +625,10 @@ int QtVisionV4L::stopVideo()
 
     if (g) {
         g->stop();
-        g->wait();
 	V4LGrabber *t = g;
+	qApp->unlock(); // unbelievable hack
+        g->wait();
+	qApp->lock();
 	g = 0;
         delete t;
 	_w->erase();


More information about the kwintv mailing list