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 | |
Per | 9b3f56e | 2015-04-09 13:44:16 +0200 | [diff] [blame] | 21 | // Wrapper for texture object. |
Per | 488e75f | 2015-11-19 10:43:36 +0100 | [diff] [blame] | 22 | struct NativeHandleImpl { |
| 23 | NativeHandleImpl(JNIEnv* jni, |
| 24 | jint j_oes_texture_id, |
| 25 | jfloatArray j_transform_matrix); |
Per | 9b3f56e | 2015-04-09 13:44:16 +0200 | [diff] [blame] | 26 | |
Magnus Jedvert | 91b348c | 2015-10-07 22:57:06 +0200 | [diff] [blame] | 27 | const int oes_texture_id; |
| 28 | float sampling_matrix[16]; |
Peter Boström | eb66e80 | 2015-06-05 11:08:03 +0200 | [diff] [blame] | 29 | }; |
| 30 | |
magjed | 52a30e3 | 2015-10-12 06:53:20 -0700 | [diff] [blame] | 31 | class AndroidTextureBuffer : public webrtc::NativeHandleBuffer { |
| 32 | public: |
| 33 | AndroidTextureBuffer(int width, |
| 34 | int height, |
Per | 488e75f | 2015-11-19 10:43:36 +0100 | [diff] [blame] | 35 | const NativeHandleImpl& native_handle, |
nisse | c490e01 | 2015-12-10 06:23:33 -0800 | [diff] [blame] | 36 | jobject surface_texture_helper, |
magjed | 52a30e3 | 2015-10-12 06:53:20 -0700 | [diff] [blame] | 37 | const rtc::Callback0<void>& no_longer_used); |
| 38 | ~AndroidTextureBuffer(); |
| 39 | rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override; |
| 40 | |
Magnus Jedvert | a3002db | 2016-05-13 12:51:04 +0200 | [diff] [blame] | 41 | // First crop, then scale to dst resolution, and then rotate. |
| 42 | rtc::scoped_refptr<AndroidTextureBuffer> CropScaleAndRotate( |
| 43 | int cropped_width, |
| 44 | int cropped_height, |
| 45 | int dst_width, |
Per | 71f5a9a | 2015-12-11 09:32:37 +0100 | [diff] [blame] | 46 | int dst_height, |
| 47 | webrtc::VideoRotation rotation); |
Per | a3c20bb | 2015-11-26 13:41:44 +0100 | [diff] [blame] | 48 | |
magjed | 52a30e3 | 2015-10-12 06:53:20 -0700 | [diff] [blame] | 49 | private: |
Per | 488e75f | 2015-11-19 10:43:36 +0100 | [diff] [blame] | 50 | NativeHandleImpl native_handle_; |
nisse | c490e01 | 2015-12-10 06:23:33 -0800 | [diff] [blame] | 51 | // Raw object pointer, relying on the caller, i.e., |
| 52 | // AndroidVideoCapturerJni or the C++ SurfaceTextureHelper, to keep |
| 53 | // a global reference. TODO(nisse): Make this a reference to the C++ |
| 54 | // SurfaceTextureHelper instead, but that requires some refactoring |
| 55 | // of AndroidVideoCapturerJni. |
| 56 | jobject surface_texture_helper_; |
magjed | 52a30e3 | 2015-10-12 06:53:20 -0700 | [diff] [blame] | 57 | rtc::Callback0<void> no_longer_used_cb_; |
| 58 | }; |
| 59 | |
glaznev@webrtc.org | 18c9247 | 2015-02-18 18:42:55 +0000 | [diff] [blame] | 60 | } // namespace webrtc_jni |
| 61 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 62 | #endif // WEBRTC_API_JAVA_JNI_NATIVE_HANDLE_IMPL_H_ |