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