1. IAMovieSetup interface definition 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; }
2. IPERSIST interface definition IPERSIST: PUBLIC IUNKNOWN {public: Virtual HRESULT stdmethodCallType getClassID (/ * [out] * / clsid * pclassid) = 0;
3. IMediaFilter interface definition 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;
4. IBaseFilter interface definition 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 trila = 0; 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;.};. 5 CBaseFilter class [amfilter.h / amfilter.cpp]
O CBaseFilter particular class of pseudo code is derived from CUnknown, IBaseFilter, IAMovieSetup friend classes: friend class CBasePin; member variable part: FILTER_STATE m_State; // current state: running, pausedIReferenceClock * m_pClock; // this graph's ref clockCRefTime m_tStart; // offset from stream time to reference timeCLSID m_clsid; // This filters clsid used for serializationCCritSec * m_pLock; // Object we use for lockingWCHAR * m_pName; // Full filter nameIFilterGraph * m_pGraph; // Graph we belong toIMediaEventSink * m_pSink; / / Called with notify Eventslong M_Pinversion; // Current Pin Version where m_plock must be assigned via the constructor. The remaining pointers are initialized to NULL.
o Inherited interface functions
l IPersist Interface: STDMETHODIMP GetClassID (CLSID * pClsID); {m_clsid} l IAMovieSetup Interface: STDMETHODIMP Register (); // ask filter to register itself {// get the data by calling the virtual functions GetSetupData, if empty // returns S_FALSE generated Ifiltermapper interface, call amoviesetupregisterfilter completion registration} stdmethodimp unregister (); // and unregister itself
l IMediaFilter Interface: 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 activiVate the Pins.stdMethodimp stop (); {// If the current state m_state is not state_stopped, it is traversed for each connection PIN, call PIN's inactive // If all calls are successful, set m_state as state_stopped.} Stdmethodimp pause (); {// If the current state m_state is State_Stopped, traverse each connected PIN, call PIN's ACTIVE // If all calls were successful, set m_State to State_Paused} // the start parameter is the difference to be added to the // sample's stream time to get the reference time for its presentationSTDMETHODIMP Run (REFERENCE_TIME tStart);. {// first remember the beginning Stream Time m_tstart = TStart; // If the current state is not state_running, the PIN of the PIN is traveled to call the RUN of the PIN. // If all calls are successful, set m_state as state_running.
l IBaseFilter Interface: // pin enumeratorSTDMETHODIMP EnumPins (IEnumPins ** ppEnum); {// accomplished by Helper Class CEnumPins * ppEnum = new CEnumPins (this,} // default behaviour of FindPin assumes pin ids are their namesSTDMETHODIMP FindPin (LPCWSTR Id , IPin ** ppPin); {// traverse each Pin, name comparison if found, return the rear Pin AddRef..} STDMETHODIMP QueryFilterInfo (FILTER_INFO * pInfo); {filled FILTER_INFO} STDMETHODIMP JoinFilterGraph (IFilterGraph * pGraph, LPCWSTR PNAME); {// Simple copy M_PGRAPH and M_PSINK (if you entered PGRAPH support iMediaEventsink), but do not copy the input PNAME to m_pname} // Return a vendor information string. Optional - May Return E_NOTIMPL ./ / memory returned should be freed using CoTaskMemFreeSTDMETHODIMP QueryVendorInfo (LPWSTR * pVendorInfo); {E_NOTIMPL} o the newly added virtual functions // return the current stream time - ie find out what stream time should be appearing nowvirtual HRESULT StreamTime (CRefTime & rtStream); { // First get the current clock time m_pclock-> gettime ((reference_time *) & rtStream) // then correct offset rsstream - = m_tstart} // Find Out The Current PIN VERSION (U sed by enumerators) virtual LONG GetPinVersion (); {m_PinVersion} // you need to supply these to access the pins from the enumeratorvirtual int GetPinCount () PURE; virtual CBasePin * GetPin (int n) PURE; // (override to return filters Setup data) Virtual lpamoviesetup_filter getSetupdata () {Return NULL;}
o other related functions // 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 atparam2; {// If m_psink is not empty, process message psink-> notify (eventcode, eventparam1, eventparam2); / / Otherwise return 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 graphHRESULT ReconnectPin (IPin * pPin, AM_MEDIA_TYPE const * pmt); {// if m_pGraph is not empty, then by IFilterGraph / IFilterGraph2 interface calls Reconnect / ReconnectEx / / Otherwise return e_nointerface} Previous: (2) CBASEPIN class, CBASEOUTPUTPIN class, and CBASEINPUTPIN Class source code resolution