xoreos  0.0.5
decoder.h
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #ifndef VIDEO_DECODER_H
26 #define VIDEO_DECODER_H
27 
28 #include <vector>
29 
30 #include <boost/shared_ptr.hpp>
31 
32 #include "src/common/types.h"
33 #include "src/common/rational.h"
34 #include "src/common/scopedptr.h"
35 #include "src/common/timestamp.h"
36 
37 #include "src/graphics/types.h"
40 
41 #include "src/sound/types.h"
42 
43 namespace Graphics {
44  class Surface;
45 }
46 
47 namespace Sound {
48  class AudioStream;
49  class QueuingAudioStream;
50 }
51 
52 namespace Video {
53 
56 public:
57  enum Scale {
62  };
63 
64  VideoDecoder();
65  ~VideoDecoder();
66 
67  void setScale(Scale scale);
68 
70  bool isPlaying() const;
71 
81  virtual uint32 getWidth() const;
82 
92  virtual uint32 getHeight() const;
93 
95  void start();
96 
98  void abort();
99 
105  bool needsUpdate() const;
106 
111  bool endOfVideo() const;
112 
116  bool endOfVideoTracks() const;
117 
119  uint32 getTime() const;
120 
122  uint32 getTimeToNextFrame() const;
123 
124  // Renderable
125  void calculateDistance();
127 
134  virtual Common::Timestamp getDuration() const;
135 
147  void pauseVideo(bool pause);
148 
152  bool isPaused() const { return _pauseLevel != 0; }
153 
154 protected:
159  class Track {
160  public:
161  Track();
162  virtual ~Track() {}
163 
167  enum TrackType {
172 
177 
182  };
183 
189  virtual TrackType getTrackType() const = 0;
190 
194  virtual bool endOfTrack() const = 0;
195 
199  void pause(bool shouldPause);
200 
204  bool isPaused() const { return _paused; }
205 
211  virtual Common::Timestamp getDuration() const;
212 
213  protected:
217  virtual void pauseIntern(bool shouldPause);
218 
219  private:
220  bool _paused;
221  };
222 
226  class VideoTrack : public Track {
227  public:
229  virtual ~VideoTrack() {}
230 
232  virtual bool endOfTrack() const;
233 
237  virtual uint32 getWidth() const = 0;
238 
242  virtual uint32 getHeight() const = 0;
243 
247  virtual int getCurFrame() const = 0;
248 
256  virtual int getFrameCount() const { return 0; }
257 
261  virtual Common::Timestamp getNextFrameStartTime() const = 0;
262 
269  virtual Common::Timestamp getFrameTime(uint frame) const;
270  };
271 
278  public:
280  virtual ~FixedRateVideoTrack() {}
281 
283  virtual Common::Timestamp getDuration() const;
284  Common::Timestamp getFrameTime(uint frame) const;
285 
290  uint getFrameAtTime(const Common::Timestamp &time) const;
291 
292  protected:
296  virtual Common::Rational getFrameRate() const = 0;
297  };
298 
302  class AudioTrack : public Track {
303  public:
304  AudioTrack();
305  virtual ~AudioTrack() {}
306 
308 
309  bool endOfTrack() const;
310 
314  void start();
315 
319  void stop();
320 
324  float getGain() const { return _gain; }
325 
329  void setGain(float gain);
330 
335  uint32 getRunningTime() const;
336 
340  void setMute(bool mute);
341 
345  virtual bool canBufferData() const = 0;
346 
347  protected:
348  void pauseIntern(bool shouldPause);
349 
353  virtual Sound::AudioStream *getAudioStream() const = 0;
354 
355  private:
357  float _gain;
358  bool _muted;
359  };
360 
364  typedef boost::shared_ptr<Track> TrackPtr;
365 
369  typedef boost::shared_ptr<const Track> ConstTrackPtr;
370 
374  typedef boost::shared_ptr<AudioTrack> AudioTrackPtr;
375 
379  typedef boost::shared_ptr<VideoTrack> VideoTrackPtr;
380 
384  typedef std::vector<TrackPtr> TrackList;
385 
389  typedef std::vector<ConstTrackPtr> ConstTrackList;
390 
391  bool _needCopy;
392 
394 
405  void initVideo();
406 
407  void deinit();
408 
409  // GLContainer
410  void doRebuild();
411  void doDestroy();
412 
419  virtual void decodeNextTrackFrame(VideoTrack &track) = 0;
420 
425  virtual void checkAudioBuffer(AudioTrack &track, const Common::Timestamp &endTime);
426 
435  void addTrack(Track *track, bool isExternal = false);
436 
442  TrackPtr getTrack(uint track);
443 
449  ConstTrackPtr getTrack(uint track) const;
450 
457 
462 
467 
468 private:
472 
474 
475  void stopAudio();
476  void startAudio();
477  bool hasAudio() const;
478 
480 
483 
485 
486 
489 
492 
495 
497  void update();
498 
500  void copyData();
501 
503  void getQuadDimensions(float &width, float &height) const;
504 };
505 
506 } // End of namespace Video
507 
508 #endif // VIDEO_DECODER_H
Common::ScopedPtr< Graphics::Surface > _surface
The video&#39;s surface.
Definition: decoder.h:393
uint32 getTimeToNextFrame() const
Return the time, in milliseconds, to the next frame.
Definition: decoder.cpp:423
Only scale the video up, if necessary.
Definition: decoder.h:59
virtual void pauseIntern(bool shouldPause)
Function called by pause() for subclasses to implement.
Definition: decoder.cpp:462
Don&#39;t scale the video.
Definition: decoder.h:58
An abstract representation of an audio track.
Definition: decoder.h:302
The track is a video track.
Definition: decoder.h:181
boost::shared_ptr< const Track > ConstTrackPtr
A const Track pointer.
Definition: decoder.h:369
A simple rational class that holds fractions.
Definition: rational.h:56
void addTrack(Track *track, bool isExternal=false)
Define a track to be used by this class.
Definition: decoder.cpp:152
bool hasAudio() const
Definition: decoder.cpp:235
bool _needCopy
Is new frame content available that needs to by copied?
Definition: decoder.h:391
virtual void decodeNextTrackFrame(VideoTrack &track)=0
Decode enough data for the next frame.
Graphics::TextureID _texture
Definition: decoder.h:479
void setMute(bool mute)
Mute the track.
Definition: decoder.cpp:513
virtual bool endOfTrack() const =0
Return if the track has finished.
Basic sound types.
virtual Common::Timestamp getDuration() const
Get the duration of the track.
Definition: decoder.cpp:465
Basic graphics types.
Lossless timestamping.
TrackPtr getTrack(uint track)
Get the given internal track based on its index.
Definition: decoder.cpp:181
virtual bool canBufferData() const =0
Can more audio data be buffered?
The track is an audio track.
Definition: decoder.h:176
virtual uint32 getWidth() const =0
Get the width of this track.
void update()
Update the video, if necessary.
Definition: decoder.cpp:304
GLuint TextureID
Definition: types.h:45
void setScale(Scale scale)
Definition: decoder.cpp:289
A generic interface for video decoders.
Definition: decoder.h:55
virtual uint32 getHeight() const
Returns the height of the video&#39;s frames.
Definition: decoder.cpp:98
Common::Timestamp getFrameTime(uint frame) const
Get the time the given frame should be shown.
Definition: decoder.cpp:544
A simple scoped smart pointer template.
void initVideo()
Create a surface for video of these dimensions.
Definition: decoder.cpp:71
A container of OpenGL elements.
bool needsUpdate() const
Check whether a new frame should be decoded, i.e.
Definition: decoder.cpp:122
A VideoTrack that is played at a constant rate.
Definition: decoder.h:277
virtual Common::Timestamp getDuration() const
Get the duration of the track.
Definition: decoder.cpp:561
TrackList getInternalTracks()
Get a copy of the internal tracks.
Definition: decoder.h:461
Definition: game.h:37
virtual TrackType getTrackType() const =0
Get the type of track.
void render(Graphics::RenderPass pass)
Render the object.
Definition: decoder.cpp:365
uint32 _pauseLevel
The pause level of the video; 0 for not paused.
Definition: decoder.h:491
VideoTrackPtr _nextVideoTrack
The next video track that needs to display.
Definition: decoder.h:473
RenderPass
Definition: types.h:97
boost::shared_ptr< VideoTrack > VideoTrackPtr
A VideoTrack pointer.
Definition: decoder.h:379
Common::Timestamp getNextFrameStartTime() const
Get the start time of the next frame since the start of the video.
Definition: decoder.cpp:537
Sound::ChannelHandle _handle
Definition: decoder.h:356
VideoTrackPtr findNextVideoTrack()
Set _nextVideoTrack to the video track with the lowest start time for the next frame.
Definition: decoder.cpp:195
void start()
Start playing this track.
Definition: decoder.cpp:483
void pauseVideo(bool pause)
Pause or resume the video.
Definition: decoder.cpp:126
void start()
Start playing the video.
Definition: decoder.cpp:397
virtual Sound::AudioStream * getAudioStream() const =0
Get the AudioStream that is the representation of this AudioTrack.
void stopAudio()
Stop all audio tracks.
Definition: decoder.cpp:229
bool endOfTrack() const
Return if the track has finished.
Definition: decoder.cpp:472
std::vector< ConstTrackPtr > ConstTrackList
A list of const tracks.
Definition: decoder.h:389
bool isPlaying() const
Is the video currently playing?
Definition: decoder.cpp:293
void pause(bool shouldPause)
Set the pause status of the track.
Definition: decoder.cpp:457
void getQuadDimensions(float &width, float &height) const
Get the dimensions of the quad to draw the texture on.
Definition: decoder.cpp:332
bool _paused
Is the track paused?
Definition: decoder.h:220
Low-level type definitions to handle fixed width types portably.
TrackList _internalTracks
Tracks internal to this VideoDecoder.
Definition: decoder.h:470
An abstract representation of a video track.
Definition: decoder.h:226
float getGain() const
Get the gain for this track.
Definition: decoder.h:324
void setGain(float gain)
Set the gain for this track.
Definition: decoder.cpp:476
The track type is unknown.
Definition: decoder.h:171
bool endOfVideo() const
Returns if the video has reached the end or not.
Definition: decoder.cpp:106
void calculateDistance()
Calculate the object&#39;s distance.
Definition: decoder.cpp:362
bool isPaused() const
Return whether the video is currently paused or not.
Definition: decoder.h:152
virtual int getCurFrame() const =0
Get the current frame of this track.
virtual Common::Rational getFrameRate() const =0
Get the rate at which this track is played.
virtual uint32 getHeight() const =0
Get the height of this track.
Generic audio input stream.
Definition: audiostream.h:70
An object that can be displayed by the graphics manager.
Definition: renderable.h:42
uint32 getTime() const
Returns the time position (in ms) of the current video.
Definition: decoder.cpp:411
virtual int getFrameCount() const
Get the frame count of this track.
Definition: decoder.h:256
void abort()
Abort the playing of the video.
Definition: decoder.cpp:405
virtual void checkAudioBuffer(AudioTrack &track, const Common::Timestamp &endTime)
Ensure that there is enough audio buffered in the given track to reach the given timestamp.
Definition: decoder.cpp:436
boost::shared_ptr< Track > TrackPtr
A Track pointer.
Definition: decoder.h:364
uint getFrameAtTime(const Common::Timestamp &time) const
Get the frame that should be displaying at the given time.
Definition: decoder.cpp:548
void pauseIntern(bool shouldPause)
Function called by pause() for subclasses to implement.
Definition: decoder.cpp:523
uint32 getRunningTime() const
Get the time the AudioStream behind this track has been running.
Definition: decoder.cpp:506
virtual bool endOfTrack() const
Return if the track has finished.
Definition: decoder.cpp:528
A handle to a sound channel.
Definition: types.h:35
uint32_t uint32
Definition: types.h:204
bool endOfVideoTracks() const
Have all video tracks finished?
Definition: decoder.cpp:114
TrackType getTrackType() const
Get the type of track.
Definition: decoder.h:307
virtual uint32 getWidth() const
Returns the width of the video&#39;s frames.
Definition: decoder.cpp:90
virtual Common::Timestamp getDuration() const
Get the duration of the video.
Definition: decoder.cpp:439
Timestamps allow specifying points in time and measuring time intervals with a sub-millisecond granul...
Definition: timestamp.h:108
TrackType
The types of tracks this class can be.
Definition: decoder.h:167
float _textureHeight
Definition: decoder.h:482
An abstract representation of a track in a movie.
Definition: decoder.h:159
A container of OpenGL elements.
Definition: glcontainer.h:35
Rational number implementation.
Scale the video up and down, if necessary.
Definition: decoder.h:61
#define pass
Definition: fft.cpp:257
virtual Common::Timestamp getFrameTime(uint frame) const
Get the time the given frame should be shown.
Definition: decoder.cpp:532
virtual Common::Timestamp getNextFrameStartTime() const =0
Get the start time of the next frame since the start of the video.
bool isPaused() const
Return if the track is paused.
Definition: decoder.h:204
void copyData()
Copy the video image data to the texture.
Definition: decoder.cpp:273
TrackList _externalTracks
Tracks loaded from externals files.
Definition: decoder.h:471
void startAudio()
Start the designated internal audio track and any external audio tracks.
Definition: decoder.cpp:223
TrackList _tracks
Tracks owned by this VideoDecoder (both internal and external).
Definition: decoder.h:469
An object that can be displayed by the graphics manager.
TrackType getTrackType() const
Get the type of track.
Definition: decoder.h:231
uint32 _startTime
The start time of the video, or -1 for not set.
Definition: decoder.h:488
std::vector< TrackPtr > TrackList
A list of tracks.
Definition: decoder.h:384
Only scale the video down, if necessary.
Definition: decoder.h:60
void stop()
Stop playing this track.
Definition: decoder.cpp:502
boost::shared_ptr< AudioTrack > AudioTrackPtr
An AudioTrack pointer.
Definition: decoder.h:374
unsigned int uint
Definition: types.h:211
uint32 _pauseStartTime
The time when the track was first paused.
Definition: decoder.h:494