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 #include "webrtc/sdk/android/src/jni/native_handle_impl.h" | 11 #include "webrtc/sdk/android/src/jni/native_handle_impl.h" |
12 | 12 |
13 #include <memory> | 13 #include <memory> |
14 | 14 |
15 #include "webrtc/api/video/i420_buffer.h" | 15 #include "webrtc/sdk/android/src/jni/jni_helpers.h" |
16 #include "webrtc/base/bind.h" | 16 #include "webrtc/base/bind.h" |
17 #include "webrtc/base/checks.h" | 17 #include "webrtc/base/checks.h" |
18 #include "webrtc/base/keep_ref_until_done.h" | 18 #include "webrtc/base/keep_ref_until_done.h" |
19 #include "webrtc/base/logging.h" | 19 #include "webrtc/base/logging.h" |
20 #include "webrtc/base/scoped_ref_ptr.h" | 20 #include "webrtc/base/scoped_ref_ptr.h" |
21 #include "webrtc/sdk/android/src/jni/jni_helpers.h" | |
22 | 21 |
23 using webrtc::NativeHandleBuffer; | 22 using webrtc::NativeHandleBuffer; |
24 | 23 |
25 namespace webrtc_jni { | 24 namespace webrtc_jni { |
26 | 25 |
27 Matrix::Matrix(JNIEnv* jni, jfloatArray a) { | 26 Matrix::Matrix(JNIEnv* jni, jfloatArray a) { |
28 RTC_CHECK_EQ(16, jni->GetArrayLength(a)); | 27 RTC_CHECK_EQ(16, jni->GetArrayLength(a)); |
29 jfloat* ptr = jni->GetFloatArrayElements(a, nullptr); | 28 jfloat* ptr = jni->GetFloatArrayElements(a, nullptr); |
30 for (int i = 0; i < 16; ++i) { | 29 for (int i = 0; i < 16; ++i) { |
31 elem_[i] = ptr[i]; | 30 elem_[i] = ptr[i]; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 AndroidTextureBuffer::NativeToI420Buffer() { | 135 AndroidTextureBuffer::NativeToI420Buffer() { |
137 int uv_width = (width()+7) / 8; | 136 int uv_width = (width()+7) / 8; |
138 int stride = 8 * uv_width; | 137 int stride = 8 * uv_width; |
139 int uv_height = (height()+1)/2; | 138 int uv_height = (height()+1)/2; |
140 size_t size = stride * (height() + uv_height); | 139 size_t size = stride * (height() + uv_height); |
141 // The data is owned by the frame, and the normal case is that the | 140 // The data is owned by the frame, and the normal case is that the |
142 // data is deleted by the frame's destructor callback. | 141 // data is deleted by the frame's destructor callback. |
143 // | 142 // |
144 // TODO(nisse): Use an I420BufferPool. We then need to extend that | 143 // TODO(nisse): Use an I420BufferPool. We then need to extend that |
145 // class, and I420Buffer, to support our memory layout. | 144 // class, and I420Buffer, to support our memory layout. |
146 // TODO(nisse): Depending on | |
147 // system_wrappers/include/aligned_malloc.h violate current DEPS | |
148 // rules. We get away for now only because it is indirectly included | |
149 // by i420_buffer.h | |
150 std::unique_ptr<uint8_t, webrtc::AlignedFreeDeleter> yuv_data( | 145 std::unique_ptr<uint8_t, webrtc::AlignedFreeDeleter> yuv_data( |
151 static_cast<uint8_t*>(webrtc::AlignedMalloc(size, kBufferAlignment))); | 146 static_cast<uint8_t*>(webrtc::AlignedMalloc(size, kBufferAlignment))); |
152 // See YuvConverter.java for the required layout. | 147 // See YuvConverter.java for the required layout. |
153 uint8_t* y_data = yuv_data.get(); | 148 uint8_t* y_data = yuv_data.get(); |
154 uint8_t* u_data = y_data + height() * stride; | 149 uint8_t* u_data = y_data + height() * stride; |
155 uint8_t* v_data = u_data + stride/2; | 150 uint8_t* v_data = u_data + stride/2; |
156 | 151 |
157 rtc::scoped_refptr<webrtc::VideoFrameBuffer> copy = | 152 rtc::scoped_refptr<webrtc::VideoFrameBuffer> copy = |
158 new rtc::RefCountedObject<webrtc::WrappedI420Buffer>( | 153 new rtc::RefCountedObject<webrtc::WrappedI420Buffer>( |
159 width(), height(), | 154 width(), height(), |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 cropped_width / static_cast<float>(width()), | 206 cropped_width / static_cast<float>(width()), |
212 cropped_height / static_cast<float>(height()), | 207 cropped_height / static_cast<float>(height()), |
213 crop_x / static_cast<float>(width()), | 208 crop_x / static_cast<float>(width()), |
214 crop_y / static_cast<float>(height())); | 209 crop_y / static_cast<float>(height())); |
215 } | 210 } |
216 buffer->native_handle_.sampling_matrix.Rotate(rotation); | 211 buffer->native_handle_.sampling_matrix.Rotate(rotation); |
217 return buffer; | 212 return buffer; |
218 } | 213 } |
219 | 214 |
220 } // namespace webrtc_jni | 215 } // namespace webrtc_jni |
OLD | NEW |