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