Re: Global CComPtr
- From: "Walter" <waltshirey@xxxxxxxxx>
- Date: 15 Sep 2006 11:39:48 -0700
Are you releasing the pVideoMenu pointers anywhere?
Yes i omitted this by accident:
for (int i = 0; i<10; i++)
pVideoMenu[i].Release();
I also manually connect all filters, so I don't know if this is an
issue too.
It's not an issue unless you forget to release pointers.
Here is where I build my graph:
// Create the Filter Graph Manager (FGM)
hr = pSourceGraph.CoCreateInstance(CLSID_FilterGraph);
// Obtain the interface used to run, stop, and pause the graph
hr = pSourceGraph->QueryInterface(IID_IMediaControl, (void
**)&pMediaControl);
// Obtain the interface to receive events from the graph
hr = pSourceGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);
// Add the capture filter to the filter graph
// create IBaseFilter from IMoniker selected by user in videoMenu
CComPtr<IBaseFilter> pCapture;
// pVideo is moniker selected from submenu
hr = pVideo->BindToObject(0, 0, IID_IBaseFilter, (void**)&pCapture);
hr = pSourceGraph->AddFilter(pCapture, L"DV Capture Filter");
// add dv splitter filter
CComPtr<IBaseFilter> pDVSplitter;
hr = pDVSplitter.CoCreateInstance(CLSID_DVSplitter);
hr = pSourceGraph->AddFilter(pDVSplitter, L"DV Splitter");
// add dv video decoder
CComPtr<IBaseFilter> pDVDDecoder;
hr = pDVDDecoder.CoCreateInstance(CLSID_DVVideoCodec);
hr = pSourceGraph->AddFilter(pDVDDecoder, L"DV Video Decoder");
// add infinitie tee filter
CComPtr<IBaseFilter> pInfiniteTee;
hr = pInfiniteTee.CoCreateInstance(CLSID_InfTee);
hr = pSourceGraph->AddFilter(pInfiniteTee, L"Infinite Tee Filter");
// add picture mixer filter
CComPtr<IBaseFilter> pMediaLooksFilter;
CLSID clsid;
CLSIDFromString(L"{957C0DCF-37B6-4968-9C2F-2B66E26625A6}", &clsid);
// create MediaLooks PictureFilter Object
hr = pMediaLooksFilter.CoCreateInstance(clsid);
hr = pSourceGraph->AddFilter(pMediaLooksFilter, L"Media Looks Filter");
// get interface so we can add text and images
hr = pMediaLooksFilter->QueryInterface(__uuidof(IPictureMixer2), (void
**)&pPictureMixer);
// add smart tee filter
CComPtr<IBaseFilter> pSmartTee;
hr = pSmartTee.CoCreateInstance(CLSID_SmartTee);
hr = pSourceGraph->AddFilter(pSmartTee, L"Smart Tee Filter");
// add GMF Bridge Controller filter
hr = pBridge.CoCreateInstance(__uuidof(GMFBridgeController));
CComPtr<IUnknown> pUnkVidSink, pUnkAudioSink;
// add video sink filter
hr = pBridge->AddStream(true, eUncompressed, true);
hr = pBridge->InsertSinkFilter(pSourceGraph, &pUnkVidSink);
CComPtr<IBaseFilter> pVidSink,pAudioSink;
pVidSink = pUnkVidSink;
// add vmr to FGM
CComPtr<IBaseFilter> pVmr;
hr = InitWindowlessVMR(hApp, pSourceGraph, &pWindowlessControl, &pVmr);
// connect manually
// connect capture filter to DV Splitter
hr = ConnectFilters(pSourceGraph, pCapture, pDVSplitter,
MEDIATYPE_Interleaved, MEDIASUBTYPE_dvsd);
// connect DV Splitter (video) to DV Video Decoder
hr = ConnectFilters(pSourceGraph, pDVSplitter, pDVDDecoder,
MEDIATYPE_Video, MEDIASUBTYPE_dvsd);
// connect DV Video Decoder to Smart Tee Filter
hr = ConnectFilters(pSourceGraph, pDVSplitter, pDVDDecoder,
MEDIATYPE_Video, MEDIASUBTYPE_ARGB32);
// connect DV Video Decoder to Infinite Pin Tee Filter
hr = ConnectFilters(pSourceGraph, pDVDDecoder, pInfiniteTee,
MEDIATYPE_Video, MEDIASUBTYPE_ARGB32);
// connect Infinite Pin Tee Filter to Picture Mixer
hr = ConnectFilters(pSourceGraph, pInfiniteTee, pMediaLooksFilter,
MEDIATYPE_Video, MEDIASUBTYPE_ARGB32);
// connect Infinite Pin Tee Filter to EZRGB24
//hr = ConnectFilters(pSourceGraph, pInfiniteTee, pEZRGB24,
MEDIATYPE_Video, MEDIASUBTYPE_RGB24);
// connect EZRGB24 to Null Renderer
//hr = ConnectFilters(pSourceGraph, pEZRGB24, pNullRenderer,
MEDIATYPE_Video, MEDIASUBTYPE_RGB24);
// connect Picture Mixer to Smart Tee Filter
hr = ConnectFilters(pSourceGraph, pMediaLooksFilter, pSmartTee,
MEDIATYPE_Video, MEDIASUBTYPE_ARGB32);
// Connect Smart Tee Capture Pin to Bridge Controller
hr = GetUnconnectedPin(pSmartTee, PINDIR_OUTPUT, &pCapturePin, 0);
hr = ConnectFilters(pSourceGraph, pCapturePin, pVidSink);
CComPtr<IAMStreamControl> pSC;
pSC = pCapturePin;
REFERENCE_TIME tNever = MAXLONGLONG;
pSC->StartAt(&tNever, 0);
// Connect Smart Tee Preview pin to VMR
CComPtr<IPin> previewPin;
hr = GetUnconnectedPin(pSmartTee, PINDIR_OUTPUT, &previewPin, 0);
hr = ConnectFilters(pSourceGraph, previewPin, pVmr);
pSourceGraphSinkFilter = pUnkVidSink;
pVidSink = NULL;
pUnkVidSink = NULL;
// Find the native video size.
long lWidth, lHeight;
hr = pWindowlessControl->GetNativeVideoSize(&lWidth, &lHeight, NULL,
NULL);
....
// Set the video position.
hr = pWindowlessControl->SetVideoPosition(&rcSrc, &rcSrc);
and that's the end of that routine. I release no pointers there because
they're all smart pointers.
I also don't see the point in having that loop, since you're always
getting the same pin and trying the same connection, right?
Yes, you're right.
HRESULT GetUnconnectedPin(
IBaseFilter *pFilter, // Pointer to the filter.
PIN_DIRECTION PinDir, // Direction of the pin to find.
IPin **ppPin, // Receives a pointer to the pin.
GUID MajorType,
GUID SubType)
{
*ppPin = 0;
CComPtr<IEnumPins> pEnum;
CComPtr<IPin> pPin;
HRESULT hr = pFilter->EnumPins(&pEnum);
if (FAILED(hr))
{
return hr;
}
while (pEnum->Next(1, &pPin, NULL) == S_OK)
{
HRESULT hr;
PIN_DIRECTION ThisPinDir;
pPin->QueryDirection(&ThisPinDir);
if (ThisPinDir == PinDir)
{
CComPtr<IPin> pTmp;
hr = pPin->ConnectedTo(&pTmp);
if (SUCCEEDED(hr)) // Already connected, not the pin we
want.
{
pTmp.Release();
}
// it's unconnected, but is it the right media type?
else
{
// enumerate preferred media types of pin
CComPtr<IEnumMediaTypes> pEnumMedia;
pPin->EnumMediaTypes(&pEnumMedia);
AM_MEDIA_TYPE *mediaType;
while ((hr = pEnumMedia->Next(1, &mediaType, NULL)) == S_OK)
{
if (mediaType->majortype == MajorType && mediaType->subtype ==
SubType)
{
pEnum.Release();
*ppPin = pPin;
return S_OK;
You have a problem here, because you are assigning pPin directly to
ppPin without adding a reference to it. pPin will be released when you
return, which will leave ppPin invalid. Try doing an AddRef() before
you return.
I thought you couldn't use AddRef() with a CComPtr. At least that's
what my compiler is telling me.
I'm still getting an error after releasing all my smart pointers. The
error occurs when calling pSourceGraph.Release(). Is there any way to
find what's keeping that from releasing?
Thanks for your help and patience.
.
- Follow-Ups:
- Re: Global CComPtr
- From: Thore B. Karlsen [DShow MVP]
- Re: Global CComPtr
- References:
- Global CComPtr
- From: Walter
- Re: Global CComPtr
- From: The March Hare [MVP]
- Re: Global CComPtr
- From: Walter
- Re: Global CComPtr
- From: Thore B. Karlsen [DShow MVP]
- Re: Global CComPtr
- From: Walter
- Re: Global CComPtr
- From: Thore B. Karlsen [DShow MVP]
- Re: Global CComPtr
- From: Walter
- Re: Global CComPtr
- From: Thore B. Karlsen [DShow MVP]
- Global CComPtr
- Prev by Date: Re: Global CComPtr
- Next by Date: Re: Global CComPtr
- Previous by thread: Re: Global CComPtr
- Next by thread: Re: Global CComPtr
- Index(es):
Relevant Pages
|