From 384468c0148ede9ae8140b4fd75183368d26ada6 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Tue, 31 Aug 2010 09:45:21 +0000 Subject: SWORD25: Started to hook TheoraDecoder. Crashes at startup. svn-id: r53297 --- engines/sword25/fmv/movieplayer.cpp | 21 ++++++++++++++++++++- engines/sword25/fmv/movieplayer.h | 6 +++--- engines/sword25/fmv/theora_decoder.cpp | 14 ++++++++------ engines/sword25/fmv/theora_decoder.h | 4 ++-- 4 files changed, 33 insertions(+), 12 deletions(-) (limited to 'engines/sword25/fmv') diff --git a/engines/sword25/fmv/movieplayer.cpp b/engines/sword25/fmv/movieplayer.cpp index e4b33bdf8c..3114d68bdc 100644 --- a/engines/sword25/fmv/movieplayer.cpp +++ b/engines/sword25/fmv/movieplayer.cpp @@ -33,6 +33,9 @@ */ #include "sword25/fmv/movieplayer.h" +#include "sword25/fmv/theora_decoder.h" +#include "sword25/kernel/kernel.h" +#include "sword25/package/packagemanager.h" namespace Sword25 { @@ -47,13 +50,29 @@ MoviePlayer::MoviePlayer(Kernel *pKernel) : Service(pKernel) { BS_LOG_ERRORLN("Script bindings could not be registered."); else BS_LOGLN("Script bindings registered."); + + _decoder = new TheoraDecoder(); } -bool MoviePlayer::LoadMovie(const Common::String &Filename, unsigned int Z) { +bool MoviePlayer::LoadMovie(const Common::String &filename, unsigned int Z) { + Common::SeekableReadStream *in = Kernel::GetInstance()->GetPackage()->GetStream(filename); + + if (!in) { + BS_LOG_ERRORLN("Could not open movie file \"%s\".", filename.c_str()); + return false; + } + + if (!_decoder->load(in)) { + BS_LOG_ERRORLN("Could not load movie file \"%s\".", filename.c_str()); + return false; + } + return true; } bool MoviePlayer::UnloadMovie() { + _decoder->close(); + return true; } diff --git a/engines/sword25/fmv/movieplayer.h b/engines/sword25/fmv/movieplayer.h index 3404eaacd8..233c500fd5 100644 --- a/engines/sword25/fmv/movieplayer.h +++ b/engines/sword25/fmv/movieplayer.h @@ -44,9 +44,7 @@ namespace Sword25 { -// ----------------------------------------------------------------------------- -// Class definitions -// ----------------------------------------------------------------------------- +class TheoraDecoder; class MoviePlayer : public Service { public: @@ -140,6 +138,8 @@ public: private: bool _RegisterScriptBindings(); + + TheoraDecoder *_decoder; }; } // End of namespace Sword25 diff --git a/engines/sword25/fmv/theora_decoder.cpp b/engines/sword25/fmv/theora_decoder.cpp index ef9f904f77..31458a2deb 100644 --- a/engines/sword25/fmv/theora_decoder.cpp +++ b/engines/sword25/fmv/theora_decoder.cpp @@ -84,10 +84,10 @@ int TheoraDecoder::bufferData() { return(bytes); } -bool TheoraDecoder::load(Common::SeekableReadStream &stream) { +bool TheoraDecoder::load(Common::SeekableReadStream *stream) { close(); - _fileStream = &stream; + _fileStream = stream; // start up Ogg stream synchronization layer ogg_sync_init(&_oggSync); @@ -236,7 +236,7 @@ bool TheoraDecoder::load(Common::SeekableReadStream &stream) { // open audio if (_vorbisPacket) { _audStream = createAudioStream(); - if (_audStream) + if (_audStream && _mixer) _mixer->playStream(_soundType, _audHandle, _audStream); } @@ -255,7 +255,8 @@ void TheoraDecoder::close() { vorbis_comment_clear(&_vorbisComment); vorbis_info_clear(&_vorbisInfo); - _mixer->stopHandle(*_audHandle); + if (_mixer) + _mixer->stopHandle(*_audHandle); _audStream = 0; } if (_theoraPacket) { @@ -264,11 +265,12 @@ void TheoraDecoder::close() { th_comment_clear(&_theoraComment); th_info_clear(&_theoraInfo); } - ogg_sync_clear(&_oggSync); if (!_fileStream) return; + ogg_sync_clear(&_oggSync); + delete _fileStream; _fileStream = 0; @@ -417,7 +419,7 @@ void TheoraDecoder::reset() { } uint32 TheoraDecoder::getElapsedTime() const { - if (_audStream) + if (_audStream && _mixer) return _mixer->getSoundElapsedTime(*_audHandle); return VideoDecoder::getElapsedTime(); diff --git a/engines/sword25/fmv/theora_decoder.h b/engines/sword25/fmv/theora_decoder.h index 690763e940..7faadfd9dc 100644 --- a/engines/sword25/fmv/theora_decoder.h +++ b/engines/sword25/fmv/theora_decoder.h @@ -47,14 +47,14 @@ namespace Sword25 { */ class TheoraDecoder : public Graphics::FixedRateVideoDecoder { public: - TheoraDecoder(Audio::Mixer *mixer, Audio::Mixer::SoundType soundType); + TheoraDecoder(Audio::Mixer *mixer = 0, Audio::Mixer::SoundType soundType = Audio::Mixer::kMusicSoundType); virtual ~TheoraDecoder(); /** * Load a video file * @param stream the stream to load */ - bool load(Common::SeekableReadStream &stream); + bool load(Common::SeekableReadStream *stream); void close(); void reset(); -- cgit v1.2.3