Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: media/ffmpeg/ffmpeg_common.cc

Issue 11308310: Replace av_malloc with AlignedAlloc for memory allocation in VideoFrame. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/base/video_frame.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "media/base/decoder_buffer.h" 9 #include "media/base/decoder_buffer.h"
10 #include "media/base/video_frame.h"
10 #include "media/base/video_util.h" 11 #include "media/base/video_util.h"
11 12
12 namespace media { 13 namespace media {
13 14
14 // Why FF_INPUT_BUFFER_PADDING_SIZE? FFmpeg assumes all input buffers are 15 // Why FF_INPUT_BUFFER_PADDING_SIZE? FFmpeg assumes all input buffers are
15 // padded. Check here to ensure FFmpeg only receives data padded to its 16 // padded. Check here to ensure FFmpeg only receives data padded to its
16 // specifications. 17 // specifications.
17 COMPILE_ASSERT(DecoderBuffer::kPaddingSize >= FF_INPUT_BUFFER_PADDING_SIZE, 18 COMPILE_ASSERT(DecoderBuffer::kPaddingSize >= FF_INPUT_BUFFER_PADDING_SIZE,
18 decoder_buffer_padding_size_does_not_fit_ffmpeg_requirement); 19 decoder_buffer_padding_size_does_not_fit_ffmpeg_requirement);
19 20
20 // Alignment requirement by FFmpeg for input buffers. This need to be updated 21 // Alignment requirement by FFmpeg for input and output buffers. This need to
21 // to match FFmpeg when it changes. 22 // be updated to match FFmpeg when it changes.
22 #if defined(ARCH_CPU_ARM_FAMILY) 23 #if defined(ARCH_CPU_ARM_FAMILY)
23 static const int kFFmpegInputBufferAlignmentSize = 16; 24 static const int kFFmpegBufferAddressAlignment = 16;
24 #else 25 #else
25 static const int kFFmpegInputBufferAlignmentSize = 32; 26 static const int kFFmpegBufferAddressAlignment = 32;
26 #endif 27 #endif
28
27 // Check here to ensure FFmpeg only receives data aligned to its specifications. 29 // Check here to ensure FFmpeg only receives data aligned to its specifications.
28 COMPILE_ASSERT( 30 COMPILE_ASSERT(
29 DecoderBuffer::kAlignmentSize >= kFFmpegInputBufferAlignmentSize && 31 DecoderBuffer::kAlignmentSize >= kFFmpegBufferAddressAlignment &&
30 DecoderBuffer::kAlignmentSize % kFFmpegInputBufferAlignmentSize == 0, 32 DecoderBuffer::kAlignmentSize % kFFmpegBufferAddressAlignment == 0,
31 decoder_buffer_alignment_size_does_not_fit_ffmpeg_requirement); 33 decoder_buffer_alignment_size_does_not_fit_ffmpeg_requirement);
32 34
35 // Allows faster SIMD YUV convert. Also, FFmpeg overreads/-writes occasionally.
36 // See video_get_buffer() in libavcodec/utils.c.
37 static const int kFFmpegOutputBufferPaddingSize = 16;
38
39 COMPILE_ASSERT(VideoFrame::kFrameSizePadding >= kFFmpegOutputBufferPaddingSize,
40 video_frame_padding_size_does_not_fit_ffmpeg_requirement);
41
42 COMPILE_ASSERT(
43 VideoFrame::kFrameAddressAlignment >= kFFmpegBufferAddressAlignment &&
44 VideoFrame::kFrameAddressAlignment % kFFmpegBufferAddressAlignment == 0,
45 video_frame_address_alignment_does_not_fit_ffmpeg_requirement);
46
33 static const AVRational kMicrosBase = { 1, base::Time::kMicrosecondsPerSecond }; 47 static const AVRational kMicrosBase = { 1, base::Time::kMicrosecondsPerSecond };
34 48
35 base::TimeDelta ConvertFromTimeBase(const AVRational& time_base, 49 base::TimeDelta ConvertFromTimeBase(const AVRational& time_base,
36 int64 timestamp) { 50 int64 timestamp) {
37 int64 microseconds = av_rescale_q(timestamp, time_base, kMicrosBase); 51 int64 microseconds = av_rescale_q(timestamp, time_base, kMicrosBase);
38 return base::TimeDelta::FromMicroseconds(microseconds); 52 return base::TimeDelta::FromMicroseconds(microseconds);
39 } 53 }
40 54
41 int64 ConvertToTimeBase(const AVRational& time_base, 55 int64 ConvertToTimeBase(const AVRational& time_base,
42 const base::TimeDelta& timestamp) { 56 const base::TimeDelta& timestamp) {
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 return PIX_FMT_YUV422P; 421 return PIX_FMT_YUV422P;
408 case VideoFrame::YV12: 422 case VideoFrame::YV12:
409 return PIX_FMT_YUV420P; 423 return PIX_FMT_YUV420P;
410 default: 424 default:
411 DVLOG(1) << "Unsupported VideoFrame::Format: " << video_format; 425 DVLOG(1) << "Unsupported VideoFrame::Format: " << video_format;
412 } 426 }
413 return PIX_FMT_NONE; 427 return PIX_FMT_NONE;
414 } 428 }
415 429
416 } // namespace media 430 } // namespace media
OLDNEW
« no previous file with comments | « media/base/video_frame.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698