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 ++-- engines/sword25/module.mk | 2 +- engines/sword25/package/packagemanager.h | 7 +++++++ engines/sword25/package/scummvmpackagemanager.cpp | 11 +++++++++++ engines/sword25/package/scummvmpackagemanager.h | 1 + 8 files changed, 53 insertions(+), 13 deletions(-) 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(); diff --git a/engines/sword25/module.mk b/engines/sword25/module.mk index 6cb4ad934c..4576cf519a 100644 --- a/engines/sword25/module.mk +++ b/engines/sword25/module.mk @@ -109,7 +109,7 @@ MODULE_OBJS := \ $(QUIET)$(MKDIR) $(*D)/$(DEPDIR) $(QUIET_CXX)gcc $(CXX_UPDATE_DEP_FLAG) $(CXXFLAGS) $(CPPFLAGS) -c $(<) -o $*.o -LIBS += -lpng +LIBS += -lpng -ltheoradec # This module can be built as a plugin ifeq ($(ENABLE_SWORD25), DYNAMIC_PLUGIN) diff --git a/engines/sword25/package/packagemanager.h b/engines/sword25/package/packagemanager.h index c441fff122..4aaa05c589 100644 --- a/engines/sword25/package/packagemanager.h +++ b/engines/sword25/package/packagemanager.h @@ -101,6 +101,13 @@ public: * @remark The client must not forget to release the data of the file using BE_DELETE_A. */ virtual byte *GetFile(const Common::String &FileName, unsigned int *pFileSize = NULL) = 0; + + /** + * Returns a stream from file file from the virtual directory tree + * @param FileName The filename of the file to load + * @return Pointer to the stream object + */ + virtual Common::SeekableReadStream *GetStream(const Common::String &fileName) = 0; /** * Downloads an XML file and prefixes it with an XML Version key, since the XML files don't contain it, * and it is required for ScummVM to correctly parse the XML. diff --git a/engines/sword25/package/scummvmpackagemanager.cpp b/engines/sword25/package/scummvmpackagemanager.cpp index 7a38e8d22a..ee4e100b32 100644 --- a/engines/sword25/package/scummvmpackagemanager.cpp +++ b/engines/sword25/package/scummvmpackagemanager.cpp @@ -152,6 +152,17 @@ byte *ScummVMPackageManager::GetFile(const Common::String &fileName, unsigned in return buffer; } +Common::SeekableReadStream *ScummVMPackageManager::GetStream(const Common::String &fileName) { + Common::SeekableReadStream *in; + Common::ArchiveMemberPtr fileNode = GetArchiveMember(normalizePath(fileName, _currentDirectory)); + if (!fileNode) + return 0; + if (!(in = fileNode->createReadStream())) + return 0; + + return in; +} + Common::String ScummVMPackageManager::GetCurrentDirectory() { return _currentDirectory; } diff --git a/engines/sword25/package/scummvmpackagemanager.h b/engines/sword25/package/scummvmpackagemanager.h index 140347000b..6ffc10264a 100644 --- a/engines/sword25/package/scummvmpackagemanager.h +++ b/engines/sword25/package/scummvmpackagemanager.h @@ -73,6 +73,7 @@ public: virtual bool LoadPackage(const Common::String &fileName, const Common::String &mountPosition); virtual bool LoadDirectoryAsPackage(const Common::String &directoryName, const Common::String &mountPosition); virtual byte *GetFile(const Common::String &fileName, unsigned int *fileSizePtr = 0); + virtual Common::SeekableReadStream *GetStream(const Common::String &fileName); virtual Common::String GetCurrentDirectory(); virtual bool ChangeDirectory(const Common::String &directory); virtual Common::String GetAbsolutePath(const Common::String &fileName); -- cgit v1.2.3