Index: trunk/MagicSoft/AMC/activemirrorcontrol/activemirrorcontrol/amcframegrabber.cpp
===================================================================
--- trunk/MagicSoft/AMC/activemirrorcontrol/activemirrorcontrol/amcframegrabber.cpp	(revision 4478)
+++ trunk/MagicSoft/AMC/activemirrorcontrol/activemirrorcontrol/amcframegrabber.cpp	(revision 4479)
@@ -7,4 +7,5 @@
 {
 	m_pMutex = new QMutex();
+  m_zActive = false;
 
 	m_iOffset = 0;
@@ -89,4 +90,5 @@
 AMCFrameGrabber::~AMCFrameGrabber()
 {
+	delete m_pMutex;
 	//closing the device and freeing allocated memory.
 	close(m_iVid);
@@ -100,4 +102,8 @@
 int AMCFrameGrabber::grabFrame(u_char *data)
 {
+	m_pMutex->lock();
+	m_zActive = true;
+	m_pMutex->unlock();
+
   fd_set rfds;
   FD_ZERO(&rfds);
@@ -107,6 +113,6 @@
   tv.tv_usec = 1000;
   int retval = select(m_iVid+1, &rfds, NULL, NULL, &tv);
-  if( ! retval )
-    qDebug("Timed out waiting for frame");
+//  if( ! retval )
+//    qDebug("Timed out waiting for frame");
 
   int n;
@@ -115,4 +121,8 @@
   //one can do a tricky thing with pointers.
     
+	m_pMutex->lock();
+	m_zActive = false;
+	m_pMutex->unlock();
+
 	if (n < 0)
 	{
@@ -277,2 +287,23 @@
 	return stCtrl.value;
 }
+
+/**
+ * If we are still grabbing a video frame, wait until we are done.
+ * In case we are active in grabbing a frame we sleep for 20ms (should be
+ * enough time to grab an NTSC frame) to unload the system.
+ */
+void AMCFrameGrabber::waitTillInactive()
+{
+	for(;;)
+	{
+		m_pMutex->lock();
+		if( ! m_zActive )
+		{
+			m_pMutex->unlock();
+			return;
+		}
+		m_pMutex->unlock();
+		usleep(20000);
+	}
+  return;
+}
Index: trunk/MagicSoft/AMC/activemirrorcontrol/activemirrorcontrol/amcframegrabber.h
===================================================================
--- trunk/MagicSoft/AMC/activemirrorcontrol/activemirrorcontrol/amcframegrabber.h	(revision 4478)
+++ trunk/MagicSoft/AMC/activemirrorcontrol/activemirrorcontrol/amcframegrabber.h	(revision 4479)
@@ -78,4 +78,6 @@
 	/** */
 	virtual QMutex* getMutex() { return( m_pMutex ); };
+  /** No descriptions */
+  void waitTillInactive();
 
 protected: // Protected methods
@@ -125,4 +127,5 @@
 	struct v4l2_standard		m_stStdNTSC;
 	QMutex*									m_pMutex;
+	bool										m_zActive;
 };
 
