CBaseMediaFilter is an abstract base class that provides support for the IMediaFilter interface. The CBaseMediaFilter class handles State_Stopped, State_Paused, and State_Running state transitions. Typically, this class is used for plug-in distributors rather than filters with pins. Derive your filter classes from the CBaseFilter class (or base classes derived from this) instead of from this class.
All member functions in this class that return HRESULT and accept a pointer as a parameter return E_POINTER when passed a null pointer.
Protected Data Members
m_clsid Class identifier (CLSID) used for serialization using IPersist. m_pClock Pointer to a reference clock used for synchronization. The reference count of the clock object must be incremented using AddRef. Pass NULL if no reference clock is available. m_State Current state of the filter, which can be State_Stopped, State_Paused, or State_Running. m_tStart Offset from the stream time to the reference time.
Member Functions
CBaseMediaFilter Constructs a CBaseMediaFilter object. IsActive Determines if the filter is currently active (running or paused) or stopped.
Overridable Member Functions
StreamTime Returns the current stream time.
GetClassID Returns the class identifier of this filter.
Implemented IMediaFilter Methods
GetState Retrieves the current state of the filter. GetSyncSource Retrieves the current reference clock in use by this filter. Pause Instructs the filter to transition to the new (paused) state. Run Instructs the filter to transition to the new (running) state. SetSyncSource Informs the filter of the reference clock with which it should synchronize activity. Stop Instructs the filter to transition to the new (stopped) state.
Implemented INonDelegatingUnknown Methods
NonDelegatingQueryInterface Passes out references to interfaces supported by CBaseFilter. Override this to pass out pointers to interfaces supported in a derived filter class.
Constructs a CBaseMediaFilter object.
Syntax
CBaseMediaFilter(
TCHAR *pName,
LPUNKNOWN pUnk,
CCritSec *pLock,
REFCLSID clsid
);
Parameters
- pName
- Pointer to the name of the CBaseMediaFilter class.
- pUnk
- IUnknown interface of the delegating object.
- pLock
- Pointer to the object that maintains the lock.
- clsid
- Class identifier used to serialize this filter.
Return Value
No return value.
Fills the pClsID parameter with the class identifier of this filter (from m_clsid).
Syntax
HRESULT GetClassID(
CLSID *pClsID
);
Parameters
- pClsID
- Pointer to the class identifier to be filled out.
Return Value
Returns an HRESULT value.
Retrieves the current state of the filter.
Syntax
HRESULT GetState(
DWORD dwMilliSecsTimeout,
FILTER_STATE *State
);
Parameters
- dwMilliSecsTimeout
- Duration of the time-out, in milliseconds.
- State
- Pointer to the returned state of the filter.
Return Value
Returns S_OK.
Remarks
This member function implements the IMediaFilter::GetState method. It returns the value of the m_State data member.
Filters should derive their filters from CBaseFilter and not from CBaseMediaFilter, so filters will not likely use this member function. Use CBaseFilter::GetState instead.
Retrieves the current reference clock in use by this filter.
Syntax
HRESULT GetSyncSource(
IReferenceClock **pClock
);
Parameters
- pClock
- Address of a pointer to a reference clock; will be set to the IReferenceClock interface.
Return Value
Returns an HRESULT value
Remarks
This member function implements the IMediaFilter::GetSyncSource method. It returns the value of m_pClock after adding a reference to it. Be sure to release the interface by calling the IUnknown::Release method when finished with the pointer.
Filters should derive their filters from CBaseFilter and not from CBaseMediaFilter, so filters will not likely use this member function. Use CBaseFilter::GetSyncSource instead.
Determines if the filter is currently active (running or paused) or stopped.
Syntax
BOOL IsActive(void);
Return Value
Returns TRUE if the filter is paused or running, or FALSE if it is stopped.
Retrieves an interface and increments the reference count.
Syntax
HRESULT NonDelegatingQueryInterface(
REFIID riid,
void **ppv
);
Parameters
- riid
- Reference identifier.
- ppv
- Address of a pointer to the interface.
Return Value
Returns E_POINTER if ppv is invalid. Returns NOERROR if the query is successful or E_NOINTERFACE if it is not.
Remarks
This member function implements the INonDelegatingUnknown::NonDelegatingQueryInterface method and passes out references to the IMediaFilter, IPersist, and IUnknown interfaces. Override this class to return other interfaces on the object in the derived class.
Transitions the filter to State_Paused state if it is not in this state already.
Syntax
HRESULT Pause(void);
Return Value
Returns an HRESULT value (S_OK by default).
Remarks
This member function implements the IMediaFilter::Pause method. It sets the value of m_State to State_Paused.
Filters should derive their filters from CBaseFilter and not from CBaseMediaFilter, so this member function will not likely be used by filters. Use CBaseFilter::Pause instead.
Transitions the filter to State_Running state if it is not in this state already.
Syntax
HRESULT Run(
REFERENCE_TIME tStart
);
Parameters
- tStart
- Reference time value corresponding to stream time 0.
Return Value
Returns an HRESULT value.
Remarks
If the filter is in State_Stopped state, the CBaseMediaFilter::Pause member function is called first to transition the filter to State_Paused state, which has the effect of activating any of the filter's connected pins. If any pin returns a failure return code from its CBasePin::Active member function, the function fails and the state is not changed. If this member function succeeds, the filter's m_State member variable is set to State_Running. This member function holds the filter's lock.
Filters should derive their filters from CBaseFilter and not from CBaseMediaFilter, so filters will not likely use this member function. Use CBaseFilter::Run instead.
Identifies the reference clock to which the filter should synchronize activity.
Syntax
HRESULT SetSyncSource(
IReferenceClock *pClock
);
Parameters
- pClock
- Pointer to the IReferenceClock interface.
Return Value
Returns an HRESULT value.
Remarks
This member function implements the IMediaFilter::SetSyncSource method. It sets the m_pClock data member to the pClock parameter and increments the reference count on the IReferenceClock interface passed in.
This member function is most important to rendering filters and might not apply to other filters.
Filters should derive their filters from CBaseFilter and not from CBaseMediaFilter, so filters will not likely use this member function. Use CBaseFilter::SetSyncSource instead.
Transitions the filter to State_Stopped state if it is not in this state already.
Syntax
HRESULT Stop(void);
Return Value
Returns an HRESULT value.
Remarks
This member function implements the IMediaFilter::Stop method. It sets the m_State member variable to State_Stopped.
Note that filters should derive their filters from CBaseFilter and not from CBaseMediaFilter, so this member function will not likely be used by filters. Use CBaseFilter::Stop instead.
Retrieves the current stream time.
Syntax
virtual HRESULT StreamTime(
CRefTime& rtStream
);
Parameters
- rtStream
- Current stream time.
Return Value
Returns an HRESULT value, which can include the following values.
E_FAIL Unable to get time from clock. S_OK Stream time returned in the rtStream parameter. VFW_E_NO_CLOCK No reference clock is available.
Remarks
Current stream time is the reference clock time minus the stream time offset. All samples with time stamps less than or equal to this time should have been presented.
Top of Page
© 2000 Microsoft and/or its suppliers. All rights reserved. Terms of Use.