| 1 | /* |
| 2 | * Copyright 2025 LiveKit, Inc. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #pragma once |
| 18 | |
| 19 | #include <jni.h> |
| 20 | |
| 21 | #include <cstdint> |
| 22 | #include <memory> |
| 23 | |
| 24 | #include "api/video_codecs/video_decoder_factory.h" |
| 25 | #include "api/video_codecs/video_encoder_factory.h" |
| 26 | |
| 27 | namespace livekit_ffi { |
| 28 | typedef JavaVM JavaVM; |
| 29 | } // namespace livekit_ffi |
| 30 | #include "webrtc-sys/src/android.rs.h" |
| 31 | |
| 32 | namespace livekit_ffi { |
| 33 | |
| 34 | /// Initialize Android WebRTC with the JVM. |
| 35 | /// This is called automatically by init_android_context(), so you only need to |
| 36 | /// call this directly in JNI_OnLoad or if you don't have an Android Context. |
| 37 | /// This function is idempotent - safe to call multiple times. |
| 38 | /// |
| 39 | /// @param jvm The JavaVM pointer |
| 40 | void init_android(JavaVM* jvm); |
| 41 | |
| 42 | /// Initialize Android WebRTC with the application context. |
| 43 | /// This is the main initialization function - it calls init_android() internally |
| 44 | /// and then initializes ContextUtils for PlatformAudio support. |
| 45 | /// This function is idempotent - safe to call multiple times. |
| 46 | /// |
| 47 | /// @param jvm The JavaVM pointer |
| 48 | /// @param context The Android application context (jobject cast to uintptr_t) |
| 49 | /// @return true if context initialization was successful, false otherwise. |
| 50 | /// Note: JVM init (init_android) always happens regardless of return value. |
| 51 | bool init_android_context(JavaVM* jvm, uintptr_t context); |
| 52 | |
| 53 | std::unique_ptr<webrtc::VideoEncoderFactory> CreateAndroidVideoEncoderFactory(); |
| 54 | std::unique_ptr<webrtc::VideoDecoderFactory> CreateAndroidVideoDecoderFactory(); |
| 55 | |
| 56 | } // namespace livekit_ffi |