Update UNRAR.H
[xy_vsfilter.git] / src / filters / BaseClasses / transip.h
blob92d006c1acd15aa427fed2cd1b5004a84e9b7f01
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-2002 Microsoft Corporation. All rights reserved.
8 //------------------------------------------------------------------------------
12 // The difference between this and Transfrm.h is that Transfrm copies the data.
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.
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.
22 #ifndef __TRANSIP__
23 #define __TRANSIP__
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 // ======================================================================
30 class CTransInPlaceFilter;
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.
38 // ==================================================
39 // Implements the input pin
40 // ==================================================
42 class CTransInPlaceInputPin : public CTransformInputPin
45 protected:
46 CTransInPlaceFilter * const m_pTIPFilter; // our filter
47 BOOL m_bReadOnly; // incoming stream is read only
49 public:
51 CTransInPlaceInputPin(
52 TCHAR *pObjectName,
53 CTransInPlaceFilter *pFilter,
54 HRESULT *phr,
55 LPCWSTR pName);
57 // --- IMemInputPin -----
59 // Provide an enumerator for media types by getting one from downstream
60 STDMETHODIMP EnumMediaTypes( IEnumMediaTypes **ppEnum );
62 // Say whether media type is acceptable.
63 HRESULT CheckMediaType(const CMediaType* pmt);
65 // Return our upstream allocator
66 STDMETHODIMP GetAllocator(IMemAllocator ** ppAllocator);
68 // get told which allocator the upstream output pin is actually
69 // going to use.
70 STDMETHODIMP NotifyAllocator(IMemAllocator * pAllocator,
71 BOOL bReadOnly);
73 // Allow the filter to see what allocator we have
74 // N.B. This does NOT AddRef
75 IMemAllocator * PeekAllocator() const
76 { return m_pAllocator; }
78 // Pass this on downstream if it ever gets called.
79 STDMETHODIMP GetAllocatorRequirements(ALLOCATOR_PROPERTIES *pProps);
81 HRESULT CompleteConnect(IPin *pReceivePin);
83 inline const BOOL ReadOnly() { return m_bReadOnly ; }
85 }; // CTransInPlaceInputPin
87 // ==================================================
88 // Implements the output pin
89 // ==================================================
91 class CTransInPlaceOutputPin : public CTransformOutputPin
94 protected:
95 // m_pFilter points to our CBaseFilter
96 CTransInPlaceFilter * const m_pTIPFilter;
98 public:
100 CTransInPlaceOutputPin(
101 TCHAR *pObjectName,
102 CTransInPlaceFilter *pFilter,
103 HRESULT *phr,
104 LPCWSTR pName);
107 // --- CBaseOutputPin ------------
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);
115 // Provide a media type enumerator. Get it from upstream.
116 STDMETHODIMP EnumMediaTypes( IEnumMediaTypes **ppEnum );
118 // Say whether media type is acceptable.
119 HRESULT CheckMediaType(const CMediaType* pmt);
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);
125 IMemInputPin * ConnectedIMemInputPin()
126 { return m_pInputPin; }
128 // Allow the filter to see what allocator we have
129 // N.B. This does NOT AddRef
130 IMemAllocator * PeekAllocator() const
131 { return m_pAllocator; }
133 HRESULT CompleteConnect(IPin *pReceivePin);
135 }; // CTransInPlaceOutputPin
138 class AM_NOVTABLE CTransInPlaceFilter : public CTransformFilter
141 public:
143 // map getpin/getpincount for base enum of pins to owner
144 // override this to return more specialised pin objects
146 virtual CBasePin *GetPin(int n);
148 public:
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).
154 CTransInPlaceFilter(TCHAR *, LPUNKNOWN, REFCLSID clsid, HRESULT *,
155 bool bModifiesData = true);
156 #ifdef UNICODE
157 CTransInPlaceFilter(CHAR *, LPUNKNOWN, REFCLSID clsid, 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
163 // We override EnumMediaTypes to bypass the transform class enumerator
164 // which would otherwise call this.
165 HRESULT GetMediaType(int iPosition, CMediaType *pMediaType)
166 { DbgBreak("CTransInPlaceFilter::GetMediaType should never be called");
167 return E_UNEXPECTED;
170 // This is called when we actually have to provide out own allocator.
171 HRESULT DecideBufferSize(IMemAllocator*, ALLOCATOR_PROPERTIES *);
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)
179 return S_OK;
183 // =================================================================
184 // ----- You may want to override this -----------------------------
185 // =================================================================
187 HRESULT CompleteConnect(PIN_DIRECTION dir,IPin *pReceivePin);
189 // chance to customize the transform process
190 virtual HRESULT Receive(IMediaSample *pSample);
192 // =================================================================
193 // ----- You MUST override these -----------------------------------
194 // =================================================================
196 virtual HRESULT Transform(IMediaSample *pSample) PURE;
198 // this goes in the factory template table to create new instances
199 // static CCOMObject * CreateInstance(LPUNKNOWN, HRESULT *);
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
210 // implementation details
212 protected:
214 IMediaSample * CTransInPlaceFilter::Copy(IMediaSample *pSource);
216 #ifdef PERF
217 int m_idTransInPlace; // performance measuring id
218 #endif // PERF
219 bool m_bModifiesData; // Does this filter change the data?
221 // these hold our input and output pins
223 friend class CTransInPlaceInputPin;
224 friend class CTransInPlaceOutputPin;
226 CTransInPlaceInputPin *InputPin() const
228 return (CTransInPlaceInputPin *)m_pInput;
230 CTransInPlaceOutputPin *OutputPin() const
232 return (CTransInPlaceOutputPin *)m_pOutput;
235 // Helper to see if the input and output types match
236 BOOL TypesMatch()
238 return InputPin()->CurrentMediaType() ==
239 OutputPin()->CurrentMediaType();
242 // Are the input and output allocators different?
243 BOOL UsingDifferentAllocators() const
245 return InputPin()->PeekAllocator() != OutputPin()->PeekAllocator();
247 }; // CTransInPlaceFilter
249 #endif /* __TRANSIP__ */