| 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 side_data_size_(0) { |
| 15 Initialize(); | 15 Initialize(); |
| 16 } | 16 } |
| 17 | 17 |
| 18 DecoderBuffer::DecoderBuffer(const uint8* data, int size) | |
| 19 : size_(size), | |
| 20 side_data_size_(0) { | |
| 21 if (!data) { | |
| 22 CHECK_EQ(size_, 0); | |
| 23 return; | |
| 24 } | |
| 25 | |
| 26 Initialize(); | |
| 27 memcpy(data_.get(), data, size_); | |
| 28 } | |
| 29 | |
| 30 DecoderBuffer::DecoderBuffer(const uint8* data, int size, | 18 DecoderBuffer::DecoderBuffer(const uint8* data, int size, |
| 31 const uint8* side_data, int side_data_size) | 19 const uint8* side_data, int side_data_size) |
| 32 : size_(size), | 20 : size_(size), |
| 33 side_data_size_(side_data_size) { | 21 side_data_size_(side_data_size) { |
| 34 if (!data) { | 22 if (!data) { |
| 35 CHECK_EQ(size_, 0); | 23 CHECK_EQ(size_, 0); |
| 24 CHECK(!side_data); |
| 36 return; | 25 return; |
| 37 } | 26 } |
| 38 | 27 |
| 39 Initialize(); | 28 Initialize(); |
| 40 memcpy(data_.get(), data, size_); | 29 memcpy(data_.get(), data, size_); |
| 41 memcpy(side_data_.get(), side_data, side_data_size_); | 30 if (side_data) |
| 31 memcpy(side_data_.get(), side_data, side_data_size_); |
| 42 } | 32 } |
| 43 | 33 |
| 44 DecoderBuffer::~DecoderBuffer() {} | 34 DecoderBuffer::~DecoderBuffer() {} |
| 45 | 35 |
| 46 void DecoderBuffer::Initialize() { | 36 void DecoderBuffer::Initialize() { |
| 47 CHECK_GE(size_, 0); | 37 CHECK_GE(size_, 0); |
| 48 data_.reset(reinterpret_cast<uint8*>( | 38 data_.reset(reinterpret_cast<uint8*>( |
| 49 base::AlignedAlloc(size_ + kPaddingSize, kAlignmentSize))); | 39 base::AlignedAlloc(size_ + kPaddingSize, kAlignmentSize))); |
| 50 memset(data_.get() + size_, 0, kPaddingSize); | 40 memset(data_.get() + size_, 0, kPaddingSize); |
| 51 if (side_data_size_ > 0) { | 41 if (side_data_size_ > 0) { |
| 52 side_data_.reset(reinterpret_cast<uint8*>( | 42 side_data_.reset(reinterpret_cast<uint8*>( |
| 53 base::AlignedAlloc(side_data_size_ + kPaddingSize, kAlignmentSize))); | 43 base::AlignedAlloc(side_data_size_ + kPaddingSize, kAlignmentSize))); |
| 54 memset(side_data_.get() + side_data_size_, 0, kPaddingSize); | 44 memset(side_data_.get() + side_data_size_, 0, kPaddingSize); |
| 55 } | 45 } |
| 56 } | 46 } |
| 57 | 47 |
| 58 // static | 48 // static |
| 59 scoped_refptr<DecoderBuffer> DecoderBuffer::CopyFrom(const uint8* data, | 49 scoped_refptr<DecoderBuffer> DecoderBuffer::CopyFrom(const uint8* data, |
| 60 int data_size) { | 50 int data_size) { |
| 61 // 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. |
| 62 CHECK(data); | 52 CHECK(data); |
| 63 return make_scoped_refptr(new DecoderBuffer(data, data_size)); | 53 return make_scoped_refptr(new DecoderBuffer(data, data_size, NULL, 0)); |
| 64 } | 54 } |
| 65 | 55 |
| 66 // static | 56 // static |
| 67 scoped_refptr<DecoderBuffer> DecoderBuffer::CopyFrom(const uint8* data, | 57 scoped_refptr<DecoderBuffer> DecoderBuffer::CopyFrom(const uint8* data, |
| 68 int data_size, | 58 int data_size, |
| 69 const uint8* side_data, | 59 const uint8* side_data, |
| 70 int side_data_size) { | 60 int side_data_size) { |
| 71 // 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. |
| 72 CHECK(data); | 62 CHECK(data); |
| 73 CHECK(side_data); | 63 CHECK(side_data); |
| 74 return make_scoped_refptr(new DecoderBuffer(data, data_size, | 64 return make_scoped_refptr(new DecoderBuffer(data, data_size, |
| 75 side_data, side_data_size)); | 65 side_data, side_data_size)); |
| 76 } | 66 } |
| 77 | 67 |
| 78 // static | 68 // static |
| 79 scoped_refptr<DecoderBuffer> DecoderBuffer::CreateEOSBuffer() { | 69 scoped_refptr<DecoderBuffer> DecoderBuffer::CreateEOSBuffer() { |
| 80 return make_scoped_refptr(new DecoderBuffer(NULL, 0)); | 70 return make_scoped_refptr(new DecoderBuffer(NULL, 0, NULL, 0)); |
| 81 } | 71 } |
| 82 | 72 |
| 83 base::TimeDelta DecoderBuffer::GetTimestamp() const { | 73 base::TimeDelta DecoderBuffer::GetTimestamp() const { |
| 84 DCHECK(!IsEndOfStream()); | 74 DCHECK(!IsEndOfStream()); |
| 85 return timestamp_; | 75 return timestamp_; |
| 86 } | 76 } |
| 87 | 77 |
| 88 void DecoderBuffer::SetTimestamp(const base::TimeDelta& timestamp) { | 78 void DecoderBuffer::SetTimestamp(const base::TimeDelta& timestamp) { |
| 89 DCHECK(!IsEndOfStream()); | 79 DCHECK(!IsEndOfStream()); |
| 90 timestamp_ = timestamp; | 80 timestamp_ = timestamp; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 std::ostringstream s; | 137 std::ostringstream s; |
| 148 s << "timestamp: " << timestamp_.InMicroseconds() | 138 s << "timestamp: " << timestamp_.InMicroseconds() |
| 149 << " duration: " << duration_.InMicroseconds() | 139 << " duration: " << duration_.InMicroseconds() |
| 150 << " size: " << size_ | 140 << " size: " << size_ |
| 151 << " side_data_size: " << side_data_size_ | 141 << " side_data_size: " << side_data_size_ |
| 152 << " encrypted: " << (decrypt_config_ != NULL); | 142 << " encrypted: " << (decrypt_config_ != NULL); |
| 153 return s.str(); | 143 return s.str(); |
| 154 } | 144 } |
| 155 | 145 |
| 156 } // namespace media | 146 } // namespace media |
| OLD | NEW |