How DirectShow Decides Which Filters to Use

来源:互联网 发布:知乎专栏怎么写文章 编辑:程序博客网 时间:2024/04/30 16:38

How DirectShow Decides Which Filters to Use

MC supports a number of audio file types natively. When you playback a MP3 file, for example, MC uses it's own internal high-qualityfilters to split and decode the file and send it to the appropriateoutput device (sound card). When you attempt to play a file back in MCthat it doesn't support natively, MC tries a number of different thingsto get the file to play. The first step is to attempt to render thefile using DirectShow.

By default, if you haven't modified the DirectShow playbackconfiguration options in MC, and you play a file back, it simply asksWindows to build the regular DirectShow graph. This works the same asWindows Media Player and any other DirectShow player does when playingback a file.

Illustration of how Filters get selected. In the example, even though all of the filters support MP4 playback, DirectShow will use the Haali filter because it has the highest Merit Score.
Enlarge
Illustrationof how Filters get selected. In the example, even though all of thefilters support MP4 playback, DirectShow will use the Haali filterbecause it has the highest Merit Score.

The default graph is built based on two factors: a) each individualfilter "tells" DirectShow what kinds of media streams it is able torender, and b) DirectShow assigns (or more precisely, the filtersassign to themselves when you install them) a priority number calledits "merit score".

When you play a file, DirectShow attempts to build a chain offilters capable of decoding the content based on these two pieces ofinformation. It tries filters matching the stream type, in the order ofwhich filter has the highest priority first. If the "render" fails,then it tries the next highest priority set, and so on and so forthuntil it runs out of options or succeeds. Just because it "works"doesn't mean it's necessarily finding the "best" filter graph. It justuses whichever one it "bumbles" into that works first.

MC's DirectShow Playback settings dialog overrides the prioritypart of this sequence of events. If you select one or more of thosefilters, it overrides the normal merit score system (perhaps bytemporarily elevating them to the highest possible Merit -- I'm notsure of the details of this mechanism). So, you can force it to "try"to use a different filter to play a file back, but you can't force itto use one or fail outright. If that graph fails (the output pins can'tconnect to the input pins to build a complete render graph) then iteither ignores certain selected filters, or it fails over completely tothe default graph. (MC's DirectShow Playback Settings dialog providesessentially identical functionality to ZoomPlayer's "Smart Play"feature.)

I've simplified this a bit for the sake of explanation, butthat's the general idea of what happens when you try to play a fileback via DirectShow.

原创粉丝点击