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/api/java/jni/native_handle_impl.h" | 11 #include "webrtc/api/java/jni/native_handle_impl.h" |
12 | 12 |
| 13 #include <memory> |
| 14 |
13 #include "webrtc/api/java/jni/jni_helpers.h" | 15 #include "webrtc/api/java/jni/jni_helpers.h" |
14 #include "webrtc/base/bind.h" | 16 #include "webrtc/base/bind.h" |
15 #include "webrtc/base/checks.h" | 17 #include "webrtc/base/checks.h" |
16 #include "webrtc/base/keep_ref_until_done.h" | 18 #include "webrtc/base/keep_ref_until_done.h" |
17 #include "webrtc/base/logging.h" | 19 #include "webrtc/base/logging.h" |
18 #include "webrtc/base/scoped_ptr.h" | |
19 #include "webrtc/base/scoped_ref_ptr.h" | 20 #include "webrtc/base/scoped_ref_ptr.h" |
20 | 21 |
21 using webrtc::NativeHandleBuffer; | 22 using webrtc::NativeHandleBuffer; |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
25 void RotateMatrix(float a[16], webrtc::VideoRotation rotation) { | 26 void RotateMatrix(float a[16], webrtc::VideoRotation rotation) { |
26 // Texture coordinates are in the range 0 to 1. The transformation of the last | 27 // Texture coordinates are in the range 0 to 1. The transformation of the last |
27 // row in each rotation matrix is needed for proper translation, e.g, to | 28 // row in each rotation matrix is needed for proper translation, e.g, to |
28 // mirror x, we don't replace x by -x, but by 1-x. | 29 // mirror x, we don't replace x by -x, but by 1-x. |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 AndroidTextureBuffer::NativeToI420Buffer() { | 98 AndroidTextureBuffer::NativeToI420Buffer() { |
98 int uv_width = (width()+7) / 8; | 99 int uv_width = (width()+7) / 8; |
99 int stride = 8 * uv_width; | 100 int stride = 8 * uv_width; |
100 int uv_height = (height()+1)/2; | 101 int uv_height = (height()+1)/2; |
101 size_t size = stride * (height() + uv_height); | 102 size_t size = stride * (height() + uv_height); |
102 // The data is owned by the frame, and the normal case is that the | 103 // The data is owned by the frame, and the normal case is that the |
103 // data is deleted by the frame's destructor callback. | 104 // data is deleted by the frame's destructor callback. |
104 // | 105 // |
105 // TODO(nisse): Use an I420BufferPool. We then need to extend that | 106 // TODO(nisse): Use an I420BufferPool. We then need to extend that |
106 // class, and I420Buffer, to support our memory layout. | 107 // class, and I420Buffer, to support our memory layout. |
107 rtc::scoped_ptr<uint8_t, webrtc::AlignedFreeDeleter> yuv_data( | 108 std::unique_ptr<uint8_t, webrtc::AlignedFreeDeleter> yuv_data( |
108 static_cast<uint8_t*>(webrtc::AlignedMalloc(size, kBufferAlignment))); | 109 static_cast<uint8_t*>(webrtc::AlignedMalloc(size, kBufferAlignment))); |
109 // See SurfaceTextureHelper.java for the required layout. | 110 // See SurfaceTextureHelper.java for the required layout. |
110 uint8_t* y_data = yuv_data.get(); | 111 uint8_t* y_data = yuv_data.get(); |
111 uint8_t* u_data = y_data + height() * stride; | 112 uint8_t* u_data = y_data + height() * stride; |
112 uint8_t* v_data = u_data + stride/2; | 113 uint8_t* v_data = u_data + stride/2; |
113 | 114 |
114 rtc::scoped_refptr<webrtc::VideoFrameBuffer> copy = | 115 rtc::scoped_refptr<webrtc::VideoFrameBuffer> copy = |
115 new rtc::RefCountedObject<webrtc::WrappedI420Buffer>( | 116 new rtc::RefCountedObject<webrtc::WrappedI420Buffer>( |
116 width(), height(), | 117 width(), height(), |
117 y_data, stride, | 118 y_data, stride, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 rtc::scoped_refptr<AndroidTextureBuffer> buffer( | 161 rtc::scoped_refptr<AndroidTextureBuffer> buffer( |
161 new rtc::RefCountedObject<AndroidTextureBuffer>( | 162 new rtc::RefCountedObject<AndroidTextureBuffer>( |
162 rotated_width, rotated_height, native_handle_, | 163 rotated_width, rotated_height, native_handle_, |
163 surface_texture_helper_, rtc::KeepRefUntilDone(this))); | 164 surface_texture_helper_, rtc::KeepRefUntilDone(this))); |
164 | 165 |
165 RotateMatrix(buffer->native_handle_.sampling_matrix, rotation); | 166 RotateMatrix(buffer->native_handle_.sampling_matrix, rotation); |
166 return buffer; | 167 return buffer; |
167 } | 168 } |
168 | 169 |
169 } // namespace webrtc_jni | 170 } // namespace webrtc_jni |
OLD | NEW |