2014-09-03 18:19:21 +08:00
|
|
|
/****************************************************************************
|
2016-12-02 13:52:37 +08:00
|
|
|
Copyright (c) 2014-2016 Chukong Technologies Inc.
|
|
|
|
|
2014-09-03 18:19:21 +08:00
|
|
|
http://www.cocos2d-x.org
|
2016-12-02 13:52:37 +08:00
|
|
|
|
2014-09-03 18:19:21 +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-02 13:52:37 +08:00
|
|
|
|
2014-09-03 18:19:21 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2016-12-02 13:52:37 +08:00
|
|
|
|
2014-09-03 18:19:21 +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.
|
|
|
|
****************************************************************************/
|
2014-09-30 01:07:11 +08:00
|
|
|
|
2016-07-21 14:57:59 +08:00
|
|
|
#define LOG_TAG "AudioCache"
|
|
|
|
|
2014-09-30 01:07:11 +08:00
|
|
|
#include "platform/CCPlatformConfig.h"
|
2014-09-22 15:38:12 +08:00
|
|
|
#if CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC
|
2014-09-30 01:07:11 +08:00
|
|
|
|
2016-03-21 11:02:00 +08:00
|
|
|
#include "audio/apple/AudioCache.h"
|
2014-09-30 01:07:11 +08:00
|
|
|
|
|
|
|
#import <Foundation/Foundation.h>
|
2014-09-03 18:19:21 +08:00
|
|
|
#import <OpenAL/alc.h>
|
2014-09-30 01:07:11 +08:00
|
|
|
#include <thread>
|
2015-07-28 15:27:07 +08:00
|
|
|
#include "base/CCDirector.h"
|
|
|
|
#include "base/CCScheduler.h"
|
2014-09-03 18:19:21 +08:00
|
|
|
|
2016-12-02 13:52:37 +08:00
|
|
|
#include "audio/apple/AudioDecoder.h"
|
|
|
|
|
2016-07-21 14:57:59 +08:00
|
|
|
#define VERY_VERY_VERBOSE_LOGGING
|
|
|
|
#ifdef VERY_VERY_VERBOSE_LOGGING
|
|
|
|
#define ALOGVV ALOGV
|
|
|
|
#else
|
|
|
|
#define ALOGVV(...) do{} while(false)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
unsigned int __idIndex = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define INVALID_AL_BUFFER_ID 0xFFFFFFFF
|
2014-09-10 17:12:46 +08:00
|
|
|
#define PCMDATA_CACHEMAXSIZE 1048576
|
2014-09-03 18:19:21 +08:00
|
|
|
|
|
|
|
typedef ALvoid AL_APIENTRY (*alBufferDataStaticProcPtr) (const ALint bid, ALenum format, ALvoid* data, ALsizei size, ALsizei freq);
|
2014-09-10 17:12:46 +08:00
|
|
|
static ALvoid alBufferDataStaticProc(const ALint bid, ALenum format, ALvoid* data, ALsizei size, ALsizei freq)
|
2014-09-03 18:19:21 +08:00
|
|
|
{
|
2016-06-23 11:39:23 +08:00
|
|
|
static alBufferDataStaticProcPtr proc = nullptr;
|
2016-12-02 13:52:37 +08:00
|
|
|
|
2016-06-23 11:39:23 +08:00
|
|
|
if (proc == nullptr) {
|
|
|
|
proc = (alBufferDataStaticProcPtr) alcGetProcAddress(nullptr, (const ALCchar*) "alBufferDataStatic");
|
2014-09-03 18:19:21 +08:00
|
|
|
}
|
2016-12-02 13:52:37 +08:00
|
|
|
|
2014-09-10 17:12:46 +08:00
|
|
|
if (proc){
|
2014-09-03 18:19:21 +08:00
|
|
|
proc(bid, format, data, size, freq);
|
2014-09-10 17:12:46 +08:00
|
|
|
}
|
2016-12-02 13:52:37 +08:00
|
|
|
|
2014-09-03 18:19:21 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
using namespace cocos2d;
|
2014-09-16 14:57:58 +08:00
|
|
|
using namespace cocos2d::experimental;
|
2014-09-03 18:19:21 +08:00
|
|
|
|
|
|
|
AudioCache::AudioCache()
|
2017-02-04 09:46:32 +08:00
|
|
|
: _format(-1)
|
2016-07-21 14:57:59 +08:00
|
|
|
, _duration(0.0f)
|
2017-02-04 09:46:32 +08:00
|
|
|
, _totalFrames(0)
|
|
|
|
, _framesRead(0)
|
2016-07-21 14:57:59 +08:00
|
|
|
, _alBufferId(INVALID_AL_BUFFER_ID)
|
2014-11-26 09:53:52 +08:00
|
|
|
, _pcmData(nullptr)
|
2014-09-03 18:19:21 +08:00
|
|
|
, _queBufferFrames(0)
|
2016-07-21 14:57:59 +08:00
|
|
|
, _state(State::INITIAL)
|
|
|
|
, _isDestroyed(std::make_shared<bool>(false))
|
|
|
|
, _id(++__idIndex)
|
|
|
|
, _isLoadingFinished(false)
|
|
|
|
, _isSkipReadDataTask(false)
|
2014-09-03 18:19:21 +08:00
|
|
|
{
|
2016-07-21 14:57:59 +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-03 18:19:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
AudioCache::~AudioCache()
|
|
|
|
{
|
2016-07-21 14:57:59 +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;
|
|
|
|
}
|
|
|
|
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();
|
2016-12-02 13:52:37 +08:00
|
|
|
|
2016-07-21 14:57:59 +08:00
|
|
|
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
|
|
|
|
{
|
|
|
|
ALOGW("AudioCache (%p), id=%u, buffer isn't ready, state=%d", this, _id, _state);
|
2014-09-11 10:53:01 +08:00
|
|
|
}
|
2016-12-02 13:52:37 +08:00
|
|
|
|
2014-09-03 18:19:21 +08:00
|
|
|
free(_pcmData);
|
|
|
|
}
|
2016-12-02 13:52:37 +08:00
|
|
|
|
2016-07-21 14:57:59 +08:00
|
|
|
if (_queBufferFrames > 0)
|
|
|
|
{
|
|
|
|
for (int index = 0; index < QUEUEBUFFER_NUM; ++index)
|
|
|
|
{
|
2014-09-03 18:19:21 +08:00
|
|
|
free(_queBuffers[index]);
|
|
|
|
}
|
|
|
|
}
|
2016-07-21 14:57:59 +08:00
|
|
|
ALOGVV("~AudioCache() %p, id=%u, end", this, _id);
|
2014-09-03 18:19:21 +08:00
|
|
|
}
|
|
|
|
|
2016-07-21 14:57:59 +08:00
|
|
|
void AudioCache::readDataTask(unsigned int selfId)
|
2014-09-03 18:19:21 +08:00
|
|
|
{
|
2016-07-21 14:57:59 +08:00
|
|
|
//Note: It's in sub thread
|
|
|
|
ALOGVV("readDataTask, cache id=%u", selfId);
|
2016-12-02 13:52:37 +08:00
|
|
|
|
2016-07-21 14:57:59 +08:00
|
|
|
_readDataTaskMutex.lock();
|
|
|
|
_state = State::LOADING;
|
2016-12-02 13:52:37 +08:00
|
|
|
|
|
|
|
AudioDecoder decoder;
|
2016-07-21 14:57:59 +08:00
|
|
|
do
|
|
|
|
{
|
2016-12-02 13:52:37 +08:00
|
|
|
if (!decoder.open(_fileFullPath.c_str()))
|
2016-07-21 14:57:59 +08:00
|
|
|
break;
|
2016-12-02 13:52:37 +08:00
|
|
|
|
|
|
|
const uint32_t originalTotalFrames = decoder.getTotalFrames();
|
|
|
|
const uint32_t bytesPerFrame = decoder.getBytesPerFrame();
|
|
|
|
const uint32_t sampleRate = decoder.getSampleRate();
|
|
|
|
const uint32_t channelCount = decoder.getChannelCount();
|
|
|
|
|
|
|
|
uint32_t totalFrames = originalTotalFrames;
|
|
|
|
uint32_t dataSize = totalFrames * bytesPerFrame;
|
|
|
|
uint32_t remainingFrames = totalFrames;
|
|
|
|
uint32_t adjustFrames = 0;
|
|
|
|
|
|
|
|
_format = channelCount > 1 ? AL_FORMAT_STEREO16 : AL_FORMAT_MONO16;
|
|
|
|
_sampleRate = (ALsizei)sampleRate;
|
|
|
|
_duration = 1.0f * totalFrames / sampleRate;
|
|
|
|
_totalFrames = totalFrames;
|
|
|
|
|
|
|
|
if (dataSize <= PCMDATA_CACHEMAXSIZE)
|
2016-07-21 14:57:59 +08:00
|
|
|
{
|
2016-12-02 13:52:37 +08:00
|
|
|
uint32_t framesRead = 0;
|
|
|
|
const uint32_t framesToReadOnce = std::min(totalFrames, static_cast<uint32_t>(sampleRate * QUEUEBUFFER_TIME_STEP * QUEUEBUFFER_NUM));
|
|
|
|
|
|
|
|
BREAK_IF_ERR_LOG(!decoder.seek(totalFrames), "AudioDecoder::seek(%u) error", totalFrames);
|
|
|
|
|
|
|
|
char* tmpBuf = (char*)malloc(framesToReadOnce * bytesPerFrame);
|
|
|
|
std::vector<char> adjustFrameBuf;
|
|
|
|
adjustFrameBuf.reserve(framesToReadOnce * bytesPerFrame);
|
|
|
|
|
2016-12-15 09:58:47 +08:00
|
|
|
// Adjust total frames by setting position to the end of frames and try to read more data.
|
|
|
|
// This is a workaround for https://github.com/cocos2d/cocos2d-x/issues/16938
|
2016-12-02 13:52:37 +08:00
|
|
|
do
|
|
|
|
{
|
|
|
|
framesRead = decoder.read(framesToReadOnce, tmpBuf);
|
|
|
|
if (framesRead > 0)
|
|
|
|
{
|
|
|
|
adjustFrames += framesRead;
|
|
|
|
adjustFrameBuf.insert(adjustFrameBuf.end(), tmpBuf, tmpBuf + framesRead * bytesPerFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
} while (framesRead > 0);
|
|
|
|
|
|
|
|
if (adjustFrames > 0)
|
|
|
|
{
|
|
|
|
ALOGV("Orignal total frames: %u, adjust frames: %u, current total frames: %u", totalFrames, adjustFrames, totalFrames + adjustFrames);
|
|
|
|
totalFrames += adjustFrames;
|
|
|
|
_totalFrames = remainingFrames = totalFrames;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset dataSize
|
|
|
|
dataSize = totalFrames * bytesPerFrame;
|
|
|
|
|
|
|
|
free(tmpBuf);
|
|
|
|
|
|
|
|
// Reset to frame 0
|
|
|
|
BREAK_IF_ERR_LOG(!decoder.seek(0), "AudioDecoder::seek(0) failed!");
|
|
|
|
|
|
|
|
_pcmData = (char*)malloc(dataSize);
|
2016-12-15 09:58:47 +08:00
|
|
|
memset(_pcmData, 0x00, dataSize);
|
2016-12-02 13:52:37 +08:00
|
|
|
|
|
|
|
if (adjustFrames > 0)
|
|
|
|
{
|
|
|
|
memcpy(_pcmData + (dataSize - adjustFrameBuf.size()), adjustFrameBuf.data(), adjustFrameBuf.size());
|
|
|
|
}
|
|
|
|
|
2016-07-21 14:57:59 +08:00
|
|
|
alGenBuffers(1, &_alBufferId);
|
|
|
|
auto alError = alGetError();
|
|
|
|
if (alError != AL_NO_ERROR) {
|
|
|
|
ALOGE("%s: attaching audio to buffer fail: %x", __PRETTY_FUNCTION__, alError);
|
|
|
|
break;
|
|
|
|
}
|
2016-12-02 13:52:37 +08:00
|
|
|
|
|
|
|
if (*_isDestroyed)
|
|
|
|
break;
|
|
|
|
|
|
|
|
alBufferDataStaticProc(_alBufferId, _format, _pcmData, (ALsizei)dataSize, (ALsizei)sampleRate);
|
|
|
|
|
2016-12-15 09:58:47 +08:00
|
|
|
framesRead = decoder.readFixedFrames(std::min(framesToReadOnce, remainingFrames), _pcmData + _framesRead * bytesPerFrame);
|
|
|
|
_framesRead += framesRead;
|
|
|
|
remainingFrames -= framesRead;
|
2016-12-02 13:52:37 +08:00
|
|
|
|
|
|
|
if (*_isDestroyed)
|
|
|
|
break;
|
|
|
|
|
2016-07-21 14:57:59 +08:00
|
|
|
_state = State::READY;
|
2016-12-02 13:52:37 +08:00
|
|
|
|
2016-07-21 14:57:59 +08:00
|
|
|
invokingPlayCallbacks();
|
2016-12-02 13:52:37 +08:00
|
|
|
|
|
|
|
uint32_t frames = 0;
|
|
|
|
while (!*_isDestroyed && _framesRead < originalTotalFrames)
|
|
|
|
{
|
|
|
|
frames = std::min(framesToReadOnce, remainingFrames);
|
|
|
|
if (_framesRead + frames > originalTotalFrames)
|
|
|
|
{
|
|
|
|
frames = originalTotalFrames - _framesRead;
|
|
|
|
}
|
|
|
|
framesRead = decoder.read(frames, _pcmData + _framesRead * bytesPerFrame);
|
|
|
|
if (framesRead == 0)
|
|
|
|
break;
|
|
|
|
_framesRead += framesRead;
|
|
|
|
remainingFrames -= framesRead;
|
2016-07-21 14:57:59 +08:00
|
|
|
}
|
2016-12-02 13:52:37 +08:00
|
|
|
|
2016-12-15 09:58:47 +08:00
|
|
|
if (_framesRead < originalTotalFrames)
|
|
|
|
{
|
|
|
|
memset(_pcmData + _framesRead * bytesPerFrame, 0x00, (totalFrames - _framesRead) * bytesPerFrame);
|
|
|
|
}
|
2016-12-02 13:52:37 +08:00
|
|
|
ALOGV("pcm buffer was loaded successfully, total frames: %u, total read frames: %u, adjust frames: %u, remainingFrames: %u", totalFrames, _framesRead, adjustFrames, remainingFrames);
|
|
|
|
|
|
|
|
_framesRead += adjustFrames;
|
2014-09-03 18:19:21 +08:00
|
|
|
}
|
2016-07-21 14:57:59 +08:00
|
|
|
else
|
|
|
|
{
|
2016-12-02 13:52:37 +08:00
|
|
|
_queBufferFrames = sampleRate * QUEUEBUFFER_TIME_STEP;
|
|
|
|
BREAK_IF_ERR_LOG(_queBufferFrames == 0, "_queBufferFrames == 0");
|
|
|
|
|
|
|
|
const uint32_t queBufferBytes = _queBufferFrames * bytesPerFrame;
|
|
|
|
|
|
|
|
for (int index = 0; index < QUEUEBUFFER_NUM; ++index)
|
|
|
|
{
|
|
|
|
_queBuffers[index] = (char*)malloc(queBufferBytes);
|
|
|
|
_queBufferSize[index] = queBufferBytes;
|
|
|
|
|
2016-12-15 09:58:47 +08:00
|
|
|
decoder.readFixedFrames(_queBufferFrames, _queBuffers[index]);
|
2016-07-21 14:57:59 +08:00
|
|
|
}
|
2016-12-02 13:52:37 +08:00
|
|
|
|
2016-07-21 14:57:59 +08:00
|
|
|
_state = State::READY;
|
|
|
|
}
|
2016-12-02 13:52:37 +08:00
|
|
|
|
2016-07-21 14:57:59 +08:00
|
|
|
} while (false);
|
2016-12-02 13:52:37 +08:00
|
|
|
|
|
|
|
decoder.close();
|
|
|
|
|
2016-07-21 14:57:59 +08:00
|
|
|
//FIXME: Why to invoke play callback first? Should it be after 'load' callback?
|
2015-07-28 15:27:07 +08:00
|
|
|
invokingPlayCallbacks();
|
|
|
|
invokingLoadCallbacks();
|
2016-12-02 13:52:37 +08:00
|
|
|
|
2016-07-21 14:57:59 +08:00
|
|
|
_isLoadingFinished = true;
|
|
|
|
if (_state != State::READY)
|
|
|
|
{
|
|
|
|
_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;
|
|
|
|
}
|
|
|
|
}
|
2016-12-02 13:52:37 +08:00
|
|
|
|
2016-07-21 14:57:59 +08:00
|
|
|
_readDataTaskMutex.unlock();
|
2015-07-28 15:27:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AudioCache::addPlayCallback(const std::function<void()>& callback)
|
|
|
|
{
|
2016-07-21 14:57:59 +08:00
|
|
|
std::lock_guard<std::mutex> lk(_playCallbackMutex);
|
|
|
|
switch (_state)
|
|
|
|
{
|
|
|
|
case State::INITIAL:
|
|
|
|
case State::LOADING:
|
|
|
|
_playCallbacks.push_back(callback);
|
|
|
|
break;
|
2016-12-02 13:52:37 +08:00
|
|
|
|
2016-07-21 14:57:59 +08:00
|
|
|
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;
|
2016-12-02 13:52:37 +08:00
|
|
|
|
2016-07-21 14:57:59 +08:00
|
|
|
default:
|
|
|
|
ALOGE("Invalid state: %d", _state);
|
|
|
|
break;
|
2015-07-28 15:27:07 +08:00
|
|
|
}
|
2014-09-03 18:19:21 +08:00
|
|
|
}
|
|
|
|
|
2015-07-28 15:27:07 +08:00
|
|
|
void AudioCache::invokingPlayCallbacks()
|
2014-09-03 18:19:21 +08:00
|
|
|
{
|
2016-07-21 14:57:59 +08:00
|
|
|
std::lock_guard<std::mutex> lk(_playCallbackMutex);
|
2016-12-02 13:52:37 +08:00
|
|
|
|
2016-07-21 14:57:59 +08:00
|
|
|
for (auto&& cb : _playCallbacks)
|
|
|
|
{
|
|
|
|
cb();
|
2014-09-03 18:19:21 +08:00
|
|
|
}
|
2016-12-02 13:52:37 +08:00
|
|
|
|
2016-07-21 14:57:59 +08:00
|
|
|
_playCallbacks.clear();
|
2014-09-03 18:19:21 +08:00
|
|
|
}
|
|
|
|
|
2015-07-28 15:27:07 +08:00
|
|
|
void AudioCache::addLoadCallback(const std::function<void(bool)>& callback)
|
2014-09-03 18:19:21 +08:00
|
|
|
{
|
2016-07-21 14:57:59 +08:00
|
|
|
switch (_state)
|
|
|
|
{
|
|
|
|
case State::INITIAL:
|
|
|
|
case State::LOADING:
|
|
|
|
_loadCallbacks.push_back(callback);
|
|
|
|
break;
|
2016-12-02 13:52:37 +08:00
|
|
|
|
2016-07-21 14:57:59 +08:00
|
|
|
case State::READY:
|
|
|
|
callback(true);
|
|
|
|
break;
|
|
|
|
case State::FAILED:
|
|
|
|
callback(false);
|
|
|
|
break;
|
2016-12-02 13:52:37 +08:00
|
|
|
|
2016-07-21 14:57:59 +08:00
|
|
|
default:
|
|
|
|
ALOGE("Invalid state: %d", _state);
|
|
|
|
break;
|
2015-07-28 15:27:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioCache::invokingLoadCallbacks()
|
|
|
|
{
|
2016-07-21 14:57:59 +08:00
|
|
|
if (*_isDestroyed)
|
|
|
|
{
|
|
|
|
ALOGV("AudioCache (%p) was destroyed, don't invoke preload callback ...", this);
|
|
|
|
return;
|
|
|
|
}
|
2016-12-02 13:52:37 +08:00
|
|
|
|
2016-07-21 14:57:59 +08:00
|
|
|
auto isDestroyed = _isDestroyed;
|
2015-07-28 15:27:07 +08:00
|
|
|
auto scheduler = Director::getInstance()->getScheduler();
|
2016-07-21 14:57:59 +08:00
|
|
|
scheduler->performFunctionInCocosThread([&, isDestroyed](){
|
|
|
|
if (*isDestroyed)
|
|
|
|
{
|
|
|
|
ALOGV("invokingLoadCallbacks perform in cocos thread, AudioCache (%p) was destroyed!", this);
|
|
|
|
return;
|
2015-07-28 15:27:07 +08:00
|
|
|
}
|
2016-12-02 13:52:37 +08:00
|
|
|
|
2016-07-21 14:57:59 +08:00
|
|
|
for (auto&& cb : _loadCallbacks)
|
|
|
|
{
|
|
|
|
cb(_state == State::READY);
|
|
|
|
}
|
|
|
|
|
2015-07-28 15:27:07 +08:00
|
|
|
_loadCallbacks.clear();
|
|
|
|
});
|
2014-09-03 18:19:21 +08:00
|
|
|
}
|
2014-09-22 15:38:12 +08:00
|
|
|
|
|
|
|
#endif
|