diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 0d0294fa7d..59f9fa6926 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -377,7 +377,7 @@ void OMW::Engine::prepareEngine (Settings::Manager & settings) mEnvironment.setWindowManager (window); // Create sound system - mEnvironment.setSoundManager (new MWSound::SoundManager(mUseSound)); + mEnvironment.setSoundManager (new MWSound::SoundManager(mVFS.get(), mUseSound)); if (!mSkipMenu) { diff --git a/apps/openmw/mwsound/ffmpeg_decoder.cpp b/apps/openmw/mwsound/ffmpeg_decoder.cpp index 0185d3ecc1..55607b5b72 100644 --- a/apps/openmw/mwsound/ffmpeg_decoder.cpp +++ b/apps/openmw/mwsound/ffmpeg_decoder.cpp @@ -4,6 +4,7 @@ #include #include +#include extern "C" { #ifndef HAVE_LIBSWRESAMPLE @@ -15,6 +16,8 @@ AVAudioResampleContext * swr_alloc_set_opts( AVAudioResampleContext *avr, int64_ #endif } +#include + namespace MWSound { @@ -27,8 +30,10 @@ int FFmpeg_Decoder::readPacket(void *user_data, uint8_t *buf, int buf_size) { try { - Ogre::DataStreamPtr stream = static_cast(user_data)->mDataStream; - return stream->read(buf, buf_size); + std::istream& stream = *static_cast(user_data)->mDataStream; + stream.read((char*)buf, buf_size); + stream.clear(); + return stream.gcount(); } catch (std::exception& ) { @@ -36,36 +41,36 @@ int FFmpeg_Decoder::readPacket(void *user_data, uint8_t *buf, int buf_size) } } -int FFmpeg_Decoder::writePacket(void *user_data, uint8_t *buf, int buf_size) +int FFmpeg_Decoder::writePacket(void *, uint8_t *, int) { - try - { - Ogre::DataStreamPtr stream = static_cast(user_data)->mDataStream; - return stream->write(buf, buf_size); - } - catch (std::exception& ) - { - return 0; - } + throw std::runtime_error("can't write to read-only stream"); } int64_t FFmpeg_Decoder::seek(void *user_data, int64_t offset, int whence) { - Ogre::DataStreamPtr stream = static_cast(user_data)->mDataStream; + std::istream& stream = *static_cast(user_data)->mDataStream; whence &= ~AVSEEK_FORCE; + if(whence == AVSEEK_SIZE) - return stream->size(); + { + size_t prev = stream.tellg(); + stream.seekg(0, std::ios_base::end); + size_t size = stream.tellg(); + stream.seekg(prev, std::ios_base::beg); + return size; + } + if(whence == SEEK_SET) - stream->seek(static_cast(offset)); + stream.seekg(offset, std::ios_base::beg); else if(whence == SEEK_CUR) - stream->seek(static_cast(stream->tell()+offset)); + stream.seekg(offset, std::ios_base::cur); else if(whence == SEEK_END) - stream->seek(static_cast(stream->size()+offset)); + stream.seekg(offset, std::ios_base::end); else return -1; - return stream->tell(); + return stream.tellg(); } @@ -186,7 +191,7 @@ size_t FFmpeg_Decoder::readAVAudioData(void *data, size_t length) void FFmpeg_Decoder::open(const std::string &fname) { close(); - mDataStream = mResourceMgr.openResource(fname); + mDataStream = mResourceMgr->get(fname); if((mFormatCtx=avformat_alloc_context()) == NULL) fail("Failed to allocate context"); @@ -289,7 +294,7 @@ void FFmpeg_Decoder::close() avformat_close_input(&mFormatCtx); } - mDataStream.setNull(); + mDataStream.reset(); } std::string FFmpeg_Decoder::getName() @@ -409,8 +414,9 @@ size_t FFmpeg_Decoder::getSampleOffset() return (int)(mNextPts*(*mStream)->codec->sample_rate) - delay; } -FFmpeg_Decoder::FFmpeg_Decoder() - : mFormatCtx(NULL) +FFmpeg_Decoder::FFmpeg_Decoder(const VFS::Manager* vfs) + : Sound_Decoder(vfs) + , mFormatCtx(NULL) , mStream(NULL) , mFrame(NULL) , mFrameSize(0) diff --git a/apps/openmw/mwsound/ffmpeg_decoder.hpp b/apps/openmw/mwsound/ffmpeg_decoder.hpp index 2cdbbf363d..3abf7c474d 100644 --- a/apps/openmw/mwsound/ffmpeg_decoder.hpp +++ b/apps/openmw/mwsound/ffmpeg_decoder.hpp @@ -37,7 +37,10 @@ extern "C" #endif } +#include + #include +#include #include "sound_decoder.hpp" @@ -66,7 +69,8 @@ namespace MWSound bool getNextPacket(); - Ogre::DataStreamPtr mDataStream; + Files::IStreamPtr mDataStream; + static int readPacket(void *user_data, uint8_t *buf, int buf_size); static int writePacket(void *user_data, uint8_t *buf, int buf_size); static int64_t seek(void *user_data, int64_t offset, int whence); @@ -90,7 +94,7 @@ namespace MWSound FFmpeg_Decoder& operator=(const FFmpeg_Decoder &rhs); FFmpeg_Decoder(const FFmpeg_Decoder &rhs); - FFmpeg_Decoder(); + FFmpeg_Decoder(const VFS::Manager* vfs); public: virtual ~FFmpeg_Decoder(); diff --git a/apps/openmw/mwsound/openal_output.cpp b/apps/openmw/mwsound/openal_output.cpp index 1b3dced801..266b97f875 100644 --- a/apps/openmw/mwsound/openal_output.cpp +++ b/apps/openmw/mwsound/openal_output.cpp @@ -786,7 +786,7 @@ const CachedSound& OpenAL_Output::getBuffer(const std::string &fname) { decoder->open(fname); } - catch(Ogre::FileNotFoundException&) + catch(std::exception&) { std::string::size_type pos = fname.rfind('.'); if(pos == std::string::npos) diff --git a/apps/openmw/mwsound/sound_decoder.hpp b/apps/openmw/mwsound/sound_decoder.hpp index 151b580360..1be9dd3749 100644 --- a/apps/openmw/mwsound/sound_decoder.hpp +++ b/apps/openmw/mwsound/sound_decoder.hpp @@ -2,8 +2,12 @@ #define GAME_SOUND_SOUND_DECODER_H #include +#include -#include +namespace VFS +{ + class Manager; +} namespace MWSound { @@ -28,7 +32,7 @@ namespace MWSound struct Sound_Decoder { - Ogre::ResourceGroupManager &mResourceMgr; + const VFS::Manager* mResourceMgr; virtual void open(const std::string &fname) = 0; virtual void close() = 0; @@ -41,7 +45,7 @@ namespace MWSound virtual void rewind() = 0; virtual size_t getSampleOffset() = 0; - Sound_Decoder() : mResourceMgr(Ogre::ResourceGroupManager::getSingleton()) + Sound_Decoder(const VFS::Manager* resourceMgr) : mResourceMgr(resourceMgr) { } virtual ~Sound_Decoder() { } diff --git a/apps/openmw/mwsound/soundmanagerimp.cpp b/apps/openmw/mwsound/soundmanagerimp.cpp index 5fc39f03e8..84f61ddf8d 100644 --- a/apps/openmw/mwsound/soundmanagerimp.cpp +++ b/apps/openmw/mwsound/soundmanagerimp.cpp @@ -6,6 +6,8 @@ #include +#include + #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" #include "../mwbase/statemanager.hpp" @@ -27,8 +29,8 @@ namespace MWSound { - SoundManager::SoundManager(bool useSound) - : mResourceMgr(Ogre::ResourceGroupManager::getSingleton()) + SoundManager::SoundManager(const VFS::Manager* vfs, bool useSound) + : mVFS(vfs) , mOutput(new DEFAULT_OUTPUT(*this)) , mMasterVolume(1.0f) , mSFXVolume(1.0f) @@ -96,7 +98,7 @@ namespace MWSound // Return a new decoder instance, used as needed by the output implementations DecoderPtr SoundManager::getDecoder() { - return DecoderPtr(new DEFAULT_DECODER); + return DecoderPtr(new DEFAULT_DECODER (mVFS)); } // Convert a soundId to file name, and modify the volume @@ -208,20 +210,24 @@ namespace MWSound void SoundManager::startRandomTitle() { - Ogre::StringVector filelist; + std::vector filelist; if (mMusicFiles.find(mCurrentPlaylist) == mMusicFiles.end()) { -#if 0 - Ogre::StringVector groups = Ogre::ResourceGroupManager::getSingleton().getResourceGroups (); - for (Ogre::StringVector::iterator it = groups.begin(); it != groups.end(); ++it) + const std::map& index = mVFS->getIndex(); + + std::string pattern = "Music/" + mCurrentPlaylist; + mVFS->normalizeFilename(pattern); + + std::map::const_iterator found = index.lower_bound(pattern); + while (found != index.end()) { - Ogre::StringVectorPtr resourcesInThisGroup = mResourceMgr.findResourceNames(*it, - "Music/"+mCurrentPlaylist+"/*"); - filelist.insert(filelist.end(), resourcesInThisGroup->begin(), resourcesInThisGroup->end()); + if (found->first.size() >= pattern.size() && found->first.substr(0, pattern.size()) == pattern) + filelist.push_back(found->first); + ++found; } + mMusicFiles[mCurrentPlaylist] = filelist; -#endif } else filelist = mMusicFiles[mCurrentPlaylist]; diff --git a/apps/openmw/mwsound/soundmanagerimp.hpp b/apps/openmw/mwsound/soundmanagerimp.hpp index 250cb0d51c..8089a7e6f5 100644 --- a/apps/openmw/mwsound/soundmanagerimp.hpp +++ b/apps/openmw/mwsound/soundmanagerimp.hpp @@ -8,12 +8,16 @@ #include #include -#include #include #include "../mwbase/soundmanager.hpp" +namespace VFS +{ + class Manager; +} + namespace MWSound { class Sound_Output; @@ -27,12 +31,12 @@ namespace MWSound class SoundManager : public MWBase::SoundManager { - Ogre::ResourceGroupManager& mResourceMgr; + const VFS::Manager* mVFS; std::auto_ptr mOutput; // Caches available music tracks by - std::map mMusicFiles; + std::map > mMusicFiles; std::string mLastPlayedMusic; // The music file that was last played float mMasterVolume; @@ -74,7 +78,7 @@ namespace MWSound friend class OpenAL_Output; public: - SoundManager(bool useSound); + SoundManager(const VFS::Manager* vfs, bool useSound); virtual ~SoundManager(); virtual void processChangedSettings(const Settings::CategorySettingVector& settings);