glaznev@webrtc.org | 18c9247 | 2015-02-18 18:42:55 +0000 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
glaznev@webrtc.org | 18c9247 | 2015-02-18 18:42:55 +0000 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
glaznev@webrtc.org | 18c9247 | 2015-02-18 18:42:55 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 11 | #ifndef WEBRTC_API_JAVA_JNI_NATIVE_HANDLE_IMPL_H_ |
| 12 | #define WEBRTC_API_JAVA_JNI_NATIVE_HANDLE_IMPL_H_ |
glaznev@webrtc.org | 18c9247 | 2015-02-18 18:42:55 +0000 | [diff] [blame] | 13 | |
Magnus Jedvert | 6781ea4 | 2015-10-02 13:56:04 +0200 | [diff] [blame] | 14 | #include <jni.h> |
| 15 | |
kjellander | 6f8ce06 | 2015-11-16 13:52:24 -0800 | [diff] [blame] | 16 | #include "webrtc/common_video/include/video_frame_buffer.h" |
Per | 71f5a9a | 2015-12-11 09:32:37 +0100 | [diff] [blame] | 17 | #include "webrtc/common_video/rotation.h" |
magjed | 52a30e3 | 2015-10-12 06:53:20 -0700 | [diff] [blame] | 18 | |
glaznev@webrtc.org | 18c9247 | 2015-02-18 18:42:55 +0000 | [diff] [blame] | 19 | namespace webrtc_jni { |
| 20 | |
nisse | 47ac462 | 2016-05-25 08:47:01 -0700 | [diff] [blame] | 21 | // Open gl texture matrix, in column-major order. Operations are |
| 22 | // in-place. |
| 23 | class Matrix { |
| 24 | public: |
| 25 | Matrix(JNIEnv* jni, jfloatArray a); |
| 26 | |
| 27 | jfloatArray ToJava(JNIEnv* jni); |
| 28 | |
| 29 | // Crop arguments are relative to original size. |
| 30 | void Crop(float cropped_width, |
| 31 | float cropped_height, |
| 32 | float crop_x, |
| 33 | float crop_y); |
| 34 | |
| 35 | void Rotate(webrtc::VideoRotation rotation); |
| 36 | |
| 37 | private: |
| 38 | static void Multiply(const float a[16], const float b[16], float result[16]); |
| 39 | float elem_[16]; |
| 40 | }; |
| 41 | |
Per | 9b3f56e | 2015-04-09 13:44:16 +0200 | [diff] [blame] | 42 | // Wrapper for texture object. |
Per | 488e75f | 2015-11-19 10:43:36 +0100 | [diff] [blame] | 43 | struct NativeHandleImpl { |
| 44 | NativeHandleImpl(JNIEnv* jni, |
| 45 | jint j_oes_texture_id, |
| 46 | jfloatArray j_transform_matrix); |
Per | 9b3f56e | 2015-04-09 13:44:16 +0200 | [diff] [blame] | 47 | |
nisse | 47ac462 | 2016-05-25 08:47:01 -0700 | [diff] [blame] | 48 | NativeHandleImpl(int id, const Matrix& matrix); |
| 49 | |
Magnus Jedvert | 91b348c | 2015-10-07 22:57:06 +0200 | [diff] [blame] | 50 | const int oes_texture_id; |
nisse | 47ac462 | 2016-05-25 08:47:01 -0700 | [diff] [blame] | 51 | Matrix sampling_matrix; |
Peter Boström | eb66e80 | 2015-06-05 11:08:03 +0200 | [diff] [blame] | 52 | }; |
| 53 | |
magjed | 52a30e3 | 2015-10-12 06:53:20 -0700 | [diff] [blame] | 54 | class AndroidTextureBuffer : public webrtc::NativeHandleBuffer { |
| 55 | public: |
| 56 | AndroidTextureBuffer(int width, |
| 57 | int height, |
Per | 488e75f | 2015-11-19 10:43:36 +0100 | [diff] [blame] | 58 | const NativeHandleImpl& native_handle, |
nisse | c490e01 | 2015-12-10 06:23:33 -0800 | [diff] [blame] | 59 | jobject surface_texture_helper, |
magjed | 52a30e3 | 2015-10-12 06:53:20 -0700 | [diff] [blame] | 60 | const rtc::Callback0<void>& no_longer_used); |
| 61 | ~AndroidTextureBuffer(); |
| 62 | rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override; |
| 63 | |
Magnus Jedvert | a3002db | 2016-05-13 12:51:04 +0200 | [diff] [blame] | 64 | // First crop, then scale to dst resolution, and then rotate. |
| 65 | rtc::scoped_refptr<AndroidTextureBuffer> CropScaleAndRotate( |
| 66 | int cropped_width, |
| 67 | int cropped_height, |
nisse | 47ac462 | 2016-05-25 08:47:01 -0700 | [diff] [blame] | 68 | int crop_x, |
| 69 | int crop_y, |
Magnus Jedvert | a3002db | 2016-05-13 12:51:04 +0200 | [diff] [blame] | 70 | int dst_width, |
Per | 71f5a9a | 2015-12-11 09:32:37 +0100 | [diff] [blame] | 71 | int dst_height, |
| 72 | webrtc::VideoRotation rotation); |
Per | a3c20bb | 2015-11-26 13:41:44 +0100 | [diff] [blame] | 73 | |
magjed | 52a30e3 | 2015-10-12 06:53:20 -0700 | [diff] [blame] | 74 | private: |
Per | 488e75f | 2015-11-19 10:43:36 +0100 | [diff] [blame] | 75 | NativeHandleImpl native_handle_; |
nisse | c490e01 | 2015-12-10 06:23:33 -0800 | [diff] [blame] | 76 | // Raw object pointer, relying on the caller, i.e., |
| 77 | // AndroidVideoCapturerJni or the C++ SurfaceTextureHelper, to keep |
| 78 | // a global reference. TODO(nisse): Make this a reference to the C++ |
| 79 | // SurfaceTextureHelper instead, but that requires some refactoring |
| 80 | // of AndroidVideoCapturerJni. |
| 81 | jobject surface_texture_helper_; |
magjed | 52a30e3 | 2015-10-12 06:53:20 -0700 | [diff] [blame] | 82 | rtc::Callback0<void> no_longer_used_cb_; |
| 83 | }; |
| 84 | |
glaznev@webrtc.org | 18c9247 | 2015-02-18 18:42:55 +0000 | [diff] [blame] | 85 | } // namespace webrtc_jni |
| 86 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 87 | #endif // WEBRTC_API_JAVA_JNI_NATIVE_HANDLE_IMPL_H_ |