• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_encoder_factory.h"
12 #include "api/video_codecs/video_encoder.h"
13 #include "sdk/android/generated_swcodecs_jni/SoftwareVideoEncoderFactory_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_SoftwareVideoEncoderFactory_CreateFactory(JNIEnv * env)21 static jlong JNI_SoftwareVideoEncoderFactory_CreateFactory(JNIEnv* env) {
22   return webrtc::NativeToJavaPointer(
23       CreateBuiltinVideoEncoderFactory().release());
24 }
25 
JNI_SoftwareVideoEncoderFactory_CreateEncoder(JNIEnv * env,jlong j_factory,const webrtc::JavaParamRef<jobject> & j_video_codec_info)26 static jlong JNI_SoftwareVideoEncoderFactory_CreateEncoder(
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::VideoEncoderFactory*>(j_factory);
32   const auto video_format =
33       webrtc::jni::VideoCodecInfoToSdpVideoFormat(env, j_video_codec_info);
34 
35   auto encoder = native_factory->CreateVideoEncoder(video_format);
36   if (encoder == nullptr) {
37     return 0;
38   }
39   return webrtc::NativeToJavaPointer(encoder.release());
40 }
41 
42 static webrtc::ScopedJavaLocalRef<jobject>
JNI_SoftwareVideoEncoderFactory_GetSupportedCodecs(JNIEnv * env,jlong j_factory)43 JNI_SoftwareVideoEncoderFactory_GetSupportedCodecs(JNIEnv* env,
44                                                    jlong j_factory) {
45   auto* const native_factory =
46       reinterpret_cast<webrtc::VideoEncoderFactory*>(j_factory);
47 
48   return webrtc::NativeToJavaList(env, native_factory->GetSupportedFormats(),
49                                   &webrtc::jni::SdpVideoFormatToVideoCodecInfo);
50 }
51 
52 }  // namespace jni
53 }  // namespace webrtc
54