|
From: libvidcap c. m. <lib...@li...> - 2007-09-12 13:58:09
|
Revision: 16
http://libvidcap.svn.sourceforge.net/libvidcap/?rev=16&view=rev
Author: bcholew
Date: 2007-09-12 06:57:59 -0700 (Wed, 12 Sep 2007)
Log Message:
-----------
Rename sourceIDs_ to acquiredSourceIDs_. Constify scan(), getJustCapDevice(), sprintDeviceInfo(), getOutPin(), getPin(), and getDeviceInfo(). Privatize getOutPin(). Remove getInPin(). Move freeMediaType() to DirectShowSource. Tidy up.
Modified Paths:
--------------
trunk/src/directshow/DShowSrcManager.cpp
trunk/src/directshow/DShowSrcManager.h
trunk/src/directshow/DirectShowSource.cpp
trunk/src/directshow/DirectShowSource.h
Modified: trunk/src/directshow/DShowSrcManager.cpp
===================================================================
--- trunk/src/directshow/DShowSrcManager.cpp 2007-09-11 18:43:51 UTC (rev 15)
+++ trunk/src/directshow/DShowSrcManager.cpp 2007-09-12 13:57:59 UTC (rev 16)
@@ -58,7 +58,8 @@
{
delete graphMon_;
- sourceIDs_.erase( sourceIDs_.begin(), sourceIDs_.end() );
+ acquiredSourceIDs_.erase( acquiredSourceIDs_.begin(),
+ acquiredSourceIDs_.end() );
srcGraphList_.erase( srcGraphList_.begin(), srcGraphList_.end() );
CoUninitialize();
@@ -157,7 +158,7 @@
}
int
-DShowSrcManager::scan(struct sapi_src_list * srcList)
+DShowSrcManager::scan(struct sapi_src_list * srcList) const
{
//FIXME: consider multiple sources per device
@@ -254,9 +255,9 @@
DShowSrcManager::okayToBuildSource(const char *id)
{
// Enforce exclusive access to a source
- for ( unsigned int i = 0; i < sourceIDs_.size(); i++ )
+ for ( unsigned int i = 0; i < acquiredSourceIDs_.size(); i++ )
{
- if ( !strcmp(sourceIDs_[i], id) )
+ if ( !strcmp(acquiredSourceIDs_[i], id) )
{
// a source with this id already exists - and was acquired
log_warn("source already acquired: '%s'\n", id);
@@ -265,20 +266,20 @@
}
// add source to collection
- sourceIDs_.push_back(id);
+ acquiredSourceIDs_.push_back(id);
return true;
}
void DShowSrcManager::sourceReleased(const char *id)
{
- for ( unsigned int i = 0; i < sourceIDs_.size(); i++ )
+ for ( unsigned int i = 0; i < acquiredSourceIDs_.size(); i++ )
{
- if ( !strcmp(sourceIDs_[i], id) )
+ if ( !strcmp(acquiredSourceIDs_[i], id) )
{
// found source with matching id
- sourceIDs_.erase( sourceIDs_.begin() + i );
+ acquiredSourceIDs_.erase( acquiredSourceIDs_.begin() + i );
return;
}
@@ -287,30 +288,10 @@
log_warn("couldn't find source '%s' to release\n", id);
}
-IPin *
-DShowSrcManager::getOutPin( IBaseFilter * pFilter, int nPin )
-{
- CComPtr<IPin> pComPin = 0;
-
- getPin(pFilter, PINDIR_OUTPUT, nPin, &pComPin);
-
- return pComPin;
-}
-
-void
-DShowSrcManager::freeMediaType(AM_MEDIA_TYPE& mt)
-{
- if ( mt.cbFormat != 0 )
- CoTaskMemFree((PVOID)mt.pbFormat);
-
- if ( mt.pUnk != NULL )
- mt.pUnk->Release();
-}
-
bool
DShowSrcManager::getJustCapDevice(const char *devLongName,
IBindCtx **ppBindCtx,
- IMoniker **ppMoniker)
+ IMoniker **ppMoniker) const
{
HRESULT hr;
@@ -395,7 +376,7 @@
void
DShowSrcManager::sprintDeviceInfo(IMoniker * pM, IBindCtx * pbc,
- char* idBuff, char *descBuff, int buffsSize)
+ char* idBuff, char *descBuff, int buffsSize) const
{
USES_CONVERSION;
@@ -454,16 +435,18 @@
}
IPin *
-DShowSrcManager::getInPin( IBaseFilter * pFilter, int nPin )
+DShowSrcManager::getOutPin( IBaseFilter * pFilter, int nPin ) const
{
CComPtr<IPin> pComPin = 0;
- getPin(pFilter, PINDIR_INPUT, nPin, &pComPin);
+
+ getPin(pFilter, PINDIR_OUTPUT, nPin, &pComPin);
+
return pComPin;
}
HRESULT
DShowSrcManager::getPin( IBaseFilter * pFilter, PIN_DIRECTION dirrequired,
- int iNum, IPin **ppPin)
+ int iNum, IPin **ppPin) const
{
*ppPin = NULL;
@@ -505,7 +488,7 @@
// Allocates and returns the friendlyName and displayName for a device
int
DShowSrcManager::getDeviceInfo(IMoniker * pM, IBindCtx * pbc,
- char** easyName, char **longName)
+ char** easyName, char **longName) const
{
USES_CONVERSION;
Modified: trunk/src/directshow/DShowSrcManager.h
===================================================================
--- trunk/src/directshow/DShowSrcManager.h 2007-09-11 18:43:51 UTC (rev 15)
+++ trunk/src/directshow/DShowSrcManager.h 2007-09-12 13:57:59 UTC (rev 16)
@@ -38,7 +38,7 @@
public:
static DShowSrcManager * instance();
- int scan(struct sapi_src_list *);
+ int scan(struct sapi_src_list *) const;
// for device event notifications (additions and removals)
int registerNotifyCallback(void *);
@@ -51,12 +51,9 @@
typedef bool (*cancelCallbackFunc)(IMediaEventEx *, void *);
static bool cancelSrcCaptureCallback(IMediaEventEx *, void *);
- IPin * getOutPin( IBaseFilter *, int);
- IPin * getInPin( IBaseFilter *, int);
- void freeMediaType(AM_MEDIA_TYPE& mt);
bool getJustCapDevice(const char *devLongName,
IBindCtx **ppBindCtx,
- IMoniker **ppMoniker);
+ IMoniker **ppMoniker) const;
bool okayToBuildSource(const char *);
void sourceReleased(const char *id);
void release();
@@ -64,7 +61,7 @@
private:
static DShowSrcManager *instance_;
int numRefs_;
- std::vector<const char *> sourceIDs_;
+ std::vector<const char *> acquiredSourceIDs_;
DevMonitor devMon_;
GraphMonitor *graphMon_;
@@ -79,10 +76,11 @@
std::vector<srcGraphContext *> srcGraphList_;
private:
- HRESULT getPin( IBaseFilter *, PIN_DIRECTION, int, IPin **);
+ IPin * getOutPin( IBaseFilter *, int) const;
+ HRESULT getPin( IBaseFilter *, PIN_DIRECTION, int, IPin **) const;
int getDeviceInfo(IMoniker * pM, IBindCtx * pbc,
- char** easyName, char **longName);
- void sprintDeviceInfo(IMoniker *, IBindCtx *, char *, char *, int);
+ char** easyName, char **longName) const;
+ void sprintDeviceInfo(IMoniker *, IBindCtx *, char *, char *, int) const;
};
#endif
Modified: trunk/src/directshow/DirectShowSource.cpp
===================================================================
--- trunk/src/directshow/DirectShowSource.cpp 2007-09-11 18:43:51 UTC (rev 15)
+++ trunk/src/directshow/DirectShowSource.cpp 2007-09-12 13:57:59 UTC (rev 16)
@@ -173,7 +173,7 @@
dshowMgr_->unregisterSrcGraph(pMediaEventIF_);
if ( nativeMediaType_ )
- dshowMgr_->freeMediaType(*nativeMediaType_);
+ freeMediaType(*nativeMediaType_);
// These below were initialized in constructor
pMediaEventIF_->Release();
@@ -380,7 +380,7 @@
if ( !findBestFormat(fmtNominal, fmtNative, &mediaFormat) )
return 0;
- dshowMgr_->freeMediaType(*mediaFormat);
+ freeMediaType(*mediaFormat);
return 1;
}
@@ -392,7 +392,7 @@
// If we've already got one, free it
if ( nativeMediaType_ )
{
- dshowMgr_->freeMediaType(*nativeMediaType_);
+ freeMediaType(*nativeMediaType_);
nativeMediaType_ = 0;
}
@@ -415,7 +415,7 @@
{
log_error("failed setting stream format (%d)\n", hr);
- dshowMgr_->freeMediaType(*nativeMediaType_);
+ freeMediaType(*nativeMediaType_);
nativeMediaType_ = 0;
return 1;
@@ -549,7 +549,7 @@
{
// NOT the chosen one?
if ( !itCanWork || iFmt != bestFmtNum )
- dshowMgr_->freeMediaType(*candidateFmtProps[iFmt].mediaFormat);
+ freeMediaType(*candidateFmtProps[iFmt].mediaFormat);
}
}
@@ -604,7 +604,7 @@
fmtNominal->width > scc.MaxOutputSize.cx ||
fmtNominal->height > scc.MaxOutputSize.cy )
{
- dshowMgr_->freeMediaType(*pMediaType);
+ freeMediaType(*pMediaType);
return false;
}
@@ -632,7 +632,7 @@
if ( !matchesWidth || !matchesHeight )
{
- dshowMgr_->freeMediaType(*pMediaType);
+ freeMediaType(*pMediaType);
return false;
}
@@ -648,7 +648,7 @@
// check framerate
if ( fps > fpsMax )
{
- dshowMgr_->freeMediaType(*pMediaType);
+ freeMediaType(*pMediaType);
return false;
}
@@ -661,7 +661,7 @@
if ( mapDirectShowMediaTypeToVidcapFourcc(
pMediaType->subtype.Data1, nativeFourcc) )
{
- dshowMgr_->freeMediaType(*pMediaType);
+ freeMediaType(*pMediaType);
return false;
}
@@ -671,7 +671,7 @@
{
if ( conv_conversion_func_get(nativeFourcc, fmtNominal->fourcc) == 0 )
{
- dshowMgr_->freeMediaType(*pMediaType);
+ freeMediaType(*pMediaType);
return false;
}
}
@@ -700,6 +700,16 @@
}
void
+DirectShowSource::freeMediaType(AM_MEDIA_TYPE &mediaType) const
+{
+ if ( mediaType.cbFormat != 0 )
+ CoTaskMemFree((PVOID)mediaType.pbFormat);
+
+ if ( mediaType.pUnk != NULL )
+ mediaType.pUnk->Release();
+}
+
+void
DirectShowSource::cancelCallbacks()
{
// serialize with normal capture callbacks
@@ -721,7 +731,6 @@
stop();
}
-// Fake out interface queries
STDMETHODIMP
DirectShowSource::QueryInterface(REFIID riid, void ** ppv)
{
@@ -737,8 +746,7 @@
return E_NOINTERFACE;
}
-// The sample grabber is calling us back on its deliver thread.
-// This is NOT the main app thread!
+// The sample grabber calls us back from its deliver thread
STDMETHODIMP
DirectShowSource::BufferCB( double dblSampleTime, BYTE * pBuff, long buffSize )
{
Modified: trunk/src/directshow/DirectShowSource.h
===================================================================
--- trunk/src/directshow/DirectShowSource.h 2007-09-11 18:43:51 UTC (rev 15)
+++ trunk/src/directshow/DirectShowSource.h 2007-09-12 13:57:59 UTC (rev 16)
@@ -47,8 +47,7 @@
void cancelCallbacks();
- const char *
- getID() const
+ const char * getID() const
{
return sourceContext_->src_info.identifier;
}
@@ -63,21 +62,21 @@
bool findBestFormat(const vidcap_fmt_info * fmtNominal,
vidcap_fmt_info * fmtNative, AM_MEDIA_TYPE **mediaFormat) const;
- // Fake out COM reference counting
+ void freeMediaType(AM_MEDIA_TYPE &) const;
+
+ // Fake out COM
STDMETHODIMP_(ULONG) AddRef() { return 2; }
STDMETHODIMP_(ULONG) Release() { return 1; }
+ STDMETHODIMP QueryInterface(REFIID riid, void ** ppv);
- // Fake out interface querying
- STDMETHODIMP
- QueryInterface(REFIID riid, void ** ppv);
+ // Not used
+ STDMETHODIMP SampleCB( double SampleTime, IMediaSample * pSample )
+ {
+ return S_OK;
+ }
- // We don't implement this one
+ // The sample grabber calls us back from its deliver thread
STDMETHODIMP
- SampleCB( double SampleTime, IMediaSample * pSample ) { return S_OK; }
-
- // The sample grabber is calling us back on its deliver thread.
- // This is NOT the main app thread
- STDMETHODIMP
BufferCB( double dblSampleTime, BYTE * pBuffer, long lBufferSize );
static int mapDirectShowMediaTypeToVidcapFourcc(DWORD data, int & fourcc);
@@ -85,7 +84,6 @@
private:
struct sapi_src_context * sourceContext_;
DShowSrcManager * dshowMgr_;
-
IBaseFilter * pSource_;
ICaptureGraphBuilder2 *pCapGraphBuilder_;
IAMStreamConfig * pStreamConfig_;
@@ -94,11 +92,8 @@
IBaseFilter * pSampleGrabber_;
ISampleGrabber * pSampleGrabberIF_;
IBaseFilter * pNullRenderer_;
-
IMediaControl * pMediaControlIF_;
-
AM_MEDIA_TYPE *nativeMediaType_;
-
CRITICAL_SECTION captureMutex_;
bool stoppingCapture_;
};
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|