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