1
0

transip.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. // The difference between this and Transfrm.h is that Transfrm copies the data.
  11. //
  12. // It assumes the filter has one input and one output stream, and has no
  13. // interest in memory management, interface negotiation or anything else.
  14. //
  15. // Derive your class from this, and supply Transform and the media type/format
  16. // negotiation functions. Implement that class, compile and link and
  17. // you're done.
  18. #ifndef __TRANSIP__
  19. #define __TRANSIP__
  20. // ======================================================================
  21. // This is the com object that represents a simple transform filter. It
  22. // supports IBaseFilter, IMediaFilter and two pins through nested interfaces
  23. // ======================================================================
  24. class CTransInPlaceFilter;
  25. // Several of the pin functions call filter functions to do the work,
  26. // so you can often use the pin classes unaltered, just overriding the
  27. // functions in CTransInPlaceFilter. If that's not enough and you want
  28. // to derive your own pin class, override GetPin in the filter to supply
  29. // your own pin classes to the filter.
  30. // ==================================================
  31. // Implements the input pin
  32. // ==================================================
  33. class CTransInPlaceInputPin : public CTransformInputPin
  34. {
  35. protected:
  36. CTransInPlaceFilter * const m_pTIPFilter; // our filter
  37. BOOL m_bReadOnly; // incoming stream is read only
  38. public:
  39. CTransInPlaceInputPin(
  40. __in_opt LPCTSTR pObjectName,
  41. __inout CTransInPlaceFilter *pFilter,
  42. __inout HRESULT *phr,
  43. __in_opt LPCWSTR pName);
  44. // --- IMemInputPin -----
  45. // Provide an enumerator for media types by getting one from downstream
  46. STDMETHODIMP EnumMediaTypes( __deref_out IEnumMediaTypes **ppEnum );
  47. // Say whether media type is acceptable.
  48. HRESULT CheckMediaType(const CMediaType* pmt);
  49. // Return our upstream allocator
  50. STDMETHODIMP GetAllocator(__deref_out IMemAllocator ** ppAllocator);
  51. // get told which allocator the upstream output pin is actually
  52. // going to use.
  53. STDMETHODIMP NotifyAllocator(IMemAllocator * pAllocator,
  54. BOOL bReadOnly);
  55. // Allow the filter to see what allocator we have
  56. // N.B. This does NOT AddRef
  57. __out IMemAllocator * PeekAllocator() const
  58. { return m_pAllocator; }
  59. // Pass this on downstream if it ever gets called.
  60. STDMETHODIMP GetAllocatorRequirements(__out ALLOCATOR_PROPERTIES *pProps);
  61. HRESULT CompleteConnect(IPin *pReceivePin);
  62. inline const BOOL ReadOnly() { return m_bReadOnly ; }
  63. }; // CTransInPlaceInputPin
  64. // ==================================================
  65. // Implements the output pin
  66. // ==================================================
  67. class CTransInPlaceOutputPin : public CTransformOutputPin
  68. {
  69. protected:
  70. // m_pFilter points to our CBaseFilter
  71. CTransInPlaceFilter * const m_pTIPFilter;
  72. public:
  73. CTransInPlaceOutputPin(
  74. __in_opt LPCTSTR pObjectName,
  75. __inout CTransInPlaceFilter *pFilter,
  76. __inout HRESULT *phr,
  77. __in_opt LPCWSTR pName);
  78. // --- CBaseOutputPin ------------
  79. // negotiate the allocator and its buffer size/count
  80. // Insists on using our own allocator. (Actually the one upstream of us).
  81. // We don't override this - instead we just agree the default
  82. // then let the upstream filter decide for itself on reconnect
  83. // virtual HRESULT DecideAllocator(IMemInputPin * pPin, IMemAllocator ** pAlloc);
  84. // Provide a media type enumerator. Get it from upstream.
  85. STDMETHODIMP EnumMediaTypes( __deref_out IEnumMediaTypes **ppEnum );
  86. // Say whether media type is acceptable.
  87. HRESULT CheckMediaType(const CMediaType* pmt);
  88. // This just saves the allocator being used on the output pin
  89. // Also called by input pin's GetAllocator()
  90. void SetAllocator(IMemAllocator * pAllocator);
  91. __out_opt IMemInputPin * ConnectedIMemInputPin()
  92. { return m_pInputPin; }
  93. // Allow the filter to see what allocator we have
  94. // N.B. This does NOT AddRef
  95. __out IMemAllocator * PeekAllocator() const
  96. { return m_pAllocator; }
  97. HRESULT CompleteConnect(IPin *pReceivePin);
  98. }; // CTransInPlaceOutputPin
  99. class AM_NOVTABLE CTransInPlaceFilter : public CTransformFilter
  100. {
  101. public:
  102. // map getpin/getpincount for base enum of pins to owner
  103. // override this to return more specialised pin objects
  104. virtual CBasePin *GetPin(int n);
  105. public:
  106. // Set bModifiesData == false if your derived filter does
  107. // not modify the data samples (for instance it's just copying
  108. // them somewhere else or looking at the timestamps).
  109. CTransInPlaceFilter(__in_opt LPCTSTR, __inout_opt LPUNKNOWN, REFCLSID clsid, __inout HRESULT *,
  110. bool bModifiesData = true);
  111. #ifdef UNICODE
  112. CTransInPlaceFilter(__in_opt LPCSTR, __inout_opt LPUNKNOWN, REFCLSID clsid, __inout HRESULT *,
  113. bool bModifiesData = true);
  114. #endif
  115. // The following are defined to avoid undefined pure virtuals.
  116. // Even if they are never called, they will give linkage warnings/errors
  117. // We override EnumMediaTypes to bypass the transform class enumerator
  118. // which would otherwise call this.
  119. HRESULT GetMediaType(int iPosition, __inout CMediaType *pMediaType)
  120. { DbgBreak("CTransInPlaceFilter::GetMediaType should never be called");
  121. return E_UNEXPECTED;
  122. }
  123. // This is called when we actually have to provide our own allocator.
  124. HRESULT DecideBufferSize(IMemAllocator*, __inout ALLOCATOR_PROPERTIES *);
  125. // The functions which call this in CTransform are overridden in this
  126. // class to call CheckInputType with the assumption that the type
  127. // does not change. In Debug builds some calls will be made and
  128. // we just ensure that they do not assert.
  129. HRESULT CheckTransform(const CMediaType *mtIn, const CMediaType *mtOut)
  130. {
  131. return S_OK;
  132. };
  133. // =================================================================
  134. // ----- You may want to override this -----------------------------
  135. // =================================================================
  136. HRESULT CompleteConnect(PIN_DIRECTION dir,IPin *pReceivePin);
  137. // chance to customize the transform process
  138. virtual HRESULT Receive(IMediaSample *pSample);
  139. // =================================================================
  140. // ----- You MUST override these -----------------------------------
  141. // =================================================================
  142. virtual HRESULT Transform(IMediaSample *pSample) PURE;
  143. // this goes in the factory template table to create new instances
  144. // static CCOMObject * CreateInstance(LPUNKNOWN, HRESULT *);
  145. #ifdef PERF
  146. // Override to register performance measurement with a less generic string
  147. // You should do this to avoid confusion with other filters
  148. virtual void RegisterPerfId()
  149. {m_idTransInPlace = MSR_REGISTER(TEXT("TransInPlace"));}
  150. #endif // PERF
  151. // implementation details
  152. protected:
  153. __out_opt IMediaSample * CTransInPlaceFilter::Copy(IMediaSample *pSource);
  154. #ifdef PERF
  155. int m_idTransInPlace; // performance measuring id
  156. #endif // PERF
  157. bool m_bModifiesData; // Does this filter change the data?
  158. // these hold our input and output pins
  159. friend class CTransInPlaceInputPin;
  160. friend class CTransInPlaceOutputPin;
  161. __out CTransInPlaceInputPin *InputPin() const
  162. {
  163. return (CTransInPlaceInputPin *)m_pInput;
  164. };
  165. __out CTransInPlaceOutputPin *OutputPin() const
  166. {
  167. return (CTransInPlaceOutputPin *)m_pOutput;
  168. };
  169. // Helper to see if the input and output types match
  170. BOOL TypesMatch()
  171. {
  172. return InputPin()->CurrentMediaType() ==
  173. OutputPin()->CurrentMediaType();
  174. }
  175. // Are the input and output allocators different?
  176. BOOL UsingDifferentAllocators() const
  177. {
  178. return InputPin()->PeekAllocator() != OutputPin()->PeekAllocator();
  179. }
  180. }; // CTransInPlaceFilter
  181. #endif /* __TRANSIP__ */