|
From: libvidcap c. <lib...@li...> - 2007-12-03 14:09:59
|
Revision: 73
http://libvidcap.svn.sourceforge.net/libvidcap/?rev=73&view=rev
Author: bcholew
Date: 2007-12-03 06:09:55 -0800 (Mon, 03 Dec 2007)
Log Message:
-----------
Use abstracted thread and mutex functions in directshow sapi.
Modified Paths:
--------------
trunk/src/directshow/DevMonitor.cpp
trunk/src/directshow/DevMonitor.h
trunk/src/directshow/GraphMonitor.cpp
trunk/src/directshow/GraphMonitor.h
trunk/src/directshow/SourceStateMachine.cpp
trunk/src/directshow/SourceStateMachine.h
Modified: trunk/src/directshow/DevMonitor.cpp
===================================================================
--- trunk/src/directshow/DevMonitor.cpp 2007-12-03 14:09:08 UTC (rev 72)
+++ trunk/src/directshow/DevMonitor.cpp 2007-12-03 14:09:55 UTC (rev 73)
@@ -39,7 +39,7 @@
szWindowClass_(0),
sapiCtx_(0)
{
- InitializeCriticalSection(®istrationMutex_);
+ vc_mutex_init(®istrationMutex_);
// create an event used to signal that the thread has been created
initDoneEvent_ = CreateEvent(
@@ -86,15 +86,9 @@
}
// pass instance to thread
- devMonitorThread_ = CreateThread(
- NULL,
- 0,
- (LPTHREAD_START_ROUTINE)(&DevMonitor::monitorDevices),
- this,
- 0,
- &devMonitorThreadID_);
-
- if ( devMonitorThread_ == NULL )
+ if ( vc_create_thread(&devMonitorThread_,
+ &DevMonitor::monitorDevices,
+ this, &devMonitorThreadID_) )
{
log_error("DevMonitor: failed spinning DevMonitor thread (%d)\n",
GetLastError());
@@ -131,7 +125,7 @@
return;
}
- DWORD rc = WaitForSingleObject(devMonitorThread_, INFINITE);
+ DWORD rc = WaitForSingleObject((HANDLE)devMonitorThread_, INFINITE);
if ( rc == WAIT_FAILED )
{
@@ -145,7 +139,7 @@
GetLastError());
}
- DeleteCriticalSection(®istrationMutex_);
+ vc_mutex_destroy(®istrationMutex_);
}
LRESULT CALLBACK
@@ -181,13 +175,13 @@
return 0;
}
-DWORD WINAPI
-DevMonitor::monitorDevices(LPVOID lpParam)
+unsigned int
+DevMonitor::monitorDevices(void * param)
{
//FIXME: move window creation to constructor
// extract instance
- DevMonitor * pDevMon = (DevMonitor *)lpParam;
+ DevMonitor * pDevMon = (DevMonitor *)param;
// Create a window, so main thread can communicate with us
pDevMon->windowHandle_ = CreateWindow(
@@ -285,7 +279,7 @@
}
log_info("[[ Device event: %s ]]\n", str.c_str());
- EnterCriticalSection(&pDevMon->registrationMutex_);
+ vc_mutex_lock(&pDevMon->registrationMutex_);
if ( sapiCtx &&
sapiCtx->notify_callback )
@@ -302,7 +296,7 @@
log_info("[[ no user-defined handler registered ]]\n");
}
- LeaveCriticalSection(&pDevMon->registrationMutex_);
+ vc_mutex_unlock(&pDevMon->registrationMutex_);
default:
str.assign("");
@@ -321,11 +315,11 @@
if ( !sapiCtx )
return -1;
- EnterCriticalSection(®istrationMutex_);
+ vc_mutex_lock(®istrationMutex_);
sapiCtx_ = sapiCtx;
- LeaveCriticalSection(®istrationMutex_);
+ vc_mutex_unlock(®istrationMutex_);
return 0;
}
Modified: trunk/src/directshow/DevMonitor.h
===================================================================
--- trunk/src/directshow/DevMonitor.h 2007-12-03 14:09:08 UTC (rev 72)
+++ trunk/src/directshow/DevMonitor.h 2007-12-03 14:09:55 UTC (rev 73)
@@ -36,26 +36,23 @@
int registerCallback(void *);
private:
- static LRESULT __stdcall
- processWindowsMsgs(HWND, UINT, WPARAM, LPARAM);
+ static LRESULT __stdcall processWindowsMsgs(HWND, UINT, WPARAM, LPARAM);
+ static unsigned int STDCALL monitorDevices(void * lpParam);
- static DWORD WINAPI
- monitorDevices(LPVOID lpParam);
-
private:
HANDLE initDoneEvent_;
enum threadStatusEnum { initializing=0, initFailed, initDone };
threadStatusEnum threadStatus_;
HWND windowHandle_;
- void * devMonitorThread_;
- DWORD devMonitorThreadID_;
+ vc_thread devMonitorThread_;
+ unsigned int devMonitorThreadID_;
TCHAR * szTitle_;
TCHAR * szWindowClass_;
void * sapiCtx_;
- CRITICAL_SECTION registrationMutex_;
+ vc_mutex registrationMutex_;
};
#endif
Modified: trunk/src/directshow/GraphMonitor.cpp
===================================================================
--- trunk/src/directshow/GraphMonitor.cpp 2007-12-03 14:09:08 UTC (rev 72)
+++ trunk/src/directshow/GraphMonitor.cpp 2007-12-03 14:09:55 UTC (rev 73)
@@ -68,15 +68,9 @@
}
// create thread, pass instance
- graphMonitorThread_ = CreateThread(
- NULL,
- 0,
- (LPTHREAD_START_ROUTINE)(&GraphMonitor::monitorGraph),
- this,
- 0,
- &graphMonitorThreadID_);
-
- if ( graphMonitorThread_ == NULL )
+ if ( vc_create_thread(&graphMonitorThread_,
+ &GraphMonitor::monitorGraph,
+ this, &graphMonitorThreadID_) )
{
log_error("GraphMonitor: failed spinning GraphMonitor thread (%d)\n",
GetLastError());
@@ -99,7 +93,7 @@
}
// wait for thread to shutdown
- DWORD rc = WaitForSingleObject(graphMonitorThread_, INFINITE);
+ DWORD rc = WaitForSingleObject((HANDLE)graphMonitorThread_, INFINITE);
if ( rc == WAIT_FAILED )
{
@@ -110,11 +104,11 @@
log_info("graph monitor thread destroyed\n");
}
-DWORD WINAPI
-GraphMonitor::monitorGraph(LPVOID lpParam)
+unsigned int
+GraphMonitor::monitorGraph(void * param)
{
// extract instance
- GraphMonitor * pGraphMon = (GraphMonitor *)lpParam;
+ GraphMonitor * pGraphMon = (GraphMonitor *)param;
// signal that thread is ready
if ( !SetEvent(pGraphMon->initDoneEvent_) )
Modified: trunk/src/directshow/GraphMonitor.h
===================================================================
--- trunk/src/directshow/GraphMonitor.h 2007-12-03 14:09:08 UTC (rev 72)
+++ trunk/src/directshow/GraphMonitor.h 2007-12-03 14:09:55 UTC (rev 73)
@@ -25,7 +25,7 @@
#ifndef _GRAPHMONITOR_H_
#define _GRAPHMONITOR_H_
-#include <windows.h>
+#include "os_funcs.h"
class GraphMonitor
{
@@ -37,7 +37,7 @@
~GraphMonitor();
private:
- static DWORD WINAPI monitorGraph(LPVOID lpParam);
+ static unsigned int STDCALL monitorGraph(void * param);
private:
HANDLE *graphHandle_;
@@ -47,8 +47,8 @@
HANDLE initDoneEvent_;
HANDLE terminateEvent_;
- void * graphMonitorThread_;
- DWORD graphMonitorThreadID_;
+ vc_thread graphMonitorThread_;
+ unsigned int graphMonitorThreadID_;
};
#endif
Modified: trunk/src/directshow/SourceStateMachine.cpp
===================================================================
--- trunk/src/directshow/SourceStateMachine.cpp 2007-12-03 14:09:08 UTC (rev 72)
+++ trunk/src/directshow/SourceStateMachine.cpp 2007-12-03 14:09:55 UTC (rev 73)
@@ -85,15 +85,9 @@
}
// pass instance to thread
- sourceThread_ = CreateThread(
- NULL,
- 0,
- (LPTHREAD_START_ROUTINE)(&SourceStateMachine::waitForCmd),
- this,
- 0,
- &sourceThreadID_);
-
- if ( sourceThread_ != NULL )
+ if ( !vc_create_thread(&sourceThread_,
+ &SourceStateMachine::waitForCmd,
+ this, &sourceThreadID_) )
{
// wait for signal from thread that it is ready
WaitForSingleObject(eventInitDone_, INFINITE);
@@ -123,7 +117,7 @@
}
// wait for thread to shutdown
- DWORD rc = WaitForSingleObject(sourceThread_, INFINITE);
+ DWORD rc = WaitForSingleObject((HANDLE)sourceThread_, INFINITE);
if ( rc == WAIT_FAILED )
{
@@ -231,11 +225,11 @@
return 0;
}
-DWORD WINAPI
-SourceStateMachine::waitForCmd(LPVOID lpParam)
+unsigned int
+SourceStateMachine::waitForCmd(void *param)
{
// extract instance
- SourceStateMachine * pSrc = (SourceStateMachine *)lpParam;
+ SourceStateMachine * pSrc = (SourceStateMachine *)param;
// signal to main thread that we are ready for commands
if ( !SetEvent(pSrc->eventInitDone_) )
Modified: trunk/src/directshow/SourceStateMachine.h
===================================================================
--- trunk/src/directshow/SourceStateMachine.h 2007-12-03 14:09:08 UTC (rev 72)
+++ trunk/src/directshow/SourceStateMachine.h 2007-12-03 14:09:55 UTC (rev 73)
@@ -47,7 +47,7 @@
}
private:
- static DWORD WINAPI waitForCmd(LPVOID);
+ static unsigned int STDCALL waitForCmd(void *);
void terminate();
void doStart();
void doStop();
@@ -70,8 +70,8 @@
HANDLE eventStop_;
HANDLE eventTerminate_;
HANDLE eventCancel_;
- void * sourceThread_;
- DWORD sourceThreadID_;
+ vc_thread sourceThread_;
+ unsigned int sourceThreadID_;
bool okToSendStart_;
bool okToSendStop_;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|