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.

157 lines
6.0 KiB

  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( const REFERENCE_TIME * pSampleStart,
  65. 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();
  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. {
  88. CAutoLock lck(&m_CritSec);
  89. if (m_pRefClock) m_pRefClock->Release();
  90. m_pRefClock = pRefClock;
  91. if (m_pRefClock) m_pRefClock->AddRef();
  92. }
  93. // Set event sink for notifications
  94. // The filter should call this in its JoinFilterGraph after it creates the
  95. // IMediaEventSink
  96. //
  97. void SetFilterGraph( IMediaEventSink *pSink ) {
  98. m_pSink = pSink;
  99. }
  100. // Since we schedule in stream time, we need the tStart and must track the
  101. // state of our owning filter.
  102. // The app should call this ever state change
  103. //
  104. void NotifyFilterState( FILTER_STATE new_state, REFERENCE_TIME tStart = 0 );
  105. // Filter should call Flushing(TRUE) in BeginFlush,
  106. // and Flushing(FALSE) in EndFlush.
  107. //
  108. void Flushing( BOOL bInProgress );
  109. // The two main methods of IAMStreamControl
  110. // Class adds default values suitable for immediate
  111. // muting and unmuting of the stream.
  112. STDMETHODIMP StopAt( const REFERENCE_TIME * ptStop = NULL,
  113. BOOL bSendExtra = FALSE,
  114. DWORD dwCookie = 0 );
  115. STDMETHODIMP StartAt( const REFERENCE_TIME * ptStart = NULL,
  116. DWORD dwCookie = 0 );
  117. STDMETHODIMP GetInfo( AM_STREAM_INFO *pInfo);
  118. // Helper function for pin's receive method. Call this with
  119. // the sample and we'll tell you what to do with it. We'll do a
  120. // WaitForSingleObject within this call if one is required. This is
  121. // a "What should I do with this sample?" kind of call. We'll tell the
  122. // caller to either flow it or discard it.
  123. // If pSample is NULL we evaluate based on the current state
  124. // settings
  125. enum StreamControlState CheckStreamState( IMediaSample * pSample );
  126. private:
  127. // These don't require locking, but we are relying on the fact that
  128. // m_StreamState can be retrieved with integrity, and is a snap shot that
  129. // may have just been, or may be just about to be, changed.
  130. HANDLE GetStreamEventHandle() const { return m_StreamEvent; }
  131. enum StreamControlState GetStreamState() const { return m_StreamState; }
  132. BOOL IsStreaming() const { return m_StreamState == STREAM_FLOWING; }
  133. };
  134. #endif