mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2025-09-02 17:53:48 +00:00
webrtc: android: Migrate to FindGStreamerMobile
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/2266>
This commit is contained in:
parent
97bded80c6
commit
e860627092
4 changed files with 65 additions and 117 deletions
|
@ -21,7 +21,7 @@ android {
|
|||
versionName = "0.1.0"
|
||||
|
||||
externalNativeBuild {
|
||||
ndkBuild {
|
||||
cmake {
|
||||
var gstRoot: String?
|
||||
if (project.hasProperty("gstAndroidRoot"))
|
||||
gstRoot = project.property("gstAndroidRoot").toString()
|
||||
|
@ -30,14 +30,12 @@ android {
|
|||
if (gstRoot == null)
|
||||
throw 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/cpp/Application.mk", "GSTREAMER_JAVA_SRC_DIR=src/main/java", "GSTREAMER_ROOT_ANDROID=$gstRoot", "V=1")
|
||||
arguments ("-DANDROID_STL=c++_shared", "-DGSTREAMER_ROOT_ANDROID=$gstRoot", "-GNinja")
|
||||
|
||||
targets("gstreamer_webrtcsrc")
|
||||
|
||||
// All archs except MIPS and MIPS64 are supported
|
||||
//abiFilters("armeabi-v7a", "arm64-v8a", "x86", "x86_64")
|
||||
// FIXME for some reasons x86 generation fails (observed with gstreamer-1.0-android-universal-1.24.3)
|
||||
abiFilters("armeabi-v7a", "arm64-v8a", "x86_64")
|
||||
abiFilters("armeabi-v7a", "arm64-v8a", "x86", "x86_64")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -71,9 +69,9 @@ android {
|
|||
viewBinding = true
|
||||
}
|
||||
externalNativeBuild {
|
||||
ndkBuild {
|
||||
path = file("src/main/cpp/Android.mk")
|
||||
}
|
||||
cmake {
|
||||
path = file("src/main/cpp/CMakeLists.txt")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
cmake_minimum_required(VERSION 3.18.1)
|
||||
|
||||
project("gstreamer-webrtcsrc" 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_JAVA_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../java")
|
||||
|
||||
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 autodetect)
|
||||
set(GSTREAMER_PLUGINS_CODECS_CUSTOM videoparsersbad vpx opus audioparsers opusparse androidmedia)
|
||||
set(GSTREAMER_PLUGINS_NET_CUSTOM tcp rtsp rtp rtpmanager udp srtp webrtc dtls nice rswebrtc rsrtp)
|
||||
set(GSTREAMER_PLUGINS_PLAYBACK_CUSTOM playback)
|
||||
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-video-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(gstreamer_webrtcsrc SHARED WebRTCSrc.c dummy.cpp)
|
||||
target_link_libraries(gstreamer_webrtcsrc
|
||||
PUBLIC
|
||||
GStreamer::mobile
|
||||
${ANDROID_LIB}
|
||||
${LOG_LIB}
|
||||
)
|
||||
set_target_properties(gstreamer_webrtcsrc
|
||||
PROPERTIES
|
||||
C_VISIBILITY_PRESET hidden
|
||||
CXX_VISIBILITY_PRESET hidden
|
||||
)
|
|
@ -1,6 +1,4 @@
|
|||
# Generated:
|
||||
androidmedia/
|
||||
# Note that gstreamer_android will generate (and overwrite) GStreamer.java
|
||||
# during native code and libraries compilation.
|
||||
# We keep it in git for dependent code to be able to refere to it if they are
|
||||
# compiled before native code.
|
||||
# FindGStreamerMobile blocks generation until the java targets are executed.
|
||||
*.java
|
||||
|
|
|
@ -1,105 +0,0 @@
|
|||
/**
|
||||
* Copy this file into your Android project and call init(). If your project
|
||||
* contains fonts and/or certificates in assets, uncomment copyFonts() and/or
|
||||
* copyCaCertificates() lines in init().
|
||||
*/
|
||||
package org.freedesktop.gstreamer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.AssetManager;
|
||||
import android.system.Os;
|
||||
|
||||
public class GStreamer {
|
||||
private static native void nativeInit(Context context) throws Exception;
|
||||
|
||||
public static void init(Context context) throws Exception {
|
||||
copyFonts(context);
|
||||
copyCaCertificates(context);
|
||||
nativeInit(context);
|
||||
}
|
||||
|
||||
private static void copyFonts(Context context) {
|
||||
AssetManager assetManager = context.getAssets();
|
||||
File filesDir = context.getFilesDir();
|
||||
File fontsFCDir = new File (filesDir, "fontconfig");
|
||||
File fontsDir = new File (fontsFCDir, "fonts");
|
||||
File fontsCfg = new File (fontsFCDir, "fonts.conf");
|
||||
|
||||
fontsDir.mkdirs();
|
||||
|
||||
try {
|
||||
/* Copy the config file */
|
||||
copyFile (assetManager, "fontconfig/fonts.conf", fontsCfg);
|
||||
/* Copy the fonts */
|
||||
for(String filename : assetManager.list("fontconfig/fonts/truetype")) {
|
||||
File font = new File(fontsDir, filename);
|
||||
copyFile (assetManager, "fontconfig/fonts/truetype/" + filename, font);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void copyCaCertificates(Context context) {
|
||||
AssetManager assetManager = context.getAssets();
|
||||
File filesDir = context.getFilesDir();
|
||||
File sslDir = new File (filesDir, "ssl");
|
||||
File certsDir = new File (sslDir, "certs");
|
||||
File certs = new File (certsDir, "ca-certificates.crt");
|
||||
|
||||
certsDir.mkdirs();
|
||||
|
||||
try {
|
||||
/* Copy the certificates file */
|
||||
copyFile (assetManager, "ssl/certs/ca-certificates.crt", certs);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void copyFile(AssetManager assetManager, String assetPath, File outFile) throws IOException {
|
||||
InputStream in = null;
|
||||
OutputStream out = null;
|
||||
IOException exception = null;
|
||||
|
||||
if (outFile.exists())
|
||||
outFile.delete();
|
||||
|
||||
try {
|
||||
in = assetManager.open(assetPath);
|
||||
out = new FileOutputStream(outFile);
|
||||
|
||||
byte[] buffer = new byte[1024];
|
||||
int read;
|
||||
while ((read = in.read(buffer)) != -1) {
|
||||
out.write(buffer, 0, read);
|
||||
}
|
||||
out.flush();
|
||||
} catch (IOException e) {
|
||||
exception = e;
|
||||
} finally {
|
||||
if (in != null)
|
||||
try {
|
||||
in.close();
|
||||
} catch (IOException e) {
|
||||
if (exception == null)
|
||||
exception = e;
|
||||
}
|
||||
if (out != null)
|
||||
try {
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
if (exception == null)
|
||||
exception = e;
|
||||
}
|
||||
if (exception != null)
|
||||
throw exception;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue