Jump to content
  • Advertisement
Sign in to follow this  
mrmrcoleman

VMR-9 problems... Inexplicable error!

This topic is 4886 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I am sorry to post such a volume of code but I have spoken to at least two other people on the newsgroups who are having the same or similar problem so I thought it would be worth getting it sorted once and for all, so if you could possibly spare the time could you please have a look! The confusing thing about this problem is that it does not seem to be reproducable. I use the following code to initialise my DirectShow graph.
// Create the graph builder
if(FAILED(CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&GraphBuilder)))
{
	DXTRACE_MSG("Could not create Graph Manager");
	return S_FALSE;
}

// Add the graph to the running object table
AddToROT(GraphBuilder);

// BUILD the VMR9
HRESULT hr = CoCreateInstance(CLSID_VideoMixingRenderer9, 0, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**) &VMRBaseFilter);
if (FAILED(hr))
{
	DXTRACE_ERR("Could not create an instance ofthe VMR9", hr);
	return FALSE;
}

// ADD the VMR9 to the graph
hr = GraphBuilder->AddFilter(VMRBaseFilter, L"VMR9");
if (FAILED(hr))
{
	DXTRACE_ERR("Could not add the VMR9 to the Graph", hr);
	return FALSE;
}

// QUERY the VMR9 interfaces
hr = VMRBaseFilter->QueryInterface(IID_IVMRFilterConfig9, (void**) &VMRFilterConfig);
if (SUCCEEDED(hr))
{
	// CONFIGURE the VMR9
	hr = VMRFilterConfig->SetRenderingMode(VMR9Mode_Windowless);
	if(FAILED(hr))
	{
		DXTRACE_ERR("Could not set the rendering mode of the VMR9", hr);
	}

	hr = VMRFilterConfig->SetNumberOfStreams(1);
	if(FAILED(hr))
	{
		DXTRACE_ERR("Could not set the number of streams in the VMR9", hr);
	}
}
else
{
	DXTRACE_MSG("Could not retrieve the FilterConfig interface");
}

hr = VMRBaseFilter->QueryInterface(IID_IVMRWindowlessControl9, (void**) &VMRWindowlessControl);
if (SUCCEEDED(hr))
{
	// CONFIGURE the VMR9
	hr = VMRWindowlessControl->SetVideoClippingWindow(g_hWnd);
	if(FAILED(hr))
	{
		DXTRACE_ERR("Could not set the video clipping window", hr);
	}

	hr = VMRWindowlessControl->SetAspectRatioMode(VMR9ARMode_LetterBox);
	if(FAILED(hr))
	{
		DXTRACE_ERR("Could not set the aspect ratio mode", hr);
	}
}
else
{
	DXTRACE_MSG("Could not retrieve the WindowlessControl interface");
}

// CONFIGURE the VMR9
// MEDIA SIZE
LONG  Width;
LONG  Height;
LONG  ARWidth;
LONG  ARHeight;

hr = VMRWindowlessControl->GetNativeVideoSize(&Width, &Height, &ARWidth, &ARHeight);
if(FAILED(hr))
{
	DXTRACE_ERR("Could not get the native video size", hr);
}
			
RECT mediaRect;
mediaRect.left = 0;
mediaRect.top = 0;
mediaRect.right = Width;
mediaRect.bottom = Height;
RECT wndRect;
GetClientRect(g_hWnd, &wndRect);
VMRWindowlessControl->SetVideoPosition(&mediaRect, &wndRect);

hr = VMRBaseFilter->QueryInterface(IID_IVMRMixerBitmap9, (void**) &VMRMixerBitmap);
if(FAILED(hr))
{
	DXTRACE_ERR("Could not retrieve the Mixer Bitmap interface", hr);
	return FALSE;
}
			
hr = VMRBaseFilter->QueryInterface(IID_IVMRMixerControl9, (void**) &VMRMixerControl);
if(FAILED(hr))
{
	DXTRACE_ERR("Could not retrieve the mixer control interface", hr);
	return FALSE;
}

hr = VMRBaseFilter->QueryInterface(IID_IVMRMonitorConfig9, (void**) &VMRMonitorConfig);
if(FAILED(hr))
{
	DXTRACE_ERR("Could not retrieve the monitor config interface", hr);
	return FALSE;
}

