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