AJA NTV2 SDK  17.6.0.2675
NTV2 SDK 17.6.0.2675
transfrm.h
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // File: Transfrm.h
3 //
4 // Desc: DirectShow base classes - defines classes from which simple
5 // transform codecs may be derived.
6 //
7 // Copyright (c) 1992-2001 Microsoft Corporation. All rights reserved.
8 //------------------------------------------------------------------------------
9 
10 
11 // It assumes the codec has one input and one output stream, and has no
12 // interest in memory management, interface negotiation or anything else.
13 //
14 // derive your class from this, and supply Transform and the media type/format
15 // negotiation functions. Implement that class, compile and link and
16 // you're done.
17 
18 
19 #ifndef __TRANSFRM__
20 #define __TRANSFRM__
21 
22 // ======================================================================
23 // This is the com object that represents a simple transform filter. It
24 // supports IBaseFilter, IMediaFilter and two pins through nested interfaces
25 // ======================================================================
26 
27 class CTransformFilter;
28 
29 // ==================================================
30 // Implements the input pin
31 // ==================================================
32 
34 {
35  friend class CTransformFilter;
36 
37 protected:
39 
40 
41 public:
42 
44  __in_opt LPCTSTR pObjectName,
45  __inout CTransformFilter *pTransformFilter,
46  __inout HRESULT * phr,
47  __in_opt LPCWSTR pName);
48 #ifdef UNICODE
50  __in_opt LPCSTR pObjectName,
51  __inout CTransformFilter *pTransformFilter,
52  __inout HRESULT * phr,
53  __in_opt LPCWSTR pName);
54 #endif
55 
56  STDMETHODIMP QueryId(__deref_out LPWSTR * Id)
57  {
58  return AMGetWideString(L"In", Id);
59  }
60 
61  // Grab and release extra interfaces if required
62 
63  HRESULT CheckConnect(IPin *pPin);
64  HRESULT BreakConnect();
65  HRESULT CompleteConnect(IPin *pReceivePin);
66 
67  // check that we can support this output type
68  HRESULT CheckMediaType(const CMediaType* mtIn);
69 
70  // set the connection media type
71  HRESULT SetMediaType(const CMediaType* mt);
72 
73  // --- IMemInputPin -----
74 
75  // here's the next block of data from the stream.
76  // AddRef it yourself if you need to hold it beyond the end
77  // of this call.
78  STDMETHODIMP Receive(IMediaSample * pSample);
79 
80  // provide EndOfStream that passes straight downstream
81  // (there is no queued data)
82  STDMETHODIMP EndOfStream(void);
83 
84  // passes it to CTransformFilter::BeginFlush
85  STDMETHODIMP BeginFlush(void);
86 
87  // passes it to CTransformFilter::EndFlush
88  STDMETHODIMP EndFlush(void);
89 
90  STDMETHODIMP NewSegment(
91  REFERENCE_TIME tStart,
92  REFERENCE_TIME tStop,
93  double dRate);
94 
95  // Check if it's OK to process samples
96  virtual HRESULT CheckStreaming();
97 
98  // Media type
99 public:
101 
102 };
103 
104 // ==================================================
105 // Implements the output pin
106 // ==================================================
107 
109 {
110  friend class CTransformFilter;
111 
112 protected:
114 
115 public:
116 
117  // implement IMediaPosition by passing upstream
118  IUnknown * m_pPosition;
119 
121  __in_opt LPCTSTR pObjectName,
122  __inout CTransformFilter *pTransformFilter,
123  __inout HRESULT * phr,
124  __in_opt LPCWSTR pName);
125 #ifdef UNICODE
127  __in_opt LPCSTR pObjectName,
128  __inout CTransformFilter *pTransformFilter,
129  __inout HRESULT * phr,
130  __in_opt LPCWSTR pName);
131 #endif
133 
134  // override to expose IMediaPosition
135  STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, __deref_out void **ppv);
136 
137  // --- CBaseOutputPin ------------
138 
139  STDMETHODIMP QueryId(__deref_out LPWSTR * Id)
140  {
141  return AMGetWideString(L"Out", Id);
142  }
143 
144  // Grab and release extra interfaces if required
145 
146  HRESULT CheckConnect(IPin *pPin);
147  HRESULT BreakConnect();
148  HRESULT CompleteConnect(IPin *pReceivePin);
149 
150  // check that we can support this output type
151  HRESULT CheckMediaType(const CMediaType* mtOut);
152 
153  // set the connection media type
154  HRESULT SetMediaType(const CMediaType *pmt);
155 
156  // called from CBaseOutputPin during connection to ask for
157  // the count and size of buffers we need.
158  HRESULT DecideBufferSize(
159  IMemAllocator * pAlloc,
160  __inout ALLOCATOR_PROPERTIES *pProp);
161 
162  // returns the preferred formats for a pin
163  HRESULT GetMediaType(int iPosition, __inout CMediaType *pMediaType);
164 
165  // inherited from IQualityControl via CBasePin
166  STDMETHODIMP Notify(IBaseFilter * pSender, Quality q);
167 
168  // Media type
169 public:
171 };
172 
173 
174 class AM_NOVTABLE CTransformFilter : public CBaseFilter
175 {
176 
177 public:
178 
179  // map getpin/getpincount for base enum of pins to owner
180  // override this to return more specialised pin objects
181 
182  virtual int GetPinCount();
183  virtual CBasePin * GetPin(int n);
184  STDMETHODIMP FindPin(LPCWSTR Id, __deref_out IPin **ppPin);
185 
186  // override state changes to allow derived transform filter
187  // to control streaming start/stop
188  STDMETHODIMP Stop();
189  STDMETHODIMP Pause();
190 
191 public:
192 
193  CTransformFilter(__in_opt LPCTSTR , __inout_opt LPUNKNOWN, REFCLSID clsid);
194 #ifdef UNICODE
195  CTransformFilter(__in_opt LPCSTR , __inout_opt LPUNKNOWN, REFCLSID clsid);
196 #endif
197  ~CTransformFilter();
198 
199  // =================================================================
200  // ----- override these bits ---------------------------------------
201  // =================================================================
202 
203  // These must be supplied in a derived class
204 
205  virtual HRESULT Transform(IMediaSample * pIn, IMediaSample *pOut);
206 
207  // check if you can support mtIn
208  virtual HRESULT CheckInputType(const CMediaType* mtIn) PURE;
209 
210  // check if you can support the transform from this input to this output
211  virtual HRESULT CheckTransform(const CMediaType* mtIn, const CMediaType* mtOut) PURE;
212 
213  // this goes in the factory template table to create new instances
214  // static CCOMObject * CreateInstance(__inout_opt LPUNKNOWN, HRESULT *);
215 
216  // call the SetProperties function with appropriate arguments
217  virtual HRESULT DecideBufferSize(
218  IMemAllocator * pAllocator,
219  __inout ALLOCATOR_PROPERTIES *pprop) PURE;
220 
221  // override to suggest OUTPUT pin media types
222  virtual HRESULT GetMediaType(int iPosition, __inout CMediaType *pMediaType) PURE;
223 
224 
225 
226  // =================================================================
227  // ----- Optional Override Methods -----------------------
228  // =================================================================
229 
230  // you can also override these if you want to know about streaming
231  virtual HRESULT StartStreaming();
232  virtual HRESULT StopStreaming();
233 
234  // override if you can do anything constructive with quality notifications
235  virtual HRESULT AlterQuality(Quality q);
236 
237  // override this to know when the media type is actually set
238  virtual HRESULT SetMediaType(PIN_DIRECTION direction,const CMediaType *pmt);
239 
240  // chance to grab extra interfaces on connection
241  virtual HRESULT CheckConnect(PIN_DIRECTION dir,IPin *pPin);
242  virtual HRESULT BreakConnect(PIN_DIRECTION dir);
243  virtual HRESULT CompleteConnect(PIN_DIRECTION direction,IPin *pReceivePin);
244 
245  // chance to customize the transform process
246  virtual HRESULT Receive(IMediaSample *pSample);
247 
248  // Standard setup for output sample
249  HRESULT InitializeOutputSample(IMediaSample *pSample, __deref_out IMediaSample **ppOutSample);
250 
251  // if you override Receive, you may need to override these three too
252  virtual HRESULT EndOfStream(void);
253  virtual HRESULT BeginFlush(void);
254  virtual HRESULT EndFlush(void);
255  virtual HRESULT NewSegment(
256  REFERENCE_TIME tStart,
257  REFERENCE_TIME tStop,
258  double dRate);
259 
260 #ifdef PERF
261  // Override to register performance measurement with a less generic string
262  // You should do this to avoid confusion with other filters
263  virtual void RegisterPerfId()
264  {m_idTransform = MSR_REGISTER(TEXT("Transform"));}
265 #endif // PERF
266 
267 
268 // implementation details
269 
270 protected:
271 
272 #ifdef PERF
273  int m_idTransform; // performance measuring id
274 #endif
275  BOOL m_bEOSDelivered; // have we sent EndOfStream
276  BOOL m_bSampleSkipped; // Did we just skip a frame
277  BOOL m_bQualityChanged; // Have we degraded?
278 
279  // critical section protecting filter state.
280 
282 
283  // critical section stopping state changes (ie Stop) while we're
284  // processing a sample.
285  //
286  // This critical section is held when processing
287  // events that occur on the receive thread - Receive() and EndOfStream().
288  //
289  // If you want to hold both m_csReceive and m_csFilter then grab
290  // m_csFilter FIRST - like CTransformFilter::Stop() does.
291 
293 
294  // these hold our input and output pins
295 
296  friend class CTransformInputPin;
297  friend class CTransformOutputPin;
300 };
301 
302 #endif /* __TRANSFRM__ */
303 
304 
CTransformFilter::m_pOutput
CTransformOutputPin * m_pOutput
Definition: transfrm.h:299
CTransformFilter::m_bEOSDelivered
BOOL m_bEOSDelivered
Definition: transfrm.h:275
CTransformOutputPin
Definition: transfrm.h:108
CTransformFilter::m_csFilter
CCritSec m_csFilter
Definition: transfrm.h:281
CTransformInputPin::NewSegment
STDMETHODIMP NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate)
Definition: transfrm.cpp:773
CBasePin
Definition: amfilter.h:330
CTransformFilter::m_pInput
CTransformInputPin * m_pInput
Definition: transfrm.h:298
CTransformOutputPin::CurrentMediaType
CMediaType & CurrentMediaType()
Definition: transfrm.h:170
CTransformOutputPin::m_pPosition
IUnknown * m_pPosition
Definition: transfrm.h:118
CTransformOutputPin::CTransformOutputPin
CTransformOutputPin(__in_opt LPCTSTR pObjectName, __inout CTransformFilter *pTransformFilter, __inout HRESULT *phr, __in_opt LPCWSTR pName)
Definition: transfrm.cpp:793
CTransformInputPin::Receive
STDMETHODIMP Receive(IMediaSample *pSample)
Definition: transfrm.cpp:754
CTransformOutputPin::GetMediaType
HRESULT GetMediaType(int iPosition, __inout CMediaType *pMediaType)
Definition: transfrm.cpp:971
CBaseFilter::Pause
STDMETHODIMP Pause()
Definition: amfilter.cpp:555
CBaseFilter::GetPinCount
virtual int GetPinCount() PURE
CTransformInputPin::BreakConnect
HRESULT BreakConnect()
Definition: transfrm.cpp:620
CTransformInputPin::EndOfStream
STDMETHODIMP EndOfStream(void)
Definition: transfrm.cpp:694
CTransformOutputPin::QueryId
STDMETHODIMP QueryId(__deref_out LPWSTR *Id)
Definition: transfrm.h:139
CMediaType
Definition: mtype.h:18
n
unsigned int n
Definition: pstream.cpp:148
CTransformFilter::m_csReceive
CCritSec m_csReceive
Definition: transfrm.h:292
CTransformInputPin::CTransformInputPin
CTransformInputPin(__in_opt LPCTSTR pObjectName, __inout CTransformFilter *pTransformFilter, __inout HRESULT *phr, __in_opt LPCWSTR pName)
Definition: transfrm.cpp:580
CTransformOutputPin::CompleteConnect
HRESULT CompleteConnect(IPin *pReceivePin)
Definition: transfrm.cpp:899
CTransformOutputPin::BreakConnect
HRESULT BreakConnect()
Definition: transfrm.cpp:887
CTransformInputPin::EndFlush
STDMETHODIMP EndFlush(void)
Definition: transfrm.cpp:730
CTransformInputPin::BeginFlush
STDMETHODIMP BeginFlush(void)
Definition: transfrm.cpp:708
CTransformOutputPin::~CTransformOutputPin
~CTransformOutputPin()
Definition: transfrm.cpp:823
pName
CHAR * pName
Definition: amvideo.cpp:26
CTransformInputPin::CheckConnect
HRESULT CheckConnect(IPin *pPin)
Definition: transfrm.cpp:607
CCritSec
Definition: wxutil.h:18
riid
__in REFIID riid
Definition: dllentry.cpp:192
CTransformInputPin::QueryId
STDMETHODIMP QueryId(__deref_out LPWSTR *Id)
Definition: transfrm.h:56
CTransformOutputPin::DecideBufferSize
HRESULT DecideBufferSize(IMemAllocator *pAlloc, __inout ALLOCATOR_PROPERTIES *pProp)
Definition: transfrm.cpp:959
CTransformOutputPin::NonDelegatingQueryInterface
STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, __deref_out void **ppv)
Definition: transfrm.cpp:834
CTransformFilter::m_bQualityChanged
BOOL m_bQualityChanged
Definition: transfrm.h:277
CBaseOutputPin
Definition: amfilter.h:712
CTransformInputPin::CompleteConnect
HRESULT CompleteConnect(IPin *pReceivePin)
Definition: transfrm.cpp:632
MSR_REGISTER
#define MSR_REGISTER(a)
Definition: measure.h:134
CBaseFilter::FindPin
STDMETHODIMP FindPin(LPCWSTR Id, __deref_out IPin **ppPin)
Definition: amfilter.cpp:691
CBaseFilter::GetPin
virtual CBasePin * GetPin(int n) PURE
CTransformInputPin::CurrentMediaType
CMediaType & CurrentMediaType()
Definition: transfrm.h:100
CBaseFilter
Definition: amfilter.h:148
CTransformOutputPin::SetMediaType
HRESULT SetMediaType(const CMediaType *pmt)
Definition: transfrm.cpp:930
AMGetWideString
STDAPI AMGetWideString(LPCWSTR psz, __deref_out LPWSTR *ppszReturn)
Definition: wxutil.cpp:571
CTransformOutputPin::Notify
STDMETHODIMP Notify(IBaseFilter *pSender, Quality q)
Definition: transfrm.cpp:993
CTransformInputPin::CheckMediaType
HRESULT CheckMediaType(const CMediaType *mtIn)
Definition: transfrm.cpp:645
CTransformFilter::m_bSampleSkipped
BOOL m_bSampleSkipped
Definition: transfrm.h:276
CTransformOutputPin::m_pTransformFilter
CTransformFilter * m_pTransformFilter
Definition: transfrm.h:113
CTransformOutputPin::CheckMediaType
HRESULT CheckMediaType(const CMediaType *mtOut)
Definition: transfrm.cpp:912
CBaseInputPin
Definition: amfilter.h:819
CBasePin::m_mt
CMediaType m_mt
Definition: amfilter.h:346
CTransformInputPin::SetMediaType
HRESULT SetMediaType(const CMediaType *mt)
Definition: transfrm.cpp:671
CTransformInputPin::m_pTransformFilter
CTransformFilter * m_pTransformFilter
Definition: transfrm.h:38
CBaseFilter::Stop
STDMETHODIMP Stop()
Definition: amfilter.cpp:512
CTransformInputPin
Definition: transfrm.h:33
CTransformOutputPin::CheckConnect
HRESULT CheckConnect(IPin *pPin)
Definition: transfrm.cpp:867
CTransformFilter
Definition: transfrm.h:174
CTransformInputPin::CheckStreaming
virtual HRESULT CheckStreaming()
Definition: transfrm.cpp:548