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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SWORD25_THEORADECODER_H
|
|
|
|
#define SWORD25_THEORADECODER_H
|
|
|
|
|
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
|
|
|
|
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/audiostream.h"
|
|
|
|
#include "audio/mixer.h"
|
2011-04-24 08:34:27 +00:00
|
|
|
#include "graphics/pixelformat.h"
|
|
|
|
#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
|
|
|
}
|
|
|
|
|
|
|
|
namespace Sword25 {
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Decoder for Theora videos.
|
|
|
|
* Video decoder used in engines:
|
|
|
|
* - sword25
|
|
|
|
*/
|
2011-05-17 02:47:41 +00:00
|
|
|
class TheoraDecoder : public Video::VideoDecoder {
|
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();
|
2010-08-05 12:16:21 +00:00
|
|
|
void reset();
|
2010-08-04 14:53:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Decode the next frame and return the frame's surface
|
|
|
|
* @note the return surface should *not* be freed
|
|
|
|
* @note this may return 0, in which case the last frame should be kept on screen
|
|
|
|
*/
|
2010-12-16 01:35:13 +00:00
|
|
|
const Graphics::Surface *decodeNextFrame();
|
2010-08-04 14:53:07 +00:00
|
|
|
|
2011-05-15 02:48:44 +00:00
|
|
|
bool isVideoLoaded() const { return _fileStream != 0; }
|
|
|
|
uint16 getWidth() const { return _surface->w; }
|
|
|
|
uint16 getHeight() const { return _surface->h; }
|
2010-08-31 18:37:59 +00:00
|
|
|
|
2010-08-06 13:13:25 +00:00
|
|
|
uint32 getFrameCount() const {
|
2010-08-31 18:37:59 +00:00
|
|
|
// It is not possible to get frame count easily
|
|
|
|
// I.e. seeking is required
|
|
|
|
assert(0);
|
2010-09-01 07:35:38 +00:00
|
|
|
return 0;
|
2010-08-06 13:13:25 +00:00
|
|
|
}
|
2011-05-15 02:48:44 +00:00
|
|
|
|
|
|
|
Graphics::PixelFormat getPixelFormat() const { return _surface->format; }
|
2010-08-04 21:13:43 +00:00
|
|
|
uint32 getElapsedTime() const;
|
2011-05-17 02:47:41 +00:00
|
|
|
uint32 getTimeToNextFrame() const;
|
2010-08-04 21:13:43 +00:00
|
|
|
|
2010-08-31 18:37:59 +00:00
|
|
|
bool endOfVideo() const;
|
|
|
|
|
2010-08-04 14:53:07 +00:00
|
|
|
private:
|
|
|
|
void queuePage(ogg_page *page);
|
2011-05-17 02:47:41 +00:00
|
|
|
bool queueAudio();
|
2010-08-04 14:53:07 +00:00
|
|
|
int bufferData();
|
2011-05-15 02:48:44 +00:00
|
|
|
void translateYUVtoRGBA(th_ycbcr_buffer &YUVBuffer);
|
2010-08-04 14:53:07 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Common::SeekableReadStream *_fileStream;
|
|
|
|
Graphics::Surface *_surface;
|
|
|
|
Common::Rational _frameRate;
|
2011-05-17 02:47:41 +00:00
|
|
|
double _nextFrameStartTime;
|
|
|
|
bool _endOfVideo;
|
|
|
|
bool _endOfAudio;
|
2010-08-04 14:53:07 +00:00
|
|
|
|
2010-08-04 21:13:43 +00:00
|
|
|
Audio::Mixer::SoundType _soundType;
|
|
|
|
Audio::SoundHandle *_audHandle;
|
|
|
|
Audio::QueuingAudioStream *_audStream;
|
|
|
|
|
2010-08-04 14:53:07 +00:00
|
|
|
ogg_sync_state _oggSync;
|
|
|
|
ogg_page _oggPage;
|
|
|
|
ogg_packet _oggPacket;
|
|
|
|
ogg_stream_state _vorbisOut;
|
|
|
|
ogg_stream_state _theoraOut;
|
|
|
|
th_info _theoraInfo;
|
|
|
|
th_comment _theoraComment;
|
|
|
|
th_dec_ctx *_theoraDecode;
|
|
|
|
th_setup_info *_theoraSetup;
|
|
|
|
vorbis_info _vorbisInfo;
|
|
|
|
vorbis_dsp_state _vorbisDSP;
|
|
|
|
vorbis_block _vorbisBlock;
|
|
|
|
vorbis_comment _vorbisComment;
|
|
|
|
|
|
|
|
int _theoraPacket;
|
|
|
|
int _vorbisPacket;
|
|
|
|
|
|
|
|
int _ppLevelMax;
|
|
|
|
int _ppLevel;
|
|
|
|
int _ppInc;
|
|
|
|
|
|
|
|
// single audio fragment audio buffering
|
|
|
|
int _audiobufFill;
|
2010-08-04 21:13:43 +00:00
|
|
|
bool _audiobufReady;
|
2010-08-04 14:53:07 +00:00
|
|
|
ogg_int16_t *_audiobuf;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // End of namespace Sword25
|
|
|
|
|
|
|
|
#endif
|
2010-10-13 13:07:16 +00:00
|
|
|
|
|
|
|
#endif
|