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.

152 lines
4.3 KiB

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