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

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

Issue 10447035: Introducing DecoderBuffer and general Buffer cleanup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Buffer Bonanza! Created 8 years, 7 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 "base/logging.h" 5 #include "base/logging.h"
6 #include "media/base/data_buffer.h" 6 #include "media/base/data_buffer.h"
7 #include "media/base/decrypt_config.h"
8 #if !defined(OS_ANDROID)
9 #include "media/ffmpeg/ffmpeg_common.h"
10 #endif
11 7
12 namespace media { 8 namespace media {
13 9
14 DataBuffer::DataBuffer(scoped_array<uint8> buffer, int buffer_size) 10 DataBuffer::DataBuffer(scoped_array<uint8> buffer, int buffer_size)
15 : Buffer(base::TimeDelta(), base::TimeDelta()), 11 : Buffer(base::TimeDelta(), base::TimeDelta()),
16 data_(buffer.Pass()), 12 data_(buffer.Pass()),
17 buffer_size_(buffer_size), 13 buffer_size_(buffer_size),
18 data_size_(buffer_size) { 14 data_size_(buffer_size) {
19 } 15 }
20 16
21 DataBuffer::DataBuffer(int buffer_size) 17 DataBuffer::DataBuffer(int buffer_size)
22 : Buffer(base::TimeDelta(), base::TimeDelta()), 18 : Buffer(base::TimeDelta(), base::TimeDelta()),
23 data_(new uint8[buffer_size]),
24 buffer_size_(buffer_size), 19 buffer_size_(buffer_size),
25 data_size_(0) { 20 data_size_(0) {
26 CHECK(data_.get()) << "DataBuffer ctor failed to allocate memory"; 21 Initialize();
27
28 // Prevent arbitrary pointers.
29 if (buffer_size == 0)
30 data_.reset(NULL);
31 } 22 }
32 23
33 DataBuffer::DataBuffer(const uint8* data, int data_size) 24 DataBuffer::DataBuffer(const uint8* data, int data_size)
34 : Buffer(base::TimeDelta(), base::TimeDelta()), 25 : Buffer(base::TimeDelta(), base::TimeDelta()),
35 buffer_size_(0), 26 buffer_size_(data_size),
36 data_size_(0) { 27 data_size_(data_size) {
37 if (data_size == 0) 28 Initialize();
38 return; 29 // If Initialize fails data_size_ == 0 and this becomes a no-op.
scherkus (not reviewing) 2012/05/26 01:36:32 comment not needed -- it's impossible for Initiali
DaleCurtis 2012/05/29 21:17:01 Done.
39 30 memcpy(data_.get(), data, data_size_);
40 int padding_size = 0;
41 #if !defined(OS_ANDROID)
42 // FFmpeg assumes all input buffers are padded with this value.
43 padding_size = FF_INPUT_BUFFER_PADDING_SIZE;
44 #endif
45
46 buffer_size_ = data_size + padding_size;
47 data_.reset(new uint8[buffer_size_]);
48 memcpy(data_.get(), data, data_size);
49 memset(data_.get() + data_size, 0, padding_size);
50 SetDataSize(data_size);
51 } 31 }
52 32
53 DataBuffer::~DataBuffer() {} 33 DataBuffer::~DataBuffer() {}
54 34
35 void DataBuffer::Initialize() {
36 // Prevent arbitrary pointers.
37 if (buffer_size_ <= 0) {
38 buffer_size_ = data_size_ = 0;
39 data_.reset(NULL);
scherkus (not reviewing) 2012/05/26 01:36:32 s/NULL//
DaleCurtis 2012/05/29 21:17:01 Done.
40 return;
41 }
42
43 data_.reset(new uint8[buffer_size_]);
44 CHECK(data_.get()) << "DataBuffer ctor failed to allocate memory";
scherkus (not reviewing) 2012/05/26 01:36:32 I noticed you moved this CHECK around but in fact
DaleCurtis 2012/05/29 21:17:01 Done.
45 }
46
55 scoped_refptr<DataBuffer> DataBuffer::CopyFrom(const uint8* data, 47 scoped_refptr<DataBuffer> DataBuffer::CopyFrom(const uint8* data,
56 int data_size) { 48 int data_size) {
57 return make_scoped_refptr(new DataBuffer(data, data_size)); 49 return make_scoped_refptr(new DataBuffer(data, data_size));
58 } 50 }
59 51
60 const uint8* DataBuffer::GetData() const { 52 const uint8* DataBuffer::GetData() const {
61 return data_.get(); 53 return data_.get();
62 } 54 }
63 55
64 int DataBuffer::GetDataSize() const { 56 int DataBuffer::GetDataSize() const {
65 return data_size_; 57 return data_size_;
66 } 58 }
67 59
68 const DecryptConfig* DataBuffer::GetDecryptConfig() const {
69 return decrypt_config_.get();
70 }
71
72 uint8* DataBuffer::GetWritableData() { 60 uint8* DataBuffer::GetWritableData() {
73 return data_.get(); 61 return data_.get();
74 } 62 }
75 63
76 void DataBuffer::SetDataSize(int data_size) { 64 void DataBuffer::SetDataSize(int data_size) {
77 DCHECK_LE(data_size, buffer_size_); 65 DCHECK_LE(data_size, buffer_size_);
78 data_size_ = data_size; 66 data_size_ = data_size;
79 } 67 }
80 68
81 int DataBuffer::GetBufferSize() const { 69 int DataBuffer::GetBufferSize() const {
82 return buffer_size_; 70 return buffer_size_;
83 } 71 }
84 72
85 void DataBuffer::SetDecryptConfig(scoped_ptr<DecryptConfig> decrypt_config) {
86 decrypt_config_ = decrypt_config.Pass();
87 }
88
89 } // namespace media 73 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698