2022-01-03 11:42:07 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
|
|
|
Copyright (c) 2018-2020 HALX99.
|
|
|
|
Copyright (c) 2021 Bytedance Inc.
|
|
|
|
|
2022-10-01 16:24:52 +08:00
|
|
|
https://axmolengine.github.io/
|
2022-01-03 11:42:07 +08:00
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#define LOG_TAG "AudioDecoderManager"
|
|
|
|
|
|
|
|
#include "audio/AudioDecoderManager.h"
|
|
|
|
#include "audio/AudioDecoderOgg.h"
|
|
|
|
#include "audio/AudioMacros.h"
|
2023-06-11 13:08:08 +08:00
|
|
|
#include "platform/FileUtils.h"
|
|
|
|
#include "base/Console.h"
|
2022-01-03 11:42:07 +08:00
|
|
|
|
|
|
|
#if !defined(__APPLE__)
|
|
|
|
# include "audio/AudioDecoderMp3.h"
|
|
|
|
# include "audio/AudioDecoderWav.h"
|
|
|
|
#else
|
|
|
|
# include "audio/AudioDecoderEXT.h"
|
|
|
|
#endif
|
|
|
|
|
2023-01-04 23:20:07 +08:00
|
|
|
#include "yasio/stl/string_view.hpp"
|
2022-01-03 11:42:07 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BEGIN
|
2022-01-03 11:42:07 +08:00
|
|
|
|
|
|
|
bool AudioDecoderManager::init()
|
|
|
|
{
|
|
|
|
#if !defined(__APPLE__)
|
|
|
|
AudioDecoderMp3::lazyInit();
|
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioDecoderManager::destroy()
|
|
|
|
{
|
|
|
|
#if !defined(__APPLE__)
|
|
|
|
AudioDecoderMp3::destroy();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioDecoder* AudioDecoderManager::createDecoder(std::string_view path)
|
|
|
|
{
|
2023-01-04 23:06:52 +08:00
|
|
|
if (cxx20::ic::ends_with(path, ".ogg"))
|
2022-01-03 11:42:07 +08:00
|
|
|
{
|
|
|
|
return new AudioDecoderOgg();
|
|
|
|
}
|
|
|
|
#if !defined(__APPLE__)
|
2023-01-04 23:06:52 +08:00
|
|
|
else if (cxx20::ic::ends_with(path, ".mp3"))
|
2022-01-03 11:42:07 +08:00
|
|
|
{
|
|
|
|
return new AudioDecoderMp3();
|
|
|
|
}
|
2023-01-04 23:06:52 +08:00
|
|
|
else if (cxx20::ic::ends_with(path, ".wav"))
|
2022-01-03 11:42:07 +08:00
|
|
|
{
|
|
|
|
return new AudioDecoderWav();
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return new AudioDecoderEXT();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioDecoderManager::destroyDecoder(AudioDecoder* decoder)
|
|
|
|
{
|
|
|
|
if (decoder)
|
|
|
|
decoder->close();
|
|
|
|
delete decoder;
|
|
|
|
}
|
|
|
|
|
2022-08-29 20:51:22 +08:00
|
|
|
NS_AX_END // namespace ax
|