// Create and add a file source
IBaseFilter *SourceFilter = NULL;
hr = GraphBuilder->AddSourceFilter(AllocLPWSTR(AnimationFileLocation.c_str()), L"Source Filter", &SourceFilter);
if(FAILED(hr))
{
	DXTRACE_ERR("Could not add the source filter", hr);
	return S_FALSE;
}

// BUILD the AVI Splitter
IBaseFilter *AVISplitter;
hr = CoCreateInstance(CLSID_AviSplitter, 0, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**) &AVISplitter);
if (FAILED(hr))
{
	DXTRACE_ERR("Could not create an instance ofthe AVI splitter", hr);
	return FALSE;
}

// Add the splitter to the graph
hr = GraphBuilder->AddFilter(AVISplitter, L"AVI Splitter");
if (FAILED(hr))
{
	DXTRACE_ERR("Could not add the AVI splitter to the Graph", hr);
	return FALSE;
}
			
// BUILD the AVI Splitter
IBaseFilter *AVIDecompressor;
hr = CoCreateInstance(CLSID_AVIDec, 0, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**) &AVIDecompressor);
if (FAILED(hr))
{
	DXTRACE_ERR("Could not create an instance ofthe AVI decompressor", hr);
	return FALSE;
}

// Add the splitter to the graph
hr = GraphBuilder->AddFilter(AVIDecompressor, L"AVI Decompressor");
if (FAILED(hr))
{
	DXTRACE_ERR("Could not add the AVI decompressor to the Graph", hr);
	return FALSE;
}

// Connect all the filters together
// Pins
IPin* ipin;
IPin* opin;

// Connect the output of the source to the input of the AVI splitter
opin = GetPin(SourceFilter, PINDIR_OUTPUT);
ipin = GetPin(AVISplitter, PINDIR_INPUT);

hr = GraphBuilder->Connect(opin, ipin);
if (FAILED(hr))
{
	DXTRACE_ERR("Could not connect Source to Splitter", hr);
	return FALSE;
}

SAFE_RELEASE(opin);
SAFE_RELEASE(ipin);

// Connect the output of the AVI splitter to the input of the decompressor
opin = GetPin(AVISplitter, PINDIR_OUTPUT);
ipin = GetPin(AVIDecompressor, PINDIR_INPUT);

hr = GraphBuilder->Connect(opin, ipin);
if (FAILED(hr))
{
	DXTRACE_ERR("Could not connect splitter to decompressor", hr);
	return FALSE;
}

SAFE_RELEASE(opin);
SAFE_RELEASE(ipin);

// Connect the output of the decompressor to the input of the VMR
opin = GetPin(AVIDecompressor, PINDIR_OUTPUT);
ipin = GetPin(VMRBaseFilter, PINDIR_INPUT);

hr = GraphBuilder->ConnectDirect(opin, ipin, NULL);
if (FAILED(hr))
{
	DXTRACE_ERR("Could not connect decompressor to VMR", hr);
	return FALSE;
}

SAFE_RELEASE(opin);
SAFE_RELEASE(ipin);

The first time this is executed the graph is built without problems. It may be worth noting that the file in question is a 24bit Cinepak compressed AVI of about 5.7 Meg. My program resources in and out of memory as needed so at some point the following release method is called to release the above graph.
// Stop the graph
MediaControl->Stop();

// Release all the DirectX interfaces
SAFE_RELEASE(MediaPosition);
SAFE_RELEASE(MediaControl);
SAFE_RELEASE(MediaEvent);
SAFE_RELEASE(AnimationTexture);
SAFE_RELEASE(GrabberBase);
SAFE_RELEASE(SampleGrabber);
SAFE_RELEASE(NullBase);
SAFE_RELEASE(GraphBuilder);

SAFE_RELEASE(VMRBaseFilter);
SAFE_RELEASE(VMRFilterConfig);
SAFE_RELEASE(VMRMixerBitmap);
SAFE_RELEASE(VMRMixerControl);
SAFE_RELEASE(VMRMonitorConfig);
SAFE_RELEASE(VMRWindowlessControl);

Please note that the other filter seen here are used with the video class in different configurations and can be ignored. Now later in the program when I run the above initialise method again I run into a problem. The final connect call (ConnectDirect(AVIDecompressor, VMR 9) fails with VFW_NO_ACCEPTABLE_TYPES. How could this be? The file is the same and the method is the same so I would expect the same results. I have tried as many things as I can think of but I cannot figure this out. A huge thanks in advance for any advice on this matter, it has been dogging me for close to a fortnight now. Kind regards, Mark Coleman

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!