| 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 { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 base::AlignedAlloc(size_ + kPaddingSize, kAlignmentSize))); | 39 base::AlignedAlloc(size_ + kPaddingSize, kAlignmentSize))); |
| 40 memset(data_.get() + size_, 0, kPaddingSize); | 40 memset(data_.get() + size_, 0, kPaddingSize); |
| 41 if (side_data_size_ > 0) { | 41 if (side_data_size_ > 0) { |
| 42 side_data_.reset(reinterpret_cast<uint8*>( | 42 side_data_.reset(reinterpret_cast<uint8*>( |
| 43 base::AlignedAlloc(side_data_size_ + kPaddingSize, kAlignmentSize))); | 43 base::AlignedAlloc(side_data_size_ + kPaddingSize, kAlignmentSize))); |
| 44 memset(side_data_.get() + side_data_size_, 0, kPaddingSize); | 44 memset(side_data_.get() + side_data_size_, 0, kPaddingSize); |
| 45 } | 45 } |
| 46 } | 46 } |
| 47 | 47 |
| 48 // static | 48 // static |
| 49 scoped_refptr<DecoderBuffer> DecoderBuffer::CopyFrom(const uint8* data, | 49 scoped_refptr<DecoderBuffer> DecoderBuffer::copy_from(const uint8* data, |
| 50 int data_size) { | 50 int data_size) { |
| 51 // If you hit this CHECK you likely have a bug in a demuxer. Go fix it. | 51 // If you hit this CHECK you likely have a bug in a demuxer. Go fix it. |
| 52 CHECK(data); | 52 CHECK(data); |
| 53 return make_scoped_refptr(new DecoderBuffer(data, data_size, NULL, 0)); | 53 return make_scoped_refptr(new DecoderBuffer(data, data_size, NULL, 0)); |
| 54 } | 54 } |
| 55 | 55 |
| 56 // static | 56 // static |
| 57 scoped_refptr<DecoderBuffer> DecoderBuffer::CopyFrom(const uint8* data, | 57 scoped_refptr<DecoderBuffer> DecoderBuffer::copy_from(const uint8* data, |
| 58 int data_size, | 58 int data_size, |
| 59 const uint8* side_data, | 59 const uint8* side_data, |
| 60 int side_data_size) { | 60 int side_data_size) { |
| 61 // 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. |
| 62 CHECK(data); | 62 CHECK(data); |
| 63 CHECK(side_data); | 63 CHECK(side_data); |
| 64 return make_scoped_refptr(new DecoderBuffer(data, data_size, | 64 return make_scoped_refptr(new DecoderBuffer(data, data_size, |
| 65 side_data, side_data_size)); | 65 side_data, side_data_size)); |
| 66 } | 66 } |
| 67 | 67 |
| 68 // static | 68 // static |
| 69 scoped_refptr<DecoderBuffer> DecoderBuffer::CreateEOSBuffer() { | 69 scoped_refptr<DecoderBuffer> DecoderBuffer::create_eos_buffer() { |
| 70 return make_scoped_refptr(new DecoderBuffer(NULL, 0, NULL, 0)); | 70 return make_scoped_refptr(new DecoderBuffer(NULL, 0, NULL, 0)); |
| 71 } | 71 } |
| 72 | 72 |
| 73 base::TimeDelta DecoderBuffer::GetTimestamp() const { | 73 base::TimeDelta DecoderBuffer::get_timestamp() const { |
| 74 DCHECK(!IsEndOfStream()); | 74 DCHECK(!is_end_of_stream()); |
| 75 return timestamp_; | 75 return timestamp_; |
| 76 } | 76 } |
| 77 | 77 |
| 78 void DecoderBuffer::SetTimestamp(const base::TimeDelta& timestamp) { | 78 void DecoderBuffer::set_timestamp(const base::TimeDelta& timestamp) { |
| 79 DCHECK(!IsEndOfStream()); | 79 DCHECK(!is_end_of_stream()); |
| 80 timestamp_ = timestamp; | 80 timestamp_ = timestamp; |
| 81 } | 81 } |
| 82 | 82 |
| 83 base::TimeDelta DecoderBuffer::GetDuration() const { | 83 base::TimeDelta DecoderBuffer::get_duration() const { |
| 84 DCHECK(!IsEndOfStream()); | 84 DCHECK(!is_end_of_stream()); |
| 85 return duration_; | 85 return duration_; |
| 86 } | 86 } |
| 87 | 87 |
| 88 void DecoderBuffer::SetDuration(const base::TimeDelta& duration) { | 88 void DecoderBuffer::set_duration(const base::TimeDelta& duration) { |
| 89 DCHECK(!IsEndOfStream()); | 89 DCHECK(!is_end_of_stream()); |
| 90 duration_ = duration; | 90 duration_ = duration; |
| 91 } | 91 } |
| 92 | 92 |
| 93 const uint8* DecoderBuffer::GetData() const { | 93 const uint8* DecoderBuffer::get_data() const { |
| 94 DCHECK(!IsEndOfStream()); | 94 DCHECK(!is_end_of_stream()); |
| 95 return data_.get(); | 95 return data_.get(); |
| 96 } | 96 } |
| 97 | 97 |
| 98 uint8* DecoderBuffer::GetWritableData() const { | 98 uint8* DecoderBuffer::get_writable_data() const { |
| 99 DCHECK(!IsEndOfStream()); | 99 DCHECK(!is_end_of_stream()); |
| 100 return data_.get(); | 100 return data_.get(); |
| 101 } | 101 } |
| 102 | 102 |
| 103 int DecoderBuffer::GetDataSize() const { | 103 int DecoderBuffer::get_data_size() const { |
| 104 DCHECK(!IsEndOfStream()); | 104 DCHECK(!is_end_of_stream()); |
| 105 return size_; | 105 return size_; |
| 106 } | 106 } |
| 107 | 107 |
| 108 const uint8* DecoderBuffer::GetSideData() const { | 108 const uint8* DecoderBuffer::get_side_data() const { |
| 109 DCHECK(!IsEndOfStream()); | 109 DCHECK(!is_end_of_stream()); |
| 110 return side_data_.get(); | 110 return side_data_.get(); |
| 111 } | 111 } |
| 112 | 112 |
| 113 int DecoderBuffer::GetSideDataSize() const { | 113 int DecoderBuffer::get_side_data_size() const { |
| 114 DCHECK(!IsEndOfStream()); | 114 DCHECK(!is_end_of_stream()); |
| 115 return side_data_size_; | 115 return side_data_size_; |
| 116 } | 116 } |
| 117 | 117 |
| 118 const DecryptConfig* DecoderBuffer::GetDecryptConfig() const { | 118 const DecryptConfig* DecoderBuffer::get_decrypt_config() const { |
| 119 DCHECK(!IsEndOfStream()); | 119 DCHECK(!is_end_of_stream()); |
| 120 return decrypt_config_.get(); | 120 return decrypt_config_.get(); |
| 121 } | 121 } |
| 122 | 122 |
| 123 void DecoderBuffer::SetDecryptConfig(scoped_ptr<DecryptConfig> decrypt_config) { | 123 void DecoderBuffer::SetDecryptConfig(scoped_ptr<DecryptConfig> decrypt_config) { |
| 124 DCHECK(!IsEndOfStream()); | 124 DCHECK(!is_end_of_stream()); |
| 125 decrypt_config_ = decrypt_config.Pass(); | 125 decrypt_config_ = decrypt_config.Pass(); |
| 126 } | 126 } |
| 127 | 127 |
| 128 bool DecoderBuffer::IsEndOfStream() const { | 128 bool DecoderBuffer::is_end_of_stream() const { |
| 129 return data_ == NULL; | 129 return data_ == NULL; |
| 130 } | 130 } |
| 131 | 131 |
| 132 std::string DecoderBuffer::AsHumanReadableString() { | 132 std::string DecoderBuffer::as_human_readable_string() { |
| 133 if (IsEndOfStream()) { | 133 if (is_end_of_stream()) { |
| 134 return "end of stream"; | 134 return "end of stream"; |
| 135 } | 135 } |
| 136 | 136 |
| 137 std::ostringstream s; | 137 std::ostringstream s; |
| 138 s << "timestamp: " << timestamp_.InMicroseconds() | 138 s << "timestamp: " << timestamp_.InMicroseconds() |
| 139 << " duration: " << duration_.InMicroseconds() | 139 << " duration: " << duration_.InMicroseconds() |
| 140 << " size: " << size_ | 140 << " size: " << size_ |
| 141 << " side_data_size: " << side_data_size_ | 141 << " side_data_size: " << side_data_size_ |
| 142 << " encrypted: " << (decrypt_config_ != NULL); | 142 << " encrypted: " << (decrypt_config_ != NULL); |
| 143 return s.str(); | 143 return s.str(); |
| 144 } | 144 } |
| 145 | 145 |
| 146 } // namespace media | 146 } // namespace media |
| OLD | NEW |