[DirectShow] 004 - About DirectShow Filters

来源:互联网 发布:深圳市软件企业协会 编辑:程序博客网 时间:2024/04/30 12:21

        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).
        DirectShow使用模块体系,在处理的每一个阶段都是由被称作filter的COM对象来完成。DirectShow提供了一套标准filters集给应用程序使用,开发人员也可以使用DirectShow的扩展功能编写自定义filters。下图显示播放一个视频文件所需要的步骤,以及执行的步骤:
        以二进制流的形式从文件中读取数据流。(File Source filter).
        检测AVI文件头,从二进制数据流中分离出视频帧和音频采样。(AVI Splitter filter).
        解码视频帧(多种解码filters,依赖于压缩格式)
        画视频帧(Video Renderer filter).
        发送音频采样到声卡。

        As the diagram shows, each filter is connected to one or more other filters. The connection points are also COM objects, called pins. 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 a filter graph.
        图中显示的,每一个filter与一个或多个其他的filters连接。连接点也是COM对象,叫做pins。Filters利用pins把数据从一个filter移动到下一个filter。图中箭头的方向就是数据流动的方向。在DirectShow中,一个filters的集合叫做filter 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 section Data 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有三种状态:运行、停止和暂停。当filter处于运行状态的时候,它处理媒体数据;当filter处于停止状态的时候,它停止处理数据;暂停状态习惯于在运行之前发送提示。在Data Flow in the Filter Graph一节中对这一概念有详细的描述。With very rare exceptions, state changes are coordinated throughout the entire filter graph;graph中的所有filters保持一致的状态。


        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.
        Filters可以被分为几大种类:
        source filter 把数据输入到graph。数据可以来源于一个文件,网络,摄像头或者其它。每个source filter处理不同类型的数据源。
        transform filter 产生一个输入流,处理数据,创建一个输出流。编码器和解码器就是一个transform filter的例子。
        renderer filters 在链路的末端。它们接收数据并呈现给用户。例如视频renderer在显示器上画视频帧;音频renderer发送音频数据给声卡;file-writer filter把数据写到文件中。
        splitter filter 把输入流分离成两个或多个输出流。例如,AVI splitter 把二进制数据流分解成视频流和音频流。
        mux filter产生多种输入并把他们合并到单一的数据流。例如,AVI Mux 执行AVI Splitter的反操作。它产生视频和音频流并产生AVI格式的二进制流。
        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.
        所有DirectShow filters都暴露IBaseFilter接口,所有pins都暴露IPin接口。DirectShow还定义了许多其他的接口来支持更多具体的功能。

原创粉丝点击