Saturday, November 06, 2010 12:21 AM
Is there a limit on the number of media sessions that can exist at a given time for a process because I am getting an out of memory error or an unspecified error when trying to create more than 7 media sessions. I can reproduce this in 2 scenarios:
Using the MediaElement in a WPF application: I get the issue when opening the 8th MediaElement in WPF (each MediaElement has a video loaded but not playing, loadedbehavior is set to MediaState.Manual and ScrubbingEnabled = true, I call Stop() when media gets opened). The 8th MediaElement never raises the MediaOpened event.
In a MF multimedia application: I preload videos by creating multiple MediaSessions using MFCreateMediaSession. I call Play() followed by Pause(). The 8th media session will report an unspecified error in IMFAsyncCallback and never load the video. I've tried using the SequencerSource to overcome the limit but I need seamless looping and skipping (not just seamless transitions) so the sequencer source isn't going to work for me.
I am using windows 7 64-bit but creating 32-bit applications in both cases. The videos I use are WMV's with a 540x960 resolution.
Monday, November 08, 2010 12:04 PM
well, at least i can say that there is definitely no limit for parallel media sessions running. i successfully played up to 25 videos at the same time with media sessions. (on a windows 7 64bit system using a 32-bit process).
however, i used mpeg4 / h264 streams. maybe there is an issue with the WMV decoder. have you tried using other video formats?
Tuesday, November 09, 2010 7:03 PM
I have two questions, I think is simillar:
- How many sessions can drive WMS concurrent?
- Can I get a file, in a Pull service in WMS, without stop the service?
Thank you for your help.
Thursday, November 18, 2010 11:52 PM
I switched to mp4 / h264 and have the same limitation issue. I've also tried switching to DirectShow using EVR and the haali media splitter. I've tried different decoders (Microsoft's DTV-DVD Video decoder, MPC Video Decoder). I get an E_OUTOFMEMORY when calling IMediaControl::Run(). In DirectShow with the VMR I don't seem to have a limit but unfortunately I cannot access the DXVA textures to render them.
I've reproduced the EVR limit using GraphEdit (limit here seems to be 6 for some reason). Just add 6 EVR, 6 decoders, select 6 mp4 files (with HaaliSimpleMediaSplitter for example). Connect everything and it will work. Add a 7th and it will give you an error saying "not enough storage". Doesn't seem to matter how big the files are. Memory usage using MPC Video decoder is around 240mb while its around 300mb using Microsoft's DTV-DVD decoder.
Thanks for your help!
Friday, November 19, 2010 11:10 AM
i just started topoEdit, added 10 sources (h264, 720x576, 28fps) and 10 EVR presenters, connected them and the videos were displayed correctly (Win7 64bit). So i assume it has nothing to do with MF itself.
maybe you could get some information using mftrace.exe, this could help finding your problem.
how much memory does your machine have? i encountered an issue when using h264 decoder as it consumes about 50mb of memory per running media session. however, this does not apply to mpeg4 or wmv.
Friday, November 19, 2010 9:16 PM
Hi again, my machine has 12 gigs of ram, 1.2gig of video memory. I've also profiled my application and it clearly isn't close from the theorical limit of 2800MB (http://blogs.msdn.com/b/tom/archive/2008/04/10/chat-question-memory-limits-for-32-bit-and-64-bit-processes.aspx).
I tried playing around with topoEdit but the app will never playback anything unless I select file->render file. I've tried adding an mp4 source, an h264 decoder and an evr, connecting them or using the resolve topology menu but not window pops. If I try to add more than 1 source it says "Topology resolution failed. There is no connected source node in the topology. Media Foundation topologies require a source node.
It also fails to save anything, it says "Failed to save file. BUG: the given COM class is not registered."
Friday, November 19, 2010 10:19 PM
Experimented with MFTrace but it doesn't log anything below level 4 (no errors, warnings, etc).
Monday, November 22, 2010 7:53 AM
well, i added a h264 file (file extension .m4v) in TopoEdit with "add source", then i added an EVR, connected the nodes, pressed play and everything works fine. the decoder node is inserted automatically by topoedit after i pressed play.
what i can reda from what you´ve writen above. you add an mp4 source but use a h264 decoder? i guess this might not work as mp4 and h264 use different decoders.
can you skip adding a decoder manually and just connect the source with the evr? does this work for you?
Monday, November 22, 2010 8:24 PM
Connecting the EVR directly to the source works, I was able to add quite a lot of Source+EVR that way in TopoEdit, I tried 14 and they played fine. The second time I hit play though all the video windows were blank (entirely white).
Other interesting thing I noticed with our MF application: with no debugger attached I can create more Media Sessions (12) before it crashes. Our videos are H264 with MP4 container. We need to play about 7 or 8 layers at any given time while being able to switch playback to other pre-cached videos at any time (seamlessly). Perhaps you have a better way of attacking this problem? What we've tried: MF with 1 Media Session per video, DirectShow with 1 filtergraph per video.
Tuesday, November 23, 2010 7:51 AM
i guess problems when playing the videos in topoedit the second time are topoedit related and not direct problems of MF.
however, switching streams seamlessly can be quite tricky i guess. i solved this problem by starting another media session in background and
when buffering finished and the stream is ready, i switch the media session on my video displaying control in WPF (the actual client frontend) which works fine for me with up to 20 streams in parallel. using a sequencer source did not what i needed (as i had no real presentation times due to live streams).
i did not had the same problems you had when a debugger was attached. starting my process in debug mode using vs2008 (managed code using interop) i can play as much videos (and therefore media sessions) as i want. limit is memory (which is a problem when it comes to h264 as it uses a lot of memory for each instance).
do you have fixed video files (with their timestamps) or live video streams? do you use the already delivered media sources or a custom one? in some cases the sequencer source may be what you are looking for.
Tuesday, November 23, 2010 8:22 PMI use video files that I load from disk, no live or streaming data. I dont know in which order they will play as user interaction affects what plays next. We are also in a managed environment (using XNA and Interop). We want to use DXVA to minimize load on the CPU so we are stuck with H264 with DirectShow or H264/WMV in MF. DirectShow provides much better event notifications as far as playback goes to support looping and switching streams but it requires us to register 3rd party filters to split MP4 files. So each approach has its pros and cons. Guess I'll be experiementing more and see which one works the best. I'll be looking at the GMFBridge toolkit which seems to create a seperate graph for rendering.. this might resolve our issue of creating 1 EVR per pre-cached video.
Thursday, November 25, 2010 1:35 AMGMFBridge prevents me from using DXVA so I'm stuck here. I've tested again with MediaFoundation and I cannot render more than 7 media sessions when each one is using an EVR. I can in TopoEdit but in the application at runtime it reports an out of memory. I use a custom presenter (which is something I cannot test with TopoEdit) but even if I increase the number of samples it doesn't affect the maximum number of media sessions. The custom presenter is essentially the same as the one from the SDK.
Thursday, November 25, 2010 9:42 AMi als used (some some scenarios) a custom evr presenter but i did not had this limitations. have you tried running your process with a profiler attached so you can see what is consuming that much memory? do you get the out of memory exception at startup or after some time of playback (e.g. maybe your samples do not get disposed after rendering) ?
Wednesday, December 01, 2010 2:47 AMYea I did profile it but the memory usage remains stable with 7 videos playing back for hours. It just refuses to play with 8. When you say you have 25 media sessions playing at the same time, do you have 25 evr's with a custom presenter each? I'm leaning towards a hybrid solution right now with some layers playing with MF and some with GMFBridge and directshow (those won't have any hw acceleration). It looks like it will be the only way to achieve what we need.
Thursday, December 02, 2010 9:52 AM
when using the custom EVR presenter (i need it to get a direct reference to D3DSurfaces to display them within a D3DImage in wpf) i am still able to play dozens of video streams at the same time. it doesnt perform as good as the direct mode with the built in EVR (mostly due to overhead because of wpf) but having a separate custom EVR presenter for each video stream is no problem for me.
the memory consumption stays stable for me too, it was just an issue that rendering a h264 stream needs 10 times the memory of an mpeg4 stream (but is allocated at the beginning and remains stable).
Thursday, December 09, 2010 8:54 PMModerator
Have you tried temporarily disabling DXVA and seeing if that resolves the issue? You can quickly disable DXVA by starting Windows Media Player, right clicking and going to Tools->Options, going to the Performance tab, and unchecking "Turn on DirectX Video Acceleration for WMV files." This would potentially isolate the problem to a graphics issue.
Have you reproduced the issue on another machine with a different graphics card (particularly one from a different vendor?)
Friday, January 28, 2011 7:46 PMHi Matt, it does not happen if I turn DXVA off. Also it seems to happen with our Nvidia GTX 470 but not on a Quattro FX 580 (although both cards use the same unified driver version). Should we contact Nvidia for support?
Saturday, February 05, 2011 1:25 AMModerator
NVidia would be the only ones who could investigate what is going on to cause the failure with the 8th instance. It sounds like the driver might just reach a resource limitation and bail out. MF will drop DXVA and do software decoding if DXVA cannot be instantiated in the decoder, but if a failure happens mid-stream there is no recovery.
You can disable DXVA per-decoder by querying for IPropertyStore and setting MFPKEY_DXVA_ENABLED to false. This means you cannot use the topology loader to insert decoders, however. In Windows 7, you can disable DXVA at the topology level by using the MF_TOPOLOGY_DXVA_MODE attribute on the topology. Either of these options might help you work around the issue.
- Marked As Answer by Guy Godin Thursday, May 12, 2011 12:53 AM
Monday, December 05, 2011 2:56 PM
I have the same problems with DirectShow - limits on the number of EVRs that can be used at the same time. I am using ATI/AMD hardware and they have told me they place no limits on the number of EVRs and it is only limited by video memory. I suspect the answer from Nvidia would be the same.
In my tests I have found it is also related to the number of screens attached to the desktop and more screens equal less EVR. So, your first thought would be, well that is due to less video memory available but I can get the same results whether 3 screens come from one graphics card or three cards. So in the later, each screen has 1 GIG of memory and the EVR limit is the same with the same content. One can only assume from this that there is some decision process between the application and the graphics hardware/driver that places limits or there is a bug in some calculation.
You should note that when you build for 64 bit, the EVR limit goes way up but it is still a problem and again is related to the number of screens attached to the desktop.