Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V3.8.5 oh api12 #17869

Merged
merged 11 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cocos/rendering/legacy/index.jsb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ import { RenderTexture } from '../../asset/assets/render-texture';

export function createDefaultPipeline (): ForwardPipeline {
const rppl = new ForwardPipeline();
rppl.initialize({ flows: [] });
if (!window.oh) {
rppl.initialize({ flows: [] });
}
return rppl;
}
export const ForwardPipeline: typeof NrForwardPipeline = nr.ForwardPipeline;
Expand Down
101 changes: 90 additions & 11 deletions native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ cc_set_if_undefined(CC_DEBUG_FORCE OFF)
cc_set_if_undefined(USE_SE_V8 ON)
cc_set_if_undefined(USE_SE_SM OFF)
cc_set_if_undefined(USE_SE_NAPI OFF)
if(OPENHARMONY)
cc_set_if_undefined(USE_SE_JSVM OFF)
endif()
cc_set_if_undefined(USE_V8_DEBUGGER ON)
cc_set_if_undefined(USE_V8_DEBUGGER_FORCE OFF)
cc_set_if_undefined(USE_SOCKET ON)
Expand Down Expand Up @@ -344,21 +347,32 @@ NO_WERROR cocos/audio/common/utils/primitives.cpp
cocos/audio/android/OpenSLHelper.h
cocos/audio/android/PcmAudioPlayer.cpp
cocos/audio/android/PcmAudioPlayer.h
cocos/audio/android/PcmAudioService.cpp
cocos/audio/android/PcmAudioService.h
cocos/audio/android/PcmBufferProvider.cpp
cocos/audio/android/PcmBufferProvider.h
cocos/audio/android/PcmData.cpp
cocos/audio/android/PcmData.h
cocos/audio/android/Track.cpp
cocos/audio/android/Track.h
cocos/audio/android/UrlAudioPlayer.cpp
cocos/audio/android/UrlAudioPlayer.h
cocos/audio/android/utils/Compat.h
cocos/audio/android/utils/Errors.h
cocos/audio/android/utils/Utils.cpp
cocos/audio/android/utils/Utils.h
)
if(ANDROID)
cocos_source_files(
cocos/audio/android/PcmAudioService.cpp
cocos/audio/android/PcmAudioService.h
cocos/audio/android/UrlAudioPlayer.cpp
cocos/audio/android/UrlAudioPlayer.h
)
elseif(OPENHARMONY)
cocos_source_files(
cocos/audio/openharmony/PcmAudioService.cpp
cocos/audio/openharmony/PcmAudioService.h
cocos/audio/openharmony/UrlAudioPlayer.cpp
cocos/audio/openharmony/UrlAudioPlayer.h
)
endif()
elseif(OHOS)
cocos_source_files(
cocos/audio/common/utils/tinysndfile.cpp
Expand Down Expand Up @@ -558,7 +572,9 @@ elseif(OPENHARMONY)
cocos_source_files(
cocos/platform/openharmony/napi/NapiHelper.cpp
cocos/platform/openharmony/napi/NapiHelper.h

cocos/platform/openharmony/napi/NapiValueConverter.cpp
cocos/platform/openharmony/napi/NapiValueConverter.h
cocos/platform/openharmony/napi/native_common.h
cocos/platform/openharmony/WorkerMessageQueue.cpp
cocos/platform/openharmony/WorkerMessageQueue.h
cocos/platform/openharmony/OpenHarmonyPlatform.cpp
Expand Down Expand Up @@ -2575,6 +2591,8 @@ if(ANDROID)
elseif(OPENHARMONY)
cocos_source_files(
cocos/bindings/manual/jsb_platform_openharmony.cpp
cocos/bindings/manual/JavaScriptArkTsBridge.cpp
cocos/bindings/manual/JavaScriptArkTsBridge.h
)
elseif(OHOS)
cocos_source_files(
Expand Down Expand Up @@ -2695,6 +2713,25 @@ if(USE_SE_NAPI)
)
endif()



if(OPENHARMONY AND USE_SE_JSVM)
cocos_source_files(MODULE ccbindings
cocos/bindings/jswrapper/jsvm/Class.cpp
cocos/bindings/jswrapper/jsvm/Class.h
cocos/bindings/jswrapper/jsvm/HelperMacros.cpp
cocos/bindings/jswrapper/jsvm/HelperMacros.h
cocos/bindings/jswrapper/jsvm/Object.cpp
cocos/bindings/jswrapper/jsvm/Object.h
cocos/bindings/jswrapper/jsvm/ScriptEngine.cpp
cocos/bindings/jswrapper/jsvm/ScriptEngine.h
cocos/bindings/jswrapper/jsvm/SeApi.h
cocos/bindings/jswrapper/jsvm/Utils.cpp
cocos/bindings/jswrapper/jsvm/Utils.h
cocos/bindings/jswrapper/jsvm/CommonHeader.h
)
endif()

cocos_source_files(MODULE ccbindings
cocos/bindings/jswrapper/config.h
cocos/bindings/jswrapper/config.cpp
Expand Down Expand Up @@ -3074,6 +3111,7 @@ function(cc_apply_definations target)
$<$<BOOL:${USE_SE_SM}>:SCRIPT_ENGINE_TYPE=1>
$<$<BOOL:${USE_SE_V8}>:SCRIPT_ENGINE_TYPE=2>
$<$<BOOL:${USE_SE_NAPI}>:SCRIPT_ENGINE_TYPE=5>
$<$<BOOL:${USE_SE_JSVM}>:SCRIPT_ENGINE_TYPE=6>
$<$<OR:$<CONFIG:Debug>,$<BOOL:${CC_DEBUG_FORCE}>>:CC_DEBUG=1>
)
endfunction()
Expand Down Expand Up @@ -3267,14 +3305,55 @@ if(OPENHARMONY)

find_library( hilog-lib
hilog_ndk.z )

find_library( libace-lib
libace_ndk.z )

target_link_libraries(${ENGINE_NAME} PUBLIC
${EGL-lib} ${GLESv3-lib} ${hilog-lib} libace_napi.z.so libace_ndk.z.so libz.so libuv.so libnative_drawing.so librawfile.z.so libOpenSLES.so

find_library( # Sets the name of the path variable.
libace-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
ace_ndk.z )
find_library( # Sets the name of the path variable.
libnapi-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
ace_napi.z )
find_library( # Sets the name of the path variable.
libuv-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
uv )
find_library( # Sets the name of the path variable.
rawfile-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
rawfile.z )
set(LIBS
${EGL-lib}
${GLESv3-lib}
${hilog-lib}
${libace-lib}
${libnapi-lib}
${libuv-lib}
${rawfile-lib}
libnative_drawing.so
libc++.a
libOpenSLES.so
libohaudio.so
libavplayer.so
libnative_window.so
libnative_buffer.so
libbundle_ndk.z.so
libace_napi.z.so
libace_ndk.z.so
libz.so
librawfile.z.so
${CC_EXTERNAL_LIBS}
)
if(USE_SE_JSVM)
list(APPEND LIBS libjsvm.so)
endif()

target_link_libraries(${ENGINE_NAME} PUBLIC ${LIBS})

endif()

if(APPLE)
Expand Down
69 changes: 40 additions & 29 deletions native/cocos/audio/android/AudioEngine-inl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ AudioEngineImpl *gAudioImpl = nullptr;
int outputSampleRate = 44100;
#if CC_PLATFORM == CC_PLATFORM_ANDROID
int bufferSizeInFrames = 192;
#elif CC_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

void getAudioInfo() {
Expand Down Expand Up @@ -129,7 +125,7 @@ static int fdGetter(const ccstd::string &url, off_t *start, off_t *length) {
#elif CC_PLATFORM == CC_PLATFORM_OPENHARMONY
FileUtilsOpenHarmony* fileUtils = dynamic_cast<FileUtilsOpenHarmony*>(FileUtils::getInstance());
if(fileUtils) {
RawFileDescriptor descriptor;
RawFileDescriptor64 descriptor;
fileUtils->getRawFileDescriptor(url, descriptor);
fd = descriptor.fd;
}
Expand Down Expand Up @@ -193,25 +189,27 @@ bool AudioEngineImpl::init() {
CC_LOG_ERROR("get the engine interface fail");
break;
}

// create output mix
const SLInterfaceID outputMixIIDs[] = {};
const SLboolean outputMixReqs[] = {};
result = (*_engineEngine)->CreateOutputMix(_engineEngine, &_outputMixObject, 0, outputMixIIDs, outputMixReqs);
if (SL_RESULT_SUCCESS != result) {
CC_LOG_ERROR("create output mix fail");
break;
}

// realize the output mix
result = (*_outputMixObject)->Realize(_outputMixObject, SL_BOOLEAN_FALSE);
if (SL_RESULT_SUCCESS != result) {
CC_LOG_ERROR("realize the output mix fail");
break;
}

_audioPlayerProvider = ccnew AudioPlayerProvider(_engineEngine, _outputMixObject, outputSampleRate, bufferSizeInFrames, fdGetter, &gCallerThreadUtils);

#if CC_PLATFORM == CC_PLATFORM_ANDROID
// create output mix
const SLInterfaceID outputMixIIDs[] = {};
const SLboolean outputMixReqs[] = {};
result = (*_engineEngine)->CreateOutputMix(_engineEngine, &_outputMixObject, 0, outputMixIIDs, outputMixReqs);
if (SL_RESULT_SUCCESS != result) {
CC_LOG_ERROR("create output mix fail");
break;
}

// realize the output mix
result = (*_outputMixObject)->Realize(_outputMixObject, SL_BOOLEAN_FALSE);
if (SL_RESULT_SUCCESS != result) {
CC_LOG_ERROR("realize the output mix fail");
break;
}

_audioPlayerProvider = ccnew AudioPlayerProvider(_engineEngine, _outputMixObject, outputSampleRate, bufferSizeInFrames, fdGetter, &gCallerThreadUtils);
#elif CC_PLATFORM == CC_PLATFORM_OPENHARMONY
_audioPlayerProvider = ccnew AudioPlayerProvider(_engineEngine, outputSampleRate, fdGetter, &gCallerThreadUtils);
#endif
ret = true;
} while (false);

Expand All @@ -229,9 +227,14 @@ int AudioEngineImpl::play2d(const ccstd::string &filePath, bool loop, float volu
auto audioId = AudioEngine::INVALID_AUDIO_ID;

do {
if (_engineEngine == nullptr || _audioPlayerProvider == nullptr) {
break;
}
#if CC_PLATFORM == CC_PLATFORM_ANDROID
if (_engineEngine == nullptr || _audioPlayerProvider == nullptr) {
break;
}
#elif CC_PLATFORM == CC_PLATFORM_OPENHARMONY
if (_audioPlayerProvider == nullptr)
break;
#endif

auto fullPath = FileUtils::getInstance()->fullPathForFilename(filePath);

Expand Down Expand Up @@ -434,9 +437,12 @@ PCMHeader AudioEngineImpl::getPCMHeader(const char *url) {
CC_LOG_DEBUG("file %s pcm data already cached", url);
return header;
}

#if CC_PLATFORM == CC_PLATFORM_ANDROID
AudioDecoder *decoder = AudioDecoderProvider::createAudioDecoder(_engineEngine, fileFullPath, bufferSizeInFrames, outputSampleRate, fdGetter);

#elif CC_PLATFORM == CC_PLATFORM_OPENHARMONY
AudioDecoder *decoder = AudioDecoderProvider::createAudioDecoder(
_engineEngine, fileFullPath, _audioPlayerProvider->getBufferSizeInFrames(), outputSampleRate, fdGetter);
#endif
if (decoder == nullptr) {
CC_LOG_DEBUG("decode %s failed, the file formate might not support", url);
return header;
Expand Down Expand Up @@ -470,7 +476,12 @@ ccstd::vector<uint8_t> AudioEngineImpl::getOriginalPCMBuffer(const char *url, ui
if (_audioPlayerProvider->getPcmData(url, data)) {
CC_LOG_DEBUG("file %s pcm data already cached", url);
} else {
#if CC_PLATFORM == CC_PLATFORM_ANDROID
AudioDecoder *decoder = AudioDecoderProvider::createAudioDecoder(_engineEngine, fileFullPath, bufferSizeInFrames, outputSampleRate, fdGetter);
#else
AudioDecoder *decoder = AudioDecoderProvider::createAudioDecoder(
_engineEngine, fileFullPath, _audioPlayerProvider->getBufferSizeInFrames(), outputSampleRate, fdGetter);
#endif
if (decoder == nullptr) {
CC_LOG_DEBUG("decode %s failed, the file formate might not support", url);
return pcmData;
Expand Down
4 changes: 4 additions & 0 deletions native/cocos/audio/android/AudioMixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ static inline audio_format_t selectMixerInFormat(audio_format_t inputFormat __un
return kUseFloat && kUseNewMixer ? AUDIO_FORMAT_PCM_FLOAT : AUDIO_FORMAT_PCM_16_BIT;
}

void AudioMixer::setBufferSize(size_t size) {
mState.frameCount = size;
}

int AudioMixer::getTrackName(audio_channel_mask_t channelMask,
audio_format_t format, int sessionId) {
if (!isValidPcmTrackFormat(format)) {
Expand Down
1 change: 1 addition & 0 deletions native/cocos/audio/android/AudioMixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class AudioMixer {
void setParameter(int name, int target, int param, void *value);

void setBufferProvider(int name, AudioBufferProvider *bufferProvider);
void setBufferSize(size_t size);
void process(int64_t pts);

uint32_t trackNames() const { return mTrackNames; }
Expand Down
Loading
Loading