|
From: libvidcap c. m. <lib...@li...> - 2007-09-13 13:05:23
|
Revision: 18
http://libvidcap.svn.sourceforge.net/libvidcap/?rev=18&view=rev
Author: bcholew
Date: 2007-09-13 06:05:21 -0700 (Thu, 13 Sep 2007)
Log Message:
-----------
When cancelling capture callbacks, stop() capture before calling final callback. This removes the need for a mutex to protect capture_callback from simultaneous access by cancelCallbacks() and an actual capture callback ( BufferCB() ).
Modified Paths:
--------------
trunk/src/directshow/DirectShowSource.cpp
trunk/src/directshow/DirectShowSource.h
Modified: trunk/src/directshow/DirectShowSource.cpp
===================================================================
--- trunk/src/directshow/DirectShowSource.cpp 2007-09-12 18:05:45 UTC (rev 17)
+++ trunk/src/directshow/DirectShowSource.cpp 2007-09-13 13:05:21 UTC (rev 18)
@@ -50,8 +50,7 @@
pSampleGrabberIF_(0),
pNullRenderer_(0),
pMediaControlIF_(0),
- nativeMediaType_(0),
- stoppingCapture_(false)
+ nativeMediaType_(0)
{
if ( !dshowMgr_ )
{
@@ -146,8 +145,6 @@
// FIXME: Is this too early? Should we only do it during captures?
dshowMgr_->registerSrcGraph(this, pMediaEventIF_);
- InitializeCriticalSection(&captureMutex_);
-
return;
constructionFailure:
@@ -189,8 +186,6 @@
pCapGraphBuilder_->Release();
dshowMgr_->sourceReleased( getID() );
-
- DeleteCriticalSection(&captureMutex_);
}
void
@@ -336,10 +331,8 @@
pSampleGrabber_->Release();
pSampleGrabber_ = 0;
bail_1:
- EnterCriticalSection(&captureMutex_);
pMediaControlIF_->Release();
pMediaControlIF_ = 0;
- LeaveCriticalSection(&captureMutex_);
return -1;
}
@@ -367,10 +360,7 @@
DirectShowSource::stop()
{
int ret = 0;
- stoppingCapture_ = true;
- EnterCriticalSection(&captureMutex_);
-
if ( pMediaControlIF_ )
{
HRESULT hr = pMediaControlIF_->Stop();
@@ -382,10 +372,6 @@
}
}
- LeaveCriticalSection(&captureMutex_);
-
- stoppingCapture_ = false;
-
return ret;
}
@@ -732,23 +718,18 @@
void
DirectShowSource::cancelCallbacks()
{
- // serialize with normal capture callbacks
- EnterCriticalSection(&captureMutex_);
-
- // only cancel callbacks once (unless re-registered)
+ // have capture callbacks already been cancelled?
if ( !sourceContext_->capture_callback )
- {
- LeaveCriticalSection(&captureMutex_);
return;
- }
- // call capture callback - but let the
+ // stop callbacks BEFORE thinking of
+ // touching sourceContext_->capture_callback
+ stop();
+
+ // call capture callback - but let vidcap and the
// app know that this is the last time
+ // (vidcap will reset capture_callback)
sapi_src_capture_notify(sourceContext_, 0, 0, -1);
-
- LeaveCriticalSection(&captureMutex_);
-
- stop();
}
STDMETHODIMP
@@ -770,22 +751,12 @@
STDMETHODIMP
DirectShowSource::BufferCB( double dblSampleTime, BYTE * pBuff, long buffSize )
{
- // prevent deadlock while stopping
- if ( stoppingCapture_ )
- return 0;
-
- EnterCriticalSection(&captureMutex_);
-
if ( !sourceContext_->capture_callback )
return 0;
- int ret = sapi_src_capture_notify(sourceContext_,
+ return sapi_src_capture_notify(sourceContext_,
reinterpret_cast<const char *>(pBuff),
static_cast<int>(buffSize), 0);
-
- LeaveCriticalSection(&captureMutex_);
-
- return ret;
}
int
Modified: trunk/src/directshow/DirectShowSource.h
===================================================================
--- trunk/src/directshow/DirectShowSource.h 2007-09-12 18:05:45 UTC (rev 17)
+++ trunk/src/directshow/DirectShowSource.h 2007-09-13 13:05:21 UTC (rev 18)
@@ -96,8 +96,6 @@
IBaseFilter * pNullRenderer_;
IMediaControl * pMediaControlIF_;
AM_MEDIA_TYPE *nativeMediaType_;
- CRITICAL_SECTION captureMutex_;
- bool stoppingCapture_;
};
#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|