Gnash  0.8.11dev
PlayHead.h
Go to the documentation of this file.
1 // PlayHead.h: media playback controller
2 //
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 // Free Software 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.
15 //
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
19 
20 
21 #ifndef GNASH_PLAYHEAD_H
22 #define GNASH_PLAYHEAD_H
23 
24 #include <cstdint> // For C99 int types
25 
26 // Forward declarations
27 namespace gnash {
28  class VirtualClock;
29 }
30 
31 namespace gnash {
32 
34 class PlayHead {
35 
36 public:
37 
42  };
43 
46  //
54  PlayHead(VirtualClock* clockSource);
55 
57  //
62  {
63  _availableConsumers |= CONSUMER_VIDEO;
64  }
65 
67  //
72  {
73  _availableConsumers |= CONSUMER_AUDIO;
74  }
75 
77  std::uint64_t getPosition() const { return _position; }
78 
80  PlaybackStatus getState() const { return _state; }
81 
84 
87 
89  bool isVideoConsumed() const
90  {
91  return (_positionConsumers & CONSUMER_VIDEO);
92  }
93 
96  {
97  _positionConsumers |= CONSUMER_VIDEO;
98  }
99 
101  bool isAudioConsumed() const
102  {
103  return (_positionConsumers & CONSUMER_AUDIO);
104  }
105 
108  {
109  _positionConsumers |= CONSUMER_AUDIO;
110  }
111 
113  //
124  void seekTo(std::uint64_t position);
125 
127  //
137  void advanceIfConsumed();
138 
139 
140 private:
141 
143  enum ConsumerFlag {
144  CONSUMER_VIDEO = 1,
145  CONSUMER_AUDIO = 2
146  };
147 
149  std::uint64_t _position;
150 
152  PlaybackStatus _state;
153 
156  int _availableConsumers;
157 
160  int _positionConsumers;
161 
163  VirtualClock* _clockSource;
164 
167  //
169  std::uint64_t _clockOffset;
170 
171 };
172 
173 } // end of gnash namespace
174 
175 // __PLAYHEAD_H__
176 #endif
177 
A class used to virtualize time flow.
Definition: VirtualClock.h:33
Definition: PlayHead.h:41
void setAudioConsumerAvailable()
Set an audio consumer as available.
Definition: PlayHead.h:71
PlaybackStatus toggleState()
Toggle playback state, returning old state.
Definition: PlayHead.cpp:82
PlayHead(VirtualClock *clockSource)
Definition: PlayHead.cpp:29
Definition: klash_part.cpp:329
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
void setAudioConsumed()
Mark current position as being consumed by audio consumer.
Definition: PlayHead.h:107
void advanceIfConsumed()
Advance position if all available consumers consumed the current one.
Definition: PlayHead.cpp:89
The playback controller.
Definition: PlayHead.h:34
PlaybackStatus getState() const
Get current playback state.
Definition: PlayHead.h:80
bool isVideoConsumed() const
Return true if video of current position have been consumed.
Definition: PlayHead.h:89
Definition: PlayHead.h:40
void setVideoConsumerAvailable()
Set a video consumer as available.
Definition: PlayHead.h:61
void seekTo(std::uint64_t position)
Change current position to the given time.
Definition: PlayHead.cpp:112
PlaybackStatus
Flags for playback state.
Definition: PlayHead.h:39
bool isAudioConsumed() const
Return true if audio of current position have been consumed.
Definition: PlayHead.h:101
PlaybackStatus setState(PlaybackStatus newState)
Set playback state, returning old state.
Definition: PlayHead.cpp:45
void setVideoConsumed()
Mark current position as being consumed by video consumer.
Definition: PlayHead.h:95
std::uint64_t getPosition() const
Get current playhead position (milliseconds)
Definition: PlayHead.h:77