OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 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/common_video/include/video_frame_buffer.h" | 11 #include "webrtc/common_video/include/video_frame_buffer.h" |
12 | 12 |
13 #include "webrtc/base/checks.h" | 13 #include "webrtc/base/checks.h" |
14 #include "webrtc/base/keep_ref_until_done.h" | 14 #include "webrtc/base/keep_ref_until_done.h" |
| 15 #include "libyuv/convert.h" |
15 | 16 |
16 // Aligning pointer to 64 bytes for improved performance, e.g. use SIMD. | 17 // Aligning pointer to 64 bytes for improved performance, e.g. use SIMD. |
17 static const int kBufferAlignment = 64; | 18 static const int kBufferAlignment = 64; |
18 | 19 |
19 namespace webrtc { | 20 namespace webrtc { |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 int I420DataSize(int height, int stride_y, int stride_u, int stride_v) { | 24 int I420DataSize(int height, int stride_y, int stride_u, int stride_v) { |
24 return stride_y * height + (stride_u + stride_v) * ((height + 1) / 2); | 25 return stride_y * height + (stride_u + stride_v) * ((height + 1) / 2); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 | 111 |
111 void* I420Buffer::native_handle() const { | 112 void* I420Buffer::native_handle() const { |
112 return nullptr; | 113 return nullptr; |
113 } | 114 } |
114 | 115 |
115 rtc::scoped_refptr<VideoFrameBuffer> I420Buffer::NativeToI420Buffer() { | 116 rtc::scoped_refptr<VideoFrameBuffer> I420Buffer::NativeToI420Buffer() { |
116 RTC_NOTREACHED(); | 117 RTC_NOTREACHED(); |
117 return nullptr; | 118 return nullptr; |
118 } | 119 } |
119 | 120 |
| 121 rtc::scoped_refptr<I420Buffer> I420Buffer::Copy( |
| 122 const rtc::scoped_refptr<VideoFrameBuffer>& buffer) { |
| 123 int width = buffer->width(); |
| 124 int height = buffer->height(); |
| 125 rtc::scoped_refptr<I420Buffer> copy = |
| 126 new rtc::RefCountedObject<I420Buffer>(width, height); |
| 127 RTC_CHECK(libyuv::I420Copy(buffer->data(kYPlane), buffer->stride(kYPlane), |
| 128 buffer->data(kUPlane), buffer->stride(kUPlane), |
| 129 buffer->data(kVPlane), buffer->stride(kVPlane), |
| 130 copy->MutableData(kYPlane), copy->stride(kYPlane), |
| 131 copy->MutableData(kUPlane), copy->stride(kUPlane), |
| 132 copy->MutableData(kVPlane), copy->stride(kVPlane), |
| 133 width, height) == 0); |
| 134 |
| 135 return copy; |
| 136 } |
| 137 |
120 NativeHandleBuffer::NativeHandleBuffer(void* native_handle, | 138 NativeHandleBuffer::NativeHandleBuffer(void* native_handle, |
121 int width, | 139 int width, |
122 int height) | 140 int height) |
123 : native_handle_(native_handle), width_(width), height_(height) { | 141 : native_handle_(native_handle), width_(width), height_(height) { |
124 RTC_DCHECK(native_handle != nullptr); | 142 RTC_DCHECK(native_handle != nullptr); |
125 RTC_DCHECK_GT(width, 0); | 143 RTC_DCHECK_GT(width, 0); |
126 RTC_DCHECK_GT(height, 0); | 144 RTC_DCHECK_GT(height, 0); |
127 } | 145 } |
128 | 146 |
129 int NativeHandleBuffer::width() const { | 147 int NativeHandleBuffer::width() const { |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 buffer->stride(kVPlane) * uv_offset_y + uv_offset_x; | 260 buffer->stride(kVPlane) * uv_offset_y + uv_offset_x; |
243 return new rtc::RefCountedObject<WrappedI420Buffer>( | 261 return new rtc::RefCountedObject<WrappedI420Buffer>( |
244 cropped_width, cropped_height, | 262 cropped_width, cropped_height, |
245 y_plane, buffer->stride(kYPlane), | 263 y_plane, buffer->stride(kYPlane), |
246 u_plane, buffer->stride(kUPlane), | 264 u_plane, buffer->stride(kUPlane), |
247 v_plane, buffer->stride(kVPlane), | 265 v_plane, buffer->stride(kVPlane), |
248 rtc::KeepRefUntilDone(buffer)); | 266 rtc::KeepRefUntilDone(buffer)); |
249 } | 267 } |
250 | 268 |
251 } // namespace webrtc | 269 } // namespace webrtc |
OLD | NEW |