From ff199cdc2bdad8a35fe5aae25f8420f40752cc3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?The=CC=81o=20Monnom?= Date: Mon, 26 Feb 2024 13:18:58 +0100 Subject: [PATCH 1/2] add JNI_OnLoad --- Cargo.lock | 1 + livekit-ffi/Cargo.toml | 3 +++ livekit-ffi/src/cabi.rs | 13 +++++++++++++ 3 files changed, 17 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 72c40032..a11986ea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1159,6 +1159,7 @@ dependencies = [ "env_logger", "futures-util", "imgproc", + "jni", "lazy_static", "livekit", "livekit-api", diff --git a/livekit-ffi/Cargo.toml b/livekit-ffi/Cargo.toml index f111bfa9..4d7dc8f4 100644 --- a/livekit-ffi/Cargo.toml +++ b/livekit-ffi/Cargo.toml @@ -34,6 +34,9 @@ downcast-rs = "1.2" console-subscriber = { version = "0.1", features = ["parking_lot"], optional = true } imgproc = "0.3.11" +[target.'cfg(target_os = "android")'.dependencies] +jni = "0.21.1" + [build-dependencies] webrtc-sys-build = { path = "../webrtc-sys/build", version = "0.3.0" } diff --git a/livekit-ffi/src/cabi.rs b/livekit-ffi/src/cabi.rs index 517ce992..99d9f52e 100644 --- a/livekit-ffi/src/cabi.rs +++ b/livekit-ffi/src/cabi.rs @@ -84,3 +84,16 @@ pub unsafe extern "C" fn livekit_ffi_request( pub extern "C" fn livekit_ffi_drop_handle(handle_id: FfiHandleId) -> bool { FFI_SERVER.drop_handle(handle_id) } + +#[cfg(target_os = "android")] +pub mod android { + use std::os::raw::c_void; + + #[allow(non_snake_case)] + #[no_mangle] + pub extern "C" fn JNI_OnLoad(vm: JavaVM, _: *mut c_void) -> jint { + println!("JNI_OnLoad, initializing LiveKit"); + livekit::webrtc::android::initialize_android(&vm); + JNI_VERSION_1_6 + } +} From 69ea4b4e176bc9627fa73d92e6a78fa10423ca45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?The=CC=81o=20Monnom?= Date: Mon, 26 Feb 2024 13:21:56 +0100 Subject: [PATCH 2/2] Update cabi.rs --- livekit-ffi/src/cabi.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/livekit-ffi/src/cabi.rs b/livekit-ffi/src/cabi.rs index 99d9f52e..a56c8f8c 100644 --- a/livekit-ffi/src/cabi.rs +++ b/livekit-ffi/src/cabi.rs @@ -87,6 +87,10 @@ pub extern "C" fn livekit_ffi_drop_handle(handle_id: FfiHandleId) -> bool { #[cfg(target_os = "android")] pub mod android { + use jni::{ + sys::{jint, JNI_VERSION_1_6}, + JavaVM, + }; use std::os::raw::c_void; #[allow(non_snake_case)]