Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/base/video_util.h" | 5 #include "media/base/video_util.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/numerics/safe_conversions.h" | 10 #include "base/numerics/safe_conversions.h" |
| 11 #include "base/numerics/safe_math.h" | 11 #include "base/numerics/safe_math.h" |
| 12 #include "media/base/video_frame.h" | 12 #include "media/base/video_frame.h" |
| 13 #include "media/base/yuv_convert.h" | 13 #include "media/base/yuv_convert.h" |
| 14 #include "third_party/libyuv/include/libyuv.h" | |
| 14 | 15 |
| 15 namespace media { | 16 namespace media { |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 // Empty method used for keeping a reference to the original media::VideoFrame. | 20 // Empty method used for keeping a reference to the original media::VideoFrame. |
| 20 void ReleaseOriginalFrame(const scoped_refptr<media::VideoFrame>& frame) {} | 21 void ReleaseOriginalFrame(const scoped_refptr<media::VideoFrame>& frame) {} |
| 21 | 22 |
| 22 } // namespace | 23 } // namespace |
| 23 | 24 |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 332 media::VideoFrame::WrapVideoFrame(frame, PIXEL_FORMAT_I420, | 333 media::VideoFrame::WrapVideoFrame(frame, PIXEL_FORMAT_I420, |
| 333 frame->visible_rect(), | 334 frame->visible_rect(), |
| 334 frame->natural_size()); | 335 frame->natural_size()); |
| 335 if (!wrapped_frame) | 336 if (!wrapped_frame) |
| 336 return nullptr; | 337 return nullptr; |
| 337 wrapped_frame->AddDestructionObserver( | 338 wrapped_frame->AddDestructionObserver( |
| 338 base::Bind(&ReleaseOriginalFrame, frame)); | 339 base::Bind(&ReleaseOriginalFrame, frame)); |
| 339 return wrapped_frame; | 340 return wrapped_frame; |
| 340 } | 341 } |
| 341 | 342 |
| 343 // Helper to pad the input |frame| with the repeated last column / row. | |
| 344 void Padding(uint8_t* frame, | |
|
miu
2016/04/30 00:41:13
Please put this function in an anonymous namespace
miu
2016/04/30 00:41:14
naming nit: ApplyPaddingOutsideVisibleRegion() or
xjz
2016/05/03 01:17:58
Done. Renamed as FillRegionOutsideVisibleRect().
xjz
2016/05/03 01:17:58
Done.
| |
| 345 const gfx::Size& frame_size, | |
| 346 const gfx::Size& visible_size) { | |
| 347 if (!frame) | |
|
miu
2016/04/30 00:41:13
This should go at the top of I420CopyWithPadding()
xjz
2016/05/03 01:17:58
Done.
| |
| 348 return; | |
| 349 uint8_t* dst = frame; | |
| 350 const int stride = frame_size.width(); | |
| 351 if (visible_size.width() < stride) { | |
|
miu
2016/04/30 00:41:13
To avoid the possibility of copying from an empty
xjz
2016/05/03 01:17:58
Done. Add early return when the visible region is
| |
| 352 const int width = visible_size.width(); | |
| 353 const int pad_length = stride - visible_size.width(); | |
| 354 for (int i = 0; i < visible_size.height(); ++i, dst += stride) | |
| 355 std::memset(dst + width, dst[width - 1], pad_length); | |
| 356 } | |
| 357 | |
| 358 if (visible_size.height() < frame_size.height()) { | |
|
miu
2016/04/30 00:41:13
Here too:
if (... && !visible_size.IsEmpty()) {
xjz
2016/05/03 01:17:58
Add early return when the visible region is empty.
| |
| 359 uint8_t* src = dst - stride; | |
| 360 for (int i = visible_size.height(); i < frame_size.height(); | |
| 361 ++i, dst += stride) | |
| 362 std::memcpy(dst, src, frame_size.width()); | |
| 363 } | |
| 364 } | |
| 365 | |
| 366 bool I420CopyWithPadding(const scoped_refptr<VideoFrame> src_frame, | |
| 367 scoped_refptr<VideoFrame> dst_frame) { | |
| 368 DCHECK_GE(dst_frame->coded_size().width(), src_frame->visible_rect().width()); | |
| 369 DCHECK_GE(dst_frame->coded_size().height(), | |
|
miu
2016/04/30 00:41:14
Looks like this code assumes dst_frame->visible_re
xjz
2016/05/03 01:17:58
Done.
| |
| 370 src_frame->visible_rect().height()); | |
| 371 | |
| 372 if (libyuv::I420Copy(src_frame->data(media::VideoFrame::kYPlane), | |
|
miu
2016/04/30 00:41:13
Please replace all data() calls with visible_data(
xjz
2016/05/03 01:17:58
Done. Though I think in our application src_frame-
| |
| 373 src_frame->stride(media::VideoFrame::kYPlane), | |
| 374 src_frame->data(media::VideoFrame::kUPlane), | |
| 375 src_frame->stride(media::VideoFrame::kUPlane), | |
| 376 src_frame->data(media::VideoFrame::kVPlane), | |
| 377 src_frame->stride(media::VideoFrame::kVPlane), | |
| 378 dst_frame->data(media::VideoFrame::kYPlane), | |
| 379 dst_frame->stride(media::VideoFrame::kYPlane), | |
| 380 dst_frame->data(media::VideoFrame::kUPlane), | |
| 381 dst_frame->stride(media::VideoFrame::kUPlane), | |
| 382 dst_frame->data(media::VideoFrame::kVPlane), | |
| 383 dst_frame->stride(media::VideoFrame::kVPlane), | |
| 384 src_frame->visible_rect().width(), | |
| 385 src_frame->visible_rect().height())) | |
| 386 return false; | |
| 387 | |
| 388 // Padding with the repeated last column / row. | |
| 389 Padding(dst_frame->data(media::VideoFrame::kYPlane), dst_frame->coded_size(), | |
| 390 src_frame->visible_rect().size()); | |
| 391 const gfx::Size uv_visible_size(src_frame->visible_rect().width() / 2, | |
|
miu
2016/04/30 00:41:14
Is this correct for odd widths/heights? The logic
xjz
2016/05/03 01:17:58
Done.
| |
| 392 src_frame->visible_rect().height() / 2); | |
| 393 const gfx::Size uv_coded_size(dst_frame->coded_size().width() / 2, | |
| 394 dst_frame->coded_size().height() / 2); | |
| 395 Padding(dst_frame->data(media::VideoFrame::kUPlane), uv_coded_size, | |
| 396 uv_visible_size); | |
| 397 Padding(dst_frame->data(media::VideoFrame::kVPlane), uv_coded_size, | |
| 398 uv_visible_size); | |
| 399 | |
| 400 return true; | |
| 401 } | |
| 402 | |
| 342 } // namespace media | 403 } // namespace media |
| OLD | NEW |