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

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

Issue 12263013: media: Add support for playback of VP8 Alpha video streams (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 8 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
10 namespace media { 10 namespace media {
11 11
12 DecoderBuffer::DecoderBuffer(int size) 12 DecoderBuffer::DecoderBuffer(int size)
13 : size_(size) { 13 : size_(size),
14 side_data_size_(0) {
14 Initialize(); 15 Initialize();
15 } 16 }
16 17
17 DecoderBuffer::DecoderBuffer(const uint8* data, int size) 18 DecoderBuffer::DecoderBuffer(const uint8* data, int size)
18 : size_(size) { 19 : size_(size),
20 side_data_size_(0) {
19 if (!data) { 21 if (!data) {
20 CHECK_EQ(size_, 0); 22 CHECK_EQ(size_, 0);
21 return; 23 return;
22 } 24 }
23 25
24 Initialize(); 26 Initialize();
25 memcpy(data_.get(), data, size_); 27 memcpy(data_.get(), data, size_);
26 } 28 }
27 29
30 DecoderBuffer::DecoderBuffer(const uint8* data, int size,
31 const uint8* side_data, int side_data_size)
32 : size_(size),
33 side_data_size_(side_data_size) {
34 if (!data) {
35 CHECK_EQ(size_, 0);
36 return;
37 }
38
39 Initialize();
40 memcpy(data_.get(), data, size_);
41 memcpy(side_data_.get(), side_data, side_data_size_);
42 }
43
28 DecoderBuffer::~DecoderBuffer() {} 44 DecoderBuffer::~DecoderBuffer() {}
29 45
30 void DecoderBuffer::Initialize() { 46 void DecoderBuffer::Initialize() {
31 CHECK_GE(size_, 0); 47 CHECK_GE(size_, 0);
32 data_.reset(reinterpret_cast<uint8*>( 48 data_.reset(reinterpret_cast<uint8*>(
33 base::AlignedAlloc(size_ + kPaddingSize, kAlignmentSize))); 49 base::AlignedAlloc(size_ + kPaddingSize, kAlignmentSize)));
34 memset(data_.get() + size_, 0, kPaddingSize); 50 memset(data_.get() + size_, 0, kPaddingSize);
51 if (side_data_size_ > 0) {
52 side_data_.reset(reinterpret_cast<uint8*>(
53 base::AlignedAlloc(side_data_size_ + kPaddingSize, kAlignmentSize)));
54 memset(side_data_.get() + side_data_size_, 0, kPaddingSize);
55 }
35 } 56 }
36 57
37 // static 58 // static
38 scoped_refptr<DecoderBuffer> DecoderBuffer::CopyFrom(const uint8* data, 59 scoped_refptr<DecoderBuffer> DecoderBuffer::CopyFrom(const uint8* data,
39 int data_size) { 60 int data_size) {
40 // If you hit this CHECK you likely have a bug in a demuxer. Go fix it. 61 // If you hit this CHECK you likely have a bug in a demuxer. Go fix it.
41 CHECK(data); 62 CHECK(data);
42 return make_scoped_refptr(new DecoderBuffer(data, data_size)); 63 return make_scoped_refptr(new DecoderBuffer(data, data_size));
43 } 64 }
44 65
45 // static 66 // static
67 scoped_refptr<DecoderBuffer> DecoderBuffer::CopyFrom(const uint8* data,
68 int data_size,
69 const uint8* side_data,
70 int side_data_size) {
71 // If you hit this CHECK you likely have a bug in a demuxer. Go fix it.
72 CHECK(data);
73 CHECK(side_data);
74 return make_scoped_refptr(new DecoderBuffer(data, data_size,
75 side_data, side_data_size));
76 }
77
78 // static
46 scoped_refptr<DecoderBuffer> DecoderBuffer::CreateEOSBuffer() { 79 scoped_refptr<DecoderBuffer> DecoderBuffer::CreateEOSBuffer() {
47 return make_scoped_refptr(new DecoderBuffer(NULL, 0)); 80 return make_scoped_refptr(new DecoderBuffer(NULL, 0));
48 } 81 }
49 82
50 base::TimeDelta DecoderBuffer::GetTimestamp() const { 83 base::TimeDelta DecoderBuffer::GetTimestamp() const {
51 DCHECK(!IsEndOfStream()); 84 DCHECK(!IsEndOfStream());
52 return timestamp_; 85 return timestamp_;
53 } 86 }
54 87
55 void DecoderBuffer::SetTimestamp(const base::TimeDelta& timestamp) { 88 void DecoderBuffer::SetTimestamp(const base::TimeDelta& timestamp) {
(...skipping 19 matching lines...) Expand all
75 uint8* DecoderBuffer::GetWritableData() const { 108 uint8* DecoderBuffer::GetWritableData() const {
76 DCHECK(!IsEndOfStream()); 109 DCHECK(!IsEndOfStream());
77 return data_.get(); 110 return data_.get();
78 } 111 }
79 112
80 int DecoderBuffer::GetDataSize() const { 113 int DecoderBuffer::GetDataSize() const {
81 DCHECK(!IsEndOfStream()); 114 DCHECK(!IsEndOfStream());
82 return size_; 115 return size_;
83 } 116 }
84 117
118 const uint8* DecoderBuffer::GetSideData() const {
119 DCHECK(!IsEndOfStream());
120 return side_data_.get();
121 }
122
123 int DecoderBuffer::GetSideDataSize() const {
124 DCHECK(!IsEndOfStream());
125 return side_data_size_;
126 }
127
85 const DecryptConfig* DecoderBuffer::GetDecryptConfig() const { 128 const DecryptConfig* DecoderBuffer::GetDecryptConfig() const {
86 DCHECK(!IsEndOfStream()); 129 DCHECK(!IsEndOfStream());
87 return decrypt_config_.get(); 130 return decrypt_config_.get();
88 } 131 }
89 132
90 void DecoderBuffer::SetDecryptConfig(scoped_ptr<DecryptConfig> decrypt_config) { 133 void DecoderBuffer::SetDecryptConfig(scoped_ptr<DecryptConfig> decrypt_config) {
91 DCHECK(!IsEndOfStream()); 134 DCHECK(!IsEndOfStream());
92 decrypt_config_ = decrypt_config.Pass(); 135 decrypt_config_ = decrypt_config.Pass();
93 } 136 }
94 137
95 bool DecoderBuffer::IsEndOfStream() const { 138 bool DecoderBuffer::IsEndOfStream() const {
96 return data_ == NULL; 139 return data_ == NULL;
97 } 140 }
98 141
99 std::string DecoderBuffer::AsHumanReadableString() { 142 std::string DecoderBuffer::AsHumanReadableString() {
100 if (IsEndOfStream()) { 143 if (IsEndOfStream()) {
101 return "end of stream"; 144 return "end of stream";
102 } 145 }
103 146
104 std::ostringstream s; 147 std::ostringstream s;
105 s << "timestamp: " << timestamp_.InMicroseconds() 148 s << "timestamp: " << timestamp_.InMicroseconds()
106 << " duration: " << duration_.InMicroseconds() 149 << " duration: " << duration_.InMicroseconds()
107 << " size: " << size_ 150 << " size: " << size_
151 << " side_data_size: " << side_data_size_
108 << " encrypted: " << (decrypt_config_ != NULL); 152 << " encrypted: " << (decrypt_config_ != NULL);
109 return s.str(); 153 return s.str();
110 } 154 }
111 155
112 } // namespace media 156 } // 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