[Kwintv] Re: Howto stop qtvision from autoscanning

Koos Vriezen koos.vriezen at xs4all.nl
Sun Dec 14 17:34:28 CET 2003


----- Forwarded message from Koos Vriezen <koos.vriezen at xs4all.nl> -----

Date: Sun, 14 Dec 2003 17:30:03 +0100
From: Koos Vriezen <koos.vriezen at xs4all.nl>
To: Dirk Ziegelmeier <dirk at ziegelmeier.net>
Subject: Re: [Kwintv] Re: Howto stop qtvision from autoscanning

On Sun, Dec 14, 2003 at 02:03:33PM +0100, Koos Vriezen wrote:
> On Sun, Dec 14, 2003 at 10:27:59AM +0100, Dirk Ziegelmeier wrote:
> > On Saturday 13 December 2003 22:27, Koos Vriezen wrote:
> > I think you fixed the crash on resize bug!!!!
> > I tracked it to your qApp->lock() change, that was the fix!
> > 
> > The QMutexLocker in updateClipping() sounded good, but it seems to have no 
> > effect, but it surely belongs there.
> > 
> > I tried resizing for about one minute, qtvision remained stable, without the 
> > qApp->lock() it crashes after a few seconds.
> 
> 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 :-/

> 
> Koos

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 15:26:22 -0000
@@ -94,7 +94,7 @@ public:
 };
 
 
-class V4LGrabber : public QThread {
+class V4LGrabber : public QObject, public QThread {
 public:
 	V4LGrabber(QObject *owner, V4LDev *dev, QMutex& devMtx, int gsn);
 	virtual ~V4LGrabber();
@@ -117,6 +117,7 @@ V4LGrabber::V4LGrabber(QObject *owner, V
 }
 
 V4LGrabber::~V4LGrabber() {
+    kdDebug() << "V4LGrabber::~V4LGrabber" << endl;
 }
 
 void V4LGrabber::run() {
@@ -153,6 +154,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();
@@ -171,6 +176,7 @@ _errors = 0;
 			break;
 		}
 	}
+        deleteLater();
 }
 
 
@@ -621,11 +627,10 @@ int QtVisionV4L::stopVideo()
 
     if (g) {
         g->stop();
-        g->wait();
-	V4LGrabber *t = g;
+        { // if grabber is in grab, wait for it
+            QMutexLocker l(&_devMtx);
+        }
 	g = 0;
-        delete t;
-	_w->erase();
     } else {  // overlay
         dev->stopCapture();
         delete _clipper;


----- End forwarded message -----


More information about the kwintv mailing list