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