Create an experimental Android NDK.
Following files were split: sdk/android/native_api/jni_helpers.h -> sdk/android/native_api/jni/java_types.h sdk/android/native_api/jni_helpers.cc -> sdk/android/native_api/jni/java_types.cc Skipping presubmit to avoid changing moved code. Bug: webrtc:8769 Change-Id: I0ef0f6b297b5002322915660d26cca33e91ff05b No-Presubmit: true Reviewed-on: https://webrtc-review.googlesource.com/40800 Commit-Queue: Sami Kalliomäki <sakal@webrtc.org> Reviewed-by: Rasmus Brandt <brandtr@webrtc.org> Reviewed-by: Anders Carlsson <andersc@webrtc.org> Cr-Commit-Position: refs/heads/master@{#21799}
This commit is contained in:
committed by
Commit Bot
parent
4f6e4f0884
commit
82f96e6a56
@ -598,7 +598,9 @@ if (rtc_include_tests) {
|
|||||||
]
|
]
|
||||||
|
|
||||||
deps += [
|
deps += [
|
||||||
"../../sdk/android:libjingle_peerconnection_jni",
|
"../../sdk/android:native_api_base",
|
||||||
|
"../../sdk/android:native_api_codecs",
|
||||||
|
"../../sdk/android:native_api_jni",
|
||||||
"//base",
|
"//base",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,8 +12,7 @@
|
|||||||
|
|
||||||
#include "modules/video_coding/codecs/test/android_test_initializer.h"
|
#include "modules/video_coding/codecs/test/android_test_initializer.h"
|
||||||
#include "rtc_base/ignore_wundef.h"
|
#include "rtc_base/ignore_wundef.h"
|
||||||
#include "sdk/android/src/jni/classreferenceholder.h"
|
#include "sdk/android/native_api/base/init.h"
|
||||||
#include "sdk/android/src/jni/jni_helpers.h"
|
|
||||||
|
|
||||||
// Note: this dependency is dangerous since it reaches into Chromium's base.
|
// Note: this dependency is dangerous since it reaches into Chromium's base.
|
||||||
// There's a risk of e.g. macro clashes. This file may only be used in tests.
|
// There's a risk of e.g. macro clashes. This file may only be used in tests.
|
||||||
@ -40,10 +39,7 @@ void EnsureInitializedOnce() {
|
|||||||
JavaVM* jvm = NULL;
|
JavaVM* jvm = NULL;
|
||||||
RTC_CHECK_EQ(0, jni->GetJavaVM(&jvm));
|
RTC_CHECK_EQ(0, jni->GetJavaVM(&jvm));
|
||||||
|
|
||||||
jint ret = jni::InitGlobalJniVariables(jvm);
|
InitAndroid(jvm);
|
||||||
RTC_DCHECK_GE(ret, 0);
|
|
||||||
|
|
||||||
jni::LoadGlobalClassReferenceHolder();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@ -15,9 +15,10 @@
|
|||||||
|
|
||||||
#if defined(WEBRTC_ANDROID)
|
#if defined(WEBRTC_ANDROID)
|
||||||
#include "modules/video_coding/codecs/test/android_test_initializer.h"
|
#include "modules/video_coding/codecs/test/android_test_initializer.h"
|
||||||
#include "sdk/android/src/jni/class_loader.h"
|
#include "sdk/android/native_api/codecs/wrapper.h"
|
||||||
#include "sdk/android/src/jni/videodecoderfactorywrapper.h"
|
#include "sdk/android/native_api/jni/class_loader.h"
|
||||||
#include "sdk/android/src/jni/videoencoderfactorywrapper.h"
|
#include "sdk/android/native_api/jni/jvm.h"
|
||||||
|
#include "sdk/android/native_api/jni/scoped_java_ref.h"
|
||||||
#elif defined(WEBRTC_IOS)
|
#elif defined(WEBRTC_IOS)
|
||||||
#include "modules/video_coding/codecs/test/objc_codec_h264_test.h"
|
#include "modules/video_coding/codecs/test/objc_codec_h264_test.h"
|
||||||
#endif
|
#endif
|
||||||
@ -375,18 +376,18 @@ void VideoProcessorIntegrationTest::CreateEncoderAndDecoder() {
|
|||||||
std::unique_ptr<VideoEncoderFactory> encoder_factory;
|
std::unique_ptr<VideoEncoderFactory> encoder_factory;
|
||||||
if (config_.hw_encoder) {
|
if (config_.hw_encoder) {
|
||||||
#if defined(WEBRTC_ANDROID)
|
#if defined(WEBRTC_ANDROID)
|
||||||
JNIEnv* env = jni::AttachCurrentThreadIfNeeded();
|
JNIEnv* env = AttachCurrentThreadIfNeeded();
|
||||||
jni::ScopedJavaLocalRef<jclass> factory_class =
|
ScopedJavaLocalRef<jclass> factory_class =
|
||||||
jni::GetClass(env, "org/webrtc/HardwareVideoEncoderFactory");
|
GetClass(env, "org/webrtc/HardwareVideoEncoderFactory");
|
||||||
jmethodID factory_constructor = env->GetMethodID(
|
jmethodID factory_constructor = env->GetMethodID(
|
||||||
factory_class.obj(), "<init>", "(Lorg/webrtc/EglBase$Context;ZZ)V");
|
factory_class.obj(), "<init>", "(Lorg/webrtc/EglBase$Context;ZZ)V");
|
||||||
jni::ScopedJavaLocalRef<jobject> factory_object(
|
ScopedJavaLocalRef<jobject> factory_object(
|
||||||
env, env->NewObject(factory_class.obj(), factory_constructor,
|
env, env->NewObject(factory_class.obj(), factory_constructor,
|
||||||
nullptr /* shared_context */,
|
nullptr /* shared_context */,
|
||||||
false /* enable_intel_vp8_encoder */,
|
false /* enable_intel_vp8_encoder */,
|
||||||
true /* enable_h264_high_profile */));
|
true /* enable_h264_high_profile */));
|
||||||
encoder_factory = rtc::MakeUnique<webrtc::jni::VideoEncoderFactoryWrapper>(
|
encoder_factory =
|
||||||
env, factory_object);
|
JavaToNativeVideoEncoderFactory(env, factory_object.obj());
|
||||||
#elif defined(WEBRTC_IOS)
|
#elif defined(WEBRTC_IOS)
|
||||||
EXPECT_EQ(kVideoCodecH264, config_.codec_settings.codecType)
|
EXPECT_EQ(kVideoCodecH264, config_.codec_settings.codecType)
|
||||||
<< "iOS HW codecs only support H264.";
|
<< "iOS HW codecs only support H264.";
|
||||||
@ -401,16 +402,16 @@ void VideoProcessorIntegrationTest::CreateEncoderAndDecoder() {
|
|||||||
std::unique_ptr<VideoDecoderFactory> decoder_factory;
|
std::unique_ptr<VideoDecoderFactory> decoder_factory;
|
||||||
if (config_.hw_decoder) {
|
if (config_.hw_decoder) {
|
||||||
#if defined(WEBRTC_ANDROID)
|
#if defined(WEBRTC_ANDROID)
|
||||||
JNIEnv* env = jni::AttachCurrentThreadIfNeeded();
|
JNIEnv* env = AttachCurrentThreadIfNeeded();
|
||||||
jni::ScopedJavaLocalRef<jclass> factory_class =
|
ScopedJavaLocalRef<jclass> factory_class =
|
||||||
jni::GetClass(env, "org/webrtc/HardwareVideoDecoderFactory");
|
GetClass(env, "org/webrtc/HardwareVideoDecoderFactory");
|
||||||
jmethodID factory_constructor = env->GetMethodID(
|
jmethodID factory_constructor = env->GetMethodID(
|
||||||
factory_class.obj(), "<init>", "(Lorg/webrtc/EglBase$Context;)V");
|
factory_class.obj(), "<init>", "(Lorg/webrtc/EglBase$Context;)V");
|
||||||
jni::ScopedJavaLocalRef<jobject> factory_object(
|
ScopedJavaLocalRef<jobject> factory_object(
|
||||||
env, env->NewObject(factory_class.obj(), factory_constructor,
|
env, env->NewObject(factory_class.obj(), factory_constructor,
|
||||||
nullptr /* shared_context */));
|
nullptr /* shared_context */));
|
||||||
decoder_factory = rtc::MakeUnique<webrtc::jni::VideoDecoderFactoryWrapper>(
|
decoder_factory =
|
||||||
env, factory_object);
|
JavaToNativeVideoDecoderFactory(env, factory_object.obj());
|
||||||
#elif defined(WEBRTC_IOS)
|
#elif defined(WEBRTC_IOS)
|
||||||
EXPECT_EQ(kVideoCodecH264, config_.codec_settings.codecType)
|
EXPECT_EQ(kVideoCodecH264, config_.codec_settings.codecType)
|
||||||
<< "iOS HW codecs only support H264.";
|
<< "iOS HW codecs only support H264.";
|
||||||
|
|||||||
@ -17,6 +17,7 @@ group("android") {
|
|||||||
":libjingle_peerconnection_jni",
|
":libjingle_peerconnection_jni",
|
||||||
":libjingle_peerconnection_so",
|
":libjingle_peerconnection_so",
|
||||||
":libwebrtc",
|
":libwebrtc",
|
||||||
|
":native_api",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -37,8 +38,6 @@ generate_jni("generated_base_jni") {
|
|||||||
sources = [
|
sources = [
|
||||||
"src/java/org/webrtc/Histogram.java",
|
"src/java/org/webrtc/Histogram.java",
|
||||||
"src/java/org/webrtc/JniCommon.java",
|
"src/java/org/webrtc/JniCommon.java",
|
||||||
"src/java/org/webrtc/JniHelper.java",
|
|
||||||
"src/java/org/webrtc/WebRtcClassLoader.java",
|
|
||||||
]
|
]
|
||||||
jni_package = ""
|
jni_package = ""
|
||||||
jni_generator_include = "//sdk/android/src/jni/jni_generator_helper.h"
|
jni_generator_include = "//sdk/android/src/jni/jni_generator_helper.h"
|
||||||
@ -62,27 +61,46 @@ generate_jar_jni("generated_external_classes_jni") {
|
|||||||
jni_generator_include = "//sdk/android/src/jni/jni_generator_helper.h"
|
jni_generator_include = "//sdk/android/src/jni/jni_generator_helper.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Internal code that is needed by native_api_jni. The code cannot be placed in
|
||||||
|
# base_jni because native_api_jni depends on the code (and base_jni depends on
|
||||||
|
# native_api_jni).
|
||||||
|
rtc_source_set("internal_jni") {
|
||||||
|
sources = [
|
||||||
|
"src/jni/jvm.cc",
|
||||||
|
"src/jni/jvm.h",
|
||||||
|
]
|
||||||
|
|
||||||
|
deps = [
|
||||||
|
"../../rtc_base:checks",
|
||||||
|
]
|
||||||
|
|
||||||
|
if (is_clang) {
|
||||||
|
# Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163).
|
||||||
|
suppressed_configs += [
|
||||||
|
"//build/config/clang:extra_warnings",
|
||||||
|
"//build/config/clang:find_bad_constructs",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
rtc_source_set("base_jni") {
|
rtc_source_set("base_jni") {
|
||||||
visibility = [ "*" ]
|
visibility = [ "*" ]
|
||||||
sources = [
|
sources = [
|
||||||
"src/jni/androidhistogram.cc",
|
"src/jni/androidhistogram.cc",
|
||||||
"src/jni/class_loader.cc",
|
|
||||||
"src/jni/class_loader.h",
|
"src/jni/class_loader.h",
|
||||||
"src/jni/classreferenceholder.h",
|
"src/jni/classreferenceholder.h",
|
||||||
"src/jni/jni_common.cc",
|
"src/jni/jni_common.cc",
|
||||||
"src/jni/jni_generator_helper.cc",
|
|
||||||
"src/jni/jni_generator_helper.h",
|
|
||||||
"src/jni/jni_helpers.cc",
|
"src/jni/jni_helpers.cc",
|
||||||
"src/jni/jni_helpers.h",
|
"src/jni/jni_helpers.h",
|
||||||
"src/jni/pc/audio.h",
|
"src/jni/pc/audio.h",
|
||||||
"src/jni/pc/media.h",
|
"src/jni/pc/media.h",
|
||||||
"src/jni/pc/video.h",
|
"src/jni/pc/video.h",
|
||||||
"src/jni/scoped_java_ref.h",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
deps = [
|
deps = [
|
||||||
":generated_base_jni",
|
":generated_base_jni",
|
||||||
":generated_external_classes_jni",
|
":internal_jni",
|
||||||
|
":native_api_jni",
|
||||||
"../../api:libjingle_peerconnection_api",
|
"../../api:libjingle_peerconnection_api",
|
||||||
"../../api:optional",
|
"../../api:optional",
|
||||||
"../../rtc_base:checks",
|
"../../rtc_base:checks",
|
||||||
@ -231,7 +249,7 @@ rtc_static_library("video_jni") {
|
|||||||
deps = [
|
deps = [
|
||||||
":base_jni",
|
":base_jni",
|
||||||
":generated_video_jni",
|
":generated_video_jni",
|
||||||
":peerconnection_jni",
|
":native_api_jni",
|
||||||
"../..:webrtc_common",
|
"../..:webrtc_common",
|
||||||
"../../api:libjingle_peerconnection_api",
|
"../../api:libjingle_peerconnection_api",
|
||||||
"../../api:video_frame_api",
|
"../../api:video_frame_api",
|
||||||
@ -415,6 +433,7 @@ rtc_static_library("peerconnection_jni") {
|
|||||||
":base_jni",
|
":base_jni",
|
||||||
":generated_external_classes_jni",
|
":generated_external_classes_jni",
|
||||||
":generated_peerconnection_jni",
|
":generated_peerconnection_jni",
|
||||||
|
":native_api_jni",
|
||||||
"../..:webrtc_common",
|
"../..:webrtc_common",
|
||||||
"../../api:libjingle_peerconnection_api",
|
"../../api:libjingle_peerconnection_api",
|
||||||
"../../api:peerconnection_and_implicit_call_api",
|
"../../api:peerconnection_and_implicit_call_api",
|
||||||
@ -464,6 +483,7 @@ rtc_static_library("libjingle_peerconnection_metrics_default_jni") {
|
|||||||
deps = [
|
deps = [
|
||||||
":base_jni",
|
":base_jni",
|
||||||
":generated_metrics_jni",
|
":generated_metrics_jni",
|
||||||
|
":native_api_jni",
|
||||||
":peerconnection_jni",
|
":peerconnection_jni",
|
||||||
"../../pc:peerconnection",
|
"../../pc:peerconnection",
|
||||||
"../../system_wrappers:field_trial_default",
|
"../../system_wrappers:field_trial_default",
|
||||||
@ -706,3 +726,95 @@ if (rtc_include_tests) {
|
|||||||
shared_libraries = [ "../../sdk/android:libjingle_peerconnection_so" ]
|
shared_libraries = [ "../../sdk/android:libjingle_peerconnection_so" ]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# The native API is currently experimental and may change without notice.
|
||||||
|
group("native_api") {
|
||||||
|
deps = [
|
||||||
|
":native_api_base",
|
||||||
|
":native_api_codecs",
|
||||||
|
":native_api_jni",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
rtc_static_library("native_api_base") {
|
||||||
|
visibility = [ "*" ]
|
||||||
|
sources = [
|
||||||
|
"native_api/base/init.cc",
|
||||||
|
"native_api/base/init.h",
|
||||||
|
]
|
||||||
|
|
||||||
|
deps = [
|
||||||
|
":base_jni",
|
||||||
|
":native_api_jni",
|
||||||
|
"//rtc_base:checks",
|
||||||
|
"//rtc_base:rtc_base",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
generate_jni("generated_native_api_jni") {
|
||||||
|
sources = [
|
||||||
|
"src/java/org/webrtc/JniHelper.java",
|
||||||
|
"src/java/org/webrtc/WebRtcClassLoader.java",
|
||||||
|
]
|
||||||
|
jni_package = ""
|
||||||
|
jni_generator_include = "//sdk/android/src/jni/jni_generator_helper.h"
|
||||||
|
}
|
||||||
|
|
||||||
|
# JNI helpers that are also needed from internal JNI code. Cannot depend on any
|
||||||
|
# other JNI targets than internal_jni.
|
||||||
|
rtc_static_library("native_api_jni") {
|
||||||
|
visibility = [ "*" ]
|
||||||
|
sources = [
|
||||||
|
"native_api/jni/class_loader.cc",
|
||||||
|
"native_api/jni/class_loader.h",
|
||||||
|
"native_api/jni/java_types.cc",
|
||||||
|
"native_api/jni/java_types.h",
|
||||||
|
"native_api/jni/jvm.cc",
|
||||||
|
"native_api/jni/jvm.h",
|
||||||
|
"native_api/jni/scoped_java_ref.h",
|
||||||
|
"src/jni/jni_generator_helper.cc",
|
||||||
|
"src/jni/jni_generator_helper.h",
|
||||||
|
]
|
||||||
|
|
||||||
|
public = [
|
||||||
|
"native_api/jni/class_loader.h",
|
||||||
|
"native_api/jni/java_types.h",
|
||||||
|
"native_api/jni/jvm.h",
|
||||||
|
"native_api/jni/scoped_java_ref.h",
|
||||||
|
]
|
||||||
|
|
||||||
|
deps = [
|
||||||
|
":generated_external_classes_jni",
|
||||||
|
":generated_native_api_jni",
|
||||||
|
":internal_jni",
|
||||||
|
"//api:optional",
|
||||||
|
"//rtc_base:checks",
|
||||||
|
"//rtc_base:rtc_base_approved",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
# API for wrapping Java VideoDecoderFactory/VideoEncoderFactory classes to C++
|
||||||
|
# objects.
|
||||||
|
rtc_static_library("native_api_codecs") {
|
||||||
|
visibility = [ "*" ]
|
||||||
|
sources = [
|
||||||
|
"native_api/codecs/wrapper.cc",
|
||||||
|
"native_api/codecs/wrapper.h",
|
||||||
|
]
|
||||||
|
|
||||||
|
if (is_clang) {
|
||||||
|
# Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163).
|
||||||
|
suppressed_configs += [
|
||||||
|
"//build/config/clang:extra_warnings",
|
||||||
|
"//build/config/clang:find_bad_constructs",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
deps = [
|
||||||
|
":base_jni",
|
||||||
|
":video_jni",
|
||||||
|
"//api/video_codecs:video_codecs_api",
|
||||||
|
"//rtc_base:checks",
|
||||||
|
"//rtc_base:rtc_base_approved",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|||||||
24
sdk/android/native_api/base/init.cc
Normal file
24
sdk/android/native_api/base/init.cc
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018 The WebRTC project authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license
|
||||||
|
* that can be found in the LICENSE file in the root of the source
|
||||||
|
* tree. An additional intellectual property rights grant can be found
|
||||||
|
* in the file PATENTS. All contributing project authors may
|
||||||
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "sdk/android/native_api/base/init.h"
|
||||||
|
|
||||||
|
#include "rtc_base/checks.h"
|
||||||
|
#include "sdk/android/native_api/jni/class_loader.h"
|
||||||
|
#include "sdk/android/src/jni/jni_helpers.h"
|
||||||
|
|
||||||
|
namespace webrtc {
|
||||||
|
|
||||||
|
void InitAndroid(JavaVM* jvm) {
|
||||||
|
RTC_CHECK_GE(jni::InitGlobalJniVariables(jvm), 0);
|
||||||
|
InitClassLoader(jni::GetEnv());
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace webrtc
|
||||||
23
sdk/android/native_api/base/init.h
Normal file
23
sdk/android/native_api/base/init.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018 The WebRTC project authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license
|
||||||
|
* that can be found in the LICENSE file in the root of the source
|
||||||
|
* tree. An additional intellectual property rights grant can be found
|
||||||
|
* in the file PATENTS. All contributing project authors may
|
||||||
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SDK_ANDROID_NATIVE_API_BASE_INIT_H_
|
||||||
|
#define SDK_ANDROID_NATIVE_API_BASE_INIT_H_
|
||||||
|
|
||||||
|
#include <jni.h>
|
||||||
|
|
||||||
|
namespace webrtc {
|
||||||
|
|
||||||
|
// Initializes global state needed by WebRTC Android NDK.
|
||||||
|
void InitAndroid(JavaVM* jvm);
|
||||||
|
|
||||||
|
} // namespace webrtc
|
||||||
|
|
||||||
|
#endif // SDK_ANDROID_NATIVE_API_BASE_INIT_H_
|
||||||
33
sdk/android/native_api/codecs/wrapper.cc
Normal file
33
sdk/android/native_api/codecs/wrapper.cc
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018 The WebRTC project authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license
|
||||||
|
* that can be found in the LICENSE file in the root of the source
|
||||||
|
* tree. An additional intellectual property rights grant can be found
|
||||||
|
* in the file PATENTS. All contributing project authors may
|
||||||
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "sdk/android/native_api/codecs/wrapper.h"
|
||||||
|
|
||||||
|
#include "rtc_base/ptr_util.h"
|
||||||
|
#include "sdk/android/src/jni/videodecoderfactorywrapper.h"
|
||||||
|
#include "sdk/android/src/jni/videoencoderfactorywrapper.h"
|
||||||
|
|
||||||
|
namespace webrtc {
|
||||||
|
|
||||||
|
std::unique_ptr<VideoDecoderFactory> JavaToNativeVideoDecoderFactory(
|
||||||
|
JNIEnv* jni,
|
||||||
|
jobject decoder_factory) {
|
||||||
|
return rtc::MakeUnique<jni::VideoDecoderFactoryWrapper>(
|
||||||
|
jni, JavaParamRef<jobject>(decoder_factory));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<VideoEncoderFactory> JavaToNativeVideoEncoderFactory(
|
||||||
|
JNIEnv* jni,
|
||||||
|
jobject en) {
|
||||||
|
return rtc::MakeUnique<jni::VideoEncoderFactoryWrapper>(
|
||||||
|
jni, JavaParamRef<jobject>(en));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace webrtc
|
||||||
36
sdk/android/native_api/codecs/wrapper.h
Normal file
36
sdk/android/native_api/codecs/wrapper.h
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018 The WebRTC project authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license
|
||||||
|
* that can be found in the LICENSE file in the root of the source
|
||||||
|
* tree. An additional intellectual property rights grant can be found
|
||||||
|
* in the file PATENTS. All contributing project authors may
|
||||||
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SDK_ANDROID_NATIVE_API_CODECS_WRAPPER_H_
|
||||||
|
#define SDK_ANDROID_NATIVE_API_CODECS_WRAPPER_H_
|
||||||
|
|
||||||
|
#include <jni.h>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "api/video_codecs/video_decoder_factory.h"
|
||||||
|
#include "api/video_codecs/video_encoder_factory.h"
|
||||||
|
|
||||||
|
namespace webrtc {
|
||||||
|
|
||||||
|
// Creates an instance of webrtc::VideoDecoderFactory from Java
|
||||||
|
// VideoDecoderFactory.
|
||||||
|
std::unique_ptr<VideoDecoderFactory> JavaToNativeVideoDecoderFactory(
|
||||||
|
JNIEnv* jni,
|
||||||
|
jobject decoder_factory);
|
||||||
|
|
||||||
|
// Creates an instance of webrtc::VideoEncoderFactory from Java
|
||||||
|
// VideoEncoderFactory.
|
||||||
|
std::unique_ptr<VideoEncoderFactory> JavaToNativeVideoEncoderFactory(
|
||||||
|
JNIEnv* jni,
|
||||||
|
jobject encoder_factory);
|
||||||
|
|
||||||
|
} // namespace webrtc
|
||||||
|
|
||||||
|
#endif // SDK_ANDROID_NATIVE_API_CODECS_WRAPPER_H_
|
||||||
@ -8,15 +8,15 @@
|
|||||||
* be found in the AUTHORS file in the root of the source tree.
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "sdk/android/src/jni/class_loader.h"
|
#include "sdk/android/native_api/jni/class_loader.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
#include "sdk/android/generated_base_jni/jni/WebRtcClassLoader_jni.h"
|
#include "sdk/android/generated_native_api_jni/jni/WebRtcClassLoader_jni.h"
|
||||||
#include "sdk/android/src/jni/jni_helpers.h"
|
#include "sdk/android/native_api/jni/java_types.h"
|
||||||
#include "sdk/android/src/jni/scoped_java_ref.h"
|
#include "sdk/android/native_api/jni/scoped_java_ref.h"
|
||||||
|
|
||||||
// Abort the process if |jni| has a Java exception pending. This macros uses the
|
// Abort the process if |jni| has a Java exception pending. This macros uses the
|
||||||
// comma operator to execute ExceptionDescribe and ExceptionClear ignoring their
|
// comma operator to execute ExceptionDescribe and ExceptionClear ignoring their
|
||||||
@ -26,7 +26,6 @@
|
|||||||
<< (jni->ExceptionDescribe(), jni->ExceptionClear(), "")
|
<< (jni->ExceptionDescribe(), jni->ExceptionClear(), "")
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
namespace jni {
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
@ -78,5 +77,4 @@ ScopedJavaLocalRef<jclass> GetClass(JNIEnv* env, const char* name) {
|
|||||||
: g_class_loader->FindClass(env, name);
|
: g_class_loader->FindClass(env, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace jni
|
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
40
sdk/android/native_api/jni/class_loader.h
Normal file
40
sdk/android/native_api/jni/class_loader.h
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2017 The WebRTC project authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license
|
||||||
|
* that can be found in the LICENSE file in the root of the source
|
||||||
|
* tree. An additional intellectual property rights grant can be found
|
||||||
|
* in the file PATENTS. All contributing project authors may
|
||||||
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Android's FindClass() is tricky because the app-specific ClassLoader is not
|
||||||
|
// consulted when there is no app-specific frame on the stack (i.e. when called
|
||||||
|
// from a thread created from native C++ code). These helper functions provide a
|
||||||
|
// workaround for this.
|
||||||
|
// http://developer.android.com/training/articles/perf-jni.html#faq_FindClass
|
||||||
|
|
||||||
|
#ifndef SDK_ANDROID_NATIVE_API_JNI_CLASS_LOADER_H_
|
||||||
|
#define SDK_ANDROID_NATIVE_API_JNI_CLASS_LOADER_H_
|
||||||
|
|
||||||
|
#include <jni.h>
|
||||||
|
|
||||||
|
#include "sdk/android/native_api/jni/scoped_java_ref.h"
|
||||||
|
|
||||||
|
namespace webrtc {
|
||||||
|
|
||||||
|
// This method should be called from JNI_OnLoad and before any calls to
|
||||||
|
// FindClass. This is normally called by InitAndroid.
|
||||||
|
void InitClassLoader(JNIEnv* env);
|
||||||
|
|
||||||
|
// This function is identical to JNIEnv::FindClass except that it works from any
|
||||||
|
// thread. This function loads and returns a local reference to the class with
|
||||||
|
// the given name. The name argument is a fully-qualified class name. For
|
||||||
|
// example, the fully-qualified class name for the java.lang.String class is:
|
||||||
|
// "java/lang/String". This function will be used from the JNI generated code
|
||||||
|
// and should rarely be used manually.
|
||||||
|
ScopedJavaLocalRef<jclass> GetClass(JNIEnv* env, const char* name);
|
||||||
|
|
||||||
|
} // namespace webrtc
|
||||||
|
|
||||||
|
#endif // SDK_ANDROID_NATIVE_API_JNI_CLASS_LOADER_H_
|
||||||
259
sdk/android/native_api/jni/java_types.cc
Normal file
259
sdk/android/native_api/jni/java_types.cc
Normal file
@ -0,0 +1,259 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 The WebRTC project authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license
|
||||||
|
* that can be found in the LICENSE file in the root of the source
|
||||||
|
* tree. An additional intellectual property rights grant can be found
|
||||||
|
* in the file PATENTS. All contributing project authors may
|
||||||
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "sdk/android/native_api/jni/java_types.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
#include "sdk/android/generated_external_classes_jni/jni/ArrayList_jni.h"
|
||||||
|
#include "sdk/android/generated_external_classes_jni/jni/Boolean_jni.h"
|
||||||
|
#include "sdk/android/generated_external_classes_jni/jni/Double_jni.h"
|
||||||
|
#include "sdk/android/generated_external_classes_jni/jni/Enum_jni.h"
|
||||||
|
#include "sdk/android/generated_external_classes_jni/jni/Integer_jni.h"
|
||||||
|
#include "sdk/android/generated_external_classes_jni/jni/Iterable_jni.h"
|
||||||
|
#include "sdk/android/generated_external_classes_jni/jni/Iterator_jni.h"
|
||||||
|
#include "sdk/android/generated_external_classes_jni/jni/LinkedHashMap_jni.h"
|
||||||
|
#include "sdk/android/generated_external_classes_jni/jni/Long_jni.h"
|
||||||
|
#include "sdk/android/generated_external_classes_jni/jni/Map_jni.h"
|
||||||
|
#include "sdk/android/generated_native_api_jni/jni/JniHelper_jni.h"
|
||||||
|
|
||||||
|
namespace webrtc {
|
||||||
|
|
||||||
|
bool IsNull(JNIEnv* jni, const JavaRef<jobject>& obj) {
|
||||||
|
return jni->IsSameObject(obj.obj(), nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Given a jstring, reinterprets it to a new native string.
|
||||||
|
std::string JavaToStdString(JNIEnv* jni, const JavaRef<jstring>& j_string) {
|
||||||
|
const ScopedJavaLocalRef<jbyteArray> j_byte_array =
|
||||||
|
Java_JniHelper_getStringBytes(jni, j_string);
|
||||||
|
|
||||||
|
const size_t len = jni->GetArrayLength(j_byte_array.obj());
|
||||||
|
CHECK_EXCEPTION(jni) << "error during GetArrayLength";
|
||||||
|
std::string str(len, '\0');
|
||||||
|
jni->GetByteArrayRegion(j_byte_array.obj(), 0, len,
|
||||||
|
reinterpret_cast<jbyte*>(&str[0]));
|
||||||
|
CHECK_EXCEPTION(jni) << "error during GetByteArrayRegion";
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Given a list of jstrings, reinterprets it to a new vector of native strings.
|
||||||
|
std::vector<std::string> JavaToStdVectorStrings(JNIEnv* jni,
|
||||||
|
const JavaRef<jobject>& list) {
|
||||||
|
std::vector<std::string> converted_list;
|
||||||
|
if (!list.is_null()) {
|
||||||
|
for (const JavaRef<jobject>& str : Iterable(jni, list)) {
|
||||||
|
converted_list.push_back(JavaToStdString(
|
||||||
|
jni, JavaParamRef<jstring>(static_cast<jstring>(str.obj()))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return converted_list;
|
||||||
|
}
|
||||||
|
|
||||||
|
rtc::Optional<int32_t> JavaToNativeOptionalInt(
|
||||||
|
JNIEnv* jni,
|
||||||
|
const JavaRef<jobject>& integer) {
|
||||||
|
if (IsNull(jni, integer))
|
||||||
|
return rtc::nullopt;
|
||||||
|
return JNI_Integer::Java_Integer_intValue(jni, integer);
|
||||||
|
}
|
||||||
|
|
||||||
|
rtc::Optional<bool> JavaToNativeOptionalBool(JNIEnv* jni,
|
||||||
|
const JavaRef<jobject>& boolean) {
|
||||||
|
if (IsNull(jni, boolean))
|
||||||
|
return rtc::nullopt;
|
||||||
|
return JNI_Boolean::Java_Boolean_booleanValue(jni, boolean);
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t JavaToNativeLong(JNIEnv* env, const JavaRef<jobject>& j_long) {
|
||||||
|
return JNI_Long::Java_Long_longValue(env, j_long);
|
||||||
|
}
|
||||||
|
|
||||||
|
ScopedJavaLocalRef<jobject> NativeToJavaBoolean(JNIEnv* env, bool b) {
|
||||||
|
return JNI_Boolean::Java_Boolean_ConstructorJLB_Z(env, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
ScopedJavaLocalRef<jobject> NativeToJavaInteger(JNIEnv* jni, int32_t i) {
|
||||||
|
return JNI_Integer::Java_Integer_ConstructorJLI_I(jni, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
ScopedJavaLocalRef<jobject> NativeToJavaLong(JNIEnv* env, int64_t u) {
|
||||||
|
return JNI_Long::Java_Long_ConstructorJLLO_J(env, u);
|
||||||
|
}
|
||||||
|
|
||||||
|
ScopedJavaLocalRef<jobject> NativeToJavaDouble(JNIEnv* env, double d) {
|
||||||
|
return JNI_Double::Java_Double_ConstructorJLD_D(env, d);
|
||||||
|
}
|
||||||
|
|
||||||
|
ScopedJavaLocalRef<jstring> NativeToJavaString(JNIEnv* env, const char* str) {
|
||||||
|
jstring j_str = env->NewStringUTF(str);
|
||||||
|
CHECK_EXCEPTION(env) << "error during NewStringUTF";
|
||||||
|
return ScopedJavaLocalRef<jstring>(env, j_str);
|
||||||
|
}
|
||||||
|
|
||||||
|
ScopedJavaLocalRef<jstring> NativeToJavaString(JNIEnv* jni,
|
||||||
|
const std::string& str) {
|
||||||
|
return NativeToJavaString(jni, str.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
ScopedJavaLocalRef<jobject> NativeToJavaInteger(
|
||||||
|
JNIEnv* jni,
|
||||||
|
const rtc::Optional<int32_t>& optional_int) {
|
||||||
|
return optional_int ? NativeToJavaInteger(jni, *optional_int) : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string GetJavaEnumName(JNIEnv* jni, const JavaRef<jobject>& j_enum) {
|
||||||
|
return JavaToStdString(jni, JNI_Enum::Java_Enum_name(jni, j_enum));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::map<std::string, std::string> JavaToStdMapStrings(
|
||||||
|
JNIEnv* jni,
|
||||||
|
const JavaRef<jobject>& j_map) {
|
||||||
|
const JavaRef<jobject>& j_entry_set = JNI_Map::Java_Map_entrySet(jni, j_map);
|
||||||
|
std::map<std::string, std::string> result;
|
||||||
|
for (const JavaRef<jobject>& j_entry : Iterable(jni, j_entry_set)) {
|
||||||
|
result.insert(std::make_pair(
|
||||||
|
JavaToStdString(jni, Java_JniHelper_getKey(jni, j_entry)),
|
||||||
|
JavaToStdString(jni, Java_JniHelper_getValue(jni, j_entry))));
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
Iterable::Iterable(JNIEnv* jni, const JavaRef<jobject>& iterable)
|
||||||
|
: jni_(jni), iterable_(jni, iterable) {}
|
||||||
|
|
||||||
|
Iterable::~Iterable() = default;
|
||||||
|
|
||||||
|
// Creates an iterator representing the end of any collection.
|
||||||
|
Iterable::Iterator::Iterator() = default;
|
||||||
|
|
||||||
|
// Creates an iterator pointing to the beginning of the specified collection.
|
||||||
|
Iterable::Iterator::Iterator(JNIEnv* jni, const JavaRef<jobject>& iterable)
|
||||||
|
: jni_(jni) {
|
||||||
|
iterator_ = JNI_Iterable::Java_Iterable_iterator(jni, iterable);
|
||||||
|
RTC_CHECK(!iterator_.is_null());
|
||||||
|
// Start at the first element in the collection.
|
||||||
|
++(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move constructor - necessary to be able to return iterator types from
|
||||||
|
// functions.
|
||||||
|
Iterable::Iterator::Iterator(Iterator&& other)
|
||||||
|
: jni_(std::move(other.jni_)),
|
||||||
|
iterator_(std::move(other.iterator_)),
|
||||||
|
value_(std::move(other.value_)),
|
||||||
|
thread_checker_(std::move(other.thread_checker_)) {}
|
||||||
|
|
||||||
|
Iterable::Iterator::~Iterator() = default;
|
||||||
|
|
||||||
|
// Advances the iterator one step.
|
||||||
|
Iterable::Iterator& Iterable::Iterator::operator++() {
|
||||||
|
RTC_CHECK(thread_checker_.CalledOnValidThread());
|
||||||
|
if (AtEnd()) {
|
||||||
|
// Can't move past the end.
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
bool has_next = JNI_Iterator::Java_Iterator_hasNext(jni_, iterator_);
|
||||||
|
if (!has_next) {
|
||||||
|
iterator_ = nullptr;
|
||||||
|
value_ = nullptr;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
value_ = JNI_Iterator::Java_Iterator_next(jni_, iterator_);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Iterable::Iterator::Remove() {
|
||||||
|
JNI_Iterator::Java_Iterator_remove(jni_, iterator_);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Provides a way to compare the iterator with itself and with the end iterator.
|
||||||
|
// Note: all other comparison results are undefined, just like for C++ input
|
||||||
|
// iterators.
|
||||||
|
bool Iterable::Iterator::operator==(const Iterable::Iterator& other) {
|
||||||
|
// Two different active iterators should never be compared.
|
||||||
|
RTC_DCHECK(this == &other || AtEnd() || other.AtEnd());
|
||||||
|
return AtEnd() == other.AtEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
ScopedJavaLocalRef<jobject>& Iterable::Iterator::operator*() {
|
||||||
|
RTC_CHECK(!AtEnd());
|
||||||
|
return value_;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Iterable::Iterator::AtEnd() const {
|
||||||
|
RTC_CHECK(thread_checker_.CalledOnValidThread());
|
||||||
|
return jni_ == nullptr || IsNull(jni_, iterator_);
|
||||||
|
}
|
||||||
|
|
||||||
|
ScopedJavaLocalRef<jobjectArray> NativeToJavaIntegerArray(
|
||||||
|
JNIEnv* env,
|
||||||
|
const std::vector<int32_t>& container) {
|
||||||
|
ScopedJavaLocalRef<jobject> (*convert_function)(JNIEnv*, int32_t) =
|
||||||
|
&NativeToJavaInteger;
|
||||||
|
return NativeToJavaObjectArray(env, container, java_lang_Integer_clazz(env),
|
||||||
|
convert_function);
|
||||||
|
}
|
||||||
|
|
||||||
|
ScopedJavaLocalRef<jobjectArray> NativeToJavaBooleanArray(
|
||||||
|
JNIEnv* env,
|
||||||
|
const std::vector<bool>& container) {
|
||||||
|
return NativeToJavaObjectArray(env, container, java_lang_Boolean_clazz(env),
|
||||||
|
&NativeToJavaBoolean);
|
||||||
|
}
|
||||||
|
|
||||||
|
ScopedJavaLocalRef<jobjectArray> NativeToJavaDoubleArray(
|
||||||
|
JNIEnv* env,
|
||||||
|
const std::vector<double>& container) {
|
||||||
|
return NativeToJavaObjectArray(env, container, java_lang_Double_clazz(env),
|
||||||
|
&NativeToJavaDouble);
|
||||||
|
}
|
||||||
|
|
||||||
|
ScopedJavaLocalRef<jobjectArray> NativeToJavaLongArray(
|
||||||
|
JNIEnv* env,
|
||||||
|
const std::vector<int64_t>& container) {
|
||||||
|
return NativeToJavaObjectArray(env, container, java_lang_Long_clazz(env),
|
||||||
|
&NativeToJavaLong);
|
||||||
|
}
|
||||||
|
|
||||||
|
ScopedJavaLocalRef<jobjectArray> NativeToJavaStringArray(
|
||||||
|
JNIEnv* env,
|
||||||
|
const std::vector<std::string>& container) {
|
||||||
|
ScopedJavaLocalRef<jstring> (*convert)(JNIEnv*, const std::string&) =
|
||||||
|
&NativeToJavaString;
|
||||||
|
return NativeToJavaObjectArray(
|
||||||
|
env, container,
|
||||||
|
static_cast<jclass>(Java_JniHelper_getStringClass(env).obj()), convert);
|
||||||
|
}
|
||||||
|
|
||||||
|
JavaMapBuilder::JavaMapBuilder(JNIEnv* env)
|
||||||
|
: env_(env),
|
||||||
|
j_map_(JNI_LinkedHashMap::Java_LinkedHashMap_ConstructorJULIHM(env)) {}
|
||||||
|
|
||||||
|
JavaMapBuilder::~JavaMapBuilder() = default;
|
||||||
|
|
||||||
|
void JavaMapBuilder::put(const JavaRef<jobject>& key,
|
||||||
|
const JavaRef<jobject>& value) {
|
||||||
|
JNI_Map::Java_Map_put(env_, j_map_, key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
JavaListBuilder::JavaListBuilder(JNIEnv* env)
|
||||||
|
: env_(env), j_list_(JNI_ArrayList::Java_ArrayList_ConstructorJUALI(env)) {}
|
||||||
|
|
||||||
|
JavaListBuilder::~JavaListBuilder() = default;
|
||||||
|
|
||||||
|
void JavaListBuilder::add(const JavaRef<jobject>& element) {
|
||||||
|
JNI_ArrayList::Java_ArrayList_addZ_JUE(env_, j_list_, element);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace webrtc
|
||||||
253
sdk/android/native_api/jni/java_types.h
Normal file
253
sdk/android/native_api/jni/java_types.h
Normal file
@ -0,0 +1,253 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 The WebRTC project authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license
|
||||||
|
* that can be found in the LICENSE file in the root of the source
|
||||||
|
* tree. An additional intellectual property rights grant can be found
|
||||||
|
* in the file PATENTS. All contributing project authors may
|
||||||
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Android's FindClass() is tricky because the app-specific ClassLoader is not
|
||||||
|
// consulted when there is no app-specific frame on the stack (i.e. when called
|
||||||
|
// from a thread created from native C++ code). These helper functions provide a
|
||||||
|
// workaround for this.
|
||||||
|
// http://developer.android.com/training/articles/perf-jni.html#faq_FindClass
|
||||||
|
|
||||||
|
#ifndef SDK_ANDROID_NATIVE_API_JNI_JAVA_TYPES_H_
|
||||||
|
#define SDK_ANDROID_NATIVE_API_JNI_JAVA_TYPES_H_
|
||||||
|
|
||||||
|
#include <jni.h>
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "api/optional.h"
|
||||||
|
#include "rtc_base/checks.h"
|
||||||
|
#include "rtc_base/thread_checker.h"
|
||||||
|
#include "sdk/android/native_api/jni/scoped_java_ref.h"
|
||||||
|
|
||||||
|
// Abort the process if |jni| has a Java exception pending.
|
||||||
|
// This macros uses the comma operator to execute ExceptionDescribe
|
||||||
|
// and ExceptionClear ignoring their return values and sending ""
|
||||||
|
// to the error stream.
|
||||||
|
#define CHECK_EXCEPTION(jni) \
|
||||||
|
RTC_CHECK(!jni->ExceptionCheck()) \
|
||||||
|
<< (jni->ExceptionDescribe(), jni->ExceptionClear(), "")
|
||||||
|
|
||||||
|
namespace webrtc {
|
||||||
|
|
||||||
|
// Returns true if |obj| == null in Java.
|
||||||
|
bool IsNull(JNIEnv* jni, const JavaRef<jobject>& obj);
|
||||||
|
|
||||||
|
// Given a (UTF-16) jstring return a new UTF-8 native string.
|
||||||
|
std::string JavaToStdString(JNIEnv* jni, const JavaRef<jstring>& j_string);
|
||||||
|
|
||||||
|
// Deprecated. Use scoped jobjects instead.
|
||||||
|
inline std::string JavaToStdString(JNIEnv* jni, jstring j_string) {
|
||||||
|
return JavaToStdString(jni, JavaParamRef<jstring>(j_string));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Given a List of (UTF-16) jstrings
|
||||||
|
// return a new vector of UTF-8 native strings.
|
||||||
|
std::vector<std::string> JavaToStdVectorStrings(JNIEnv* jni,
|
||||||
|
const JavaRef<jobject>& list);
|
||||||
|
|
||||||
|
rtc::Optional<int32_t> JavaToNativeOptionalInt(JNIEnv* jni,
|
||||||
|
const JavaRef<jobject>& integer);
|
||||||
|
rtc::Optional<bool> JavaToNativeOptionalBool(JNIEnv* jni,
|
||||||
|
const JavaRef<jobject>& boolean);
|
||||||
|
int64_t JavaToNativeLong(JNIEnv* env, const JavaRef<jobject>& j_long);
|
||||||
|
|
||||||
|
ScopedJavaLocalRef<jobject> NativeToJavaBoolean(JNIEnv* env, bool b);
|
||||||
|
ScopedJavaLocalRef<jobject> NativeToJavaInteger(JNIEnv* jni, int32_t i);
|
||||||
|
ScopedJavaLocalRef<jobject> NativeToJavaLong(JNIEnv* env, int64_t u);
|
||||||
|
ScopedJavaLocalRef<jobject> NativeToJavaDouble(JNIEnv* env, double d);
|
||||||
|
ScopedJavaLocalRef<jstring> NativeToJavaString(JNIEnv* jni, const char* str);
|
||||||
|
ScopedJavaLocalRef<jstring> NativeToJavaString(JNIEnv* jni,
|
||||||
|
const std::string& str);
|
||||||
|
ScopedJavaLocalRef<jobject> NativeToJavaInteger(
|
||||||
|
JNIEnv* jni,
|
||||||
|
const rtc::Optional<int32_t>& optional_int);
|
||||||
|
|
||||||
|
// Parses Map<String, String> to std::map<std::string, std::string>.
|
||||||
|
std::map<std::string, std::string> JavaToStdMapStrings(
|
||||||
|
JNIEnv* jni,
|
||||||
|
const JavaRef<jobject>& j_map);
|
||||||
|
|
||||||
|
// Deprecated. Use scoped jobjects instead.
|
||||||
|
inline std::map<std::string, std::string> JavaToStdMapStrings(JNIEnv* jni,
|
||||||
|
jobject j_map) {
|
||||||
|
return JavaToStdMapStrings(jni, JavaParamRef<jobject>(j_map));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns the name of a Java enum.
|
||||||
|
std::string GetJavaEnumName(JNIEnv* jni, const JavaRef<jobject>& j_enum);
|
||||||
|
|
||||||
|
// Provides a convenient way to iterate over a Java Iterable using the
|
||||||
|
// C++ range-for loop.
|
||||||
|
// E.g. for (jobject value : Iterable(jni, j_iterable)) { ... }
|
||||||
|
// Note: Since Java iterators cannot be duplicated, the iterator class is not
|
||||||
|
// copyable to prevent creating multiple C++ iterators that refer to the same
|
||||||
|
// Java iterator.
|
||||||
|
class Iterable {
|
||||||
|
public:
|
||||||
|
Iterable(JNIEnv* jni, const JavaRef<jobject>& iterable);
|
||||||
|
~Iterable();
|
||||||
|
|
||||||
|
class Iterator {
|
||||||
|
public:
|
||||||
|
// Creates an iterator representing the end of any collection.
|
||||||
|
Iterator();
|
||||||
|
// Creates an iterator pointing to the beginning of the specified
|
||||||
|
// collection.
|
||||||
|
Iterator(JNIEnv* jni, const JavaRef<jobject>& iterable);
|
||||||
|
|
||||||
|
// Move constructor - necessary to be able to return iterator types from
|
||||||
|
// functions.
|
||||||
|
Iterator(Iterator&& other);
|
||||||
|
|
||||||
|
~Iterator();
|
||||||
|
|
||||||
|
// Move assignment should not be used.
|
||||||
|
Iterator& operator=(Iterator&&) = delete;
|
||||||
|
|
||||||
|
// Advances the iterator one step.
|
||||||
|
Iterator& operator++();
|
||||||
|
|
||||||
|
// Removes the element the iterator is pointing to. Must still advance the
|
||||||
|
// iterator afterwards.
|
||||||
|
void Remove();
|
||||||
|
|
||||||
|
// Provides a way to compare the iterator with itself and with the end
|
||||||
|
// iterator.
|
||||||
|
// Note: all other comparison results are undefined, just like for C++ input
|
||||||
|
// iterators.
|
||||||
|
bool operator==(const Iterator& other);
|
||||||
|
bool operator!=(const Iterator& other) { return !(*this == other); }
|
||||||
|
ScopedJavaLocalRef<jobject>& operator*();
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool AtEnd() const;
|
||||||
|
|
||||||
|
JNIEnv* jni_ = nullptr;
|
||||||
|
ScopedJavaLocalRef<jobject> iterator_;
|
||||||
|
ScopedJavaLocalRef<jobject> value_;
|
||||||
|
rtc::ThreadChecker thread_checker_;
|
||||||
|
|
||||||
|
RTC_DISALLOW_COPY_AND_ASSIGN(Iterator);
|
||||||
|
};
|
||||||
|
|
||||||
|
Iterable::Iterator begin() { return Iterable::Iterator(jni_, iterable_); }
|
||||||
|
Iterable::Iterator end() { return Iterable::Iterator(); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
JNIEnv* jni_;
|
||||||
|
ScopedJavaLocalRef<jobject> iterable_;
|
||||||
|
|
||||||
|
RTC_DISALLOW_COPY_AND_ASSIGN(Iterable);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Helper function for converting std::vector<T> into a Java array.
|
||||||
|
template <typename T, typename Convert>
|
||||||
|
ScopedJavaLocalRef<jobjectArray> NativeToJavaObjectArray(
|
||||||
|
JNIEnv* env,
|
||||||
|
const std::vector<T>& container,
|
||||||
|
jclass clazz,
|
||||||
|
Convert convert) {
|
||||||
|
ScopedJavaLocalRef<jobjectArray> j_container(
|
||||||
|
env, env->NewObjectArray(container.size(), clazz, nullptr));
|
||||||
|
int i = 0;
|
||||||
|
for (const T& element : container) {
|
||||||
|
env->SetObjectArrayElement(j_container.obj(), i,
|
||||||
|
convert(env, element).obj());
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
return j_container;
|
||||||
|
}
|
||||||
|
|
||||||
|
ScopedJavaLocalRef<jobjectArray> NativeToJavaIntegerArray(
|
||||||
|
JNIEnv* env,
|
||||||
|
const std::vector<int32_t>& container);
|
||||||
|
ScopedJavaLocalRef<jobjectArray> NativeToJavaBooleanArray(
|
||||||
|
JNIEnv* env,
|
||||||
|
const std::vector<bool>& container);
|
||||||
|
ScopedJavaLocalRef<jobjectArray> NativeToJavaLongArray(
|
||||||
|
JNIEnv* env,
|
||||||
|
const std::vector<int64_t>& container);
|
||||||
|
ScopedJavaLocalRef<jobjectArray> NativeToJavaDoubleArray(
|
||||||
|
JNIEnv* env,
|
||||||
|
const std::vector<double>& container);
|
||||||
|
ScopedJavaLocalRef<jobjectArray> NativeToJavaStringArray(
|
||||||
|
JNIEnv* env,
|
||||||
|
const std::vector<std::string>& container);
|
||||||
|
|
||||||
|
template <typename T, typename Convert>
|
||||||
|
std::vector<T> JavaToNativeVector(JNIEnv* env,
|
||||||
|
const JavaRef<jobjectArray>& j_container,
|
||||||
|
Convert convert) {
|
||||||
|
std::vector<T> container;
|
||||||
|
const size_t size = env->GetArrayLength(j_container.obj());
|
||||||
|
container.reserve(size);
|
||||||
|
for (size_t i = 0; i < size; ++i) {
|
||||||
|
container.emplace_back(convert(
|
||||||
|
env, ScopedJavaLocalRef<jobject>(
|
||||||
|
env, env->GetObjectArrayElement(j_container.obj(), i))));
|
||||||
|
}
|
||||||
|
CHECK_EXCEPTION(env) << "Error during JavaToNativeVector";
|
||||||
|
return container;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is a helper class for NativeToJavaList(). Use that function instead of
|
||||||
|
// using this class directly.
|
||||||
|
class JavaListBuilder {
|
||||||
|
public:
|
||||||
|
explicit JavaListBuilder(JNIEnv* env);
|
||||||
|
~JavaListBuilder();
|
||||||
|
void add(const JavaRef<jobject>& element);
|
||||||
|
ScopedJavaLocalRef<jobject> java_list() { return j_list_; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
JNIEnv* env_;
|
||||||
|
ScopedJavaLocalRef<jobject> j_list_;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename C, typename Convert>
|
||||||
|
ScopedJavaLocalRef<jobject> NativeToJavaList(JNIEnv* env,
|
||||||
|
const C& container,
|
||||||
|
Convert convert) {
|
||||||
|
JavaListBuilder builder(env);
|
||||||
|
for (const auto& e : container)
|
||||||
|
builder.add(convert(env, e));
|
||||||
|
return builder.java_list();
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is a helper class for NativeToJavaMap(). Use that function instead of
|
||||||
|
// using this class directly.
|
||||||
|
class JavaMapBuilder {
|
||||||
|
public:
|
||||||
|
explicit JavaMapBuilder(JNIEnv* env);
|
||||||
|
~JavaMapBuilder();
|
||||||
|
void put(const JavaRef<jobject>& key, const JavaRef<jobject>& value);
|
||||||
|
ScopedJavaLocalRef<jobject> GetJavaMap() { return j_map_; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
JNIEnv* env_;
|
||||||
|
ScopedJavaLocalRef<jobject> j_map_;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename C, typename Convert>
|
||||||
|
ScopedJavaLocalRef<jobject> NativeToJavaMap(JNIEnv* env,
|
||||||
|
const C& container,
|
||||||
|
Convert convert) {
|
||||||
|
JavaMapBuilder builder(env);
|
||||||
|
for (const auto& e : container) {
|
||||||
|
const auto key_value_pair = convert(env, e);
|
||||||
|
builder.put(key_value_pair.first, key_value_pair.second);
|
||||||
|
}
|
||||||
|
return builder.GetJavaMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace webrtc
|
||||||
|
|
||||||
|
#endif // SDK_ANDROID_NATIVE_API_JNI_JAVA_TYPES_H_
|
||||||
21
sdk/android/native_api/jni/jvm.cc
Normal file
21
sdk/android/native_api/jni/jvm.cc
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018 The WebRTC project authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license
|
||||||
|
* that can be found in the LICENSE file in the root of the source
|
||||||
|
* tree. An additional intellectual property rights grant can be found
|
||||||
|
* in the file PATENTS. All contributing project authors may
|
||||||
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "sdk/android/native_api/jni/jvm.h"
|
||||||
|
|
||||||
|
#include "sdk/android/src/jni/jvm.h"
|
||||||
|
|
||||||
|
namespace webrtc {
|
||||||
|
|
||||||
|
JNIEnv* AttachCurrentThreadIfNeeded() {
|
||||||
|
return jni::AttachCurrentThreadIfNeeded();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace webrtc
|
||||||
21
sdk/android/native_api/jni/jvm.h
Normal file
21
sdk/android/native_api/jni/jvm.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018 The WebRTC project authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license
|
||||||
|
* that can be found in the LICENSE file in the root of the source
|
||||||
|
* tree. An additional intellectual property rights grant can be found
|
||||||
|
* in the file PATENTS. All contributing project authors may
|
||||||
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SDK_ANDROID_NATIVE_API_JNI_JVM_H_
|
||||||
|
#define SDK_ANDROID_NATIVE_API_JNI_JVM_H_
|
||||||
|
|
||||||
|
#include <jni.h>
|
||||||
|
|
||||||
|
namespace webrtc {
|
||||||
|
// Returns a JNI environment usable on this thread.
|
||||||
|
JNIEnv* AttachCurrentThreadIfNeeded();
|
||||||
|
} // namespace webrtc
|
||||||
|
|
||||||
|
#endif // SDK_ANDROID_NATIVE_API_JNI_JVM_H_
|
||||||
@ -11,18 +11,16 @@
|
|||||||
// Originally these classes are from Chromium.
|
// Originally these classes are from Chromium.
|
||||||
// https://cs.chromium.org/chromium/src/base/android/scoped_java_ref.h.
|
// https://cs.chromium.org/chromium/src/base/android/scoped_java_ref.h.
|
||||||
|
|
||||||
#ifndef SDK_ANDROID_SRC_JNI_SCOPED_JAVA_REF_H_
|
#ifndef SDK_ANDROID_NATIVE_API_JNI_SCOPED_JAVA_REF_H_
|
||||||
#define SDK_ANDROID_SRC_JNI_SCOPED_JAVA_REF_H_
|
#define SDK_ANDROID_NATIVE_API_JNI_SCOPED_JAVA_REF_H_
|
||||||
|
|
||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "rtc_base/constructormagic.h"
|
#include "rtc_base/constructormagic.h"
|
||||||
|
#include "sdk/android/native_api/jni/jvm.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
namespace jni {
|
|
||||||
|
|
||||||
JNIEnv* AttachCurrentThreadIfNeeded();
|
|
||||||
|
|
||||||
// Generic base class for ScopedJavaLocalRef and ScopedJavaGlobalRef. Useful
|
// Generic base class for ScopedJavaLocalRef and ScopedJavaGlobalRef. Useful
|
||||||
// for allowing functions to accept a reference without having to mandate
|
// for allowing functions to accept a reference without having to mandate
|
||||||
@ -199,7 +197,6 @@ class ScopedJavaGlobalRef : public JavaRef<T> {
|
|||||||
RTC_DISALLOW_COPY_AND_ASSIGN(ScopedJavaGlobalRef);
|
RTC_DISALLOW_COPY_AND_ASSIGN(ScopedJavaGlobalRef);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace jni
|
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
|
||||||
#endif // SDK_ANDROID_SRC_JNI_SCOPED_JAVA_REF_H_
|
#endif // SDK_ANDROID_NATIVE_API_JNI_SCOPED_JAVA_REF_H_
|
||||||
@ -12,6 +12,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "sdk/android/generated_base_jni/jni/Histogram_jni.h"
|
#include "sdk/android/generated_base_jni/jni/Histogram_jni.h"
|
||||||
|
#include "sdk/android/native_api/jni/java_types.h"
|
||||||
#include "sdk/android/src/jni/jni_helpers.h"
|
#include "sdk/android/src/jni/jni_helpers.h"
|
||||||
#include "system_wrappers/include/metrics.h"
|
#include "system_wrappers/include/metrics.h"
|
||||||
|
|
||||||
|
|||||||
@ -28,6 +28,7 @@
|
|||||||
#include "rtc_base/thread.h"
|
#include "rtc_base/thread.h"
|
||||||
#include "rtc_base/timeutils.h"
|
#include "rtc_base/timeutils.h"
|
||||||
#include "sdk/android/generated_video_jni/jni/MediaCodecVideoDecoder_jni.h"
|
#include "sdk/android/generated_video_jni/jni/MediaCodecVideoDecoder_jni.h"
|
||||||
|
#include "sdk/android/native_api/jni/java_types.h"
|
||||||
#include "sdk/android/src/jni/androidmediacodeccommon.h"
|
#include "sdk/android/src/jni/androidmediacodeccommon.h"
|
||||||
#include "sdk/android/src/jni/surfacetexturehelper.h"
|
#include "sdk/android/src/jni/surfacetexturehelper.h"
|
||||||
#include "sdk/android/src/jni/videoframe.h"
|
#include "sdk/android/src/jni/videoframe.h"
|
||||||
|
|||||||
@ -38,6 +38,7 @@
|
|||||||
#include "rtc_base/timeutils.h"
|
#include "rtc_base/timeutils.h"
|
||||||
#include "rtc_base/weak_ptr.h"
|
#include "rtc_base/weak_ptr.h"
|
||||||
#include "sdk/android/generated_video_jni/jni/MediaCodecVideoEncoder_jni.h"
|
#include "sdk/android/generated_video_jni/jni/MediaCodecVideoEncoder_jni.h"
|
||||||
|
#include "sdk/android/native_api/jni/java_types.h"
|
||||||
#include "sdk/android/src/jni/androidmediacodeccommon.h"
|
#include "sdk/android/src/jni/androidmediacodeccommon.h"
|
||||||
#include "sdk/android/src/jni/androidmediadecoder_jni.h"
|
#include "sdk/android/src/jni/androidmediadecoder_jni.h"
|
||||||
#include "sdk/android/src/jni/jni_helpers.h"
|
#include "sdk/android/src/jni/jni_helpers.h"
|
||||||
|
|||||||
@ -12,6 +12,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "sdk/android/generated_metrics_jni/jni/Metrics_jni.h"
|
#include "sdk/android/generated_metrics_jni/jni/Metrics_jni.h"
|
||||||
|
#include "sdk/android/native_api/jni/java_types.h"
|
||||||
#include "sdk/android/src/jni/jni_helpers.h"
|
#include "sdk/android/src/jni/jni_helpers.h"
|
||||||
#include "system_wrappers/include/metrics.h"
|
#include "system_wrappers/include/metrics.h"
|
||||||
#include "system_wrappers/include/metrics_default.h"
|
#include "system_wrappers/include/metrics_default.h"
|
||||||
|
|||||||
@ -8,34 +8,16 @@
|
|||||||
* be found in the AUTHORS file in the root of the source tree.
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Android's FindClass() is tricky because the app-specific ClassLoader is not
|
// Deprecated: use sdk/android/native_api/jni/class_loader.h instead.
|
||||||
// consulted when there is no app-specific frame on the stack (i.e. when called
|
|
||||||
// from a thread created from native C++ code). These helper functions provide a
|
|
||||||
// workaround for this.
|
|
||||||
// http://developer.android.com/training/articles/perf-jni.html#faq_FindClass
|
|
||||||
|
|
||||||
#ifndef SDK_ANDROID_SRC_JNI_CLASS_LOADER_H_
|
#ifndef SDK_ANDROID_SRC_JNI_CLASS_LOADER_H_
|
||||||
#define SDK_ANDROID_SRC_JNI_CLASS_LOADER_H_
|
#define SDK_ANDROID_SRC_JNI_CLASS_LOADER_H_
|
||||||
|
|
||||||
#include <jni.h>
|
#include "sdk/android/native_api/jni/class_loader.h"
|
||||||
|
|
||||||
#include "sdk/android/src/jni/scoped_java_ref.h"
|
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
namespace jni {
|
namespace jni {
|
||||||
|
using ::webrtc::InitClassLoader;
|
||||||
// This method should be called from JNI_OnLoad and before any calls to
|
|
||||||
// FindClass.
|
|
||||||
void InitClassLoader(JNIEnv* env);
|
|
||||||
|
|
||||||
// This function is identical to JNIEnv::FindClass except that it works from any
|
|
||||||
// thread. This function loads and returns a local reference to the class with
|
|
||||||
// the given name. The name argument is a fully-qualified class name. For
|
|
||||||
// example, the fully-qualified class name for the java.lang.String class is:
|
|
||||||
// "java/lang/String". This function will be used from the JNI generated code
|
|
||||||
// and should rarely be used manually.
|
|
||||||
ScopedJavaLocalRef<jclass> GetClass(JNIEnv* env, const char* name);
|
|
||||||
|
|
||||||
} // namespace jni
|
} // namespace jni
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
|
||||||
|
|||||||
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
// TODO(magjed): Update external clients to call webrtc::jni::InitClassLoader
|
// TODO(magjed): Update external clients to call webrtc::jni::InitClassLoader
|
||||||
// immediately instead.
|
// immediately instead.
|
||||||
#include "sdk/android/src/jni/class_loader.h"
|
#include "sdk/android/native_api/jni/class_loader.h"
|
||||||
#include "sdk/android/src/jni/jni_helpers.h"
|
#include "sdk/android/src/jni/jni_helpers.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
@ -21,7 +21,7 @@ namespace jni {
|
|||||||
|
|
||||||
// Deprecated. Call webrtc::jni::InitClassLoader() immediately instead..
|
// Deprecated. Call webrtc::jni::InitClassLoader() immediately instead..
|
||||||
inline void LoadGlobalClassReferenceHolder() {
|
inline void LoadGlobalClassReferenceHolder() {
|
||||||
webrtc::jni::InitClassLoader(GetEnv());
|
webrtc::InitClassLoader(GetEnv());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated. Do not call at all.
|
// Deprecated. Do not call at all.
|
||||||
|
|||||||
@ -13,6 +13,7 @@
|
|||||||
#include "common_video/include/video_frame.h"
|
#include "common_video/include/video_frame.h"
|
||||||
#include "rtc_base/timeutils.h"
|
#include "rtc_base/timeutils.h"
|
||||||
#include "sdk/android/generated_video_jni/jni/EncodedImage_jni.h"
|
#include "sdk/android/generated_video_jni/jni/EncodedImage_jni.h"
|
||||||
|
#include "sdk/android/native_api/jni/java_types.h"
|
||||||
#include "sdk/android/src/jni/jni_helpers.h"
|
#include "sdk/android/src/jni/jni_helpers.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|||||||
@ -14,7 +14,7 @@
|
|||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
#include "common_types.h" // NOLINT(build/include)
|
#include "common_types.h" // NOLINT(build/include)
|
||||||
|
|
||||||
#include "sdk/android/src/jni/scoped_java_ref.h"
|
#include "sdk/android/native_api/jni/scoped_java_ref.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
|
|||||||
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include "media/base/h264_profile_level_id.h"
|
#include "media/base/h264_profile_level_id.h"
|
||||||
#include "sdk/android/generated_video_jni/jni/HardwareVideoEncoderFactory_jni.h"
|
#include "sdk/android/generated_video_jni/jni/HardwareVideoEncoderFactory_jni.h"
|
||||||
|
#include "sdk/android/native_api/jni/java_types.h"
|
||||||
#include "sdk/android/src/jni/jni_helpers.h"
|
#include "sdk/android/src/jni/jni_helpers.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|||||||
@ -11,7 +11,7 @@
|
|||||||
#include "sdk/android/src/jni/jni_generator_helper.h"
|
#include "sdk/android/src/jni/jni_generator_helper.h"
|
||||||
|
|
||||||
#include "rtc_base/atomicops.h"
|
#include "rtc_base/atomicops.h"
|
||||||
#include "sdk/android/src/jni/class_loader.h"
|
#include "sdk/android/native_api/jni/class_loader.h"
|
||||||
|
|
||||||
namespace base {
|
namespace base {
|
||||||
namespace android {
|
namespace android {
|
||||||
@ -28,8 +28,7 @@ jclass LazyGetClass(JNIEnv* env,
|
|||||||
rtc::AtomicOps::AcquireLoadPtr(atomic_class_id);
|
rtc::AtomicOps::AcquireLoadPtr(atomic_class_id);
|
||||||
if (value)
|
if (value)
|
||||||
return reinterpret_cast<jclass>(value);
|
return reinterpret_cast<jclass>(value);
|
||||||
webrtc::jni::ScopedJavaGlobalRef<jclass> clazz(
|
webrtc::ScopedJavaGlobalRef<jclass> clazz(webrtc::GetClass(env, class_name));
|
||||||
webrtc::jni::GetClass(env, class_name));
|
|
||||||
RTC_CHECK(!clazz.is_null()) << class_name;
|
RTC_CHECK(!clazz.is_null()) << class_name;
|
||||||
base::subtle::AtomicWord null_aw = nullptr;
|
base::subtle::AtomicWord null_aw = nullptr;
|
||||||
base::subtle::AtomicWord cas_result = rtc::AtomicOps::CompareAndSwapPtr(
|
base::subtle::AtomicWord cas_result = rtc::AtomicOps::CompareAndSwapPtr(
|
||||||
|
|||||||
@ -19,7 +19,7 @@
|
|||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
|
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
#include "sdk/android/src/jni/scoped_java_ref.h"
|
#include "sdk/android/native_api/jni/scoped_java_ref.h"
|
||||||
|
|
||||||
// TODO(crbug.com/801260): Remove this macro definition as soon as
|
// TODO(crbug.com/801260): Remove this macro definition as soon as
|
||||||
// crrev.com/531028 will be reverted.
|
// crrev.com/531028 will be reverted.
|
||||||
@ -61,9 +61,9 @@ typedef void* AtomicWord;
|
|||||||
|
|
||||||
namespace android {
|
namespace android {
|
||||||
|
|
||||||
using webrtc::jni::JavaRef;
|
using webrtc::JavaRef;
|
||||||
using webrtc::jni::ScopedJavaLocalRef;
|
using webrtc::ScopedJavaLocalRef;
|
||||||
using webrtc::jni::JavaParamRef;
|
using webrtc::JavaParamRef;
|
||||||
|
|
||||||
// This function will initialize |atomic_class_id| to contain a global ref to
|
// This function will initialize |atomic_class_id| to contain a global ref to
|
||||||
// the given class, and will return that ref on subsequent calls. The caller is
|
// the given class, and will return that ref on subsequent calls. The caller is
|
||||||
|
|||||||
@ -9,133 +9,13 @@
|
|||||||
*/
|
*/
|
||||||
#include "sdk/android/src/jni/jni_helpers.h"
|
#include "sdk/android/src/jni/jni_helpers.h"
|
||||||
|
|
||||||
#include <asm/unistd.h>
|
|
||||||
#include <sys/prctl.h>
|
|
||||||
#include <sys/syscall.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "sdk/android/generated_base_jni/jni/JniHelper_jni.h"
|
#include "sdk/android/native_api/jni/java_types.h"
|
||||||
#include "sdk/android/generated_external_classes_jni/jni/ArrayList_jni.h"
|
|
||||||
#include "sdk/android/generated_external_classes_jni/jni/Boolean_jni.h"
|
|
||||||
#include "sdk/android/generated_external_classes_jni/jni/Double_jni.h"
|
|
||||||
#include "sdk/android/generated_external_classes_jni/jni/Enum_jni.h"
|
|
||||||
#include "sdk/android/generated_external_classes_jni/jni/Integer_jni.h"
|
|
||||||
#include "sdk/android/generated_external_classes_jni/jni/Iterable_jni.h"
|
|
||||||
#include "sdk/android/generated_external_classes_jni/jni/Iterator_jni.h"
|
|
||||||
#include "sdk/android/generated_external_classes_jni/jni/LinkedHashMap_jni.h"
|
|
||||||
#include "sdk/android/generated_external_classes_jni/jni/Long_jni.h"
|
|
||||||
#include "sdk/android/generated_external_classes_jni/jni/Map_jni.h"
|
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
namespace jni {
|
namespace jni {
|
||||||
|
|
||||||
static JavaVM* g_jvm = nullptr;
|
|
||||||
|
|
||||||
static pthread_once_t g_jni_ptr_once = PTHREAD_ONCE_INIT;
|
|
||||||
|
|
||||||
// Key for per-thread JNIEnv* data. Non-NULL in threads attached to |g_jvm| by
|
|
||||||
// AttachCurrentThreadIfNeeded(), NULL in unattached threads and threads that
|
|
||||||
// were attached by the JVM because of a Java->native call.
|
|
||||||
static pthread_key_t g_jni_ptr;
|
|
||||||
|
|
||||||
JavaVM *GetJVM() {
|
|
||||||
RTC_CHECK(g_jvm) << "JNI_OnLoad failed to run?";
|
|
||||||
return g_jvm;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return a |JNIEnv*| usable on this thread or NULL if this thread is detached.
|
|
||||||
JNIEnv* GetEnv() {
|
|
||||||
void* env = nullptr;
|
|
||||||
jint status = g_jvm->GetEnv(&env, JNI_VERSION_1_6);
|
|
||||||
RTC_CHECK(((env != nullptr) && (status == JNI_OK)) ||
|
|
||||||
((env == nullptr) && (status == JNI_EDETACHED)))
|
|
||||||
<< "Unexpected GetEnv return: " << status << ":" << env;
|
|
||||||
return reinterpret_cast<JNIEnv*>(env);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ThreadDestructor(void* prev_jni_ptr) {
|
|
||||||
// This function only runs on threads where |g_jni_ptr| is non-NULL, meaning
|
|
||||||
// we were responsible for originally attaching the thread, so are responsible
|
|
||||||
// for detaching it now. However, because some JVM implementations (notably
|
|
||||||
// Oracle's http://goo.gl/eHApYT) also use the pthread_key_create mechanism,
|
|
||||||
// the JVMs accounting info for this thread may already be wiped out by the
|
|
||||||
// time this is called. Thus it may appear we are already detached even though
|
|
||||||
// it was our responsibility to detach! Oh well.
|
|
||||||
if (!GetEnv())
|
|
||||||
return;
|
|
||||||
|
|
||||||
RTC_CHECK(GetEnv() == prev_jni_ptr)
|
|
||||||
<< "Detaching from another thread: " << prev_jni_ptr << ":" << GetEnv();
|
|
||||||
jint status = g_jvm->DetachCurrentThread();
|
|
||||||
RTC_CHECK(status == JNI_OK) << "Failed to detach thread: " << status;
|
|
||||||
RTC_CHECK(!GetEnv()) << "Detaching was a successful no-op???";
|
|
||||||
}
|
|
||||||
|
|
||||||
static void CreateJNIPtrKey() {
|
|
||||||
RTC_CHECK(!pthread_key_create(&g_jni_ptr, &ThreadDestructor))
|
|
||||||
<< "pthread_key_create";
|
|
||||||
}
|
|
||||||
|
|
||||||
jint InitGlobalJniVariables(JavaVM *jvm) {
|
|
||||||
RTC_CHECK(!g_jvm) << "InitGlobalJniVariables!";
|
|
||||||
g_jvm = jvm;
|
|
||||||
RTC_CHECK(g_jvm) << "InitGlobalJniVariables handed NULL?";
|
|
||||||
|
|
||||||
RTC_CHECK(!pthread_once(&g_jni_ptr_once, &CreateJNIPtrKey)) << "pthread_once";
|
|
||||||
|
|
||||||
JNIEnv* jni = nullptr;
|
|
||||||
if (jvm->GetEnv(reinterpret_cast<void**>(&jni), JNI_VERSION_1_6) != JNI_OK)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
return JNI_VERSION_1_6;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return thread ID as a string.
|
|
||||||
static std::string GetThreadId() {
|
|
||||||
char buf[21]; // Big enough to hold a kuint64max plus terminating NULL.
|
|
||||||
RTC_CHECK_LT(snprintf(buf, sizeof(buf), "%ld",
|
|
||||||
static_cast<long>(syscall(__NR_gettid))),
|
|
||||||
sizeof(buf))
|
|
||||||
<< "Thread id is bigger than uint64??";
|
|
||||||
return std::string(buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the current thread's name.
|
|
||||||
static std::string GetThreadName() {
|
|
||||||
char name[17] = {0};
|
|
||||||
if (prctl(PR_GET_NAME, name) != 0)
|
|
||||||
return std::string("<noname>");
|
|
||||||
return std::string(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return a |JNIEnv*| usable on this thread. Attaches to |g_jvm| if necessary.
|
|
||||||
JNIEnv* AttachCurrentThreadIfNeeded() {
|
|
||||||
JNIEnv* jni = GetEnv();
|
|
||||||
if (jni)
|
|
||||||
return jni;
|
|
||||||
RTC_CHECK(!pthread_getspecific(g_jni_ptr))
|
|
||||||
<< "TLS has a JNIEnv* but not attached?";
|
|
||||||
|
|
||||||
std::string name(GetThreadName() + " - " + GetThreadId());
|
|
||||||
JavaVMAttachArgs args;
|
|
||||||
args.version = JNI_VERSION_1_6;
|
|
||||||
args.name = &name[0];
|
|
||||||
args.group = nullptr;
|
|
||||||
// Deal with difference in signatures between Oracle's jni.h and Android's.
|
|
||||||
#ifdef _JAVASOFT_JNI_H_ // Oracle's jni.h violates the JNI spec!
|
|
||||||
void* env = nullptr;
|
|
||||||
#else
|
|
||||||
JNIEnv* env = nullptr;
|
|
||||||
#endif
|
|
||||||
RTC_CHECK(!g_jvm->AttachCurrentThread(&env, &args))
|
|
||||||
<< "Failed to attach thread";
|
|
||||||
RTC_CHECK(env) << "AttachCurrentThread handed back NULL!";
|
|
||||||
jni = reinterpret_cast<JNIEnv*>(env);
|
|
||||||
RTC_CHECK(!pthread_setspecific(g_jni_ptr, jni)) << "pthread_setspecific";
|
|
||||||
return jni;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return a |jlong| that will correctly convert back to |ptr|. This is needed
|
// Return a |jlong| that will correctly convert back to |ptr|. This is needed
|
||||||
// because the alternative (of silently passing a 32-bit pointer to a vararg
|
// because the alternative (of silently passing a 32-bit pointer to a vararg
|
||||||
// function expecting a 64-bit param) picks up garbage in the high 32 bits.
|
// function expecting a 64-bit param) picks up garbage in the high 32 bits.
|
||||||
@ -150,10 +30,6 @@ jlong jlongFromPointer(void* ptr) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsNull(JNIEnv* jni, const JavaRef<jobject>& obj) {
|
|
||||||
return jni->IsSameObject(obj.obj(), nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
ScopedJavaLocalRef<jobject> NewDirectByteBuffer(JNIEnv* env,
|
ScopedJavaLocalRef<jobject> NewDirectByteBuffer(JNIEnv* env,
|
||||||
void* address,
|
void* address,
|
||||||
jlong capacity) {
|
jlong capacity) {
|
||||||
@ -163,103 +39,6 @@ ScopedJavaLocalRef<jobject> NewDirectByteBuffer(JNIEnv* env,
|
|||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Given a jstring, reinterprets it to a new native string.
|
|
||||||
std::string JavaToStdString(JNIEnv* jni, const JavaRef<jstring>& j_string) {
|
|
||||||
const ScopedJavaLocalRef<jbyteArray> j_byte_array =
|
|
||||||
Java_JniHelper_getStringBytes(jni, j_string);
|
|
||||||
|
|
||||||
const size_t len = jni->GetArrayLength(j_byte_array.obj());
|
|
||||||
CHECK_EXCEPTION(jni) << "error during GetArrayLength";
|
|
||||||
std::string str(len, '\0');
|
|
||||||
jni->GetByteArrayRegion(j_byte_array.obj(), 0, len,
|
|
||||||
reinterpret_cast<jbyte*>(&str[0]));
|
|
||||||
CHECK_EXCEPTION(jni) << "error during GetByteArrayRegion";
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Given a list of jstrings, reinterprets it to a new vector of native strings.
|
|
||||||
std::vector<std::string> JavaToStdVectorStrings(JNIEnv* jni,
|
|
||||||
const JavaRef<jobject>& list) {
|
|
||||||
std::vector<std::string> converted_list;
|
|
||||||
if (!list.is_null()) {
|
|
||||||
for (const JavaRef<jobject>& str : Iterable(jni, list)) {
|
|
||||||
converted_list.push_back(JavaToStdString(
|
|
||||||
jni, JavaParamRef<jstring>(static_cast<jstring>(str.obj()))));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return converted_list;
|
|
||||||
}
|
|
||||||
|
|
||||||
rtc::Optional<int32_t> JavaToNativeOptionalInt(
|
|
||||||
JNIEnv* jni,
|
|
||||||
const JavaRef<jobject>& integer) {
|
|
||||||
if (IsNull(jni, integer))
|
|
||||||
return rtc::nullopt;
|
|
||||||
return JNI_Integer::Java_Integer_intValue(jni, integer);
|
|
||||||
}
|
|
||||||
|
|
||||||
rtc::Optional<bool> JavaToNativeOptionalBool(JNIEnv* jni,
|
|
||||||
const JavaRef<jobject>& boolean) {
|
|
||||||
if (IsNull(jni, boolean))
|
|
||||||
return rtc::nullopt;
|
|
||||||
return JNI_Boolean::Java_Boolean_booleanValue(jni, boolean);
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t JavaToNativeLong(JNIEnv* env, const JavaRef<jobject>& j_long) {
|
|
||||||
return JNI_Long::Java_Long_longValue(env, j_long);
|
|
||||||
}
|
|
||||||
|
|
||||||
ScopedJavaLocalRef<jobject> NativeToJavaBoolean(JNIEnv* env, bool b) {
|
|
||||||
return JNI_Boolean::Java_Boolean_ConstructorJLB_Z(env, b);
|
|
||||||
}
|
|
||||||
|
|
||||||
ScopedJavaLocalRef<jobject> NativeToJavaInteger(JNIEnv* jni, int32_t i) {
|
|
||||||
return JNI_Integer::Java_Integer_ConstructorJLI_I(jni, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
ScopedJavaLocalRef<jobject> NativeToJavaLong(JNIEnv* env, int64_t u) {
|
|
||||||
return JNI_Long::Java_Long_ConstructorJLLO_J(env, u);
|
|
||||||
}
|
|
||||||
|
|
||||||
ScopedJavaLocalRef<jobject> NativeToJavaDouble(JNIEnv* env, double d) {
|
|
||||||
return JNI_Double::Java_Double_ConstructorJLD_D(env, d);
|
|
||||||
}
|
|
||||||
|
|
||||||
ScopedJavaLocalRef<jstring> NativeToJavaString(JNIEnv* env, const char* str) {
|
|
||||||
jstring j_str = env->NewStringUTF(str);
|
|
||||||
CHECK_EXCEPTION(env) << "error during NewStringUTF";
|
|
||||||
return ScopedJavaLocalRef<jstring>(env, j_str);
|
|
||||||
}
|
|
||||||
|
|
||||||
ScopedJavaLocalRef<jstring> NativeToJavaString(JNIEnv* jni,
|
|
||||||
const std::string& str) {
|
|
||||||
return NativeToJavaString(jni, str.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
ScopedJavaLocalRef<jobject> NativeToJavaInteger(
|
|
||||||
JNIEnv* jni,
|
|
||||||
const rtc::Optional<int32_t>& optional_int) {
|
|
||||||
return optional_int ? NativeToJavaInteger(jni, *optional_int) : nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string GetJavaEnumName(JNIEnv* jni, const JavaRef<jobject>& j_enum) {
|
|
||||||
return JavaToStdString(jni, JNI_Enum::Java_Enum_name(jni, j_enum));
|
|
||||||
}
|
|
||||||
|
|
||||||
std::map<std::string, std::string> JavaToStdMapStrings(
|
|
||||||
JNIEnv* jni,
|
|
||||||
const JavaRef<jobject>& j_map) {
|
|
||||||
const JavaRef<jobject>& j_entry_set = JNI_Map::Java_Map_entrySet(jni, j_map);
|
|
||||||
std::map<std::string, std::string> result;
|
|
||||||
for (const JavaRef<jobject>& j_entry : Iterable(jni, j_entry_set)) {
|
|
||||||
result.insert(std::make_pair(
|
|
||||||
JavaToStdString(jni, Java_JniHelper_getKey(jni, j_entry)),
|
|
||||||
JavaToStdString(jni, Java_JniHelper_getValue(jni, j_entry))));
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
jobject NewGlobalRef(JNIEnv* jni, jobject o) {
|
jobject NewGlobalRef(JNIEnv* jni, jobject o) {
|
||||||
jobject ret = jni->NewGlobalRef(o);
|
jobject ret = jni->NewGlobalRef(o);
|
||||||
CHECK_EXCEPTION(jni) << "error during NewGlobalRef";
|
CHECK_EXCEPTION(jni) << "error during NewGlobalRef";
|
||||||
@ -282,133 +61,5 @@ ScopedLocalRefFrame::~ScopedLocalRefFrame() {
|
|||||||
jni_->PopLocalFrame(nullptr);
|
jni_->PopLocalFrame(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterable::Iterable(JNIEnv* jni, const JavaRef<jobject>& iterable)
|
|
||||||
: jni_(jni), iterable_(jni, iterable) {}
|
|
||||||
|
|
||||||
Iterable::~Iterable() = default;
|
|
||||||
|
|
||||||
// Creates an iterator representing the end of any collection.
|
|
||||||
Iterable::Iterator::Iterator() = default;
|
|
||||||
|
|
||||||
// Creates an iterator pointing to the beginning of the specified collection.
|
|
||||||
Iterable::Iterator::Iterator(JNIEnv* jni, const JavaRef<jobject>& iterable)
|
|
||||||
: jni_(jni) {
|
|
||||||
iterator_ = JNI_Iterable::Java_Iterable_iterator(jni, iterable);
|
|
||||||
RTC_CHECK(!iterator_.is_null());
|
|
||||||
// Start at the first element in the collection.
|
|
||||||
++(*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Move constructor - necessary to be able to return iterator types from
|
|
||||||
// functions.
|
|
||||||
Iterable::Iterator::Iterator(Iterator&& other)
|
|
||||||
: jni_(std::move(other.jni_)),
|
|
||||||
iterator_(std::move(other.iterator_)),
|
|
||||||
value_(std::move(other.value_)),
|
|
||||||
thread_checker_(std::move(other.thread_checker_)){};
|
|
||||||
|
|
||||||
Iterable::Iterator::~Iterator() = default;
|
|
||||||
|
|
||||||
// Advances the iterator one step.
|
|
||||||
Iterable::Iterator& Iterable::Iterator::operator++() {
|
|
||||||
RTC_CHECK(thread_checker_.CalledOnValidThread());
|
|
||||||
if (AtEnd()) {
|
|
||||||
// Can't move past the end.
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
bool has_next = JNI_Iterator::Java_Iterator_hasNext(jni_, iterator_);
|
|
||||||
if (!has_next) {
|
|
||||||
iterator_ = nullptr;
|
|
||||||
value_ = nullptr;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
value_ = JNI_Iterator::Java_Iterator_next(jni_, iterator_);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Iterable::Iterator::Remove() {
|
|
||||||
JNI_Iterator::Java_Iterator_remove(jni_, iterator_);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Provides a way to compare the iterator with itself and with the end iterator.
|
|
||||||
// Note: all other comparison results are undefined, just like for C++ input
|
|
||||||
// iterators.
|
|
||||||
bool Iterable::Iterator::operator==(const Iterable::Iterator& other) {
|
|
||||||
// Two different active iterators should never be compared.
|
|
||||||
RTC_DCHECK(this == &other || AtEnd() || other.AtEnd());
|
|
||||||
return AtEnd() == other.AtEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
ScopedJavaLocalRef<jobject>& Iterable::Iterator::operator*() {
|
|
||||||
RTC_CHECK(!AtEnd());
|
|
||||||
return value_;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Iterable::Iterator::AtEnd() const {
|
|
||||||
RTC_CHECK(thread_checker_.CalledOnValidThread());
|
|
||||||
return jni_ == nullptr || IsNull(jni_, iterator_);
|
|
||||||
}
|
|
||||||
|
|
||||||
ScopedJavaLocalRef<jobjectArray> NativeToJavaIntegerArray(
|
|
||||||
JNIEnv* env,
|
|
||||||
const std::vector<int32_t>& container) {
|
|
||||||
ScopedJavaLocalRef<jobject> (*convert_function)(JNIEnv*, int32_t) =
|
|
||||||
&NativeToJavaInteger;
|
|
||||||
return NativeToJavaObjectArray(env, container, java_lang_Integer_clazz(env),
|
|
||||||
convert_function);
|
|
||||||
}
|
|
||||||
|
|
||||||
ScopedJavaLocalRef<jobjectArray> NativeToJavaBooleanArray(
|
|
||||||
JNIEnv* env,
|
|
||||||
const std::vector<bool>& container) {
|
|
||||||
return NativeToJavaObjectArray(env, container, java_lang_Boolean_clazz(env),
|
|
||||||
&NativeToJavaBoolean);
|
|
||||||
}
|
|
||||||
|
|
||||||
ScopedJavaLocalRef<jobjectArray> NativeToJavaDoubleArray(
|
|
||||||
JNIEnv* env,
|
|
||||||
const std::vector<double>& container) {
|
|
||||||
return NativeToJavaObjectArray(env, container, java_lang_Double_clazz(env),
|
|
||||||
&NativeToJavaDouble);
|
|
||||||
}
|
|
||||||
|
|
||||||
ScopedJavaLocalRef<jobjectArray> NativeToJavaLongArray(
|
|
||||||
JNIEnv* env,
|
|
||||||
const std::vector<int64_t>& container) {
|
|
||||||
return NativeToJavaObjectArray(env, container, java_lang_Long_clazz(env),
|
|
||||||
&NativeToJavaLong);
|
|
||||||
}
|
|
||||||
|
|
||||||
ScopedJavaLocalRef<jobjectArray> NativeToJavaStringArray(
|
|
||||||
JNIEnv* env,
|
|
||||||
const std::vector<std::string>& container) {
|
|
||||||
ScopedJavaLocalRef<jstring> (*convert)(JNIEnv*, const std::string&) =
|
|
||||||
&NativeToJavaString;
|
|
||||||
return NativeToJavaObjectArray(
|
|
||||||
env, container,
|
|
||||||
static_cast<jclass>(Java_JniHelper_getStringClass(env).obj()), convert);
|
|
||||||
}
|
|
||||||
|
|
||||||
JavaMapBuilder::JavaMapBuilder(JNIEnv* env)
|
|
||||||
: env_(env),
|
|
||||||
j_map_(JNI_LinkedHashMap::Java_LinkedHashMap_ConstructorJULIHM(env)) {}
|
|
||||||
|
|
||||||
JavaMapBuilder::~JavaMapBuilder() = default;
|
|
||||||
|
|
||||||
void JavaMapBuilder::put(const JavaRef<jobject>& key,
|
|
||||||
const JavaRef<jobject>& value) {
|
|
||||||
JNI_Map::Java_Map_put(env_, j_map_, key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
JavaListBuilder::JavaListBuilder(JNIEnv* env)
|
|
||||||
: env_(env), j_list_(JNI_ArrayList::Java_ArrayList_ConstructorJUALI(env)) {}
|
|
||||||
|
|
||||||
JavaListBuilder::~JavaListBuilder() = default;
|
|
||||||
|
|
||||||
void JavaListBuilder::add(const JavaRef<jobject>& element) {
|
|
||||||
JNI_ArrayList::Java_ArrayList_addZ_JUE(env_, j_list_, element);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace jni
|
} // namespace jni
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
|||||||
@ -15,24 +15,11 @@
|
|||||||
#define SDK_ANDROID_SRC_JNI_JNI_HELPERS_H_
|
#define SDK_ANDROID_SRC_JNI_JNI_HELPERS_H_
|
||||||
|
|
||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
#include <map>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "api/optional.h"
|
#include "sdk/android/native_api/jni/java_types.h"
|
||||||
#include "rtc_base/checks.h"
|
#include "sdk/android/native_api/jni/scoped_java_ref.h"
|
||||||
#include "rtc_base/constructormagic.h"
|
#include "sdk/android/src/jni/jvm.h"
|
||||||
#include "rtc_base/refcount.h"
|
|
||||||
#include "rtc_base/thread_checker.h"
|
|
||||||
#include "sdk/android/src/jni/scoped_java_ref.h"
|
|
||||||
|
|
||||||
// Abort the process if |jni| has a Java exception pending.
|
|
||||||
// This macros uses the comma operator to execute ExceptionDescribe
|
|
||||||
// and ExceptionClear ignoring their return values and sending ""
|
|
||||||
// to the error stream.
|
|
||||||
#define CHECK_EXCEPTION(jni) \
|
|
||||||
RTC_CHECK(!jni->ExceptionCheck()) \
|
|
||||||
<< (jni->ExceptionDescribe(), jni->ExceptionClear(), "")
|
|
||||||
|
|
||||||
// Convenience macro defining JNI-accessible methods in the org.webrtc package.
|
// Convenience macro defining JNI-accessible methods in the org.webrtc package.
|
||||||
// Eliminates unnecessary boilerplate and line-wraps, reducing visual clutter.
|
// Eliminates unnecessary boilerplate and line-wraps, reducing visual clutter.
|
||||||
@ -42,70 +29,17 @@
|
|||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
namespace jni {
|
namespace jni {
|
||||||
|
|
||||||
jint InitGlobalJniVariables(JavaVM *jvm);
|
// TODO(sakal): Remove once clients have migrated.
|
||||||
|
using ::webrtc::JavaToStdMapStrings;
|
||||||
// Return a |JNIEnv*| usable on this thread or NULL if this thread is detached.
|
|
||||||
JNIEnv* GetEnv();
|
|
||||||
|
|
||||||
JavaVM *GetJVM();
|
|
||||||
|
|
||||||
// Return a |JNIEnv*| usable on this thread. Attaches to |g_jvm| if necessary.
|
|
||||||
JNIEnv* AttachCurrentThreadIfNeeded();
|
|
||||||
|
|
||||||
// Return a |jlong| that will correctly convert back to |ptr|. This is needed
|
// Return a |jlong| that will correctly convert back to |ptr|. This is needed
|
||||||
// because the alternative (of silently passing a 32-bit pointer to a vararg
|
// because the alternative (of silently passing a 32-bit pointer to a vararg
|
||||||
// function expecting a 64-bit param) picks up garbage in the high 32 bits.
|
// function expecting a 64-bit param) picks up garbage in the high 32 bits.
|
||||||
jlong jlongFromPointer(void* ptr);
|
jlong jlongFromPointer(void* ptr);
|
||||||
|
|
||||||
// Returns true if |obj| == null in Java.
|
|
||||||
bool IsNull(JNIEnv* jni, const JavaRef<jobject>& obj);
|
|
||||||
|
|
||||||
ScopedJavaLocalRef<jobject> NewDirectByteBuffer(JNIEnv* env,
|
ScopedJavaLocalRef<jobject> NewDirectByteBuffer(JNIEnv* env,
|
||||||
void* address,
|
void* address,
|
||||||
jlong capacity);
|
jlong capacity);
|
||||||
// Given a (UTF-16) jstring return a new UTF-8 native string.
|
|
||||||
std::string JavaToStdString(JNIEnv* jni, const JavaRef<jstring>& j_string);
|
|
||||||
|
|
||||||
// Deprecated. Use scoped jobjects instead.
|
|
||||||
inline std::string JavaToStdString(JNIEnv* jni, jstring j_string) {
|
|
||||||
return JavaToStdString(jni, JavaParamRef<jstring>(j_string));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Given a List of (UTF-16) jstrings
|
|
||||||
// return a new vector of UTF-8 native strings.
|
|
||||||
std::vector<std::string> JavaToStdVectorStrings(JNIEnv* jni,
|
|
||||||
const JavaRef<jobject>& list);
|
|
||||||
|
|
||||||
rtc::Optional<int32_t> JavaToNativeOptionalInt(JNIEnv* jni,
|
|
||||||
const JavaRef<jobject>& integer);
|
|
||||||
rtc::Optional<bool> JavaToNativeOptionalBool(JNIEnv* jni,
|
|
||||||
const JavaRef<jobject>& boolean);
|
|
||||||
int64_t JavaToNativeLong(JNIEnv* env, const JavaRef<jobject>& j_long);
|
|
||||||
|
|
||||||
ScopedJavaLocalRef<jobject> NativeToJavaBoolean(JNIEnv* env, bool b);
|
|
||||||
ScopedJavaLocalRef<jobject> NativeToJavaInteger(JNIEnv* jni, int32_t i);
|
|
||||||
ScopedJavaLocalRef<jobject> NativeToJavaLong(JNIEnv* env, int64_t u);
|
|
||||||
ScopedJavaLocalRef<jobject> NativeToJavaDouble(JNIEnv* env, double d);
|
|
||||||
ScopedJavaLocalRef<jstring> NativeToJavaString(JNIEnv* jni, const char* str);
|
|
||||||
ScopedJavaLocalRef<jstring> NativeToJavaString(JNIEnv* jni,
|
|
||||||
const std::string& str);
|
|
||||||
ScopedJavaLocalRef<jobject> NativeToJavaInteger(
|
|
||||||
JNIEnv* jni,
|
|
||||||
const rtc::Optional<int32_t>& optional_int);
|
|
||||||
|
|
||||||
// Parses Map<String, String> to std::map<std::string, std::string>.
|
|
||||||
std::map<std::string, std::string> JavaToStdMapStrings(
|
|
||||||
JNIEnv* jni,
|
|
||||||
const JavaRef<jobject>& j_map);
|
|
||||||
|
|
||||||
// Deprecated. Use scoped jobjects instead.
|
|
||||||
inline std::map<std::string, std::string> JavaToStdMapStrings(JNIEnv* jni,
|
|
||||||
jobject j_map) {
|
|
||||||
return JavaToStdMapStrings(jni, JavaParamRef<jobject>(j_map));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the name of a Java enum.
|
|
||||||
std::string GetJavaEnumName(JNIEnv* jni, const JavaRef<jobject>& j_enum);
|
|
||||||
|
|
||||||
jobject NewGlobalRef(JNIEnv* jni, jobject o);
|
jobject NewGlobalRef(JNIEnv* jni, jobject o);
|
||||||
|
|
||||||
@ -123,178 +57,13 @@ class ScopedLocalRefFrame {
|
|||||||
JNIEnv* jni_;
|
JNIEnv* jni_;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Provides a convenient way to iterate over a Java Iterable using the
|
|
||||||
// C++ range-for loop.
|
|
||||||
// E.g. for (jobject value : Iterable(jni, j_iterable)) { ... }
|
|
||||||
// Note: Since Java iterators cannot be duplicated, the iterator class is not
|
|
||||||
// copyable to prevent creating multiple C++ iterators that refer to the same
|
|
||||||
// Java iterator.
|
|
||||||
class Iterable {
|
|
||||||
public:
|
|
||||||
Iterable(JNIEnv* jni, const JavaRef<jobject>& iterable);
|
|
||||||
~Iterable();
|
|
||||||
|
|
||||||
class Iterator {
|
|
||||||
public:
|
|
||||||
// Creates an iterator representing the end of any collection.
|
|
||||||
Iterator();
|
|
||||||
// Creates an iterator pointing to the beginning of the specified
|
|
||||||
// collection.
|
|
||||||
Iterator(JNIEnv* jni, const JavaRef<jobject>& iterable);
|
|
||||||
|
|
||||||
// Move constructor - necessary to be able to return iterator types from
|
|
||||||
// functions.
|
|
||||||
Iterator(Iterator&& other);
|
|
||||||
|
|
||||||
~Iterator();
|
|
||||||
|
|
||||||
// Move assignment should not be used.
|
|
||||||
Iterator& operator=(Iterator&&) = delete;
|
|
||||||
|
|
||||||
// Advances the iterator one step.
|
|
||||||
Iterator& operator++();
|
|
||||||
|
|
||||||
// Removes the element the iterator is pointing to. Must still advance the
|
|
||||||
// iterator afterwards.
|
|
||||||
void Remove();
|
|
||||||
|
|
||||||
// Provides a way to compare the iterator with itself and with the end
|
|
||||||
// iterator.
|
|
||||||
// Note: all other comparison results are undefined, just like for C++ input
|
|
||||||
// iterators.
|
|
||||||
bool operator==(const Iterator& other);
|
|
||||||
bool operator!=(const Iterator& other) { return !(*this == other); }
|
|
||||||
ScopedJavaLocalRef<jobject>& operator*();
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool AtEnd() const;
|
|
||||||
|
|
||||||
JNIEnv* jni_ = nullptr;
|
|
||||||
ScopedJavaLocalRef<jobject> iterator_;
|
|
||||||
ScopedJavaLocalRef<jobject> value_;
|
|
||||||
rtc::ThreadChecker thread_checker_;
|
|
||||||
|
|
||||||
RTC_DISALLOW_COPY_AND_ASSIGN(Iterator);
|
|
||||||
};
|
|
||||||
|
|
||||||
Iterable::Iterator begin() { return Iterable::Iterator(jni_, iterable_); }
|
|
||||||
Iterable::Iterator end() { return Iterable::Iterator(); }
|
|
||||||
|
|
||||||
private:
|
|
||||||
JNIEnv* jni_;
|
|
||||||
ScopedJavaLocalRef<jobject> iterable_;
|
|
||||||
|
|
||||||
RTC_DISALLOW_COPY_AND_ASSIGN(Iterable);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Helper function for converting std::vector<T> into a Java array.
|
|
||||||
template <typename T, typename Convert>
|
|
||||||
ScopedJavaLocalRef<jobjectArray> NativeToJavaObjectArray(
|
|
||||||
JNIEnv* env,
|
|
||||||
const std::vector<T>& container,
|
|
||||||
jclass clazz,
|
|
||||||
Convert convert) {
|
|
||||||
ScopedJavaLocalRef<jobjectArray> j_container(
|
|
||||||
env, env->NewObjectArray(container.size(), clazz, nullptr));
|
|
||||||
int i = 0;
|
|
||||||
for (const T& element : container) {
|
|
||||||
env->SetObjectArrayElement(j_container.obj(), i,
|
|
||||||
convert(env, element).obj());
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
return j_container;
|
|
||||||
}
|
|
||||||
|
|
||||||
ScopedJavaLocalRef<jobjectArray> NativeToJavaIntegerArray(
|
|
||||||
JNIEnv* env,
|
|
||||||
const std::vector<int32_t>& container);
|
|
||||||
ScopedJavaLocalRef<jobjectArray> NativeToJavaBooleanArray(
|
|
||||||
JNIEnv* env,
|
|
||||||
const std::vector<bool>& container);
|
|
||||||
ScopedJavaLocalRef<jobjectArray> NativeToJavaLongArray(
|
|
||||||
JNIEnv* env,
|
|
||||||
const std::vector<int64_t>& container);
|
|
||||||
ScopedJavaLocalRef<jobjectArray> NativeToJavaDoubleArray(
|
|
||||||
JNIEnv* env,
|
|
||||||
const std::vector<double>& container);
|
|
||||||
ScopedJavaLocalRef<jobjectArray> NativeToJavaStringArray(
|
|
||||||
JNIEnv* env,
|
|
||||||
const std::vector<std::string>& container);
|
|
||||||
|
|
||||||
template <typename T, typename Convert>
|
|
||||||
std::vector<T> JavaToNativeVector(JNIEnv* env,
|
|
||||||
const JavaRef<jobjectArray>& j_container,
|
|
||||||
Convert convert) {
|
|
||||||
std::vector<T> container;
|
|
||||||
const size_t size = env->GetArrayLength(j_container.obj());
|
|
||||||
container.reserve(size);
|
|
||||||
for (size_t i = 0; i < size; ++i) {
|
|
||||||
container.emplace_back(convert(
|
|
||||||
env, ScopedJavaLocalRef<jobject>(
|
|
||||||
env, env->GetObjectArrayElement(j_container.obj(), i))));
|
|
||||||
}
|
|
||||||
CHECK_EXCEPTION(env) << "Error during JavaToNativeVector";
|
|
||||||
return container;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is a helper class for NativeToJavaList(). Use that function instead of
|
|
||||||
// using this class directly.
|
|
||||||
class JavaListBuilder {
|
|
||||||
public:
|
|
||||||
explicit JavaListBuilder(JNIEnv* env);
|
|
||||||
~JavaListBuilder();
|
|
||||||
void add(const JavaRef<jobject>& element);
|
|
||||||
ScopedJavaLocalRef<jobject> java_list() { return j_list_; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
JNIEnv* env_;
|
|
||||||
ScopedJavaLocalRef<jobject> j_list_;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename C, typename Convert>
|
|
||||||
ScopedJavaLocalRef<jobject> NativeToJavaList(JNIEnv* env,
|
|
||||||
const C& container,
|
|
||||||
Convert convert) {
|
|
||||||
JavaListBuilder builder(env);
|
|
||||||
for (const auto& e : container)
|
|
||||||
builder.add(convert(env, e));
|
|
||||||
return builder.java_list();
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is a helper class for NativeToJavaMap(). Use that function instead of
|
|
||||||
// using this class directly.
|
|
||||||
class JavaMapBuilder {
|
|
||||||
public:
|
|
||||||
explicit JavaMapBuilder(JNIEnv* env);
|
|
||||||
~JavaMapBuilder();
|
|
||||||
void put(const JavaRef<jobject>& key, const JavaRef<jobject>& value);
|
|
||||||
ScopedJavaLocalRef<jobject> GetJavaMap() { return j_map_; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
JNIEnv* env_;
|
|
||||||
ScopedJavaLocalRef<jobject> j_map_;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename C, typename Convert>
|
|
||||||
ScopedJavaLocalRef<jobject> NativeToJavaMap(JNIEnv* env,
|
|
||||||
const C& container,
|
|
||||||
Convert convert) {
|
|
||||||
JavaMapBuilder builder(env);
|
|
||||||
for (const auto& e : container) {
|
|
||||||
ScopedLocalRefFrame local_ref_frame(env);
|
|
||||||
const auto key_value_pair = convert(env, e);
|
|
||||||
builder.put(key_value_pair.first, key_value_pair.second);
|
|
||||||
}
|
|
||||||
return builder.GetJavaMap();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace jni
|
} // namespace jni
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
|
||||||
// TODO(magjed): Remove once external clients are updated.
|
// TODO(magjed): Remove once external clients are updated.
|
||||||
namespace webrtc_jni {
|
namespace webrtc_jni {
|
||||||
|
|
||||||
using webrtc::jni::AttachCurrentThreadIfNeeded;
|
using webrtc::AttachCurrentThreadIfNeeded;
|
||||||
using webrtc::jni::InitGlobalJniVariables;
|
using webrtc::jni::InitGlobalJniVariables;
|
||||||
|
|
||||||
} // namespace webrtc_jni
|
} // namespace webrtc_jni
|
||||||
|
|||||||
133
sdk/android/src/jni/jvm.cc
Normal file
133
sdk/android/src/jni/jvm.cc
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018 The WebRTC project authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license
|
||||||
|
* that can be found in the LICENSE file in the root of the source
|
||||||
|
* tree. An additional intellectual property rights grant can be found
|
||||||
|
* in the file PATENTS. All contributing project authors may
|
||||||
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "sdk/android/src/jni/jvm.h"
|
||||||
|
|
||||||
|
#include <asm/unistd.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <sys/prctl.h>
|
||||||
|
#include <sys/syscall.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "rtc_base/checks.h"
|
||||||
|
|
||||||
|
namespace webrtc {
|
||||||
|
namespace jni {
|
||||||
|
|
||||||
|
static JavaVM* g_jvm = nullptr;
|
||||||
|
|
||||||
|
static pthread_once_t g_jni_ptr_once = PTHREAD_ONCE_INIT;
|
||||||
|
|
||||||
|
// Key for per-thread JNIEnv* data. Non-NULL in threads attached to |g_jvm| by
|
||||||
|
// AttachCurrentThreadIfNeeded(), NULL in unattached threads and threads that
|
||||||
|
// were attached by the JVM because of a Java->native call.
|
||||||
|
static pthread_key_t g_jni_ptr;
|
||||||
|
|
||||||
|
JavaVM* GetJVM() {
|
||||||
|
RTC_CHECK(g_jvm) << "JNI_OnLoad failed to run?";
|
||||||
|
return g_jvm;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return a |JNIEnv*| usable on this thread or NULL if this thread is detached.
|
||||||
|
JNIEnv* GetEnv() {
|
||||||
|
void* env = nullptr;
|
||||||
|
jint status = g_jvm->GetEnv(&env, JNI_VERSION_1_6);
|
||||||
|
RTC_CHECK(((env != nullptr) && (status == JNI_OK)) ||
|
||||||
|
((env == nullptr) && (status == JNI_EDETACHED)))
|
||||||
|
<< "Unexpected GetEnv return: " << status << ":" << env;
|
||||||
|
return reinterpret_cast<JNIEnv*>(env);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ThreadDestructor(void* prev_jni_ptr) {
|
||||||
|
// This function only runs on threads where |g_jni_ptr| is non-NULL, meaning
|
||||||
|
// we were responsible for originally attaching the thread, so are responsible
|
||||||
|
// for detaching it now. However, because some JVM implementations (notably
|
||||||
|
// Oracle's http://goo.gl/eHApYT) also use the pthread_key_create mechanism,
|
||||||
|
// the JVMs accounting info for this thread may already be wiped out by the
|
||||||
|
// time this is called. Thus it may appear we are already detached even though
|
||||||
|
// it was our responsibility to detach! Oh well.
|
||||||
|
if (!GetEnv())
|
||||||
|
return;
|
||||||
|
|
||||||
|
RTC_CHECK(GetEnv() == prev_jni_ptr)
|
||||||
|
<< "Detaching from another thread: " << prev_jni_ptr << ":" << GetEnv();
|
||||||
|
jint status = g_jvm->DetachCurrentThread();
|
||||||
|
RTC_CHECK(status == JNI_OK) << "Failed to detach thread: " << status;
|
||||||
|
RTC_CHECK(!GetEnv()) << "Detaching was a successful no-op???";
|
||||||
|
}
|
||||||
|
|
||||||
|
static void CreateJNIPtrKey() {
|
||||||
|
RTC_CHECK(!pthread_key_create(&g_jni_ptr, &ThreadDestructor))
|
||||||
|
<< "pthread_key_create";
|
||||||
|
}
|
||||||
|
|
||||||
|
jint InitGlobalJniVariables(JavaVM* jvm) {
|
||||||
|
RTC_CHECK(!g_jvm) << "InitGlobalJniVariables!";
|
||||||
|
g_jvm = jvm;
|
||||||
|
RTC_CHECK(g_jvm) << "InitGlobalJniVariables handed NULL?";
|
||||||
|
|
||||||
|
RTC_CHECK(!pthread_once(&g_jni_ptr_once, &CreateJNIPtrKey)) << "pthread_once";
|
||||||
|
|
||||||
|
JNIEnv* jni = nullptr;
|
||||||
|
if (jvm->GetEnv(reinterpret_cast<void**>(&jni), JNI_VERSION_1_6) != JNI_OK)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return JNI_VERSION_1_6;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return thread ID as a string.
|
||||||
|
static std::string GetThreadId() {
|
||||||
|
char buf[21]; // Big enough to hold a kuint64max plus terminating NULL.
|
||||||
|
RTC_CHECK_LT(snprintf(buf, sizeof(buf), "%ld",
|
||||||
|
static_cast<long>(syscall(__NR_gettid))),
|
||||||
|
sizeof(buf))
|
||||||
|
<< "Thread id is bigger than uint64??";
|
||||||
|
return std::string(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the current thread's name.
|
||||||
|
static std::string GetThreadName() {
|
||||||
|
char name[17] = {0};
|
||||||
|
if (prctl(PR_GET_NAME, name) != 0)
|
||||||
|
return std::string("<noname>");
|
||||||
|
return std::string(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return a |JNIEnv*| usable on this thread. Attaches to |g_jvm| if necessary.
|
||||||
|
JNIEnv* AttachCurrentThreadIfNeeded() {
|
||||||
|
JNIEnv* jni = GetEnv();
|
||||||
|
if (jni)
|
||||||
|
return jni;
|
||||||
|
RTC_CHECK(!pthread_getspecific(g_jni_ptr))
|
||||||
|
<< "TLS has a JNIEnv* but not attached?";
|
||||||
|
|
||||||
|
std::string name(GetThreadName() + " - " + GetThreadId());
|
||||||
|
JavaVMAttachArgs args;
|
||||||
|
args.version = JNI_VERSION_1_6;
|
||||||
|
args.name = &name[0];
|
||||||
|
args.group = nullptr;
|
||||||
|
// Deal with difference in signatures between Oracle's jni.h and Android's.
|
||||||
|
#ifdef _JAVASOFT_JNI_H_ // Oracle's jni.h violates the JNI spec!
|
||||||
|
void* env = nullptr;
|
||||||
|
#else
|
||||||
|
JNIEnv* env = nullptr;
|
||||||
|
#endif
|
||||||
|
RTC_CHECK(!g_jvm->AttachCurrentThread(&env, &args))
|
||||||
|
<< "Failed to attach thread";
|
||||||
|
RTC_CHECK(env) << "AttachCurrentThread handed back NULL!";
|
||||||
|
jni = reinterpret_cast<JNIEnv*>(env);
|
||||||
|
RTC_CHECK(!pthread_setspecific(g_jni_ptr, jni)) << "pthread_setspecific";
|
||||||
|
return jni;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace jni
|
||||||
|
} // namespace webrtc
|
||||||
32
sdk/android/src/jni/jvm.h
Normal file
32
sdk/android/src/jni/jvm.h
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018 The WebRTC project authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license
|
||||||
|
* that can be found in the LICENSE file in the root of the source
|
||||||
|
* tree. An additional intellectual property rights grant can be found
|
||||||
|
* in the file PATENTS. All contributing project authors may
|
||||||
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SDK_ANDROID_SRC_JNI_JVM_H_
|
||||||
|
#define SDK_ANDROID_SRC_JNI_JVM_H_
|
||||||
|
|
||||||
|
#include <jni.h>
|
||||||
|
|
||||||
|
namespace webrtc {
|
||||||
|
namespace jni {
|
||||||
|
|
||||||
|
jint InitGlobalJniVariables(JavaVM* jvm);
|
||||||
|
|
||||||
|
// Return a |JNIEnv*| usable on this thread or NULL if this thread is detached.
|
||||||
|
JNIEnv* GetEnv();
|
||||||
|
|
||||||
|
JavaVM* GetJVM();
|
||||||
|
|
||||||
|
// Return a |JNIEnv*| usable on this thread. Attaches to |g_jvm| if necessary.
|
||||||
|
JNIEnv* AttachCurrentThreadIfNeeded();
|
||||||
|
|
||||||
|
} // namespace jni
|
||||||
|
} // namespace webrtc
|
||||||
|
|
||||||
|
#endif // SDK_ANDROID_SRC_JNI_JVM_H_
|
||||||
@ -21,6 +21,7 @@
|
|||||||
#include "rtc_base/ipaddress.h"
|
#include "rtc_base/ipaddress.h"
|
||||||
#include "sdk/android/generated_peerconnection_jni/jni/NetworkMonitorAutoDetect_jni.h"
|
#include "sdk/android/generated_peerconnection_jni/jni/NetworkMonitorAutoDetect_jni.h"
|
||||||
#include "sdk/android/generated_peerconnection_jni/jni/NetworkMonitor_jni.h"
|
#include "sdk/android/generated_peerconnection_jni/jni/NetworkMonitor_jni.h"
|
||||||
|
#include "sdk/android/native_api/jni/java_types.h"
|
||||||
#include "sdk/android/src/jni/jni_helpers.h"
|
#include "sdk/android/src/jni/jni_helpers.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|||||||
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include "rtc_base/logsinks.h"
|
#include "rtc_base/logsinks.h"
|
||||||
#include "sdk/android/generated_peerconnection_jni/jni/CallSessionFileRotatingLogSink_jni.h"
|
#include "sdk/android/generated_peerconnection_jni/jni/CallSessionFileRotatingLogSink_jni.h"
|
||||||
|
#include "sdk/android/native_api/jni/java_types.h"
|
||||||
#include "sdk/android/src/jni/jni_helpers.h"
|
#include "sdk/android/src/jni/jni_helpers.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|||||||
@ -16,6 +16,7 @@
|
|||||||
#include "rtc_base/logging.h"
|
#include "rtc_base/logging.h"
|
||||||
#include "rtc_base/ptr_util.h"
|
#include "rtc_base/ptr_util.h"
|
||||||
#include "sdk/android/generated_peerconnection_jni/jni/DataChannel_jni.h"
|
#include "sdk/android/generated_peerconnection_jni/jni/DataChannel_jni.h"
|
||||||
|
#include "sdk/android/native_api/jni/java_types.h"
|
||||||
#include "sdk/android/src/jni/jni_helpers.h"
|
#include "sdk/android/src/jni/jni_helpers.h"
|
||||||
#include "sdk/android/src/jni/pc/datachannel.h"
|
#include "sdk/android/src/jni/pc/datachannel.h"
|
||||||
|
|
||||||
|
|||||||
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include "api/dtmfsenderinterface.h"
|
#include "api/dtmfsenderinterface.h"
|
||||||
#include "sdk/android/generated_peerconnection_jni/jni/DtmfSender_jni.h"
|
#include "sdk/android/generated_peerconnection_jni/jni/DtmfSender_jni.h"
|
||||||
|
#include "sdk/android/native_api/jni/java_types.h"
|
||||||
#include "sdk/android/src/jni/jni_helpers.h"
|
#include "sdk/android/src/jni/jni_helpers.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|||||||
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
#include "pc/webrtcsdp.h"
|
#include "pc/webrtcsdp.h"
|
||||||
#include "sdk/android/generated_peerconnection_jni/jni/IceCandidate_jni.h"
|
#include "sdk/android/generated_peerconnection_jni/jni/IceCandidate_jni.h"
|
||||||
|
#include "sdk/android/native_api/jni/java_types.h"
|
||||||
#include "sdk/android/src/jni/pc/mediastreamtrack.h"
|
#include "sdk/android/src/jni/pc/mediastreamtrack.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|||||||
@ -11,6 +11,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "rtc_base/logging.h"
|
#include "rtc_base/logging.h"
|
||||||
|
#include "sdk/android/native_api/jni/java_types.h"
|
||||||
#include "sdk/android/src/jni/jni_helpers.h"
|
#include "sdk/android/src/jni/jni_helpers.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|||||||
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include "rtc_base/ptr_util.h"
|
#include "rtc_base/ptr_util.h"
|
||||||
#include "sdk/android/generated_peerconnection_jni/jni/MediaConstraints_jni.h"
|
#include "sdk/android/generated_peerconnection_jni/jni/MediaConstraints_jni.h"
|
||||||
|
#include "sdk/android/native_api/jni/java_types.h"
|
||||||
#include "sdk/android/src/jni/jni_helpers.h"
|
#include "sdk/android/src/jni/jni_helpers.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|||||||
@ -15,7 +15,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "api/mediaconstraintsinterface.h"
|
#include "api/mediaconstraintsinterface.h"
|
||||||
#include "sdk/android/src/jni/scoped_java_ref.h"
|
#include "sdk/android/native_api/jni/scoped_java_ref.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
namespace jni {
|
namespace jni {
|
||||||
|
|||||||
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include "rtc_base/ptr_util.h"
|
#include "rtc_base/ptr_util.h"
|
||||||
#include "sdk/android/generated_peerconnection_jni/jni/MediaStream_jni.h"
|
#include "sdk/android/generated_peerconnection_jni/jni/MediaStream_jni.h"
|
||||||
|
#include "sdk/android/native_api/jni/java_types.h"
|
||||||
#include "sdk/android/src/jni/jni_helpers.h"
|
#include "sdk/android/src/jni/jni_helpers.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|||||||
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include "api/mediastreaminterface.h"
|
#include "api/mediastreaminterface.h"
|
||||||
#include "sdk/android/generated_peerconnection_jni/jni/MediaStreamTrack_jni.h"
|
#include "sdk/android/generated_peerconnection_jni/jni/MediaStreamTrack_jni.h"
|
||||||
|
#include "sdk/android/native_api/jni/java_types.h"
|
||||||
#include "sdk/android/src/jni/jni_helpers.h"
|
#include "sdk/android/src/jni/jni_helpers.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|||||||
@ -14,7 +14,7 @@
|
|||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
|
|
||||||
#include "api/mediatypes.h"
|
#include "api/mediatypes.h"
|
||||||
#include "sdk/android/src/jni/scoped_java_ref.h"
|
#include "sdk/android/native_api/jni/scoped_java_ref.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
namespace jni {
|
namespace jni {
|
||||||
|
|||||||
@ -40,6 +40,7 @@
|
|||||||
#include "rtc_base/logging.h"
|
#include "rtc_base/logging.h"
|
||||||
#include "rtc_base/ptr_util.h"
|
#include "rtc_base/ptr_util.h"
|
||||||
#include "sdk/android/generated_peerconnection_jni/jni/PeerConnection_jni.h"
|
#include "sdk/android/generated_peerconnection_jni/jni/PeerConnection_jni.h"
|
||||||
|
#include "sdk/android/native_api/jni/java_types.h"
|
||||||
#include "sdk/android/src/jni/jni_helpers.h"
|
#include "sdk/android/src/jni/jni_helpers.h"
|
||||||
#include "sdk/android/src/jni/pc/datachannel.h"
|
#include "sdk/android/src/jni/pc/datachannel.h"
|
||||||
#include "sdk/android/src/jni/pc/icecandidate.h"
|
#include "sdk/android/src/jni/pc/icecandidate.h"
|
||||||
|
|||||||
@ -26,6 +26,7 @@
|
|||||||
#include "rtc_base/stringutils.h"
|
#include "rtc_base/stringutils.h"
|
||||||
#include "rtc_base/thread.h"
|
#include "rtc_base/thread.h"
|
||||||
#include "sdk/android/generated_peerconnection_jni/jni/PeerConnectionFactory_jni.h"
|
#include "sdk/android/generated_peerconnection_jni/jni/PeerConnectionFactory_jni.h"
|
||||||
|
#include "sdk/android/native_api/jni/java_types.h"
|
||||||
#include "sdk/android/src/jni/jni_helpers.h"
|
#include "sdk/android/src/jni/jni_helpers.h"
|
||||||
#include "sdk/android/src/jni/pc/androidnetworkmonitor.h"
|
#include "sdk/android/src/jni/pc/androidnetworkmonitor.h"
|
||||||
#include "sdk/android/src/jni/pc/audio.h"
|
#include "sdk/android/src/jni/pc/audio.h"
|
||||||
|
|||||||
@ -18,6 +18,7 @@
|
|||||||
#include "sdk/android/generated_peerconnection_jni/jni/RTCStatsCollectorCallback_jni.h"
|
#include "sdk/android/generated_peerconnection_jni/jni/RTCStatsCollectorCallback_jni.h"
|
||||||
#include "sdk/android/generated_peerconnection_jni/jni/RTCStatsReport_jni.h"
|
#include "sdk/android/generated_peerconnection_jni/jni/RTCStatsReport_jni.h"
|
||||||
#include "sdk/android/generated_peerconnection_jni/jni/RTCStats_jni.h"
|
#include "sdk/android/generated_peerconnection_jni/jni/RTCStats_jni.h"
|
||||||
|
#include "sdk/android/native_api/jni/java_types.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
namespace jni {
|
namespace jni {
|
||||||
|
|||||||
@ -11,6 +11,7 @@
|
|||||||
#include "sdk/android/src/jni/pc/rtpparameters.h"
|
#include "sdk/android/src/jni/pc/rtpparameters.h"
|
||||||
|
|
||||||
#include "sdk/android/generated_peerconnection_jni/jni/RtpParameters_jni.h"
|
#include "sdk/android/generated_peerconnection_jni/jni/RtpParameters_jni.h"
|
||||||
|
#include "sdk/android/native_api/jni/java_types.h"
|
||||||
#include "sdk/android/src/jni/jni_helpers.h"
|
#include "sdk/android/src/jni/jni_helpers.h"
|
||||||
#include "sdk/android/src/jni/pc/mediastreamtrack.h"
|
#include "sdk/android/src/jni/pc/mediastreamtrack.h"
|
||||||
|
|
||||||
|
|||||||
@ -14,7 +14,7 @@
|
|||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
|
|
||||||
#include "api/rtpparameters.h"
|
#include "api/rtpparameters.h"
|
||||||
#include "sdk/android/src/jni/scoped_java_ref.h"
|
#include "sdk/android/native_api/jni/scoped_java_ref.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
namespace jni {
|
namespace jni {
|
||||||
|
|||||||
@ -11,6 +11,7 @@
|
|||||||
#include "sdk/android/src/jni/pc/rtpreceiver.h"
|
#include "sdk/android/src/jni/pc/rtpreceiver.h"
|
||||||
|
|
||||||
#include "sdk/android/generated_peerconnection_jni/jni/RtpReceiver_jni.h"
|
#include "sdk/android/generated_peerconnection_jni/jni/RtpReceiver_jni.h"
|
||||||
|
#include "sdk/android/native_api/jni/java_types.h"
|
||||||
#include "sdk/android/src/jni/jni_helpers.h"
|
#include "sdk/android/src/jni/jni_helpers.h"
|
||||||
#include "sdk/android/src/jni/pc/mediastreamtrack.h"
|
#include "sdk/android/src/jni/pc/mediastreamtrack.h"
|
||||||
#include "sdk/android/src/jni/pc/rtpparameters.h"
|
#include "sdk/android/src/jni/pc/rtpparameters.h"
|
||||||
|
|||||||
@ -14,7 +14,7 @@
|
|||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
|
|
||||||
#include "api/rtpreceiverinterface.h"
|
#include "api/rtpreceiverinterface.h"
|
||||||
#include "sdk/android/src/jni/scoped_java_ref.h"
|
#include "sdk/android/native_api/jni/scoped_java_ref.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
namespace jni {
|
namespace jni {
|
||||||
|
|||||||
@ -11,6 +11,7 @@
|
|||||||
#include "sdk/android/src/jni/pc/rtpsender.h"
|
#include "sdk/android/src/jni/pc/rtpsender.h"
|
||||||
|
|
||||||
#include "sdk/android/generated_peerconnection_jni/jni/RtpSender_jni.h"
|
#include "sdk/android/generated_peerconnection_jni/jni/RtpSender_jni.h"
|
||||||
|
#include "sdk/android/native_api/jni/java_types.h"
|
||||||
#include "sdk/android/src/jni/jni_helpers.h"
|
#include "sdk/android/src/jni/jni_helpers.h"
|
||||||
#include "sdk/android/src/jni/pc/rtpparameters.h"
|
#include "sdk/android/src/jni/pc/rtpparameters.h"
|
||||||
|
|
||||||
|
|||||||
@ -14,7 +14,7 @@
|
|||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
|
|
||||||
#include "api/rtpsenderinterface.h"
|
#include "api/rtpsenderinterface.h"
|
||||||
#include "sdk/android/src/jni/scoped_java_ref.h"
|
#include "sdk/android/native_api/jni/scoped_java_ref.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
namespace jni {
|
namespace jni {
|
||||||
|
|||||||
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
#include "api/mediaconstraintsinterface.h"
|
#include "api/mediaconstraintsinterface.h"
|
||||||
#include "sdk/android/generated_peerconnection_jni/jni/SdpObserver_jni.h"
|
#include "sdk/android/generated_peerconnection_jni/jni/SdpObserver_jni.h"
|
||||||
|
#include "sdk/android/native_api/jni/java_types.h"
|
||||||
#include "sdk/android/src/jni/jni_helpers.h"
|
#include "sdk/android/src/jni/jni_helpers.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|||||||
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
#include "rtc_base/logging.h"
|
#include "rtc_base/logging.h"
|
||||||
#include "sdk/android/generated_peerconnection_jni/jni/SessionDescription_jni.h"
|
#include "sdk/android/generated_peerconnection_jni/jni/SessionDescription_jni.h"
|
||||||
|
#include "sdk/android/native_api/jni/java_types.h"
|
||||||
#include "sdk/android/src/jni/jni_helpers.h"
|
#include "sdk/android/src/jni/jni_helpers.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|||||||
@ -15,7 +15,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "api/jsep.h"
|
#include "api/jsep.h"
|
||||||
#include "sdk/android/src/jni/scoped_java_ref.h"
|
#include "sdk/android/native_api/jni/scoped_java_ref.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
namespace jni {
|
namespace jni {
|
||||||
|
|||||||
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
#include "sdk/android/generated_peerconnection_jni/jni/StatsObserver_jni.h"
|
#include "sdk/android/generated_peerconnection_jni/jni/StatsObserver_jni.h"
|
||||||
#include "sdk/android/generated_peerconnection_jni/jni/StatsReport_jni.h"
|
#include "sdk/android/generated_peerconnection_jni/jni/StatsReport_jni.h"
|
||||||
|
#include "sdk/android/native_api/jni/java_types.h"
|
||||||
#include "sdk/android/src/jni/jni_helpers.h"
|
#include "sdk/android/src/jni/jni_helpers.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|||||||
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include "api/turncustomizer.h"
|
#include "api/turncustomizer.h"
|
||||||
#include "sdk/android/generated_peerconnection_jni/jni/TurnCustomizer_jni.h"
|
#include "sdk/android/generated_peerconnection_jni/jni/TurnCustomizer_jni.h"
|
||||||
|
#include "sdk/android/native_api/jni/java_types.h"
|
||||||
#include "sdk/android/src/jni/jni_helpers.h"
|
#include "sdk/android/src/jni/jni_helpers.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|||||||
@ -12,7 +12,7 @@
|
|||||||
#define SDK_ANDROID_SRC_JNI_PC_TURNCUSTOMIZER_H_
|
#define SDK_ANDROID_SRC_JNI_PC_TURNCUSTOMIZER_H_
|
||||||
|
|
||||||
#include "api/turncustomizer.h"
|
#include "api/turncustomizer.h"
|
||||||
#include "sdk/android/src/jni/scoped_java_ref.h"
|
#include "sdk/android/native_api/jni/scoped_java_ref.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
namespace jni {
|
namespace jni {
|
||||||
|
|||||||
@ -24,7 +24,6 @@
|
|||||||
#include "sdk/android/src/jni/androidmediadecoder_jni.h"
|
#include "sdk/android/src/jni/androidmediadecoder_jni.h"
|
||||||
#include "sdk/android/src/jni/androidmediaencoder_jni.h"
|
#include "sdk/android/src/jni/androidmediaencoder_jni.h"
|
||||||
#include "sdk/android/src/jni/androidvideotracksource.h"
|
#include "sdk/android/src/jni/androidvideotracksource.h"
|
||||||
#include "sdk/android/src/jni/pc/ownedfactoryandthreads.h"
|
|
||||||
#include "sdk/android/src/jni/surfacetexturehelper.h"
|
#include "sdk/android/src/jni/surfacetexturehelper.h"
|
||||||
#include "sdk/android/src/jni/videodecoderfactorywrapper.h"
|
#include "sdk/android/src/jni/videodecoderfactorywrapper.h"
|
||||||
#include "sdk/android/src/jni/videoencoderfactorywrapper.h"
|
#include "sdk/android/src/jni/videoencoderfactorywrapper.h"
|
||||||
|
|||||||
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
#include "rtc_base/scoped_ref_ptr.h"
|
#include "rtc_base/scoped_ref_ptr.h"
|
||||||
#include "rtc_base/thread.h"
|
#include "rtc_base/thread.h"
|
||||||
#include "sdk/android/src/jni/scoped_java_ref.h"
|
#include "sdk/android/native_api/jni/scoped_java_ref.h"
|
||||||
|
|
||||||
namespace cricket {
|
namespace cricket {
|
||||||
class WebRtcVideoEncoderFactory;
|
class WebRtcVideoEncoderFactory;
|
||||||
|
|||||||
@ -13,6 +13,7 @@
|
|||||||
#include "rtc_base/bind.h"
|
#include "rtc_base/bind.h"
|
||||||
#include "rtc_base/logging.h"
|
#include "rtc_base/logging.h"
|
||||||
#include "sdk/android/generated_video_jni/jni/SurfaceTextureHelper_jni.h"
|
#include "sdk/android/generated_video_jni/jni/SurfaceTextureHelper_jni.h"
|
||||||
|
#include "sdk/android/native_api/jni/java_types.h"
|
||||||
#include "sdk/android/src/jni/videoframe.h"
|
#include "sdk/android/src/jni/videoframe.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|||||||
@ -11,6 +11,7 @@
|
|||||||
#include "sdk/android/src/jni/videocodecinfo.h"
|
#include "sdk/android/src/jni/videocodecinfo.h"
|
||||||
|
|
||||||
#include "sdk/android/generated_video_jni/jni/VideoCodecInfo_jni.h"
|
#include "sdk/android/generated_video_jni/jni/VideoCodecInfo_jni.h"
|
||||||
|
#include "sdk/android/native_api/jni/java_types.h"
|
||||||
#include "sdk/android/src/jni/jni_helpers.h"
|
#include "sdk/android/src/jni/jni_helpers.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|||||||
@ -14,7 +14,7 @@
|
|||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "sdk/android/src/jni/scoped_java_ref.h"
|
#include "sdk/android/native_api/jni/scoped_java_ref.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
namespace jni {
|
namespace jni {
|
||||||
|
|||||||
@ -15,6 +15,7 @@
|
|||||||
#include "common_types.h" // NOLINT(build/include)
|
#include "common_types.h" // NOLINT(build/include)
|
||||||
#include "rtc_base/logging.h"
|
#include "rtc_base/logging.h"
|
||||||
#include "sdk/android/generated_video_jni/jni/VideoDecoderFactory_jni.h"
|
#include "sdk/android/generated_video_jni/jni/VideoDecoderFactory_jni.h"
|
||||||
|
#include "sdk/android/native_api/jni/java_types.h"
|
||||||
#include "sdk/android/src/jni/wrappednativecodec.h"
|
#include "sdk/android/src/jni/wrappednativecodec.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|||||||
@ -17,6 +17,7 @@
|
|||||||
#include "rtc_base/logging.h"
|
#include "rtc_base/logging.h"
|
||||||
#include "sdk/android/generated_video_jni/jni/VideoDecoderWrapper_jni.h"
|
#include "sdk/android/generated_video_jni/jni/VideoDecoderWrapper_jni.h"
|
||||||
#include "sdk/android/generated_video_jni/jni/VideoDecoder_jni.h"
|
#include "sdk/android/generated_video_jni/jni/VideoDecoder_jni.h"
|
||||||
|
#include "sdk/android/native_api/jni/java_types.h"
|
||||||
#include "sdk/android/src/jni/encodedimage.h"
|
#include "sdk/android/src/jni/encodedimage.h"
|
||||||
#include "sdk/android/src/jni/videocodecstatus.h"
|
#include "sdk/android/src/jni/videocodecstatus.h"
|
||||||
#include "sdk/android/src/jni/videoframe.h"
|
#include "sdk/android/src/jni/videoframe.h"
|
||||||
|
|||||||
@ -14,7 +14,8 @@
|
|||||||
#include "common_types.h" // NOLINT(build/include)
|
#include "common_types.h" // NOLINT(build/include)
|
||||||
#include "rtc_base/logging.h"
|
#include "rtc_base/logging.h"
|
||||||
#include "sdk/android/generated_video_jni/jni/VideoEncoderFactory_jni.h"
|
#include "sdk/android/generated_video_jni/jni/VideoEncoderFactory_jni.h"
|
||||||
#include "sdk/android/src/jni/class_loader.h"
|
#include "sdk/android/native_api/jni/class_loader.h"
|
||||||
|
#include "sdk/android/native_api/jni/java_types.h"
|
||||||
#include "sdk/android/src/jni/videocodecinfo.h"
|
#include "sdk/android/src/jni/videocodecinfo.h"
|
||||||
#include "sdk/android/src/jni/wrappednativecodec.h"
|
#include "sdk/android/src/jni/wrappednativecodec.h"
|
||||||
|
|
||||||
|
|||||||
@ -23,7 +23,8 @@
|
|||||||
#include "rtc_base/timeutils.h"
|
#include "rtc_base/timeutils.h"
|
||||||
#include "sdk/android/generated_video_jni/jni/VideoEncoderWrapper_jni.h"
|
#include "sdk/android/generated_video_jni/jni/VideoEncoderWrapper_jni.h"
|
||||||
#include "sdk/android/generated_video_jni/jni/VideoEncoder_jni.h"
|
#include "sdk/android/generated_video_jni/jni/VideoEncoder_jni.h"
|
||||||
#include "sdk/android/src/jni/class_loader.h"
|
#include "sdk/android/native_api/jni/class_loader.h"
|
||||||
|
#include "sdk/android/native_api/jni/java_types.h"
|
||||||
#include "sdk/android/src/jni/encodedimage.h"
|
#include "sdk/android/src/jni/encodedimage.h"
|
||||||
#include "sdk/android/src/jni/videocodecstatus.h"
|
#include "sdk/android/src/jni/videocodecstatus.h"
|
||||||
|
|
||||||
|
|||||||
@ -23,6 +23,9 @@
|
|||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
namespace jni {
|
namespace jni {
|
||||||
|
|
||||||
|
// TODO(sakal): Remove once clients have migrated.
|
||||||
|
using ::webrtc::JavaParamRef;
|
||||||
|
|
||||||
class SurfaceTextureHelper;
|
class SurfaceTextureHelper;
|
||||||
|
|
||||||
// Open gl texture matrix, in column-major order. Operations are
|
// Open gl texture matrix, in column-major order. Operations are
|
||||||
|
|||||||
@ -14,7 +14,7 @@
|
|||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
|
|
||||||
#include "api/video/video_frame_buffer.h"
|
#include "api/video/video_frame_buffer.h"
|
||||||
#include "sdk/android/src/jni/scoped_java_ref.h"
|
#include "sdk/android/native_api/jni/scoped_java_ref.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
namespace jni {
|
namespace jni {
|
||||||
|
|||||||
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
#include "sdk/android/generated_video_jni/jni/WrappedNativeVideoDecoder_jni.h"
|
#include "sdk/android/generated_video_jni/jni/WrappedNativeVideoDecoder_jni.h"
|
||||||
#include "sdk/android/generated_video_jni/jni/WrappedNativeVideoEncoder_jni.h"
|
#include "sdk/android/generated_video_jni/jni/WrappedNativeVideoEncoder_jni.h"
|
||||||
#include "sdk/android/src/jni/class_loader.h"
|
#include "sdk/android/native_api/jni/class_loader.h"
|
||||||
#include "sdk/android/src/jni/jni_helpers.h"
|
#include "sdk/android/src/jni/jni_helpers.h"
|
||||||
#include "sdk/android/src/jni/videodecoderwrapper.h"
|
#include "sdk/android/src/jni/videodecoderwrapper.h"
|
||||||
#include "sdk/android/src/jni/videoencoderwrapper.h"
|
#include "sdk/android/src/jni/videoencoderwrapper.h"
|
||||||
|
|||||||
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
#include "api/video_codecs/video_decoder.h"
|
#include "api/video_codecs/video_decoder.h"
|
||||||
#include "api/video_codecs/video_encoder.h"
|
#include "api/video_codecs/video_encoder.h"
|
||||||
#include "sdk/android/src/jni/scoped_java_ref.h"
|
#include "sdk/android/native_api/jni/scoped_java_ref.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
namespace jni {
|
namespace jni {
|
||||||
|
|||||||
Reference in New Issue
Block a user