[engine] [cocos2d-x] [jsb-adapter] 适配引擎 v2.4.12 版本

This commit is contained in:
SmallMain
2023-10-30 22:32:32 +08:00
parent 2508616ad9
commit 0092eb9f05
787 changed files with 206249 additions and 422 deletions

View File

@@ -27,6 +27,8 @@ THE SOFTWARE.
#include "audio/android/AudioDecoderSLES.h"
#include "platform/CCFileUtils.h"
#include "platform/CCPlatformDefine.h"
#include "audio/android/utils/Compat.h"
#include <thread>
#include <mutex>
@@ -86,7 +88,7 @@ public:
thiz->prefetchCallback(caller, event);
}
static void decPlayCallback(SLAndroidSimpleBufferQueueItf queueItf, void *context)
static void decPlayCallback(CCSLBufferQueueItf queueItf, void *context)
{
AudioDecoderSLES *thiz = reinterpret_cast<AudioDecoderSLES *>(context);
thiz->decodeToPcmCallback(queueItf);
@@ -144,13 +146,14 @@ bool AudioDecoderSLES::init(SLEngineItf engineItf, const std::string &url, int b
bool AudioDecoderSLES::decodeToPcm()
{
SLresult result;
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
SLresult result;
/* Objects this application uses: one audio player */
SLObjectItf player;
/* Interfaces for the audio player */
SLAndroidSimpleBufferQueueItf decBuffQueueItf;
CCSLBufferQueueItf decBuffQueueItf;
SLPrefetchStatusItf prefetchItf;
SLPlayItf playItf;
SLMetadataExtractionItf mdExtrItf;
@@ -463,6 +466,7 @@ bool AudioDecoderSLES::decodeToPcm()
std::string info = _result.toString();
ALOGI("Original audio info: %s, total size: %d", info.c_str(), (int)_result.pcmBuffer->size());
#endif
return true;
}
@@ -585,7 +589,7 @@ void AudioDecoderSLES::decodeProgressCallback(SLPlayItf caller, SLuint32 event)
//-----------------------------------------------------------------
/* Callback for decoding buffer queue events */
void AudioDecoderSLES::decodeToPcmCallback(SLAndroidSimpleBufferQueueItf queueItf)
void AudioDecoderSLES::decodeToPcmCallback(CCSLBufferQueueItf queueItf)
{
_isDecodingCallbackInvoked = true;
ALOGV("%s ...", __FUNCTION__);

View File

@@ -26,6 +26,8 @@ THE SOFTWARE.
#pragma once
#include "audio/android/AudioDecoder.h"
#include "audio/android/utils/Compat.h"
#include "platform/CCPlatformDefine.h"
#include <mutex>
#include <condition_variable>
@@ -44,7 +46,7 @@ private:
void queryAudioInfo();
void signalEos();
void decodeToPcmCallback(SLAndroidSimpleBufferQueueItf queueItf);
void decodeToPcmCallback(CCSLBufferQueueItf queueItf);
void prefetchCallback(SLPrefetchStatusItf caller, SLuint32 event);
void decodeProgressCallback(SLPlayItf caller, SLuint32 event);

View File

@@ -22,7 +22,6 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
#define LOG_TAG "AudioEngineImpl"
@@ -30,11 +29,14 @@
#include <unistd.h>
// for native asset manager
#include <sys/types.h>
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
#include <android/asset_manager.h>
#include <android/asset_manager_jni.h>
#include <unordered_map>
#include <android/log.h>
#endif
#include <sys/types.h>
#include <thread>
#include <mutex>
@@ -42,9 +44,13 @@
#include "platform/CCApplication.h"
#include "base/CCScheduler.h"
#include "base/ccUTF8.h"
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
#include "platform/android/CCFileUtils-android.h"
#include "platform/android/jni/JniImp.h"
#include "platform/android/jni/JniHelper.h"
#include "platform/android/jni/JniImp.h"
#elif CC_TARGET_PLATFORM == CC_PLATFORM_OPENHARMONY
#include "cocos/platform/openharmony/FileUtils-openharmony.h"
#endif
#include "audio/android/IAudioPlayer.h"
#include "audio/android/ICallerThreadUtils.h"
@@ -57,6 +63,28 @@
using namespace cocos2d;
// Audio focus values synchronized with which in cocos/platform/android/java/src/com/cocos/lib/CocosNativeActivity.java
namespace {
AudioEngineImpl *gAudioImpl = nullptr;
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
int bufferSizeInFrames = getDeviceAudioBufferSizeInFramesJNI();
#elif CC_TARGET_PLATFORM == CC_PLATFORM_OPENHARMONY
// TODO(hack) : There is currently a bug in the opensles module,
// so openharmony must configure a fixed size, otherwise the callback will be suspended
int bufferSizeInFrames = 2048;
#endif
int outputSampleRate = 44100;
void getAudioInfo() {
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
outputSampleRate = getDeviceSampleRateJNI();
#elif CC_TARGET_PLATFORM == CC_PLATFORM_OPENHARMONY
// In openharmony, setting to 48K does not cause audio delays
outputSampleRate = 48000;
#endif
}
} // namespace
// Audio focus values synchronized with which in cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java
static const int AUDIOFOCUS_GAIN = 0;
static const int AUDIOFOCUS_LOST = 1;
@@ -93,6 +121,7 @@ static CallerThreadUtils __callerThreadUtils;
static int fdGetter(const std::string& url, off_t* start, off_t* length)
{
int fd = -1;
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
if (cocos2d::FileUtilsAndroid::getObbFile() != nullptr)
{
fd = getObbAssetFileDescriptorJNI(url.c_str(), start, length);
@@ -104,7 +133,14 @@ static int fdGetter(const std::string& url, off_t* start, off_t* length)
fd = AAsset_openFileDescriptor(asset, start, length);
AAsset_close(asset);
}
#elif CC_TARGET_PLATFORM == CC_PLATFORM_OPENHARMONY
FileUtilsOpenHarmony* fileUtils = static_cast<FileUtilsOpenHarmony*>(FileUtils::getInstance());
if(fileUtils) {
RawFileDescriptor descriptor;
fileUtils->getRawFileDescriptor(url, descriptor);
fd = descriptor.fd;
}
#endif
if (fd <= 0)
{
ALOGE("Failed to open file descriptor for '%s'", url.c_str());
@@ -124,6 +160,7 @@ AudioEngineImpl::AudioEngineImpl()
{
__callerThreadUtils.setCallerThreadId(std::this_thread::get_id());
__impl = this;
getAudioInfo();
}
AudioEngineImpl::~AudioEngineImpl()
@@ -173,7 +210,7 @@ bool AudioEngineImpl::init()
result = (*_outputMixObject)->Realize(_outputMixObject, SL_BOOLEAN_FALSE);
if(SL_RESULT_SUCCESS != result){ ERRORLOG("realize the output mix fail"); break; }
_audioPlayerProvider = new AudioPlayerProvider(_engineEngine, _outputMixObject, getDeviceSampleRateJNI(), getDeviceAudioBufferSizeInFramesJNI(), fdGetter, &__callerThreadUtils);
_audioPlayerProvider = new AudioPlayerProvider(_engineEngine, _outputMixObject, outputSampleRate, bufferSizeInFrames, fdGetter, &__callerThreadUtils);
ret = true;
}while (false);
@@ -462,5 +499,3 @@ void cocos_audioengine_focus_change(int focusChange)
__impl->setAudioFocusForAllPlayers(false);
}
}
#endif

View File

@@ -22,13 +22,18 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
#ifndef __AUDIO_ENGINE_INL_H_
#define __AUDIO_ENGINE_INL_H_
#include "platform/CCPlatformConfig.h"
#include <SLES/OpenSLES.h>
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
#include <SLES/OpenSLES_Android.h>
#elif CC_TARGET_PLATFORM == CC_PLATFORM_OPENHARMONY
#include <SLES/OpenSLES_Platform.h>
#endif
#include <string>
#include <unordered_map>
#include <functional>
@@ -101,5 +106,3 @@ private:
#endif // __AUDIO_ENGINE_INL_H_
NS_CC_END
#endif

View File

@@ -26,6 +26,7 @@
#include "audio/android/AudioResampler.h"
#include "audio/android/audio.h"
#include "audio/android/utils/Compat.h"
// IDEA: This is actually unity gain, which might not be max in future, expressed in U.12
#define MAX_GAIN_INT AudioMixer::UNITY_GAIN_INT

View File

@@ -36,7 +36,12 @@ THE SOFTWARE.
#include "audio/android/ICallerThreadUtils.h"
#include "audio/android/utils/Utils.h"
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
#include <sys/system_properties.h>
#elif CC_TARGET_PLATFORM == CC_PLATFORM_OPENHARMONY
#include "cocos/platform/CCFileUtils.h"
#include "cocos/platform/openharmony/FileUtils-openharmony.h"
#endif
#include <stdlib.h>
#include <algorithm> // for std::find_if
@@ -45,6 +50,8 @@ namespace cocos2d {
static int getSystemAPILevel()
{
static int __systemApiLevel = -1;
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
if (__systemApiLevel > 0)
{
return __systemApiLevel;
@@ -61,6 +68,10 @@ static int getSystemAPILevel()
}
__systemApiLevel = apiLevel;
return apiLevel;
#elif CC_TARGET_PLATFORM == CC_PLATFORM_OPENHARMONY
// TODO(qgh): On the openharmony platform, pcm streaming must be used
return std::numeric_limits<int>::max();
#endif
}
struct AudioFileIndicator
@@ -354,7 +365,7 @@ AudioPlayerProvider::AudioFileInfo AudioPlayerProvider::getFileInfo(
long fileSize = 0;
off_t start = 0, length = 0;
int assetFd = -1;
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
if (audioFilePath[0] != '/')
{
std::string relativePath;
@@ -399,7 +410,19 @@ AudioPlayerProvider::AudioFileInfo AudioPlayerProvider::getFileInfo(
info.assetFd = std::make_shared<AssetFd>(assetFd);
info.start = start;
info.length = fileSize;
#elif CC_TARGET_PLATFORM == CC_PLATFORM_OPENHARMONY
FileUtilsOpenHarmony* fileUtils = static_cast<FileUtilsOpenHarmony*>(FileUtils::getInstance());
if(!fileUtils) {
return info;
}
RawFileDescriptor descriptor;
fileUtils->getRawFileDescriptor(audioFilePath, descriptor);
info.url = audioFilePath;
info.assetFd = std::make_shared<AssetFd>(descriptor.fd);
info.start = descriptor.start;
info.length = descriptor.length;
#endif
ALOGV("(%s) file size: %ld", audioFilePath.c_str(), fileSize);
return info;
@@ -407,6 +430,10 @@ AudioPlayerProvider::AudioFileInfo AudioPlayerProvider::getFileInfo(
bool AudioPlayerProvider::isSmallFile(const AudioFileInfo &info)
{
#if CC_TARGET_PLATFORM == CC_PLATFORM_OPENHARMONY
// TODO(qgh): OpenHarmony system does not support this function yet
return true;
#endif
//REFINE: If file size is smaller than 100k, we think it's a small file. This value should be set by developers.
AudioFileInfo &audioFileInfo = const_cast<AudioFileInfo &>(info);
size_t judgeCount = sizeof(__audioFileIndicator) / sizeof(__audioFileIndicator[0]);
@@ -490,7 +517,12 @@ UrlAudioPlayer *AudioPlayerProvider::createUrlAudioPlayer(
return nullptr;
}
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
SLuint32 locatorType = info.assetFd->getFd() > 0 ? SL_DATALOCATOR_ANDROIDFD : SL_DATALOCATOR_URI;
#elif CC_TARGET_PLATFORM == CC_PLATFORM_OPENHARMONY
SLuint32 locatorType = SL_DATALOCATOR_URI;
#endif
auto urlPlayer = new (std::nothrow) UrlAudioPlayer(_engineItf, _outputMixObject, _callerThreadUtils);
bool ret = urlPlayer->prepare(info.url, locatorType, info.assetFd, info.start, info.length);
if (!ret)

View File

@@ -17,9 +17,14 @@
#pragma once
#include <stdint.h>
#include <sys/types.h>
#include "platform/CCPlatformConfig.h"
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
#include <android/log.h>
#include <sys/system_properties.h>
#include <sys/types.h>
#elif CC_TARGET_PLATFORM == CC_PLATFORM_OPENHARMONY
#include <hilog/log.h>
#endif
#include "audio/android/AudioBufferProvider.h"

View File

@@ -28,7 +28,11 @@ THE SOFTWARE.
#include "audio/android/cutils/log.h"
#include <SLES/OpenSLES.h>
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
#include <SLES/OpenSLES_Android.h>
#elif CC_TARGET_PLATFORM == CC_PLATFORM_OPENHARMONY
#include <SLES/OpenSLES_Platform.h>
#endif
#include <functional>
#include <string>

View File

@@ -27,6 +27,7 @@ THE SOFTWARE.
#include "audio/android/PcmAudioService.h"
#include "audio/android/AudioMixerController.h"
#include "audio/android/utils/Compat.h"
namespace cocos2d {
@@ -37,11 +38,18 @@ static std::vector<char> __silenceData;
class SLPcmAudioPlayerCallbackProxy
{
public:
static void samplePlayerCallback(SLAndroidSimpleBufferQueueItf bq, void *context)
{
PcmAudioService *thiz = reinterpret_cast<PcmAudioService *>(context);
thiz->bqFetchBufferCallback(bq);
}
#if CC_TARGET_PLATFORM == CC_PLATFORM_OPENHARMONY
static void samplePlayerCallback(CCSLBufferQueueItf bq, void *context, SLuint32 size) {
auto *thiz = reinterpret_cast<PcmAudioService *>(context);
thiz->bqFetchBufferCallback(bq);
}
#elif CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
static void samplePlayerCallback(CCSLBufferQueueItf bq, void *context) {
PcmAudioService *thiz = reinterpret_cast<PcmAudioService *>(context);
thiz->bqFetchBufferCallback(bq);
}
#endif
};
PcmAudioService::PcmAudioService(SLEngineItf engineItf, SLObjectItf outputMixObject)
@@ -60,6 +68,12 @@ PcmAudioService::~PcmAudioService()
bool PcmAudioService::enqueue()
{
#if CC_TARGET_PLATFORM == CC_PLATFORM_OPENHARMONY
// We need to call this interface in openharmony, otherwise there will be noise
SLuint8 *buffer = nullptr;
SLuint32 size = 0;
(*_bufferQueueItf)->GetBuffer(_bufferQueueItf, &buffer, &size);
#endif
if (_controller->hasPlayingTacks())
{
if (_controller->isPaused())
@@ -86,7 +100,7 @@ bool PcmAudioService::enqueue()
return true;
}
void PcmAudioService::bqFetchBufferCallback(SLAndroidSimpleBufferQueueItf bq)
void PcmAudioService::bqFetchBufferCallback(CCSLBufferQueueItf bq)
{
// IDEA: PcmAudioService instance may be destroyed, we need to find a way to wait...
// It's in sub thread
@@ -117,10 +131,8 @@ bool PcmAudioService::init(AudioMixerController* controller, int numChannels, in
SL_BYTEORDER_LITTLEENDIAN
};
SLDataLocator_AndroidSimpleBufferQueue locBufQueue = {
SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE,
AUDIO_PLAYER_BUFFER_COUNT
};
SLDataLocator_BufferQueue locBufQueue = {SL_DATALOCATOR_BUFFERQUEUE, AUDIO_PLAYER_BUFFER_COUNT};
SLDataSource source = {&locBufQueue, &formatPcm};
SLDataLocator_OutputMix locOutmix = {
@@ -132,7 +144,7 @@ bool PcmAudioService::init(AudioMixerController* controller, int numChannels, in
const SLInterfaceID ids[] = {
SL_IID_PLAY,
SL_IID_VOLUME,
SL_IID_ANDROIDSIMPLEBUFFERQUEUE,
CC_SL_IDD_BUFFER_QUEUE,
};
const SLboolean req[] = {
@@ -156,8 +168,8 @@ bool PcmAudioService::init(AudioMixerController* controller, int numChannels, in
r = (*_playObj)->GetInterface(_playObj, SL_IID_VOLUME, &_volumeItf);
SL_RETURN_VAL_IF_FAILED(r, false, "GetInterface SL_IID_VOLUME failed");
r = (*_playObj)->GetInterface(_playObj, SL_IID_ANDROIDSIMPLEBUFFERQUEUE, &_bufferQueueItf);
SL_RETURN_VAL_IF_FAILED(r, false, "GetInterface SL_IID_ANDROIDSIMPLEBUFFERQUEUE failed");
r = (*_playObj)->GetInterface(_playObj, CC_SL_IDD_BUFFER_QUEUE, &_bufferQueueItf);
SL_RETURN_VAL_IF_FAILED(r, false, "GetInterface CC_SL_IDD_BUFFER_QUEUE failed");
r = (*_bufferQueueItf)->RegisterCallback(_bufferQueueItf,
SLPcmAudioPlayerCallbackProxy::samplePlayerCallback,
@@ -169,6 +181,13 @@ bool PcmAudioService::init(AudioMixerController* controller, int numChannels, in
__silenceData.resize(_numChannels * _bufferSizeInBytes, 0x00);
}
#if CC_TARGET_PLATFORM == CC_PLATFORM_OPENHARMONY
// We need to call this interface in openharmony, otherwise there will be noise
SLuint8 *buffer = nullptr;
SLuint32 size = 0;
(*_bufferQueueItf)->GetBuffer(_bufferQueueItf, &buffer, &size);
#endif
r = (*_bufferQueueItf)->Enqueue(_bufferQueueItf, __silenceData.data(), __silenceData.size());
SL_RETURN_VAL_IF_FAILED(r, false, "_bufferQueueItf Enqueue failed");

View File

@@ -28,6 +28,7 @@ THE SOFTWARE.
#include "audio/android/IAudioPlayer.h"
#include "audio/android/OpenSLHelper.h"
#include "audio/android/PcmData.h"
#include "audio/android/utils/Compat.h"
#include <mutex>
#include <condition_variable>
@@ -54,7 +55,7 @@ private:
bool enqueue();
void bqFetchBufferCallback(SLAndroidSimpleBufferQueueItf bq);
void bqFetchBufferCallback(CCSLBufferQueueItf bq);
void pause();
void resume();
@@ -66,7 +67,7 @@ private:
SLObjectItf _playObj;
SLPlayItf _playItf;
SLVolumeItf _volumeItf;
SLAndroidSimpleBufferQueueItf _bufferQueueItf;
CCSLBufferQueueItf _bufferQueueItf;
int _numChannels;
int _sampleRate;

View File

@@ -27,6 +27,7 @@ THE SOFTWARE.
#include "audio/android/UrlAudioPlayer.h"
#include "audio/android/ICallerThreadUtils.h"
#include "platform/CCPlatformDefine.h"
#include <math.h>
#include <algorithm> // for std::find
@@ -70,7 +71,7 @@ UrlAudioPlayer::UrlAudioPlayer(SLEngineItf engineItf, SLObjectItf outputMixObjec
__playerContainerMutex.lock();
__playerContainer.push_back(this);
ALOGV("Current UrlAudioPlayer instance count: %d", (int)__playerContainer.size());
ALOGV("Current UrlAudioPlayer instance count: %d", (int)__playerContainer.size());
__playerContainerMutex.unlock();
_callerThreadId = callerThreadUtils->getCallerThreadId();
@@ -78,7 +79,7 @@ UrlAudioPlayer::UrlAudioPlayer(SLEngineItf engineItf, SLObjectItf outputMixObjec
UrlAudioPlayer::~UrlAudioPlayer()
{
ALOGV("~UrlAudioPlayer(): %p", this);
ALOGV("~UrlAudioPlayer(): %p", this);
__playerContainerMutex.lock();
@@ -297,6 +298,7 @@ bool UrlAudioPlayer::prepare(const std::string &url, SLuint32 locatorType, std::
_url = url;
_assetFd = assetFd;
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
const char* locatorTypeStr= "UNKNOWN";
if (locatorType == SL_DATALOCATOR_ANDROIDFD)
locatorTypeStr = "SL_DATALOCATOR_ANDROIDFD";
@@ -308,8 +310,7 @@ bool UrlAudioPlayer::prepare(const std::string &url, SLuint32 locatorType, std::
return false;
}
ALOGV("UrlAudioPlayer::prepare: %s, %s, %d, %d, %d", _url.c_str(), locatorTypeStr, _assetFd->getFd(), start,
length);
ALOGV("UrlAudioPlayer::prepare: %s, %s, %d, %d, %d", _url.c_str(), locatorTypeStr, _assetFd->getFd(), start, length);
SLDataSource audioSrc;
SLDataFormat_MIME formatMime = {SL_DATAFORMAT_MIME, nullptr, SL_CONTAINERTYPE_UNSPECIFIED};
@@ -375,6 +376,7 @@ bool UrlAudioPlayer::prepare(const std::string &url, SLuint32 locatorType, std::
setVolume(1.0f);
#endif
return true;
}

View File

@@ -28,7 +28,6 @@ THE SOFTWARE.
// ----------------------------------------------------------------------------
#include <stdint.h>
#include <android/log.h>
#include "audio/android/cutils/bitops.h"
#define PROPERTY_VALUE_MAX 256

View File

@@ -18,7 +18,11 @@
#define COCOS_AUDIO_FORMAT_H
#include <stdint.h>
#include "platform/CCPlatformConfig.h"
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
#include <sys/cdefs.h>
#endif
#include "audio/android/audio.h"
__BEGIN_DECLS

View File

@@ -18,7 +18,10 @@
#define COCOS_AUDIO_MINIFLOAT_H
#include <stdint.h>
#include "platform/CCPlatformConfig.h"
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
#include <sys/cdefs.h>
#endif
__BEGIN_DECLS

View File

@@ -19,7 +19,10 @@
#include <stdint.h>
#include <stdlib.h>
#include "platform/CCPlatformConfig.h"
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
#include <sys/cdefs.h>
#endif
__BEGIN_DECLS

View File

@@ -20,7 +20,10 @@
#include <stdbool.h>
#include <string.h>
#include <strings.h>
#include "platform/CCPlatformConfig.h"
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
#include <sys/cdefs.h>
#endif
__BEGIN_DECLS

View File

@@ -33,7 +33,12 @@
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
#include "platform/CCPlatformDefine.h"
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
#include <android/log.h>
#elif CC_TARGET_PLATFORM == CC_PLATFORM_OPENHARMONY
#include <hilog/log.h>
#endif
#ifdef __cplusplus
@@ -86,7 +91,11 @@ extern "C" {
* Simplified macro to send a verbose log message using the current LOG_TAG.
*/
#ifndef ALOGV
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
#define __ALOGV(...) ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
#elif CC_TARGET_PLATFORM == CC_PLATFORM_OPENHARMONY
#define __ALOGV(...) ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__))
#endif
#if LOG_NDEBUG
#define ALOGV(...) do { if (0) { __ALOGV(__VA_ARGS__); } } while (0)
#else
@@ -392,16 +401,29 @@ extern "C" {
* is -inverted- from the normal assert() semantics.
*/
#ifndef LOG_ALWAYS_FATAL_IF
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
#define LOG_ALWAYS_FATAL_IF(cond, ...) \
( (__predict_false(cond)) \
? ((void)android_printAssert(#cond, LOG_TAG, ## __VA_ARGS__)) \
: (void)0 )
#elif CC_TARGET_PLATFORM == CC_PLATFORM_OPENHARMONY
#define LOG_ALWAYS_FATAL_IF(cond, ...) \
((void)0 )
#endif
#endif
#ifndef LOG_ALWAYS_FATAL
#define LOG_ALWAYS_FATAL(...) \
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
#define LOG_ALWAYS_FATAL(...) \
( ((void)android_printAssert(NULL, LOG_TAG, ## __VA_ARGS__)) )
#elif CC_TARGET_PLATFORM == CC_PLATFORM_OPENHARMONY
// #define LOG_ALWAYS_FATAL(...) ((void)0)
#define LOG_ALWAYS_FATAL(...) ((void) OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_DOMAIN, "HMG_LOG", __VA_ARGS__))
#endif
#endif
/*
* Versions of LOG_ALWAYS_FATAL_IF and LOG_ALWAYS_FATAL that
@@ -424,7 +446,6 @@ extern "C" {
#ifndef LOG_FATAL
#define LOG_FATAL(...) LOG_ALWAYS_FATAL(__VA_ARGS__)
#endif
#endif
/*
@@ -447,16 +468,25 @@ extern "C" {
* The second argument may be NULL or "" to indicate the "global" tag.
*/
#ifndef ALOG
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
#define ALOG(priority, tag, ...) \
LOG_PRI(ANDROID_##priority, tag, __VA_ARGS__)
LOG_PRI(ANDROID_##priority, tag, __VA_ARGS__)
#elif CC_TARGET_PLATFORM == CC_PLATFORM_OPENHARMONY
#define ALOG(priority, tag, ...) \
LOG_PRI(priority, tag, __VA_ARGS__)
#endif
#endif
/*
* Log macro that allows you to specify a number for the priority.
*/
#ifndef LOG_PRI
#define LOG_PRI(priority, tag, ...) \
android_printLog(priority, tag, __VA_ARGS__)
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
#define LOG_PRI(priority, tag, ...) \
android_printLog(priority, tag, __VA_ARGS__)
#elif CC_TARGET_PLATFORM == CC_PLATFORM_OPENHARMONY
#define LOG_PRI(priority, tag, ...) ((void) OH_LOG_Print(LOG_APP, priority, LOG_DOMAIN, "HMG_LOG", __VA_ARGS__))
#endif
#endif
/*

View File

@@ -23,7 +23,10 @@
// no guarantee that it will stay exactly source-code compatible with other libraries.
#include <stdio.h>
#include "platform/CCPlatformConfig.h"
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
#include <sys/cdefs.h>
#endif
__BEGIN_DECLS

View File

@@ -17,7 +17,15 @@
#ifndef COCOS_LIB_UTILS_COMPAT_H
#define COCOS_LIB_UTILS_COMPAT_H
#include "platform/CCPlatformDefine.h"
#include <SLES/OpenSLES.h>
#if CC_TARGET_PLATFORM == CC_PLATFORM_OPENHARMONY
#include <SLES/OpenSLES_OpenHarmony.h>
#include <SLES/OpenSLES_Platform.h>
#elif CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
#include <SLES/OpenSLES_Android.h>
#include <unistd.h>
#endif
#if defined(__APPLE__)
@@ -85,4 +93,13 @@ static inline ssize_t pwrite64(int fd, const void* buf, size_t nbytes, off64_t o
#define OS_PATH_SEPARATOR '/'
#endif
#if CC_TARGET_PLATFORM == CC_PLATFORM_OPENHARMONY
typedef SLOHBufferQueueItf CCSLBufferQueueItf;
#define CC_SL_IDD_BUFFER_QUEUE SL_IID_OH_BUFFERQUEUE
#define __unused
#elif CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
typedef SLAndroidSimpleBufferQueueItf CCSLBufferQueueItf;
#define CC_SL_IDD_BUFFER_QUEUE SL_IID_ANDROIDSIMPLEBUFFERQUEUE
#endif
#endif /* COCOS_LIB_UTILS_COMPAT_H */

View File

@@ -23,7 +23,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "audio/android/utils/Utils.h"
#include "platform/CCPlatformDefine.h"
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
#include "platform/android/jni/JniHelper.h"
#endif
#ifndef JCLS_HELPER
#define JCLS_HELPER "org/cocos2dx/lib/Cocos2dxHelper"
@@ -33,7 +36,12 @@ namespace cocos2d {
int getSDKVersion()
{
return JniHelper::callStaticIntMethod(JCLS_HELPER, "getSDKVersion");
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
return JniHelper::callStaticIntMethod(JCLS_HELPER, "getSDKVersion");
#elif CC_TARGET_PLATFORM == CC_PLATFORM_OPENHARMONY
//TODO: openharmony未实现
return 0;
#endif
}
} // end of namespace cocos2d