Chromium Code Reviews| 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 #include "libyuv/convert.h" |
| 16 #include "libyuv/scale.h" | |
| 16 | 17 |
| 17 // Aligning pointer to 64 bytes for improved performance, e.g. use SIMD. | 18 // Aligning pointer to 64 bytes for improved performance, e.g. use SIMD. |
| 18 static const int kBufferAlignment = 64; | 19 static const int kBufferAlignment = 64; |
| 19 | 20 |
| 20 namespace webrtc { | 21 namespace webrtc { |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 int I420DataSize(int height, int stride_y, int stride_u, int stride_v) { | 25 int I420DataSize(int height, int stride_y, int stride_u, int stride_v) { |
| 25 return stride_y * height + (stride_u + stride_v) * ((height + 1) / 2); | 26 return stride_y * height + (stride_u + stride_v) * ((height + 1) / 2); |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 buffer->DataU(), buffer->StrideU(), | 201 buffer->DataU(), buffer->StrideU(), |
| 201 buffer->DataV(), buffer->StrideV(), | 202 buffer->DataV(), buffer->StrideV(), |
| 202 copy->MutableDataY(), copy->StrideY(), | 203 copy->MutableDataY(), copy->StrideY(), |
| 203 copy->MutableDataU(), copy->StrideU(), | 204 copy->MutableDataU(), copy->StrideU(), |
| 204 copy->MutableDataV(), copy->StrideV(), | 205 copy->MutableDataV(), copy->StrideV(), |
| 205 width, height) == 0); | 206 width, height) == 0); |
| 206 | 207 |
| 207 return copy; | 208 return copy; |
| 208 } | 209 } |
| 209 | 210 |
| 211 rtc::scoped_refptr<I420Buffer> I420Buffer::CropAndScale( | |
|
nisse-webrtc
2016/05/16 09:44:16
And I realize this methods still needs a unittest.
| |
| 212 const rtc::scoped_refptr<VideoFrameBuffer>& buffer, | |
| 213 int offset_x, | |
| 214 int offset_y, | |
| 215 int crop_width, | |
| 216 int crop_height, | |
| 217 int dst_width, | |
| 218 int dst_height) { | |
| 219 RTC_CHECK_LE(crop_width, buffer->width()); | |
| 220 RTC_CHECK_LE(crop_height, buffer->height()); | |
| 221 RTC_CHECK_LE(crop_width + offset_x, buffer->width()); | |
| 222 RTC_CHECK_LE(crop_height + offset_y, buffer->height()); | |
| 223 | |
| 224 rtc::scoped_refptr<I420Buffer> scaled = | |
| 225 new rtc::RefCountedObject<I420Buffer>(dst_width, dst_height); | |
| 226 | |
| 227 // Make sure offset is even so that u/v plane becomes aligned. | |
| 228 const int uv_offset_x = offset_x / 2; | |
| 229 const int uv_offset_y = offset_y / 2; | |
| 230 offset_x = uv_offset_x * 2; | |
| 231 offset_y = uv_offset_y * 2; | |
| 232 | |
| 233 const uint8_t* y_plane = buffer->DataY() + | |
| 234 buffer->StrideY() * offset_y + offset_x; | |
| 235 const uint8_t* u_plane = buffer->DataU() + | |
| 236 buffer->StrideU() * uv_offset_y + uv_offset_x; | |
| 237 const uint8_t* v_plane = buffer->DataV() + | |
| 238 buffer->StrideV() * uv_offset_y + uv_offset_x; | |
| 239 if (libyuv::I420Scale(y_plane, buffer->StrideY(), | |
| 240 u_plane, buffer->StrideU(), | |
| 241 v_plane, buffer->StrideV(), | |
| 242 crop_width, crop_height, | |
| 243 scaled->MutableDataY(), scaled->StrideY(), | |
| 244 scaled->MutableDataU(), scaled->StrideU(), | |
| 245 scaled->MutableDataV(), scaled->StrideV(), | |
| 246 dst_width, dst_height, libyuv::kFilterBox) < 0) { | |
| 247 return nullptr; | |
| 248 } | |
| 249 return scaled; | |
| 250 } | |
| 251 | |
| 210 NativeHandleBuffer::NativeHandleBuffer(void* native_handle, | 252 NativeHandleBuffer::NativeHandleBuffer(void* native_handle, |
| 211 int width, | 253 int width, |
| 212 int height) | 254 int height) |
| 213 : native_handle_(native_handle), width_(width), height_(height) { | 255 : native_handle_(native_handle), width_(width), height_(height) { |
| 214 RTC_DCHECK(native_handle != nullptr); | 256 RTC_DCHECK(native_handle != nullptr); |
| 215 RTC_DCHECK_GT(width, 0); | 257 RTC_DCHECK_GT(width, 0); |
| 216 RTC_DCHECK_GT(height, 0); | 258 RTC_DCHECK_GT(height, 0); |
| 217 } | 259 } |
| 218 | 260 |
| 219 bool NativeHandleBuffer::IsMutable() { | 261 bool NativeHandleBuffer::IsMutable() { |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 349 buffer->StrideV() * uv_offset_y + uv_offset_x; | 391 buffer->StrideV() * uv_offset_y + uv_offset_x; |
| 350 return new rtc::RefCountedObject<WrappedI420Buffer>( | 392 return new rtc::RefCountedObject<WrappedI420Buffer>( |
| 351 cropped_width, cropped_height, | 393 cropped_width, cropped_height, |
| 352 y_plane, buffer->StrideY(), | 394 y_plane, buffer->StrideY(), |
| 353 u_plane, buffer->StrideU(), | 395 u_plane, buffer->StrideU(), |
| 354 v_plane, buffer->StrideV(), | 396 v_plane, buffer->StrideV(), |
| 355 rtc::KeepRefUntilDone(buffer)); | 397 rtc::KeepRefUntilDone(buffer)); |
| 356 } | 398 } |
| 357 | 399 |
| 358 } // namespace webrtc | 400 } // namespace webrtc |
| OLD | NEW |