packet_loss_stats.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (c) 2015 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 MODULES_RTP_RTCP_SOURCE_PACKET_LOSS_STATS_H_
  11. #define MODULES_RTP_RTCP_SOURCE_PACKET_LOSS_STATS_H_
  12. #include <stdint.h>
  13. #include <set>
  14. namespace webrtc {
  15. // Keeps track of statistics of packet loss including whether losses are a
  16. // single packet or multiple packets in a row.
  17. class PacketLossStats {
  18. public:
  19. PacketLossStats();
  20. ~PacketLossStats();
  21. // Adds a lost packet to the stats by sequence number.
  22. void AddLostPacket(uint16_t sequence_number);
  23. // Queries the number of packets that were lost by themselves, no neighboring
  24. // packets were lost.
  25. int GetSingleLossCount() const;
  26. // Queries the number of times that multiple packets with sequential numbers
  27. // were lost. This is the number of events with more than one packet lost,
  28. // regardless of the size of the event;
  29. int GetMultipleLossEventCount() const;
  30. // Queries the number of packets lost in multiple packet loss events. Combined
  31. // with the event count, this can be used to determine the average event size.
  32. int GetMultipleLossPacketCount() const;
  33. private:
  34. std::set<uint16_t> lost_packets_buffer_;
  35. std::set<uint16_t> lost_packets_wrapped_buffer_;
  36. int single_loss_historic_count_;
  37. int multiple_loss_historic_event_count_;
  38. int multiple_loss_historic_packet_count_;
  39. void ComputeLossCounts(int* out_single_loss_count,
  40. int* out_multiple_loss_event_count,
  41. int* out_multiple_loss_packet_count) const;
  42. void PruneBuffer();
  43. };
  44. } // namespace webrtc
  45. #endif // MODULES_RTP_RTCP_SOURCE_PACKET_LOSS_STATS_H_