OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_API_JAVA_JNI_NATIVE_HANDLE_IMPL_H_ | 11 #ifndef WEBRTC_API_JAVA_JNI_NATIVE_HANDLE_IMPL_H_ |
12 #define WEBRTC_API_JAVA_JNI_NATIVE_HANDLE_IMPL_H_ | 12 #define WEBRTC_API_JAVA_JNI_NATIVE_HANDLE_IMPL_H_ |
13 | 13 |
14 #include <jni.h> | 14 #include <jni.h> |
15 | 15 |
16 #include "webrtc/common_video/include/video_frame_buffer.h" | 16 #include "webrtc/common_video/include/video_frame_buffer.h" |
17 #include "webrtc/common_video/rotation.h" | 17 #include "webrtc/common_video/rotation.h" |
18 | 18 |
19 namespace webrtc_jni { | 19 namespace webrtc_jni { |
20 | 20 |
| 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 |
21 // Wrapper for texture object. | 42 // Wrapper for texture object. |
22 struct NativeHandleImpl { | 43 struct NativeHandleImpl { |
23 NativeHandleImpl(JNIEnv* jni, | 44 NativeHandleImpl(JNIEnv* jni, |
24 jint j_oes_texture_id, | 45 jint j_oes_texture_id, |
25 jfloatArray j_transform_matrix); | 46 jfloatArray j_transform_matrix); |
26 | 47 |
| 48 NativeHandleImpl(int id, const Matrix& matrix); |
| 49 |
27 const int oes_texture_id; | 50 const int oes_texture_id; |
28 float sampling_matrix[16]; | 51 Matrix sampling_matrix; |
29 }; | 52 }; |
30 | 53 |
31 class AndroidTextureBuffer : public webrtc::NativeHandleBuffer { | 54 class AndroidTextureBuffer : public webrtc::NativeHandleBuffer { |
32 public: | 55 public: |
33 AndroidTextureBuffer(int width, | 56 AndroidTextureBuffer(int width, |
34 int height, | 57 int height, |
35 const NativeHandleImpl& native_handle, | 58 const NativeHandleImpl& native_handle, |
36 jobject surface_texture_helper, | 59 jobject surface_texture_helper, |
37 const rtc::Callback0<void>& no_longer_used); | 60 const rtc::Callback0<void>& no_longer_used); |
38 ~AndroidTextureBuffer(); | 61 ~AndroidTextureBuffer(); |
39 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override; | 62 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override; |
40 | 63 |
41 // First crop, then scale to dst resolution, and then rotate. | 64 // First crop, then scale to dst resolution, and then rotate. |
42 rtc::scoped_refptr<AndroidTextureBuffer> CropScaleAndRotate( | 65 rtc::scoped_refptr<AndroidTextureBuffer> CropScaleAndRotate( |
43 int cropped_width, | 66 int cropped_width, |
44 int cropped_height, | 67 int cropped_height, |
| 68 int crop_x, |
| 69 int crop_y, |
45 int dst_width, | 70 int dst_width, |
46 int dst_height, | 71 int dst_height, |
47 webrtc::VideoRotation rotation); | 72 webrtc::VideoRotation rotation); |
48 | 73 |
49 private: | 74 private: |
50 NativeHandleImpl native_handle_; | 75 NativeHandleImpl native_handle_; |
51 // Raw object pointer, relying on the caller, i.e., | 76 // Raw object pointer, relying on the caller, i.e., |
52 // AndroidVideoCapturerJni or the C++ SurfaceTextureHelper, to keep | 77 // AndroidVideoCapturerJni or the C++ SurfaceTextureHelper, to keep |
53 // a global reference. TODO(nisse): Make this a reference to the C++ | 78 // a global reference. TODO(nisse): Make this a reference to the C++ |
54 // SurfaceTextureHelper instead, but that requires some refactoring | 79 // SurfaceTextureHelper instead, but that requires some refactoring |
55 // of AndroidVideoCapturerJni. | 80 // of AndroidVideoCapturerJni. |
56 jobject surface_texture_helper_; | 81 jobject surface_texture_helper_; |
57 rtc::Callback0<void> no_longer_used_cb_; | 82 rtc::Callback0<void> no_longer_used_cb_; |
58 }; | 83 }; |
59 | 84 |
60 } // namespace webrtc_jni | 85 } // namespace webrtc_jni |
61 | 86 |
62 #endif // WEBRTC_API_JAVA_JNI_NATIVE_HANDLE_IMPL_H_ | 87 #endif // WEBRTC_API_JAVA_JNI_NATIVE_HANDLE_IMPL_H_ |
OLD | NEW |