strmctl.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. //------------------------------------------------------------------------------
  2. // File: StrmCtl.h
  3. //
  4. // Desc: DirectShow base classes.
  5. //
  6. // Copyright (c) 1996-2001 Microsoft Corporation. All rights reserved.
  7. //------------------------------------------------------------------------------
  8. #ifndef __strmctl_h__
  9. #define __strmctl_h__
  10. class CBaseStreamControl : public IAMStreamControl
  11. {
  12. public:
  13. // Used by the implementation
  14. enum StreamControlState {
  15. STREAM_FLOWING = 0x1000,
  16. STREAM_DISCARDING
  17. };
  18. private:
  19. enum StreamControlState m_StreamState; // Current stream state
  20. enum StreamControlState m_StreamStateOnStop; // State after next stop
  21. // (i.e.Blocking or Discarding)
  22. REFERENCE_TIME m_tStartTime; // MAX_TIME implies none
  23. REFERENCE_TIME m_tStopTime; // MAX_TIME implies none
  24. DWORD m_dwStartCookie; // Cookie for notification to app
  25. DWORD m_dwStopCookie; // Cookie for notification to app
  26. volatile BOOL m_bIsFlushing; // No optimization pls!
  27. volatile BOOL m_bStopSendExtra; // bSendExtra was set
  28. volatile BOOL m_bStopExtraSent; // the extra one was sent
  29. CCritSec m_CritSec; // CritSec to guard above attributes
  30. // Event to fire when we can come
  31. // out of blocking, or to come out of waiting
  32. // to discard if we change our minds.
  33. //
  34. CAMEvent m_StreamEvent;
  35. // All of these methods execute immediately. Helpers for others.
  36. //
  37. void ExecuteStop();
  38. void ExecuteStart();
  39. void CancelStop();
  40. void CancelStart();
  41. // Some things we need to be told by our owning filter
  42. // Your pin must also expose IAMStreamControl when QI'd for it!
  43. //
  44. IReferenceClock * m_pRefClock; // Need it to set advises
  45. // Filter must tell us via
  46. // SetSyncSource
  47. IMediaEventSink * m_pSink; // Event sink
  48. // Filter must tell us after it
  49. // creates it in JoinFilterGraph()
  50. FILTER_STATE m_FilterState; // Just need it!
  51. // Filter must tell us via
  52. // NotifyFilterState
  53. REFERENCE_TIME m_tRunStart; // Per the Run call to the filter
  54. // This guy will return one of the three StreamControlState's. Here's what
  55. // the caller should do for each one:
  56. //
  57. // STREAM_FLOWING: Proceed as usual (render or pass the sample on)
  58. // STREAM_DISCARDING: Calculate the time 'til *pSampleStop and wait
  59. // that long for the event handle
  60. // (GetStreamEventHandle()). If the wait
  61. // expires, throw the sample away. If the event
  62. // fires, call me back - I've changed my mind.
  63. //
  64. enum StreamControlState CheckSampleTimes( __in const REFERENCE_TIME * pSampleStart,
  65. __in const REFERENCE_TIME * pSampleStop );
  66. public:
  67. // You don't have to tell us much when we're created, but there are other
  68. // obligations that must be met. See SetSyncSource & NotifyFilterState
  69. // below.
  70. //
  71. CBaseStreamControl(__inout_opt HRESULT *phr = NULL);
  72. ~CBaseStreamControl();
  73. // If you want this class to work properly, there are thing you need to
  74. // (keep) telling it. Filters with pins that use this class
  75. // should ensure that they pass through to this method any calls they
  76. // receive on their SetSyncSource.
  77. // We need a clock to see what time it is. This is for the
  78. // "discard in a timely fashion" logic. If we discard everything as
  79. // quick as possible, a whole 60 minute file could get discarded in the
  80. // first 10 seconds, and if somebody wants to turn streaming on at 30
  81. // minutes into the file, and they make the call more than a few seconds
  82. // after the graph is run, it may be too late!
  83. // So we hold every sample until it's time has gone, then we discard it.
  84. // The filter should call this when it gets a SetSyncSource
  85. //
  86. void SetSyncSource( IReferenceClock * pRefClock ) {
  87. CAutoLock lck(&m_CritSec);
  88. if (m_pRefClock) {
  89. m_pRefClock->Release();
  90. }
  91. m_pRefClock = pRefClock;
  92. if (m_pRefClock) {
  93. m_pRefClock->AddRef();
  94. }
  95. }
  96. // Set event sink for notifications
  97. // The filter should call this in its JoinFilterGraph after it creates the
  98. // IMediaEventSink
  99. //
  100. void SetFilterGraph( IMediaEventSink *pSink ) {
  101. m_pSink = pSink;
  102. }
  103. // Since we schedule in stream time, we need the tStart and must track the
  104. // state of our owning filter.
  105. // The app should call this ever state change
  106. //
  107. void NotifyFilterState( FILTER_STATE new_state, REFERENCE_TIME tStart = 0 );
  108. // Filter should call Flushing(TRUE) in BeginFlush,
  109. // and Flushing(FALSE) in EndFlush.
  110. //
  111. void Flushing( BOOL bInProgress );
  112. // The two main methods of IAMStreamControl
  113. // Class adds default values suitable for immediate
  114. // muting and unmuting of the stream.
  115. STDMETHODIMP StopAt( const REFERENCE_TIME * ptStop = NULL,
  116. BOOL bSendExtra = FALSE,
  117. DWORD dwCookie = 0 );
  118. STDMETHODIMP StartAt( const REFERENCE_TIME * ptStart = NULL,
  119. DWORD dwCookie = 0 );
  120. STDMETHODIMP GetInfo( __out AM_STREAM_INFO *pInfo);
  121. // Helper function for pin's receive method. Call this with
  122. // the sample and we'll tell you what to do with it. We'll do a
  123. // WaitForSingleObject within this call if one is required. This is
  124. // a "What should I do with this sample?" kind of call. We'll tell the
  125. // caller to either flow it or discard it.
  126. // If pSample is NULL we evaluate based on the current state
  127. // settings
  128. enum StreamControlState CheckStreamState( IMediaSample * pSample );
  129. private:
  130. // These don't require locking, but we are relying on the fact that
  131. // m_StreamState can be retrieved with integrity, and is a snap shot that
  132. // may have just been, or may be just about to be, changed.
  133. HANDLE GetStreamEventHandle() const {
  134. return m_StreamEvent;
  135. }
  136. enum StreamControlState GetStreamState() const {
  137. return m_StreamState;
  138. }
  139. BOOL IsStreaming() const {
  140. return m_StreamState == STREAM_FLOWING;
  141. }
  142. };
  143. #endif