1 /* 2 * Copyright (c) 2019 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_LOSS_NOTIFICATION_H_ 12 #define MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_LOSS_NOTIFICATION_H_ 13 14 #include "absl/base/attributes.h" 15 #include "modules/rtp_rtcp/source/rtcp_packet/common_header.h" 16 #include "modules/rtp_rtcp/source/rtcp_packet/psfb.h" 17 18 namespace webrtc { 19 namespace rtcp { 20 21 class LossNotification : public Psfb { 22 public: 23 LossNotification(); 24 LossNotification(uint16_t last_decoded, 25 uint16_t last_received, 26 bool decodability_flag); 27 LossNotification(const LossNotification& other); 28 ~LossNotification() override; 29 30 size_t BlockLength() const override; 31 32 ABSL_MUST_USE_RESULT 33 bool Create(uint8_t* packet, 34 size_t* index, 35 size_t max_length, 36 PacketReadyCallback callback) const override; 37 38 // Parse assumes header is already parsed and validated. 39 ABSL_MUST_USE_RESULT 40 bool Parse(const CommonHeader& packet); 41 42 // Set all of the values transmitted by the loss notification message. 43 // If the values may not be represented by a loss notification message, 44 // false is returned, and no change is made to the object; this happens 45 // when `last_received` is ahead of `last_decoded` by more than 0x7fff. 46 // This is because `last_received` is represented on the wire as a delta, 47 // and only 15 bits are available for that delta. 48 ABSL_MUST_USE_RESULT 49 bool Set(uint16_t last_decoded, 50 uint16_t last_received, 51 bool decodability_flag); 52 53 // RTP sequence number of the first packet belong to the last decoded 54 // non-discardable frame. last_decoded()55 uint16_t last_decoded() const { return last_decoded_; } 56 57 // RTP sequence number of the last received packet. last_received()58 uint16_t last_received() const { return last_received_; } 59 60 // A decodability flag, whose specific meaning depends on the last-received 61 // RTP sequence number. The decodability flag is true if and only if all of 62 // the frame's dependencies are known to be decodable, and the frame itself 63 // is not yet known to be unassemblable. 64 // * Clarification #1: In a multi-packet frame, the first packet's 65 // dependencies are known, but it is not yet known whether all parts 66 // of the current frame will be received. 67 // * Clarification #2: In a multi-packet frame, the dependencies would be 68 // unknown if the first packet was not received. Then, the packet will 69 // be known-unassemblable. decodability_flag()70 bool decodability_flag() const { return decodability_flag_; } 71 72 private: 73 static constexpr uint32_t kUniqueIdentifier = 0x4C4E5446; // 'L' 'N' 'T' 'F'. 74 static constexpr size_t kLossNotificationPayloadLength = 8; 75 76 uint16_t last_decoded_; 77 uint16_t last_received_; 78 bool decodability_flag_; 79 }; 80 } // namespace rtcp 81 } // namespace webrtc 82 #endif // MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_LOSS_NOTIFICATION_H_ 83