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

  1. // Copyright (c) Microsoft Corporation 1996. All Rights Reserved
  2.  
  3. #ifndef __PULLPIN_H__
  4. #define __PULLPIN_H__
  5.  
  6. //
  7. // CPullPin
  8. //
  9. // object supporting pulling data from an IAsyncReader interface.
  10. // Given a start/stop position, calls a pure Receive method with each
  11. // IMediaSample received.
  12. //
  13. // This is essentially for use in a MemInputPin when it finds itself
  14. // connected to an IAsyncReader pin instead of a pushing pin.
  15. //
  16.  
  17. class CPullPin : public CThread
  18. {
  19.     IAsyncReader*    m_pReader;
  20.     REFERENCE_TIME    m_tStart;
  21.     REFERENCE_TIME    m_tStop;
  22.     REFERENCE_TIME    m_tDuration;
  23.     IMemAllocator *    m_pAlloc;
  24.     BOOL                m_bSync;
  25.  
  26.     enum ThreadMsg {
  27.     TM_Pause,    // stop pulling and wait for next message
  28.     TM_Start,    // start pulling
  29.     TM_Exit,    // stop and exit
  30.     };
  31.  
  32.     ThreadMsg m_State;
  33.  
  34.     // override pure thread proc from CThread
  35.     DWORD ThreadProc(void);
  36.  
  37.     // running pull method (check m_bSync)
  38.     void Process(void);
  39.  
  40.     // clean up any cancelled i/o after a flush
  41.     void CleanupCancelled(void);
  42.  
  43.     // suspend thread from pulling, eg during seek
  44.     HRESULT PauseThread();
  45.  
  46.     // start thread pulling - create thread if necy
  47.     HRESULT StartThread();
  48.  
  49.     // stop and close thread
  50.     HRESULT StopThread();
  51.  
  52.     // called from ProcessAsync to queue and collect requests
  53.     HRESULT QueueSample(
  54.                 REFERENCE_TIME& tCurrent,
  55.                 REFERENCE_TIME tAlignStop,
  56.                 BOOL bDiscontinuity);
  57.  
  58.     HRESULT CollectAndDeliver(
  59.                 REFERENCE_TIME tStart,
  60.                 REFERENCE_TIME tStop);
  61.  
  62.     HRESULT DeliverSample(
  63.                 IMediaSample* pSample,
  64.                 REFERENCE_TIME tStart,
  65.                 REFERENCE_TIME tStop);
  66.  
  67. public:
  68.     CPullPin();
  69.     virtual ~CPullPin();
  70.  
  71.     // returns S_OK if successfully connected to an IAsyncReader interface
  72.     // from this object
  73.     // Optional allocator should be proposed as a preferred allocator if
  74.     // necessary
  75.     // bSync is TRUE if we are to use sync reads instead of the
  76.     // async methods.
  77.     HRESULT Connect(IUnknown* pUnk, IMemAllocator* pAlloc, BOOL bSync);
  78.  
  79.     // disconnect any connection made in Connect
  80.     HRESULT Disconnect();
  81.  
  82.     // agree an allocator using RequestAllocator - optional
  83.     // props param specifies your requirements (non-zero fields).
  84.     // returns an error code if fail to match requirements.
  85.     // optional IMemAllocator interface is offered as a preferred allocator
  86.     // but no error occurs if it can't be met.
  87.     HRESULT DecideAllocator(
  88.                 IMemAllocator* pAlloc,
  89.                 ALLOCATOR_PROPERTIES * pProps);
  90.  
  91.     // set start and stop position. if active, will start immediately at
  92.     // the new position. Default is 0 to duration
  93.     HRESULT Seek(REFERENCE_TIME tStart, REFERENCE_TIME tStop);
  94.  
  95.     // return the total duration
  96.     HRESULT Duration(REFERENCE_TIME* ptDuration);
  97.  
  98.     // start pulling data
  99.     HRESULT Active(void);
  100.  
  101.     // stop pulling data
  102.     HRESULT Inactive(void);
  103.  
  104.     // helper functions
  105.     LONGLONG AlignDown(LONGLONG ll, LONG lAlign) {
  106.         // aligning downwards is just truncation
  107.         return ll & ~(lAlign-1);
  108.     };
  109.  
  110.     LONGLONG AlignUp(LONGLONG ll, LONG lAlign) {
  111.         // align up: round up to next boundary
  112.         return (ll + (lAlign -1)) & ~(lAlign -1);
  113.     };
  114.  
  115.     // GetReader returns the (addrefed) IAsyncReader interface
  116.     // for SyncRead etc
  117.     IAsyncReader* GetReader() {
  118.     m_pReader->AddRef();
  119.     return m_pReader;
  120.     };
  121.  
  122.     // -- pure --
  123.  
  124.     // override this to handle data arrival
  125.     // return value other than S_OK will stop data
  126.     virtual HRESULT Receive(IMediaSample*) PURE;
  127.  
  128.     // override this to handle end-of-stream
  129.     virtual HRESULT EndOfStream(void) PURE;
  130.  
  131.     // called on runtime errors that will have caused pulling
  132.     // to stop
  133.     // these errors are all returned from the upstream filter, who
  134.     // will have already reported any errors to the filtergraph.
  135.     virtual void OnError(HRESULT hr) PURE;
  136.  
  137.     // flush this pin and all downstream
  138.     virtual HRESULT BeginFlush() PURE;
  139.     virtual HRESULT EndFlush() PURE;
  140.  
  141. };
  142.  
  143. #endif //__PULLPIN_H__
  144.