nack.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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_RTCP_PACKET_NACK_H_
  11. #define MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_NACK_H_
  12. #include <vector>
  13. #include "modules/rtp_rtcp/source/rtcp_packet/rtpfb.h"
  14. namespace webrtc {
  15. namespace rtcp {
  16. class CommonHeader;
  17. class Nack : public Rtpfb {
  18. public:
  19. static constexpr uint8_t kFeedbackMessageType = 1;
  20. Nack();
  21. Nack(const Nack&);
  22. ~Nack() override;
  23. // Parse assumes header is already parsed and validated.
  24. bool Parse(const CommonHeader& packet);
  25. void SetPacketIds(const uint16_t* nack_list, size_t length);
  26. void SetPacketIds(std::vector<uint16_t> nack_list);
  27. const std::vector<uint16_t>& packet_ids() const { return packet_ids_; }
  28. size_t BlockLength() const override;
  29. bool Create(uint8_t* packet,
  30. size_t* index,
  31. size_t max_length,
  32. PacketReadyCallback callback) const override;
  33. private:
  34. static constexpr size_t kNackItemLength = 4;
  35. struct PackedNack {
  36. uint16_t first_pid;
  37. uint16_t bitmask;
  38. };
  39. void Pack(); // Fills packed_ using packed_ids_. (used in SetPacketIds).
  40. void Unpack(); // Fills packet_ids_ using packed_. (used in Parse).
  41. std::vector<PackedNack> packed_;
  42. std::vector<uint16_t> packet_ids_;
  43. };
  44. } // namespace rtcp
  45. } // namespace webrtc
  46. #endif // MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_NACK_H_