Microsoft DirectX 8.0 |
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_iPins | Number of pins on the filter. |
m_paStreams | Array of pins. |
m_cStateLock | Critical section object that protects the filter state. |
Public Methods | |
CSource | Constructor method. |
~CSource | Destructor method. |
GetPinCount | Retrieves the number of pins on the filter. |
GetPin | Retrieves a pin. |
pStateLock | Retrieves a pointer to the filter's critical section object. |
AddPin | Adds a new output pin to the filter. |
RemovePin | Removes a specified pin from the filter. |
FindPinNumber | Retrieves the number of a specified pin on the filter. |
IBaseFilter Methods | |
FindPin | Retrieves the pin with the specified identifier. |
Number of pins on the filter.
Syntax
int m_iPins;
Array of pins.
Syntax
CSourceStream **m_paStreams;
Critical section object that protects the filter state. The pStateLock helper method returns a pointer to this member variable.
Syntax
CCritSec m_cStateLock;
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_OK Success E_OUTOFMEMORY Insufficient memory
Remarks
The CSourceStream constructor calls this method, to add the output pin to the filter.
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.
Destructor method.
Syntax
~CSource(void);
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_OK Success. E_POINTER NULL pointer argument. VFW_E_NOT_FOUND Could 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.
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.
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.
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.
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.
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_OK Success. S_FALSE The filter does not contain this pin.
Remarks
The CSourceStream destructor calls this method, to remove the output pin from the filter.