27 #include <boost/pointer_cast.hpp> 51 _textureWidth(0.0f), _textureHeight(0.0f), _scale(kScaleNone),
52 _startTime(0), _pauseLevel(0), _pauseStartTime(0) {
91 for (TrackList::const_iterator it =
_tracks.begin(); it !=
_tracks.end(); it++)
93 return boost::static_pointer_cast<const VideoTrack>(*it)->getWidth();
99 for (TrackList::const_iterator it =
_tracks.begin(); it !=
_tracks.end(); it++)
101 return boost::static_pointer_cast<const VideoTrack>(*it)->getHeight();
107 for (TrackList::const_iterator it =
_tracks.begin(); it !=
_tracks.end(); it++)
108 if (!(*it)->endOfTrack())
115 for (TrackList::const_iterator it =
_tracks.begin(); it !=
_tracks.end(); it++)
142 for (TrackList::iterator it =
_tracks.begin(); it !=
_tracks.end(); it++)
145 for (TrackList::iterator it =
_tracks.begin(); it !=
_tracks.end(); it++)
164 boost::static_pointer_cast<
AudioTrack>(owned)->setGain(1.0f);
178 boost::static_pointer_cast<AudioTrack>(owned)->start();
199 for (TrackList::iterator it =
_tracks.begin(); it !=
_tracks.end(); it++) {
204 if (time < bestTime) {
218 tracks.push_back(*it);
224 for (TrackList::iterator it =
_tracks.begin(); it !=
_tracks.end(); it++)
226 boost::static_pointer_cast<AudioTrack>(*it)->start();
230 for (TrackList::iterator it =
_tracks.begin(); it !=
_tracks.end(); it++)
232 boost::static_pointer_cast<AudioTrack>(*it)->stop();
236 for (TrackList::const_iterator it =
_tracks.begin(); it !=
_tracks.end(); it++)
250 glBindTexture(GL_TEXTURE_2D,
_texture);
253 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
254 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
256 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
257 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
258 glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_FALSE);
260 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8,
_surface->getWidth(),
_surface->getHeight(),
261 0, GL_BGRA, GL_UNSIGNED_BYTE,
_surface->getData());
282 glBindTexture(GL_TEXTURE_2D,
_texture);
283 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,
_surface->getWidth(),
_surface->getHeight(),
284 GL_BGRA, GL_UNSIGNED_BYTE,
_surface->getData());
297 for (TrackList::const_iterator it =
_tracks.begin(); it !=
_tracks.end(); it++)
298 if (!(*it)->endOfTrack())
340 float screenWidth =
WindowMan.getWindowWidth();
341 float screenHeight =
WindowMan.getWindowHeight();
343 if ((
_scale ==
kScaleUp) && (width <= screenWidth) && (height <= screenHeight))
347 if ((
_scale ==
kScaleDown) && (width >= screenWidth) && (height >= screenHeight))
351 float ratio = width / height;
354 height = screenWidth / ratio;
355 if (height <= screenHeight)
358 height = screenHeight;
359 width = screenHeight * ratio;
381 float hWidth = width / 2.0f;
382 float hHeight = height / 2.0f;
384 glBindTexture(GL_TEXTURE_2D,
_texture);
386 glTexCoord2f(0.0f, 0.0f);
387 glVertex3f(-hWidth, -hHeight, -1.0f);
389 glVertex3f( hWidth, -hHeight, -1.0f);
391 glVertex3f( hWidth, hHeight, -1.0f);
393 glVertex3f(-hWidth, hHeight, -1.0f);
430 if (nextFrameStartTime <= currentTime)
433 return nextFrameStartTime - currentTime;
443 for (TrackList::const_iterator it =
_tracks.begin(); it !=
_tracks.end(); it++) {
446 if (duration > maxDuration)
447 maxDuration = duration;
458 _paused = shouldPause;
459 pauseIntern(shouldPause);
473 return !getAudioStream() || !
SoundMan.isPlaying(_handle);
480 SoundMan.setChannelGain(_handle, _muted ? 0.0f : _gain);
492 SoundMan.setChannelGain(_handle, _muted ? 0.0f : _gain);
496 SoundMan.pauseChannel(_handle,
true);
515 if (_muted != mute) {
519 SoundMan.setChannelGain(_handle, _muted ? 0.0f : _gain);
525 SoundMan.pauseChannel(_handle, shouldPause);
529 return getCurFrame() >= (getFrameCount() - 1);
538 if (endOfTrack() || getCurFrame() < 0)
541 return getFrameTime(getCurFrame() + 1);
562 return getFrameTime(getFrameCount());
Common::ScopedPtr< Graphics::Surface > _surface
The video's surface.
uint32 getTimeToNextFrame() const
Return the time, in milliseconds, to the next frame.
virtual void show()
Show the object.
Only scale the video up, if necessary.
virtual void pauseIntern(bool shouldPause)
Function called by pause() for subclasses to implement.
Only render transparent parts.
int64 totalNumberOfFrames() const
Return the time in frames described by this timestamp.
The global graphics manager.
Don't scale the video.
virtual void hide()
Hide the object.
An abstract representation of an audio track.
void debugC(Common::DebugChannel channel, uint32 level, const char *s,...)
The track is a video track.
An object containing OpenGL structures.
boost::shared_ptr< const Track > ConstTrackPtr
A const Track pointer.
A simple rational class that holds fractions.
void reset(PointerType o=0)
Resets the pointer with the new value.
Utility functions for debug output.
uint64 framerate() const
Return the framerate used by this timestamp.
void addTrack(Track *track, bool isExternal=false)
Define a track to be used by this class.
bool _needCopy
Is new frame content available that needs to by copied?
virtual void decodeNextTrackFrame(VideoTrack &track)=0
Decode enough data for the next frame.
Graphics::TextureID _texture
void setMute(bool mute)
Mute the track.
Implementing the reading stream interfaces for plain memory blocks.
virtual Common::Timestamp getDuration() const
Get the duration of the track.
static uint32 NEXTPOWER2(uint32 x)
Round up to the next power of 2.
Decoding PCM (Pulse Code Modulation).
TrackPtr getTrack(uint track)
Get the given internal track based on its index.
virtual bool canBufferData() const =0
Can more audio data be buffered?
The track is an audio track.
void update()
Update the video, if necessary.
void setScale(Scale scale)
virtual uint32 getHeight() const
Returns the height of the video's frames.
Common::Timestamp getFrameTime(uint frame) const
Get the time the given frame should be shown.
void initVideo()
Create a surface for video of these dimensions.
bool needsUpdate() const
Check whether a new frame should be decoded, i.e.
virtual Common::Timestamp getDuration() const
Get the duration of the track.
TrackList getInternalTracks()
Get a copy of the internal tracks.
virtual TrackType getTrackType() const =0
Get the type of track.
void render(Graphics::RenderPass pass)
Render the object.
Basic exceptions to throw.
Threading system helpers.
uint32 _pauseLevel
The pause level of the video; 0 for not paused.
VideoTrackPtr _nextVideoTrack
The next video track that needs to display.
boost::shared_ptr< VideoTrack > VideoTrackPtr
A VideoTrack pointer.
Common::Timestamp getNextFrameStartTime() const
Get the start time of the next frame since the start of the video.
VideoTrackPtr findNextVideoTrack()
Set _nextVideoTrack to the video track with the lowest start time for the next frame.
void start()
Start playing this track.
void pauseVideo(bool pause)
Pause or resume the video.
void start()
Start playing the video.
"GVideo", global, non-engine video (movies).
void stopAudio()
Stop all audio tracks.
bool endOfTrack() const
Return if the track has finished.
std::vector< ConstTrackPtr > ConstTrackList
A list of const tracks.
The global events manager.
bool isPlaying() const
Is the video currently playing?
void pause(bool shouldPause)
Set the pause status of the track.
void getQuadDimensions(float &width, float &height) const
Get the dimensions of the quad to draw the texture on.
bool _paused
Is the track paused?
The global sound manager, handling all sound output.
TrackList _internalTracks
Tracks internal to this VideoDecoder.
#define SoundMan
Shortcut for accessing the sound manager.
An abstract representation of a video track.
void setGain(float gain)
Set the gain for this track.
bool endOfVideo() const
Returns if the video has reached the end or not.
void calculateDistance()
Calculate the object's distance.
#define EventMan
Shortcut for accessing the events manager.
bool isPaused() const
Return whether the video is currently paused or not.
Generic audio input stream.
uint32 getTime() const
Returns the time position (in ms) of the current video.
void abort()
Abort the playing of the video.
#define WindowMan
Shortcut for accessing the window manager.
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.
boost::shared_ptr< Track > TrackPtr
A Track pointer.
uint getFrameAtTime(const Common::Timestamp &time) const
Get the frame that should be displaying at the given time.
void pauseIntern(bool shouldPause)
Function called by pause() for subclasses to implement.
An image surface, in BGRA format.
uint32 getRunningTime() const
Get the time the AudioStream behind this track has been running.
virtual bool endOfTrack() const
Return if the track has finished.
bool endOfVideoTracks() const
Have all video tracks finished?
virtual uint32 getWidth() const
Returns the width of the video's frames.
virtual Common::Timestamp getDuration() const
Get the duration of the video.
Timestamps allow specifying points in time and measuring time intervals with a sub-millisecond granul...
An abstract representation of a track in a movie.
virtual Common::Timestamp getFrameTime(uint frame) const
Get the time the given frame should be shown.
void copyData()
Copy the video image data to the texture.
TrackList _externalTracks
Tracks loaded from externals files.
void startAudio()
Start the designated internal audio track and any external audio tracks.
TrackList _tracks
Tracks owned by this VideoDecoder (both internal and external).
Timestamp addFrames(int64 frames) const
Returns a new timestamp, which corresponds to the time encoded by this timestamp with the given numbe...
uint32 _startTime
The start time of the video, or -1 for not set.
Only scale the video down, if necessary.
void stop()
Stop playing this track.
#define GfxMan
Shortcut for accessing the graphics manager.
Generic video decoder interface.
uint32 _pauseStartTime
The time when the track was first paused.