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/ffmpeg/ffmpeg_common.h" | 5 #include "media/ffmpeg/ffmpeg_common.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
11 #include "base/strings/string_split.h" | 11 #include "base/strings/string_split.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "media/base/decoder_buffer.h" | 13 #include "media/base/decoder_buffer.h" |
14 #include "media/base/video_util.h" | 14 #include "media/base/video_util.h" |
15 | 15 |
16 namespace media { | 16 namespace media { |
17 | 17 |
18 // Why FF_INPUT_BUFFER_PADDING_SIZE? FFmpeg assumes all input buffers are | 18 // Why FF_INPUT_BUFFER_PADDING_SIZE? FFmpeg assumes all input buffers are |
19 // padded. Check here to ensure FFmpeg only receives data padded to its | 19 // padded. Check here to ensure FFmpeg only receives data padded to its |
20 // specifications. | 20 // specifications. |
21 static_assert(DecoderBuffer::kPaddingSize >= FF_INPUT_BUFFER_PADDING_SIZE, | 21 static_assert(DecoderBuffer::kPaddingSize >= FF_INPUT_BUFFER_PADDING_SIZE, |
22 "DecoderBuffer padding size does not fit ffmpeg requirement"); | 22 "DecoderBuffer padding size does not fit ffmpeg requirement"); |
23 | 23 |
24 // Alignment requirement by FFmpeg for input and output buffers. This need to | 24 // Alignment requirement by FFmpeg for input and output buffers. This need to |
25 // be updated to match FFmpeg when it changes. | 25 // be updated to match FFmpeg when it changes. See libavutil/mem.c. |
26 #if defined(ARCH_CPU_ARM_FAMILY) | 26 #if defined(ARCH_CPU_ARM_FAMILY) |
27 static const int kFFmpegBufferAddressAlignment = 16; | 27 static const int kFFmpegBufferAddressAlignment = 16; |
28 #else | 28 #else |
29 static const int kFFmpegBufferAddressAlignment = 32; | 29 static const int kFFmpegBufferAddressAlignment = 32; |
30 #endif | 30 #endif |
31 | 31 |
32 // Check here to ensure FFmpeg only receives data aligned to its specifications. | 32 // Check here to ensure FFmpeg only receives data aligned to its specifications. |
33 static_assert( | 33 static_assert( |
34 DecoderBuffer::kAlignmentSize >= kFFmpegBufferAddressAlignment && | 34 DecoderBuffer::kAlignmentSize >= kFFmpegBufferAddressAlignment && |
35 DecoderBuffer::kAlignmentSize % kFFmpegBufferAddressAlignment == 0, | 35 DecoderBuffer::kAlignmentSize % kFFmpegBufferAddressAlignment == 0, |
36 "DecoderBuffer alignment size does not fit ffmpeg requirement"); | 36 "DecoderBuffer alignment size does not fit ffmpeg requirement"); |
37 | 37 |
38 // Allows faster SIMD YUV convert. Also, FFmpeg overreads/-writes occasionally. | |
39 // See video_get_buffer() in libavcodec/utils.c. | |
40 static const int kFFmpegOutputBufferPaddingSize = 16; | |
41 | |
42 static_assert(VideoFrame::kFrameSizePadding >= kFFmpegOutputBufferPaddingSize, | |
43 "VideoFrame padding size does not fit ffmpeg requirement"); | |
44 | |
45 static_assert( | 38 static_assert( |
46 VideoFrame::kFrameAddressAlignment >= kFFmpegBufferAddressAlignment && | 39 VideoFrame::kFrameAddressAlignment >= kFFmpegBufferAddressAlignment && |
47 VideoFrame::kFrameAddressAlignment % kFFmpegBufferAddressAlignment == 0, | 40 VideoFrame::kFrameAddressAlignment % kFFmpegBufferAddressAlignment == 0, |
48 "VideoFrame frame address alignment does not fit ffmpeg requirement"); | 41 "VideoFrame frame address alignment does not fit ffmpeg requirement"); |
49 | 42 |
| 43 static_assert( |
| 44 VideoFrame::kFrameSizeAlignment >= STRIDE_ALIGN && |
| 45 VideoFrame::kFrameSizeAlignment % STRIDE_ALIGN == 0, |
| 46 "VideoFrame size alignment does not fit ffmpeg requirement"); |
| 47 |
| 48 // Allows faster SIMD YUV convert. Also, FFmpeg overreads/-writes occasionally. |
| 49 // See video_get_buffer() and update_frame_pool() in libavcodec/utils.c |
| 50 static_assert(VideoFrame::kFrameSizePadding >= FRAME_PADDING, |
| 51 "VideoFrame padding size does not fit ffmpeg requirement"); |
| 52 |
50 static const AVRational kMicrosBase = { 1, base::Time::kMicrosecondsPerSecond }; | 53 static const AVRational kMicrosBase = { 1, base::Time::kMicrosecondsPerSecond }; |
51 | 54 |
52 base::TimeDelta ConvertFromTimeBase(const AVRational& time_base, | 55 base::TimeDelta ConvertFromTimeBase(const AVRational& time_base, |
53 int64 timestamp) { | 56 int64 timestamp) { |
54 int64 microseconds = av_rescale_q(timestamp, time_base, kMicrosBase); | 57 int64 microseconds = av_rescale_q(timestamp, time_base, kMicrosBase); |
55 return base::TimeDelta::FromMicroseconds(microseconds); | 58 return base::TimeDelta::FromMicroseconds(microseconds); |
56 } | 59 } |
57 | 60 |
58 int64 ConvertToTimeBase(const AVRational& time_base, | 61 int64 ConvertToTimeBase(const AVRational& time_base, |
59 const base::TimeDelta& timestamp) { | 62 const base::TimeDelta& timestamp) { |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 return false; | 640 return false; |
638 | 641 |
639 *out = parsed_time; | 642 *out = parsed_time; |
640 return true; | 643 return true; |
641 } | 644 } |
642 | 645 |
643 return false; | 646 return false; |
644 } | 647 } |
645 | 648 |
646 } // namespace media | 649 } // namespace media |
OLD | NEW |