📄 amfilter.h
字号:
//------------------------------------------------------------------------------// File: AMFilter.h//// Desc: DirectShow base classes - efines class hierarchy for streams// architecture.//// Copyright (c) Microsoft Corporation. All rights reserved.//------------------------------------------------------------------------------#ifndef __FILTER__#define __FILTER__/* The following classes are declared in this header: */class CBaseMediaFilter; // IMediaFilter supportclass CBaseFilter; // IBaseFilter,IMediaFilter supportclass CBasePin; // Abstract base class for IPin interfaceclass CEnumPins; // Enumerate input and output pinsclass CEnumMediaTypes; // Enumerate the pin's preferred formatsclass CBaseOutputPin; // Adds data provider member functionsclass CBaseInputPin; // Implements IMemInputPin interfaceclass CMediaSample; // Basic transport unit for IMemInputPinclass CBaseAllocator; // General list guff for most allocatorsclass CMemAllocator; // Implements memory buffer allocation//=====================================================================//=====================================================================//// QueryFilterInfo and QueryPinInfo AddRef the interface pointers// they return. You can use the macro below to release the interface.////=====================================================================//=====================================================================#define QueryFilterInfoReleaseGraph(fi) if ((fi).pGraph) (fi).pGraph->Release();#define QueryPinInfoReleaseFilter(pi) if ((pi).pFilter) (pi).pFilter->Release();//=====================================================================//=====================================================================// Defines CBaseMediaFilter//// Abstract base class implementing IMediaFilter.//// Typically you will derive your filter from CBaseFilter rather than// this, unless you are implementing an object such as a plug-in// distributor that needs to support IMediaFilter but not IBaseFilter.//// Note that IMediaFilter is derived from IPersist to allow query of// class id.//=====================================================================//=====================================================================class AM_NOVTABLE CBaseMediaFilter : public CUnknown, public IMediaFilter{protected: FILTER_STATE m_State; // current state: running, paused IReferenceClock *m_pClock; // this filter's reference clock // note: all filters in a filter graph use the same clock // offset from stream time to reference time CRefTime m_tStart; CLSID m_clsid; // This filters clsid // used for serialization CCritSec *m_pLock; // Object we use for lockingpublic: CBaseMediaFilter( const TCHAR *pName, LPUNKNOWN pUnk, CCritSec *pLock, REFCLSID clsid); virtual ~CBaseMediaFilter(); DECLARE_IUNKNOWN // override this to say what interfaces we support where STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void ** ppv); // // --- IPersist method --- // STDMETHODIMP GetClassID(CLSID *pClsID); // --- IMediaFilter methods --- STDMETHODIMP GetState(DWORD dwMSecs, FILTER_STATE *State); STDMETHODIMP SetSyncSource(IReferenceClock *pClock); STDMETHODIMP GetSyncSource(IReferenceClock **pClock); // default implementation of Stop and Pause just record the // state. Override to activate or de-activate your filter. // Note that Run when called from Stopped state will call Pause // to ensure activation, so if you are a source or transform // you will probably not need to override Run. STDMETHODIMP Stop(); STDMETHODIMP Pause(); // 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); // --- helper methods --- // return the current stream time - ie find out what // stream time should be appearing now virtual HRESULT StreamTime(CRefTime& rtStream); // Is the filter currently active? (running or paused) BOOL IsActive() { CAutoLock cObjectLock(m_pLock); return ((m_State == State_Paused) || (m_State == State_Running)); };};//=====================================================================//=====================================================================// Defines CBaseFilter//// An abstract class providing basic IBaseFilter support for pin// enumeration and filter information reading.//// We cannot derive from CBaseMediaFilter since methods in IMediaFilter// are also in IBaseFilter and would be ambiguous. Since much of the code// assumes that they derive from a class that has m_State and other state// directly available, we duplicate code from CBaseMediaFilter rather than// having a member variable.//// Derive your filter from this, or from a derived object such as// CTransformFilter.//=====================================================================//=====================================================================class AM_NOVTABLE CBaseFilter : public CUnknown, // Handles an IUnknown public IBaseFilter, // The Filter Interface public IAMovieSetup // For un/registration{friend class CBasePin;protected: 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 versionpublic: CBaseFilter( const TCHAR *pName, // Object description LPUNKNOWN pUnk, // IUnknown of delegating object CCritSec *pLock, // Object who maintains lock REFCLSID clsid); // The clsid to be used to serialize this filter CBaseFilter( TCHAR *pName, // Object description LPUNKNOWN pUnk, // IUnknown of delegating object CCritSec *pLock, // Object who maintains lock REFCLSID clsid, // The clsid to be used to serialize this filter HRESULT *phr); // General OLE return code#ifdef UNICODE CBaseFilter( const CHAR *pName, // Object description LPUNKNOWN pUnk, // IUnknown of delegating object CCritSec *pLock, // Object who maintains lock REFCLSID clsid); // The clsid to be used to serialize this filter CBaseFilter( CHAR *pName, // Object description LPUNKNOWN pUnk, // IUnknown of delegating object CCritSec *pLock, // Object who maintains lock REFCLSID clsid, // The clsid to be used to serialize this filter HRESULT *phr); // General OLE return code#endif ~CBaseFilter(); DECLARE_IUNKNOWN // override this to say what interfaces we support where STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void ** ppv);#ifdef DEBUG STDMETHODIMP_(ULONG) NonDelegatingRelease();#endif // // --- IPersist method --- // STDMETHODIMP GetClassID(CLSID *pClsID); // --- IMediaFilter methods --- STDMETHODIMP GetState(DWORD dwMSecs, FILTER_STATE *State); STDMETHODIMP SetSyncSource(IReferenceClock *pClock); STDMETHODIMP GetSyncSource(IReferenceClock **pClock); // override Stop and Pause so we can activate the pins. // Note that Run will call Pause first if activation needed. // Override these if you want to activate your filter rather than // your pins. STDMETHODIMP Stop(); STDMETHODIMP Pause(); // 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); // --- helper methods --- // return the current stream time - ie find out what // stream time should be appearing now virtual HRESULT StreamTime(CRefTime& rtStream); // Is the filter currently active? BOOL IsActive() { CAutoLock cObjectLock(m_pLock); return ((m_State == State_Paused) || (m_State == State_Running)); }; // Is this filter stopped (without locking) BOOL IsStopped() { return (m_State == State_Stopped); }; // // --- IBaseFilter methods --- // // pin enumerator STDMETHODIMP EnumPins( IEnumPins ** ppEnum); // default behaviour of FindPin assumes pin ids are their names STDMETHODIMP FindPin( LPCWSTR Id, IPin ** ppPin ); STDMETHODIMP QueryFilterInfo( FILTER_INFO * pInfo); STDMETHODIMP JoinFilterGraph( IFilterGraph * pGraph, LPCWSTR pName); // return a Vendor information string. Optional - may return E_NOTIMPL. // memory returned should be freed using CoTaskMemFree // default implementation returns E_NOTIMPL STDMETHODIMP QueryVendorInfo( LPWSTR* pVendorInfo ); // --- helper methods --- // 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); // return the filter graph we belong to IFilterGraph *GetFilterGraph() { return m_pGraph; } // 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); // find out the current pin version (used by enumerators) virtual LONG GetPinVersion(); void IncrementPinVersion(); // you need to supply these to access the pins from the enumerator // and for default Stop and Pause/Run activation. virtual int GetPinCount() PURE; virtual CBasePin *GetPin(int n) PURE; // --- IAMovieSetup methods --- STDMETHODIMP Register(); // ask filter to register itself STDMETHODIMP Unregister(); // and unregister itself // --- setup helper methods --- // (override to return filters setup data) virtual LPAMOVIESETUP_FILTER GetSetupData(){ return NULL; }};//=====================================================================//=====================================================================// Defines CBasePin//// Abstract class that supports the basics of IPin//=====================================================================//=====================================================================class AM_NOVTABLE CBasePin : public CUnknown, public IPin, public IQualityControl{protected: WCHAR * m_pName; // This pin's name IPin *m_Connected; // Pin we have connected to PIN_DIRECTION m_dir; // Direction of this pin CCritSec *m_pLock; // Object we use for locking bool m_bRunTimeError; // Run time error generated bool m_bCanReconnectWhenActive; // OK to reconnect when active bool m_bTryMyTypesFirst; // When connecting enumerate // this pin's types first CBaseFilter *m_pFilter; // Filter we were created by IQualityControl *m_pQSink; // Target for Quality messages LONG m_TypeVersion; // Holds current type version CMediaType m_mt; // Media type of connection CRefTime m_tStart; // time from NewSegment call CRefTime m_tStop; // time from NewSegment double m_dRate; // rate from NewSegment#ifdef DEBUG LONG m_cRef; // Ref count tracing#endif // displays pin connection information#ifdef DEBUG void DisplayPinInfo(IPin *pReceivePin); void DisplayTypeInfo(IPin *pPin, const CMediaType *pmt);#else void DisplayPinInfo(IPin *pReceivePin) {}; void DisplayTypeInfo(IPin *pPin, const CMediaType *pmt) {};#endif // used to agree a media type for a pin connection // given a specific media type, attempt a connection (includes // checking that the type is acceptable to this pin) HRESULT AttemptConnection( IPin* pReceivePin, // connect to this pin const CMediaType* pmt // using this type ); // try all the media types in this enumerator - for each that // we accept, try to connect using ReceiveConnection. HRESULT TryMediaTypes( IPin *pReceivePin, // connect to this pin const CMediaType *pmt, // proposed type from Connect IEnumMediaTypes *pEnum); // try this enumerator // establish a connection with a suitable mediatype. Needs to // propose a media type if the pmt pointer is null or partially // specified - use TryMediaTypes on both our and then the other pin's // enumerator until we find one that works. HRESULT AgreeMediaType( IPin *pReceivePin, // connect to this pin const CMediaType *pmt); // proposed type from Connectpublic: CBasePin( TCHAR *pObjectName, // Object description CBaseFilter *pFilter, // Owning filter who knows about pins CCritSec *pLock, // Object who implements the lock HRESULT *phr, // General OLE return code
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -