2014-09-29 10:15:41 +08:00
|
|
|
/****************************************************************************
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2014-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2019-11-24 14:54:45 +08:00
|
|
|
Copyright (c) 2018-2020 HALX99.
|
2016-12-29 10:05:13 +08:00
|
|
|
|
2014-09-29 10:15:41 +08:00
|
|
|
http://www.cocos2d-x.org
|
2016-12-29 10:05:13 +08:00
|
|
|
|
2014-09-29 10:15:41 +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:
|
2016-12-29 10:05:13 +08:00
|
|
|
|
2014-09-29 10:15:41 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2016-12-29 10:05:13 +08:00
|
|
|
|
2014-09-29 10:15:41 +08:00
|
|
|
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.
|
|
|
|
****************************************************************************/
|
2016-08-04 09:53:30 +08:00
|
|
|
|
|
|
|
#define LOG_TAG "AudioCache"
|
|
|
|
|
2014-09-30 09:57:28 +08:00
|
|
|
#include "platform/CCPlatformConfig.h"
|
|
|
|
|
2019-11-24 14:54:45 +08:00
|
|
|
#include "audio/include/AudioCache.h"
|
2014-09-29 10:15:41 +08:00
|
|
|
#include <thread>
|
2015-07-28 15:27:07 +08:00
|
|
|
#include "base/CCDirector.h"
|
|
|
|
#include "base/CCScheduler.h"
|
2014-09-29 10:15:41 +08:00
|
|
|
|
2019-11-24 14:54:45 +08:00
|
|
|
#include "audio/include/AudioDecoderManager.h"
|
|
|
|
#include "audio/include/AudioDecoder.h"
|
2016-08-04 09:53:30 +08:00
|
|
|
|
2016-12-29 10:05:13 +08:00
|
|
|
#define VERY_VERY_VERBOSE_LOGGING
|
|
|
|
#ifdef VERY_VERY_VERBOSE_LOGGING
|
|
|
|
#define ALOGVV ALOGV
|
|
|
|
#else
|
|
|
|
#define ALOGVV(...) do{} while(false)
|
|
|
|
#endif
|
2016-08-04 09:53:30 +08:00
|
|
|
|
2016-12-29 10:05:13 +08:00
|
|
|
namespace {
|
|
|
|
unsigned int __idIndex = 0;
|
2016-08-04 09:53:30 +08:00
|
|
|
}
|
|
|
|
|
2016-12-29 10:05:13 +08:00
|
|
|
#define INVALID_AL_BUFFER_ID 0xFFFFFFFF
|
|
|
|
#define PCMDATA_CACHEMAXSIZE 1048576
|
|
|
|
|
|
|
|
using namespace cocos2d;
|
2016-08-04 09:53:30 +08:00
|
|
|
|
2014-09-29 10:15:41 +08:00
|
|
|
AudioCache::AudioCache()
|
2016-12-29 10:05:13 +08:00
|
|
|
: _totalFrames(0)
|
|
|
|
, _framesRead(0)
|
|
|
|
, _format(-1)
|
|
|
|
, _duration(0.0f)
|
|
|
|
, _alBufferId(INVALID_AL_BUFFER_ID)
|
|
|
|
, _pcmData(nullptr)
|
2014-09-29 10:15:41 +08:00
|
|
|
, _queBufferFrames(0)
|
2016-12-29 10:05:13 +08:00
|
|
|
, _state(State::INITIAL)
|
|
|
|
, _isDestroyed(std::make_shared<bool>(false))
|
|
|
|
, _id(++__idIndex)
|
|
|
|
, _isLoadingFinished(false)
|
|
|
|
, _isSkipReadDataTask(false)
|
2014-09-29 10:15:41 +08:00
|
|
|
{
|
2016-12-29 10:05:13 +08:00
|
|
|
ALOGVV("AudioCache() %p, id=%u", this, _id);
|
|
|
|
for (int i = 0; i < QUEUEBUFFER_NUM; ++i)
|
|
|
|
{
|
|
|
|
_queBuffers[i] = nullptr;
|
|
|
|
_queBufferSize[i] = 0;
|
|
|
|
}
|
2014-09-29 10:15:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
AudioCache::~AudioCache()
|
|
|
|
{
|
2016-12-29 10:05:13 +08:00
|
|
|
ALOGVV("~AudioCache() %p, id=%u, begin", this, _id);
|
|
|
|
*_isDestroyed = true;
|
|
|
|
while (!_isLoadingFinished)
|
|
|
|
{
|
|
|
|
if (_isSkipReadDataTask)
|
|
|
|
{
|
|
|
|
ALOGV("id=%u, Skip read data task, don't continue to wait!", _id);
|
|
|
|
break;
|
2014-09-29 10:15:41 +08:00
|
|
|
}
|
2016-12-29 10:05:13 +08:00
|
|
|
ALOGVV("id=%u, waiting readData thread to finish ...", _id);
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(5));
|
|
|
|
}
|
|
|
|
//wait for the 'readDataTask' task to exit
|
|
|
|
_readDataTaskMutex.lock();
|
|
|
|
_readDataTaskMutex.unlock();
|
|
|
|
|
|
|
|
if (_pcmData)
|
|
|
|
{
|
|
|
|
if (_state == State::READY)
|
|
|
|
{
|
|
|
|
if (_alBufferId != INVALID_AL_BUFFER_ID && alIsBuffer(_alBufferId))
|
|
|
|
{
|
|
|
|
ALOGV("~AudioCache(id=%u), delete buffer: %u", _id, _alBufferId);
|
|
|
|
alDeleteBuffers(1, &_alBufferId);
|
|
|
|
_alBufferId = INVALID_AL_BUFFER_ID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-24 14:54:45 +08:00
|
|
|
ALOGW("AudioCache (%p), id=%u, buffer isn't ready, state=%d", this, _id, (int)_state);
|
2016-12-29 10:05:13 +08:00
|
|
|
}
|
|
|
|
|
2014-09-29 10:15:41 +08:00
|
|
|
free(_pcmData);
|
|
|
|
}
|
|
|
|
|
2016-12-29 10:05:13 +08:00
|
|
|
if (_queBufferFrames > 0)
|
|
|
|
{
|
|
|
|
for (int index = 0; index < QUEUEBUFFER_NUM; ++index)
|
|
|
|
{
|
2014-09-29 10:15:41 +08:00
|
|
|
free(_queBuffers[index]);
|
|
|
|
}
|
|
|
|
}
|
2016-12-29 10:05:13 +08:00
|
|
|
ALOGVV("~AudioCache() %p, id=%u, end", this, _id);
|
2014-09-29 10:15:41 +08:00
|
|
|
}
|
|
|
|
|
2016-12-29 10:05:13 +08:00
|
|
|
void AudioCache::readDataTask(unsigned int selfId)
|
2014-09-29 10:15:41 +08:00
|
|
|
{
|
2016-12-29 10:05:13 +08:00
|
|
|
//Note: It's in sub thread
|
|
|
|
ALOGVV("readDataTask begin, cache id=%u", selfId);
|
|
|
|
|
2014-09-29 10:15:41 +08:00
|
|
|
_readDataTaskMutex.lock();
|
2016-12-29 10:05:13 +08:00
|
|
|
_state = State::LOADING;
|
2014-09-29 10:15:41 +08:00
|
|
|
|
2020-05-18 14:56:13 +08:00
|
|
|
AudioDecoder* decoder = AudioDecoderManager::createDecoder(_fileFullPath);
|
2016-12-29 10:05:13 +08:00
|
|
|
do
|
2014-09-29 10:15:41 +08:00
|
|
|
{
|
2020-05-18 14:56:13 +08:00
|
|
|
if (decoder == nullptr || !decoder->open(_fileFullPath))
|
2016-12-29 10:05:13 +08:00
|
|
|
break;
|
2014-09-29 10:15:41 +08:00
|
|
|
|
2016-12-29 10:05:13 +08:00
|
|
|
const uint32_t originalTotalFrames = decoder->getTotalFrames();
|
|
|
|
const uint32_t sampleRate = decoder->getSampleRate();
|
|
|
|
const uint32_t channelCount = decoder->getChannelCount();
|
2020-05-18 17:30:42 +08:00
|
|
|
const auto sourceFormat = decoder->getSourceFormat();
|
2016-12-29 10:05:13 +08:00
|
|
|
|
|
|
|
uint32_t totalFrames = originalTotalFrames;
|
2020-06-03 23:09:45 +08:00
|
|
|
uint32_t dataSize = decoder->framesToBytes(totalFrames);
|
2016-12-29 10:05:13 +08:00
|
|
|
uint32_t remainingFrames = totalFrames;
|
|
|
|
|
2020-05-18 17:30:42 +08:00
|
|
|
switch (sourceFormat) {
|
|
|
|
case AUDIO_SOURCE_FORMAT::PCM_U8:
|
2020-05-17 17:15:10 +08:00
|
|
|
_format = channelCount > 1 ? AL_FORMAT_STEREO8 : AL_FORMAT_MONO8; // bits depth: 8bits
|
2020-05-18 14:56:13 +08:00
|
|
|
break;
|
2020-06-04 12:26:25 +08:00
|
|
|
case AUDIO_SOURCE_FORMAT::PCM_16:
|
|
|
|
_format = channelCount > 1 ? AL_FORMAT_STEREO16 : AL_FORMAT_MONO16; // bits depth: 16bits
|
|
|
|
break;
|
2020-05-18 17:30:42 +08:00
|
|
|
case AUDIO_SOURCE_FORMAT::PCM_FLT32:
|
2020-05-18 14:56:13 +08:00
|
|
|
_format = channelCount > 1 ? AL_FORMAT_STEREO_FLOAT32 : AL_FORMAT_MONO_FLOAT32;
|
|
|
|
break;
|
2020-05-18 17:30:42 +08:00
|
|
|
case AUDIO_SOURCE_FORMAT::PCM_FLT64:
|
2020-05-18 14:56:13 +08:00
|
|
|
_format = channelCount > 1 ? AL_FORMAT_STEREO_DOUBLE_EXT : AL_FORMAT_MONO_DOUBLE_EXT;
|
|
|
|
break;
|
2020-05-18 17:30:42 +08:00
|
|
|
case AUDIO_SOURCE_FORMAT::MULAW:
|
|
|
|
_format = channelCount > 1 ? AL_FORMAT_STEREO_MULAW_EXT : AL_FORMAT_MONO_MULAW_EXT;
|
|
|
|
break;
|
|
|
|
case AUDIO_SOURCE_FORMAT::ALAW:
|
|
|
|
_format = channelCount > 1 ? AL_FORMAT_STEREO_ALAW_EXT : AL_FORMAT_MONO_ALAW_EXT;
|
|
|
|
break;
|
|
|
|
case AUDIO_SOURCE_FORMAT::ADPCM:
|
2020-06-02 12:18:12 +08:00
|
|
|
_format = channelCount > 1 ? AL_FORMAT_STEREO_MSADPCM_SOFT : AL_FORMAT_MONO_MSADPCM_SOFT;
|
2020-05-18 17:30:42 +08:00
|
|
|
break;
|
|
|
|
case AUDIO_SOURCE_FORMAT::IMA_ADPCM:
|
2020-06-04 12:26:25 +08:00
|
|
|
_format = channelCount > 1 ? AL_FORMAT_STEREO_IMA4 : AL_FORMAT_MONO_IMA4;
|
2020-05-18 17:30:42 +08:00
|
|
|
break;
|
2020-05-18 14:56:13 +08:00
|
|
|
default: assert(false);
|
|
|
|
}
|
2020-06-04 12:26:25 +08:00
|
|
|
|
2016-12-29 10:05:13 +08:00
|
|
|
_sampleRate = (ALsizei)sampleRate;
|
|
|
|
_duration = 1.0f * totalFrames / sampleRate;
|
|
|
|
_totalFrames = totalFrames;
|
|
|
|
|
|
|
|
if (dataSize <= PCMDATA_CACHEMAXSIZE)
|
2014-09-29 10:15:41 +08:00
|
|
|
{
|
2016-12-29 10:05:13 +08:00
|
|
|
uint32_t framesRead = 0;
|
2020-06-02 12:09:51 +08:00
|
|
|
uint32_t framesToReadOnce = (std::min)(totalFrames, static_cast<uint32_t>(sampleRate * QUEUEBUFFER_TIME_STEP * QUEUEBUFFER_NUM));
|
2020-06-03 23:09:45 +08:00
|
|
|
|
2016-12-29 10:05:13 +08:00
|
|
|
_pcmData = (char*)malloc(dataSize);
|
|
|
|
memset(_pcmData, 0x00, dataSize);
|
|
|
|
|
|
|
|
alGenBuffers(1, &_alBufferId);
|
|
|
|
auto alError = alGetError();
|
|
|
|
if (alError != AL_NO_ERROR) {
|
|
|
|
ALOGE("%s: attaching audio to buffer fail: %x", __FUNCTION__, alError);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*_isDestroyed)
|
2014-09-29 10:15:41 +08:00
|
|
|
break;
|
2016-12-29 10:05:13 +08:00
|
|
|
|
2020-06-03 23:09:45 +08:00
|
|
|
framesRead = decoder->readFixedFrames((std::min)(framesToReadOnce, remainingFrames), _pcmData + decoder->framesToBytes(_framesRead));
|
2016-12-29 10:05:13 +08:00
|
|
|
_framesRead += framesRead;
|
|
|
|
remainingFrames -= framesRead;
|
|
|
|
|
|
|
|
if (*_isDestroyed)
|
|
|
|
break;
|
|
|
|
|
|
|
|
uint32_t frames = 0;
|
|
|
|
while (!*_isDestroyed && _framesRead < originalTotalFrames)
|
|
|
|
{
|
2019-11-24 14:54:45 +08:00
|
|
|
frames = (std::min)(framesToReadOnce, remainingFrames);
|
2016-12-29 10:05:13 +08:00
|
|
|
if (_framesRead + frames > originalTotalFrames)
|
2014-09-29 10:15:41 +08:00
|
|
|
{
|
2016-12-29 10:05:13 +08:00
|
|
|
frames = originalTotalFrames - _framesRead;
|
2014-09-29 10:15:41 +08:00
|
|
|
}
|
2020-06-03 23:09:45 +08:00
|
|
|
framesRead = decoder->read(frames, _pcmData + decoder->framesToBytes(_framesRead));
|
2016-12-29 10:05:13 +08:00
|
|
|
if (framesRead == 0)
|
|
|
|
break;
|
|
|
|
_framesRead += framesRead;
|
|
|
|
remainingFrames -= framesRead;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*_isDestroyed)
|
2014-09-29 10:15:41 +08:00
|
|
|
break;
|
2016-12-29 10:05:13 +08:00
|
|
|
|
|
|
|
if (_framesRead < originalTotalFrames)
|
|
|
|
{
|
2020-06-03 23:09:45 +08:00
|
|
|
memset(_pcmData + decoder->framesToBytes(_framesRead), 0x00, decoder->framesToBytes(totalFrames - _framesRead));
|
2016-12-29 10:05:13 +08:00
|
|
|
}
|
2020-06-03 23:09:45 +08:00
|
|
|
ALOGV("pcm buffer was loaded successfully, total frames: %u, total read frames: %u, remainingFrames: %u", totalFrames, _framesRead, remainingFrames);
|
2016-12-29 10:05:13 +08:00
|
|
|
|
2020-06-04 12:26:25 +08:00
|
|
|
if(sourceFormat == AUDIO_SOURCE_FORMAT::ADPCM || sourceFormat == AUDIO_SOURCE_FORMAT::IMA_ADPCM)
|
|
|
|
alBufferi(_alBufferId, AL_UNPACK_BLOCK_ALIGNMENT_SOFT, decoder->getSamplesPerBlock());
|
2016-12-29 10:05:13 +08:00
|
|
|
alBufferData(_alBufferId, _format, _pcmData, (ALsizei)dataSize, (ALsizei)sampleRate);
|
|
|
|
|
2020-06-02 12:09:51 +08:00
|
|
|
alError = alGetError();
|
|
|
|
if (alError != AL_NO_ERROR)
|
|
|
|
{
|
|
|
|
ALOGE("%s:alBufferData error code:%x", __FUNCTION__, alError);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-12-29 10:05:13 +08:00
|
|
|
_state = State::READY;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-24 14:54:45 +08:00
|
|
|
_queBufferFrames = sampleRate * QUEUEBUFFER_TIME_STEP;
|
2016-12-29 10:05:13 +08:00
|
|
|
BREAK_IF_ERR_LOG(_queBufferFrames == 0, "_queBufferFrames == 0");
|
|
|
|
|
2020-06-03 23:09:45 +08:00
|
|
|
const uint32_t queBufferBytes = decoder->framesToBytes(_queBufferFrames);
|
2016-12-29 10:05:13 +08:00
|
|
|
|
|
|
|
for (int index = 0; index < QUEUEBUFFER_NUM; ++index)
|
|
|
|
{
|
|
|
|
_queBuffers[index] = (char*)malloc(queBufferBytes);
|
|
|
|
_queBufferSize[index] = queBufferBytes;
|
|
|
|
|
|
|
|
decoder->readFixedFrames(_queBufferFrames, _queBuffers[index]);
|
2014-09-29 10:15:41 +08:00
|
|
|
}
|
2016-12-29 10:05:13 +08:00
|
|
|
|
|
|
|
_state = State::READY;
|
2014-09-29 10:15:41 +08:00
|
|
|
}
|
2016-12-29 10:05:13 +08:00
|
|
|
|
|
|
|
} while (false);
|
|
|
|
|
|
|
|
if (decoder != nullptr)
|
|
|
|
{
|
|
|
|
decoder->close();
|
2014-09-29 10:15:41 +08:00
|
|
|
}
|
2016-12-29 10:05:13 +08:00
|
|
|
|
|
|
|
AudioDecoderManager::destroyDecoder(decoder);
|
|
|
|
|
|
|
|
if (_state != State::READY)
|
2014-09-29 10:15:41 +08:00
|
|
|
{
|
2016-12-29 10:05:13 +08:00
|
|
|
_state = State::FAILED;
|
|
|
|
if (_alBufferId != INVALID_AL_BUFFER_ID && alIsBuffer(_alBufferId))
|
|
|
|
{
|
|
|
|
ALOGV("readDataTask failed, delete buffer: %u", _alBufferId);
|
|
|
|
alDeleteBuffers(1, &_alBufferId);
|
|
|
|
_alBufferId = INVALID_AL_BUFFER_ID;
|
|
|
|
}
|
2014-09-29 10:15:41 +08:00
|
|
|
}
|
2016-12-29 10:05:13 +08:00
|
|
|
|
2020-07-30 17:26:54 +08:00
|
|
|
// Set before invokingPlayCallbacks, otherwise, may cause dead-lock
|
|
|
|
_isLoadingFinished = true;
|
|
|
|
|
2016-12-29 10:05:13 +08:00
|
|
|
//FIXME: Why to invoke play callback first? Should it be after 'load' callback?
|
|
|
|
invokingPlayCallbacks();
|
|
|
|
invokingLoadCallbacks();
|
|
|
|
|
2014-09-29 10:15:41 +08:00
|
|
|
_readDataTaskMutex.unlock();
|
2016-12-29 10:05:13 +08:00
|
|
|
ALOGVV("readDataTask end, cache id=%u", selfId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioCache::addPlayCallback(const std::function<void()>& callback)
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lk(_playCallbackMutex);
|
|
|
|
switch (_state)
|
2015-07-28 15:27:07 +08:00
|
|
|
{
|
2016-12-29 10:05:13 +08:00
|
|
|
case State::INITIAL:
|
|
|
|
case State::LOADING:
|
|
|
|
_playCallbacks.push_back(callback);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case State::READY:
|
|
|
|
// If state is failure, we still need to invoke the callback
|
|
|
|
// since the callback will set the 'AudioPlayer::_removeByAudioEngine' flag to true.
|
|
|
|
case State::FAILED:
|
|
|
|
callback();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2019-11-24 14:54:45 +08:00
|
|
|
ALOGE("Invalid state: %d", (int)_state);
|
2016-12-29 10:05:13 +08:00
|
|
|
break;
|
2015-07-28 15:27:07 +08:00
|
|
|
}
|
2014-09-29 10:15:41 +08:00
|
|
|
}
|
|
|
|
|
2015-07-28 15:27:07 +08:00
|
|
|
void AudioCache::invokingPlayCallbacks()
|
2014-09-29 10:15:41 +08:00
|
|
|
{
|
2016-12-29 10:05:13 +08:00
|
|
|
std::lock_guard<std::mutex> lk(_playCallbackMutex);
|
|
|
|
|
|
|
|
for (auto&& cb : _playCallbacks)
|
|
|
|
{
|
|
|
|
cb();
|
2014-09-29 10:15:41 +08:00
|
|
|
}
|
2016-12-29 10:05:13 +08:00
|
|
|
|
|
|
|
_playCallbacks.clear();
|
2014-09-29 10:15:41 +08:00
|
|
|
}
|
|
|
|
|
2016-12-29 10:05:13 +08:00
|
|
|
void AudioCache::addLoadCallback(const std::function<void(bool)>& callback)
|
2014-09-29 10:15:41 +08:00
|
|
|
{
|
2016-12-29 10:05:13 +08:00
|
|
|
switch (_state)
|
|
|
|
{
|
|
|
|
case State::INITIAL:
|
|
|
|
case State::LOADING:
|
|
|
|
_loadCallbacks.push_back(callback);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case State::READY:
|
|
|
|
callback(true);
|
|
|
|
break;
|
|
|
|
case State::FAILED:
|
|
|
|
callback(false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2019-11-24 14:54:45 +08:00
|
|
|
ALOGE("Invalid state: %d", (int)_state);
|
2016-12-29 10:05:13 +08:00
|
|
|
break;
|
2014-09-29 10:15:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-28 15:27:07 +08:00
|
|
|
void AudioCache::invokingLoadCallbacks()
|
|
|
|
{
|
2016-12-29 10:05:13 +08:00
|
|
|
if (*_isDestroyed)
|
|
|
|
{
|
|
|
|
ALOGV("AudioCache (%p) was destroyed, don't invoke preload callback ...", this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto isDestroyed = _isDestroyed;
|
2015-07-28 15:27:07 +08:00
|
|
|
auto scheduler = Director::getInstance()->getScheduler();
|
2016-12-29 10:05:13 +08:00
|
|
|
scheduler->performFunctionInCocosThread([&, isDestroyed](){
|
|
|
|
if (*isDestroyed)
|
|
|
|
{
|
|
|
|
ALOGV("invokingLoadCallbacks perform in cocos thread, AudioCache (%p) was destroyed!", this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto&& cb : _loadCallbacks)
|
|
|
|
{
|
|
|
|
cb(_state == State::READY);
|
2015-07-28 15:27:07 +08:00
|
|
|
}
|
2016-12-29 10:05:13 +08:00
|
|
|
|
2015-07-28 15:27:07 +08:00
|
|
|
_loadCallbacks.clear();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|