Revision: 19139
http://opalvoip.svn.sourceforge.net/opalvoip/?rev=19139&view=rev
Author: rjongbloed
Date: 2007-12-20 04:29:53 -0800 (Thu, 20 Dec 2007)
Log Message:
-----------
Added mutexes so both VfW grabber and the windows video output device can survive Close() being called from multiple threads.
Modified Paths:
--------------
ptlib/trunk/src/ptlib/msos/vfw.cxx
Modified: ptlib/trunk/src/ptlib/msos/vfw.cxx
===================================================================
--- ptlib/trunk/src/ptlib/msos/vfw.cxx 2007-12-20 11:08:20 UTC (rev 19138)
+++ ptlib/trunk/src/ptlib/msos/vfw.cxx 2007-12-20 12:29:53 UTC (rev 19139)
@@ -316,12 +316,13 @@
PSyncPoint threadStarted;
HWND hCaptureWindow;
+ PMutex operationMutex;
PSyncPoint frameAvailable;
LPBYTE lastFramePtr;
unsigned lastFrameSize;
PMutex lastFrameMutex;
- PBoolean isCapturingNow;
+ bool isCapturingNow;
PAdaptiveDelay m_Pacing;
};
@@ -504,12 +505,19 @@
{
Close();
+ operationMutex.Wait();
+
deviceName = devName;
captureThread = PThread::Create(PCREATE_NOTIFIER(HandleCapture), 0,
PThread::NoAutoDeleteThread, PThread::NormalPriority,
"VidIn:%x");
+
+ operationMutex.Signal();
threadStarted.Wait();
+
+ PWaitAndSignal mutex(operationMutex);
+
if (hCaptureWindow == NULL) {
delete captureThread;
captureThread = NULL;
@@ -531,6 +539,8 @@
PBoolean PVideoInputDevice_VideoForWindows::Close()
{
+ PWaitAndSignal mutex(operationMutex);
+
if (!IsOpen())
return PFalse;
@@ -561,6 +571,8 @@
PBoolean PVideoInputDevice_VideoForWindows::Start()
{
+ PWaitAndSignal mutex(operationMutex);
+
if (IsCapturing())
return PTrue;
@@ -583,6 +595,8 @@
PBoolean PVideoInputDevice_VideoForWindows::Stop()
{
+ PWaitAndSignal mutex(operationMutex);
+
if (!IsCapturing())
return PFalse;
isCapturingNow = PFalse;
@@ -607,6 +621,8 @@
PBoolean PVideoInputDevice_VideoForWindows::SetColourFormat(const PString & colourFmt)
{
+ PWaitAndSignal mutex(operationMutex);
+
if (!IsOpen())
return PVideoDevice::SetColourFormat(colourFmt); // Not open yet, just set internal variables
@@ -656,6 +672,8 @@
PBoolean PVideoInputDevice_VideoForWindows::SetFrameRate(unsigned rate)
{
+ PWaitAndSignal mutex(operationMutex);
+
if (!PVideoDevice::SetFrameRate(rate))
return PFalse;
@@ -700,6 +718,8 @@
PBoolean PVideoInputDevice_VideoForWindows::SetFrameSize(unsigned width, unsigned height)
{
+ PWaitAndSignal mutex(operationMutex);
+
if (!IsOpen())
return PVideoDevice::SetFrameSize(width, height); // Not open yet, just set internal variables
@@ -806,6 +826,8 @@
PINDEX PVideoInputDevice_VideoForWindows::GetMaxFrameBytes()
{
+ PWaitAndSignal mutex(operationMutex);
+
if (!IsOpen())
return 0;
@@ -1136,6 +1158,7 @@
HWND m_hWnd;
PThread * m_thread;
+ PMutex m_openCloseMutex;
PSyncPoint m_started;
BITMAPINFO m_bitmap;
bool m_flipped;
@@ -1239,14 +1262,19 @@
{
Close();
+ m_openCloseMutex.Wait();
+
deviceName = name;
m_thread = PThread::Create(PCREATE_NOTIFIER(HandleDisplay), 0,
PThread::NoAutoDeleteThread, PThread::NormalPriority,
"VidOut:%x");
+ m_openCloseMutex.Signal();
m_started.Wait();
+ PWaitAndSignal m(m_openCloseMutex);
+
return startImmediate ? Start() : m_hWnd != NULL;
}
@@ -1259,18 +1287,23 @@
PBoolean PVideoOutputDevice_Window::Close()
{
+ PWaitAndSignal m(m_openCloseMutex);
+
if (m_hWnd == NULL)
return PFalse;
SendMessage(m_hWnd, WM_CLOSE, 0, 0);
m_thread->WaitForTermination(3000);
delete m_thread;
+ m_thread = NULL;
return PTrue;
}
PBoolean PVideoOutputDevice_Window::Start()
{
+ PWaitAndSignal m(m_openCloseMutex);
+
if (m_hWnd == NULL)
return PFalse;
@@ -1281,6 +1314,8 @@
PBoolean PVideoOutputDevice_Window::Stop()
{
+ PWaitAndSignal m(m_openCloseMutex);
+
if (m_hWnd != NULL)
return ShowWindow(m_hWnd, SW_HIDE);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|