2010-08-04 14:53:07 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-10-13 14:13:48 +00:00
|
|
|
#include "common/scummsys.h" // for USE_THEORADEC
|
|
|
|
|
2010-10-13 13:32:30 +00:00
|
|
|
#ifdef USE_THEORADEC
|
2010-10-13 13:07:16 +00:00
|
|
|
|
2012-08-12 12:58:00 +00:00
|
|
|
#ifndef VIDEO_THEORA_DECODER_H
|
|
|
|
#define VIDEO_THEORA_DECODER_H
|
|
|
|
|
2011-04-24 08:34:27 +00:00
|
|
|
#include "common/rational.h"
|
2011-01-23 17:14:43 +00:00
|
|
|
#include "video/video_decoder.h"
|
2011-02-09 01:09:01 +00:00
|
|
|
#include "audio/mixer.h"
|
2011-04-24 08:34:27 +00:00
|
|
|
#include "graphics/surface.h"
|
2010-08-04 14:53:07 +00:00
|
|
|
|
|
|
|
#include <theora/theoradec.h>
|
|
|
|
#include <vorbis/codec.h>
|
|
|
|
|
|
|
|
namespace Common {
|
2010-08-06 13:13:25 +00:00
|
|
|
class SeekableReadStream;
|
2010-08-04 14:53:07 +00:00
|
|
|
}
|
|
|
|
|
2012-08-13 20:23:47 +00:00
|
|
|
namespace Audio {
|
|
|
|
class AudioStream;
|
|
|
|
class QueuingAudioStream;
|
|
|
|
}
|
|
|
|
|
2012-08-12 12:58:00 +00:00
|
|
|
namespace Video {
|
2010-08-04 14:53:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Decoder for Theora videos.
|
|
|
|
* Video decoder used in engines:
|
|
|
|
* - sword25
|
|
|
|
*/
|
2012-08-13 20:23:47 +00:00
|
|
|
class TheoraDecoder : public AdvancedVideoDecoder {
|
2010-08-04 14:53:07 +00:00
|
|
|
public:
|
2011-05-15 02:48:44 +00:00
|
|
|
TheoraDecoder(Audio::Mixer::SoundType soundType = Audio::Mixer::kMusicSoundType);
|
2010-08-04 14:53:07 +00:00
|
|
|
virtual ~TheoraDecoder();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load a video file
|
|
|
|
* @param stream the stream to load
|
|
|
|
*/
|
2011-02-07 17:54:16 +00:00
|
|
|
bool loadStream(Common::SeekableReadStream *stream);
|
2010-08-04 14:53:07 +00:00
|
|
|
void close();
|
|
|
|
|
2012-08-13 20:23:47 +00:00
|
|
|
protected:
|
|
|
|
void readNextPacket();
|
2010-08-04 14:53:07 +00:00
|
|
|
|
2012-08-13 20:23:47 +00:00
|
|
|
private:
|
|
|
|
class TheoraVideoTrack : public VideoTrack {
|
|
|
|
public:
|
|
|
|
TheoraVideoTrack(const Graphics::PixelFormat &format, th_info &theoraInfo, th_setup_info *theoraSetup);
|
|
|
|
~TheoraVideoTrack();
|
2010-08-31 18:37:59 +00:00
|
|
|
|
2012-08-13 20:23:47 +00:00
|
|
|
bool endOfTrack() const { return _endOfVideo; }
|
|
|
|
uint16 getWidth() const { return _displaySurface.w; }
|
|
|
|
uint16 getHeight() const { return _displaySurface.h; }
|
|
|
|
Graphics::PixelFormat getPixelFormat() const { return _displaySurface.format; }
|
|
|
|
int getCurFrame() const { return _curFrame; }
|
|
|
|
uint32 getNextFrameStartTime() const { return (uint32)(_nextFrameStartTime * 1000); }
|
|
|
|
const Graphics::Surface *decodeNextFrame() { return &_displaySurface; }
|
2011-05-15 02:48:44 +00:00
|
|
|
|
2012-08-13 20:23:47 +00:00
|
|
|
bool decodePacket(ogg_packet &oggPacket);
|
|
|
|
void setEndOfVideo() { _endOfVideo = true; }
|
2010-08-04 21:13:43 +00:00
|
|
|
|
2012-08-13 20:23:47 +00:00
|
|
|
private:
|
|
|
|
int _curFrame;
|
|
|
|
bool _endOfVideo;
|
|
|
|
Common::Rational _frameRate;
|
|
|
|
double _nextFrameStartTime;
|
2010-08-31 18:37:59 +00:00
|
|
|
|
2012-08-13 20:23:47 +00:00
|
|
|
Graphics::Surface _surface;
|
|
|
|
Graphics::Surface _displaySurface;
|
|
|
|
|
|
|
|
th_dec_ctx *_theoraDecode;
|
|
|
|
|
|
|
|
void translateYUVtoRGBA(th_ycbcr_buffer &YUVBuffer);
|
|
|
|
};
|
|
|
|
|
|
|
|
class VorbisAudioTrack : public AudioTrack {
|
|
|
|
public:
|
|
|
|
VorbisAudioTrack(Audio::Mixer::SoundType soundType, vorbis_info &vorbisInfo);
|
|
|
|
~VorbisAudioTrack();
|
|
|
|
|
|
|
|
Audio::Mixer::SoundType getSoundType() const { return _soundType; }
|
|
|
|
|
|
|
|
bool decodeSamples();
|
|
|
|
bool hasAudio() const;
|
|
|
|
bool needsAudio() const;
|
|
|
|
void synthesizePacket(ogg_packet &oggPacket);
|
|
|
|
void setEndOfAudio() { _endOfAudio = true; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
Audio::AudioStream *getAudioStream() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// single audio fragment audio buffering
|
|
|
|
int _audioBufferFill;
|
|
|
|
ogg_int16_t *_audioBuffer;
|
|
|
|
|
|
|
|
Audio::Mixer::SoundType _soundType;
|
|
|
|
Audio::QueuingAudioStream *_audStream;
|
|
|
|
|
|
|
|
vorbis_block _vorbisBlock;
|
|
|
|
vorbis_dsp_state _vorbisDSP;
|
|
|
|
|
|
|
|
bool _endOfAudio;
|
|
|
|
};
|
2011-05-18 14:00:35 +00:00
|
|
|
|
2010-08-04 14:53:07 +00:00
|
|
|
void queuePage(ogg_page *page);
|
|
|
|
int bufferData();
|
2012-08-13 20:23:47 +00:00
|
|
|
bool queueAudio();
|
|
|
|
void ensureAudioBufferSize();
|
2010-08-04 14:53:07 +00:00
|
|
|
|
|
|
|
Common::SeekableReadStream *_fileStream;
|
|
|
|
|
2010-08-04 21:13:43 +00:00
|
|
|
Audio::Mixer::SoundType _soundType;
|
|
|
|
|
2010-08-04 14:53:07 +00:00
|
|
|
ogg_sync_state _oggSync;
|
|
|
|
ogg_page _oggPage;
|
|
|
|
ogg_packet _oggPacket;
|
|
|
|
|
2012-08-13 20:23:47 +00:00
|
|
|
ogg_stream_state _theoraOut, _vorbisOut;
|
|
|
|
bool _hasVideo, _hasAudio;
|
2010-08-04 14:53:07 +00:00
|
|
|
|
2012-08-13 20:23:47 +00:00
|
|
|
vorbis_info _vorbisInfo;
|
2010-08-04 14:53:07 +00:00
|
|
|
|
2012-08-13 20:23:47 +00:00
|
|
|
TheoraVideoTrack *_videoTrack;
|
|
|
|
VorbisAudioTrack *_audioTrack;
|
2010-08-04 14:53:07 +00:00
|
|
|
};
|
|
|
|
|
2012-08-12 12:58:00 +00:00
|
|
|
} // End of namespace Video
|
2010-08-04 14:53:07 +00:00
|
|
|
|
|
|
|
#endif
|
2010-10-13 13:07:16 +00:00
|
|
|
|
|
|
|
#endif
|