home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Game Programming for Teens / VBGPFT.cdr / DirectX8 / dx8a_sdk.exe / samples / multimedia / directshow / baseclasses / transip.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-10-02  |  8.3 KB  |  245 lines

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