VMR9 Rendering to a texture

Started by
2 comments, last by Headkaze 16 years, 9 months ago
Just trying to get my head around VMR9... What I'm trying to do is - based on the VMR9Allocator sample - render each frame of video to a texture. Then I want to use the texture each time round my render loop to paint one (or more) sprites. This should result in video rendered in an existing 3D scene within my engine. Inside my allocator class (derived from IVMRSurfaceAllocator9 and IVMRImagePresenter9) I'm creating a texture on initialisation. When PresentImage is called I'm then using StretchRect to copy the rendered frame to this texture. (This all happens - I presume - in a separate thread, so I use the CAutoLock utility to make sure that there are no simultaneous access attempts on the texture.) Outside of this thread my main render loop is running. I am assuming that I can use the texture created in the allocator class then to paint onto sprites within my scene - with suitable calls on CAutoLock as before. Can anyone confirm that this is a rational approach? I've got a white square only at the moment which implies that I'm not setting up or using the textures correctly - or that this is simply not the way to do it! Hope that's clear - I'd be very grateful for any help.
Advertisement
I've ran into this kind of problem myself.There was one thread about this problem awhile ago,can't seem to find it though.Anyway,the main problem is that the drawing runs on one thread and the DirectShow filters on another, the threads being asynchronous. DirectShow switches renderTargets (to the target surface) while the main part of the application is still drawing to the backbuffer effectively causing the drawing part of the application to render parts on the video surface and not on the backbuffer.
Use this to avoid the rendertarget switching :
hr = pVmr->QueryInterface(IID_IVMRMixerControl9, (void**)&pMix);if( SUCCEEDED(hr)) {    DWORD dwPrefs=0;    hr = pMix->GetMixingPrefs(&dwPrefs);    if (SUCCEEDED(hr))    {	dwPrefs &= ~MixerPref9_RenderTargetMask;	dwPrefs |= MixerPref9_RenderTargetYUV;		        hr = pMix->SetMixingPrefs(dwPrefs);    }    pMix->Release();}

This switches to YUV mode that is hardware accelerated and needs no rendertarget switching.Hope this helps.
Best Regards,Radu
Many thanks for your help - I'll give that a go.
You might like to also consider removing any call to SetNumberOfStreams, otherwise you turn on the mixer and that can cause issues running the allocator on a separate thread.

This topic is closed to new replies.

Advertisement