tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

loss_notification.h (3285B)


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