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 #include "modules/rtp_rtcp/include/report_block_data.h"
12 
13 namespace webrtc {
14 
ReportBlockData()15 ReportBlockData::ReportBlockData()
16     : report_block_(),
17       report_block_timestamp_utc_us_(0),
18       last_rtt_ms_(0),
19       min_rtt_ms_(0),
20       max_rtt_ms_(0),
21       sum_rtt_ms_(0),
22       num_rtts_(0) {}
23 
AvgRttMs() const24 double ReportBlockData::AvgRttMs() const {
25   return num_rtts_ ? static_cast<double>(sum_rtt_ms_) / num_rtts_ : 0.0;
26 }
27 
SetReportBlock(RTCPReportBlock report_block,int64_t report_block_timestamp_utc_us)28 void ReportBlockData::SetReportBlock(RTCPReportBlock report_block,
29                                      int64_t report_block_timestamp_utc_us) {
30   report_block_ = report_block;
31   report_block_timestamp_utc_us_ = report_block_timestamp_utc_us;
32 }
33 
AddRoundTripTimeSample(int64_t rtt_ms)34 void ReportBlockData::AddRoundTripTimeSample(int64_t rtt_ms) {
35   if (rtt_ms > max_rtt_ms_)
36     max_rtt_ms_ = rtt_ms;
37   if (num_rtts_ == 0 || rtt_ms < min_rtt_ms_)
38     min_rtt_ms_ = rtt_ms;
39   last_rtt_ms_ = rtt_ms;
40   sum_rtt_ms_ += rtt_ms;
41   ++num_rtts_;
42 }
43 
44 }  // namespace webrtc
45