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/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/numerics/safe_conversions.h" | 11 #include "base/numerics/safe_conversions.h" |
12 #include "base/numerics/safe_math.h" | 12 #include "base/numerics/safe_math.h" |
13 #include "media/base/video_frame.h" | 13 #include "media/base/video_frame.h" |
14 #include "media/base/yuv_convert.h" | |
15 #include "third_party/libyuv/include/libyuv.h" | 14 #include "third_party/libyuv/include/libyuv.h" |
16 | 15 |
17 namespace media { | 16 namespace media { |
18 | 17 |
19 namespace { | 18 namespace { |
20 | 19 |
21 // 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. |
22 void ReleaseOriginalFrame(const scoped_refptr<media::VideoFrame>& frame) {} | 21 void ReleaseOriginalFrame(const scoped_refptr<media::VideoFrame>& frame) {} |
23 | 22 |
24 // Helper to apply padding to the region outside visible rect up to the coded | 23 // Helper to apply padding to the region outside visible rect up to the coded |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 const int kY = VideoFrame::kYPlane; | 330 const int kY = VideoFrame::kYPlane; |
332 const int kU = VideoFrame::kUPlane; | 331 const int kU = VideoFrame::kUPlane; |
333 const int kV = VideoFrame::kVPlane; | 332 const int kV = VideoFrame::kVPlane; |
334 CHECK_EQ(frame->stride(kU), frame->stride(kV)); | 333 CHECK_EQ(frame->stride(kU), frame->stride(kV)); |
335 const int uv_stride = frame->stride(kU); | 334 const int uv_stride = frame->stride(kU); |
336 | 335 |
337 if (region_in_frame != gfx::Rect(frame->coded_size())) { | 336 if (region_in_frame != gfx::Rect(frame->coded_size())) { |
338 LetterboxYUV(frame, region_in_frame); | 337 LetterboxYUV(frame, region_in_frame); |
339 } | 338 } |
340 | 339 |
341 const int y_offset = region_in_frame.x() | 340 const int y_offset = |
342 + (region_in_frame.y() * frame->stride(kY)); | 341 region_in_frame.x() + (region_in_frame.y() * frame->stride(kY)); |
343 const int uv_offset = region_in_frame.x() / 2 | 342 const int uv_offset = |
344 + (region_in_frame.y() / 2 * uv_stride); | 343 region_in_frame.x() / 2 + (region_in_frame.y() / 2 * uv_stride); |
345 | 344 |
346 ConvertRGB32ToYUV(source, | 345 libyuv::ARGBToI420(source, stride, frame->data(kY) + y_offset, |
347 frame->data(kY) + y_offset, | 346 frame->stride(kY), frame->data(kU) + uv_offset, uv_stride, |
348 frame->data(kU) + uv_offset, | 347 frame->data(kV) + uv_offset, uv_stride, |
349 frame->data(kV) + uv_offset, | 348 region_in_frame.width(), region_in_frame.height()); |
350 region_in_frame.width(), | |
351 region_in_frame.height(), | |
352 stride, | |
353 frame->stride(kY), | |
354 uv_stride); | |
355 } | 349 } |
356 | 350 |
357 scoped_refptr<VideoFrame> WrapAsI420VideoFrame( | 351 scoped_refptr<VideoFrame> WrapAsI420VideoFrame( |
358 const scoped_refptr<VideoFrame>& frame) { | 352 const scoped_refptr<VideoFrame>& frame) { |
359 DCHECK_EQ(VideoFrame::STORAGE_OWNED_MEMORY, frame->storage_type()); | 353 DCHECK_EQ(VideoFrame::STORAGE_OWNED_MEMORY, frame->storage_type()); |
360 DCHECK_EQ(PIXEL_FORMAT_YV12A, frame->format()); | 354 DCHECK_EQ(PIXEL_FORMAT_YV12A, frame->format()); |
361 | 355 |
362 scoped_refptr<media::VideoFrame> wrapped_frame = | 356 scoped_refptr<media::VideoFrame> wrapped_frame = |
363 media::VideoFrame::WrapVideoFrame(frame, PIXEL_FORMAT_I420, | 357 media::VideoFrame::WrapVideoFrame(frame, PIXEL_FORMAT_I420, |
364 frame->visible_rect(), | 358 frame->visible_rect(), |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 dst_frame->stride(VideoFrame::kVPlane), | 407 dst_frame->stride(VideoFrame::kVPlane), |
414 VideoFrame::PlaneSize(PIXEL_FORMAT_I420, VideoFrame::kVPlane, | 408 VideoFrame::PlaneSize(PIXEL_FORMAT_I420, VideoFrame::kVPlane, |
415 dst_frame->coded_size()), | 409 dst_frame->coded_size()), |
416 VideoFrame::PlaneSize(PIXEL_FORMAT_I420, VideoFrame::kVPlane, | 410 VideoFrame::PlaneSize(PIXEL_FORMAT_I420, VideoFrame::kVPlane, |
417 src_frame.visible_rect().size())); | 411 src_frame.visible_rect().size())); |
418 | 412 |
419 return true; | 413 return true; |
420 } | 414 } |
421 | 415 |
422 } // namespace media | 416 } // namespace media |
OLD | NEW |