From 299c83991904846ccd88f64f2ed39338a0e2a8b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=B6ller?= Date: Mon, 12 Oct 2020 14:47:46 +0200 Subject: [PATCH] Add back AndroidVideoBuffer::CropAndScale MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now compatible with the recently added interface method VideoFramebuffer::CropAndScale. Bug: webrtc:11976 Change-Id: I461cf2de1d73ca953fda0ecad84d216b8b7ac879 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/187493 Reviewed-by: Sami Kalliomäki Reviewed-by: Ilya Nikolaevskiy Commit-Queue: Niels Moller Cr-Commit-Position: refs/heads/master@{#32391} --- sdk/android/api/org/webrtc/VideoFrame.java | 1 + sdk/android/src/jni/video_frame.cc | 13 +++++++++++++ sdk/android/src/jni/video_frame.h | 9 +++++++++ 3 files changed, 23 insertions(+) diff --git a/sdk/android/api/org/webrtc/VideoFrame.java b/sdk/android/api/org/webrtc/VideoFrame.java index 49c75facfd..a0a0d4eecb 100644 --- a/sdk/android/api/org/webrtc/VideoFrame.java +++ b/sdk/android/api/org/webrtc/VideoFrame.java @@ -54,6 +54,7 @@ public class VideoFrame implements RefCounted { * 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/video_frame.cc b/sdk/android/src/jni/video_frame.cc index ca33c5c009..860eebe5e2 100644 --- a/sdk/android/src/jni/video_frame.cc +++ b/sdk/android/src/jni/video_frame.cc @@ -152,6 +152,19 @@ const ScopedJavaGlobalRef& AndroidVideoBuffer::video_frame_buffer() return j_video_frame_buffer_; } +rtc::scoped_refptr AndroidVideoBuffer::CropAndScale( + int crop_x, + int crop_y, + int crop_width, + int crop_height, + int scale_width, + int scale_height) { + JNIEnv* jni = AttachCurrentThreadIfNeeded(); + 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/video_frame.h b/sdk/android/src/jni/video_frame.h index cb0ff0e11a..5e39b8a770 100644 --- a/sdk/android/src/jni/video_frame.h +++ b/sdk/android/src/jni/video_frame.h @@ -40,6 +40,15 @@ class AndroidVideoBuffer : public VideoFrameBuffer { const ScopedJavaGlobalRef& 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(int crop_x, + int crop_y, + int crop_width, + int crop_height, + int scale_width, + int scale_height) override; + protected: // Should not be called directly. Adopts the Java VideoFrame.Buffer. Use // Create() or Adopt() instead for clarity.