[email protected] | f1ca6df | 2012-01-10 04:47:31 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | d8a447c5 | 2008-12-16 21:46:10 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | d8a447c5 | 2008-12-16 21:46:10 | [diff] [blame] | 5 | #include "media/base/data_buffer.h" |
| 6 | |
dcheng | 652f5ff | 2015-12-27 08:54:00 | [diff] [blame] | 7 | #include <utility> |
| 8 | |
[email protected] | d8a447c5 | 2008-12-16 21:46:10 | [diff] [blame] | 9 | namespace media { |
| 10 | |
[email protected] | 5095fbf | 2013-01-17 23:20:14 | [diff] [blame] | 11 | DataBuffer::DataBuffer(int buffer_size) |
| 12 | : buffer_size_(buffer_size), |
| 13 | data_size_(0) { |
| 14 | CHECK_GE(buffer_size, 0); |
Avi Drissman | 97785ea | 2015-12-19 01:11:31 | [diff] [blame] | 15 | data_.reset(new uint8_t[buffer_size_]); |
[email protected] | 5095fbf | 2013-01-17 23:20:14 | [diff] [blame] | 16 | } |
| 17 | |
danakj | 6aaed6a | 2016-04-26 01:25:44 | [diff] [blame] | 18 | DataBuffer::DataBuffer(std::unique_ptr<uint8_t[]> buffer, int buffer_size) |
dcheng | 652f5ff | 2015-12-27 08:54:00 | [diff] [blame] | 19 | : data_(std::move(buffer)), |
| 20 | buffer_size_(buffer_size), |
| 21 | data_size_(buffer_size) { |
[email protected] | 5095fbf | 2013-01-17 23:20:14 | [diff] [blame] | 22 | CHECK(data_.get()); |
| 23 | CHECK_GE(buffer_size, 0); |
[email protected] | d8a447c5 | 2008-12-16 21:46:10 | [diff] [blame] | 24 | } |
| 25 | |
Avi Drissman | 97785ea | 2015-12-19 01:11:31 | [diff] [blame] | 26 | DataBuffer::DataBuffer(const uint8_t* data, int data_size) |
| 27 | : buffer_size_(data_size), data_size_(data_size) { |
[email protected] | 5095fbf | 2013-01-17 23:20:14 | [diff] [blame] | 28 | if (!data) { |
| 29 | CHECK_EQ(data_size, 0); |
| 30 | return; |
| 31 | } |
| 32 | |
| 33 | CHECK_GE(data_size, 0); |
Avi Drissman | 97785ea | 2015-12-19 01:11:31 | [diff] [blame] | 34 | data_.reset(new uint8_t[buffer_size_]); |
[email protected] | f42d6a10 | 2012-05-31 20:35:25 | [diff] [blame] | 35 | memcpy(data_.get(), data, data_size_); |
[email protected] | ec57586 | 2012-05-02 20:18:07 | [diff] [blame] | 36 | } |
| 37 | |
Chris Watkins | 2de6929 | 2017-12-01 03:08:01 | [diff] [blame] | 38 | DataBuffer::~DataBuffer() = default; |
[email protected] | d8a447c5 | 2008-12-16 21:46:10 | [diff] [blame] | 39 | |
[email protected] | 5095fbf | 2013-01-17 23:20:14 | [diff] [blame] | 40 | // static |
Avi Drissman | 97785ea | 2015-12-19 01:11:31 | [diff] [blame] | 41 | scoped_refptr<DataBuffer> DataBuffer::CopyFrom(const uint8_t* data, int size) { |
[email protected] | 5095fbf | 2013-01-17 23:20:14 | [diff] [blame] | 42 | // If you hit this CHECK you likely have a bug in a demuxer. Go fix it. |
| 43 | CHECK(data); |
kylechar | da69d88 | 2017-10-04 05:49:52 | [diff] [blame] | 44 | return base::WrapRefCounted(new DataBuffer(data, size)); |
[email protected] | 5095fbf | 2013-01-17 23:20:14 | [diff] [blame] | 45 | } |
[email protected] | f42d6a10 | 2012-05-31 20:35:25 | [diff] [blame] | 46 | |
[email protected] | 5095fbf | 2013-01-17 23:20:14 | [diff] [blame] | 47 | // static |
| 48 | scoped_refptr<DataBuffer> DataBuffer::CreateEOSBuffer() { |
kylechar | da69d88 | 2017-10-04 05:49:52 | [diff] [blame] | 49 | return base::WrapRefCounted(new DataBuffer(NULL, 0)); |
[email protected] | f42d6a10 | 2012-05-31 20:35:25 | [diff] [blame] | 50 | } |
[email protected] | d8a447c5 | 2008-12-16 21:46:10 | [diff] [blame] | 51 | } // namespace media |