| OLD | NEW |
| 1 // Copyright (c) 2008-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008-2009 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(char* data, size_t buffer_size, size_t data_size, | 10 DataBuffer::DataBuffer() |
| 11 const base::TimeDelta& timestamp, | 11 : data_(NULL), |
| 12 const base::TimeDelta& duration) | 12 buffer_size_(0), |
| 13 : data_(data), | 13 data_size_(0) { |
| 14 buffer_size_(buffer_size), | |
| 15 data_size_(data_size) { | |
| 16 DCHECK(data); | |
| 17 DCHECK(buffer_size >= 0); | |
| 18 DCHECK(data_size <= buffer_size); | |
| 19 SetTimestamp(timestamp); | |
| 20 SetDuration(duration); | |
| 21 } | 14 } |
| 22 | 15 |
| 23 DataBuffer::~DataBuffer() { | 16 DataBuffer::~DataBuffer() { |
| 24 delete [] data_; | 17 delete [] data_; |
| 25 } | 18 } |
| 26 | 19 |
| 27 const char* DataBuffer::GetData() const { | 20 const uint8* DataBuffer::GetData() const { |
| 28 return data_; | 21 return data_; |
| 29 } | 22 } |
| 30 | 23 |
| 31 size_t DataBuffer::GetDataSize() const { | 24 size_t DataBuffer::GetDataSize() const { |
| 32 return data_size_; | 25 return data_size_; |
| 33 } | 26 } |
| 34 | 27 |
| 35 char* DataBuffer::GetWritableData() { | 28 uint8* DataBuffer::GetWritableData(size_t buffer_size) { |
| 29 if (buffer_size > buffer_size_) { |
| 30 delete [] data_; |
| 31 data_ = new uint8[buffer_size]; |
| 32 if (!data_) { |
| 33 NOTREACHED(); |
| 34 buffer_size = 0; |
| 35 } |
| 36 buffer_size_ = buffer_size; |
| 37 } |
| 38 data_size_ = buffer_size; |
| 36 return data_; | 39 return data_; |
| 37 } | 40 } |
| 38 | 41 |
| 39 size_t DataBuffer::GetBufferSize() const { | |
| 40 return buffer_size_; | |
| 41 } | |
| 42 | 42 |
| 43 void DataBuffer::SetDataSize(size_t data_size) { | 43 void DataBuffer::SetDataSize(size_t data_size) { |
| 44 DCHECK(data_size <= buffer_size_); |
| 44 data_size_ = data_size; | 45 data_size_ = data_size; |
| 45 } | 46 } |
| 46 | 47 |
| 47 } // namespace media | 48 } // namespace media |
| OLD | NEW |