diff --git a/sdk/android/api/org/webrtc/VideoFrame.java b/sdk/android/api/org/webrtc/VideoFrame.java index 0a5a67e04e..62d4cf231d 100644 --- a/sdk/android/api/org/webrtc/VideoFrame.java +++ b/sdk/android/api/org/webrtc/VideoFrame.java @@ -51,6 +51,7 @@ public class VideoFrame { * Crops a region defined by |cropx|, |cropY|, |cropWidth| and |cropHeight|. Scales it to size * |scaleWidth| x |scaleHeight|. */ + @CalledByNative("Buffer") Buffer cropAndScale( int cropX, int cropY, int cropWidth, int cropHeight, int scaleWidth, int scaleHeight); } diff --git a/sdk/android/src/jni/androidvideotracksource.cc b/sdk/android/src/jni/androidvideotracksource.cc index ba31f7e6de..42430c2804 100644 --- a/sdk/android/src/jni/androidvideotracksource.cc +++ b/sdk/android/src/jni/androidvideotracksource.cc @@ -36,12 +36,6 @@ AndroidVideoTrackSource::AndroidVideoTrackSource( is_screencast_(is_screencast) { RTC_LOG(LS_INFO) << "AndroidVideoTrackSource ctor"; camera_thread_checker_.DetachFromThread(); - - jclass j_video_frame_buffer_class = - FindClass(jni, "org/webrtc/VideoFrame$Buffer"); - j_crop_and_scale_id_ = - jni->GetMethodID(j_video_frame_buffer_class, "cropAndScale", - "(IIIIII)Lorg/webrtc/VideoFrame$Buffer;"); } void AndroidVideoTrackSource::SetState(SourceState state) { @@ -183,12 +177,10 @@ void AndroidVideoTrackSource::OnFrameCaptured(JNIEnv* jni, return; } - jobject j_adapted_video_frame_buffer = jni->CallObjectMethod( - j_video_frame_buffer, j_crop_and_scale_id_, crop_x, crop_y, crop_width, - crop_height, adapted_width, adapted_height); - rtc::scoped_refptr buffer = - AndroidVideoBuffer::Adopt(jni, j_adapted_video_frame_buffer); + AndroidVideoBuffer::Create(jni, j_video_frame_buffer) + ->CropAndScale(jni, crop_x, crop_y, crop_width, crop_height, + adapted_width, adapted_height); // AdaptedVideoTrackSource handles applying rotation for I420 frames. if (apply_rotation() && rotation != kVideoRotation_0) { diff --git a/sdk/android/src/jni/androidvideotracksource.h b/sdk/android/src/jni/androidvideotracksource.h index 641c10f3cc..8836c11176 100644 --- a/sdk/android/src/jni/androidvideotracksource.h +++ b/sdk/android/src/jni/androidvideotracksource.h @@ -85,8 +85,6 @@ class AndroidVideoTrackSource : public rtc::AdaptedVideoTrackSource { I420BufferPool buffer_pool_; rtc::scoped_refptr surface_texture_helper_; const bool is_screencast_; - - jmethodID j_crop_and_scale_id_; }; } // namespace jni diff --git a/sdk/android/src/jni/videoframe.cc b/sdk/android/src/jni/videoframe.cc index 5e24002fc1..c914727af5 100644 --- a/sdk/android/src/jni/videoframe.cc +++ b/sdk/android/src/jni/videoframe.cc @@ -311,6 +311,19 @@ jobject AndroidVideoBuffer::video_frame_buffer() const { return *j_video_frame_buffer_; } +rtc::scoped_refptr AndroidVideoBuffer::CropAndScale( + JNIEnv* jni, + int crop_x, + int crop_y, + int crop_width, + int crop_height, + int scale_width, + int scale_height) { + return Adopt(jni, Java_Buffer_cropAndScale( + jni, *j_video_frame_buffer_, crop_x, crop_y, crop_width, + crop_height, scale_width, scale_height)); +} + VideoFrameBuffer::Type AndroidVideoBuffer::type() const { return Type::kNative; } diff --git a/sdk/android/src/jni/videoframe.h b/sdk/android/src/jni/videoframe.h index c477286a10..1f10eb4009 100644 --- a/sdk/android/src/jni/videoframe.h +++ b/sdk/android/src/jni/videoframe.h @@ -120,6 +120,16 @@ class AndroidVideoBuffer : public AndroidVideoFrameBuffer { jobject video_frame_buffer() const; + // Crops a region defined by |crop_x|, |crop_y|, |crop_width| and + // |crop_height|. Scales it to size |scale_width| x |scale_height|. + rtc::scoped_refptr CropAndScale(JNIEnv* jni, + int crop_x, + int crop_y, + int crop_width, + int crop_height, + int scale_width, + int scale_height); + // Returns an instance of VideoRenderer.I420Frame (deprecated) jobject ToJavaI420Frame(JNIEnv* jni, int rotation);