AJA NTV2 SDK  17.6.0.2675
NTV2 SDK 17.6.0.2675
transip.h
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // File: TransIP.h
3 //
4 // Desc: DirectShow base classes - defines classes from which simple
5 // Transform-In-Place filters may be derived.
6 //
7 // Copyright (c) 1992-2001 Microsoft Corporation. All rights reserved.
8 //------------------------------------------------------------------------------
9 
10 
11 //
12 // The difference between this and Transfrm.h is that Transfrm copies the data.
13 //
14 // It assumes the filter has one input and one output stream, and has no
15 // interest in memory management, interface negotiation or anything else.
16 //
17 // Derive your class from this, and supply Transform and the media type/format
18 // negotiation functions. Implement that class, compile and link and
19 // you're done.
20 
21 
22 #ifndef __TRANSIP__
23 #define __TRANSIP__
24 
25 // ======================================================================
26 // This is the com object that represents a simple transform filter. It
27 // supports IBaseFilter, IMediaFilter and two pins through nested interfaces
28 // ======================================================================
29 
31 
32 // Several of the pin functions call filter functions to do the work,
33 // so you can often use the pin classes unaltered, just overriding the
34 // functions in CTransInPlaceFilter. If that's not enough and you want
35 // to derive your own pin class, override GetPin in the filter to supply
36 // your own pin classes to the filter.
37 
38 // ==================================================
39 // Implements the input pin
40 // ==================================================
41 
43 {
44 
45 protected:
46  CTransInPlaceFilter * const m_pTIPFilter; // our filter
47  BOOL m_bReadOnly; // incoming stream is read only
48 
49 public:
50 
52  __in_opt LPCTSTR pObjectName,
53  __inout CTransInPlaceFilter *pFilter,
54  __inout HRESULT *phr,
55  __in_opt LPCWSTR pName);
56 
57  // --- IMemInputPin -----
58 
59  // Provide an enumerator for media types by getting one from downstream
60  STDMETHODIMP EnumMediaTypes( __deref_out IEnumMediaTypes **ppEnum );
61 
62  // Say whether media type is acceptable.
63  HRESULT CheckMediaType(const CMediaType* pmt);
64 
65  // Return our upstream allocator
66  STDMETHODIMP GetAllocator(__deref_out IMemAllocator ** ppAllocator);
67 
68  // get told which allocator the upstream output pin is actually
69  // going to use.
70  STDMETHODIMP NotifyAllocator(IMemAllocator * pAllocator,
71  BOOL bReadOnly);
72 
73  // Allow the filter to see what allocator we have
74  // N.B. This does NOT AddRef
75  __out IMemAllocator * PeekAllocator() const
76  { return m_pAllocator; }
77 
78  // Pass this on downstream if it ever gets called.
79  STDMETHODIMP GetAllocatorRequirements(__out ALLOCATOR_PROPERTIES *pProps);
80 
81  HRESULT CompleteConnect(IPin *pReceivePin);
82 
83  inline const BOOL ReadOnly() { return m_bReadOnly ; }
84 
85 }; // CTransInPlaceInputPin
86 
87 // ==================================================
88 // Implements the output pin
89 // ==================================================
90 
92 {
93 
94 protected:
95  // m_pFilter points to our CBaseFilter
97 
98 public:
99 
101  __in_opt LPCTSTR pObjectName,
102  __inout CTransInPlaceFilter *pFilter,
103  __inout HRESULT *phr,
104  __in_opt LPCWSTR pName);
105 
106 
107  // --- CBaseOutputPin ------------
108 
109  // negotiate the allocator and its buffer size/count
110  // Insists on using our own allocator. (Actually the one upstream of us).
111  // We don't override this - instead we just agree the default
112  // then let the upstream filter decide for itself on reconnect
113  // virtual HRESULT DecideAllocator(IMemInputPin * pPin, IMemAllocator ** pAlloc);
114 
115  // Provide a media type enumerator. Get it from upstream.
116  STDMETHODIMP EnumMediaTypes( __deref_out IEnumMediaTypes **ppEnum );
117 
118  // Say whether media type is acceptable.
119  HRESULT CheckMediaType(const CMediaType* pmt);
120 
121  // This just saves the allocator being used on the output pin
122  // Also called by input pin's GetAllocator()
123  void SetAllocator(IMemAllocator * pAllocator);
124 
125  __out_opt IMemInputPin * ConnectedIMemInputPin()
126  { return m_pInputPin; }
127 
128  // Allow the filter to see what allocator we have
129  // N.B. This does NOT AddRef
130  __out IMemAllocator * PeekAllocator() const
131  { return m_pAllocator; }
132 
133  HRESULT CompleteConnect(IPin *pReceivePin);
134 
135 }; // CTransInPlaceOutputPin
136 
137 
138 class AM_NOVTABLE CTransInPlaceFilter : public CTransformFilter
139 {
140 
141 public:
142 
143  // map getpin/getpincount for base enum of pins to owner
144  // override this to return more specialised pin objects
145 
146  virtual CBasePin *GetPin(int n);
147 
148 public:
149 
150  // Set bModifiesData == false if your derived filter does
151  // not modify the data samples (for instance it's just copying
152  // them somewhere else or looking at the timestamps).
153 
154  CTransInPlaceFilter(__in_opt LPCTSTR, __inout_opt LPUNKNOWN, REFCLSID clsid, __inout HRESULT *,
155  bool bModifiesData = true);
156 #ifdef UNICODE
157  CTransInPlaceFilter(__in_opt LPCSTR, __inout_opt LPUNKNOWN, REFCLSID clsid, __inout HRESULT *,
158  bool bModifiesData = true);
159 #endif
160  // The following are defined to avoid undefined pure virtuals.
161  // Even if they are never called, they will give linkage warnings/errors
162 
163  // We override EnumMediaTypes to bypass the transform class enumerator
164  // which would otherwise call this.
165  HRESULT GetMediaType(int iPosition, __inout CMediaType *pMediaType)
166  { DbgBreak("CTransInPlaceFilter::GetMediaType should never be called");
167  return E_UNEXPECTED;
168  }
169 
170  // This is called when we actually have to provide our own allocator.
171  HRESULT DecideBufferSize(IMemAllocator*, __inout ALLOCATOR_PROPERTIES *);
172 
173  // The functions which call this in CTransform are overridden in this
174  // class to call CheckInputType with the assumption that the type
175  // does not change. In Debug builds some calls will be made and
176  // we just ensure that they do not assert.
177  HRESULT CheckTransform(const CMediaType *mtIn, const CMediaType *mtOut)
178  {
179  return S_OK;
180  };
181 
182 
183  // =================================================================
184  // ----- You may want to override this -----------------------------
185  // =================================================================
186 
187  HRESULT CompleteConnect(PIN_DIRECTION dir,IPin *pReceivePin);
188 
189  // chance to customize the transform process
190  virtual HRESULT Receive(IMediaSample *pSample);
191 
192  // =================================================================
193  // ----- You MUST override these -----------------------------------
194  // =================================================================
195 
196  virtual HRESULT Transform(IMediaSample *pSample) PURE;
197 
198  // this goes in the factory template table to create new instances
199  // static CCOMObject * CreateInstance(LPUNKNOWN, HRESULT *);
200 
201 
202 #ifdef PERF
203  // Override to register performance measurement with a less generic string
204  // You should do this to avoid confusion with other filters
205  virtual void RegisterPerfId()
206  {m_idTransInPlace = MSR_REGISTER(TEXT("TransInPlace"));}
207 #endif // PERF
208 
209 
210 // implementation details
211 
212 protected:
213 
214  __out_opt IMediaSample * CTransInPlaceFilter::Copy(IMediaSample *pSource);
215 
216 #ifdef PERF
217  int m_idTransInPlace; // performance measuring id
218 #endif // PERF
219  bool m_bModifiesData; // Does this filter change the data?
220 
221  // these hold our input and output pins
222 
223  friend class CTransInPlaceInputPin;
225 
227  {
229  };
231  {
233  };
234 
235  // Helper to see if the input and output types match
236  BOOL TypesMatch()
237  {
238  return InputPin()->CurrentMediaType() ==
239  OutputPin()->CurrentMediaType();
240  }
241 
242  // Are the input and output allocators different?
244  {
245  return InputPin()->PeekAllocator() != OutputPin()->PeekAllocator();
246  }
247 }; // CTransInPlaceFilter
248 
249 #endif /* __TRANSIP__ */
250 
CTransformFilter::m_pOutput
CTransformOutputPin * m_pOutput
Definition: transfrm.h:299
CTransInPlaceOutputPin::m_pTIPFilter
CTransInPlaceFilter *const m_pTIPFilter
Definition: transip.h:96
CTransInPlaceFilter::OutputPin
__out CTransInPlaceOutputPin * OutputPin() const
Definition: transip.h:230
CTransInPlaceInputPin::CheckMediaType
HRESULT CheckMediaType(const CMediaType *pmt)
Definition: transip.cpp:834
CTransformOutputPin
Definition: transfrm.h:108
CBasePin
Definition: amfilter.h:330
CTransformFilter::Receive
virtual HRESULT Receive(IMediaSample *pSample)
Definition: transfrm.cpp:310
CTransInPlaceOutputPin::SetAllocator
void SetAllocator(IMemAllocator *pAllocator)
Definition: transip.cpp:949
CTransInPlaceFilter::m_bModifiesData
bool m_bModifiesData
Definition: transip.h:219
CTransInPlaceFilter::CheckTransform
HRESULT CheckTransform(const CMediaType *mtIn, const CMediaType *mtOut)
Definition: transip.h:177
CTransformFilter::m_pInput
CTransformInputPin * m_pInput
Definition: transfrm.h:298
CTransInPlaceInputPin
Definition: transip.h:42
DbgBreak
#define DbgBreak(_x_)
Definition: wxdebug.h:201
CTransInPlaceInputPin::EnumMediaTypes
STDMETHODIMP EnumMediaTypes(__deref_out IEnumMediaTypes **ppEnum)
Definition: transip.cpp:818
CBaseOutputPin::m_pInputPin
IMemInputPin * m_pInputPin
Definition: amfilter.h:718
CTransInPlaceInputPin::ReadOnly
const BOOL ReadOnly()
Definition: transip.h:83
CTransInPlaceFilter::UsingDifferentAllocators
BOOL UsingDifferentAllocators() const
Definition: transip.h:243
CTransInPlaceFilter::GetMediaType
HRESULT GetMediaType(int iPosition, __inout CMediaType *pMediaType)
Definition: transip.h:165
CMediaType
Definition: mtype.h:18
CTransInPlaceInputPin::PeekAllocator
__out IMemAllocator * PeekAllocator() const
Definition: transip.h:75
n
unsigned int n
Definition: pstream.cpp:148
CTransInPlaceInputPin::CompleteConnect
HRESULT CompleteConnect(IPin *pReceivePin)
Definition: transip.cpp:867
CTransformFilter::GetPin
virtual CBasePin * GetPin(int n)
Definition: transfrm.cpp:90
CTransInPlaceOutputPin::ConnectedIMemInputPin
__out_opt IMemInputPin * ConnectedIMemInputPin()
Definition: transip.h:125
CTransInPlaceInputPin::GetAllocatorRequirements
STDMETHODIMP GetAllocatorRequirements(__out ALLOCATOR_PROPERTIES *pProps)
Definition: transip.cpp:850
pName
CHAR * pName
Definition: amvideo.cpp:26
CTransInPlaceFilter
Definition: transip.h:138
CTransInPlaceInputPin::NotifyAllocator
STDMETHODIMP NotifyAllocator(IMemAllocator *pAllocator, BOOL bReadOnly)
Definition: transip.cpp:727
CTransInPlaceFilter::TypesMatch
BOOL TypesMatch()
Definition: transip.h:236
MSR_REGISTER
#define MSR_REGISTER(a)
Definition: measure.h:134
CTransInPlaceOutputPin
Definition: transip.h:91
CBaseOutputPin::m_pAllocator
IMemAllocator * m_pAllocator
Definition: amfilter.h:717
CTransInPlaceOutputPin::CheckMediaType
HRESULT CheckMediaType(const CMediaType *pmt)
Definition: transip.cpp:920
CTransformFilter::Transform
virtual HRESULT Transform(IMediaSample *pIn, IMediaSample *pOut)
Definition: transfrm.cpp:63
CTransformFilter::CompleteConnect
virtual HRESULT CompleteConnect(PIN_DIRECTION direction, IPin *pReceivePin)
Definition: transfrm.cpp:209
CTransInPlaceInputPin::GetAllocator
STDMETHODIMP GetAllocator(__deref_out IMemAllocator **ppAllocator)
Definition: transip.cpp:694
CTransInPlaceFilter::Copy
__out_opt IMediaSample * Copy(IMediaSample *pSource)
Definition: transip.cpp:482
CTransInPlaceInputPin::m_bReadOnly
BOOL m_bReadOnly
Definition: transip.h:47
CTransInPlaceOutputPin::EnumMediaTypes
STDMETHODIMP EnumMediaTypes(__deref_out IEnumMediaTypes **ppEnum)
Definition: transip.cpp:904
CTransformFilter::DecideBufferSize
virtual HRESULT DecideBufferSize(IMemAllocator *pAllocator, __inout ALLOCATOR_PROPERTIES *pprop) PURE
CTransInPlaceOutputPin::PeekAllocator
__out IMemAllocator * PeekAllocator() const
Definition: transip.h:130
CTransInPlaceInputPin::m_pTIPFilter
CTransInPlaceFilter *const m_pTIPFilter
Definition: transip.h:46
CTransInPlaceOutputPin::CTransInPlaceOutputPin
CTransInPlaceOutputPin(__in_opt LPCTSTR pObjectName, __inout CTransInPlaceFilter *pFilter, __inout HRESULT *phr, __in_opt LPCWSTR pName)
Definition: transip.cpp:885
CTransInPlaceOutputPin::CompleteConnect
HRESULT CompleteConnect(IPin *pReceivePin)
Definition: transip.cpp:966
CTransInPlaceFilter::InputPin
__out CTransInPlaceInputPin * InputPin() const
Definition: transip.h:226
CTransformInputPin
Definition: transfrm.h:33
CTransformFilter
Definition: transfrm.h:174
CBaseInputPin::m_pAllocator
IMemAllocator * m_pAllocator
Definition: amfilter.h:825
CTransInPlaceInputPin::CTransInPlaceInputPin
CTransInPlaceInputPin(__in_opt LPCTSTR pObjectName, __inout CTransInPlaceFilter *pFilter, __inout HRESULT *phr, __in_opt LPCWSTR pName)
Definition: transip.cpp:662