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

Side by Side Diff: media/base/decoder_buffer.cc

Issue 10949029: Replace av_malloc with AlignedAlloc for memory allocation in DecoderBuffer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Resolve Dale's comments. Created 8 years, 3 months 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/decoder_buffer.h ('k') | media/base/decoder_buffer_unittest.cc » ('j') | 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/base/decoder_buffer.h" 5 #include "media/base/decoder_buffer.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "media/base/decrypt_config.h" 8 #include "media/base/decrypt_config.h"
9
9 #if !defined(OS_ANDROID) 10 #if !defined(OS_ANDROID)
10 #include "media/ffmpeg/ffmpeg_common.h" 11 #include "base/memory/aligned_memory.h"
11 #endif 12 #endif
12 13
13 namespace media { 14 namespace media {
14 15
15 DecoderBuffer::DecoderBuffer(int buffer_size) 16 DecoderBuffer::DecoderBuffer(int buffer_size)
16 : Buffer(base::TimeDelta(), base::TimeDelta()), 17 : Buffer(base::TimeDelta(), base::TimeDelta()),
17 buffer_size_(buffer_size) { 18 buffer_size_(buffer_size) {
18 Initialize(); 19 Initialize();
19 } 20 }
20 21
21 DecoderBuffer::DecoderBuffer(const uint8* data, int buffer_size) 22 DecoderBuffer::DecoderBuffer(const uint8* data, int buffer_size)
22 : Buffer(base::TimeDelta(), base::TimeDelta()), 23 : Buffer(base::TimeDelta(), base::TimeDelta()),
23 buffer_size_(buffer_size) { 24 buffer_size_(buffer_size) {
24 // Prevent invalid allocations. Also used to create end of stream buffers. 25 // Prevent invalid allocations. Also used to create end of stream buffers.
25 if (!data) { 26 if (!data) {
26 buffer_size_ = 0; 27 buffer_size_ = 0;
27 data_ = NULL; 28 data_ = NULL;
28 return; 29 return;
29 } 30 }
30 31
31 Initialize(); 32 Initialize();
32 memcpy(data_, data, buffer_size_); 33 memcpy(data_, data, buffer_size_);
33 } 34 }
34 35
35 DecoderBuffer::~DecoderBuffer() { 36 DecoderBuffer::~DecoderBuffer() {
36 #if !defined(OS_ANDROID) 37 #if !defined(OS_ANDROID)
37 av_free(data_); 38 base::AlignedFree(data_);
38 #else 39 #else
39 delete[] data_; 40 delete[] data_;
40 #endif 41 #endif
41 } 42 }
42 43
43 void DecoderBuffer::Initialize() { 44 void DecoderBuffer::Initialize() {
44 DCHECK_GE(buffer_size_, 0); 45 DCHECK_GE(buffer_size_, 0);
45 #if !defined(OS_ANDROID) 46 #if !defined(OS_ANDROID)
46 // Why FF_INPUT_BUFFER_PADDING_SIZE? FFmpeg assumes all input buffers are
47 // padded. Using av_malloc with padding ensures FFmpeg only recieves data
48 // padded and aligned to its specifications.
49 data_ = reinterpret_cast<uint8*>( 47 data_ = reinterpret_cast<uint8*>(
50 av_malloc(buffer_size_ + FF_INPUT_BUFFER_PADDING_SIZE)); 48 base::AlignedAlloc(buffer_size_ + kPaddingSize, kAlignmentSize));
51 memset(data_ + buffer_size_, 0, FF_INPUT_BUFFER_PADDING_SIZE); 49 memset(data_ + buffer_size_, 0, kPaddingSize);
52 #else 50 #else
53 data_ = new uint8[buffer_size_]; 51 data_ = new uint8[buffer_size_];
54 #endif 52 #endif
55 } 53 }
56 54
57 scoped_refptr<DecoderBuffer> DecoderBuffer::CopyFrom(const uint8* data, 55 scoped_refptr<DecoderBuffer> DecoderBuffer::CopyFrom(const uint8* data,
58 int data_size) { 56 int data_size) {
59 DCHECK(data); 57 DCHECK(data);
60 return make_scoped_refptr(new DecoderBuffer(data, data_size)); 58 return make_scoped_refptr(new DecoderBuffer(data, data_size));
61 } 59 }
(...skipping 16 matching lines...) Expand all
78 76
79 const DecryptConfig* DecoderBuffer::GetDecryptConfig() const { 77 const DecryptConfig* DecoderBuffer::GetDecryptConfig() const {
80 return decrypt_config_.get(); 78 return decrypt_config_.get();
81 } 79 }
82 80
83 void DecoderBuffer::SetDecryptConfig(scoped_ptr<DecryptConfig> decrypt_config) { 81 void DecoderBuffer::SetDecryptConfig(scoped_ptr<DecryptConfig> decrypt_config) {
84 decrypt_config_ = decrypt_config.Pass(); 82 decrypt_config_ = decrypt_config.Pass();
85 } 83 }
86 84
87 } // namespace media 85 } // namespace media
OLDNEW
« no previous file with comments | « media/base/decoder_buffer.h ('k') | media/base/decoder_buffer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698