transip.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. }
  60. // Pass this on downstream if it ever gets called.
  61. STDMETHODIMP GetAllocatorRequirements(__out ALLOCATOR_PROPERTIES *pProps);
  62. HRESULT CompleteConnect(IPin *pReceivePin);
  63. inline const BOOL ReadOnly() {
  64. return m_bReadOnly ;
  65. }
  66. }; // CTransInPlaceInputPin
  67. // ==================================================
  68. // Implements the output pin
  69. // ==================================================
  70. class CTransInPlaceOutputPin : public CTransformOutputPin
  71. {
  72. protected:
  73. // m_pFilter points to our CBaseFilter
  74. CTransInPlaceFilter * const m_pTIPFilter;
  75. public:
  76. CTransInPlaceOutputPin(
  77. __in_opt LPCTSTR pObjectName,
  78. __inout CTransInPlaceFilter *pFilter,
  79. __inout HRESULT *phr,
  80. __in_opt LPCWSTR pName);
  81. // --- CBaseOutputPin ------------
  82. // negotiate the allocator and its buffer size/count
  83. // Insists on using our own allocator. (Actually the one upstream of us).
  84. // We don't override this - instead we just agree the default
  85. // then let the upstream filter decide for itself on reconnect
  86. // virtual HRESULT DecideAllocator(IMemInputPin * pPin, IMemAllocator ** pAlloc);
  87. // Provide a media type enumerator. Get it from upstream.
  88. STDMETHODIMP EnumMediaTypes( __deref_out IEnumMediaTypes **ppEnum );
  89. // Say whether media type is acceptable.
  90. HRESULT CheckMediaType(const CMediaType* pmt);
  91. // This just saves the allocator being used on the output pin
  92. // Also called by input pin's GetAllocator()
  93. void SetAllocator(IMemAllocator * pAllocator);
  94. __out_opt IMemInputPin * ConnectedIMemInputPin() {
  95. return m_pInputPin;
  96. }
  97. // Allow the filter to see what allocator we have
  98. // N.B. This does NOT AddRef
  99. __out IMemAllocator * PeekAllocator() const {
  100. return m_pAllocator;
  101. }
  102. HRESULT CompleteConnect(IPin *pReceivePin);
  103. }; // CTransInPlaceOutputPin
  104. class AM_NOVTABLE CTransInPlaceFilter : public CTransformFilter
  105. {
  106. public:
  107. // map getpin/getpincount for base enum of pins to owner
  108. // override this to return more specialised pin objects
  109. virtual CBasePin *GetPin(int n);
  110. public:
  111. // Set bModifiesData == false if your derived filter does
  112. // not modify the data samples (for instance it's just copying
  113. // them somewhere else or looking at the timestamps).
  114. CTransInPlaceFilter(__in_opt LPCTSTR, __inout_opt LPUNKNOWN, REFCLSID clsid, __inout HRESULT *,
  115. bool bModifiesData = true);
  116. #ifdef UNICODE
  117. CTransInPlaceFilter(__in_opt LPCSTR, __inout_opt LPUNKNOWN, REFCLSID clsid, __inout HRESULT *,
  118. bool bModifiesData = true);
  119. #endif
  120. // The following are defined to avoid undefined pure virtuals.
  121. // Even if they are never called, they will give linkage warnings/errors
  122. // We override EnumMediaTypes to bypass the transform class enumerator
  123. // which would otherwise call this.
  124. HRESULT GetMediaType(int iPosition, __inout CMediaType *pMediaType) {
  125. DbgBreak("CTransInPlaceFilter::GetMediaType should never be called");
  126. return E_UNEXPECTED;
  127. }
  128. // This is called when we actually have to provide our own allocator.
  129. HRESULT DecideBufferSize(IMemAllocator*, __inout ALLOCATOR_PROPERTIES *);
  130. // The functions which call this in CTransform are overridden in this
  131. // class to call CheckInputType with the assumption that the type
  132. // does not change. In Debug builds some calls will be made and
  133. // we just ensure that they do not assert.
  134. HRESULT CheckTransform(const CMediaType *mtIn, const CMediaType *mtOut) {
  135. return S_OK;
  136. };
  137. // =================================================================
  138. // ----- You may want to override this -----------------------------
  139. // =================================================================
  140. HRESULT CompleteConnect(PIN_DIRECTION dir,IPin *pReceivePin);
  141. // chance to customize the transform process
  142. virtual HRESULT Receive(IMediaSample *pSample);
  143. // =================================================================
  144. // ----- You MUST override these -----------------------------------
  145. // =================================================================
  146. virtual HRESULT Transform(IMediaSample *pSample) PURE;
  147. // this goes in the factory template table to create new instances
  148. // static CCOMObject * CreateInstance(LPUNKNOWN, HRESULT *);
  149. #ifdef PERF
  150. // Override to register performance measurement with a less generic string
  151. // You should do this to avoid confusion with other filters
  152. virtual void RegisterPerfId() {
  153. m_idTransInPlace = MSR_REGISTER(TEXT("TransInPlace"));
  154. }
  155. #endif // PERF
  156. // implementation details
  157. protected:
  158. __out_opt IMediaSample * CTransInPlaceFilter::Copy(IMediaSample *pSource);
  159. #ifdef PERF
  160. int m_idTransInPlace; // performance measuring id
  161. #endif // PERF
  162. bool m_bModifiesData; // Does this filter change the data?
  163. // these hold our input and output pins
  164. friend class CTransInPlaceInputPin;
  165. friend class CTransInPlaceOutputPin;
  166. __out CTransInPlaceInputPin *InputPin() const {
  167. return (CTransInPlaceInputPin *)m_pInput;
  168. };
  169. __out CTransInPlaceOutputPin *OutputPin() const {
  170. return (CTransInPlaceOutputPin *)m_pOutput;
  171. };
  172. // Helper to see if the input and output types match
  173. BOOL TypesMatch() {
  174. return InputPin()->CurrentMediaType() ==
  175. OutputPin()->CurrentMediaType();
  176. }
  177. // Are the input and output allocators different?
  178. BOOL UsingDifferentAllocators() const {
  179. return InputPin()->PeekAllocator() != OutputPin()->PeekAllocator();
  180. }
  181. }; // CTransInPlaceFilter
  182. #endif /* __TRANSIP__ */