分享
 
 
 

DirectShow 学习(三) CBaseFilter类源代码解析

王朝other·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

IAMovieSetup接口定义

IAMovieSetup : public IUnknown

{

public:

// Adds the filter to the registry.

virtual HRESULT STDMETHODCALLTYPE Register( void) = 0;

// Removes the filter from the registry.

virtual HRESULT STDMETHODCALLTYPE Unregister( void) = 0;

};

IPersist 接口定义

IPersist : public IUnknown

{

public:

virtual HRESULT STDMETHODCALLTYPE GetClassID(

/* [out] */ CLSID *pClassID) = 0;

};

IMediaFilter 接口定义

IMediaFilter : public IPersist

{

public:

// Stops the filter.

virtual HRESULT STDMETHODCALLTYPE Stop( void) = 0;

// Pauses the filter.

virtual HRESULT STDMETHODCALLTYPE Pause( void) = 0;

// Runs the filter.

virtual HRESULT STDMETHODCALLTYPE Run(

REFERENCE_TIME tStart) = 0;

// Retrieves the state of the filter (running, stopped, or paused).

virtual HRESULT STDMETHODCALLTYPE GetState(

/* [in] */ DWORD dwMilliSecsTimeout,

/* [out] */ FILTER_STATE *State) = 0;

// Sets the reference clock for the filter or the filter graph.

virtual HRESULT STDMETHODCALLTYPE SetSyncSource(

/* [in] */ IReferenceClock *pClock) = 0;

// Retrieves the current reference clock.

virtual HRESULT STDMETHODCALLTYPE GetSyncSource(

/* [out] */ IReferenceClock **pClock) = 0;

};

IBaseFilter接口定义

IBaseFilter : public IMediaFilter

{

public:

// Enumerates the pins on this filter.

virtual HRESULT STDMETHODCALLTYPE EnumPins(

/* [out] */ IEnumPins **ppEnum) = 0;

// Retrieves the pin with the specified identifier.

virtual HRESULT STDMETHODCALLTYPE FindPin(

/* [string][in] */ LPCWSTR Id,

/* [out] */ IPin **ppPin) = 0;

// Notifies the filter that it has joined or left the filter graph.

virtual HRESULT STDMETHODCALLTYPE QueryFilterInfo(

/* [out] */ FILTER_INFO *pInfo) = 0;

// Retrieves information about the filter.

virtual HRESULT STDMETHODCALLTYPE JoinFilterGraph(

/* [in] */ IFilterGraph *pGraph,

/* [string][in] */ LPCWSTR pName) = 0;

// Retrieves a string containing vendor information.

virtual HRESULT STDMETHODCALLTYPE QueryVendorInfo(

/* [string][out] */ LPWSTR *pVendorInfo) = 0;

};

CBaseFilter类 [amfilter.h/amfilter.cpp]

CBaseFilter类的的具体实现伪代码

派生自 CUnknown, IBaseFilter, IAMovieSetup

友元类: friend class CBasePin;

成员变量部分:

FILTER_STATE m_State; // current state: running, paused

IReferenceClock *m_pClock; // this graph's ref clock

CRefTime m_tStart; // offset from stream time to reference time

CLSID m_clsid; // This filters clsid used for serialization

CCritSec *m_pLock; // Object we use for locking

WCHAR *m_pName; // Full filter name

IFilterGraph *m_pGraph; // Graph we belong to

IMediaEventSink *m_pSink; // Called with notify events

LONG m_PinVersion; // Current pin version

其中,m_pLock必须通过Constructor赋值。其余指针初始化为NULL。

继承的接口函数实现

IPersist接口:

STDMETHODIMP GetClassID(CLSID *pClsID);{ m_clsid }

IAMovieSetup接口:

STDMETHODIMP Register(); // ask filter to register itself

{

// 通过调用virtual函数GetSetupData得到数据,如果为空返回S_FALSE

// 生成IFilterMapper接口,调用AMovieSetupRegisterFilter完成注册

}

STDMETHODIMP Unregister(); // and unregister itself

IMediaFilter接口:

STDMETHODIMP GetState(DWORD dwMSecs, FILTER_STATE *State);

