AJA NTV2 SDK  18.0.0.2717
NTV2 SDK 18.0.0.2717
source.h
Go to the documentation of this file.
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-2001 Microsoft Corporation. All rights reserved.
9 //------------------------------------------------------------------------------
10 
11 
12 //
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.
17 //
18 // CSource provides:
19 // IBaseFilter interface management
20 // IMediaFilter interface management, via CBaseFilter
21 // Pin counting for CBaseFilter
22 //
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.
27 //
28 // CSourceStream provides:
29 // IPin management via CBaseOutputPin
30 // Worker thread management
31 
32 #ifndef __CSOURCE__
33 #define __CSOURCE__
34 
35 class CSourceStream; // The class that will handle each pin
36 
37 
38 //
39 // CSource
40 //
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:
45 
46  CSource(__in_opt LPCTSTR pName, __inout_opt LPUNKNOWN lpunk, CLSID clsid, __inout HRESULT *phr);
47  CSource(__in_opt LPCTSTR pName, __inout_opt LPUNKNOWN lpunk, CLSID clsid);
48 #ifdef UNICODE
49  CSource(__in_opt LPCSTR pName, __inout_opt LPUNKNOWN lpunk, CLSID clsid, __inout HRESULT *phr);
50  CSource(__in_opt LPCSTR pName, __inout_opt LPUNKNOWN lpunk, CLSID clsid);
51 #endif
52  ~CSource();
53 
54  int GetPinCount(void);
55  CBasePin *GetPin(int n);
56 
57  // -- Utilities --
58 
59  CCritSec* pStateLock(void) { return &m_cStateLock; } // provide our critical section
60 
61  HRESULT AddPin(__in CSourceStream *);
62  HRESULT RemovePin(__in CSourceStream *);
63 
64  STDMETHODIMP FindPin(
65  LPCWSTR Id,
66  __deref_out IPin ** ppPin
67  );
68 
69  int FindPinNumber(__in IPin *iPin);
70 
71 protected:
72 
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.
76 
77  CCritSec m_cStateLock; // Lock this to serialize function accesses to the filter state
78 
79 };
80 
81 
82 //
83 // CSourceStream
84 //
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:
90 
91  CSourceStream(__in_opt LPCTSTR pObjectName,
92  __inout HRESULT *phr,
93  __inout CSource *pms,
94  __in_opt LPCWSTR pName);
95 #ifdef UNICODE
96  CSourceStream(__in_opt LPCSTR pObjectName,
97  __inout HRESULT *phr,
98  __inout CSource *pms,
99  __in_opt LPCWSTR pName);
100 #endif
101  virtual ~CSourceStream(void); // virtual destructor ensures derived class destructors are called too.
102 
103 protected:
104 
105  CSource *m_pFilter; // The parent of this stream
106 
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  // *
114 
115  // Override this to provide the worker thread a means
116  // of processing a buffer
117  virtual HRESULT FillBuffer(IMediaSample *pSamp) PURE;
118 
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;};
125 
126  // *
127  // * Worker Thread
128  // *
129 
130  HRESULT Active(void); // Starts up the worker thread
131  HRESULT Inactive(void); // Exits the worker thread.
132 
133 public:
134  // thread commands
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); }
141 
142 protected:
143  Command GetRequest(void) { return (Command) CAMThread::GetRequest(); }
144  BOOL CheckRequest(Command *pCom) { return CAMThread::CheckRequest( (DWORD *) pCom); }
145 
146  // override these if you want to add thread commands
147  virtual DWORD ThreadProc(void); // the thread function
148 
149  virtual HRESULT DoBufferProcessingLoop(void); // the loop executed whilst running
150 
151 
152  // *
153  // * AM_MEDIA_TYPE support
154  // *
155 
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, __inout CMediaType *pMediaType); // List pos. 0-n
159 
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(__inout CMediaType *pMediaType) {return E_UNEXPECTED;}
165 
166  STDMETHODIMP QueryId(
167  __deref_out LPWSTR * Id
168  );
169 };
170 
171 #endif // __CSOURCE__
172 
CSource::pStateLock
CCritSec * pStateLock(void)
Definition: source.h:59
CSourceStream::QueryId
STDMETHODIMP QueryId(__deref_out LPWSTR *Id)
Definition: source.cpp:199
CSource::GetPinCount
int GetPinCount(void)
Definition: source.cpp:162
CSourceStream::Command
Command
Definition: source.h:135
CSourceStream::CMD_RUN
@ CMD_RUN
Definition: source.h:135
CSource::CSource
CSource(__in_opt LPCTSTR pName, __inout_opt LPUNKNOWN lpunk, CLSID clsid, __inout HRESULT *phr)
Definition: source.cpp:36
CBasePin
Definition: amfilter.h:330
CSourceStream::Run
HRESULT Run(void)
Definition: source.h:138
CSourceStream::OnThreadCreate
virtual HRESULT OnThreadCreate(void)
Definition: source.h:122
CSourceStream::CMD_INIT
@ CMD_INIT
Definition: source.h:135
CSourceStream::CMD_EXIT
@ CMD_EXIT
Definition: source.h:135
CSource::m_iPins
int m_iPins
Definition: source.h:73
CSourceStream::Stop
HRESULT Stop(void)
Definition: source.h:140
CSourceStream
Definition: source.h:88
CSource::m_cStateLock
CCritSec m_cStateLock
Definition: source.h:77
CSourceStream::GetRequest
Command GetRequest(void)
Definition: source.h:143
CSource::GetPin
CBasePin * GetPin(int n)
Definition: source.cpp:174
CSourceStream::FillBuffer
virtual HRESULT FillBuffer(IMediaSample *pSamp) PURE
CSourceStream::DoBufferProcessingLoop
virtual HRESULT DoBufferProcessingLoop(void)
Definition: source.cpp:459
CSource::FindPinNumber
int FindPinNumber(__in IPin *iPin)
Definition: source.cpp:148
CSourceStream::OnThreadDestroy
virtual HRESULT OnThreadDestroy(void)
Definition: source.h:123
CMediaType
Definition: mtype.h:18
CSource::m_paStreams
CSourceStream ** m_paStreams
Definition: source.h:75
n
unsigned int n
Definition: pstream.cpp:148
CSourceStream::Inactive
HRESULT Inactive(void)
Definition: source.cpp:338
CSourceStream::OnThreadStartPlay
virtual HRESULT OnThreadStartPlay(void)
Definition: source.h:124
CSourceStream::ThreadProc
virtual DWORD ThreadProc(void)
Definition: source.cpp:387
pName
CHAR * pName
Definition: amvideo.cpp:26
CSourceStream::m_pFilter
CSource * m_pFilter
Definition: source.h:105
CSource::AddPin
HRESULT AddPin(__in CSourceStream *)
Definition: source.cpp:79
CSourceStream::Init
HRESULT Init(void)
Definition: source.h:136
CSourceStream::GetMediaType
virtual HRESULT GetMediaType(__inout CMediaType *pMediaType)
Definition: source.h:164
CCritSec
Definition: wxutil.h:18
CBaseOutputPin
Definition: amfilter.h:712
CSourceStream::CheckMediaType
virtual HRESULT CheckMediaType(const CMediaType *pMediaType)
Definition: source.cpp:258
CSource
Definition: source.h:43
CSource::~CSource
~CSource()
Definition: source.cpp:64
CSourceStream::~CSourceStream
virtual ~CSourceStream(void)
Definition: source.cpp:248
CBaseFilter
Definition: amfilter.h:148
CSourceStream::Active
HRESULT Active(void)
Definition: source.cpp:296
CSourceStream::GetMediaType
virtual HRESULT GetMediaType(int iPosition, __inout CMediaType *pMediaType)
Definition: source.cpp:278
CSourceStream::CMD_STOP
@ CMD_STOP
Definition: source.h:135
CSourceStream::CSourceStream
CSourceStream(__in_opt LPCTSTR pObjectName, __inout HRESULT *phr, __inout CSource *pms, __in_opt LPCWSTR pName)
Definition: source.cpp:221
CSource::RemovePin
HRESULT RemovePin(__in CSourceStream *)
Definition: source.cpp:103
CSource::FindPin
STDMETHODIMP FindPin(LPCWSTR Id, __deref_out IPin **ppPin)
Definition: source.cpp:128
CSourceStream::CMD_PAUSE
@ CMD_PAUSE
Definition: source.h:135
CSourceStream::Exit
HRESULT Exit(void)
Definition: source.h:137
CSourceStream::CheckRequest
BOOL CheckRequest(Command *pCom)
Definition: source.h:144
CSourceStream::Pause
HRESULT Pause(void)
Definition: source.h:139