Microsoft DirectX 8.0

CBaseMediaFilter Class

CBaseMediaFilter class hierarchy

Base class that implements the IMediaFilter interface. Use this class for plug-in distributors or other objects that need to support IMediaFilter without supporting the IBaseFilter interface. Do not use this class for filters. Instead, use the CBaseFilter class, or a base class derived from CBaseFilter.

Declaration: Amfilter.h

Protected Member Variables
m_StateCurrent state of the object.
m_pClockPointer to the object's reference clock.
m_tStartReference time that corresponds to stream time 0.
m_clsidClass identifier (CLSID) of the object.
m_pLockPointer to a critical section.
Public Methods
CBaseMediaFilterConstructor method.
~CBaseMediaFilterDestructor method. Virtual.
StreamTimeRetrieves the current stream time. Virtual.
IsActiveDetermines whether the object is active (running or paused).
IPersist Methods
GetClassIDRetrieves the class identifier.
IMediaFilter Methods
GetStateRetrieves the object's state (running, stopped, or paused).
SetSyncSourceSets a reference clock for the object.
GetSyncSourceRetrieves the reference clock that the object is using.
StopStops the object.
PausePauses the object.
RunRuns the object.

CBaseMediaFilter.m_State

CBaseMediaFilter Class

Current state of the object.

Syntax

FILTER_STATE m_State;

CBaseMediaFilter.m_pClock

CBaseMediaFilter Class

Pointer to the object's reference clock.

Syntax

IReferenceClock *m_pClock;

CBaseMediaFilter.m_tStart

CBaseMediaFilter Class

Reference time that corresponds to stream time 0.

Syntax

CRefTime m_tStart;

CBaseMediaFilter.m_clsid

CBaseMediaFilter Class

Class identifier (CLSID) of the object.

Syntax

CLSID m_clsid;

CBaseMediaFilter.m_pLock

CBaseMediaFilter Class

Pointer to a critical section.

Syntax

CCritSec *m_pLock;

Remarks

The critical section is held during state transitions (Run, Pause, Stop), when accessing the reference clock (SetSyncSource, GetSyncSource), and in the IsActive method.

CBaseMediaFilter::CBaseMediaFilter

CBaseMediaFilter Class

Constructor method.

Syntax

CBaseMediaFilter(
    const TCHAR *pName,
    LPUNKNOWN pUnk,
    CCritSec *pLock,
    REFCLSID clsid
);

Parameters

pName
Pointer to a string containing the name of the object.
pUnk
Pointer to the owner of this object. If the object is aggregated, pass a pointer to the aggregating object's IUnknown interface. Otherwise, set this parameter to NULL.
pLock
Pointer to a CCritSec lock, used to serialize state changes.
clsid
Class identifier of the object.

Remarks

If another object contains or aggregates the CBaseMediaFilter object, the CCritSec lock might be external to the CBaseMediaFilter object. In that case, pass a pointer to the lock in pLock.

Otherwise, you can:

CBaseMediaFilter::~CBaseMediaFilter

CBaseMediaFilter Class

Destructor method.

Syntax

CBaseMediaFilter(void);

Remarks

Always stop the object before destroying it.

CBaseMediaFilter::GetClassID

CBaseMediaFilter Class

Retrieves the class identifier. Implements the IPersist::GetClassID method.

Syntax

HRESULT GetClassID(
    CLSID *pClsID
);

Parameters

pClsID
Pointer to a variable that receives the class identifier.

Return Value

Returns S_OK or E_POINTER.

CBaseMediaFilter::GetState

CBaseMediaFilter Class

Retrieves the object's state (running, stopped, or paused). Implements the IMediaFilter::GetState method.

Syntax

HRESULT GetState(
    DWORD dwMilliSecsTimeout,
    FILTER_STATE *State
);

Parameters

dwMilliSecsTimeout
Time-out interval, in milliseconds.
State
Pointer to a variable that receives a member of the FILTER_STATE enumerated type, indicating the object's state.

Return Value

Returns S_OK or E_POINTER.

Remarks

In the base class, all state transitions are synchronous and the dwMilliSecsTimeout parameter is ignored. If a derived class performs asynchronous state transitions, it should override this method to wait during state transitions, with a time-out of dwMilliSecsTimeout milliseconds.

CBaseMediaFilter::GetSyncSource

CBaseMediaFilter Class

Retrieves the reference clock that the object is using. Implements the IMediaFilter::GetSyncSource method.

Syntax

HRESULT GetSyncSource(
    IReferenceClock **pClock
);

Parameters

pClock
Address of a variable that receives a pointer to the clock's IReferenceClock interface.

Return Value

Returns S_OK or E_POINTER.

Remarks

If the object is not using a reference clock, *pClock is set to NULL. When the method returns, if *pClock is non-NULL, the IReferenceClock interface has an outstanding reference count. Be sure to release it when you are done.

CBaseMediaFilter::IsActive

CBaseMediaFilter Class

Determines whether the object is active (running or paused).

Syntax

BOOL IsActive(void);

Return Value

Returns TRUE if the object is paused or running, or FALSE if it is stopped.

CBaseMediaFilter::Pause

CBaseMediaFilter Class

Pauses the object. Implements the IMediaFilter::Pause method.

Syntax

HRESULT Pause(void);

Return Value

Returns S_OK.

Remarks

In the base class, this method sets the m_State member variable to State_Paused but does nothing else.

CBaseMediaFilter::Run

CBaseMediaFilter Class

Runs the object. Implements the IMediaFilter::Run method.

Syntax

HRESULT Run(
    REFERENCE_TIME tStart
);

Parameters

tStart
Reference time corresponding to stream time 0.

Return Value

Returns S_OK.

Remarks

If the object is stopped, this method pauses the object by calling the CBaseMediaFilter::Pause method. It then sets the m_State member variable to State_Running.

Stream time is calculated as the current reference time minus tStart. A media sample with a time stamp of zero should be rendered at time tStart.

CBaseMediaFilter::SetSyncSource

CBaseMediaFilter Class

Sets a reference clock for the object. Implements the IMediaFilter::SetSyncSource method.

Syntax

HRESULT SetSyncSource(
    IReferenceClock *pClock
);

Parameters

pClock
Pointer to the clock's IReferenceClock interface, or NULL.

Return Value

Returns S_OK.

CBaseMediaFilter::Stop

CBaseMediaFilter Class

Stops the object. Implements the IMediaFilter::Stop method.

Syntax

HRESULT Stop(void);

Return Value

Returns S_OK.

Remarks

In the base class, this method sets the m_State member variable to State_Stopped but does nothing else.

CBaseMediaFilter::StreamTime

CBaseMediaFilter Class

Retrieves the current stream time.

Syntax

virtual HRESULT StreamTime(
    CRefTime& rtStream
);

Parameters

rtStream
Reference to a CRefTime object that receives the current stream time.

Return Value

Returns an HRESULT value. Possible values include those listed in the following table.

S_OKSuccess.
VFW_E_NO_CLOCKNo reference clock is available.

Remarks

Stream time is defined as the current reference time (as given by the reference clock) minus the start time (specified by m_tStart). A media sample's time stamp specifies the stream time when it should be rendered. If a sample with a time stamp less than the current stream time has not yet been rendered, it is late.