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 | 14 |
15 namespace media { | 15 namespace media { |
16 | 16 |
| 17 namespace { |
| 18 |
| 19 // Empty method used for keeping a reference to the original media::VideoFrame. |
| 20 void ReleaseOriginalFrame(const scoped_refptr<media::VideoFrame>& frame) {} |
| 21 |
| 22 } // namespace |
| 23 |
17 gfx::Size GetNaturalSize(const gfx::Size& visible_size, | 24 gfx::Size GetNaturalSize(const gfx::Size& visible_size, |
18 int aspect_ratio_numerator, | 25 int aspect_ratio_numerator, |
19 int aspect_ratio_denominator) { | 26 int aspect_ratio_denominator) { |
20 if (aspect_ratio_denominator == 0 || | 27 if (aspect_ratio_denominator == 0 || |
21 aspect_ratio_numerator < 0 || | 28 aspect_ratio_numerator < 0 || |
22 aspect_ratio_denominator < 0) | 29 aspect_ratio_denominator < 0) |
23 return gfx::Size(); | 30 return gfx::Size(); |
24 | 31 |
25 double aspect_ratio = aspect_ratio_numerator / | 32 double aspect_ratio = aspect_ratio_numerator / |
26 static_cast<double>(aspect_ratio_denominator); | 33 static_cast<double>(aspect_ratio_denominator); |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 frame->data(kY) + y_offset, | 316 frame->data(kY) + y_offset, |
310 frame->data(kU) + uv_offset, | 317 frame->data(kU) + uv_offset, |
311 frame->data(kV) + uv_offset, | 318 frame->data(kV) + uv_offset, |
312 region_in_frame.width(), | 319 region_in_frame.width(), |
313 region_in_frame.height(), | 320 region_in_frame.height(), |
314 stride, | 321 stride, |
315 frame->stride(kY), | 322 frame->stride(kY), |
316 uv_stride); | 323 uv_stride); |
317 } | 324 } |
318 | 325 |
| 326 scoped_refptr<VideoFrame> WrapAsI420VideoFrame( |
| 327 const scoped_refptr<VideoFrame>& frame) { |
| 328 DCHECK_EQ(VideoFrame::STORAGE_OWNED_MEMORY, frame->storage_type()); |
| 329 DCHECK_EQ(PIXEL_FORMAT_YV12A, frame->format()); |
| 330 |
| 331 scoped_refptr<media::VideoFrame> wrapped_frame = |
| 332 media::VideoFrame::WrapVideoFrame(frame, PIXEL_FORMAT_I420, |
| 333 frame->visible_rect(), |
| 334 frame->natural_size()); |
| 335 if (!wrapped_frame) |
| 336 return nullptr; |
| 337 wrapped_frame->AddDestructionObserver( |
| 338 base::Bind(&ReleaseOriginalFrame, frame)); |
| 339 return wrapped_frame; |
| 340 } |
| 341 |
319 } // namespace media | 342 } // namespace media |
OLD | NEW |