home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / mac / SiteBldr / AMOVIE / SDK / _SETUP / COMMON.Z / transip.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-10  |  7.0 KB  |  210 lines

  1. //==========================================================================;
  2. //
  3. //  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  4. //  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  5. //  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  6. //  PURPOSE.
  7. //
  8. //  Copyright (c) 1992 - 1996  Microsoft Corporation.  All Rights Reserved.
  9. //
  10. //--------------------------------------------------------------------------;
  11.  
  12. //
  13. // base class from which you can derive a simple Transform-In-Place filter.
  14. // The difference between this and Transfrm.h is that Transfrm copies the data.
  15. //
  16. // It assumes the filter has one input and one output stream, and has no
  17. // interest in memory management, interface negotiation or anything else.
  18. //
  19. // Derive your class from this, and supply Transform and the media type/format
  20. // negotiation functions. Implement that class, compile and link and
  21. // you're done.
  22.  
  23.  
  24. #ifndef __TRANSIP__
  25. #define __TRANSIP__
  26.  
  27. // ======================================================================
  28. // This is the com object that represents a simple transform filter. It
  29. // supports IFilter, IMediaFilter and two pins through nested interfaces
  30. // ======================================================================
  31.  
  32. class CTransInPlaceFilter;
  33.  
  34. // Several of the pin functions call filter functions to do the work,
  35. // so you can often use the pin classes unaltered, just overriding the
  36. // functions in CTransInPlaceFilter.  If that's not enough and you want
  37. // to derive your own pin class, override GetPin in the filter to supply
  38. // your own pin classes to the filter.
  39.  
  40. // ==================================================
  41. // Implements the input pin
  42. // ==================================================
  43.  
  44. class CTransInPlaceInputPin : public CTransformInputPin
  45. {
  46.  
  47. protected:
  48.     CTransInPlaceFilter *m_pTIPFilter;
  49.  
  50. public:
  51.  
  52.     CTransInPlaceInputPin(
  53.         TCHAR               *pObjectName,
  54.         CTransInPlaceFilter *pFilter,
  55.         HRESULT             *phr,
  56.         LPCWSTR              pName);
  57.  
  58.     // --- IMemInputPin -----
  59.  
  60.     // Provide an enumerator for media types by getting one from downstream
  61.     STDMETHODIMP EnumMediaTypes( IEnumMediaTypes **ppEnum );
  62.  
  63.     // Say whether media type is acceptable.
  64.     HRESULT CheckMediaType(const CMediaType* pmt);
  65.  
  66.     // Return our upstream allocator
  67.     STDMETHODIMP GetAllocator(IMemAllocator ** ppAllocator);
  68.  
  69.     // get told which allocator the upstream output pin is actually
  70.     // going to use.
  71.     STDMETHODIMP NotifyAllocator(IMemAllocator * pAllocator,
  72.                     BOOL bReadOnly);
  73.  
  74. };  // CTransInPlaceInputPin
  75.  
  76. // ==================================================
  77. // Implements the output pin
  78. // ==================================================
  79.  
  80. class CTransInPlaceOutputPin : public CTransformOutputPin
  81. {
  82.  
  83. protected:
  84.     // m_pFilter points to our CBaseFilter
  85.     CTransInPlaceFilter *m_pTIPFilter;
  86.  
  87. public:
  88.  
  89.     CTransInPlaceOutputPin(
  90.         TCHAR               *pObjectName,
  91.         CTransInPlaceFilter *pFilter,
  92.         HRESULT             *phr,
  93.         LPCWSTR              pName);
  94.  
  95.  
  96.     // --- CBaseOutputPin ------------
  97.  
  98.     // negotiate the allocator and its buffer size/count
  99.     // Insists on using our own allocator.  (Actually the one upstream of us).
  100.     virtual HRESULT DecideAllocator(IMemInputPin * pPin, IMemAllocator ** pAlloc);
  101.  
  102.     // get told which allocator the upstream output pin is actually
  103.     // going to use.
  104.     // (This is not an override - output pins don't normally get this)
  105.     STDMETHODIMP NotifyAllocator(IMemAllocator * pAllocator, BOOL bReadOnly);
  106.  
  107.     // Provide a media type enumerator.  Get it from upstream.
  108.     STDMETHODIMP EnumMediaTypes( IEnumMediaTypes **ppEnum );
  109.  
  110.     // Say whether media type is acceptable.
  111.     HRESULT CheckMediaType(const CMediaType* pmt);
  112.  
  113. };  // CTransInPlaceOutputPin
  114.  
  115.  
  116. class CTransInPlaceFilter : public CTransformFilter
  117. {
  118.  
  119. public:
  120.  
  121.     // map getpin/getpincount for base enum of pins to owner
  122.     // override this to return more specialised pin objects
  123.  
  124.     virtual CBasePin *GetPin(int n);
  125.  
  126. public:
  127.  
  128.     CTransInPlaceFilter(TCHAR *, LPUNKNOWN, CLSID clsid, HRESULT *);
  129.  
  130.     // The following are defined to avoid undefined pure virtuals.
  131.     // Even if they are never called, they will give linkage warnings/errors
  132.  
  133.     // We override EnumMediaTypes to bypass the transform class enumerator
  134.     // which would otherwise call this.
  135.     HRESULT GetMediaType(int iPosition, CMediaType *pMediaType)
  136.         {   DbgBreak("CTransInPlaceFilter::GetMediaType should never be called");
  137.             return E_UNEXPECTED;
  138.         }
  139.  
  140.     // We provide no allocator, so this is never called.
  141.     HRESULT DecideBufferSize(IMemAllocator*, ALLOCATOR_PROPERTIES *)
  142.     {
  143.         DbgBreak("DecideBufferSize has been called for an in-place transform.");
  144.         return E_UNEXPECTED;
  145.     };
  146.  
  147.     // The functions which call this in CTransform are overridden in this
  148.     // class to call CheckInputType with the assumption that the type
  149.     // does not change.  In Debug builds some calls will be made and
  150.     // we just ensure that they do not assert.
  151.     HRESULT CheckTransform(const CMediaType *mtIn, const CMediaType *mtOut)
  152.     {
  153.         return S_OK;
  154.     };
  155.  
  156.  
  157.     // =================================================================
  158.     // ----- You may want to override this -----------------------------
  159.     // =================================================================
  160.  
  161.     HRESULT CompleteConnect(PIN_DIRECTION dir,IPin *pReceivePin);
  162.  
  163.     // chance to customize the transform process
  164.     virtual HRESULT Receive(IMediaSample *pSample);
  165.  
  166.     // =================================================================
  167.     // ----- You MUST override these -----------------------------------
  168.     // =================================================================
  169.  
  170.     virtual HRESULT Transform(IMediaSample *pSample) PURE;
  171.  
  172.     // this goes in the factory template table to create new instances
  173.     // static CCOMObject * CreateInstance(LPUNKNOWN, HRESULT *);
  174.  
  175.  
  176. #ifdef PERF
  177.     // Override to register performance measurement with a less generic string
  178.     // You should do this to avoid confusion with other filters
  179.     virtual void RegisterPerfId()
  180.          {m_idTransInPlace = MSR_REGISTER(TEXT("TransInPlace"));}
  181. #endif // PERF
  182.  
  183.  
  184. // implementation details
  185.  
  186. protected:
  187.  
  188.     int m_idTransInPlace;                 // performance measuring id
  189.  
  190.     // The allocator on our input pin
  191.     IMemAllocator *m_pAllocator;
  192.  
  193.     // these hold our input and output pins
  194.  
  195.     friend class CTransInPlaceInputPin;
  196.     friend class CTransInPlaceOutputPin;
  197.  
  198.     CTransInPlaceInputPin  *InputPin()
  199.     {
  200.         return (CTransInPlaceInputPin *)m_pInput;
  201.     };
  202.     CTransInPlaceOutputPin *OutputPin()
  203.     {
  204.         return (CTransInPlaceOutputPin *)m_pOutput;
  205.     };
  206. }; // CTransInPlaceFilter
  207.  
  208. #endif /* __TRANSIP__ */
  209.  
  210.