Chromium Code Reviews| 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 // Wrapper for texture object. | 21 // Wrapper for texture object. | 
| 22 struct NativeHandleImpl { | 22 struct NativeHandleImpl { | 
| 23 // Open gl textre matrix, in column-major order. Operations are | |
| 24 // in-place. | |
| 25 struct Matrix { | |
| 
 
magjed_webrtc
2016/05/18 11:41:59
struct's are not allowed to have complex methods.
 
nisse-webrtc
2016/05/18 12:17:52
I'll make it a class, then. Can it still use the n
 
 | |
| 26 float elem[16]; | |
| 27 // Crop arguments are relative to original size. | |
| 28 void Crop(float cropped_width, | |
| 29 float cropped_height, | |
| 30 float crop_x, | |
| 31 float crop_y); | |
| 32 | |
| 33 void Rotate(webrtc::VideoRotation rotation); | |
| 34 static void Multiply(const Matrix& a, const Matrix& b, Matrix* result); | |
| 35 }; | |
| 36 | |
| 23 NativeHandleImpl(JNIEnv* jni, | 37 NativeHandleImpl(JNIEnv* jni, | 
| 24 jint j_oes_texture_id, | 38 jint j_oes_texture_id, | 
| 25 jfloatArray j_transform_matrix); | 39 jfloatArray j_transform_matrix); | 
| 26 | 40 | 
| 41 NativeHandleImpl(int id, const Matrix& matrix); | |
| 42 | |
| 27 const int oes_texture_id; | 43 const int oes_texture_id; | 
| 28 float sampling_matrix[16]; | 44 Matrix sampling_matrix; | 
| 45 | |
| 46 NativeHandleImpl Crop( | |
| 
 
magjed_webrtc
2016/05/18 11:41:59
Do we really need Crop and Rotate for NativeHandle
 
nisse-webrtc
2016/05/18 12:17:52
No, these are leftovers and should be deleted.
 
 | |
| 47 // Relative to original size. | |
| 48 float cropped_width, | |
| 49 float cropped_height, | |
| 50 float crop_x, | |
| 51 float crop_y) const; | |
| 52 | |
| 53 NativeHandleImpl Rotate(webrtc::VideoRotation rotation) const; | |
| 29 }; | 54 }; | 
| 30 | 55 | 
| 31 class AndroidTextureBuffer : public webrtc::NativeHandleBuffer { | 56 class AndroidTextureBuffer : public webrtc::NativeHandleBuffer { | 
| 32 public: | 57 public: | 
| 33 AndroidTextureBuffer(int width, | 58 AndroidTextureBuffer(int width, | 
| 34 int height, | 59 int height, | 
| 35 const NativeHandleImpl& native_handle, | 60 const NativeHandleImpl& native_handle, | 
| 36 jobject surface_texture_helper, | 61 jobject surface_texture_helper, | 
| 37 const rtc::Callback0<void>& no_longer_used); | 62 const rtc::Callback0<void>& no_longer_used); | 
| 38 ~AndroidTextureBuffer(); | 63 ~AndroidTextureBuffer(); | 
| 39 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override; | 64 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override; | 
| 40 | 65 | 
| 41 // First crop, then scale to dst resolution, and then rotate. | 66 // First crop, then scale to dst resolution, and then rotate. | 
| 42 rtc::scoped_refptr<AndroidTextureBuffer> CropScaleAndRotate( | 67 rtc::scoped_refptr<AndroidTextureBuffer> CropScaleAndRotate( | 
| 43 int cropped_width, | 68 int cropped_width, | 
| 44 int cropped_height, | 69 int cropped_height, | 
| 70 int crop_x, | |
| 71 int crop_y, | |
| 45 int dst_width, | 72 int dst_width, | 
| 46 int dst_height, | 73 int dst_height, | 
| 47 webrtc::VideoRotation rotation); | 74 webrtc::VideoRotation rotation); | 
| 48 | 75 | 
| 49 private: | 76 private: | 
| 50 NativeHandleImpl native_handle_; | 77 NativeHandleImpl native_handle_; | 
| 51 // Raw object pointer, relying on the caller, i.e., | 78 // Raw object pointer, relying on the caller, i.e., | 
| 52 // AndroidVideoCapturerJni or the C++ SurfaceTextureHelper, to keep | 79 // AndroidVideoCapturerJni or the C++ SurfaceTextureHelper, to keep | 
| 53 // a global reference. TODO(nisse): Make this a reference to the C++ | 80 // a global reference. TODO(nisse): Make this a reference to the C++ | 
| 54 // SurfaceTextureHelper instead, but that requires some refactoring | 81 // SurfaceTextureHelper instead, but that requires some refactoring | 
| 55 // of AndroidVideoCapturerJni. | 82 // of AndroidVideoCapturerJni. | 
| 56 jobject surface_texture_helper_; | 83 jobject surface_texture_helper_; | 
| 57 rtc::Callback0<void> no_longer_used_cb_; | 84 rtc::Callback0<void> no_longer_used_cb_; | 
| 58 }; | 85 }; | 
| 59 | 86 | 
| 60 } // namespace webrtc_jni | 87 } // namespace webrtc_jni | 
| 61 | 88 | 
| 62 #endif // WEBRTC_API_JAVA_JNI_NATIVE_HANDLE_IMPL_H_ | 89 #endif // WEBRTC_API_JAVA_JNI_NATIVE_HANDLE_IMPL_H_ | 
| OLD | NEW |