Sync branch v2.0-release to v2.1-release

This commit is contained in:
Cocos Robot
2019-04-14 17:43:18 +08:00
committed by GitHub
10 changed files with 91 additions and 85 deletions
+30 -61
View File
@@ -51,22 +51,6 @@ unsigned int __idIndex = 0;
#define INVALID_AL_BUFFER_ID 0xFFFFFFFF
#define PCMDATA_CACHEMAXSIZE 1048576
typedef ALvoid AL_APIENTRY (*alBufferDataStaticProcPtr) (const ALint bid, ALenum format, ALvoid* data, ALsizei size, ALsizei freq);
static ALvoid alBufferDataStaticProc(const ALint bid, ALenum format, ALvoid* data, ALsizei size, ALsizei freq)
{
static alBufferDataStaticProcPtr proc = nullptr;
if (proc == nullptr) {
proc = (alBufferDataStaticProcPtr) alcGetProcAddress(nullptr, (const ALCchar*) "alBufferDataStatic");
}
if (proc){
proc(bid, format, data, size, freq);
}
return;
}
@interface NSTimerWrapper : NSObject
{
std::function<void()> _timeoutCallback;
@@ -104,11 +88,6 @@ static ALvoid alBufferDataStaticProc(const ALint bid, ALenum format, ALvoid* da
@end
static void setTimeout(double seconds, const std::function<void()>& cb)
{
[[[NSTimerWrapper alloc] initWithTimeInterval:seconds callback:cb] autorelease];
}
using namespace cocos2d;
AudioCache::AudioCache()
@@ -149,35 +128,19 @@ AudioCache::~AudioCache()
}
//wait for the 'readDataTask' task to exit
_readDataTaskMutex.lock();
_readDataTaskMutex.unlock();
if (_pcmData)
if (_state == State::READY)
{
if (_state == State::READY)
if (_alBufferId != INVALID_AL_BUFFER_ID && alIsBuffer(_alBufferId))
{
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;
}
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);
}
// fixed #17494: CrashIfClientProvidedBogusAudioBufferList
// We're using 'alBufferDataStaticProc' for speeding up
// the performance of playing audio without preload, but we need to manage the memory by ourself carefully.
// It's probably that '_pcmData' is freed before OpenAL finishes the audio render task,
// then 'CrashIfClientProvidedBogusAudioBufferList' may be triggered.
// 'cpp-tests/NewAudioEngineTest/AudioSwitchStateTest' can reproduce this issue without the following fix.
// The workaround is delaying 200ms to free pcm data.
char* data = _pcmData;
setTimeout(0.2, [data](){
free(data);
});
}
else
{
ALOGW("AudioCache (%p), id=%u, buffer isn't ready, state=%d", this, _id, _state);
}
if (_queBufferFrames > 0)
@@ -188,6 +151,7 @@ AudioCache::~AudioCache()
}
}
ALOGVV("~AudioCache() %p, id=%u, end", this, _id);
_readDataTaskMutex.unlock();
}
void AudioCache::readDataTask(unsigned int selfId)
@@ -260,24 +224,16 @@ void AudioCache::readDataTask(unsigned int selfId)
_pcmData = (char*)malloc(dataSize);
memset(_pcmData, 0x00, dataSize);
ALOGV(" id=%u _pcmData alloc: %p", selfId, _pcmData);
if (adjustFrames > 0)
{
memcpy(_pcmData + (dataSize - adjustFrameBuf.size()), adjustFrameBuf.data(), adjustFrameBuf.size());
}
alGenBuffers(1, &_alBufferId);
auto alError = alGetError();
if (alError != AL_NO_ERROR) {
ALOGE("%s: attaching audio to buffer fail: %x", __PRETTY_FUNCTION__, alError);
break;
}
if (*_isDestroyed)
break;
alBufferDataStaticProc(_alBufferId, _format, _pcmData, (ALsizei)dataSize, (ALsizei)sampleRate);
framesRead = decoder.readFixedFrames(std::min(framesToReadOnce, remainingFrames), _pcmData + _framesRead * bytesPerFrame);
_framesRead += framesRead;
remainingFrames -= framesRead;
@@ -285,10 +241,6 @@ void AudioCache::readDataTask(unsigned int selfId)
if (*_isDestroyed)
break;
_state = State::READY;
invokingPlayCallbacks();
uint32_t frames = 0;
while (!*_isDestroyed && _framesRead < originalTotalFrames)
{
@@ -308,9 +260,22 @@ void AudioCache::readDataTask(unsigned int selfId)
{
memset(_pcmData + _framesRead * bytesPerFrame, 0x00, (totalFrames - _framesRead) * bytesPerFrame);
}
ALOGV("pcm buffer was loaded successfully, total frames: %u, total read frames: %u, adjust frames: %u, remainingFrames: %u", totalFrames, _framesRead, adjustFrames, remainingFrames);
ALOGV("pcm buffer was loaded successfully, total frames: %u, total read frames: %u, adjust frames: %u, remainingFrames: %u", totalFrames, _framesRead, adjustFrames, remainingFrames);
_framesRead += adjustFrames;
alGenBuffers(1, &_alBufferId);
auto alError = alGetError();
if (alError != AL_NO_ERROR) {
ALOGE("%s: attaching audio to buffer fail: %x", __PRETTY_FUNCTION__, alError);
break;
}
ALOGV(" id=%u generated alGenBuffers: %u for _pcmData: %p", selfId, _alBufferId, _pcmData);
ALOGV(" id=%u _pcmData alBufferData: %p", selfId, _pcmData);
alBufferData(_alBufferId, _format, _pcmData, (ALsizei)dataSize, (ALsizei)sampleRate);
_state = State::READY;
invokingPlayCallbacks();
}
else
{
@@ -332,6 +297,10 @@ void AudioCache::readDataTask(unsigned int selfId)
} while (false);
if (_pcmData != nullptr){
CC_SAFE_FREE(_pcmData);
}
decoder.close();
//IDEA: Why to invoke play callback first? Should it be after 'load' callback?
@@ -344,7 +313,7 @@ void AudioCache::readDataTask(unsigned int selfId)
_state = State::FAILED;
if (_alBufferId != INVALID_AL_BUFFER_ID && alIsBuffer(_alBufferId))
{
ALOGV("readDataTask failed, delete buffer: %u", _alBufferId);
ALOGV(" id=%u readDataTask failed, delete buffer: %u", selfId, _alBufferId);
alDeleteBuffers(1, &_alBufferId);
_alBufferId = INVALID_AL_BUFFER_ID;
}
@@ -1,26 +1,32 @@
/****************************************************************************
Copyright (c) 2019 Xiamen Yaji Software Co., Ltd.
http://www.cocos2d-x.org
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.
****************************************************************************/
/******************************************************************************
* Spine Runtimes Software License v2.5
*
* Copyright (c) 2013-2016, Esoteric Software
* All rights reserved.
*
* You are granted a perpetual, non-exclusive, non-sublicensable, and
* non-transferable license to use, install, execute, and perform the Spine
* Runtimes software and derivative works solely for personal or internal
* use. Without the written permission of Esoteric Software (see Section 2 of
* the Spine Software License Agreement), you may not (a) modify, translate,
* adapt, or develop new applications using the Spine Runtimes or otherwise
* create derivative works or improvements of the Spine Runtimes or (b) remove,
* delete, alter, or obscure any trademarks or any copyright, trademark, patent,
* or other intellectual property or proprietary rights notices on or in the
* Software, including any copy thereof. Redistributions in binary or source
* form must include this license and terms.
*
* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS INTERRUPTION, OR LOSS OF
* USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#include "SkeletonDataMgr.h"
#include <algorithm>
@@ -161,7 +161,6 @@ SpineAnimation::SpineAnimation (const std::string& skeletonDataFile, const std::
SpineAnimation::~SpineAnimation ()
{
clearTracks();
_startListener = nullptr;
_interruptListener = nullptr;
_endListener = nullptr;
@@ -171,6 +170,7 @@ SpineAnimation::~SpineAnimation ()
if (_state)
{
clearTracks();
if (_ownsAnimationStateData) spAnimationStateData_dispose(_state->data);
spAnimationState_dispose(_state);
}
@@ -109,6 +109,11 @@ android.applicationVariants.all { variant ->
into "${outputDir}/res"
}
copy {
from "${sourceDir}/subpackages"
into "${outputDir}/subpackages"
}
copy {
from "${sourceDir}/src"
into "${outputDir}/src"
@@ -109,6 +109,11 @@ android.applicationVariants.all { variant ->
into "${outputDir}/res"
}
copy {
from "${sourceDir}/subpackages"
into "${outputDir}/subpackages"
}
copy {
from "${sourceDir}/src"
into "${outputDir}/src"
@@ -24,6 +24,7 @@
1AFFCD851F7A5DCF00628F2C /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1AFFCD841F7A5DCD00628F2C /* Images.xcassets */; };
1AFFCD871F7A5DCF00628F2C /* LaunchScreenBackground.png in Resources */ = {isa = PBXBuildFile; fileRef = 1AFFCD831F7A5DCD00628F2C /* LaunchScreenBackground.png */; };
22CC756521BA528000FBF2F7 /* SDKWrapper.m in Sources */ = {isa = PBXBuildFile; fileRef = 22CC756121BA527F00FBF2F7 /* SDKWrapper.m */; };
288D4373225B43BE0075FBAB /* subpackages in Resources */ = {isa = PBXBuildFile; fileRef = 288D4372225B43BE0075FBAB /* subpackages */; };
294D7D7C1D0D667B002CE7B7 /* CoreText.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 294D7D7B1D0D667B002CE7B7 /* CoreText.framework */; };
4033CDC020E493CF00DAA37B /* jsb-adapter in Resources */ = {isa = PBXBuildFile; fileRef = 4033CDBF20E493CF00DAA37B /* jsb-adapter */; };
4033CDC120E493CF00DAA37B /* jsb-adapter in Resources */ = {isa = PBXBuildFile; fileRef = 4033CDBF20E493CF00DAA37B /* jsb-adapter */; };
@@ -130,6 +131,7 @@
22CC756121BA527F00FBF2F7 /* SDKWrapper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SDKWrapper.m; path = ios/SDKWrapper.m; sourceTree = "<group>"; };
22CC756221BA527F00FBF2F7 /* SDKWrapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDKWrapper.h; path = ios/SDKWrapper.h; sourceTree = "<group>"; };
22CC756421BA527F00FBF2F7 /* SDKDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDKDelegate.h; sourceTree = "<group>"; };
288D4372225B43BE0075FBAB /* subpackages */ = {isa = PBXFileReference; lastKnownFileType = folder; name = subpackages; path = ../../../subpackages; sourceTree = "<group>"; };
294D7D7B1D0D667B002CE7B7 /* CoreText.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreText.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.3.sdk/System/Library/Frameworks/CoreText.framework; sourceTree = DEVELOPER_DIR; };
4033CDBF20E493CF00DAA37B /* jsb-adapter */ = {isa = PBXFileReference; lastKnownFileType = folder; name = "jsb-adapter"; path = "../../../jsb-adapter"; sourceTree = "<group>"; };
40CEC425212BDAC1004BCE66 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
@@ -291,6 +293,7 @@
A92275321517C094001B78AA = {
isa = PBXGroup;
children = (
288D4372225B43BE0075FBAB /* subpackages */,
1AC6FB34180E9ACB004C840B /* cocos2d_libs.xcodeproj */,
D4545214156E28EF00887EB5 /* Classes */,
A92275401517C094001B78AA /* Frameworks */,
@@ -495,6 +498,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
288D4373225B43BE0075FBAB /* subpackages in Resources */,
4033CDC020E493CF00DAA37B /* jsb-adapter in Resources */,
1AFFCD871F7A5DCF00628F2C /* LaunchScreenBackground.png in Resources */,
1AE159EC18C9DF3600FCA372 /* project.json in Resources */,
@@ -8,6 +8,10 @@
"from": "../../../res",
"to": "res"
},
{
"from": "../../../subpackages",
"to": "subpackages"
},
{
"from": "../../../main.js",
"to": ""
@@ -109,6 +109,11 @@ android.applicationVariants.all { variant ->
into "${outputDir}/res"
}
copy {
from "${sourceDir}/subpackages"
into "${outputDir}/subpackages"
}
copy {
from "${sourceDir}/src"
into "${outputDir}/src"
@@ -21,6 +21,7 @@
1AFFCD7E1F7A5D5400628F2C /* LaunchScreenBackground.png in Resources */ = {isa = PBXBuildFile; fileRef = 1AFFCD7B1F7A5D4F00628F2C /* LaunchScreenBackground.png */; };
1AFFCD7F1F7A5D5400628F2C /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1ABC56911F7A005D00826282 /* Images.xcassets */; };
22CC757121BA5B5C00FBF2F7 /* SDKWrapper.m in Sources */ = {isa = PBXBuildFile; fileRef = 22CC756D21BA5B5C00FBF2F7 /* SDKWrapper.m */; };
28A34C10225B462E00926306 /* subpackages in Resources */ = {isa = PBXBuildFile; fileRef = 28A34C0F225B462E00926306 /* subpackages */; };
294D7D801D0D668F002CE7B7 /* CoreText.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 294D7D7F1D0D668F002CE7B7 /* CoreText.framework */; };
4011F9CF212BD6750091CC5B /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4011F9D1212BD6750091CC5B /* LaunchScreen.storyboard */; };
4011F9D5212BD7050091CC5B /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 4011F9D7212BD7050091CC5B /* Localizable.strings */; };
@@ -125,6 +126,7 @@
22CC756D21BA5B5C00FBF2F7 /* SDKWrapper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SDKWrapper.m; path = ios/SDKWrapper.m; sourceTree = "<group>"; };
22CC756F21BA5B5C00FBF2F7 /* SDKDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDKDelegate.h; sourceTree = "<group>"; };
22CC757021BA5B5C00FBF2F7 /* SDKWrapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDKWrapper.h; path = ios/SDKWrapper.h; sourceTree = "<group>"; };
28A34C0F225B462E00926306 /* subpackages */ = {isa = PBXFileReference; lastKnownFileType = folder; name = subpackages; path = ../../../subpackages; sourceTree = "<group>"; };
294D7D7F1D0D668F002CE7B7 /* CoreText.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreText.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.3.sdk/System/Library/Frameworks/CoreText.framework; sourceTree = DEVELOPER_DIR; };
4011F9D2212BD6810091CC5B /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
4011F9D8212BD7150091CC5B /* Base */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Base; path = Base.lproj/Localizable.strings; sourceTree = "<group>"; };
@@ -283,6 +285,7 @@
A92275321517C094001B78AA = {
isa = PBXGroup;
children = (
28A34C0F225B462E00926306 /* subpackages */,
1AC6FB34180E9ACB004C840B /* cocos2d_libs.xcodeproj */,
D4545214156E28EF00887EB5 /* Classes */,
A92275401517C094001B78AA /* Frameworks */,
@@ -485,6 +488,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
28A34C10225B462E00926306 /* subpackages in Resources */,
4033CDBC20E4935100DAA37B /* jsb-adapter in Resources */,
1AFFCD7F1F7A5D5400628F2C /* Images.xcassets in Resources */,
1AFFCD7E1F7A5D5400628F2C /* LaunchScreenBackground.png in Resources */,
@@ -8,6 +8,10 @@
"from": "../../../res",
"to": "res"
},
{
"from": "../../../subpackages",
"to": "subpackages"
},
{
"from": "../../../main.js",
"to": ""