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

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: s/2011/2012/ Created 8 years, 6 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/data_buffer.h ('k') | media/base/decoder_buffer.h » ('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 "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 memcpy(data_.get(), data, data_size_);
39
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 } 30 }
52 31
53 DataBuffer::~DataBuffer() {} 32 DataBuffer::~DataBuffer() {}
54 33
34 void DataBuffer::Initialize() {
35 // Prevent arbitrary pointers.
36 if (buffer_size_ <= 0) {
37 buffer_size_ = data_size_ = 0;
38 data_.reset();
39 return;
40 }
41
42 data_.reset(new uint8[buffer_size_]);
43 }
44
55 scoped_refptr<DataBuffer> DataBuffer::CopyFrom(const uint8* data, 45 scoped_refptr<DataBuffer> DataBuffer::CopyFrom(const uint8* data,
56 int data_size) { 46 int data_size) {
57 return make_scoped_refptr(new DataBuffer(data, data_size)); 47 return make_scoped_refptr(new DataBuffer(data, data_size));
58 } 48 }
59 49
60 const uint8* DataBuffer::GetData() const { 50 const uint8* DataBuffer::GetData() const {
61 return data_.get(); 51 return data_.get();
62 } 52 }
63 53
64 int DataBuffer::GetDataSize() const { 54 int DataBuffer::GetDataSize() const {
65 return data_size_; 55 return data_size_;
66 } 56 }
67 57
68 const DecryptConfig* DataBuffer::GetDecryptConfig() const {
69 return decrypt_config_.get();
70 }
71
72 uint8* DataBuffer::GetWritableData() { 58 uint8* DataBuffer::GetWritableData() {
73 return data_.get(); 59 return data_.get();
74 } 60 }
75 61
76 void DataBuffer::SetDataSize(int data_size) { 62 void DataBuffer::SetDataSize(int data_size) {
77 DCHECK_LE(data_size, buffer_size_); 63 DCHECK_LE(data_size, buffer_size_);
78 data_size_ = data_size; 64 data_size_ = data_size;
79 } 65 }
80 66
81 int DataBuffer::GetBufferSize() const { 67 int DataBuffer::GetBufferSize() const {
82 return buffer_size_; 68 return buffer_size_;
83 } 69 }
84 70
85 void DataBuffer::SetDecryptConfig(scoped_ptr<DecryptConfig> decrypt_config) {
86 decrypt_config_ = decrypt_config.Pass();
87 }
88
89 } // namespace media 71 } // namespace media
OLDNEW
« no previous file with comments | « media/base/data_buffer.h ('k') | media/base/decoder_buffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698