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

V4 support openharmony #20793

Open
wants to merge 5 commits into
base: v4-oh
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
10 changes: 10 additions & 0 deletions cmake/Modules/CocosConfigDefine.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ endif()
#IOS = iOS
#MACOSX = MacOS X
#LINUX = Linux
#OHOS = OHOS
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set(WINDOWS TRUE)
set(PLATFORM_FOLDER win32)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Android")
set(PLATFORM_FOLDER android)
elseif(CMAKE_SYSTEM_NAME MATCHES "OHOS")
set(PLATFORM_FOLDER ohos)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
if(ANDROID)
set(PLATFORM_FOLDER android)
Expand Down Expand Up @@ -60,7 +63,11 @@ define_property(TARGET
# check c++ standard
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
if(OHOS)
set(CMAKE_CXX_STANDARD 14)
else()
set(CMAKE_CXX_STANDARD 11)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

Expand Down Expand Up @@ -92,6 +99,9 @@ endif()
elseif(ANDROID)
target_compile_definitions(${target} PUBLIC ANDROID)
target_compile_definitions(${target} PUBLIC USE_FILE32API)
elseif(OHOS)
target_compile_definitions(${target} PUBLIC OHOS)
target_compile_definitions(${target} PUBLIC USE_FILE32API)
elseif(WINDOWS)
target_compile_definitions(${target}
PUBLIC WIN32
Expand Down
4 changes: 2 additions & 2 deletions cmake/Modules/CocosConfigDepend.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ macro(cocos2dx_depend)
set(THREADS_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
elseif(ANDROID)
list(APPEND PLATFORM_SPECIFIC_LIBS GLESv2 EGL log android OpenSLES)
elseif(OHOS)
list(APPEND PLATFORM_SPECIFIC_LIBS native_drawing EGL GLESv3 hilog_ndk.z ace_ndk.z ace_napi.z uv rawfile.z OpenSLES)
elseif(APPLE)

include_directories(/System/Library/Frameworks)
Expand Down Expand Up @@ -69,8 +71,6 @@ macro(cocos2dx_depend)
find_library(CORE_GRAPHICS_LIBRARY CoreGraphics)
find_library(AV_FOUNDATION_LIBRARY AVFoundation)
find_library(WEBKIT_LIBRARY WebKit)
find_library(ZLIB_LIBRARY z)
find_library(ICONV_LIBRARY iconv)
list(APPEND PLATFORM_SPECIFIC_LIBS
${UIKIT_LIBRARY}
${OPENGLES_LIBRARY}
Expand Down
2 changes: 2 additions & 0 deletions cocos/audio/AudioEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
#include "audio/win32/AudioEngine-win32.h"
#elif CC_TARGET_PLATFORM == CC_PLATFORM_LINUX
#include "audio/linux/AudioEngine-linux.h"
#elif CC_TARGET_PLATFORM == CC_PLATFORM_OHOS
#include "audio/ohos/AudioEngine-inl.h"
#endif

#define TIME_DELAY_PRECISION 0.0001
Expand Down
72 changes: 72 additions & 0 deletions cocos/audio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,78 @@ elseif(ANDROID)
audio/android/tinysndfile.cpp
)

elseif(OHOS)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does OHOS mean harmonyOS or openharmony? It's really confused to me.
Look at this in Cocos Creator: https://github.com/cocos/cocos-engine/blob/v3.8.2/native/CMakeLists.txt#L114

In Cocos Creator, OHOS macro is for HarmonyOS while OPENHARMONY macro is for openharmony OS.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OHOS mean OpenHarmony OS

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HarmonyOS should be HMOS

set(COCOS_AUDIO_PLATFORM_HEADER
audio/ohos/PcmAudioService.h
audio/ohos/AudioBufferProvider.h
audio/ohos/IAudioPlayer.h
audio/ohos/AudioResampler.h
audio/ohos/AudioDecoder.h
audio/ohos/AudioResamplerPublic.h
audio/ohos/AudioMixer.h
audio/ohos/tinysndfile.h
audio/ohos/mp3reader.h
audio/ohos/AudioMixerOps.h
audio/ohos/cutils/bitops.h
audio/ohos/cutils/log.h
audio/ohos/audio.h
audio/ohos/AudioPlayerProvider.h
audio/ohos/utils/Utils.h
audio/ohos/utils/Errors.h
audio/ohos/utils/Compat.h
audio/ohos/AudioDecoderOgg.h
audio/ohos/Track.h
audio/ohos/OpenSLHelper.h
audio/ohos/PcmAudioPlayer.h
audio/ohos/AssetFd.h
audio/ohos/PcmBufferProvider.h
audio/ohos/CCThreadPool.h
audio/ohos/audio_utils/include/audio_utils/minifloat.h
audio/ohos/audio_utils/include/audio_utils/primitives.h
audio/ohos/audio_utils/AudioDef.h
audio/ohos/audio_utils/RefCounted.h
audio/ohos/ICallerThreadUtils.h
audio/ohos/AudioDecoderWav.h
audio/ohos/AudioDecoderProvider.h
audio/ohos/UrlAudioPlayer.h
audio/ohos/AudioDecoderSLES.h
audio/ohos/AudioDecoderMp3.h
audio/ohos/PcmData.h
audio/ohos/AudioMixerController.h
audio/ohos/AudioResamplerCubic.h
audio/ohos/AudioEngine-inl.h
audio/ohos/IVolumeProvider.h
audio/ohos/Macros.h
)

set(COCOS_AUDIO_PLATFORM_SRC
audio/ohos/AudioEngine-inl.cpp
audio/ohos/CCThreadPool.cpp
audio/ohos/AssetFd.cpp
audio/ohos/AudioDecoder.cpp
audio/ohos/AudioDecoderProvider.cpp
audio/ohos/AudioDecoderSLES.cpp
audio/ohos/AudioDecoderOgg.cpp
audio/ohos/AudioDecoderMp3.cpp
audio/ohos/AudioDecoderWav.cpp
audio/ohos/AudioPlayerProvider.cpp
audio/ohos/AudioResampler.cpp
audio/ohos/AudioResamplerCubic.cpp
audio/ohos/PcmBufferProvider.cpp
audio/ohos/PcmAudioPlayer.cpp
audio/ohos/PcmData.cpp
audio/ohos/PcmAudioService.cpp
audio/ohos/UrlAudioPlayer.cpp
audio/ohos/AudioMixerController.cpp
audio/ohos/AudioMixer.cpp
audio/ohos/mp3reader.cpp
audio/ohos/tinysndfile.cpp
audio/ohos/Track.cpp
audio/ohos/audio_utils/RefCounted.cpp
audio/ohos/audio_utils/minifloat.cpp
audio/ohos/audio_utils/primitives.cpp
audio/ohos/utils/Utils.cpp
)
elseif(LINUX)
set(COCOS_AUDIO_PLATFORM_HEADER
audio/linux/AudioEngine-linux.h
Expand Down
45 changes: 45 additions & 0 deletions cocos/audio/ohos/AssetFd.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/****************************************************************************
Copyright (c) 2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 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.
****************************************************************************/

#define LOG_TAG "AssetFd"

#include "cutils/log.h"
#include "AssetFd.h"

namespace cocos2d {

AssetFd::AssetFd(int assetFd)
: _assetFd(assetFd) {
}

AssetFd::~AssetFd() {
ALOGV("~AssetFd: %d", _assetFd);
if (_assetFd > 0) {
::close(_assetFd);
_assetFd = 0;
}
};

} // namespace cocos2d
42 changes: 42 additions & 0 deletions cocos/audio/ohos/AssetFd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/****************************************************************************
Copyright (c) 2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 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.
****************************************************************************/
#pragma once

#include <unistd.h>

namespace cocos2d {

class AssetFd {
public:
AssetFd(int assetFd);
~AssetFd();

inline int getFd() const { return _assetFd; };

private:
int _assetFd;
};

} // namespace CocosDenshion
62 changes: 62 additions & 0 deletions cocos/audio/ohos/AudioBufferProvider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#pragma once

#include <stddef.h>
#include <stdint.h>
#include "utils/Errors.h"

namespace cocos2d {
// ----------------------------------------------------------------------------

class AudioBufferProvider {
public:
// IDEA: merge with AudioTrackShared::Buffer, AudioTrack::Buffer, and AudioRecord::Buffer
// and rename getNextBuffer() to obtainBuffer()
struct Buffer {
Buffer() : raw(NULL), frameCount(0) {}
union {
void *raw;
short *i16;
int8_t *i8;
};
size_t frameCount;
};

virtual ~AudioBufferProvider() {}

// value representing an invalid presentation timestamp
static const int64_t kInvalidPTS = 0x7FFFFFFFFFFFFFFFLL; // <stdint.h> is too painful

// pts is the local time when the next sample yielded by getNextBuffer
// will be rendered.
// Pass kInvalidPTS if the PTS is unknown or not applicable.
// On entry:
// buffer != NULL
// buffer->raw unused
// buffer->frameCount maximum number of desired frames
// On successful return:
// status NO_ERROR
// buffer->raw non-NULL pointer to buffer->frameCount contiguous available frames
// buffer->frameCount number of contiguous available frames at buffer->raw,
// 0 < buffer->frameCount <= entry value
// On error return:
// status != NO_ERROR
// buffer->raw NULL
// buffer->frameCount 0
virtual status_t getNextBuffer(Buffer *buffer, int64_t pts = kInvalidPTS) = 0;

// Release (a portion of) the buffer previously obtained by getNextBuffer().
// It is permissible to call releaseBuffer() multiple times per getNextBuffer().
// On entry:
// buffer->frameCount number of frames to release, must be <= number of frames
// obtained but not yet released
// buffer->raw unused
// On return:
// buffer->frameCount 0; implementation MUST set to zero
// buffer->raw undefined; implementation is PERMITTED to set to any value,
// so if caller needs to continue using this buffer it must
// keep track of the pointer itself
virtual void releaseBuffer(Buffer *buffer) = 0;
};

// ----------------------------------------------------------------------------
} // namespace CocosDenshion
Loading