In Windows Media Foundation, TopoEdit is the equivalent of DirectShow’s GraphEdit tool. Using a simple graphic interface, one can build topologies (the equivalent of a DirectShow filter graph), and “run” them, that is, start the flow of data, from a source node towards one or more output nodes. We’ll see that in a minute.
To open TopoEdit, the Windows SDK should be installed. Navigate using Windows Explorer to something like C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin and run TopoEdit.Exe. You should see something like this:
Not too exciting at this point. We have a blank working area where our topology would show.
The easiest way to start experimenting is use the File->Render File… menu item. Select some media file (such as a WMV or MP3 file). If all is well, you should see something like this:
What just happened? TopoEdit used Media Foundation’s source resolver and with some extra work, tried to build a topology that manages to deal with the selected source (here having two streams of data: one audio, the other video) and get each stream to a “visual” output, namely an Audio renderer and a Video renderer.
Pressing the “Play” toolbar button (or selecting from the menu Controls->Play) should show a new window with the media file playing. You can change the playing rate, pause or stop playback. In essence, you have a simple Windows Media Player.
Let’s try to create this topology in a different way. Select File->New from the menu, answer “yes” to the continue without saving the current topology and you should be back at an empty work area.
Now go to the Topology menu and select “Add Source…”. Navigate to a media file of your choosing. Let’s assume the previous file, which contains both video and audio. You should see something like this:
We’ll disregard the “attributes” pane on the right for now.
What we have is a node within the topology of type “source”. A source node is required, and a media file is a common source. Other possibilities may be a video capture device (camera for example) or a microphone. Technically it can be anything that matches a specific interface.
We can see in the toolbar area that the topology is not resolved, meaning there is no valid path from a source node to an output node – we have no output node yet. Clicking “Play” fails with a topology resolution error.
We need an output node. The most obvious may be a video renderer. Select “Add EVR” from the Topology menu. The EVR is the Enhanced Video Renderer, which is MF’s default supplied video renderer. Connect the output of the Video input stream to the Video Renderer’s input node by clicking and dragging. It should look something like:
Now for the magic part: select Topology->Resolve Topology. If you’ve selected a WMV file, a “WMVideo Decoder” node appears, resolving the mismatch that naturally exists between a WMV source and the EVR. The WMV video stream needs to be decoded before it can be rendered. MF is smart enough to look for matching transforms that can do the job. Pressing “Play” now shows video but no sound.
We can provide audio output in a similar manner. Select Topology->Add SAR to add a sound output device. Connect the audio stream to the Audio Renderer, and resolve the topology again. Now you can fully play the media file.
Now let’s try something more daring.
Disconnect the WMVDecoder from the Video renderer by clicking one of the pins and pressing DELETE.
Now select from the menu Topology->Add Tee. A “splitter” node is created. Select from the menu Topology->Add EVR.
Now connect the WMVideo Decoder to the input of the “Tee” and connect the Tee’s output to one of the EVRs. Automatically another output appears on the Tee. Connect it to the other EVR.
Now resolve the topology. Press Play. You should see two video windows playing at once.
TopoEdit is a useful tool. Unfortunately, it’s not useful enough. Setting attributes is difficult. Setting properties (in the MF sense, which I’ll discuss at a later post) is not possible as far as I could see. Also, the tool has bugs and its UI is clunky at best. Looking at its About box shows:
Looks like May 2010, but the copyright is 2005. I tend to believe the copyright. The tool could use some work. That said, its source code is part of the Windows SDK, so can be tweaked.
Until next time with the Media Foundation, happy topologies!