Skip to content
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,34 @@
"group": "build",
"problemMatcher": "$gcc"
},
{
"label": "Enable 16KB Page Size",
"type": "shell",
"command": "bash",
"args": [
"tasks.sh",
"--enable-16kb-page-size"
],
"options": {
"cwd": "${workspaceFolder}"
},
"group": "build",
"problemMatcher": "$gcc"
},
{
"label": "Disable 16KB Page Size",
"type": "shell",
"command": "bash",
"args": [
"tasks.sh",
"--disable-16kb-page-size"
],
"options": {
"cwd": "${workspaceFolder}"
},
"group": "build",
"problemMatcher": "$gcc"
},
{
"label": "Setup Gradle Project",
"type": "shell",
Expand Down
33 changes: 24 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,36 @@ allprojects {
repositories {
maven {
// Use github hosted maven repo for now.
// Will be uploaded to maven central later.
// Repo url: https://github.com/wysaid/android-gpuimage-plus-maven
url 'https://maven.wysaid.org/'
}
}
}

//Choose only one of them
// Choose only one of them
dependencies {
//All arch: armeabi-v7a, arm64-v8a, x86, x86_64 with video module (ffmpeg bundled)
implementation 'org.wysaid:gpuimage-plus:3.0.0'

//All arch: armeabi-v7a, arm64-v8a, x86, x86_64 without video module (no ffmpeg)
implementation 'org.wysaid:gpuimage-plus:3.0.0-min'
// Page size: 4KB (default)
// Architectures: armeabi-v7a, arm64-v8a, x86, x86_64
// Full-featured with FFmpeg bundled
implementation 'org.wysaid:gpuimage-plus:3.1.0'

// Page size: 16KB
// Architectures: armeabi-v7a, arm64-v8a, x86, x86_64
// Full-featured with FFmpeg bundled
implementation 'org.wysaid:gpuimage-plus:3.1.0-16k'

// Page size: 4KB (default)
// Architectures: armeabi-v7a, arm64-v8a, x86, x86_64
// Image-only version (no video features or FFmpeg)
implementation 'org.wysaid:gpuimage-plus:3.1.0-min'

// Page size: 16KB
// Architectures: armeabi-v7a, arm64-v8a, x86, x86_64
// Image-only version (no video features or FFmpeg)
implementation 'org.wysaid:gpuimage-plus:3.1.0-16k-min'
}
```

> __The jcenter is out of date, please try the source for now. Latest prebuilt versions will be provided soon.__

> To compile other versions of ffmpeg, see: <https://github.com/wysaid/FFmpeg-Android.git>

## Build
Expand Down Expand Up @@ -80,6 +92,9 @@ dependencies {
export NDK=path/of/your/ndk
cd folder/of/jni (android-gpuimage-plus/library/src/main/jni)

# Enable 16kb page sizes (optional)
export CGE_ENABLE_16KB_PAGE_SIZE=1

#This will make all arch: armeabi, armeabi-v7a arm64-v8a, x86, mips
./buildJNI
#Or use "sh buildJNI"
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ ext {
minSdkVersion : 21,
targetSdkVersion : 25, // higher target version needs more storage permission request.
versionCode : 2,
versionName : "3.0.0",
versionName : "3.1.0",
applicationId : "org.wysaid.cgeDemo",
appcompatX : "1.2.0",
ndkVersion : "26.3.11579264",
Expand Down
15 changes: 11 additions & 4 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,16 @@ if (deployArtifacts()) {
def gitUrl = 'https://github.com/wysaid/android-gpuimage-plus.git'
group = "org.wysaid"

if (disableVideoModule()) {
version = rootProject.ext.android.versionName + '-min'
if (enable16kPageSizes()) {
version = rootProject.ext.android.versionName + '-16k'
} else {
version = rootProject.ext.android.versionName
}

if (disableVideoModule()) {
version += '-min'
}

publishing {
publications {
release(MavenPublication) {
Expand All @@ -143,8 +147,11 @@ if (deployArtifacts()) {
version = version

afterEvaluate {
from components.findByName('release')
// artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")
// Use the correct Android component
from components.findByName('release') ?: components.findByName('default')

// Ensure the AAR file is included and declare the correct dependencies
artifact bundleReleaseAar
}

pom {
Expand Down
15 changes: 11 additions & 4 deletions library/src/main/jni/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ LOCAL_SRC_FILES := \
LOCAL_CPPFLAGS := -frtti -std=c++14
LOCAL_LDLIBS := -llog -lEGL -lGLESv2 -ljnigraphics

ifdef CGE_ENABLE_16KB_PAGE_SIZE
LOCAL_LDFLAGS += "-Wl,-z,max-page-size=16384"
endif

# 'CGE_USE_VIDEO_MODULE' determines if the project should compile with ffmpeg.

ifdef CGE_USE_VIDEO_MODULE
Expand Down Expand Up @@ -161,10 +165,13 @@ LOCAL_CFLAGS := -mfloat-abi=softfp -mfpu=vfp -Os -ffast-math -fPIC
ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
LOCAL_CFLAGS := $(LOCAL_CFLAGS) march=armv7-a -mfpu=neon
endif
LOCAL_SRC_FILES := ffmpeg/$(TARGET_ARCH_ABI)/libffmpeg.so
LOCAL_EXPORT_C_INCLUDES := $(CGE_ROOT)/ffmpeg

# LOCAL_SHARED_LIBRARIES := x264
ifdef CGE_ENABLE_16KB_PAGE_SIZE
LOCAL_SRC_FILES := ffmpeg-16kb/libs/$(TARGET_ARCH_ABI)/libffmpeg.so
LOCAL_EXPORT_C_INCLUDES := $(CGE_ROOT)/ffmpeg-16kb/include
else
LOCAL_SRC_FILES := ffmpeg/libs/$(TARGET_ARCH_ABI)/libffmpeg.so
LOCAL_EXPORT_C_INCLUDES := $(CGE_ROOT)/ffmpeg/include
endif

include $(PREBUILT_SHARED_LIBRARY)

Expand Down
6 changes: 5 additions & 1 deletion library/src/main/jni/Application.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ APP_STL := c++_static
#APP_CPPFLAGS := -fpermissive
APP_CPPFLAGS := -frtti -std=c++14

APP_OPTIM := release
APP_OPTIM := release

ifdef CGE_ENABLE_16KB_PAGE_SIZE
APP_SUPPORT_FLEXIBLE_PAGE_SIZES := true
endif
161 changes: 82 additions & 79 deletions library/src/main/jni/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ set(CMAKE_CXX_STANDARD 14)

option(CGE_USE_VIDEO_MODULE "boolean option to enable video module" OFF)

if (NOT DEFINED ANDROID_GRADLE OR NOT ANDROID_GRADLE)
if (NOT DEFINED ENV{NDK})
execute_process(COMMAND which ndk-build OUTPUT_VARIABLE CGE_NDK_DIR)
if ("${CGE_NDK_DIR}" STREQUAL "")
if(NOT DEFINED ANDROID_GRADLE OR NOT ANDROID_GRADLE)
if(NOT DEFINED ENV{NDK})
execute_process(COMMAND which ndk-build OUTPUT_VARIABLE CGE_NDK_BUILD_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)

if("${CGE_NDK_BUILD_PATH}" STREQUAL "")
message(FATAL_ERROR "You should define the NDK variable!")
else ()
execute_process(COMMAND export NDK=$ (dirname `which ndk-build`))
endif ()
endif ()
else()
get_filename_component(CGE_NDK_DIR "${CGE_NDK_BUILD_PATH}" DIRECTORY)
set(ENV{NDK} "${CGE_NDK_DIR}")
message(STATUS "Auto-detected NDK path: ${CGE_NDK_DIR}")
endif()
endif()

execute_process(COMMAND bash ${CMAKE_CURRENT_SOURCE_DIR}/setup_android_toolchain)

Expand All @@ -28,99 +31,99 @@ if (NOT DEFINED ANDROID_GRADLE OR NOT ANDROID_GRADLE)
set(CMAKE_SYSROOT ${NDK_STANDALONE_TOOLCHAIN}/sysroot)
set(CMAKE_FIND_ROOT_PATH ${NDK_STANDALONE_TOOLCHAIN})

if (DEFINED NDK_STANDALONE_TOOLCHAIN)
if(DEFINED NDK_STANDALONE_TOOLCHAIN)
set(NDK_INCLUDE_DIR ${NDK_STANDALONE_TOOLCHAIN}/sysroot/usr/include)
if (EXISTS ${NDK_STANDALONE_TOOLCHAIN}/sysroot/usr/include/aarch64-linux-android)

if(EXISTS ${NDK_STANDALONE_TOOLCHAIN}/sysroot/usr/include/aarch64-linux-android)
set(NDK_INCLUDE_DIR ${NDK_INCLUDE_DIR}
${NDK_STANDALONE_TOOLCHAIN}/sysroot/usr/include/aarch64-linux-android)
endif ()
include_directories(${NDK_INCLUDE_DIR})
endif ()
endif ()
${NDK_STANDALONE_TOOLCHAIN}/sysroot/usr/include/aarch64-linux-android)
endif()

if (NOT DEFINED ANDROID_ABI)
add_definitions(-DANDROID_ABI=arm64-v8a)
else ()
add_definitions(-DANDROID_ABI=${ANDROID_ABI})
file(MAKE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../libs/${ANDROID_ABI}")
endif ()
include_directories(${NDK_INCLUDE_DIR})
endif()
endif()

if (CMAKE_HOST_SYSTEM_NAME MATCHES "Windows")
if(CMAKE_HOST_SYSTEM_NAME MATCHES "Windows")
execute_process(COMMAND cmd.exe /C "dir /L /S /B /A:D"
OUTPUT_VARIABLE CGE_CORE_HEADER_DIR
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/cge)
else ()
OUTPUT_VARIABLE CGE_CORE_HEADER_DIR
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/cge)
else()
execute_process(COMMAND find ${CMAKE_CURRENT_SOURCE_DIR}/cge -maxdepth 3 -type d OUTPUT_VARIABLE CGE_CORE_HEADER_DIR)
endif ()
endif()

message(STATUS "CGE_CORE_HEADER_DIR=${CGE_CORE_HEADER_DIR}")
string(REGEX REPLACE "\n" ";" CGE_CORE_HEADER_DIR ${CGE_CORE_HEADER_DIR})

file(GLOB_RECURSE CGE_CORE_SRC "${CMAKE_CURRENT_SOURCE_DIR}/cge/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/cge/*.c"
"${CMAKE_CURRENT_SOURCE_DIR}/interface/*.cpp")
"${CMAKE_CURRENT_SOURCE_DIR}/cge/*.c"
"${CMAKE_CURRENT_SOURCE_DIR}/interface/*.cpp")

if(NOT DEFINED ANDROID_GRADLE OR NOT ANDROID_GRADLE)
add_library(CGE ${CGE_CORE_SRC})
else()
add_library(CGE SHARED ${CGE_CORE_SRC})
endif()

target_include_directories(CGE PUBLIC
${CGE_CORE_HEADER_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/cge/common
${CMAKE_CURRENT_SOURCE_DIR}/cge/extends
${CMAKE_CURRENT_SOURCE_DIR}/cge/filters
${CMAKE_CURRENT_SOURCE_DIR}/interface
${CMAKE_CURRENT_SOURCE_DIR}/custom)

if(NOT DEFINED ANDROID_ABI)
target_compile_definitions(CGE PUBLIC ANDROID_ABI=arm64-v8a)
else()
target_compile_definitions(CGE PUBLIC ANDROID_ABI=${ANDROID_ABI})
endif()

target_compile_definitions(CGE PUBLIC ANDROID_NDK=1 CGE_LOG_TAG=\"libCGE\" CGE_TEXTURE_PREMULTIPLIED=1 _CGE_DISABLE_GLOBALCONTEXT_=1 _CGE_ONLY_FILTERS_=1)

# 非 Debug 模式下添加 -O3
target_compile_options(CGE PRIVATE $<$<NOT:$<CONFIG:Debug>>:-O3>)

include_directories(
${CGE_CORE_HEADER_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/cge/common
${CMAKE_CURRENT_SOURCE_DIR}/cge/extends
${CMAKE_CURRENT_SOURCE_DIR}/cge/filters
${CMAKE_CURRENT_SOURCE_DIR}/interface
${CMAKE_CURRENT_SOURCE_DIR}/custom
${CMAKE_CURRENT_SOURCE_DIR}/ffmpeg)
target_link_options(CGE PUBLIC -fPIE -fPIC -pie -Wl,-z,relro,-z,now)

add_definitions(-DANDROID_NDK=1 -DCGE_LOG_TAG=\"libCGE\" -DCGE_TEXTURE_PREMULTIPLIED=1 -D_CGE_DISABLE_GLOBALCONTEXT_ -O3 -D_CGE_ONLY_FILTERS_=1)
target_link_libraries(CGE PUBLIC
GLESv2
EGL
jnigraphics
log
android)

if (CGE_USE_VIDEO_MODULE)
if(DEFINED ENABLE_16K_PAGE_SIZES AND ENABLE_16K_PAGE_SIZES)
# 16KB elf: <https://developer.android.com/guide/practices/page-sizes#cmake>
target_link_options(CGE PUBLIC -Wl,-z,max-page-size=16384,-z,common-page-size=16384)
message("ENABLE_16K_PAGE_SIZES=${ENABLE_16K_PAGE_SIZES}")
endif()

# ffmpeg ref
# ########### Video module ############
if(CGE_USE_VIDEO_MODULE)
add_library(ffmpeg SHARED IMPORTED)

if(ENABLE_16K_PAGE_SIZES)
set(FFMPEG_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ffmpeg-16kb")
else()
set(FFMPEG_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ffmpeg")
endif()

target_include_directories(CGE PUBLIC ${FFMPEG_DIR}/include)
target_compile_definitions(CGE PUBLIC CGE_USE_FFMPEG=1)

set_target_properties(ffmpeg PROPERTIES IMPORTED_LOCATION
${CMAKE_CURRENT_SOURCE_DIR}/ffmpeg/${ANDROID_ABI}/libffmpeg.so)
${FFMPEG_DIR}/libs/${ANDROID_ABI}/libffmpeg.so)

set(CGE_VIDEO_MODULE "ffmpeg")
add_definitions(-DCGE_USE_FFMPEG=1)
endif ()
target_link_libraries(CGE PUBLIC ffmpeg)
endif()

message("CGE_USE_VIDEO_MODULE=${CGE_USE_VIDEO_MODULE}")

if (NOT DEFINED ANDROID_GRADLE OR NOT ANDROID_GRADLE)
add_library(CGE
${CGE_CORE_SRC}
)
else ()
add_library(CGE SHARED
${CGE_CORE_SRC}
)
endif ()

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/custom)
# ########### ext module ############
file(GLOB_RECURSE CGE_EXT_SRC "${CMAKE_CURRENT_SOURCE_DIR}/custom/*.cpp")

add_library(CGEExt SHARED ${CGE_EXT_SRC})

target_link_options(CGE PUBLIC -fPIE -fPIC -pie -Wl,-z,relro,-z,now)
target_include_directories(CGEExt PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/custom)

if (DEFINED ENABLE_16K_PAGE_SIZES AND ENABLE_16K_PAGE_SIZES)
# 16KB elf: <https://developer.android.com/guide/practices/page-sizes#cmake>
target_link_options(CGE PUBLIC -Wl,-z,max-page-size=16384)
message("ENABLE_16K_PAGE_SIZES=${ENABLE_16K_PAGE_SIZES}")
endif ()

target_link_libraries(CGE
${CGE_VIDEO_MODULE}
GLESv2
EGL
jnigraphics
log
android
)

target_link_libraries(CGEExt
CGE
${CGE_VIDEO_MODULE}
GLESv2
EGL
jnigraphics
log
android)
target_link_libraries(CGEExt PRIVATE
CGE)
10 changes: 9 additions & 1 deletion library/src/main/jni/buildJNI
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,15 @@ while [[ $# -gt 0 ]]; do
export CGE_NO_VIDEO_MODULE=1
shift
;;

--16kb | --16KB)
export CGE_ENABLE_16KB_PAGE_SIZE=1
echo "16kb page size enabled!"
shift
;;
*)
echo "Unknown option: $PARSE_KEY"
shift
;;
esac

done
Expand Down
Loading