A Fast Bresenham Type Algorithm For Drawing Ellipses by John Kennedy
[xy_vsfilter.git] / src / filters / BaseClasses / source.h
blob5a7bfd45b1b8e6e4e39d39a9c7f047e324eb7824
1 //------------------------------------------------------------------------------
2 // File: Source.h
3 //
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.
7 //
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.
18 // CSource provides:
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
32 #ifndef __CSOURCE__
33 #define __CSOURCE__
35 class CSourceStream; // The class that will handle each pin
39 // CSource
41 // Override construction to provide a means of creating
42 // CSourceStream derived objects - ie a way of creating pins.
43 class CSource : public CBaseFilter {
44 public:
46 CSource(TCHAR *pName, LPUNKNOWN lpunk, CLSID clsid, HRESULT *phr);
47 CSource(TCHAR *pName, LPUNKNOWN lpunk, CLSID clsid);
48 #ifdef UNICODE
49 CSource(CHAR *pName, LPUNKNOWN lpunk, CLSID clsid, HRESULT *phr);
50 CSource(CHAR *pName, LPUNKNOWN lpunk, CLSID clsid);
51 #endif
52 ~CSource();
54 int GetPinCount(void);
55 CBasePin *GetPin(int n);
57 // -- Utilities --
59 CCritSec* pStateLock(void) { return &m_cStateLock; } // provide our critical section
61 HRESULT AddPin(CSourceStream *);
62 HRESULT RemovePin(CSourceStream *);
64 STDMETHODIMP FindPin(
65 LPCWSTR Id,
66 IPin ** ppPin
69 int FindPinNumber(IPin *iPin);
71 protected:
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
83 // CSourceStream
85 // Use this class to manage a stream of data that comes from a
86 // pin.
87 // Uses a worker thread to put data on the pin.
88 class CSourceStream : public CAMThread, public CBaseOutputPin {
89 public:
91 CSourceStream(TCHAR *pObjectName,
92 HRESULT *phr,
93 CSource *pms,
94 LPCWSTR pName);
95 #ifdef UNICODE
96 CSourceStream(CHAR *pObjectName,
97 HRESULT *phr,
98 CSource *pms,
99 LPCWSTR pName);
100 #endif
101 virtual ~CSourceStream(void); // virtual destructor ensures derived class destructors are called too.
103 protected:
105 CSource *m_pFilter; // The parent of this stream
107 // *
108 // * Data Source
109 // *
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
113 // *
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;};
126 // *
127 // * Worker Thread
128 // *
130 HRESULT Active(void); // Starts up the worker thread
131 HRESULT Inactive(void); // Exits the worker thread.
133 public:
134 // thread commands
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); }
142 protected:
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
152 // *
153 // * AM_MEDIA_TYPE support
154 // *
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(
167 LPWSTR * Id
171 #endif // __CSOURCE__