Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

250 lines
8.5 KiB

  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. TCHAR *pObjectName,
  41. CTransInPlaceFilter *pFilter,
  42. HRESULT *phr,
  43. LPCWSTR pName);
  44. // --- IMemInputPin -----
  45. // Provide an enumerator for media types by getting one from downstream
  46. STDMETHODIMP EnumMediaTypes( IEnumMediaTypes **ppEnum );
  47. // Say whether media type is acceptable.
  48. HRESULT CheckMediaType(const CMediaType* pmt);
  49. // Return our upstream allocator
  50. STDMETHODIMP GetAllocator(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. IMemAllocator * PeekAllocator() const
  58. { return m_pAllocator; }
  59. // Pass this on downstream if it ever gets called.
  60. STDMETHODIMP GetAllocatorRequirements(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. TCHAR *pObjectName,
  75. CTransInPlaceFilter *pFilter,
  76. HRESULT *phr,
  77. 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( 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. IMemInputPin * ConnectedIMemInputPin()
  92. { return m_pInputPin; }
  93. // Allow the filter to see what allocator we have
  94. // N.B. This does NOT AddRef
  95. 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(TCHAR *, LPUNKNOWN, REFCLSID clsid, HRESULT *,
  110. bool bModifiesData = true);
  111. #ifdef UNICODE
  112. CTransInPlaceFilter(CHAR *, LPUNKNOWN, REFCLSID clsid, 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, 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 out own allocator.
  124. HRESULT DecideBufferSize(IMemAllocator*, 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. 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. CTransInPlaceInputPin *InputPin() const
  162. {
  163. return (CTransInPlaceInputPin *)m_pInput;
  164. };
  165. 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__ */