1 //------------------------------------------------------------------------------
4 // Desc: DirectShow base classes - defines classes to simplify creation of
5 // ActiveX source filters that support continuous generation of data.
6 // No support is provided for IMediaControl or IMediaPosition.
8 // Copyright (c) 1992-2002 Microsoft Corporation. All rights reserved.
9 //------------------------------------------------------------------------------
13 // Derive your source filter from CSource.
14 // During construction either:
15 // Create some CSourceStream objects to manage your pins
16 // Provide the user with a means of doing so eg, an IPersistFile interface.
19 // IBaseFilter interface management
20 // IMediaFilter interface management, via CBaseFilter
21 // Pin counting for CBaseFilter
23 // Derive a class from CSourceStream to manage your output pin types
24 // Implement GetMediaType/1 to return the type you support. If you support multiple
25 // types then overide GetMediaType/3, CheckMediaType and GetMediaTypeCount.
26 // Implement Fillbuffer() to put data into one buffer.
28 // CSourceStream provides:
29 // IPin management via CBaseOutputPin
30 // Worker thread management
35 class CSourceStream
; // The class that will handle each pin
41 // Override construction to provide a means of creating
42 // CSourceStream derived objects - ie a way of creating pins.
43 class CSource
: public CBaseFilter
{
46 CSource(TCHAR
*pName
, LPUNKNOWN lpunk
, CLSID clsid
, HRESULT
*phr
);
47 CSource(TCHAR
*pName
, LPUNKNOWN lpunk
, CLSID clsid
);
49 CSource(CHAR
*pName
, LPUNKNOWN lpunk
, CLSID clsid
, HRESULT
*phr
);
50 CSource(CHAR
*pName
, LPUNKNOWN lpunk
, CLSID clsid
);
54 int GetPinCount(void);
55 CBasePin
*GetPin(int n
);
59 CCritSec
* pStateLock(void) { return &m_cStateLock
; } // provide our critical section
61 HRESULT
AddPin(CSourceStream
*);
62 HRESULT
RemovePin(CSourceStream
*);
69 int FindPinNumber(IPin
*iPin
);
73 int m_iPins
; // The number of pins on this filter. Updated by CSourceStream
74 // constructors & destructors.
75 CSourceStream
**m_paStreams
; // the pins on this filter.
77 CCritSec m_cStateLock
; // Lock this to serialize function accesses to the filter state
85 // Use this class to manage a stream of data that comes from a
87 // Uses a worker thread to put data on the pin.
88 class CSourceStream
: public CAMThread
, public CBaseOutputPin
{
91 CSourceStream(TCHAR
*pObjectName
,
96 CSourceStream(CHAR
*pObjectName
,
101 virtual ~CSourceStream(void); // virtual destructor ensures derived class destructors are called too.
105 CSource
*m_pFilter
; // The parent of this stream
110 // * The following three functions: FillBuffer, OnThreadCreate/Destroy, are
111 // * called from within the ThreadProc. They are used in the creation of
112 // * the media samples this pin will provide
115 // Override this to provide the worker thread a means
116 // of processing a buffer
117 virtual HRESULT
FillBuffer(IMediaSample
*pSamp
) PURE
;
119 // Called as the thread is created/destroyed - use to perform
120 // jobs such as start/stop streaming mode
121 // If OnThreadCreate returns an error the thread will exit.
122 virtual HRESULT
OnThreadCreate(void) {return NOERROR
;};
123 virtual HRESULT
OnThreadDestroy(void) {return NOERROR
;};
124 virtual HRESULT
OnThreadStartPlay(void) {return NOERROR
;};
130 HRESULT
Active(void); // Starts up the worker thread
131 HRESULT
Inactive(void); // Exits the worker thread.
135 enum Command
{CMD_INIT
, CMD_PAUSE
, CMD_RUN
, CMD_STOP
, CMD_EXIT
};
136 HRESULT
Init(void) { return CallWorker(CMD_INIT
); }
137 HRESULT
Exit(void) { return CallWorker(CMD_EXIT
); }
138 HRESULT
Run(void) { return CallWorker(CMD_RUN
); }
139 HRESULT
Pause(void) { return CallWorker(CMD_PAUSE
); }
140 HRESULT
Stop(void) { return CallWorker(CMD_STOP
); }
143 Command
GetRequest(void) { return (Command
) CAMThread::GetRequest(); }
144 BOOL
CheckRequest(Command
*pCom
) { return CAMThread::CheckRequest( (DWORD
*) pCom
); }
146 // override these if you want to add thread commands
147 virtual DWORD
ThreadProc(void); // the thread function
149 virtual HRESULT
DoBufferProcessingLoop(void); // the loop executed whilst running
153 // * AM_MEDIA_TYPE support
156 // If you support more than one media type then override these 2 functions
157 virtual HRESULT
CheckMediaType(const CMediaType
*pMediaType
);
158 virtual HRESULT
GetMediaType(int iPosition
, CMediaType
*pMediaType
); // List pos. 0-n
160 // If you support only one type then override this fn.
161 // This will only be called by the default implementations
162 // of CheckMediaType and GetMediaType(int, CMediaType*)
163 // You must override this fn. or the above 2!
164 virtual HRESULT
GetMediaType(CMediaType
*pMediaType
) {return E_UNEXPECTED
;}
166 STDMETHODIMP
QueryId(
171 #endif // __CSOURCE__