Reland "Android: Generate JNI code for VideoSink and VideoEncoder"
This is a reland of ba78b5a905bffa05933a135673996df02328f2a4 Original change's description: > Android: Generate JNI code for VideoSink and VideoEncoder > > This is the first CL to start generating JNI code. It has updated two of > the most recent classes to use JNI code generation. > > Bug: webrtc:8278 > Change-Id: I1b19ee78c273346ceeaa0401dbdf8696803f16c7 > Reviewed-on: https://webrtc-review.googlesource.com/3820 > Reviewed-by: Sami Kalliomäki <sakal@webrtc.org> > Commit-Queue: Magnus Jedvert <magjed@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#19994} Bug: webrtc:8278 Change-Id: Id3e6513736eb87d7c234be3b0d13c5d30435201c Reviewed-on: https://webrtc-review.googlesource.com/4500 Reviewed-by: Magnus Jedvert <magjed@webrtc.org> Reviewed-by: Sami Kalliomäki <sakal@webrtc.org> Commit-Queue: Magnus Jedvert <magjed@webrtc.org> Cr-Commit-Position: refs/heads/master@{#20548}
This commit is contained in:
committed by
Commit Bot
parent
7797a812aa
commit
56231d07b3
@ -11,6 +11,7 @@
|
||||
#include "sdk/android/src/jni/jni_generator_helper.h"
|
||||
|
||||
#include "rtc_base/atomicops.h"
|
||||
#include "sdk/android/src/jni/classreferenceholder.h"
|
||||
|
||||
namespace base {
|
||||
namespace android {
|
||||
@ -19,7 +20,7 @@ namespace {
|
||||
// JNIEnv-helper methods that RTC_CHECK success: no Java exception thrown and
|
||||
// found object/class/method/field is non-null.
|
||||
jclass GetClass(JNIEnv* jni, const char* class_name) {
|
||||
jclass clazz = jni->FindClass(class_name);
|
||||
jclass clazz = webrtc::jni::FindClass(jni, class_name);
|
||||
CHECK_EXCEPTION(jni) << "error during FindClass: " << class_name;
|
||||
RTC_CHECK(clazz) << class_name;
|
||||
return clazz;
|
||||
|
||||
@ -21,6 +21,7 @@
|
||||
#include "rtc_base/logging.h"
|
||||
#include "rtc_base/random.h"
|
||||
#include "rtc_base/timeutils.h"
|
||||
#include "sdk/android/generated_video_jni/jni/VideoEncoder_jni.h"
|
||||
#include "sdk/android/src/jni/classreferenceholder.h"
|
||||
|
||||
namespace webrtc {
|
||||
@ -40,31 +41,6 @@ VideoEncoderWrapper::VideoEncoderWrapper(JNIEnv* jni, jobject j_encoder)
|
||||
FindClass(jni, "org/webrtc/VideoEncoder$BitrateAllocation")),
|
||||
int_array_class_(jni, jni->FindClass("[I")),
|
||||
video_frame_factory_(jni) {
|
||||
jclass encoder_class = FindClass(jni, "org/webrtc/VideoEncoder");
|
||||
|
||||
init_encode_method_ =
|
||||
jni->GetMethodID(encoder_class, "initEncode",
|
||||
"(Lorg/webrtc/VideoEncoder$Settings;Lorg/webrtc/"
|
||||
"VideoEncoder$Callback;)Lorg/webrtc/VideoCodecStatus;");
|
||||
release_method_ = jni->GetMethodID(encoder_class, "release",
|
||||
"()Lorg/webrtc/VideoCodecStatus;");
|
||||
encode_method_ = jni->GetMethodID(
|
||||
encoder_class, "encode",
|
||||
"(Lorg/webrtc/VideoFrame;Lorg/webrtc/"
|
||||
"VideoEncoder$EncodeInfo;)Lorg/webrtc/VideoCodecStatus;");
|
||||
set_channel_parameters_method_ =
|
||||
jni->GetMethodID(encoder_class, "setChannelParameters",
|
||||
"(SJ)Lorg/webrtc/VideoCodecStatus;");
|
||||
set_rate_allocation_method_ =
|
||||
jni->GetMethodID(encoder_class, "setRateAllocation",
|
||||
"(Lorg/webrtc/VideoEncoder$BitrateAllocation;I)Lorg/"
|
||||
"webrtc/VideoCodecStatus;");
|
||||
get_scaling_settings_method_ =
|
||||
jni->GetMethodID(encoder_class, "getScalingSettings",
|
||||
"()Lorg/webrtc/VideoEncoder$ScalingSettings;");
|
||||
get_implementation_name_method_ = jni->GetMethodID(
|
||||
encoder_class, "getImplementationName", "()Ljava/lang/String;");
|
||||
|
||||
settings_constructor_ =
|
||||
jni->GetMethodID(*settings_class_, "<init>", "(IIIIIZ)V");
|
||||
|
||||
@ -146,7 +122,8 @@ int32_t VideoEncoderWrapper::InitEncodeInternal(JNIEnv* jni) {
|
||||
jlongFromPointer(this));
|
||||
|
||||
jobject ret =
|
||||
jni->CallObjectMethod(*encoder_, init_encode_method_, settings, callback);
|
||||
Java_VideoEncoder_initEncode(jni, *encoder_, settings, callback);
|
||||
|
||||
if (jni->CallIntMethod(ret, get_number_method_) == WEBRTC_VIDEO_CODEC_OK) {
|
||||
initialized_ = true;
|
||||
}
|
||||
@ -163,7 +140,7 @@ int32_t VideoEncoderWrapper::RegisterEncodeCompleteCallback(
|
||||
int32_t VideoEncoderWrapper::Release() {
|
||||
JNIEnv* jni = AttachCurrentThreadIfNeeded();
|
||||
ScopedLocalRefFrame local_ref_frame(jni);
|
||||
jobject ret = jni->CallObjectMethod(*encoder_, release_method_);
|
||||
jobject ret = Java_VideoEncoder_release(jni, *encoder_);
|
||||
frame_extra_infos_.clear();
|
||||
initialized_ = false;
|
||||
encoder_queue_ = nullptr;
|
||||
@ -199,8 +176,8 @@ int32_t VideoEncoderWrapper::Encode(
|
||||
info.timestamp_rtp = frame.timestamp();
|
||||
frame_extra_infos_.push_back(info);
|
||||
|
||||
jobject ret = jni->CallObjectMethod(
|
||||
*encoder_, encode_method_, video_frame_factory_.ToJavaFrame(jni, frame),
|
||||
jobject ret = Java_VideoEncoder_encode(
|
||||
jni, *encoder_, video_frame_factory_.ToJavaFrame(jni, frame),
|
||||
encode_info);
|
||||
return HandleReturnCode(jni, ret);
|
||||
}
|
||||
@ -209,8 +186,8 @@ int32_t VideoEncoderWrapper::SetChannelParameters(uint32_t packet_loss,
|
||||
int64_t rtt) {
|
||||
JNIEnv* jni = AttachCurrentThreadIfNeeded();
|
||||
ScopedLocalRefFrame local_ref_frame(jni);
|
||||
jobject ret = jni->CallObjectMethod(*encoder_, set_channel_parameters_method_,
|
||||
(jshort)packet_loss, (jlong)rtt);
|
||||
jobject ret = Java_VideoEncoder_setChannelParameters(
|
||||
jni, *encoder_, (jshort)packet_loss, (jlong)rtt);
|
||||
return HandleReturnCode(jni, ret);
|
||||
}
|
||||
|
||||
@ -221,8 +198,8 @@ int32_t VideoEncoderWrapper::SetRateAllocation(
|
||||
ScopedLocalRefFrame local_ref_frame(jni);
|
||||
|
||||
jobject j_bitrate_allocation = ToJavaBitrateAllocation(jni, allocation);
|
||||
jobject ret = jni->CallObjectMethod(*encoder_, set_rate_allocation_method_,
|
||||
j_bitrate_allocation, (jint)framerate);
|
||||
jobject ret = Java_VideoEncoder_setRateAllocation(
|
||||
jni, *encoder_, j_bitrate_allocation, (jint)framerate);
|
||||
return HandleReturnCode(jni, ret);
|
||||
}
|
||||
|
||||
@ -231,7 +208,7 @@ VideoEncoderWrapper::ScalingSettings VideoEncoderWrapper::GetScalingSettings()
|
||||
JNIEnv* jni = AttachCurrentThreadIfNeeded();
|
||||
ScopedLocalRefFrame local_ref_frame(jni);
|
||||
jobject j_scaling_settings =
|
||||
jni->CallObjectMethod(*encoder_, get_scaling_settings_method_);
|
||||
Java_VideoEncoder_getScalingSettings(jni, *encoder_);
|
||||
bool on =
|
||||
jni->GetBooleanField(j_scaling_settings, scaling_settings_on_field_);
|
||||
jobject j_low =
|
||||
@ -461,8 +438,7 @@ jobject VideoEncoderWrapper::ToJavaBitrateAllocation(
|
||||
}
|
||||
|
||||
std::string VideoEncoderWrapper::GetImplementationName(JNIEnv* jni) const {
|
||||
jstring jname = reinterpret_cast<jstring>(
|
||||
jni->CallObjectMethod(*encoder_, get_implementation_name_method_));
|
||||
jstring jname = Java_VideoEncoder_getImplementationName(jni, *encoder_);
|
||||
return JavaToStdString(jni, jname);
|
||||
}
|
||||
|
||||
|
||||
@ -96,14 +96,6 @@ class VideoEncoderWrapper : public VideoEncoder {
|
||||
const ScopedGlobalRef<jclass> bitrate_allocation_class_;
|
||||
const ScopedGlobalRef<jclass> int_array_class_;
|
||||
|
||||
jmethodID init_encode_method_;
|
||||
jmethodID release_method_;
|
||||
jmethodID encode_method_;
|
||||
jmethodID set_channel_parameters_method_;
|
||||
jmethodID set_rate_allocation_method_;
|
||||
jmethodID get_scaling_settings_method_;
|
||||
jmethodID get_implementation_name_method_;
|
||||
|
||||
jmethodID settings_constructor_;
|
||||
|
||||
jmethodID encode_info_constructor_;
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
|
||||
#include "api/mediastreaminterface.h"
|
||||
#include "rtc_base/logging.h"
|
||||
#include "sdk/android/generated_video_jni/jni/VideoSink_jni.h"
|
||||
#include "sdk/android/src/jni/classreferenceholder.h"
|
||||
#include "sdk/android/src/jni/jni_helpers.h"
|
||||
#include "sdk/android/src/jni/native_handle_impl.h"
|
||||
@ -29,24 +30,18 @@ class VideoSinkWrapper : public rtc::VideoSinkInterface<VideoFrame> {
|
||||
private:
|
||||
void OnFrame(const VideoFrame& frame) override;
|
||||
|
||||
jmethodID j_on_frame_method_;
|
||||
|
||||
const JavaVideoFrameFactory java_video_frame_factory_;
|
||||
const ScopedGlobalRef<jobject> j_sink_;
|
||||
};
|
||||
|
||||
VideoSinkWrapper::VideoSinkWrapper(JNIEnv* jni, jobject j_sink)
|
||||
: java_video_frame_factory_(jni), j_sink_(jni, j_sink) {
|
||||
jclass j_video_sink_class = FindClass(jni, "org/webrtc/VideoSink");
|
||||
j_on_frame_method_ = jni->GetMethodID(j_video_sink_class, "onFrame",
|
||||
"(Lorg/webrtc/VideoFrame;)V");
|
||||
}
|
||||
: java_video_frame_factory_(jni), j_sink_(jni, j_sink) {}
|
||||
|
||||
void VideoSinkWrapper::OnFrame(const VideoFrame& frame) {
|
||||
JNIEnv* jni = AttachCurrentThreadIfNeeded();
|
||||
ScopedLocalRefFrame local_ref_frame(jni);
|
||||
jni->CallVoidMethod(*j_sink_, j_on_frame_method_,
|
||||
java_video_frame_factory_.ToJavaFrame(jni, frame));
|
||||
Java_VideoSink_onFrame(jni, *j_sink_,
|
||||
java_video_frame_factory_.ToJavaFrame(jni, frame));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user