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