data_channel_utils.h 1.5 KB

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