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

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 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
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 #if !defined(OS_ANDROID)
9 #include "base/memory/aligned_memory.h"
10 #endif
8 #include "media/base/decrypt_config.h" 11 #include "media/base/decrypt_config.h"
9 #if !defined(OS_ANDROID)
10 #include "media/ffmpeg/ffmpeg_common.h"
11 #endif
12 12
13 namespace media { 13 namespace media {
14 14
15 DecoderBuffer::DecoderBuffer(int buffer_size) 15 DecoderBuffer::DecoderBuffer(int buffer_size)
16 : Buffer(base::TimeDelta(), base::TimeDelta()), 16 : Buffer(base::TimeDelta(), base::TimeDelta()),
17 buffer_size_(buffer_size) { 17 buffer_size_(buffer_size) {
18 Initialize(); 18 Initialize();
19 } 19 }
20 20
21 DecoderBuffer::DecoderBuffer(const uint8* data, int buffer_size) 21 DecoderBuffer::DecoderBuffer(const uint8* data, int buffer_size)
22 : Buffer(base::TimeDelta(), base::TimeDelta()), 22 : Buffer(base::TimeDelta(), base::TimeDelta()),
23 buffer_size_(buffer_size) { 23 buffer_size_(buffer_size) {
24 // Prevent invalid allocations. Also used to create end of stream buffers. 24 // Prevent invalid allocations. Also used to create end of stream buffers.
25 if (!data) { 25 if (!data) {
26 buffer_size_ = 0; 26 buffer_size_ = 0;
27 data_ = NULL; 27 data_ = NULL;
28 return; 28 return;
29 } 29 }
30 30
31 Initialize(); 31 Initialize();
32 memcpy(data_, data, buffer_size_); 32 memcpy(data_, data, buffer_size_);
33 } 33 }
34 34
35 DecoderBuffer::~DecoderBuffer() { 35 DecoderBuffer::~DecoderBuffer() {
36 #if !defined(OS_ANDROID) 36 #if !defined(OS_ANDROID)
37 av_free(data_); 37 base::AlignedFree(data_);
38 #else 38 #else
39 delete[] data_; 39 delete[] data_;
40 #endif 40 #endif
41 } 41 }
42 42
43 void DecoderBuffer::Initialize() { 43 void DecoderBuffer::Initialize() {
44 DCHECK_GE(buffer_size_, 0); 44 DCHECK_GE(buffer_size_, 0);
45 #if !defined(OS_ANDROID) 45 #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*>( 46 data_ = reinterpret_cast<uint8*>(
50 av_malloc(buffer_size_ + FF_INPUT_BUFFER_PADDING_SIZE)); 47 base::AlignedAlloc(buffer_size_ + kPaddingSize, kAlignmentSize));
51 memset(data_ + buffer_size_, 0, FF_INPUT_BUFFER_PADDING_SIZE); 48 memset(data_ + buffer_size_, 0, kPaddingSize);
52 #else 49 #else
53 data_ = new uint8[buffer_size_]; 50 data_ = new uint8[buffer_size_];
54 #endif 51 #endif
55 } 52 }
56 53
57 scoped_refptr<DecoderBuffer> DecoderBuffer::CopyFrom(const uint8* data, 54 scoped_refptr<DecoderBuffer> DecoderBuffer::CopyFrom(const uint8* data,
58 int data_size) { 55 int data_size) {
59 DCHECK(data); 56 DCHECK(data);
60 return make_scoped_refptr(new DecoderBuffer(data, data_size)); 57 return make_scoped_refptr(new DecoderBuffer(data, data_size));
61 } 58 }
(...skipping 16 matching lines...) Expand all
78 75
79 const DecryptConfig* DecoderBuffer::GetDecryptConfig() const { 76 const DecryptConfig* DecoderBuffer::GetDecryptConfig() const {
80 return decrypt_config_.get(); 77 return decrypt_config_.get();
81 } 78 }
82 79
83 void DecoderBuffer::SetDecryptConfig(scoped_ptr<DecryptConfig> decrypt_config) { 80 void DecoderBuffer::SetDecryptConfig(scoped_ptr<DecryptConfig> decrypt_config) {
84 decrypt_config_ = decrypt_config.Pass(); 81 decrypt_config_ = decrypt_config.Pass();
85 } 82 }
86 83
87 } // namespace media 84 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698