home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / mac / SiteBldr / AMOVIE / SDK / _SETUP / COMMON.Z / vmbase.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-28  |  10.0 KB  |  328 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. #ifndef __VMBASE_H__
  13. #define __VMBASE_H__
  14.  
  15. // We export this:
  16. class CBaseVideoMixer;
  17. class CBaseVideoMixerInputPin;
  18. class CBaseVideoMixerOutputPin;
  19.  
  20. // ==================================================
  21. // Implements the input pins
  22. // ==================================================
  23.  
  24. class CBaseVideoMixerInputPin : public CBaseInputPin
  25. {
  26.     friend class CBaseVideoMixer;
  27.  
  28.     // owning video mixer
  29. protected:
  30.     CBaseVideoMixer *m_pBaseVideoMixer;
  31.  
  32. public:
  33.     CBaseVideoMixerInputPin(
  34.         TCHAR *pObjectName,
  35.         CBaseFilter *pBaseFilter,
  36.         CBaseVideoMixer *pTransformFilter,
  37.         HRESULT * phr,
  38.         LPCWSTR pName,
  39.         int iPinNo);
  40.  
  41.     ~CBaseVideoMixerInputPin();
  42.  
  43.     // override connect to grab critsec
  44.     STDMETHODIMP Disconnect();
  45.  
  46.     // Grab and release extra interfaces if required
  47.     HRESULT CheckConnect(IPin *pPin);
  48.     HRESULT BreakConnect();
  49.  
  50.     // check that we can support this output type
  51.     HRESULT CheckMediaType(const CMediaType* mtIn);
  52.  
  53.     // set the connection media type
  54.     HRESULT SetMediaType(const CMediaType* mt);
  55.  
  56.     // --- IMemInputPin -----
  57.  
  58.     // here's the next block of data from the stream.
  59.     // AddRef it yourself if you need to hold it beyond the end
  60.     // of this call.
  61.     STDMETHODIMP Receive(IMediaSample * pSample);
  62.  
  63.     // provide EndOfStream that passes straight downstream
  64.     // (there is no queued data)
  65.     STDMETHODIMP EndOfStream(void);
  66.  
  67.     // passes it to CBaseVideoMixer::BeginFlush
  68.     STDMETHODIMP BeginFlush(void);
  69.  
  70.     // passes it to CBaseVideoMixer::EndFlush
  71.     STDMETHODIMP EndFlush(void);
  72.  
  73.     // Pass a Quality notification on to the appropriate sink
  74.     HRESULT PassNotify(Quality q);
  75.  
  76.     HRESULT Active(void);
  77.  
  78.     // return an enumerator for this pins preferred media types
  79.     STDMETHODIMP EnumMediaTypes(
  80.         IEnumMediaTypes **ppEnum
  81.     );
  82.  
  83.     // Sample queue
  84. protected:
  85.     CGenericList<IMediaSample> m_SampleList;
  86. public:
  87.     BOOL SampleReady( void );
  88.     IMediaSample *GetHeadSample( void );
  89.     void GetHeadStopTime( CRefTime *prt );
  90.     void ReleaseHeadSample( void );
  91.     void ReleaseAllBefore( CRefTime rtTime );
  92.  
  93.     // Media type
  94. public:
  95.     CMediaType& CurrentMediaType() { return m_mt; };
  96.     IPin *    CurrentPeer() { return m_Connected; };
  97.  
  98.     // Attributes
  99.     const int     m_iPinNo;
  100.     BOOL m_fEOSReceived;
  101. };
  102.  
  103. // ==================================================
  104. // Implements the output pin
  105. // ==================================================
  106.  
  107. class CBaseVideoMixerOutputPin : public CBaseOutputPin
  108. {
  109.     const int m_iOutputPin;             // CBaseVideoMixer's identifier
  110.     friend class CBaseVideoMixer;
  111.  
  112.     // Owning video mixer
  113. protected:
  114.     CBaseVideoMixer *m_pBaseVideoMixer;
  115.  
  116. public:
  117.  
  118.     CBaseVideoMixerOutputPin(
  119.         TCHAR *pObjectName,
  120.         CBaseFilter *pBaseFilter,
  121.         CBaseVideoMixer *pTransformFilter,
  122.         HRESULT * phr,
  123.         LPCWSTR pName);
  124.  
  125.     ~CBaseVideoMixerOutputPin();
  126.  
  127.     // override to expose IMediaPosition
  128.     STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void **ppv);
  129.  
  130.     // --- CBaseOutputPin ------------
  131.  
  132.     // override connect to grab critsec
  133.     STDMETHODIMP Disconnect();
  134.  
  135.     // Grab and release extra interfaces if required
  136.  
  137.     HRESULT CheckConnect(IPin *pPin);
  138.     HRESULT BreakConnect();
  139.  
  140.     // return an enumerator for this pins preferred media types
  141.     STDMETHODIMP EnumMediaTypes(
  142.         IEnumMediaTypes **ppEnum
  143.     );
  144.  
  145.     // check that we can support this output type
  146.     HRESULT CheckMediaType(const CMediaType* mtOut);
  147.  
  148.     // set the connection media type
  149.     HRESULT SetMediaType(const CMediaType *pmt);
  150.  
  151.     // called from CBaseOutputPin during connection to ask for
  152.     // the count and size of buffers we need.
  153.     HRESULT DecideBufferSize(
  154.                 IMemAllocator * pAlloc,
  155.                 ALLOCATOR_PROPERTIES * pProp);
  156.  
  157.     // inherited from IQualityControl via CBasePin
  158.     STDMETHODIMP Notify(IFilter * pSender, Quality q);
  159.  
  160.     // Media type
  161. public:
  162.     CMediaType& CurrentMediaType() { return m_mt; };
  163.     IPin *    CurrentPeer() { return m_Connected; };
  164. };
  165.  
  166.  
  167. /*
  168.  * Define our base video mixer
  169.  */
  170.  
  171. class CBaseVideoMixer           :   public CBaseFilter
  172.                                 ,   public IBaseVideoMixer
  173. {
  174.  
  175. protected:
  176.  
  177. public:
  178.  
  179.     // Have we connected all input and output pins
  180.     virtual HRESULT CanChangeState();
  181.  
  182.     // map getpin/getpincount for base enum of pins to owner
  183.     // override this to return more specialised pin objects
  184.     virtual int GetPinCount();
  185.     virtual CBasePin * GetPin(int n);
  186.  
  187.     // override state changes to allow derived transform filter
  188.     // to control streaming start/stop
  189.     STDMETHODIMP Stop();
  190.     STDMETHODIMP Pause();
  191.     STDMETHODIMP Run(REFERENCE_TIME tStart);
  192.  
  193. // Construction / destruction
  194. public:
  195.     CBaseVideoMixer(TCHAR *, LPUNKNOWN, CLSID clsid, HRESULT *, int iInitialPinCount);
  196.     ~CBaseVideoMixer();
  197.  
  198. // IBaseVideoMixer
  199. public:
  200.     STDMETHODIMP SetLeadPin     ( int iPin )
  201.         { CAutoLock cal( &m_csFilter ); m_iLeadPin = iPin; return NOERROR; };
  202.  
  203.     STDMETHODIMP GetLeadPin     ( int *piPin )  { *piPin = m_iLeadPin;      return NOERROR; }
  204.     STDMETHODIMP GetInputPinCount(int *piPinCount)
  205.     {
  206.         CheckPointer(piPinCount,E_INVALIDARG);
  207.         ValidateReadWritePtr(piPinCount,sizeof(int));
  208.         *piPinCount = m_iInputPinCount;
  209.         return NOERROR;
  210.     }
  211.  
  212.     STDMETHODIMP  IsUsingClock  ( int *pbValue )
  213.     {
  214.         CheckPointer(pbValue,E_INVALIDARG);
  215.         ValidateReadWritePtr(pbValue,sizeof(int));
  216.         *pbValue = m_bUsingClock;
  217.         return NOERROR;
  218.     }
  219.  
  220.     STDMETHODIMP SetUsingClock  ( int bValue )
  221.         { CAutoLock cal( &m_csFilter ); m_bUsingClock = bValue; return E_NOTIMPL; }
  222.  
  223.     STDMETHODIMP GetClockPeriod ( int *piValue )
  224.     {
  225.         CheckPointer(piValue,E_INVALIDARG);
  226.         ValidateReadWritePtr(piValue,sizeof(int));
  227.         *piValue = m_iClockPeriod;
  228.         return NOERROR;
  229.     }
  230.  
  231.     STDMETHODIMP SetClockPeriod ( int iValue )
  232.         { CAutoLock cal( &m_csFilter ); m_iClockPeriod = iValue;  return NOERROR; }
  233.  
  234. // Definitions
  235. protected:
  236.     // =================================================================
  237.     // ----- override these bits ---------------------------------------
  238.     // =================================================================
  239.  
  240.     // These must be supplied in a derived class
  241.     virtual HRESULT MixSamples( IMediaSample *pSampleOut ) PURE;
  242.  
  243.     // check if you can support this format
  244.     virtual HRESULT CanMixType(const CMediaType* mtIn) PURE;
  245.  
  246.     // override this if you want to supply your own pins
  247.     virtual HRESULT CreatePins();
  248.     // =================================================================
  249.     // ----- End of video mixer supplied functions -----------------------
  250.     // =================================================================
  251.  
  252.     // exploses ISpecifyPropertyPages & IBaseVideoMixer
  253.     STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void **ppv);
  254.  
  255.     // wraps the PURE MixSamples function
  256.     virtual HRESULT MixAndOutputSamples( IMediaSample **ppOut );
  257.  
  258.     // you can also override these if you want to know about streaming
  259.     virtual HRESULT StartStreaming();
  260.     virtual HRESULT StopStreaming();
  261.  
  262.     // override this to know when the media type is actually set
  263.     virtual HRESULT SetMediaType( int iPin, const CMediaType *pmt );
  264.  
  265.     // chance to grab extra interfaces on connection
  266.     virtual HRESULT CheckConnect( int iPin, IPin *pPin );
  267.     virtual HRESULT BreakConnect( int iPin );
  268.  
  269.     // chance to customize the mix process
  270.     virtual HRESULT Receive( void );
  271.  
  272.     // check if you can support this format
  273.     virtual HRESULT CheckMediaType(int iPin, const CMediaType* mtIn);
  274.  
  275.     // Stream flushing
  276.     virtual HRESULT BeginFlush(void);
  277.     virtual HRESULT EndFlush(void);
  278.     virtual HRESULT ReleaseAllQueuedSamples( void );
  279.  
  280.     // called when leading stream transitioned out or at EndOfStream
  281.     virtual HRESULT HandleLeadingPinStopping(void);
  282.  
  283.     // Critical sections
  284. protected:
  285.     CCritSec m_csFilter;                // filter wide lock
  286.     CCritSec m_csMixLock;               // mix lock
  287.  
  288.     // Pins
  289. protected:
  290.     friend class CBaseVideoMixerInputPin;
  291.     friend class CBaseVideoMixerOutputPin;
  292.  
  293.     int m_iInputPinCount;               // number of input pins
  294.     int m_iInputPinsConnected;        // number connected
  295.     CBaseVideoMixerInputPin **m_apInput;// Array of input pin pointers
  296.     CBaseVideoMixerOutputPin *m_pOutput;// output pin
  297.  
  298.     CRefTime             *m_pStreamOffset;
  299.  
  300.     // Method of operation (clock vs lead pin)
  301. protected:
  302.     BOOL m_bUsingClock;                 // are we using the clock?
  303.     int m_iClockPeriod;                 // period of the clock
  304.     int m_iLeadPin;                     // Which pin triggers an output?
  305.  
  306.     CRefTime        *m_apOffsets;    // if non-NULL, allows various
  307.                     // input streams to be offset in time
  308.     CRefTime        *m_apLengths;    // if non-NULL, allows various
  309.                     // input streams to be limited in time
  310.  
  311.     // Current frame that we are working on
  312. protected:
  313.     CRefTime    m_rtThisFrame;          // when will we mix?
  314.     CRefTime    m_rtNextFrame;          // this frame stop/next frame start
  315.  
  316.     // implement IMediaPosition by passing upstream
  317. protected:
  318.     CMultiPinPosPassThru * m_pPosition;
  319.  
  320. };
  321.  
  322. BOOL AreEqualVideoTypes( const CMediaType *pmt1, const CMediaType *pmt2 );
  323.  
  324.  
  325. #endif /* __VMBASE_H__ */
  326.  
  327. 
  328.