mirror of https://github.com/axmolengine/axmol.git
commit
fafa3ab1ea
|
@ -241,11 +241,12 @@ bool AudioPlayer::play2d()
|
|||
void AudioPlayer::rotateBufferThread(int offsetFrame)
|
||||
{
|
||||
char* tmpBuffer = nullptr;
|
||||
AudioDecoder* decoder = AudioDecoderManager::createDecoder(_audioCache->_fileFullPath.c_str());
|
||||
auto& fullPath = _audioCache->_fileFullPath;
|
||||
AudioDecoder* decoder = AudioDecoderManager::createDecoder(fullPath);
|
||||
long long rotateSleepTime = static_cast<long long>(QUEUEBUFFER_TIME_STEP * 1000) / 2;
|
||||
do
|
||||
{
|
||||
BREAK_IF(decoder == nullptr || !decoder->open(_audioCache->_fileFullPath.c_str()));
|
||||
BREAK_IF(decoder == nullptr || !decoder->open(fullPath));
|
||||
|
||||
uint32_t framesRead = 0;
|
||||
const uint32_t framesToRead = _audioCache->_queBufferFrames;
|
||||
|
|
|
@ -448,10 +448,10 @@ AUDIO_ID AudioEngineImpl::play2d(const std::string &filePath ,bool loop ,float v
|
|||
|
||||
void AudioEngineImpl::_play2d(AudioCache *cache, AUDIO_ID audioID)
|
||||
{
|
||||
_threadMutex.lock();
|
||||
//Note: It maybe in sub thread or main thread :(
|
||||
//Note: It may bn in sub thread or main thread :(
|
||||
if (!*cache->_isDestroyed && cache->_state == AudioCache::State::READY)
|
||||
{
|
||||
_threadMutex.lock();
|
||||
auto playerIt = _audioPlayers.find(audioID);
|
||||
if (playerIt != _audioPlayers.end() && playerIt->second->play2d()) {
|
||||
_scheduler->performFunctionInCocosThread([audioID](){
|
||||
|
@ -461,6 +461,7 @@ void AudioEngineImpl::_play2d(AudioCache *cache, AUDIO_ID audioID)
|
|||
}
|
||||
});
|
||||
}
|
||||
_threadMutex.unlock();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -471,7 +472,6 @@ void AudioEngineImpl::_play2d(AudioCache *cache, AUDIO_ID audioID)
|
|||
iter->second->_removeByAudioEngine = true;
|
||||
}
|
||||
}
|
||||
_threadMutex.unlock();
|
||||
}
|
||||
|
||||
ALuint AudioEngineImpl::findValidSource()
|
||||
|
@ -711,7 +711,7 @@ void AudioEngineImpl::update(float dt)
|
|||
delete player;
|
||||
_unusedSourcesPool.push_back(alSource);
|
||||
}
|
||||
else if (player->_ready && sourceState == AL_STOPPED) {
|
||||
else if (player->_ready && player->isFinished()) {
|
||||
|
||||
std::string filePath;
|
||||
if (player->_finishCallbak) {
|
||||
|
|
|
@ -55,6 +55,8 @@ public:
|
|||
float getTime() { return _currTime;}
|
||||
bool setLoop(bool loop);
|
||||
|
||||
bool isFinished() const;
|
||||
|
||||
protected:
|
||||
void setCache(AudioCache* cache);
|
||||
void rotateBufferThread(int offsetFrame);
|
||||
|
@ -65,7 +67,7 @@ protected:
|
|||
|
||||
float _volume;
|
||||
bool _loop;
|
||||
std::function<void (int, const std::string &)> _finishCallbak;
|
||||
std::function<void (AUDIO_ID, const std::string &)> _finishCallbak;
|
||||
|
||||
bool _isDestroyed;
|
||||
bool _removeByAudioEngine;
|
||||
|
|
|
@ -327,6 +327,25 @@ void AudioPlayer::rotateBufferThread(int offsetFrame)
|
|||
alSourceQueueBuffers(_alSource, 1, &bid);
|
||||
}
|
||||
}
|
||||
/* Make sure the source hasn't underrun */
|
||||
else if (sourceState != AL_PAUSED)
|
||||
{
|
||||
ALint queued;
|
||||
|
||||
/* If no buffers are queued, playback is finished */
|
||||
alGetSourcei(_alSource, AL_BUFFERS_QUEUED, &queued);
|
||||
if (queued == 0) {
|
||||
needToExitThread = true;
|
||||
}
|
||||
else {
|
||||
alSourcePlay(_alSource);
|
||||
if (alGetError() != AL_NO_ERROR)
|
||||
{
|
||||
ALOGE("Error restarting playback!");
|
||||
needToExitThread = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_lock<std::mutex> lk(_sleepMutex);
|
||||
if (_isDestroyed || needToExitThread) {
|
||||
|
@ -357,6 +376,16 @@ void AudioPlayer::wakeupRotateThread()
|
|||
_sleepCondition.notify_all();
|
||||
}
|
||||
|
||||
bool AudioPlayer::isFinished() const
|
||||
{
|
||||
if(_streamingSource) return _isRotateThreadExited;
|
||||
else {
|
||||
ALint sourceState;
|
||||
alGetSourcei(_alSource, AL_SOURCE_STATE, &sourceState);
|
||||
return sourceState == AL_STOPPED;
|
||||
}
|
||||
}
|
||||
|
||||
bool AudioPlayer::setLoop(bool loop)
|
||||
{
|
||||
if (!_isDestroyed ) {
|
||||
|
|
|
@ -78,7 +78,7 @@ protected:
|
|||
//play by circular buffer
|
||||
float _currTime;
|
||||
bool _streamingSource;
|
||||
ALuint _bufferIds[3];
|
||||
ALuint _bufferIds[QUEUEBUFFER_NUM];
|
||||
std::thread* _rotateBufferThread;
|
||||
std::condition_variable _sleepCondition;
|
||||
std::mutex _sleepMutex;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"version": "deps-6",
|
||||
"zip_file_size": "103992055",
|
||||
"version": "deps-7",
|
||||
"zip_file_size": "105359521",
|
||||
"repo_name": "engine-v5-3rd",
|
||||
"repo_parent": "https://github.com/simdsoft/",
|
||||
"move_dirs": {
|
||||
|
|
|
@ -70,12 +70,12 @@ function build_ios_cmake()
|
|||
mkdir -p ios_cmake_build
|
||||
cd ios_cmake_build
|
||||
cmake .. -GXcode -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphonesimulator
|
||||
cmake --build . --config Release --target cpp-tests
|
||||
# cmake --build . --config Release --target cpp-tests
|
||||
# too much logs on console when "cmake --build ."
|
||||
# cmake --build .
|
||||
#xcodebuild -project Cocos2d-x.xcodeproj -alltargets -jobs $NUM_OF_CORES -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" build | xcpretty
|
||||
xcodebuild -project Cocos2d-x.xcodeproj -target cpp-tests -jobs $NUM_OF_CORES -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" build | xcpretty
|
||||
#the following commands must not be removed
|
||||
#xcodebuild -project Cocos2d-x.xcodeproj -alltargets -jobs $NUM_OF_CORES -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" build
|
||||
xcodebuild -project Cocos2d-x.xcodeproj -target cpp-tests -jobs $NUM_OF_CORES -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" build
|
||||
exit 0
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue