From f4810ddfd992e183feffbaeb2998f897d4f6f08f Mon Sep 17 00:00:00 2001 From: Magnus Jedvert Date: Wed, 27 Sep 2017 11:56:45 +0000 Subject: [PATCH] Revert "Android: Generate JNI code for VideoSink and VideoEncoder" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit ba78b5a905bffa05933a135673996df02328f2a4. Reason for revert: Breaks external projects. 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 > Commit-Queue: Magnus Jedvert > Cr-Commit-Position: refs/heads/master@{#19994} TBR=magjed@webrtc.org,sakal@webrtc.org Change-Id: I48e079f3ab9661ae4171a3ae5cca571a75d14810 No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: webrtc:8278 Reviewed-on: https://webrtc-review.googlesource.com/4100 Reviewed-by: Magnus Jedvert Commit-Queue: Magnus Jedvert Cr-Commit-Position: refs/heads/master@{#19997} --- sdk/android/BUILD.gn | 11 ----- sdk/android/api/org/webrtc/VideoEncoder.java | 20 +++----- sdk/android/api/org/webrtc/VideoSink.java | 2 +- sdk/android/src/jni/DEPS | 1 - sdk/android/src/jni/videoencoderwrapper.cc | 48 +++++++++++++++----- sdk/android/src/jni/videoencoderwrapper.h | 8 ++++ sdk/android/src/jni/videotrack_jni.cc | 13 ++++-- 7 files changed, 61 insertions(+), 42 deletions(-) diff --git a/sdk/android/BUILD.gn b/sdk/android/BUILD.gn index 5d04d06882..d313771e17 100644 --- a/sdk/android/BUILD.gn +++ b/sdk/android/BUILD.gn @@ -87,15 +87,6 @@ rtc_static_library("null_audio_jni") { ] } -generate_jni("generated_video_jni") { - sources = [ - "api/org/webrtc/VideoEncoder.java", - "api/org/webrtc/VideoSink.java", - ] - jni_package = "video" - jni_generator_include = "//sdk/android/src/jni/jni_generator_helper.h" -} - rtc_static_library("video_jni") { sources = [ "src/jni/androidmediacodeccommon.h", @@ -107,7 +98,6 @@ rtc_static_library("video_jni") { "src/jni/androidvideotracksource.h", "src/jni/androidvideotracksource_jni.cc", "src/jni/filevideocapturer_jni.cc", - "src/jni/jni_generator_helper.h", "src/jni/native_handle_impl.cc", "src/jni/native_handle_impl.h", "src/jni/nv12buffer_jni.cc", @@ -153,7 +143,6 @@ rtc_static_library("video_jni") { deps = [ ":base_jni", - ":generated_video_jni", ":peerconnection_jni", "../..:webrtc_common", "../../api:libjingle_peerconnection_api", diff --git a/sdk/android/api/org/webrtc/VideoEncoder.java b/sdk/android/api/org/webrtc/VideoEncoder.java index b7dc369cf2..1fb96011d0 100644 --- a/sdk/android/api/org/webrtc/VideoEncoder.java +++ b/sdk/android/api/org/webrtc/VideoEncoder.java @@ -123,32 +123,26 @@ public interface VideoEncoder { /** * Initializes the encoding process. Call before any calls to encode. */ - @CalledByNative VideoCodecStatus initEncode(Settings settings, Callback encodeCallback); - + VideoCodecStatus initEncode(Settings settings, Callback encodeCallback); /** * Releases the encoder. No more calls to encode will be made after this call. */ - @CalledByNative VideoCodecStatus release(); - + VideoCodecStatus release(); /** * Requests the encoder to encode a frame. */ - @CalledByNative VideoCodecStatus encode(VideoFrame frame, EncodeInfo info); - + VideoCodecStatus encode(VideoFrame frame, EncodeInfo info); /** * Informs the encoder of the packet loss and the round-trip time of the network. * * @param packetLoss How many packets are lost on average per 255 packets. * @param roundTripTimeMs Round-trip time of the network in milliseconds. */ - @CalledByNative VideoCodecStatus setChannelParameters(short packetLoss, long roundTripTimeMs); - + VideoCodecStatus setChannelParameters(short packetLoss, long roundTripTimeMs); /** Sets the bitrate allocation and the target framerate for the encoder. */ - @CalledByNative VideoCodecStatus setRateAllocation(BitrateAllocation allocation, int framerate); - + VideoCodecStatus setRateAllocation(BitrateAllocation allocation, int framerate); /** Any encoder that wants to use WebRTC provided quality scaler must implement this method. */ - @CalledByNative ScalingSettings getScalingSettings(); - + ScalingSettings getScalingSettings(); /** Should return a descriptive name for the implementation. Gets called once and cached. */ - @CalledByNative String getImplementationName(); + String getImplementationName(); } diff --git a/sdk/android/api/org/webrtc/VideoSink.java b/sdk/android/api/org/webrtc/VideoSink.java index 5a0a6c719c..e4162feb8b 100644 --- a/sdk/android/api/org/webrtc/VideoSink.java +++ b/sdk/android/api/org/webrtc/VideoSink.java @@ -19,5 +19,5 @@ public interface VideoSink { * this function returns. Each call to retain() should be followed by a call to frame.release() * when the reference is no longer needed. */ - @CalledByNative void onFrame(VideoFrame frame); + void onFrame(VideoFrame frame); } diff --git a/sdk/android/src/jni/DEPS b/sdk/android/src/jni/DEPS index c90b605a5c..4ac0aac23d 100644 --- a/sdk/android/src/jni/DEPS +++ b/sdk/android/src/jni/DEPS @@ -9,7 +9,6 @@ include_rules = [ "+modules/include", "+modules/utility/include/jvm_android.h", "+modules/video_coding", - "+jni", # folder for generated JNI headers "+pc", "+system_wrappers/include", "+voice_engine/include/voe_base.h", diff --git a/sdk/android/src/jni/videoencoderwrapper.cc b/sdk/android/src/jni/videoencoderwrapper.cc index 8e1812d585..ceecda2bf2 100644 --- a/sdk/android/src/jni/videoencoderwrapper.cc +++ b/sdk/android/src/jni/videoencoderwrapper.cc @@ -13,7 +13,6 @@ #include #include "common_video/h264/h264_common.h" -#include "jni/VideoEncoder_jni.h" #include "modules/include/module_common_types.h" #include "modules/video_coding/include/video_codec_interface.h" #include "modules/video_coding/include/video_error_codes.h" @@ -41,6 +40,31 @@ 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_, "", "(IIIIIZ)V"); @@ -123,8 +147,7 @@ int32_t VideoEncoderWrapper::InitEncodeInternal(JNIEnv* jni) { jlongFromPointer(this)); jobject ret = - Java_VideoEncoder_initEncode(jni, *encoder_, settings, callback); - + jni->CallObjectMethod(*encoder_, init_encode_method_, settings, callback); if (jni->CallIntMethod(ret, get_number_method_) == WEBRTC_VIDEO_CODEC_OK) { initialized_ = true; } @@ -141,7 +164,7 @@ int32_t VideoEncoderWrapper::RegisterEncodeCompleteCallback( int32_t VideoEncoderWrapper::Release() { JNIEnv* jni = AttachCurrentThreadIfNeeded(); ScopedLocalRefFrame local_ref_frame(jni); - jobject ret = Java_VideoEncoder_release(jni, *encoder_); + jobject ret = jni->CallObjectMethod(*encoder_, release_method_); frame_extra_infos_.clear(); initialized_ = false; return HandleReturnCode(jni, ret); @@ -176,8 +199,8 @@ int32_t VideoEncoderWrapper::Encode( info.timestamp_rtp = frame.timestamp(); frame_extra_infos_.push_back(info); - jobject ret = Java_VideoEncoder_encode( - jni, *encoder_, video_frame_factory_.ToJavaFrame(jni, frame), + jobject ret = jni->CallObjectMethod( + *encoder_, encode_method_, video_frame_factory_.ToJavaFrame(jni, frame), encode_info); return HandleReturnCode(jni, ret); } @@ -186,8 +209,8 @@ int32_t VideoEncoderWrapper::SetChannelParameters(uint32_t packet_loss, int64_t rtt) { JNIEnv* jni = AttachCurrentThreadIfNeeded(); ScopedLocalRefFrame local_ref_frame(jni); - jobject ret = Java_VideoEncoder_setChannelParameters( - jni, *encoder_, (jshort)packet_loss, (jlong)rtt); + jobject ret = jni->CallObjectMethod(*encoder_, set_channel_parameters_method_, + (jshort)packet_loss, (jlong)rtt); return HandleReturnCode(jni, ret); } @@ -198,8 +221,8 @@ int32_t VideoEncoderWrapper::SetRateAllocation( ScopedLocalRefFrame local_ref_frame(jni); jobject j_bitrate_allocation = ToJavaBitrateAllocation(jni, allocation); - jobject ret = Java_VideoEncoder_setRateAllocation( - jni, *encoder_, j_bitrate_allocation, (jint)framerate); + jobject ret = jni->CallObjectMethod(*encoder_, set_rate_allocation_method_, + j_bitrate_allocation, (jint)framerate); return HandleReturnCode(jni, ret); } @@ -208,7 +231,7 @@ VideoEncoderWrapper::ScalingSettings VideoEncoderWrapper::GetScalingSettings() JNIEnv* jni = AttachCurrentThreadIfNeeded(); ScopedLocalRefFrame local_ref_frame(jni); jobject j_scaling_settings = - Java_VideoEncoder_getScalingSettings(jni, *encoder_); + jni->CallObjectMethod(*encoder_, get_scaling_settings_method_); bool on = jni->GetBooleanField(j_scaling_settings, scaling_settings_on_field_); jobject j_low = @@ -438,7 +461,8 @@ jobject VideoEncoderWrapper::ToJavaBitrateAllocation( } std::string VideoEncoderWrapper::GetImplementationName(JNIEnv* jni) const { - jstring jname = Java_VideoEncoder_getImplementationName(jni, *encoder_); + jstring jname = reinterpret_cast( + jni->CallObjectMethod(*encoder_, get_implementation_name_method_)); return JavaToStdString(jni, jname); } diff --git a/sdk/android/src/jni/videoencoderwrapper.h b/sdk/android/src/jni/videoencoderwrapper.h index 866002afc4..4468fcb22f 100644 --- a/sdk/android/src/jni/videoencoderwrapper.h +++ b/sdk/android/src/jni/videoencoderwrapper.h @@ -96,6 +96,14 @@ class VideoEncoderWrapper : public VideoEncoder { const ScopedGlobalRef bitrate_allocation_class_; const ScopedGlobalRef 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_; diff --git a/sdk/android/src/jni/videotrack_jni.cc b/sdk/android/src/jni/videotrack_jni.cc index 9cccad7cc6..0da609f290 100644 --- a/sdk/android/src/jni/videotrack_jni.cc +++ b/sdk/android/src/jni/videotrack_jni.cc @@ -11,7 +11,6 @@ #include #include "api/mediastreaminterface.h" -#include "jni/VideoSink_jni.h" #include "rtc_base/logging.h" #include "sdk/android/src/jni/classreferenceholder.h" #include "sdk/android/src/jni/jni_helpers.h" @@ -30,18 +29,24 @@ class VideoSinkWrapper : public rtc::VideoSinkInterface { private: void OnFrame(const VideoFrame& frame) override; + jmethodID j_on_frame_method_; + const JavaVideoFrameFactory java_video_frame_factory_; const ScopedGlobalRef j_sink_; }; VideoSinkWrapper::VideoSinkWrapper(JNIEnv* jni, jobject j_sink) - : java_video_frame_factory_(jni), j_sink_(jni, 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"); +} void VideoSinkWrapper::OnFrame(const VideoFrame& frame) { JNIEnv* jni = AttachCurrentThreadIfNeeded(); ScopedLocalRefFrame local_ref_frame(jni); - Java_VideoSink_onFrame(jni, *j_sink_, - java_video_frame_factory_.ToJavaFrame(jni, frame)); + jni->CallVoidMethod(*j_sink_, j_on_frame_method_, + java_video_frame_factory_.ToJavaFrame(jni, frame)); } } // namespace