|
From: libvidcap c. m. <lib...@li...> - 2007-10-01 21:47:33
|
Revision: 39
http://libvidcap.svn.sourceforge.net/libvidcap/?rev=39&view=rev
Author: bcholew
Date: 2007-10-01 14:47:31 -0700 (Mon, 01 Oct 2007)
Log Message:
-----------
Remove function sprintDeviceInfo(), in favor of function getDeviceInfo(). Alter DShowSrcManager::scan() to use getDeviceInfo(). Move function getJustCapDevice from DShowSrcManager to DirectShowSource. Move getDeviceInfo from DShowSrcManager to new base class DirectShowObject. Derive DirectShowSource and DShowSrcManager from this new class. Remove references to DShowSrcMgr in DirectShowSource.
Modified Paths:
--------------
trunk/src/directshow/DShowSrcManager.cpp
trunk/src/directshow/DShowSrcManager.h
trunk/src/directshow/DirectShowSource.cpp
trunk/src/directshow/DirectShowSource.h
trunk/src/directshow/GraphMonitor.cpp
trunk/src/directshow/SourceStateMachine.cpp
Added Paths:
-----------
trunk/src/directshow/DirectShowObject.cpp
trunk/src/directshow/DirectShowObject.h
Modified: trunk/src/directshow/DShowSrcManager.cpp
===================================================================
--- trunk/src/directshow/DShowSrcManager.cpp 2007-10-01 19:42:06 UTC (rev 38)
+++ trunk/src/directshow/DShowSrcManager.cpp 2007-10-01 21:47:31 UTC (rev 39)
@@ -158,12 +158,19 @@
srcInfo = &srcList->list[newListLen - 1];
- //FIXME: rename to getDeviceId()
- sprintDeviceInfo(pM, pbc,
- srcInfo->identifier, srcInfo->description,
- min(sizeof(srcInfo->identifier),
- sizeof(srcInfo->description)));
+ // get device description and ID
+ char *tempDesc;
+ char *tempID;
+ getDeviceInfo(pM, pbc, &tempDesc, &tempID);
+ sprintf_s(srcInfo->description, sizeof(srcInfo->description),
+ "%s", tempDesc);
+ sprintf_s(srcInfo->identifier, sizeof(srcInfo->identifier),
+ "%s", tempID);
+
+ free(tempID);
+ free(tempDesc);
+
clean_continue:
if ( pCaptureFilter )
pCaptureFilter->Release();
@@ -233,150 +240,7 @@
log_warn("couldn't find source '%s' to release\n", id);
}
-bool
-DShowSrcManager::getJustCapDevice(const char *devLongName,
- IBindCtx **ppBindCtx,
- IMoniker **ppMoniker) const
-{
- HRESULT hr;
- // Create an enumerator
- CComPtr<ICreateDevEnum> pCreateDevEnum;
-
- pCreateDevEnum.CoCreateInstance(CLSID_SystemDeviceEnum);
-
- if ( !pCreateDevEnum )
- {
- log_error("failed creating device enumerator - to get a source\n");
- return false;
- }
-
- // Enumerate video capture devices
- CComPtr<IEnumMoniker> pEm;
-
- pCreateDevEnum->CreateClassEnumerator(
- CLSID_VideoInputDeviceCategory, &pEm, 0);
-
- if ( !pEm )
- {
- log_error("failed creating enumerator moniker\n");
- return false;
- }
-
- pEm->Reset();
-
- ULONG ulFetched;
- IMoniker * pM;
-
- // Iterate over all video capture devices
- int i=0;
- while ( pEm->Next(1, &pM, &ulFetched) == S_OK )
- {
- IBindCtx *pbc;
-
- hr = CreateBindCtx(0, &pbc);
-
- if ( FAILED(hr) )
- {
- log_error("failed CreateBindCtx\n");
- pM->Release();
- return false;
- }
-
- // Get the device names
- char *shortName;
- char *longName;
- if ( getDeviceInfo(pM, pbc, &shortName, &longName) )
- {
- log_warn("failed to get device info.\n");
- pbc->Release();
- continue;
- }
-
- // Compare with the desired dev name
- if ( !strcmp(longName, devLongName) )
- {
- // Got the correct device
- *ppMoniker = pM;
- *ppBindCtx = pbc;
-
- free(shortName);
- free(longName);
- return true;
- }
-
- // Wrong device. Cleanup and try again
- free(shortName);
- free(longName);
-
- pbc->Release();
- }
-
- pM->Release();
-
- return false;
-}
-
-void
-DShowSrcManager::sprintDeviceInfo(IMoniker * pM, IBindCtx * pbc,
- char* idBuff, char *descBuff, int buffsSize) const
-{
- USES_CONVERSION;
-
- HRESULT hr;
-
- CComPtr< IMalloc > pMalloc;
-
- hr = CoGetMalloc(1, &pMalloc);
-
- if ( FAILED(hr) )
- {
- log_error("failed CoGetMalloc\n");
- return;
- }
-
- LPOLESTR pDisplayName;
-
- hr = pM->GetDisplayName(pbc, 0, &pDisplayName);
-
- if ( FAILED(hr) )
- {
- log_warn("failed GetDisplayName\n");
- return;
- }
-
- // This gets stack memory, no dealloc needed.
- char * pszDisplayName = OLE2A(pDisplayName);
-
- pMalloc->Free(pDisplayName);
-
- CComPtr< IPropertyBag > pPropBag;
-
- hr = pM->BindToStorage(pbc, 0, IID_IPropertyBag,
- (void **)&pPropBag);
-
- if ( FAILED(hr) )
- {
- log_error("failed getting video device property bag\n");
- return;
- }
-
- VARIANT v;
- VariantInit(&v);
-
- char * pszFriendlyName = 0;
-
- hr = pPropBag->Read(L"FriendlyName", &v, 0);
-
- if ( SUCCEEDED(hr) )
- pszFriendlyName = _com_util::ConvertBSTRToString(v.bstrVal);
-
- sprintf_s(descBuff, buffsSize, "%s", pszFriendlyName);
- sprintf_s(idBuff, buffsSize, "%s", pszDisplayName);
-
- delete [] pszFriendlyName;
-}
-
IPin *
DShowSrcManager::getOutPin( IBaseFilter * pFilter, int nPin ) const
{
@@ -428,68 +292,3 @@
return hr;
}
-// Allocates and returns the friendlyName and displayName for a device
-int
-DShowSrcManager::getDeviceInfo(IMoniker * pM, IBindCtx * pbc,
- char** easyName, char **longName) const
-{
- USES_CONVERSION;
-
- HRESULT hr;
-
- CComPtr< IMalloc > pMalloc;
-
- hr = CoGetMalloc(1, &pMalloc);
-
- if ( FAILED(hr) )
- {
- log_error("failed CoGetMalloc\n");
- return 1;
- }
-
- LPOLESTR pDisplayName;
-
- hr = pM->GetDisplayName(pbc, 0, &pDisplayName);
-
- if ( FAILED(hr) )
- {
- log_warn("failed GetDisplayName\n");
- return 1;
- }
-
- // This gets stack memory, no dealloc needed.
- char * pszDisplayName = OLE2A(pDisplayName);
-
- // Allocate a copy of this long name
- *longName = _strdup(pszDisplayName);
-
- pMalloc->Free(pDisplayName);
-
- CComPtr< IPropertyBag > pPropBag;
-
- hr = pM->BindToStorage(pbc, 0, IID_IPropertyBag,
- (void **)&pPropBag);
-
- if ( FAILED(hr) )
- {
- log_warn("failed getting video device property bag\n");
- return 1;
- }
-
- VARIANT v;
- VariantInit(&v);
-
- char * pszFriendlyName = 0;
-
- hr = pPropBag->Read(L"FriendlyName", &v, 0);
-
- if ( SUCCEEDED(hr) )
- pszFriendlyName =
- _com_util::ConvertBSTRToString(v.bstrVal);
-
- // Allocate a copy of this short name
- *easyName = _strdup(pszFriendlyName);
-
- delete [] pszFriendlyName;
- return 0;
-}
Modified: trunk/src/directshow/DShowSrcManager.h
===================================================================
--- trunk/src/directshow/DShowSrcManager.h 2007-10-01 19:42:06 UTC (rev 38)
+++ trunk/src/directshow/DShowSrcManager.h 2007-10-01 21:47:31 UTC (rev 39)
@@ -26,9 +26,10 @@
#define _DSHOWSRCMANAGER_H_
#include <vector>
+#include "DirectShowObject.h"
#include "DevMonitor.h"
-class DShowSrcManager
+class DShowSrcManager : public DirectShowObject
{
protected:
@@ -42,9 +43,6 @@
// for device event notifications (additions and removals)
int registerNotifyCallback(void *);
- bool getJustCapDevice(const char *devLongName,
- IBindCtx **ppBindCtx,
- IMoniker **ppMoniker) const;
bool okayToBuildSource(const char *);
void sourceReleased(const char *id);
void release();
@@ -67,9 +65,6 @@
private:
IPin * getOutPin( IBaseFilter *, int) const;
HRESULT getPin( IBaseFilter *, PIN_DIRECTION, int, IPin **) const;
- int getDeviceInfo(IMoniker * pM, IBindCtx * pbc,
- char** easyName, char **longName) const;
- void sprintDeviceInfo(IMoniker *, IBindCtx *, char *, char *, int) const;
};
#endif
Added: trunk/src/directshow/DirectShowObject.cpp
===================================================================
--- trunk/src/directshow/DirectShowObject.cpp (rev 0)
+++ trunk/src/directshow/DirectShowObject.cpp 2007-10-01 21:47:31 UTC (rev 39)
@@ -0,0 +1,97 @@
+//
+// libvidcap - a cross-platform video capture library
+//
+// Copyright 2007 Wimba, Inc.
+//
+// Contributors:
+// Peter Grayson <jpg...@gm...>
+// Bill Cholewka <bc...@gm...>
+//
+// libvidcap is free software; you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as
+// published by the Free Software Foundation; either version 2.1 of
+// the License, or (at your option) any later version.
+//
+// libvidcap is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this program. If not, see
+// <http://www.gnu.org/licenses/>.
+//
+
+#include <windows.h>
+#include <atlbase.h>
+#include <comutil.h>
+
+#include "DirectShowObject.h"
+#include "logging.h"
+
+// Allocates and returns the description and ID for a given device
+int
+DirectShowObject::getDeviceInfo(IMoniker * pM, IBindCtx * pbc,
+ char ** description, char **ID) const
+{
+ USES_CONVERSION;
+
+ HRESULT hr;
+
+ CComPtr< IMalloc > pMalloc;
+
+ hr = CoGetMalloc(1, &pMalloc);
+
+ if ( FAILED(hr) )
+ {
+ log_error("failed CoGetMalloc\n");
+ return 1;
+ }
+
+ LPOLESTR pDisplayName;
+
+ hr = pM->GetDisplayName(pbc, 0, &pDisplayName);
+
+ if ( FAILED(hr) )
+ {
+ log_warn("failed GetDisplayName\n");
+ return 1;
+ }
+
+ // This gets stack memory, no dealloc needed.
+ char * pszDisplayName = OLE2A(pDisplayName);
+
+ // Allocate a copy of this identifier
+ *ID = _strdup(pszDisplayName);
+
+ pMalloc->Free(pDisplayName);
+
+ CComPtr< IPropertyBag > pPropBag;
+
+ hr = pM->BindToStorage(pbc, 0, IID_IPropertyBag,
+ (void **)&pPropBag);
+
+ if ( FAILED(hr) )
+ {
+ log_warn("failed getting video device property bag\n");
+ return 1;
+ }
+
+ VARIANT v;
+ VariantInit(&v);
+
+ char * pszFriendlyName = 0;
+
+ hr = pPropBag->Read(L"FriendlyName", &v, 0);
+
+ if ( SUCCEEDED(hr) )
+ pszFriendlyName =
+ _com_util::ConvertBSTRToString(v.bstrVal);
+
+ // Allocate a copy of this description
+ *description = _strdup(pszFriendlyName);
+
+ delete [] pszFriendlyName;
+ return 0;
+}
+
Added: trunk/src/directshow/DirectShowObject.h
===================================================================
--- trunk/src/directshow/DirectShowObject.h (rev 0)
+++ trunk/src/directshow/DirectShowObject.h 2007-10-01 21:47:31 UTC (rev 39)
@@ -0,0 +1,41 @@
+//
+// libvidcap - a cross-platform video capture library
+//
+// Copyright 2007 Wimba, Inc.
+//
+// Contributors:
+// Peter Grayson <jpg...@gm...>
+// Bill Cholewka <bc...@gm...>
+//
+// libvidcap is free software; you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as
+// published by the Free Software Foundation; either version 2.1 of
+// the License, or (at your option) any later version.
+//
+// libvidcap is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this program. If not, see
+// <http://www.gnu.org/licenses/>.
+//
+
+#ifndef _DIRECTSHOWOBJECT_H_
+#define _DIRECTSHOWOBJECT_H_
+
+class DirectShowObject
+{
+
+public:
+ DirectShowObject() { };
+ ~DirectShowObject() { };
+
+protected:
+ int getDeviceInfo(IMoniker * pM, IBindCtx * pbc,
+ char ** descr, char **ID) const;
+};
+
+#endif
+
Modified: trunk/src/directshow/DirectShowSource.cpp
===================================================================
--- trunk/src/directshow/DirectShowSource.cpp 2007-10-01 19:42:06 UTC (rev 38)
+++ trunk/src/directshow/DirectShowSource.cpp 2007-10-01 21:47:31 UTC (rev 39)
@@ -37,9 +37,8 @@
#include "DirectShowSource.h"
DirectShowSource::DirectShowSource(struct sapi_src_context *src,
- DShowSrcManager *mgr, bufferCallbackFunc cbFunc, cancelCaptureFunc cancelCaptureCB, void * parent)
+ bufferCallbackFunc cbFunc, cancelCaptureFunc cancelCaptureCB, void * parent)
: sourceContext_(src),
- dshowMgr_(mgr),
bufferCB_(cbFunc),
cancelCaptureCB_(cancelCaptureCB),
parent_(parent),
@@ -61,8 +60,7 @@
IMoniker * pMoniker = 0;
// Get the capture device - identified by it's long display name
- if ( !dshowMgr_->getJustCapDevice(getID(), &pBindCtx, &pMoniker) )
- {
+ if ( !getCaptureDevice(getID(), &pBindCtx, &pMoniker) ){
log_warn("Failed to get device '%s'.\n", getID());
throw std::runtime_error("failed to get device");
}
@@ -280,9 +278,6 @@
if ( pCapGraphBuilder_ )
pCapGraphBuilder_->Release();
-
- if ( graphHandle_ )
- CloseHandle(graphHandle_);
}
int
@@ -1111,3 +1106,86 @@
}
}
+bool
+DirectShowSource::getCaptureDevice(const char *devLongName,
+ IBindCtx **ppBindCtx,
+ IMoniker **ppMoniker) const
+{
+ HRESULT hr;
+
+ // Create an enumerator
+ CComPtr<ICreateDevEnum> pCreateDevEnum;
+
+ pCreateDevEnum.CoCreateInstance(CLSID_SystemDeviceEnum);
+
+ if ( !pCreateDevEnum )
+ {
+ log_error("failed creating device enumerator - to get a source\n");
+ return false;
+ }
+
+ // Enumerate video capture devices
+ CComPtr<IEnumMoniker> pEm;
+
+ pCreateDevEnum->CreateClassEnumerator(
+ CLSID_VideoInputDeviceCategory, &pEm, 0);
+
+ if ( !pEm )
+ {
+ log_error("failed creating enumerator moniker\n");
+ return false;
+ }
+
+ pEm->Reset();
+
+ ULONG ulFetched;
+ IMoniker * pM;
+
+ // Iterate over all video capture devices
+ int i=0;
+ while ( pEm->Next(1, &pM, &ulFetched) == S_OK )
+ {
+ IBindCtx *pbc;
+
+ hr = CreateBindCtx(0, &pbc);
+
+ if ( FAILED(hr) )
+ {
+ log_error("failed CreateBindCtx\n");
+ pM->Release();
+ return false;
+ }
+
+ // Get the device names
+ char *shortName;
+ char *longName;
+ if ( getDeviceInfo(pM, pbc, &shortName, &longName) )
+ {
+ log_warn("failed to get device info.\n");
+ pbc->Release();
+ continue;
+ }
+
+ // Compare with the desired dev name
+ if ( !strcmp(longName, devLongName) )
+ {
+ // Got the correct device
+ *ppMoniker = pM;
+ *ppBindCtx = pbc;
+
+ free(shortName);
+ free(longName);
+ return true;
+ }
+
+ // Wrong device. Cleanup and try again
+ free(shortName);
+ free(longName);
+
+ pbc->Release();
+ }
+
+ pM->Release();
+
+ return false;
+}
Modified: trunk/src/directshow/DirectShowSource.h
===================================================================
--- trunk/src/directshow/DirectShowSource.h 2007-10-01 19:42:06 UTC (rev 38)
+++ trunk/src/directshow/DirectShowSource.h 2007-10-01 21:47:31 UTC (rev 39)
@@ -34,14 +34,14 @@
#include "sapi_context.h"
#include "GraphMonitor.h"
-class DirectShowSource : public ISampleGrabberCB
+class DirectShowSource : public ISampleGrabberCB, public DirectShowObject
{
public:
typedef int (*bufferCallbackFunc)(double, BYTE *, long, void *);
typedef void (*cancelCaptureFunc)(void *);
- DirectShowSource(struct sapi_src_context *, DShowSrcManager *,
+ DirectShowSource(struct sapi_src_context *,
bufferCallbackFunc, cancelCaptureFunc, void *);
~DirectShowSource();
@@ -69,11 +69,12 @@
int formatNum,
bool *needsFramerateEnforcing, bool *needsFormatConversion,
AM_MEDIA_TYPE **candidateMediaFormat) const;
-
bool findBestFormat(const vidcap_fmt_info * fmtNominal,
vidcap_fmt_info * fmtNative, AM_MEDIA_TYPE **mediaFormat) const;
-
void freeMediaType(AM_MEDIA_TYPE &) const;
+ bool getCaptureDevice(const char *devLongName,
+ IBindCtx **ppBindCtx,
+ IMoniker **ppMoniker) const;
// Fake out COM
STDMETHODIMP_(ULONG) AddRef() { return 2; }
Modified: trunk/src/directshow/GraphMonitor.cpp
===================================================================
--- trunk/src/directshow/GraphMonitor.cpp 2007-10-01 19:42:06 UTC (rev 38)
+++ trunk/src/directshow/GraphMonitor.cpp 2007-10-01 21:47:31 UTC (rev 39)
@@ -85,7 +85,6 @@
}
DWORD rc = WaitForSingleObject(initDoneEvent_, INFINITE);
- //FIXME: consider a timeout
return;
@@ -144,7 +143,6 @@
DWORD rc = WaitForMultipleObjects(static_cast<DWORD>(numHandles),
waitHandles, false, INFINITE);
-
// get index of object that signaled
unsigned int index = rc - WAIT_OBJECT_0;
Modified: trunk/src/directshow/SourceStateMachine.cpp
===================================================================
--- trunk/src/directshow/SourceStateMachine.cpp 2007-10-01 19:42:06 UTC (rev 38)
+++ trunk/src/directshow/SourceStateMachine.cpp 2007-10-01 21:47:31 UTC (rev 39)
@@ -70,7 +70,6 @@
try
{
src_ = new DirectShowSource(src,
- mgr,
(bufferCallbackFunc)&SourceStateMachine::bufferCB,
(cancelCaptureFunc)&SourceStateMachine::cancelCaptureCB,
this);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|