|
From: libvidcap c. m. <lib...@li...> - 2007-09-07 21:53:32
|
Revision: 9
http://libvidcap.svn.sourceforge.net/libvidcap/?rev=9&view=rev
Author: bcholew
Date: 2007-09-07 14:53:30 -0700 (Fri, 07 Sep 2007)
Log Message:
-----------
Removed unused code: functions canConvertToRGB32(), getMediaType(), buildFormatList(), and member variables pSourceOutPin_, pIntermediateFilter_ and intermediateMediaType_.
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-07 21:33:40 UTC (rev 8)
+++ trunk/src/directshow/DirectShowSource.cpp 2007-09-07 21:53:30 UTC (rev 9)
@@ -51,8 +51,6 @@
pNullRenderer_(0),
pMediaControlIF_(0),
nativeMediaType_(0),
- pIntermediateFilter_(0),
- intermediateMediaType_(0),
stoppingCapture_(false)
{
if ( !dshowMgr_ )
@@ -93,14 +91,6 @@
goto constructionFailure;
}
-#if 0
- if ( !buildFormatList(pBindCtx, pMoniker) )
- {
- log_warn("Failed building format list for '%s'.\n", getID());
- goto constructionFailure;
- }
-#else
-
hr = CoCreateInstance(CLSID_CaptureGraphBuilder2,
NULL,
CLSCTX_INPROC_SERVER,
@@ -125,18 +115,7 @@
pCapGraphBuilder_->Release();
goto constructionFailure;
}
-#endif
- // FIXME: does this really need to be a member? Maybe should be in start().
- pSourceOutPin_ = dshowMgr_->getOutPin( pSource_, 0 );
-
- if ( !pSourceOutPin_ )
- {
- log_error("Failed getting source output pin\n");
- goto constructionFailure;
- }
-
-
hr = CoCreateInstance(CLSID_FilterGraph,
0,
CLSCTX_INPROC_SERVER,
@@ -202,8 +181,6 @@
pFilterGraph_->Release();
- pSourceOutPin_.Release();
-
pSource_->Release();
pStreamConfig_->Release();
@@ -215,316 +192,7 @@
DeleteCriticalSection(&captureMutex_);
}
-#if 0
int
-DirectShowSource::buildFormatList(IBindCtx * pBindCtx, IMoniker * pMoniker)
-{
- HRESULT hr = CoCreateInstance(CLSID_CaptureGraphBuilder2,
- NULL,
- CLSCTX_INPROC_SERVER,
- IID_ICaptureGraphBuilder2,
- (void **)&pCapGraphBuilder_);
-
- if ( FAILED(hr) )
- {
- log_error("failed creating capture graph builder (%d)\n", hr);
- return 0;
- }
-
- hr = pCapGraphBuilder_->FindInterface(&PIN_CATEGORY_CAPTURE,
- &MEDIATYPE_Video,
- pSource_,
- IID_IAMStreamConfig,
- (void **)&pStreamConfig_);
- if( FAILED(hr) )
- {
- log_error("failed getting stream config "
- "while building format list (%d)\n", hr);
- pCapGraphBuilder_->Release();
- return 0;
- }
-
- int iCount = 0, iSize = 0;
- hr = pStreamConfig_->GetNumberOfCapabilities(&iCount, &iSize);
-
- // Check the size to make sure we pass in the correct structure.
- if (iSize != sizeof(VIDEO_STREAM_CONFIG_CAPS) )
- {
- log_error("capabilities struct is wrong size (%d not %d)\n",
- iSize, sizeof(VIDEO_STREAM_CONFIG_CAPS));
- pStreamConfig_->Release();
- pCapGraphBuilder_->Release();
- return 0;
- }
-
- // enumerate each source format
- for (int iFormat = 0; iFormat < iCount; iFormat++)
- {
- // get the video stream capabilities structure
- VIDEO_STREAM_CONFIG_CAPS scc;
- AM_MEDIA_TYPE *pMediaType;
- hr = pStreamConfig_->GetStreamCaps(iFormat, &pMediaType,
- (BYTE*)&scc);
-
- if (FAILED(hr))
- {
- log_warn("failed getting stream capabilities [%d of %d] (%d)\n",
- iFormat+1, iCount, hr);
- continue;
- }
-
- int fourcc;
-
- if ( mapDirectShowMediaTypeToVidcapFourcc(
- pMediaType->subtype.Data1, fourcc) )
- continue;
-
- // calculate range of supported frame rates
- double fpsMin = static_cast<double>( 1000000000 / scc.MaxFrameInterval)
- / 100.0;
- double fpsMax = static_cast<double>( 1000000000 / scc.MinFrameInterval)
- / 100.0;
-
- // enumerate a format for each frame rate
- for ( int i = 0; i < hot_fps_list_len; ++i )
- {
- int hot_fps_num = hot_fps_list[i].fps_numerator;
- int hot_fps_den = hot_fps_list[i].fps_denominator;
- double fps = static_cast<double>(hot_fps_num) /
- static_cast<double>(hot_fps_den);
-
- if ( fps < fpsMin || fps > fpsMax )
- continue;
-
- for ( int j = 0; j < hot_resolution_list_len; ++j )
- {
- vidcap_fmt_info * fmt;
-
- const int hot_width =
- hot_resolution_list[j].width;
- const int hot_height =
- hot_resolution_list[j].height;
-
- if ( hot_width < scc.MinOutputSize.cx ||
- hot_height < scc.MinOutputSize.cy ||
- hot_width > scc.MaxOutputSize.cx ||
- hot_height > scc.MaxOutputSize.cy )
- {
- continue;
- }
-
- fmtListLen_++;
- pFmtList_ = static_cast<vidcap_fmt_info *>(
- realloc(pFmtList_,
- fmtListLen_ *
- sizeof(vidcap_fmt_info)));
-
- if ( !pFmtList_ )
- {
- log_error("failed reallocating format list\n");
-
- dshowMgr_->freeMediaType(*pMediaType);
- pStreamConfig_->Release();
- pCapGraphBuilder_->Release();
- return 0;
- }
-
- fmt = &pFmtList_[fmtListLen_ - 1];
-
- fmt->width = hot_width;
- fmt->height = hot_height;
- fmt->fourcc = fourcc;
- fmt->fps_numerator = hot_fps_num;
- fmt->fps_denominator = hot_fps_den;
-
- // TODO: revisit OutputGranularity if a device
- // is found that uses it
- }
- }
-
- dshowMgr_->freeMediaType(*pMediaType);
- }
-
- return fmtListLen_;
-}
-#endif
-
-bool
-DirectShowSource::canConvertToRGB32()
-{
- if ( pIntermediateFilter_ )
- pIntermediateFilter_->Release();
-
- // used if format conversion is necessary
- intermediateMediaType_ = 0;
- pIntermediateFilter_ = 0;
-
- IFilterMapper2 *pMapper = NULL;
- IEnumMoniker *pEnum = NULL;
-
- HRESULT hr;
- hr = CoCreateInstance(CLSID_FilterMapper2,
- NULL,
- CLSCTX_INPROC,
- IID_IFilterMapper2,
- (void **) &pMapper);
-
- if (FAILED(hr))
- {
- log_error("failed to create FilterMapper2 (%d)\n", hr);
- return false;
- }
-
- // search for a filter to convert to RGB32
-
- GUID arrayInTypes[2];
- GUID arrayOutTypes[2];
- memset(&arrayInTypes[1], 0, sizeof(arrayInTypes[1]));
- memset(&arrayOutTypes[1], 0, sizeof(arrayOutTypes[1]));
-
- CComPtr< IEnumMediaTypes > pMediaEnum;
- hr = pSourceOutPin_->EnumMediaTypes(&pMediaEnum);
- if ( FAILED(hr) )
- {
- log_error("failed creating media type enumerator (rc=%d)\n", hr);
- pMapper->Release();
- return false;
- }
-
- // enumerate all media types of source
- ULONG ulFound;
- AM_MEDIA_TYPE * pMedia;
- while ( S_OK == pMediaEnum->Next(1, &pMedia, &ulFound) )
- {
- VIDEOINFOHEADER * vih = (VIDEOINFOHEADER *)pMedia->pbFormat;
-
- // find entry that matches desired format
- if ( vih->bmiHeader.biWidth != sourceContext_->fmt_nominal.width ||
- vih->bmiHeader.biHeight != sourceContext_->fmt_nominal.height )
- {
- // invalid dimensions
- dshowMgr_->freeMediaType(*pMedia);
- continue;
- }
-
- arrayInTypes[0] = pMedia->majortype;
- arrayInTypes[1] = pMedia->subtype;
-
- arrayOutTypes[0] = MEDIATYPE_Video;
- arrayOutTypes[1] = MEDIASUBTYPE_RGB32;
-
-#if 0
- log_info("considering input format %c%c%c%c\n",
- (arrayInTypes[1].Data1 >> 0) & 0xff,
- (arrayInTypes[1].Data1 >> 8) & 0xff,
- (arrayInTypes[1].Data1 >> 16) & 0xff,
- (arrayInTypes[1].Data1 >> 24) & 0xff);
-#endif
-
- IEnumMoniker *pFilterEnum = NULL;
- hr = pMapper->EnumMatchingFilters(
- &pFilterEnum,
- 0, // Reserved.
- TRUE, // Use exact match?
- MERIT_DO_NOT_USE+1, // Minimum merit.
- TRUE, // At least one input pin?
-
- 1, // # of major type/subtype pairs for input
- arrayInTypes, // Array of major/subtype pairs for input
-
- NULL, // Input medium.
- NULL, // Input pin category.
- FALSE, // Must be a renderer?
- TRUE, // At least one output pin?
-
- 1, // # of major type/subtype pairs for output
- arrayOutTypes, // Array of major/subtype pairs for output
-
- NULL, // Output medium.
- NULL); // Output pin category.
-
- // Enumerate the filter monikers
- IMoniker *pMoniker;
- ULONG cFetched;
- while ( pFilterEnum->Next(1, &pMoniker, &cFetched) == S_OK )
- {
- IPropertyBag *pPropBag = NULL;
- hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag,
- (void **)&pPropBag);
-
- if ( FAILED(hr) )
- {
- log_warn("Couldn't bind to storage for this matching filter\n");
- pMoniker->Release();
- continue;
- }
-
- // Get the friendly name of the filter
- VARIANT varName;
- VariantInit(&varName);
- hr = pPropBag->Read(L"FriendlyName", &varName, 0);
- if ( SUCCEEDED(hr) )
- {
- char * pszFriendlyName =
- _com_util::ConvertBSTRToString(
- varName.bstrVal);
-
- log_info("conversion filter '%s' should work\n",
- pszFriendlyName);
-
- delete [] pszFriendlyName;
- }
- VariantClear(&varName);
-
- // Create an instance of the filter
- hr = pMoniker->BindToObject(NULL,
- NULL,
- IID_IBaseFilter,
- (void**)&pIntermediateFilter_);
-
- if (FAILED(hr))
- {
- //FIXME: name it
- log_warn("failed to instantiate conversion filter (%d)\n",
- hr);
-
- pPropBag->Release();
- pMoniker->Release();
- pIntermediateFilter_ = 0;
- continue;
- }
-
- // TODO:
- // get output pin of intermediate filter?
- // get it's media type?
-
- intermediateMediaType_ = arrayInTypes[1].Data1;
-
- pPropBag->Release();
- pMoniker->Release();
- pFilterEnum->Release();
- dshowMgr_->freeMediaType(*pMedia);
- pMediaEnum.Release();
- pMapper->Release();
-
- return true;
- }
-
- // cleanup
- pFilterEnum->Release();
- dshowMgr_->freeMediaType(*pMedia);
-
- // failed to find filter suitable to convert this media type to RGB32
- }
-
- pMediaEnum.Release();
- pMapper->Release();
-
- // Can't build filter graph to convert this source's output to RGB32
- return false;
-}
-
-int
DirectShowSource::start()
{
HRESULT hr = pFilterGraph_->QueryInterface(IID_IMediaControl,
@@ -604,19 +272,8 @@
}
// Set sample grabber's media type to match that of the source
- // OR the conversion filter
- if ( intermediateMediaType_ )
- {
- //FIXME: Shouldn't this be necessary?
- pAmMediaType->subtype.Data1 = intermediateMediaType_;
- //hr = pSampleGrabberIF_->SetMediaType(pAmMediaType);
- hr = pSampleGrabberIF_->SetMediaType(NULL);
- }
- else
- {
- //FIXME: do at bind time
- hr = pSampleGrabberIF_->SetMediaType(pAmMediaType);
- }
+ //FIXME: do at bind time
+ hr = pSampleGrabberIF_->SetMediaType(pAmMediaType);
if ( FAILED(hr) )
{
log_error("failed to set grabber media type (%d)\n", hr);
@@ -658,81 +315,17 @@
goto bail_5;
}
- if ( pIntermediateFilter_ )
+ hr = pCapGraphBuilder_->RenderStream(&PIN_CATEGORY_CAPTURE,
+ &MEDIATYPE_Video,
+ pSource_,
+ pSampleGrabber_,
+ pNullRenderer_);
+ if ( FAILED(hr) )
{
- hr = pFilterGraph_->AddFilter(pIntermediateFilter_,
- L"ConversionFilter");
- if ( FAILED(hr) )
- {
- log_error("failed to add conversion filter (%d)\n", hr);
- goto bail_5;
- }
-
- hr = pCapGraphBuilder_->RenderStream(NULL, //&PIN_CATEGORY_CAPTURE,
- NULL, //&MEDIATYPE_Video,
- pSource_,
- pIntermediateFilter_,
- pSampleGrabber_);
- if ( FAILED(hr) )
- {
- log_error("failed to connect source, conversion filter, "
- "sample grabber (%lu 0x%x)\n", hr, hr);
- switch ( hr )
- {
- case VFW_S_NOPREVIEWPIN:
- log_error("VFW_S_NOPREVIEWPIN\n");
- break;
-
- case E_FAIL:
- log_error("E_FAIL\n");
- break;
-
- case E_POINTER:
- log_error("E_POINTER\n");
- break;
-
- case VFW_E_NOT_IN_GRAPH:
- log_error("VFW_E_NOT_IN_GRAPH\n");
- break;
-
- case E_INVALIDARG:
- log_error("E_INVALIDARG\n");
- break;
-
- default:
- log_error("default\n");
- break;
- }
- goto bail_5;
- }
-
- hr = pCapGraphBuilder_->RenderStream(
- NULL, //&PIN_CATEGORY_CAPTURE,
- NULL, //&MEDIATYPE_Video,
- pSampleGrabber_,
- NULL,
- pNullRenderer_);
- if ( FAILED(hr) )
- {
- log_error("failed to connect grabber and null renderer (%d)\n",
- hr);
- goto bail_5;
- }
+ log_error("failed to connect source, grabber "
+ "and null renderer (%d)\n", hr);
+ goto bail_5;
}
- else
- {
- hr = pCapGraphBuilder_->RenderStream(&PIN_CATEGORY_CAPTURE,
- &MEDIATYPE_Video,
- pSource_,
- pSampleGrabber_,
- pNullRenderer_);
- if ( FAILED(hr) )
- {
- log_error("failed to connect source, grabber "
- "and null renderer (%d)\n", hr);
- goto bail_5;
- }
- }
hr = pMediaControlIF_->Run();
@@ -786,10 +379,6 @@
log_error("failed to STOP the filter graph (%ul)\n", hr);
}
- if ( pIntermediateFilter_ )
- pIntermediateFilter_->Release();
- pIntermediateFilter_ = 0;
-
if ( pNullRenderer_ )
pNullRenderer_->Release();
pNullRenderer_ = 0;
@@ -1217,86 +806,6 @@
return ret;
}
-//FIXME: Is there a better way to get the media type
-// from the width, height and fourcc?
-AM_MEDIA_TYPE *
-DirectShowSource::getMediaType( CComPtr< IPin > pPin) const
-{
- CComPtr< IEnumMediaTypes > pEnum;
-
- HRESULT hr = pPin->EnumMediaTypes(&pEnum);
-
- if ( FAILED(hr) )
- {
- log_error("failed creating media type enumerator (rc=%d)\n", hr);
- return NULL;
- }
-
- ULONG ulFound;
- AM_MEDIA_TYPE * pMedia;
- DWORD boundMediaType;
-
- if ( mapVidcapFourccToDirectShowMediaType(
- sourceContext_->fmt_nominal.fourcc,
- boundMediaType) )
- return NULL;
-
- int requiredMediaType = intermediateMediaType_ ?
- intermediateMediaType_ : boundMediaType;
-
- while ( S_OK == pEnum->Next(1, &pMedia, &ulFound) )
- {
- //printMediaFormatType(pMedia);
-
- VIDEOINFOHEADER * vih =
- (VIDEOINFOHEADER *) pMedia->pbFormat;
- int thisFourcc;
-
- if ( mapDirectShowMediaTypeToVidcapFourcc(pMedia->subtype.Data1,
- thisFourcc) )
- continue;
-
- // find entry that matches desired format
- if ( vih->bmiHeader.biWidth ==
- sourceContext_->fmt_nominal.width &&
- vih->bmiHeader.biHeight ==
- sourceContext_->fmt_nominal.height &&
- (thisFourcc ==
- sourceContext_->fmt_nominal.fourcc ||
- pMedia->subtype.Data1 == requiredMediaType) )
- {
- return pMedia;
- }
-
- dshowMgr_->freeMediaType(*pMedia);
- }
-
- return NULL;
-}
-
-void
-DirectShowSource::printMediaFormatType(AM_MEDIA_TYPE *pMedia)
-{
- if ( pMedia->formattype == FORMAT_DvInfo )
- log_info("FORMAT_DvInfo\n");
- else if ( pMedia->formattype == FORMAT_MPEG2Video )
- log_info("FORMAT_MPEG2Video\n");
- else if ( pMedia->formattype == FORMAT_MPEGStreams )
- log_info("FORMAT_MPEGStreams\n");
- else if ( pMedia->formattype == FORMAT_MPEGVideo )
- log_info("FORMAT_MPEGVideo\n");
- else if ( pMedia->formattype == FORMAT_None )
- log_info("FORMAT_None\n");
- else if ( pMedia->formattype == FORMAT_VideoInfo )
- log_info("FORMAT_VideoInfo\n");
- else if ( pMedia->formattype == FORMAT_VideoInfo2 )
- log_info("FORMAT_VideoInfo2\n");
- else if ( pMedia->formattype == FORMAT_WaveFormatEx )
- log_info("FORMAT_WaveFormatEx\n");
- else
- log_info("unknown\n");
-}
-
int
DirectShowSource::mapDirectShowMediaTypeToVidcapFourcc(DWORD data, int & fourcc)
{
Modified: trunk/src/directshow/DirectShowSource.h
===================================================================
--- trunk/src/directshow/DirectShowSource.h 2007-09-07 21:33:40 UTC (rev 8)
+++ trunk/src/directshow/DirectShowSource.h 2007-09-07 21:53:30 UTC (rev 9)
@@ -54,17 +54,12 @@
}
private:
- bool canConvertToRGB32();
bool checkFormat(const vidcap_fmt_info * fmtNominal,
vidcap_fmt_info * fmtNative,
int formatNum,
bool *needsFramerateEnforcing, bool *needsFormatConversion,
AM_MEDIA_TYPE **candidateMediaFormat) const;
- // NOTE: this will soon be obsolete
- AM_MEDIA_TYPE * getMediaType( CComPtr< IPin > pPin) const;
- void printMediaFormatType(AM_MEDIA_TYPE *pMedia);
-
// Fake out COM reference counting
STDMETHODIMP_(ULONG) AddRef() { return 2; }
STDMETHODIMP_(ULONG) Release() { return 1; }
@@ -90,7 +85,6 @@
DShowSrcManager * dshowMgr_;
IBaseFilter * pSource_;
- CComPtr<IPin> pSourceOutPin_; // TODO: remove CComPtr
ICaptureGraphBuilder2 *pCapGraphBuilder_;
IAMStreamConfig * pStreamConfig_;
IGraphBuilder *pFilterGraph_;
@@ -103,11 +97,6 @@
AM_MEDIA_TYPE *nativeMediaType_;
- // when necessary to convert source output format
- //NOTE: these two will soon be obsolete
- IBaseFilter *pIntermediateFilter_;
- DWORD intermediateMediaType_;
-
CRITICAL_SECTION captureMutex_;
bool stoppingCapture_;
};
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|