fork/rust-sdks
git clone https://git.julia.blue/fork/rust-sdks
c65a275
main
1/* 2* Copyright 2023 LiveKit 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#include "livekit/android.h" 18 19#include <jni.h> 20 21#include <memory> 22 23#include "api/video_codecs/video_decoder_factory.h" 24#include "sdk/android/native_api/base/init.h" 25#include "sdk/android/native_api/codecs/wrapper.h" 26#include "sdk/android/native_api/jni/class_loader.h" 27#include "sdk/android/native_api/jni/scoped_java_ref.h" 28#include "sdk/android/src/jni/jni_helpers.h" 29 30namespace livekit { 31 32void init_android (JavaVM * jvm ) { 33 webrtc::InitAndroid (jvm ); 34} 35 36std::unique_ptr < webrtc::VideoEncoderFactory > 37CreateAndroidVideoEncoderFactory () { 38JNIEnv * env = webrtc::AttachCurrentThreadIfNeeded (); 39 webrtc::ScopedJavaLocalRef < jclass > factory_class = 40 webrtc::GetClass (env ,"org/webrtc/DefaultVideoEncoderFactory" ); 41 42jmethodID ctor = env -> GetMethodID (factory_class .obj (),"<init>" , 43"(Lorg/webrtc/EglBase$Context;ZZ)V" ); 44 45jobject encoder_factory = 46env -> NewObject (factory_class .obj (),ctor ,nullptr , true, false); 47 48return webrtc::JavaToNativeVideoEncoderFactory (env ,encoder_factory ); 49} 50 51std::unique_ptr < webrtc::VideoDecoderFactory > 52CreateAndroidVideoDecoderFactory () { 53JNIEnv * env = webrtc::AttachCurrentThreadIfNeeded (); 54 55 webrtc::ScopedJavaLocalRef < jclass > factory_class = 56 webrtc::GetClass (env ,"org/webrtc/WrappedVideoDecoderFactory" ); 57 58jmethodID ctor = env -> GetMethodID (factory_class .obj (),"<init>" , 59"(Lorg/webrtc/EglBase$Context;)V" ); 60 61jobject decoder_factory = env -> NewObject (factory_class .obj (),ctor ,nullptr ); 62return webrtc::JavaToNativeVideoDecoderFactory (env ,decoder_factory ); 63} 64 65}// namespace livekit