From 4ebca98559c3f3b5bc98fb024e2474f63d544456 Mon Sep 17 00:00:00 2001 From: Nimetu Date: Fri, 17 Apr 2020 11:49:21 +0300 Subject: [PATCH] Fixed: Audio decoder getMusicInfo/getSongTitle needs to be thread safe --- nel/include/nel/sound/driver/sound_driver.h | 2 +- nel/src/sound/audio_decoder.cpp | 11 ++++----- .../sound/driver/fmod/sound_driver_fmod.cpp | 24 ++++--------------- nel/src/sound/driver/fmod/sound_driver_fmod.h | 2 +- 4 files changed, 11 insertions(+), 28 deletions(-) diff --git a/nel/include/nel/sound/driver/sound_driver.h b/nel/include/nel/sound/driver/sound_driver.h index 1fba9c887..9c758487a 100644 --- a/nel/include/nel/sound/driver/sound_driver.h +++ b/nel/include/nel/sound/driver/sound_driver.h @@ -191,7 +191,7 @@ public: /// Create a native music channel, only supported by the FMod driver. virtual IMusicChannel *createMusicChannel() { return NULL; } /** Get music info. Returns false if the song is not found or the function is not implemented. - * \param filepath path to file, CPath::lookup done by driver + * \param filepath full path to file * \param artist returns the song artist (empty if not available) * \param title returns the title (empty if not available) */ diff --git a/nel/src/sound/audio_decoder.cpp b/nel/src/sound/audio_decoder.cpp index a282942c4..db87bd990 100644 --- a/nel/src/sound/audio_decoder.cpp +++ b/nel/src/sound/audio_decoder.cpp @@ -110,10 +110,9 @@ IAudioDecoder *IAudioDecoder::createAudioDecoder(const std::string &type, NLMISC bool IAudioDecoder::getInfo(const std::string &filepath, std::string &artist, std::string &title, float &length) { - std::string lookup = CPath::lookup(filepath, false); - if (lookup.empty()) + if (filepath.empty() || !CFile::fileExists(filepath)) { - nlwarning("Music file %s does not exist!", filepath.c_str()); + nlwarning("Music file '%s' does not exist!", filepath.c_str()); return false; } @@ -121,7 +120,7 @@ bool IAudioDecoder::getInfo(const std::string &filepath, std::string &artist, st CIFile ifile; ifile.setCacheFileOnOpen(false); ifile.allowBNPCacheFileOnOpen(false); - if (ifile.open(lookup)) + if (ifile.open(filepath)) return CAudioDecoderFfmpeg::getInfo(&ifile, artist, title, length); #else std::string type = CFile::getExtension(filepath); @@ -132,7 +131,7 @@ bool IAudioDecoder::getInfo(const std::string &filepath, std::string &artist, st CIFile ifile; ifile.setCacheFileOnOpen(false); ifile.allowBNPCacheFileOnOpen(false); - if (ifile.open(lookup)) + if (ifile.open(filepath)) return CAudioDecoderVorbis::getInfo(&ifile, artist, title, length); nlwarning("Unable to open: '%s'", filepath.c_str()); @@ -143,7 +142,7 @@ bool IAudioDecoder::getInfo(const std::string &filepath, std::string &artist, st CIFile ifile; ifile.setCacheFileOnOpen(false); ifile.allowBNPCacheFileOnOpen(false); - if (ifile.open(lookup)) + if (ifile.open(filepath)) return CAudioDecoderMP3::getInfo(&ifile, artist, title, length); nlwarning("Unable to open: '%s'", filepath.c_str()); diff --git a/nel/src/sound/driver/fmod/sound_driver_fmod.cpp b/nel/src/sound/driver/fmod/sound_driver_fmod.cpp index d98aa600f..2b250a1d3 100644 --- a/nel/src/sound/driver/fmod/sound_driver_fmod.cpp +++ b/nel/src/sound/driver/fmod/sound_driver_fmod.cpp @@ -496,36 +496,20 @@ bool getTag (std::string &result, const char *tag, FSOUND_STREAM *stream) } /** Get music info. Returns false if the song is not found or the function is not implemented. - * \param filepath path to file, CPath::lookup done by driver + * \param filepath full path to file * \param artist returns the song artist (empty if not available) * \param title returns the title (empty if not available) */ bool CSoundDriverFMod::getMusicInfo(const std::string &filepath, std::string &artist, std::string &title, float &length) { - /* Open a stream, get the tag if it exists, close the stream */ - string pathName = CPath::lookup(filepath, false); - uint32 fileOffset = 0, fileSize = 0; - if (pathName.empty()) + if (filepath.empty() || !CFile::fileExists(filepath)) { nlwarning("NLSOUND FMod Driver: Music file %s not found!", filepath.c_str()); return false; } - // if the file is in a bnp - if (pathName.find('@') != string::npos) - { - if (CBigFile::getInstance().getFileInfo(pathName, fileSize, fileOffset)) - { - // set pathname to bnp - pathName = pathName.substr(0, pathName.find('@')); - } - else - { - nlwarning("NLSOUND FMod Driver: BNP BROKEN"); - return false; - } - } - FSOUND_STREAM *stream = FSOUND_Stream_Open((const char *)CPath::lookup(filepath, false).c_str(), FSOUND_2D, (sint)fileOffset, (sint)fileSize); + uint32 fileOffset = 0, fileSize = 0; + FSOUND_STREAM *stream = FSOUND_Stream_Open(filepath.c_str(), FSOUND_2D, (sint)fileOffset, (sint)fileSize); if (stream) { getTag(artist, "ARTIST", stream); diff --git a/nel/src/sound/driver/fmod/sound_driver_fmod.h b/nel/src/sound/driver/fmod/sound_driver_fmod.h index db82cde6e..73d3b8673 100644 --- a/nel/src/sound/driver/fmod/sound_driver_fmod.h +++ b/nel/src/sound/driver/fmod/sound_driver_fmod.h @@ -112,7 +112,7 @@ public: virtual IMusicChannel *createMusicChannel(); /** Get music info. Returns false if the song is not found or the function is not implemented. - * \param filepath path to file, CPath::lookup done by driver + * \param filepath full path to file * \param artist returns the song artist (empty if not available) * \param title returns the title (empty if not available) */