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/data_buffer.h" | 5 #include "media/base/data_buffer.h" |
6 | 6 |
7 | |
8 namespace media { | 7 namespace media { |
9 | 8 |
10 DataBuffer::DataBuffer(int buffer_size) | 9 DataBuffer::DataBuffer(int buffer_size) |
11 : buffer_size_(buffer_size), | 10 : buffer_size_(buffer_size), |
12 data_size_(0) { | 11 data_size_(0) { |
13 CHECK_GE(buffer_size, 0); | 12 CHECK_GE(buffer_size, 0); |
14 data_.reset(new uint8[buffer_size_]); | 13 data_.reset(new uint8_t[buffer_size_]); |
15 } | 14 } |
16 | 15 |
17 DataBuffer::DataBuffer(scoped_ptr<uint8[]> buffer, int buffer_size) | 16 DataBuffer::DataBuffer(scoped_ptr<uint8_t[]> buffer, int buffer_size) |
18 : data_(buffer.Pass()), | 17 : data_(buffer.Pass()), buffer_size_(buffer_size), data_size_(buffer_size) { |
19 buffer_size_(buffer_size), | |
20 data_size_(buffer_size) { | |
21 CHECK(data_.get()); | 18 CHECK(data_.get()); |
22 CHECK_GE(buffer_size, 0); | 19 CHECK_GE(buffer_size, 0); |
23 } | 20 } |
24 | 21 |
25 DataBuffer::DataBuffer(const uint8* data, int data_size) | 22 DataBuffer::DataBuffer(const uint8_t* data, int data_size) |
26 : buffer_size_(data_size), | 23 : buffer_size_(data_size), data_size_(data_size) { |
27 data_size_(data_size) { | |
28 if (!data) { | 24 if (!data) { |
29 CHECK_EQ(data_size, 0); | 25 CHECK_EQ(data_size, 0); |
30 return; | 26 return; |
31 } | 27 } |
32 | 28 |
33 CHECK_GE(data_size, 0); | 29 CHECK_GE(data_size, 0); |
34 data_.reset(new uint8[buffer_size_]); | 30 data_.reset(new uint8_t[buffer_size_]); |
35 memcpy(data_.get(), data, data_size_); | 31 memcpy(data_.get(), data, data_size_); |
36 } | 32 } |
37 | 33 |
38 DataBuffer::~DataBuffer() {} | 34 DataBuffer::~DataBuffer() {} |
39 | 35 |
40 // static | 36 // static |
41 scoped_refptr<DataBuffer> DataBuffer::CopyFrom(const uint8* data, int size) { | 37 scoped_refptr<DataBuffer> DataBuffer::CopyFrom(const uint8_t* data, int size) { |
42 // If you hit this CHECK you likely have a bug in a demuxer. Go fix it. | 38 // If you hit this CHECK you likely have a bug in a demuxer. Go fix it. |
43 CHECK(data); | 39 CHECK(data); |
44 return make_scoped_refptr(new DataBuffer(data, size)); | 40 return make_scoped_refptr(new DataBuffer(data, size)); |
45 } | 41 } |
46 | 42 |
47 // static | 43 // static |
48 scoped_refptr<DataBuffer> DataBuffer::CreateEOSBuffer() { | 44 scoped_refptr<DataBuffer> DataBuffer::CreateEOSBuffer() { |
49 return make_scoped_refptr(new DataBuffer(NULL, 0)); | 45 return make_scoped_refptr(new DataBuffer(NULL, 0)); |
50 } | 46 } |
51 } // namespace media | 47 } // namespace media |
OLD | NEW |