From 5154f43b58ce10011e3b8e9bc0967a16fbb876e1 Mon Sep 17 00:00:00 2001 From: "L. E. Segovia" Date: Sat, 9 Nov 2024 21:57:38 -0300 Subject: [PATCH] examples: Port Android examples to CMake Part-of: --- .../playback/player/android/app/.gitignore | 2 + .../playback/player/android/app/build.gradle | 11 ++--- .../android/app/src/main/jni/CMakeLists.txt | 45 +++++++++++++++++ .../gst-examples/vulkan/android/.gitignore | 2 + .../gst-examples/vulkan/android/build.gradle | 12 ++--- .../vulkan/android/jni/CMakeLists.txt | 44 +++++++++++++++++ .../webrtc/android/app/.gitignore | 2 + .../webrtc/android/app/build.gradle | 8 ++-- .../android/app/src/main/jni/CMakeLists.txt | 48 +++++++++++++++++++ 9 files changed, 158 insertions(+), 16 deletions(-) create mode 100644 subprojects/gst-examples/playback/player/android/app/src/main/jni/CMakeLists.txt create mode 100644 subprojects/gst-examples/vulkan/android/jni/CMakeLists.txt create mode 100644 subprojects/gst-examples/webrtc/android/app/src/main/jni/CMakeLists.txt diff --git a/subprojects/gst-examples/playback/player/android/app/.gitignore b/subprojects/gst-examples/playback/player/android/app/.gitignore index 04be8f69ca..7fc62c5a26 100644 --- a/subprojects/gst-examples/playback/player/android/app/.gitignore +++ b/subprojects/gst-examples/playback/player/android/app/.gitignore @@ -1,5 +1,7 @@ +.cxx/ .externalNativeBuild/ assets/ gst-android-build/ src/main/java/org/freedesktop/gstreamer/GStreamer.java +src/main/java/org/freedesktop/gstreamer/Gst*.java src/main/java/org/freedesktop/gstreamer/androidmedia/ diff --git a/subprojects/gst-examples/playback/player/android/app/build.gradle b/subprojects/gst-examples/playback/player/android/app/build.gradle index 58e4a9b70e..628b395c6d 100644 --- a/subprojects/gst-examples/playback/player/android/app/build.gradle +++ b/subprojects/gst-examples/playback/player/android/app/build.gradle @@ -11,7 +11,7 @@ android { versionName "1.0" externalNativeBuild { - ndkBuild { + cmake { def gstRoot if (project.hasProperty('gstAndroidRoot')) @@ -22,13 +22,12 @@ android { if (gstRoot == null) throw new GradleException('GSTREAMER_ROOT_ANDROID must be set, or "gstAndroidRoot" must be defined in your gradle.properties in the top level directory of the unpacked universal GStreamer Android binaries') - arguments "NDK_APPLICATION_MK=src/main/jni/Application.mk", "GSTREAMER_JAVA_SRC_DIR=src/main/java", "GSTREAMER_ROOT_ANDROID=$gstRoot", "GSTREAMER_ASSETS_DIR=src/main/assets" + arguments "-DCMAKE_BUILD_TYPE=Release", "-DANDROID_STL=c++_shared", "-DGStreamer_JAVA_SRC_DIR=java", "-DGSTREAMER_ROOT_ANDROID=$gstRoot", "-DGStreamer_ASSETS_DIR=assets" targets "gstplayer" // All archs except MIPS and MIPS64 are supported - abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86' - // x86_64 abis disabled because of https://bugzilla.gnome.org/show_bug.cgi?id=795454 + abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64' } } } @@ -41,8 +40,8 @@ android { } externalNativeBuild { - ndkBuild { - path 'src/main/jni/Android.mk' + cmake { + path 'src/main/jni/CMakeLists.txt' } } ndkVersion '25.2.9519653' diff --git a/subprojects/gst-examples/playback/player/android/app/src/main/jni/CMakeLists.txt b/subprojects/gst-examples/playback/player/android/app/src/main/jni/CMakeLists.txt new file mode 100644 index 0000000000..79bdf8b80f --- /dev/null +++ b/subprojects/gst-examples/playback/player/android/app/src/main/jni/CMakeLists.txt @@ -0,0 +1,45 @@ +cmake_minimum_required(VERSION 3.18.1) + +project("android-player" LANGUAGES C CXX) + +if(NOT DEFINED GSTREAMER_ROOT_ANDROID) + message(FATAL_ERROR "GSTREAMER_ROOT_ANDROID is not defined!") +endif() + +if(ANDROID_ABI STREQUAL "armeabi") + set(GSTREAMER_ROOT "${GSTREAMER_ROOT_ANDROID}/arm") +elseif(ANDROID_ABI STREQUAL "armeabi-v7a") + set(GSTREAMER_ROOT "${GSTREAMER_ROOT_ANDROID}/armv7") +elseif(ANDROID_ABI STREQUAL "arm64-v8a") + set(GSTREAMER_ROOT "${GSTREAMER_ROOT_ANDROID}/arm64") +elseif(ANDROID_ABI STREQUAL "x86") + set(GSTREAMER_ROOT "${GSTREAMER_ROOT_ANDROID}/x86") +elseif(ANDROID_ABI STREQUAL "x86_64") + set(GSTREAMER_ROOT "${GSTREAMER_ROOT_ANDROID}/x86_64") +else() + message(FATAL_ERROR "Target arch ABI not supported: ${ANDROID_ABI}") +endif() + +list(APPEND CMAKE_MODULE_PATH "${GSTREAMER_ROOT}/share/cmake") + +set(GSTREAMER_NDK_BUILD_PATH "${GSTREAMER_ROOT}/share/gst-android/ndk-build/") +include("${GSTREAMER_NDK_BUILD_PATH}/plugins.cmake") +set(GSTREAMER_PLUGINS ${GSTREAMER_PLUGINS_CORE} ${GSTREAMER_PLUGINS_PLAYBACK} ${GSTREAMER_PLUGINS_CODECS} ${GSTREAMER_PLUGINS_NET} ${GSTREAMER_PLUGINS_SYS} ${GSTREAMER_PLUGINS_CODECS_RESTRICTED} ${GSTREAMER_CODECS_GPL} ${GSTREAMER_PLUGINS_ENCODING} ${GSTREAMER_PLUGINS_VIS} ${GSTREAMER_PLUGINS_EFFECTS} ${GSTREAMER_PLUGINS_NET_RESTRICTED}) +set(GStreamer_EXTRA_DEPS gstreamer-play-1.0 gstreamer-player-1.0 gstreamer-video-1.0 glib-2.0) +find_library(ANDROID_LIB android REQUIRED) +find_library(LOG_LIB log REQUIRED) + +find_package(GStreamerMobile COMPONENTS ${GSTREAMER_PLUGINS} fonts REQUIRED) + +add_library(gstplayer SHARED player.c dummy.cpp) +target_link_libraries(gstplayer + PUBLIC + GStreamer::mobile + ${ANDROID_LIB} + ${LOG_LIB} +) +set_target_properties(gstplayer + PROPERTIES + C_VISIBILITY_PRESET hidden + CXX_VISIBILITY_PRESET hidden +) diff --git a/subprojects/gst-examples/vulkan/android/.gitignore b/subprojects/gst-examples/vulkan/android/.gitignore index c64350ad7d..6d504558d4 100644 --- a/subprojects/gst-examples/vulkan/android/.gitignore +++ b/subprojects/gst-examples/vulkan/android/.gitignore @@ -6,5 +6,7 @@ assets/ build/ gst-android-build/ local.properties +src/org/freedesktop/gstreamer/Gst*.java src/org/freedesktop/gstreamer/GStreamer.java +!src/org/freedesktop/gstreamer/vulkan *.iml diff --git a/subprojects/gst-examples/vulkan/android/build.gradle b/subprojects/gst-examples/vulkan/android/build.gradle index dfadfc36de..b7522371ea 100644 --- a/subprojects/gst-examples/vulkan/android/build.gradle +++ b/subprojects/gst-examples/vulkan/android/build.gradle @@ -12,7 +12,7 @@ android { archivesBaseName = "$applicationId-v$versionCode" externalNativeBuild { - ndkBuild { + cmake { def gstRoot if (project.hasProperty('gstAndroidRoot')) @@ -23,12 +23,12 @@ android { if (gstRoot == null) throw new GradleException('GSTREAMER_ROOT_ANDROID must be set, or "gstAndroidRoot" must be defined in your gradle.properties in the top level directory of the unpacked universal GStreamer Android binaries') - arguments "NDK_APPLICATION_MK=jni/Application.mk", "GSTREAMER_JAVA_SRC_DIR=src", "GSTREAMER_ROOT_ANDROID=$gstRoot", "GSTREAMER_ASSETS_DIR=src/assets" + arguments "-DCMAKE_BUILD_TYPE=Release", "-DANDROID_STL=c++_shared", "-DGSTREAMER_ROOT_ANDROID=$gstRoot" targets "vulkan-1" // All archs except MIPS and MIPS64 are supported - abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64' + abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64' } } } @@ -52,11 +52,11 @@ android { } externalNativeBuild { - ndkBuild { - path 'jni/Android.mk' + cmake { + path 'jni/CMakeLists.txt' } } - ndkVersion '25.2.9519653' + ndkVersion '25.2.9519653' } afterEvaluate { diff --git a/subprojects/gst-examples/vulkan/android/jni/CMakeLists.txt b/subprojects/gst-examples/vulkan/android/jni/CMakeLists.txt new file mode 100644 index 0000000000..c21482bcf2 --- /dev/null +++ b/subprojects/gst-examples/vulkan/android/jni/CMakeLists.txt @@ -0,0 +1,44 @@ +cmake_minimum_required(VERSION 3.18.1) + +project("android-vulkan-1" LANGUAGES C CXX) + +if(NOT DEFINED GSTREAMER_ROOT_ANDROID) + message(FATAL_ERROR "GSTREAMER_ROOT_ANDROID is not defined!") +endif() + +if(ANDROID_ABI STREQUAL "armeabi") + set(GSTREAMER_ROOT "${GSTREAMER_ROOT_ANDROID}/arm") +elseif(ANDROID_ABI STREQUAL "armeabi-v7a") + set(GSTREAMER_ROOT "${GSTREAMER_ROOT_ANDROID}/armv7") +elseif(ANDROID_ABI STREQUAL "arm64-v8a") + set(GSTREAMER_ROOT "${GSTREAMER_ROOT_ANDROID}/arm64") +elseif(ANDROID_ABI STREQUAL "x86") + set(GSTREAMER_ROOT "${GSTREAMER_ROOT_ANDROID}/x86") +elseif(ANDROID_ABI STREQUAL "x86_64") + set(GSTREAMER_ROOT "${GSTREAMER_ROOT_ANDROID}/x86_64") +else() + message(FATAL_ERROR "Target arch ABI not supported: ${ANDROID_ABI}") +endif() + +list(APPEND CMAKE_MODULE_PATH "${GSTREAMER_ROOT}/share/cmake") + +set(GSTREAMER_NDK_BUILD_PATH "${GSTREAMER_ROOT}/share/gst-android/ndk-build/") +include("${GSTREAMER_NDK_BUILD_PATH}/plugins.cmake") +set(GSTREAMER_PLUGINS ${GSTREAMER_PLUGINS_CORE} ${GSTREAMER_PLUGINS_SYS} ${GSTREAMER_PLUGINS_EFFECTS} vulkan androidmedia) +set(GStreamer_EXTRA_DEPS gstreamer-video-1.0 gobject-2.0) +find_library(ANDROID_LIB android REQUIRED) +find_library(LOG_LIB log REQUIRED) +find_package(GStreamerMobile COMPONENTS ${GSTREAMER_PLUGINS} fonts ca_certificates REQUIRED) + +add_library(vulkan-1 SHARED vulkan-1.c dummy.cpp) +target_link_libraries(vulkan-1 + PUBLIC + GStreamer::mobile + ${ANDROID_LIB} + ${LOG_LIB} +) +set_target_properties(vulkan-1 + PROPERTIES + C_VISIBILITY_PRESET hidden + CXX_VISIBILITY_PRESET hidden +) diff --git a/subprojects/gst-examples/webrtc/android/app/.gitignore b/subprojects/gst-examples/webrtc/android/app/.gitignore index 04be8f69ca..5260dca52d 100644 --- a/subprojects/gst-examples/webrtc/android/app/.gitignore +++ b/subprojects/gst-examples/webrtc/android/app/.gitignore @@ -1,5 +1,7 @@ +.cxx/ .externalNativeBuild/ assets/ gst-android-build/ +src/main/java/org/freedesktop/gstreamer/Gst*.java src/main/java/org/freedesktop/gstreamer/GStreamer.java src/main/java/org/freedesktop/gstreamer/androidmedia/ diff --git a/subprojects/gst-examples/webrtc/android/app/build.gradle b/subprojects/gst-examples/webrtc/android/app/build.gradle index 37fb9fff68..b8894db2a5 100644 --- a/subprojects/gst-examples/webrtc/android/app/build.gradle +++ b/subprojects/gst-examples/webrtc/android/app/build.gradle @@ -12,7 +12,7 @@ android { archivesBaseName = "$applicationId-v$versionCode" externalNativeBuild { - ndkBuild { + cmake { def gstRoot if (project.hasProperty('gstAndroidRoot')) @@ -23,7 +23,7 @@ android { if (gstRoot == null) throw new GradleException('GSTREAMER_ROOT_ANDROID must be set, or "gstAndroidRoot" must be defined in your gradle.properties in the top level directory of the unpacked universal GStreamer Android binaries') - arguments "NDK_APPLICATION_MK=src/main/jni/Application.mk", "GSTREAMER_JAVA_SRC_DIR=src/main/java", "GSTREAMER_ROOT_ANDROID=$gstRoot", "GSTREAMER_ASSETS_DIR=src/main/assets", "V=1" + arguments "-DCMAKE_BUILD_TYPE=Release", "-DANDROID_STL=c++_shared", "-DGStreamer_JAVA_SRC_DIR=java", "-DGSTREAMER_ROOT_ANDROID=$gstRoot", "-DGStreamer_ASSETS_DIR=assets" targets "gstwebrtc" @@ -41,8 +41,8 @@ android { } externalNativeBuild { - ndkBuild { - path 'src/main/jni/Android.mk' + cmake { + path 'src/main/jni/CMakeLists.txt' } } diff --git a/subprojects/gst-examples/webrtc/android/app/src/main/jni/CMakeLists.txt b/subprojects/gst-examples/webrtc/android/app/src/main/jni/CMakeLists.txt new file mode 100644 index 0000000000..fb7cde36f2 --- /dev/null +++ b/subprojects/gst-examples/webrtc/android/app/src/main/jni/CMakeLists.txt @@ -0,0 +1,48 @@ +cmake_minimum_required(VERSION 3.18.1) + +project("android-webrtc" LANGUAGES C CXX) + +if(NOT DEFINED GSTREAMER_ROOT_ANDROID) + message(FATAL_ERROR "GSTREAMER_ROOT_ANDROID is not defined!") +endif() + +if(ANDROID_ABI STREQUAL "armeabi") + set(GSTREAMER_ROOT "${GSTREAMER_ROOT_ANDROID}/arm") +elseif(ANDROID_ABI STREQUAL "armeabi-v7a") + set(GSTREAMER_ROOT "${GSTREAMER_ROOT_ANDROID}/armv7") +elseif(ANDROID_ABI STREQUAL "arm64-v8a") + set(GSTREAMER_ROOT "${GSTREAMER_ROOT_ANDROID}/arm64") +elseif(ANDROID_ABI STREQUAL "x86") + set(GSTREAMER_ROOT "${GSTREAMER_ROOT_ANDROID}/x86") +elseif(ANDROID_ABI STREQUAL "x86_64") + set(GSTREAMER_ROOT "${GSTREAMER_ROOT_ANDROID}/x86_64") +else() + message(FATAL_ERROR "Target arch ABI not supported: ${ANDROID_ABI}") +endif() + +list(APPEND CMAKE_MODULE_PATH "${GSTREAMER_ROOT}/share/cmake") + +set(GSTREAMER_NDK_BUILD_PATH "${GSTREAMER_ROOT}/share/gst-android/ndk-build/") +include("${GSTREAMER_NDK_BUILD_PATH}/plugins.cmake") +set(GSTREAMER_PLUGINS_CORE_CUSTOM coreelements app audioconvert audiorate audioresample videorate videoconvertscale videotestsrc audiotestsrc volume autodetect) +set(GSTREAMER_PLUGINS_CODECS_CUSTOM videoparsersbad vpx opus audioparsers opusparse androidmedia) +set(GSTREAMER_PLUGINS_NET_CUSTOM soup tcp rtsp rtp rtpmanager udp srtp webrtc dtls nice) +set(GSTREAMER_PLUGINS ${GSTREAMER_PLUGINS_CORE_CUSTOM} ${GSTREAMER_PLUGINS_CODECS_CUSTOM} ${GSTREAMER_PLUGINS_NET_CUSTOM} ${GSTREAMER_PLUGINS_ENCODING} ${GSTREAMER_PLUGINS_SYS} ${GSTREAMER_PLUGINS_PLAYBACK}) +set(GStreamer_EXTRA_DEPS gstreamer-webrtc-1.0 gstreamer-sdp-1.0 gstreamer-video-1.0 libsoup-3.0 json-glib-1.0 glib-2.0) +set(G_IO_MODULES openssl) +find_library(ANDROID_LIB android REQUIRED) +find_library(LOG_LIB log REQUIRED) +find_package(GStreamerMobile COMPONENTS ${GSTREAMER_PLUGINS} fonts ca_certificates REQUIRED) + +add_library(gstwebrtc SHARED webrtc.c dummy.cpp) +target_link_libraries(gstwebrtc + PUBLIC + GStreamer::mobile + ${ANDROID_LIB} + ${LOG_LIB} +) +set_target_properties(gstwebrtc + PROPERTIES + C_VISIBILITY_PRESET hidden + CXX_VISIBILITY_PRESET hidden +)