您的位置:首页 > 其它

About DirectShow Filters

2014-09-30 09:47 239 查看
引自http://msdn.microsoft.com/en-us/library/dd373390%28v=vs.85%29

DirectShow uses a modular architecture, where each stage of processing is done by a COM object called a filter. DirectShow provides a set of standard filters for applications to use, and developers can write their own custom filters that extend the functionality
of DirectShow. To illustrate, here are the steps needed to play an AVI video file, along with the filters that perform each step:

Read the raw data from the file as a byte stream (File Source filter).
Examine the AVI headers, and parse the byte stream into separate video frames and audio samples (AVI Splitter filter).
Decode the video frames (various decoder filters, depending on the compression format).
Draw the video frames (Video Renderer filter).
Send the audio samples to the sound card (Default DirectSound Device filter).

These filters are shown in the following diagram.



As the diagram shows, each filter is connected to one or more other filters. The connection points are also COM objects, calledpins. Filters use pins to move data from one filter the next. The arrows in the diagram show the direction in which the
data travels. In DirectShow, a set of filters is called afilter graph.

Filters have three possible states: running, stopped, and paused. When a filter is running, it processes media data. When it is stopped, it stops processing data. The paused state is used to cue data before running; the sectionData
Flow in the Filter Graph describes this concept in more detail. With very rare exceptions, state changes are coordinated throughout the entire filter graph; all the filters in the graph switch states in unison. Thus, the entire filter graph is also said
to be running, stopped, or paused.

Filters can be grouped into several broad categories:

A source filter introduces data into the graph. The data might come from a file, a network, a camera, or anywhere else. Each source filter handles a different type of data source.
A transform filter takes an input stream, processes the data, and creates an output stream. Encoders and decoders are examples of transform filters.
Renderer filters sit at the end of the chain. They receive data and present it to the user. For example, a video renderer draws video frames on the display; an audio renderer sends audio data to the sound card; and a file-writer filter writes data
to a file.
A splitter filter splits an input stream into two or more outputs, typically parsing the input stream along the way. For example, the AVI Splitter parses a byte stream into separate video and audio streams.
A mux filter takes multiple inputs and combines them into a single stream. For example, the AVI Mux performs the inverse operation of the AVI Splitter. It takes audio and video streams and produces an AVI-formatted byte stream.

The distinctions between these categories are not absolute. For example, the ASF Reader filter acts as both a source filter and a splitter filter.

All DirectShow filters expose the
IBaseFilter interface, and all pins expose the
IPin interface. DirectShow also defines many other interfaces that support more specific functionality.

Related topics

About the Filter Graph Manager
Data Flow in the Filter Graph

DirectShow Filters

1..如果将这个graph看成水流系统的话,filter是水处理中枢,pin就是管道和filter的阀门。


pin决定了数据流的类型格式和每次允许的流量(每个sample的大小),filter可以对数据进行处理或者存储。

2..没有"重载filter"的说法,一般都是继承。

filter基本的类型了三种:

source filter——数据源,只有一个output pin,没有input pin;

transform filter——中间处理数据的filter,一个input 一个output;

sink filter(或者叫做render filter)——数据终端,流的最终到达位置,只有input,没有outpin;

这三种类型dshow都有提供接口类,直接继承就可以了.

如果你的filter是除此以外的特殊filter(我们写的filter大部分都是一进一出的transform filter)——特殊不特殊指的是pin的数量,那么你可以继承CBaseFilter,这个是所有filter类的基类。


filter类和pin类是互为友元关系,并互设为成员变量联系起来。

3..如果你用directX自带的可视化工具graphedit的话,不需要考虑filter间的connect、pin的媒体检测和枚举、run这些问题,只要写好你的filter加载到这个工具中就行,filter的编写流程以及如何加载,dshow的自带文档都有教学。

如果是自己写底层的源代码进行filter连接,你可以去查API(IGraphBuilder、IBaseFilter这两个类),网上资料就那几篇,需要自己去研究了,建议还是用graphedit这个工具.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: