tor-browser

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

report_block_data.h (5809B)


      1 /*
      2 *  Copyright 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_INCLUDE_REPORT_BLOCK_DATA_H_
     12 #define MODULES_RTP_RTCP_INCLUDE_REPORT_BLOCK_DATA_H_
     13 
     14 #include <cstddef>
     15 #include <cstdint>
     16 
     17 #include "api/units/time_delta.h"
     18 #include "api/units/timestamp.h"
     19 #include "modules/rtp_rtcp/source/rtcp_packet/report_block.h"
     20 
     21 namespace webrtc {
     22 
     23 // Represents fields and derived information received in RTCP report block
     24 // attached to RTCP sender report or RTCP receiver report, as described in
     25 // https://www.rfc-editor.org/rfc/rfc3550#section-6.4.1
     26 class ReportBlockData {
     27 public:
     28  ReportBlockData() = default;
     29 
     30  ReportBlockData(const ReportBlockData&) = default;
     31  ReportBlockData& operator=(const ReportBlockData&) = default;
     32 
     33  // The SSRC identifier for the originator of this report block,
     34  // i.e. remote receiver of the RTP stream.
     35  uint32_t sender_ssrc() const { return sender_ssrc_; }
     36 
     37  // The SSRC identifier of the source to which the information in this
     38  // reception report block pertains, i.e. local sender of the RTP stream.
     39  uint32_t source_ssrc() const { return source_ssrc_; }
     40 
     41  // The fraction of RTP data packets from 'source_ssrc()' lost since the
     42  // previous report block was sent.
     43  // Fraction loss in range [0.0, 1.0].
     44  float fraction_lost() const {
     45    return static_cast<float>(fraction_lost_raw()) / 256.0f;
     46  }
     47 
     48  // Fraction loss as was written in the raw packet: range is [0, 255] where 0
     49  // represents no loss, and 255 represents 99.6% loss (255/256 * 100%).
     50  uint8_t fraction_lost_raw() const { return fraction_lost_raw_; }
     51 
     52  // The total number of RTP data packets from 'source_ssrc()' that have been
     53  // lost since the beginning of reception.  This number is defined to be the
     54  // number of packets expected less the number of packets actually received,
     55  // where the number of packets received includes any which are late or
     56  // duplicates. Thus, packets that arrive late are not counted as lost, and the
     57  // loss may be negative if there are duplicates.
     58  int cumulative_lost() const { return cumulative_lost_; }
     59 
     60  // The low 16 bits contain the highest sequence number received in an RTP data
     61  // packet from 'source_ssrc()', and the most significant 16 bits extend that
     62  // sequence number with the corresponding count of sequence number cycles.
     63  uint32_t extended_highest_sequence_number() const {
     64    return extended_highest_sequence_number_;
     65  }
     66 
     67  // An estimate of the statistical variance of the RTP data packet interarrival
     68  // time, measured in RTP timestamp units. The interarrival jitter J is defined
     69  // to be the mean deviation (smoothed absolute value) of the difference D in
     70  // packet spacing at the receiver compared to the sender for a pair of
     71  // packets.
     72  uint32_t jitter() const { return jitter_; }
     73 
     74  // Jitter converted to common time units.
     75  TimeDelta jitter(int rtp_clock_rate_hz) const;
     76 
     77  // Time in utc epoch (Jan 1st, 1970) the report block was received.
     78  // TODO: bugs.webrtc.org/370535296 - Remove the utc timestamp when linked
     79  // issue is fixed.
     80  Timestamp report_block_timestamp_utc() const {
     81    return report_block_timestamp_utc_;
     82  }
     83 
     84  // Monotonic time when the report block was received.
     85  Timestamp report_block_timestamp() const { return report_block_timestamp_; }
     86 
     87  // Round Trip Time measurments for given (sender_ssrc, source_ssrc) pair.
     88  // Min, max, sum, number of measurements are since beginning of the call.
     89  TimeDelta last_rtt() const { return last_rtt_; }
     90  TimeDelta sum_rtts() const { return sum_rtt_; }
     91  size_t num_rtts() const { return num_rtts_; }
     92  bool has_rtt() const { return num_rtts_ != 0; }
     93 
     94  void set_sender_ssrc(uint32_t ssrc) { sender_ssrc_ = ssrc; }
     95  void set_source_ssrc(uint32_t ssrc) { source_ssrc_ = ssrc; }
     96  void set_fraction_lost_raw(uint8_t lost) { fraction_lost_raw_ = lost; }
     97  void set_cumulative_lost(int lost) { cumulative_lost_ = lost; }
     98  void set_extended_highest_sequence_number(uint32_t sn) {
     99    extended_highest_sequence_number_ = sn;
    100  }
    101  void set_jitter(uint32_t jitter) { jitter_ = jitter; }
    102  // TODO: bugs.webrtc.org/370535296 - Remove the utc timestamp when linked
    103  // issue is fixed.
    104  void set_report_block_timestamp_utc(Timestamp arrival_time) {
    105    report_block_timestamp_utc_ = arrival_time;
    106  }
    107  void set_report_block_timestamp(Timestamp arrival_time) {
    108    report_block_timestamp_ = arrival_time;
    109  }
    110 
    111  void SetReportBlock(uint32_t sender_ssrc,
    112                      const rtcp::ReportBlock& report_block,
    113                      Timestamp report_block_timestamp_utc,
    114                      Timestamp report_block_timestamp);
    115  void AddRoundTripTimeSample(TimeDelta rtt);
    116 
    117 private:
    118  uint32_t sender_ssrc_ = 0;
    119  uint32_t source_ssrc_ = 0;
    120  uint8_t fraction_lost_raw_ = 0;
    121  int32_t cumulative_lost_ = 0;
    122  uint32_t extended_highest_sequence_number_ = 0;
    123  uint32_t jitter_ = 0;
    124  // TODO: bugs.webrtc.org/370535296 - Remove the utc timestamp when linked
    125  // issue is fixed.
    126  Timestamp report_block_timestamp_utc_ = Timestamp::Zero();
    127  Timestamp report_block_timestamp_ = Timestamp::Zero();
    128  TimeDelta last_rtt_ = TimeDelta::Zero();
    129  TimeDelta sum_rtt_ = TimeDelta::Zero();
    130  size_t num_rtts_ = 0;
    131 };
    132 
    133 class ReportBlockDataObserver {
    134 public:
    135  virtual ~ReportBlockDataObserver() = default;
    136 
    137  virtual void OnReportBlockDataUpdated(ReportBlockData report_block_data) = 0;
    138 };
    139 
    140 }  // namespace webrtc
    141 
    142 #endif  // MODULES_RTP_RTCP_INCLUDE_REPORT_BLOCK_DATA_H_