当前位置:编程学习 > 网站相关 >>

DirectShow学习笔记-Filter概述

       Filter 是DirectShow中最基本的概念。DirectShow使用Filter Graph来管理Filter(管理者叫做Filter Graph Manager)。Filter Graph是Filter的“容器“,而Filter是Filter Graph中的最小功能模块。   
Filter一般由一个或多个Pin组成,Filter之间通过Pin相互连接,构成一条顺序的链路,Filter根据实现功能的不同大致分为3类:Source Filters、Transform Filters和Rendering Filters。
Filter的类别:
Source Filters:仅有输出Pin,没有输入Pin的Filter。主要负责获取数据,数据源可以是文件也可以是设备。只有输出Pin。
Transform Filters:既有输入Pin也有输出Pin。主要负责数据的格式转换,例如数据流分离/合成、编码/解码等,然后将数据继续往下传输。既有输入Pin又有输出Pin。
Rendering Filters:仅有输入Pin,没有输出Pin的Filter。主要负责数据的最终去向,送达设备或文件。只有输出Pin。
Filter的类型,如以下示图:
 
        Filter是一种COM组件。为了实现在Filter Graph中的统一操作,每个Filter上都至少实现了IBaseFilter接口。IBaseFilter继承自IMediaFilter。Filter Graph Manager正是通过IMediaFilter的接口方法来控制Filter Graph的状态(运行、暂停、停止)转换。实现Filter的文件一般是一个DLL,扩展名可以是.dll。Filter的创建是通过API函数CoCreateInstance来完成的,代码如下:
[cpp]  
HRESULT CoCreateInstance(  
  __in   REFCLSID rclsid, //The CLSID associated with the data and code that will be used to create the object.  
  __in   LPUNKNOWN pUnkOuter, //If NULL, indicates that the object is not being created as part of an aggregate. If non-NULL, pointer to the aggregate object's IUnknown interface (the controlling IUnknown).   
  __in   DWORD dwClsContext, //Context in which the code that manages the newly created object will run. The values are taken from the enumeration CLSCTX.  
  __in   REFIID riid, //A reference to the identifier of the interface to be used to communicate with the object.  
  __out  LPVOID *ppv //Address of pointer variable that receives the interface pointer requested in riid. Upon successful return, * ppv contains the requested interface pointer. Upon failure, * ppv contains NULL.   
);  
该方法的使用就不过多介绍。
 
 
 
补充:综合编程 , 其他综合 ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,