OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include <utility> | |
12 | |
13 #include "webrtc/base/checks.h" | |
11 #include "webrtc/base/buffer.h" | 14 #include "webrtc/base/buffer.h" |
12 | 15 |
13 #include <cassert> | |
14 #include <utility> | |
15 | |
16 namespace rtc { | 16 namespace rtc { |
17 | 17 |
18 Buffer::Buffer() : size_(0), capacity_(0), data_(nullptr) { | 18 Buffer::BufferData::BufferData(const void* data, size_t size, size_t capacity) |
19 assert(IsConsistent()); | 19 : size_(size), |
20 capacity_(std::max(size, capacity)), | |
21 data_(new uint8_t[capacity_]) { | |
22 RTC_DCHECK(IsConsistent()); | |
23 if (data && size) { | |
24 std::memcpy(data_.get(), data, size); | |
25 } | |
20 } | 26 } |
21 | 27 |
22 Buffer::Buffer(const Buffer& buf) : Buffer(buf.data(), buf.size()) { | 28 Buffer::Buffer() : data_(nullptr) { |
23 } | 29 } |
24 | 30 |
25 Buffer::Buffer(Buffer&& buf) | 31 Buffer::Buffer(const Buffer& buf) : data_(buf.data_) { |
26 : size_(buf.size()), | 32 } |
27 capacity_(buf.capacity()), | 33 |
28 data_(std::move(buf.data_)) { | 34 Buffer::Buffer(Buffer&& buf) : data_(std::move(buf.data_)) { |
kwiberg-webrtc
2016/02/15 12:33:16
If I'm reading things right, scoped_refptr isn't m
tommi
2016/02/15 14:56:51
scoped_refptr isn't movable, so this would leave t
kwiberg-webrtc
2016/02/15 15:05:03
Yeah, that's better. Introducing sharing is going
| |
29 assert(IsConsistent()); | |
30 buf.OnMovedFrom(); | 35 buf.OnMovedFrom(); |
31 } | 36 } |
32 | 37 |
33 Buffer::Buffer(size_t size) : Buffer(size, size) { | 38 Buffer::Buffer(size_t size) : Buffer(size, size) { |
34 } | 39 } |
35 | 40 |
36 Buffer::Buffer(size_t size, size_t capacity) | 41 Buffer::Buffer(size_t size, size_t capacity) |
37 : size_(size), | 42 : data_(new BufferData(nullptr, size, capacity)) { |
38 capacity_(std::max(size, capacity)), | 43 RTC_DCHECK(IsConsistent()); |
39 data_(new uint8_t[capacity_]) { | |
40 assert(IsConsistent()); | |
41 } | 44 } |
42 | 45 |
43 // Note: The destructor works even if the buffer has been moved from. | 46 // Note: The destructor works even if the buffer has been moved from. |
44 Buffer::~Buffer() = default; | 47 Buffer::~Buffer() = default; |
45 | 48 |
46 }; // namespace rtc | 49 }; // namespace rtc |
OLD | NEW |