Microsoft DirectX 8.0

CSource Class

CSource class hierarchy

Base class for implementing source filters.

Declaration: Source.h

A filter derived from CSource contains one or more output pins derived from the CSourceStream class. Each output pin creates a worker thread that pushes media samples downstream.

To implement an output pin:

To implement the filter:

To synchronize the filter state among multiple threads, call the CSource::pStateLock method. This method returns a pointer to the filter-state critical section. Use the CAutoLock class to hold the critical section. From a pin, you can access pStateLock from the pin's CBasePin.m_pFilter member variable, as follows:

CAutoLock lock(m_pFilter->pStateLock());

Note  The CSource class is designed to support the push model for data flow. This class is not recommended for creating file-reader filters. File readers should support the pull model, through the IAsyncReader interface. For more information, see Data Flow for Filter Developers.

Protected Member Variables
m_iPinsNumber of pins on the filter.
m_paStreamsArray of pins.
m_cStateLockCritical section object that protects the filter state.
Public Methods
CSourceConstructor method.
~CSourceDestructor method.
GetPinCountRetrieves the number of pins on the filter.
GetPinRetrieves a pin.
pStateLockRetrieves a pointer to the filter's critical section object.
AddPinAdds a new output pin to the filter.
RemovePinRemoves a specified pin from the filter.
FindPinNumberRetrieves the number of a specified pin on the filter.
IBaseFilter Methods
FindPinRetrieves the pin with the specified identifier.

CSource.m_iPins

CSource Class

Number of pins on the filter.

Syntax

int m_iPins;

CSource.m_paStreams

CSource Class

Array of pins.

Syntax

CSourceStream **m_paStreams;

CSource.m_cStateLock

CSource Class

Critical section object that protects the filter state. The pStateLock helper method returns a pointer to this member variable.

Syntax

CCritSec m_cStateLock;

CSource::AddPin

CSource Class

Adds a new output pin to the filter.

Syntax

HRESULT AddPin(
    CSourceStream *pStream
);

Parameters

pStream
Pointer to the CSourceStream object that implements the pin.

Return Value

Returns one of the HRESULT values shown in the following table.

S_OKSuccess
E_OUTOFMEMORYInsufficient memory

Remarks

The CSourceStream constructor calls this method, to add the output pin to the filter.

CSource::CSource

CSource Class

Constructor method.

Syntax

CSource(
    TCHAR *pName,
    LPUNKNOWN lpunk,
    CLSID clsid
);

Parameters

pName
Pointer to a string containing the name of the object. For more information, see CBaseObject.
lpunk
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.
clsid
Class identifier of the filter.

CSource::~CSource

CSource Class

Destructor method.

Syntax

~CSource(void);

CSource::FindPin

CSource Class

Retrieves the pin with the specified identifier. Implements the IBaseFilter::FindPin method.

Syntax

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

Parameters

Id
Pointer to a null-terminated string that identifies the pin.
ppPin
Address of a variable that receives a pointer to the pin's IPin interface. If the method fails, *ppPin is set to NULL

Return Value

Returns one of the HRESULT values shown in the following table.

S_OKSuccess.
E_POINTERNULL pointer argument.
VFW_E_NOT_FOUNDCould not find a pin with this identifier.

Remarks

The first pin is "1"; the second pin is "2"; and so forth. For more information, see CSourceStream::QueryId.

CSource::FindPinNumber

CSource Class

Retrieves the number of a specified pin on the filter.

Syntax

int FindPinNumber(
    IPin *iPin
);

Parameters

iPin
Pointer to the pin's IPin interface.

Return Value

Returns the pin number, or –1 if the pin is not found on this filter. The first pin is numbered zero.

CSource::GetPin

CSource Class

Retrieves a pin. Implements the pure virtual CBaseFilter::GetPin method.

Syntax

CBasePin *GetPin(
    int n
);

Parameters

n
Number of the specified pin.

Return Value

Returns the pointer to the CBasePin object that implements the pin, or NULL if the index is out of range.

CSource::GetPinCount

CSource Class

Retrieves the number of pins on the filter. Implements the pure virtual CBaseFilter::GetPinCount method.

Syntax

int GetPinCount(void);

Return Value

Returns the number of pins on this filter.

CSource::pStateLock

CSource Class

Retrieves a pointer to the filter's critical section object.

Syntax

CCritSec* pStateLock(void);

Return Value

Returns a pointer to the m_cStateLock member variable.

CSource::RemovePin

CSource Class

Removes a specified pin from the filter. The method does not delete the pin.

Syntax

HRESULT RemovePin(
    CSourceStream *pStream
);

Parameters

pStream
Pointer to the CSourceStream object that implements the pin.

Return Value

Returns one of the HRESULT values shown in the following table.

S_OKSuccess.
S_FALSEThe filter does not contain this pin.

Remarks

The CSourceStream destructor calls this method, to remove the output pin from the filter.