blob: 9153733fb91091a470c03ab9806764fa757b194f [file] [log] [blame]
danilchapa8890a52015-12-22 03:43:04 -08001/*
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_NACK_H_
12#define MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_NACK_H_
danilchapa8890a52015-12-22 03:43:04 -080013
14#include <vector>
15
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "modules/rtp_rtcp/source/rtcp_packet/rtpfb.h"
danilchapa8890a52015-12-22 03:43:04 -080017
18namespace webrtc {
19namespace rtcp {
danilchap95e75602016-08-01 06:51:13 -070020class CommonHeader;
danilchapa8890a52015-12-22 03:43:04 -080021
22class Nack : public Rtpfb {
23 public:
danilchap95e75602016-08-01 06:51:13 -070024 static constexpr uint8_t kFeedbackMessageType = 1;
25 Nack();
Mirko Bonadei55d5ef02018-09-03 09:47:38 +020026 Nack(const Nack&);
danilchap95e75602016-08-01 06:51:13 -070027 ~Nack() override;
danilchapa8890a52015-12-22 03:43:04 -080028
29 // Parse assumes header is already parsed and validated.
danilchap95e75602016-08-01 06:51:13 -070030 bool Parse(const CommonHeader& packet);
danilchapa8890a52015-12-22 03:43:04 -080031
danilchap822a16f2016-09-27 09:27:47 -070032 void SetPacketIds(const uint16_t* nack_list, size_t length);
Danil Chapovalov327c43c2017-11-27 17:23:04 +010033 void SetPacketIds(std::vector<uint16_t> nack_list);
danilchapa8890a52015-12-22 03:43:04 -080034 const std::vector<uint16_t>& packet_ids() const { return packet_ids_; }
35
eladalon8fa21c42017-06-16 07:07:47 -070036 size_t BlockLength() const override;
37
danilchapa8890a52015-12-22 03:43:04 -080038 bool Create(uint8_t* packet,
39 size_t* index,
40 size_t max_length,
Danil Chapovalov5c3cc412017-12-07 10:15:53 +010041 PacketReadyCallback callback) const override;
danilchapa8890a52015-12-22 03:43:04 -080042
danilchapa8890a52015-12-22 03:43:04 -080043 private:
danilchap95e75602016-08-01 06:51:13 -070044 static constexpr size_t kNackItemLength = 4;
danilchapa8890a52015-12-22 03:43:04 -080045 struct PackedNack {
46 uint16_t first_pid;
47 uint16_t bitmask;
48 };
49
danilchap822a16f2016-09-27 09:27:47 -070050 void Pack(); // Fills packed_ using packed_ids_. (used in SetPacketIds).
danilchapa8890a52015-12-22 03:43:04 -080051 void Unpack(); // Fills packet_ids_ using packed_. (used in Parse).
52
53 std::vector<PackedNack> packed_;
54 std::vector<uint16_t> packet_ids_;
danilchapa8890a52015-12-22 03:43:04 -080055};
56
57} // namespace rtcp
58} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020059#endif // MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_NACK_H_