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 #ifndef PC_DATA_CHANNEL_UTILS_H_ 12 #define PC_DATA_CHANNEL_UTILS_H_ 13 14 #include <stddef.h> 15 #include <stdint.h> 16 #include <deque> 17 #include <memory> 18 #include <string> 19 #include <utility> 20 21 #include "api/data_channel_interface.h" 22 #include "media/base/media_engine.h" 23 24 namespace webrtc { 25 26 // A packet queue which tracks the total queued bytes. Queued packets are 27 // owned by this class. 28 class PacketQueue final { 29 public: byte_count()30 size_t byte_count() const { return byte_count_; } 31 32 bool Empty() const; 33 34 std::unique_ptr<DataBuffer> PopFront(); 35 36 void PushFront(std::unique_ptr<DataBuffer> packet); 37 void PushBack(std::unique_ptr<DataBuffer> packet); 38 39 void Clear(); 40 41 void Swap(PacketQueue* other); 42 43 private: 44 std::deque<std::unique_ptr<DataBuffer>> packets_; 45 size_t byte_count_ = 0; 46 }; 47 48 struct DataChannelStats { 49 int internal_id; 50 int id; 51 std::string label; 52 std::string protocol; 53 DataChannelInterface::DataState state; 54 uint32_t messages_sent; 55 uint32_t messages_received; 56 uint64_t bytes_sent; 57 uint64_t bytes_received; 58 }; 59 60 } // namespace webrtc 61 62 #endif // PC_DATA_CHANNEL_UTILS_H_ 63