Taylor Brandstetter | 3a034e1 | 2020-07-09 22:32:34 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #include "pc/data_channel_utils.h" |
| 12 | |
Harald Alvestrand | 5761e7b | 2021-01-29 14:45:08 | [diff] [blame] | 13 | #include <utility> |
| 14 | |
| 15 | #include "rtc_base/checks.h" |
| 16 | |
Taylor Brandstetter | 3a034e1 | 2020-07-09 22:32:34 | [diff] [blame] | 17 | namespace webrtc { |
| 18 | |
| 19 | bool PacketQueue::Empty() const { |
| 20 | return packets_.empty(); |
| 21 | } |
| 22 | |
| 23 | std::unique_ptr<DataBuffer> PacketQueue::PopFront() { |
| 24 | RTC_DCHECK(!packets_.empty()); |
| 25 | byte_count_ -= packets_.front()->size(); |
| 26 | std::unique_ptr<DataBuffer> packet = std::move(packets_.front()); |
| 27 | packets_.pop_front(); |
| 28 | return packet; |
| 29 | } |
| 30 | |
| 31 | void PacketQueue::PushFront(std::unique_ptr<DataBuffer> packet) { |
| 32 | byte_count_ += packet->size(); |
| 33 | packets_.push_front(std::move(packet)); |
| 34 | } |
| 35 | |
| 36 | void PacketQueue::PushBack(std::unique_ptr<DataBuffer> packet) { |
| 37 | byte_count_ += packet->size(); |
| 38 | packets_.push_back(std::move(packet)); |
| 39 | } |
| 40 | |
| 41 | void PacketQueue::Clear() { |
| 42 | packets_.clear(); |
| 43 | byte_count_ = 0; |
| 44 | } |
| 45 | |
| 46 | void PacketQueue::Swap(PacketQueue* other) { |
| 47 | size_t other_byte_count = other->byte_count_; |
| 48 | other->byte_count_ = byte_count_; |
| 49 | byte_count_ = other_byte_count; |
| 50 | |
| 51 | other->packets_.swap(packets_); |
| 52 | } |
| 53 | |
Taylor Brandstetter | 3a034e1 | 2020-07-09 22:32:34 | [diff] [blame] | 54 | } // namespace webrtc |