zoukankan      html  css  js  c++  java
  • 学习写DSHOW框架下的FILTER之四

    时间:8:23 2011-1-8

    8:30 --- 9:00
    总结与计划

    完善[ FILTER 必须实现的三个接口分析]

    [ PIN 必然实现基本接口]
    IPin
    IQualityControl

    从两个接口方面谈起:
    1.APP用户
    2. FILTER 用户

    APP用户
        其几乎是不要关心FILTER的PIN的.其更多地还是与DSHOW所封装地操作接口通信.

    FILTER 用户
        整个FILTER GRAPH其是通过PIN来连接的.
    PIN所充当的角色:
        连接:  连接当中所需要考虑的问题
        数据的发送
        数据的接收
        数据的管理

    IPin Interface
    This interface is exposed by all input and output pins.
    // 其说明所有的FILTER其均要实现此接口,下面讲了原因.

    The filter graph manager uses this interface to connect pins and perform flushing operations.
    // 这是说明DSHOW( 具体表现为: filter graph manager) 其使用此接口做什么, 使用此接口来连接其他FILTER的PIN,与执行一些操作
    // 并且这些操作,其只是局限于flushing 操作. flush : 数据的发送,接收,
    // 而其是否接收,则是由二方面的因素所决定的: FILTER 的状态( RUN ,STOP,PAUSE), PIN是否已经连接(connect,Disconnent)
    // 而对于数据进行怎么样的处理,其既不是PIN处理,也不是FILTER处理,而是由COM类处理.

    Applications can use this interface to query the pin for information. Applications should never call IPin methods that change a pin's state, such as Connect, Disconnect, BeginFlush, or EndFlush. To connect pins, an application must use the methods in IGraphBuilder.
    // APP其使用此接口能做什么,不能做什么,不能做那由谁来做.
    // APP其只能查询FILTER的状态信息.而不能改变PIN的状态, 那么其由谁来调用: DSHOW(FILTER GRAPH MANAGER),
    // 但其的实现是由FILTER 当中的PIN实现

    // APP其要求连接PINS,其是通过 IGraphBuilder ,可以得到两种信息
    // 1. APP用户其对于FILTER,PIN的操作其均是通过 DSHOW的封装接口来完成的(如:IGraphBuilder,其是管理PIN连接,IMediaControl 其是管理FILTER 状态,,,)
    // 2. FILTER,PIN的调用 其是通过DSHOW来完成的

    Filter developers: The CBasePin, CBaseInputPin, and CBaseOutputPin classes implement this interface. Other base classes derive from these three classes.
    // 其是说明了 对于开发人员,其可以使用已经实现IPin,IQualityControl 接口的类: CBasePin, CBaseInputPin,CBaseOutputPin,或其的子类

    只有 IPin 其还是不足的,因为 IPin 其只是关注了:connect pins and perform flushing operations

    IQualityControl
    其有什么作用,为什么每一个PIN其都要实现此接口呢.

    [ 对于 发送PIN与接收 PIN的思考 ]
        发送,接收PIN其本质还是PIN,所以其要实现PIN的基本接口:IPin, IQualityControl这是相同点的.
    发送,接收PIN其所产生的背景是:
        PIN其的最基本功能已经在IPIN 当中体现了: 连接FILTER.
        PIN其还能为FILTER 接收与发送数据.
        接收到数据
        数据的处理
        发送数据
        ==> 接收与发送数据由DSHOW框架管理,FILTE 开发人员只要管理数据的处理, 思考业务逻辑与框架之间的关系

    receive and send PIN 其之间的数据传递是方式是什么呢: 是SEND PIN 主动将数据放送给RECEIVE,还是RECEIVE 主动到SEND PIN当中取数据
        在整个FILTER GRAPH 当中,我们所需要去管理的部分: 数据.
    什么样FILTER 状态,PIN连接,数据的放送什么.业务流程,这些均是神马浮云.
        其均是为了得到数据,然后处理数据.

        所以关键是得到数据,然后其是怎么样调用业务逻辑来处理

    在DSHOW当中得到数据的得到,数据所在内存管理(创建与释放)这些均是由DSHOW框架来管理的.
        FILTER DEVELOP其只要知道从哪个方法当中得到数据.然后使用数据,只管理使用,而不要去管理释放.
        所以我们只是关注:数据的组合形式与数据的访问形式.
        数据的背景:内存管理,数据的格式,其均是由:IMemAllocator, IMediaSample

    [ 对于 IMemInputPin 的思考]
        其使用发送PIN通过此接口来向接收PIN发送数据.

    [ 对于 IMediaPosition 的思考]
        我们在播放影片的时候,都有一个进度条,其显示了:总时间,当前时间.
    在DSHOW当中定位其是通过时间来实现的.那其以哪一个时间为准呢.这一点在IMediaPosition当中无法体现,但在IMediaPosition的替代接口IMediaSeeking当中有实现
        IMediaPosition 其就是这样的一个功能行为接口.使用DSHOW能通过此接口来控制PIN,
    其通过一个PIN的IMediaPosition就能定位吗,当前进度吗.
        得到当前进度,设置当前进度(在FILTER GRAPH当中,其要对于哪一个设置才有效呢)
    // dshow( filter graph Manager) 其已经封装了同样的一份接口,以方便APP用户其能够控制整个FILTER GRAPH .

    This interface is exposed by the Filter Graph Manager as well as by individual filters. Applications should obtain an IMediaPosition interface pointer from the Filter Graph Manager, not from a filter.
    // 说明: PIN的此个接口其是由 FILTER GRAPH MANAGER来调用的.

    The Filter Graph Manager distributes method calls to all of the renderer filters. The renderer filters propagate the calls upstream to the source filters. This sequence of events ensures that all streams remain synchronized.
    // 说明: FILTER GRAPH MANAGER其是怎么样管理FILTER GRAPH当中的FILTER的.其是从RENDER( 注意是all of the render filters,一个Filter graph MANAGER 其是可以有多个 FIILTER GRAPH ,但可以肯定的是: 一个FILTER GRAPH当中其是可以有多个RENDER的

        [ IMediaPosition 需要去注意的地方]
    The IMediaPosition interface contains methods for seeking to a position within a stream. The IMediaSeeking interface improves on this interface. Applications written in C/C++ should use IMediaSeeking instead of IMediaPosition. However, IMediaSeeking is not compatible with Automation, so applications written in Microsoft® Visual Basic® must use IMediaPosition instead.

        IMediaPosition可以被IMediaSeeking所代替.但其两者的原理是差不多的,只是功能强大些.

    [ 按创建PIN来分接口的种类]
        功能行为接口
            类其实现了这种接口,其就具有这种行为,别人就可以通过这样接口来(操作)访问此对象.
            如:IPin 接口,   
            我们通过IPin接口来使用PIN之间的连接.
            如:IMemInputPin 接口
            其就是使用发送PIN其通过得到接收PIN的IMemInputPin接口来给接收PIN发送数据.
        总结:
        FILTE 对象,PIN对象,其各自之间的通过就是通过接口.所以FILTER, PIN其之所以要继承接口,就是为了提供通信方式
    以这种功能为主导方向,其他的接口均是为了实现以任务而准备的

    其还要实现
    IMediaPosition ,IMediaSeeking

    其还要实现
    IMediaPosition
    IMediaSeeking

    接收PIN其还要实现
    IMemInputPin

    接口其是: 其是要求这个对象有这种能力
    类: 其是使用这个对象有这种性质
    ==> 编写FILTER的时候,一般是直接地继承类,而使用的时候通过 接口

    小知识:
    CBasePin 其使用了装饰者模式,刚刚又看一下其他类,感觉装饰者模式使用的场合很广. 

    时间:9:01 2011-1-10

    [ 对于FILTER GRAPH当中的数据源,数据流动,数据终止的思考]
        时间: 9:01 --- 9:15
    以播放一下影片为例:
        DSHOW其是通过SOURCE FILTER来从本地存储当中读取数据, [ 从外存到内存 再到DSHOW当中]
        数据其在DSHOW当中从SOURCE FIFLTER向RENDER FILTER的流动.
         个人感得此过程有种猜想:
            1. 所有FILTER其均是对于DSHOW当中的同一份内存的操作,数据并没有真正地流,
            但这样不方便且效率跟不上.
            因为SOURCE 其只是读取数据,然后填充内存, TRANSLATE 其对于数据解码( 且过程费时间),RENDER其要等待,
            DSHOW其只有一个BUFFER是不行,其应该是,每一个SOURCE ,TRANSLATE ,RENDER其均是有多个BUFFER,而且
            SOURCE ,TRANSLATE,RENDER其是否是三个线程,且还要使用同步信号, 类似于" 生产者与消费者模型"
        那DSHOW当中的数据其到底是怎么样一回事呢.

    属于SOURCE 性质的FILTE的PIN其还要实现
    IAsyncReader
    注意: 不是所有SOURCE FILTER其要实现,而只是File Source (Async) Filter 要实现此接口

    SOURCE 其要实现IAsyncReader接口, 此接口其有什么用呢,其是由谁来调用呢.
    这涉及到SOURCE FILTER与TRANSLATE FILTER其之间的通信方式, 是SOURCE FILTER其主动地将数据发送到TRANSLATE FILTER BUFFER当中,还是TRANSLATE FILTER其从SOURCE FILTER当中的读取数据.
        在FILTE SOURCE (Async) FILTER 其应该是TRANSLATE FILTER 从SOURCE FILTER当中读取数据. SOURCE OUTPIN 其是由下游程的INPUTPIN来查询与调用的,
        下游的INPUTPIN 其只要向SOURCE PIN发送命令与提供信息: 内存地址,数据大小. 就可以了. SOURCE PIN其完成了其怎么样通知下游的PIN呢.

    [ DirectShow 上关于IAsyncReader 文档]

    IAsyncReader Interface
    The IAsyncReader interface is exposed by output pins that perform asynchronous read operations. The interface is used by the input pin on the downstream filter. Applications do not use this interface.
    // 这是FILTER当中的PIN之间细节信息,其对于APP用户来讲是应该隐藏的, 其只是对于FILTER DEVELOPERS来知道,其对于DSHOW框架也// 是隐藏的吗?

    The Async File Source filter exposes this interface on its output pin.
    // 说明了由哪一种PIN其要实现此接口

    Filter developers: Implement this interface if your output pin delivers data in the form of a byte stream (MEDIATYPE_Stream) and supports the pull model.
    // 对于实现了此接口的PIN的要求:
    // 1. 传递数据的格式为: byte stream( MEDIATYPE_Stream)
    // 2. 支持PULL MODEL(拉模式)

    During the connection process, check whether the downstream pin queries for the IAsyncReader interface. If it does not, your pin should either fail the connection or establish some other transport. (If your pin derives from CBasePin, perform this check in the CBasePin::CheckConnect method.)

    For more information about using this interface, see the following topics:

    Negotiating Allocators
    Data Flow for Filter Developers
    CPullPin Class

    Negotiating Allocators
        10:28 --- 10: 35

    1. 如果是按着DSHOW数据流的猜想,
        1. 每一个BUFFER其大小的确定.BUFFER的管理(创建与释放)

    2. PIN之间的数据传递,不管是PULL还是PUSH,其之间的数据是:共享同一份,还是COPY一份.
        其要分情况讨论:   
        首先要确定:内存当中的数据管理方式.
        这对于APP用户而言是隐藏的.这是FILTER DEVELOPER所需要关心的,其是怎么样让DSHOW 框架所知道呢.
        不管是PULL, PUSH,其最终还是将数据发送给了下游的 INPUT PIN,
        此过程的当中的问题:
        1. 是以INPUT PIN还是OUTPUT PIN的大小为主,在DSHOW当中其是没有规定BUFFER的大小的呢.这一点很灵活.
        2. 

    ==> 我想的接口:
        COM类其只要使用一个方法:得到数据,然后进行数据处理,然后发送,
        而得到与发送的具体细节,其由PIN来管理呢,这也是DSHOW框架的职责.

        PIN其也只是设置一些必要参数,然后其就可以得到数据,然后通知COM类来处理数据,

        1. PUSH模式(INPUT PIN其将数据发送给OUTPUT PIN)
            实现 : INPUT PIN其使用OUTPUT PIN的IMemInputPin

    Data Flow for Filter Developers
        FILTER其是负责 PIN的控制
        PIN其是负责DATA的接收
        COM类A其是负责数据加工处理

    两个PIN之间连接,难道是真正地像实际世界当中的,手拉着手吗,
        就像是手拉着手,DSHOW当中的手拉手是怎么样表达的呢,其通过PIN,PIN其就是手,
        PIN之间其是通过通过另一个对象连接一起,此对象其记录:是些PIN,PIN之间的类型,ALLOCATOR

    FILTER与PIN之间的关系

    FILTE,PIN其之间的通信,其与FILTER GRAPH MANAGER之间的通信

    Data is held in buffers, which are simply arrays of bytes. Each buffer is wrapped by a COM object called a media sample, which implements the IMediaSample interface
    // 说明:each buffer 其是由一个对象管理,用户其是通过 IMediaSample接口来使用 BUFFER.

    对象其实现接口,其就是为让其它对象来使用此接口

    Samples are created by another type of object, called an allocator, which implements the IMemAllocator interface
    // allocator 其是用来创建SAMPLE POOL , 其因为不是用户直接地创建SAMPLE呢,而要于ALLOCATOR来负责管理呢,
    // 分析:如果是用户直接地创建SAMPLE, 用户其除了使用SAMPLE,其还要额外地做哪些事件呢,
    // 因为 PIN之间地连接其是通过SAMPLE来连接的,对于SAMPLE的引用计数,
    // 更为重要的是: PIN之间其不一定只有一个SAMPLE,其有很多的SAMPLE, 形成了一个SAMPLE POOL,类似于线程池.
    // 一个SAMPLE其用完成了,其最好是能够回收循环地使用.
    // 如果这些事件,来样FILTER DEVELOPER来做,很显然是麻烦且重复的,
    // 其由DSHOW框架来完成,DSHOW其提供了ALLOCATOR来管理这一部分.
    // DSHOW框架其给用户地接口是:用户其只要管理使用SAMPLE就可以了,

    An allocator is assigned for every pin connection, although two or more pin connections might share the same allocator.

    // 说明:  allocator 其作用于PIN的连接,在DSHOW当中其有可能是:一个FILTER GRAPH当中所有PIN其均是连接同一个 allocator.
    // allocator其应该是使用生产者消息者模型来管理SAMPLE POOL

    Each allocator creates a pool of media samples and allocates the buffers for each sample. Whenever a filter needs to fill a buffer with data, it requests a sample from the allocator by calling IMemAllocator::GetBuffer.
    // 说明: sample 其是管理数据,而SAMPLE其是由ALLOCATOR来管理,用户要得到数据其通过ALLOCATOR的IMemAllocator接口
    // FILTER其要得到数据,其具体是FILTER的PIN得到,COM类对于得到数据进行加工.
    // filter 需要去填充SAMPLE,其应该是OUTPIN向INPUTPIN 发送数据.OUTPUT其通过 ALLOCATOR来得到SAMPLE,
    // OUTPUT其是得到的ALLOCATOR是哪一个的呢.
    // translate filter 其是有INPUT PIN ,OUTPUT PIN, 连接其的INPUT 与OUTPUT PIN其之间是一种什么,其是否也已经连接了

    If the allocator has any samples that are not currently in use by another filter, the GetBuffer method returns immediately with a pointer to the sample. If all of the allocator's samples are in use, the method blocks until a sample becomes available.
    // 说明:IMemAllocator::GetBuffer其是会BLOCK.

    When the method does return a sample, the filter puts data into the buffer, sets the appropriate flags on the sample (typically including a time stamp), and delivers the sample downstream.
    // 说明:input pin 其要实现IMemAllocator,PIN 其是提供SAMPLE,COM其负责对于SAMPLE进行处理,处理之后,其要对于SAMPLE
    // 进行SET FLAGS, 时间标志是很关键的.
    // 其是怎么样发送到下游INPUT PIN的,其也得到INPUT PIN的IMemAllocator接口的,
    // 在具体地编写过程,此步骤其应该由基本类来完成.

    When a renderer filter receives a sample, it checks the time stamp and holds onto the sample until the filter graph's reference clock indicates that the data should be rendered. After the filter renders the data, it releases the sample. The sample does not go back into the allocator's pool of samples until the sample's reference count is zero, meaning that every filter has released the sample.
    // 说明:sample 其是有引用计数的,难道SOURCE, TRANSLATE, RENDER其均是使用同一个SAMPLE只是添加了一个引用,
    // 类似于递归似添加与删除吗.

    PIN之间要建立连接的业务流程:
        1.

    PIN其传递数据的业务流程:
        1. PIN之间要建立连接:

        2. 确定PIN之间的

    属于RENDER性质的FILTER的PIN其还要实现
    IPinConnection

    IPinConnection Interface
    This interface provides methods for reconnecting an input pin while the filter is still running. The Filter Graph Manager calls methods on this interface when it performs dynamic reconnections (see the IGraphConfig interface). Applications might also use this interface to perform dynamic pin reconnections.

    Filter developers: Implement this interface on any input pin that allows dynamic reconnection or dynamic changes in format.

    // 说明:不是所有的RENDER FILTER的PIN其要实现此接口,而是那些 allows dynamic reconnection or dynamic changes in format

    [FILTER GRAPH MANAGER当中的数据类型]
    1. 其是有MEDIA DATA
    2. 其是有CONTROL DATA

    FILTER ,PIN其均是调用COM类实现自己的业务逻辑

    参考PAGE
    [1]实现file writer filter
    http://blog.csdn.net/wolf_baby/archive/2006/04/21/671312.aspx
    [2]掌握 dump filter 的用法:采集MPG,AVI和ASF的程序代码
    http://blog.csdn.net/markman101/archive/2010/07/19/5746312.aspx

  • 相关阅读:
    bzoj 3930: [CQOI2015]选数
    bzoj 2301: [HAOI2011]Problem b
    HDU 1695 GCD
    2017ACM/ICPC广西邀请赛-重现赛 1007.Duizi and Shunzi
    2017ACM/ICPC广西邀请赛-重现赛 1010.Query on A Tree
    2017ACM/ICPC广西邀请赛-重现赛 1004.Covering
    P3501 [POI2010]ANT-Antisymmetry
    P1171 售货员的难题
    P3385 【模板】负环
    P1659 [国家集训队]拉拉队排练
  • 原文地址:https://www.cnblogs.com/pengxinglove/p/1932506.html
Copyright © 2011-2022 走看看