Sign in to follow this  

Using VMR9 to render to XNA Texture2D

This topic is 2669 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

I'm trying to use the VMR9 in renderless mode to render to an XNA texture. After approaching it a billion different ways this is what seems to almost be working:

1. In my IVMRSurfaceAllocator9::InitializeDevice method, create a Texture2D with the requested size and format.

2. Use reflection to grab the "pComPtr" field from the texture, use this to construct an MDX texture so I can call GetSurfaceLevel to get the surface pointer. This is the pointer I give to VMR9 to render to.

This almost seems to work, my PresentImage method gets hit every frame as expected, except when I try to draw the texture to the screen (with SpriteBatch) I get this error from D3D:

"Direct3D9: (ERROR) :Cannot render when currently set textures are locked"

Followed by:

"A first chance exception of type 'System.InvalidOperationException' occurred in Microsoft.Xna.Framework.dll
An unhandled exception of type 'System.InvalidOperationException' occurred in Microsoft.Xna.Framework.dll

Additional information: An unexpected error has occurred."

And the app dies.

Since DirectShow is running on a separate thread I can see how there could be synchronization issues... the moment that my Game.Draw happens to execute may be when the VMR9 is in the middle of rendering a new frame.

What I can't figure out though is how I would be able to synchronize this since there's no way to force the VMR9 to use any critical section I might create in the application.

I notice that the SDK "vmr9allocator" sample creates its device with the D3DCREATE_MULTITHREADED flag, I'm not sure if this is intended to avoid this type of problem. When I modify that sample and remove this flag it still runs fine, and there are a bunch of warnings like this in the output:

"Direct3D9: (WARN) :Device that was created without D3DCREATE_MULTITHREADED is being used by a thread other than the creation thread."

Which I don't see in my XNA app, so maybe XNA is already setting this flag?

Anyway, I'm pretty stumped as to how to proceed. I've seen some posts online that suggest other people have gotten this working (VMR9 + XNA) but there are no implementation details to be found.

Share this post


Link to post
Share on other sites
Did you take a look at the vmr9allocator sample from the WinSDK? It shows you that you'll need multiple surfaces to avoid synchronization issues.

Otherwise I'll suggest you take a look at the MediaPortal source. They access DirectShow from C#.

Henning

Share this post


Link to post
Share on other sites

This topic is 2669 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this