1 // PlayHead.h: media playback controller
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef GNASH_PLAYHEAD_H
22 #define GNASH_PLAYHEAD_H
24 #include <boost/cstdint.hpp> // For C99 int types
26 // Forward declarations
33 /// The playback controller
38 /// Flags for playback state
44 /// Initialize playhead given a VirtualCock to use
47 /// The PlayHead will have initial state set to PAUSED
48 /// and initial position set to 0.
50 /// @param clockSource
51 /// The VirtualClock to use as time source.
52 /// Ownership left to caller (not necessarely a good thing).
54 PlayHead(VirtualClock
* clockSource
);
56 /// Set a video consumer as available
58 /// This should be completely fine to do during
59 /// PlayHead lifetime.
61 void setVideoConsumerAvailable()
63 _availableConsumers
|= CONSUMER_VIDEO
;
66 /// Set an audio consumer as available
68 /// This should be completely fine to do during
69 /// PlayHead lifetime.
71 void setAudioConsumerAvailable()
73 _availableConsumers
|= CONSUMER_AUDIO
;
76 /// Get current playhead position (milliseconds)
77 boost::uint64_t getPosition() const { return _position
; }
79 /// Get current playback state
80 PlaybackStatus
getState() const { return _state
; }
82 /// Set playback state, returning old state
83 PlaybackStatus
setState(PlaybackStatus newState
);
85 /// Toggle playback state, returning old state
86 PlaybackStatus
toggleState();
88 /// Return true if video of current position have been consumed
89 bool isVideoConsumed() const
91 return (_positionConsumers
& CONSUMER_VIDEO
);
94 /// Mark current position as being consumed by video consumer
95 void setVideoConsumed()
97 _positionConsumers
|= CONSUMER_VIDEO
;
100 /// Return true if audio of current position have been consumed
101 bool isAudioConsumed() const
103 return (_positionConsumers
& CONSUMER_AUDIO
);
106 /// Mark current position as being consumed by audio consumer
107 void setAudioConsumed()
109 _positionConsumers
|= CONSUMER_AUDIO
;
112 /// Change current position to the given time.
114 /// Consume flag will be reset.
117 /// Position timestamp (milliseconds)
120 /// - isVideoConsumed() == false
121 /// - isAudioConsumed() == false
122 /// - getPosition() == position
124 void seekTo(boost::uint64_t position
);
126 /// Advance position if all available consumers consumed the current one
128 /// Clock source will be used to determine the amount
129 /// of milliseconds to advance position to.
131 /// Consumer flags will be reset.
134 /// - isVideoConsumed() == false
135 /// - isAudioConsumed() == false
137 void advanceIfConsumed();
142 /// Flags for consumers state
148 /// Current playhead position
149 boost::uint64_t _position
;
151 /// Current playback state
152 PlaybackStatus _state
;
154 /// Binary OR of consumers representing
155 /// which consumers are active
156 int _availableConsumers
;
158 /// Binary OR of consumers representing
159 /// which consumers consumed current position
160 int _positionConsumers
;
162 /// The clock source, externally owned
163 VirtualClock
* _clockSource
;
165 /// Offset to subtract from current clock source
166 /// to get current position
168 /// The offset will be
169 boost::uint64_t _clockOffset
;
173 } // end of gnash namespace