CSource Class
Microsoft DirectShow 9.0 |
CSource Class
The CSource class is a base class for implementing source filters. 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, do the following:
- Derive a class from CSourceStream.
- Override the CSourceStream::GetMediaType method and possibly the CSourceStream::CheckMediaType method, which validate media types for the pin.
- Implement the CBaseOutputPin::DecideBufferSize method, which returns the pin's buffer requirements.
- Implement the CSourceStream::FillBuffer method, which fills a media sample buffer with data.
To implement the filter, do the following:
- Derive a class from CSource.
- In the constructor, create one or more output pins derived from CSourceStream. The pins automatically add themselves to the filter in their constructor methods, and remove themselves in their destructor methods.
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.
Requirements
** Header:** Declared in Source.h; include Streams.h.
** Library:** Use Strmbase.lib (retail builds) or Strmbasd.lib (debug builds).
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. |