OLD | NEW |
---|---|
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 |
28 DecoderBuffer::~DecoderBuffer() {} | 30 DecoderBuffer::~DecoderBuffer() {} |
29 | 31 |
30 void DecoderBuffer::Initialize() { | 32 void DecoderBuffer::Initialize() { |
31 CHECK_GE(size_, 0); | 33 CHECK_GE(size_, 0); |
32 data_.reset(reinterpret_cast<uint8*>( | 34 data_.reset(reinterpret_cast<uint8*>( |
33 base::AlignedAlloc(size_ + kPaddingSize, kAlignmentSize))); | 35 base::AlignedAlloc(size_ + kPaddingSize, kAlignmentSize))); |
34 memset(data_.get() + size_, 0, kPaddingSize); | 36 memset(data_.get() + size_, 0, kPaddingSize); |
37 side_data_size_ = 0; | |
35 } | 38 } |
36 | 39 |
37 // static | 40 // static |
38 scoped_refptr<DecoderBuffer> DecoderBuffer::CopyFrom(const uint8* data, | 41 scoped_refptr<DecoderBuffer> DecoderBuffer::CopyFrom(const uint8* data, |
39 int data_size) { | 42 int data_size) { |
40 // If you hit this CHECK you likely have a bug in a demuxer. Go fix it. | 43 // If you hit this CHECK you likely have a bug in a demuxer. Go fix it. |
41 CHECK(data); | 44 CHECK(data); |
42 return make_scoped_refptr(new DecoderBuffer(data, data_size)); | 45 return make_scoped_refptr(new DecoderBuffer(data, data_size)); |
43 } | 46 } |
44 | 47 |
48 void DecoderBuffer::SetSideData(const uint8* side_data, int side_data_size) { | |
49 DCHECK(side_data); | |
50 DCHECK_GE(side_data_size_, 0); | |
51 side_data_size_ = side_data_size; | |
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 memcpy(side_data_.get(), side_data, side_data_size_); | |
56 } | |
57 | |
45 // static | 58 // static |
46 scoped_refptr<DecoderBuffer> DecoderBuffer::CreateEOSBuffer() { | 59 scoped_refptr<DecoderBuffer> DecoderBuffer::CreateEOSBuffer() { |
47 return make_scoped_refptr(new DecoderBuffer(NULL, 0)); | 60 return make_scoped_refptr(new DecoderBuffer(NULL, 0)); |
48 } | 61 } |
49 | 62 |
50 base::TimeDelta DecoderBuffer::GetTimestamp() const { | 63 base::TimeDelta DecoderBuffer::GetTimestamp() const { |
51 DCHECK(!IsEndOfStream()); | 64 DCHECK(!IsEndOfStream()); |
52 return timestamp_; | 65 return timestamp_; |
53 } | 66 } |
54 | 67 |
(...skipping 20 matching lines...) Expand all Loading... | |
75 uint8* DecoderBuffer::GetWritableData() const { | 88 uint8* DecoderBuffer::GetWritableData() const { |
76 DCHECK(!IsEndOfStream()); | 89 DCHECK(!IsEndOfStream()); |
77 return data_.get(); | 90 return data_.get(); |
78 } | 91 } |
79 | 92 |
80 int DecoderBuffer::GetDataSize() const { | 93 int DecoderBuffer::GetDataSize() const { |
81 DCHECK(!IsEndOfStream()); | 94 DCHECK(!IsEndOfStream()); |
82 return size_; | 95 return size_; |
83 } | 96 } |
84 | 97 |
98 const uint8* DecoderBuffer::GetSideData() const { | |
99 return side_data_.get(); | |
scherkus (not reviewing)
2013/02/22 23:18:01
add DCHECK(!IsEndOfStream());
vignesh
2013/02/25 21:51:42
Done.
| |
100 } | |
101 | |
102 int DecoderBuffer::GetSideDataSize() const { | |
103 return side_data_size_; | |
scherkus (not reviewing)
2013/02/22 23:18:01
add DCHECK(!IsEndOfStream());
vignesh
2013/02/25 21:51:42
Done.
| |
104 } | |
105 | |
85 const DecryptConfig* DecoderBuffer::GetDecryptConfig() const { | 106 const DecryptConfig* DecoderBuffer::GetDecryptConfig() const { |
86 DCHECK(!IsEndOfStream()); | 107 DCHECK(!IsEndOfStream()); |
87 return decrypt_config_.get(); | 108 return decrypt_config_.get(); |
88 } | 109 } |
89 | 110 |
90 void DecoderBuffer::SetDecryptConfig(scoped_ptr<DecryptConfig> decrypt_config) { | 111 void DecoderBuffer::SetDecryptConfig(scoped_ptr<DecryptConfig> decrypt_config) { |
91 DCHECK(!IsEndOfStream()); | 112 DCHECK(!IsEndOfStream()); |
92 decrypt_config_ = decrypt_config.Pass(); | 113 decrypt_config_ = decrypt_config.Pass(); |
93 } | 114 } |
94 | 115 |
95 bool DecoderBuffer::IsEndOfStream() const { | 116 bool DecoderBuffer::IsEndOfStream() const { |
96 return data_ == NULL; | 117 return data_ == NULL; |
97 } | 118 } |
98 | 119 |
99 std::string DecoderBuffer::AsHumanReadableString() { | 120 std::string DecoderBuffer::AsHumanReadableString() { |
100 if (IsEndOfStream()) { | 121 if (IsEndOfStream()) { |
101 return "end of stream"; | 122 return "end of stream"; |
102 } | 123 } |
103 | 124 |
104 std::ostringstream s; | 125 std::ostringstream s; |
105 s << "timestamp: " << timestamp_.InMicroseconds() | 126 s << "timestamp: " << timestamp_.InMicroseconds() |
106 << " duration: " << duration_.InMicroseconds() | 127 << " duration: " << duration_.InMicroseconds() |
107 << " size: " << size_ | 128 << " size: " << size_ |
108 << " encrypted: " << (decrypt_config_ != NULL); | 129 << " encrypted: " << (decrypt_config_ != NULL); |
109 return s.str(); | 130 return s.str(); |
110 } | 131 } |
111 | 132 |
112 } // namespace media | 133 } // namespace media |
OLD | NEW |