unhandled_packets_buffer.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright (c) 2019 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 MEDIA_ENGINE_UNHANDLED_PACKETS_BUFFER_H_
  11. #define MEDIA_ENGINE_UNHANDLED_PACKETS_BUFFER_H_
  12. #include <stdint.h>
  13. #include <functional>
  14. #include <tuple>
  15. #include <utility>
  16. #include <vector>
  17. #include "rtc_base/copy_on_write_buffer.h"
  18. namespace cricket {
  19. class UnhandledPacketsBuffer {
  20. public:
  21. // Visible for testing.
  22. static constexpr size_t kMaxStashedPackets = 50;
  23. UnhandledPacketsBuffer();
  24. ~UnhandledPacketsBuffer();
  25. // Store packet in buffer.
  26. void AddPacket(uint32_t ssrc,
  27. int64_t packet_time_us,
  28. rtc::CopyOnWriteBuffer packet);
  29. // Feed all packets with |ssrcs| into |consumer|.
  30. void BackfillPackets(
  31. rtc::ArrayView<const uint32_t> ssrcs,
  32. std::function<void(uint32_t, int64_t, rtc::CopyOnWriteBuffer)> consumer);
  33. private:
  34. size_t insert_pos_ = 0;
  35. struct PacketWithMetadata {
  36. uint32_t ssrc;
  37. int64_t packet_time_us;
  38. rtc::CopyOnWriteBuffer packet;
  39. };
  40. std::vector<PacketWithMetadata> buffer_;
  41. };
  42. } // namespace cricket
  43. #endif // MEDIA_ENGINE_UNHANDLED_PACKETS_BUFFER_H_