1 /* 2 * Copyright 2022 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #include "api/video_codecs/builtin_video_decoder_factory.h" 12 #include "api/video_codecs/video_decoder.h" 13 #include "sdk/android/generated_swcodecs_jni/SoftwareVideoDecoderFactory_jni.h" 14 #include "sdk/android/native_api/jni/java_types.h" 15 #include "sdk/android/src/jni/jni_helpers.h" 16 #include "sdk/android/src/jni/video_codec_info.h" 17 18 namespace webrtc { 19 namespace jni { 20 JNI_SoftwareVideoDecoderFactory_CreateFactory(JNIEnv * env)21static jlong JNI_SoftwareVideoDecoderFactory_CreateFactory(JNIEnv* env) { 22 return webrtc::NativeToJavaPointer( 23 CreateBuiltinVideoDecoderFactory().release()); 24 } 25 JNI_SoftwareVideoDecoderFactory_CreateDecoder(JNIEnv * env,jlong j_factory,const webrtc::JavaParamRef<jobject> & j_video_codec_info)26static jlong JNI_SoftwareVideoDecoderFactory_CreateDecoder( 27 JNIEnv* env, 28 jlong j_factory, 29 const webrtc::JavaParamRef<jobject>& j_video_codec_info) { 30 auto* const native_factory = 31 reinterpret_cast<webrtc::VideoDecoderFactory*>(j_factory); 32 const auto video_format = 33 webrtc::jni::VideoCodecInfoToSdpVideoFormat(env, j_video_codec_info); 34 35 auto decoder = native_factory->CreateVideoDecoder(video_format); 36 if (decoder == nullptr) { 37 return 0; 38 } 39 return webrtc::NativeToJavaPointer(decoder.release()); 40 } 41 42 static webrtc::ScopedJavaLocalRef<jobject> JNI_SoftwareVideoDecoderFactory_GetSupportedCodecs(JNIEnv * env,jlong j_factory)43JNI_SoftwareVideoDecoderFactory_GetSupportedCodecs(JNIEnv* env, 44 jlong j_factory) { 45 auto* const native_factory = 46 reinterpret_cast<webrtc::VideoDecoderFactory*>(j_factory); 47 48 return webrtc::NativeToJavaList(env, native_factory->GetSupportedFormats(), 49 &webrtc::jni::SdpVideoFormatToVideoCodecInfo); 50 } 51 52 } // namespace jni 53 } // namespace webrtc 54