| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/logging.h" | 5 #include "base/logging.h" |
| 6 #include "media/base/data_buffer.h" | 6 #include "media/base/data_buffer.h" |
| 7 | 7 |
| 8 namespace media { | 8 namespace media { |
| 9 | 9 |
| 10 DataBuffer::DataBuffer(uint8* buffer, size_t buffer_size) | 10 DataBuffer::DataBuffer(uint8* buffer, size_t buffer_size) |
| 11 : data_(buffer), | 11 : data_(buffer), |
| 12 buffer_size_(buffer_size), | 12 buffer_size_(buffer_size), |
| 13 data_size_(buffer_size) { | 13 data_size_(buffer_size) { |
| 14 } | 14 } |
| 15 | 15 |
| 16 DataBuffer::DataBuffer(uint8* buffer, size_t buffer_size, bool copy) |
| 17 : buffer_size_(buffer_size), |
| 18 data_size_(buffer_size) { |
| 19 if (copy) { |
| 20 data_.reset(new uint8[buffer_size]); |
| 21 memcpy(data_.get(), buffer, buffer_size); |
| 22 } else { |
| 23 data_.reset(buffer); |
| 24 } |
| 25 } |
| 26 |
| 16 DataBuffer::DataBuffer(size_t buffer_size) | 27 DataBuffer::DataBuffer(size_t buffer_size) |
| 17 : data_(new uint8[buffer_size]), | 28 : data_(new uint8[buffer_size]), |
| 18 buffer_size_(buffer_size), | 29 buffer_size_(buffer_size), |
| 19 data_size_(0) { | 30 data_size_(0) { |
| 20 CHECK(data_.get()) << "DataBuffer ctor failed to allocate memory"; | 31 CHECK(data_.get()) << "DataBuffer ctor failed to allocate memory"; |
| 21 | 32 |
| 22 // Prevent arbitrary pointers. | 33 // Prevent arbitrary pointers. |
| 23 if (buffer_size == 0) | 34 if (buffer_size == 0) |
| 24 data_.reset(NULL); | 35 data_.reset(NULL); |
| 25 } | 36 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 43 void DataBuffer::SetDataSize(size_t data_size) { | 54 void DataBuffer::SetDataSize(size_t data_size) { |
| 44 DCHECK_LE(data_size, buffer_size_); | 55 DCHECK_LE(data_size, buffer_size_); |
| 45 data_size_ = data_size; | 56 data_size_ = data_size; |
| 46 } | 57 } |
| 47 | 58 |
| 48 size_t DataBuffer::GetBufferSize() const { | 59 size_t DataBuffer::GetBufferSize() const { |
| 49 return buffer_size_; | 60 return buffer_size_; |
| 50 } | 61 } |
| 51 | 62 |
| 52 } // namespace media | 63 } // namespace media |
| OLD | NEW |