{ m_State }

STDMETHODIMP SetSyncSource(IReferenceClock *pClock);

{ pClock->AddRef, m_pClock->Release, m_pClock = pClock;}

STDMETHODIMP GetSyncSource(IReferenceClock **pClock);

{ m_pClock->AddRef, *pCLock = m_pClock; }

// override Stop and Pause so we can activate the pins.

STDMETHODIMP Stop();

{

// 如果当前状态m_State不是State_Stopped,则遍历每个连接的Pin,调用Pin的Inactive

// 如果所有的调用均成功,设置m_State为State_Stopped.

}

STDMETHODIMP Pause();

{

// 如果当前状态m_State是State_Stopped,则遍历每个连接的Pin,调用Pin的Active

// 如果所有调用均成功,设置m_State为State_Paused.

}

// the start parameter is the difference to be added to the

// sample's stream time to get the reference time for its presentation

STDMETHODIMP Run(REFERENCE_TIME tStart);

{

// 首先记住Stream的开始时间 m_tStart = tStart;

// 如果当前状态不是State_Running,则遍历每个连接的Pin,调用Pin的Run。

// 如果所有调用均成功,设置m_State为State_Running.

}

IBaseFilter接口:

// pin enumerator

STDMETHODIMP EnumPins(IEnumPins ** ppEnum);

{

// 通过Helper Class CEnumPins来完成 *ppEnum = new CEnumPins(this,

}

// default behaviour of FindPin assumes pin ids are their names

STDMETHODIMP FindPin(LPCWSTR Id, IPin ** ppPin);

{

// 遍历每个Pin,比较名称。如果找到,则对该Pin AddRef后返回。

}

STDMETHODIMP QueryFilterInfo(FILTER_INFO * pInfo);{ 填充FILTER_INFO }

STDMETHODIMP JoinFilterGraph(IFilterGraph * pGraph, LPCWSTR pName);

{

// 简单的复制m_pGraph和m_pSink(如果输入的pGraph支持IMediaEventSink),但不对其AddRef

// 将输入的pName复制到m_pName

}

// return a Vendor information string. Optional - may return E_NOTIMPL.

// memory returned should be freed using CoTaskMemFree

STDMETHODIMP QueryVendorInfo(LPWSTR* pVendorInfo);{ E_NOTIMPL }

新增加的virtual函数

// return the current stream time - ie find out what stream time should be appearing now

virtual HRESULT StreamTime(CRefTime& rtStream);

{

// 首先得到当前Clock的时间 m_pClock->GetTime ((REFERENCE_TIME*)&rtStream)

// 然后矫正偏移 rsStream -= m_tStart

}

// find out the current pin version (used by enumerators)

virtual LONG GetPinVersion();{m_PinVersion }

// you need to supply these to access the pins from the enumerator

virtual int GetPinCount() PURE;

virtual CBasePin *GetPin(int n) PURE;

// (override to return filters setup data)

virtual LPAMOVIESETUP_FILTER GetSetupData(){ return NULL; }

其他一些相关函数

// send an event notification to the filter graph if we know about it. returns S_OK if delivered,

// S_FALSE if the filter graph does not sink events, or an error otherwise.

HRESULT NotifyEvent(long EventCode, LONG_PTR EventParam1, LONG_PTR EventParam2);

{

// 如果m_pSink不为空,则处理消息pSink->Notify(EventCode, EventParam1, EventParam2);

// 否则返回E_NOTIMPL

}

// Request reconnect

// pPin is the pin to reconnect, pmt is the type to reconnect with - can be NULL

// Calls ReconnectEx on the filter graph

HRESULT ReconnectPin(IPin *pPin, AM_MEDIA_TYPE const *pmt);

{

// 如果m_pGraph不为空,则通过IFilterGraph/IFilterGraph2接口调用Reconnect/ReconnectEx

// 否则返回E_NOINTERFACE

}

学习(四)将侧重于一些Helper Class的实现和CSource的分析。

上一篇:学习(二)CBasePin类、CBaseOutputPin类和CBaseInputPin类源代码解析

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有