Merge branch 'master' of git.sv.gnu.org:/srv/git/gnash
[gnash.git] / libcore / asobj / PlayHead.h
blobdb93611c5320796c0dc30539c64526c678d11a2c
1 // PlayHead.h: media playback controller
2 //
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
4 // Foundation, Inc
5 //
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.
10 //
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
27 namespace gnash {
28 class VirtualClock;
31 namespace gnash {
33 /// The playback controller
34 class PlayHead {
36 public:
38 /// Flags for playback state
39 enum PlaybackStatus {
40 PLAY_PLAYING = 1,
41 PLAY_PAUSED = 2
44 /// Initialize playhead given a VirtualCock to use
45 /// as clock source.
47 /// The PlayHead will have initial state set to PAUSED
48 /// and initial position set to 0.
49 ///
50 /// @param clockSource
51 /// The VirtualClock to use as time source.
52 /// Ownership left to caller (not necessarely a good thing).
53 ///
54 PlayHead(VirtualClock* clockSource);
56 /// Set a video consumer as available
58 /// This should be completely fine to do during
59 /// PlayHead lifetime.
60 ///
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.
70 ///
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.
116 /// @param position
117 /// Position timestamp (milliseconds)
119 /// POSTCONDITIONS:
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.
133 /// POSTCONDITIONS:
134 /// - isVideoConsumed() == false
135 /// - isAudioConsumed() == false
137 void advanceIfConsumed();
140 private:
142 /// Flags for consumers state
143 enum ConsumerFlag {
144 CONSUMER_VIDEO = 1,
145 CONSUMER_AUDIO = 2
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
175 // __PLAYHEAD_H__
176 #endif