2013-08-15 23:38:54 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/rtp_rtcp/source/receive_statistics_impl.h"
|
2013-08-15 23:38:54 +00:00
|
|
|
|
2019-04-23 08:50:04 +02:00
|
|
|
#include <cmath>
|
2016-05-14 19:44:11 -07:00
|
|
|
#include <cstdlib>
|
2018-11-23 11:03:25 +01:00
|
|
|
#include <memory>
|
2017-07-27 04:44:18 -07:00
|
|
|
#include <vector>
|
2016-05-14 19:44:11 -07:00
|
|
|
|
2018-11-23 11:03:25 +01:00
|
|
|
#include "absl/memory/memory.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/remote_bitrate_estimator/test/bwe_test_logging.h"
|
2018-09-14 08:26:32 +02:00
|
|
|
#include "modules/rtp_rtcp/source/rtp_packet_received.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/rtp_rtcp/source/rtp_rtcp_config.h"
|
|
|
|
|
#include "modules/rtp_rtcp/source/time_util.h"
|
|
|
|
|
#include "rtc_base/logging.h"
|
|
|
|
|
#include "system_wrappers/include/clock.h"
|
2013-08-15 23:38:54 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2013-08-21 20:58:21 +00:00
|
|
|
const int64_t kStatisticsTimeoutMs = 8000;
|
2014-12-15 22:09:40 +00:00
|
|
|
const int64_t kStatisticsProcessIntervalMs = 1000;
|
2013-08-15 23:38:54 +00:00
|
|
|
|
2013-08-21 20:58:21 +00:00
|
|
|
StreamStatistician::~StreamStatistician() {}
|
2013-08-15 23:38:54 +00:00
|
|
|
|
2013-12-19 13:26:02 +00:00
|
|
|
StreamStatisticianImpl::StreamStatisticianImpl(
|
2017-08-14 05:51:02 -07:00
|
|
|
uint32_t ssrc,
|
2013-12-19 13:26:02 +00:00
|
|
|
Clock* clock,
|
2018-11-22 14:04:02 +01:00
|
|
|
int max_reordering_threshold,
|
2014-01-23 10:00:39 +00:00
|
|
|
RtcpStatisticsCallback* rtcp_callback,
|
|
|
|
|
StreamDataCountersCallback* rtp_callback)
|
2017-08-14 05:51:02 -07:00
|
|
|
: ssrc_(ssrc),
|
|
|
|
|
clock_(clock),
|
2016-07-13 09:11:28 -07:00
|
|
|
incoming_bitrate_(kStatisticsProcessIntervalMs,
|
|
|
|
|
RateStatistics::kBpsScale),
|
2018-11-22 14:04:02 +01:00
|
|
|
max_reordering_threshold_(max_reordering_threshold),
|
2019-05-24 14:04:28 +02:00
|
|
|
enable_retransmit_detection_(false),
|
2013-08-15 23:38:54 +00:00
|
|
|
jitter_q4_(0),
|
Revert "Update packetsLost and jitter stats any time a packet is received."
This reverts commit 84916937b70472715efe5682bc273e91c3a72695.
Reason for revert: breaking downstream projects.
Original change's description:
> Update packetsLost and jitter stats any time a packet is received.
>
> Before this CL, the packetsLost and jitter stats (as returned by
> GetStats, at the API level) were only being updated when an RTCP SR or
> RR is generated. According to the stats spec, "local" stats like this
> should be updated any time a packet is received.
>
> This CL also fixes some minor issues with the calculation of packetsLost
> (and fractionLost):
> * Packets weren't being count as lost if lost over a sequence number
> rollover.
> * Temporary periods of "negative" loss (caused by duplicate or out of
> order packets) weren't being accumulated into the cumulative loss
> counter. Example:
> Period 1: Received packets 1, 2, 4
> Loss over that period: 1 (expected 4 packets, got 3)
> Reported cumulative loss: 1
> Period 2: Received packets 3, 5
> Loss over that period: -1 (expected 1 packet, got 2)
> Reported cumulative loss: 1 (should be 0!)
>
> Landing with NOTRY because Android compile bots are broken for an
> unrelated reason.
> NOTRY=True
>
> Bug: webrtc:8804
> Change-Id: I840ba34de8957b1276f6bdaf93718f805629f5c8
> Reviewed-on: https://webrtc-review.googlesource.com/50020
> Commit-Queue: Taylor Brandstetter <deadbeef@webrtc.org>
> Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
> Reviewed-by: Oskar Sundbom <ossu@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#23731}
TBR=danilchap@webrtc.org,deadbeef@webrtc.org,ossu@webrtc.org
# Not skipping CQ checks because original CL landed > 1 day ago.
Landing with NOTRY because ios64_sim_ios10_dbg bot is broken.
Passing all other bots.
NOTRY=True
Bug: webrtc:8804
Change-Id: I07bd6b1206d5a8d211792ad392842f9ed6c505e9
Reviewed-on: https://webrtc-review.googlesource.com/95280
Commit-Queue: Qingsi Wang <qingsi@webrtc.org>
Reviewed-by: Qingsi Wang <qingsi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24370}
2018-08-21 14:24:26 -07:00
|
|
|
cumulative_loss_(0),
|
2013-09-06 13:40:11 +00:00
|
|
|
last_receive_time_ms_(0),
|
2013-08-15 23:38:54 +00:00
|
|
|
last_received_timestamp_(0),
|
|
|
|
|
received_seq_first_(0),
|
2018-12-05 14:55:46 +00:00
|
|
|
received_seq_max_(-1),
|
Revert "Update packetsLost and jitter stats any time a packet is received."
This reverts commit 84916937b70472715efe5682bc273e91c3a72695.
Reason for revert: breaking downstream projects.
Original change's description:
> Update packetsLost and jitter stats any time a packet is received.
>
> Before this CL, the packetsLost and jitter stats (as returned by
> GetStats, at the API level) were only being updated when an RTCP SR or
> RR is generated. According to the stats spec, "local" stats like this
> should be updated any time a packet is received.
>
> This CL also fixes some minor issues with the calculation of packetsLost
> (and fractionLost):
> * Packets weren't being count as lost if lost over a sequence number
> rollover.
> * Temporary periods of "negative" loss (caused by duplicate or out of
> order packets) weren't being accumulated into the cumulative loss
> counter. Example:
> Period 1: Received packets 1, 2, 4
> Loss over that period: 1 (expected 4 packets, got 3)
> Reported cumulative loss: 1
> Period 2: Received packets 3, 5
> Loss over that period: -1 (expected 1 packet, got 2)
> Reported cumulative loss: 1 (should be 0!)
>
> Landing with NOTRY because Android compile bots are broken for an
> unrelated reason.
> NOTRY=True
>
> Bug: webrtc:8804
> Change-Id: I840ba34de8957b1276f6bdaf93718f805629f5c8
> Reviewed-on: https://webrtc-review.googlesource.com/50020
> Commit-Queue: Taylor Brandstetter <deadbeef@webrtc.org>
> Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
> Reviewed-by: Oskar Sundbom <ossu@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#23731}
TBR=danilchap@webrtc.org,deadbeef@webrtc.org,ossu@webrtc.org
# Not skipping CQ checks because original CL landed > 1 day ago.
Landing with NOTRY because ios64_sim_ios10_dbg bot is broken.
Passing all other bots.
NOTRY=True
Bug: webrtc:8804
Change-Id: I07bd6b1206d5a8d211792ad392842f9ed6c505e9
Reviewed-on: https://webrtc-review.googlesource.com/95280
Commit-Queue: Qingsi Wang <qingsi@webrtc.org>
Reviewed-by: Qingsi Wang <qingsi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24370}
2018-08-21 14:24:26 -07:00
|
|
|
last_report_inorder_packets_(0),
|
|
|
|
|
last_report_old_packets_(0),
|
2018-12-05 14:55:46 +00:00
|
|
|
last_report_seq_max_(-1),
|
2014-01-23 10:00:39 +00:00
|
|
|
rtcp_callback_(rtcp_callback),
|
|
|
|
|
rtp_callback_(rtp_callback) {}
|
2013-08-15 23:38:54 +00:00
|
|
|
|
2018-02-07 09:38:31 +01:00
|
|
|
StreamStatisticianImpl::~StreamStatisticianImpl() = default;
|
|
|
|
|
|
2018-11-15 08:05:16 +01:00
|
|
|
void StreamStatisticianImpl::OnRtpPacket(const RtpPacketReceived& packet) {
|
2018-11-22 11:28:45 +01:00
|
|
|
StreamDataCounters counters = UpdateCounters(packet);
|
2018-11-23 11:03:25 +01:00
|
|
|
if (rtp_callback_)
|
|
|
|
|
rtp_callback_->DataCountersUpdated(counters, ssrc_);
|
2014-01-27 16:22:08 +00:00
|
|
|
}
|
|
|
|
|
|
2018-12-05 14:55:46 +00:00
|
|
|
bool StreamStatisticianImpl::UpdateOutOfOrder(const RtpPacketReceived& packet,
|
|
|
|
|
int64_t sequence_number,
|
|
|
|
|
int64_t now_ms) {
|
|
|
|
|
RTC_DCHECK_EQ(sequence_number,
|
|
|
|
|
seq_unwrapper_.UnwrapWithoutUpdate(packet.SequenceNumber()));
|
|
|
|
|
|
|
|
|
|
// Check if |packet| is second packet of a stream restart.
|
|
|
|
|
if (received_seq_out_of_order_) {
|
|
|
|
|
uint16_t expected_sequence_number = *received_seq_out_of_order_ + 1;
|
|
|
|
|
received_seq_out_of_order_ = absl::nullopt;
|
|
|
|
|
if (packet.SequenceNumber() == expected_sequence_number) {
|
|
|
|
|
// Ignore sequence number gap caused by stream restart for next packet
|
|
|
|
|
// loss calculation.
|
|
|
|
|
last_report_seq_max_ = sequence_number;
|
|
|
|
|
last_report_inorder_packets_ = receive_counters_.transmitted.packets -
|
|
|
|
|
receive_counters_.retransmitted.packets;
|
|
|
|
|
// As final part of stream restart consider |packet| is not out of order.
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (std::abs(sequence_number - received_seq_max_) >
|
|
|
|
|
max_reordering_threshold_) {
|
|
|
|
|
// Sequence number gap looks too large, wait until next packet to check
|
|
|
|
|
// for a stream restart.
|
|
|
|
|
received_seq_out_of_order_ = packet.SequenceNumber();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sequence_number > received_seq_max_)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// Old out of order packet, may be retransmit.
|
|
|
|
|
if (enable_retransmit_detection_ && IsRetransmitOfOldPacket(packet, now_ms))
|
|
|
|
|
receive_counters_.retransmitted.AddPacket(packet);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-14 05:51:02 -07:00
|
|
|
StreamDataCounters StreamStatisticianImpl::UpdateCounters(
|
2018-11-22 11:28:45 +01:00
|
|
|
const RtpPacketReceived& packet) {
|
|
|
|
|
rtc::CritScope cs(&stream_lock_);
|
2018-11-15 08:05:16 +01:00
|
|
|
RTC_DCHECK_EQ(ssrc_, packet.Ssrc());
|
2018-11-22 11:28:45 +01:00
|
|
|
int64_t now_ms = clock_->TimeInMilliseconds();
|
|
|
|
|
|
|
|
|
|
incoming_bitrate_.Update(packet.size(), now_ms);
|
2019-04-02 15:11:48 +02:00
|
|
|
receive_counters_.last_packet_received_timestamp_ms = now_ms;
|
2018-11-15 08:05:16 +01:00
|
|
|
receive_counters_.transmitted.AddPacket(packet);
|
2013-08-15 23:38:54 +00:00
|
|
|
|
2018-12-05 14:55:46 +00:00
|
|
|
int64_t sequence_number =
|
|
|
|
|
seq_unwrapper_.UnwrapWithoutUpdate(packet.SequenceNumber());
|
|
|
|
|
if (!ReceivedRtpPacket()) {
|
|
|
|
|
received_seq_first_ = sequence_number;
|
|
|
|
|
last_report_seq_max_ = sequence_number - 1;
|
2018-11-22 11:28:45 +01:00
|
|
|
receive_counters_.first_packet_time_ms = now_ms;
|
2018-12-05 14:55:46 +00:00
|
|
|
} else if (UpdateOutOfOrder(packet, sequence_number, now_ms)) {
|
|
|
|
|
return receive_counters_;
|
2013-08-15 23:38:54 +00:00
|
|
|
}
|
2018-12-05 14:55:46 +00:00
|
|
|
// In order packet.
|
|
|
|
|
received_seq_max_ = sequence_number;
|
|
|
|
|
seq_unwrapper_.UpdateLast(sequence_number);
|
|
|
|
|
|
|
|
|
|
// If new time stamp and more than one in-order packet received, calculate
|
|
|
|
|
// new jitter statistics.
|
|
|
|
|
if (packet.Timestamp() != last_received_timestamp_ &&
|
|
|
|
|
(receive_counters_.transmitted.packets -
|
|
|
|
|
receive_counters_.retransmitted.packets) > 1) {
|
|
|
|
|
UpdateJitter(packet, now_ms);
|
2013-08-15 23:38:54 +00:00
|
|
|
}
|
2018-12-05 14:55:46 +00:00
|
|
|
last_received_timestamp_ = packet.Timestamp();
|
|
|
|
|
last_receive_time_ms_ = now_ms;
|
2017-08-14 05:51:02 -07:00
|
|
|
return receive_counters_;
|
2014-01-23 10:00:39 +00:00
|
|
|
}
|
|
|
|
|
|
2018-11-15 08:05:16 +01:00
|
|
|
void StreamStatisticianImpl::UpdateJitter(const RtpPacketReceived& packet,
|
2018-11-26 10:20:01 +01:00
|
|
|
int64_t receive_time_ms) {
|
|
|
|
|
int64_t receive_diff_ms = receive_time_ms - last_receive_time_ms_;
|
|
|
|
|
RTC_DCHECK_GE(receive_diff_ms, 0);
|
|
|
|
|
uint32_t receive_diff_rtp = static_cast<uint32_t>(
|
|
|
|
|
(receive_diff_ms * packet.payload_type_frequency()) / 1000);
|
|
|
|
|
int32_t time_diff_samples =
|
|
|
|
|
receive_diff_rtp - (packet.Timestamp() - last_received_timestamp_);
|
2014-01-23 10:00:39 +00:00
|
|
|
|
2016-05-14 19:44:11 -07:00
|
|
|
time_diff_samples = std::abs(time_diff_samples);
|
2014-01-23 10:00:39 +00:00
|
|
|
|
|
|
|
|
// lib_jingle sometimes deliver crazy jumps in TS for the same stream.
|
|
|
|
|
// If this happens, don't update jitter value. Use 5 secs video frequency
|
|
|
|
|
// as the threshold.
|
|
|
|
|
if (time_diff_samples < 450000) {
|
|
|
|
|
// Note we calculate in Q4 to avoid using float.
|
|
|
|
|
int32_t jitter_diff_q4 = (time_diff_samples << 4) - jitter_q4_;
|
|
|
|
|
jitter_q4_ += ((jitter_diff_q4 + 8) >> 4);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-15 08:05:16 +01:00
|
|
|
void StreamStatisticianImpl::FecPacketReceived(
|
|
|
|
|
const RtpPacketReceived& packet) {
|
2017-08-14 05:51:02 -07:00
|
|
|
StreamDataCounters counters;
|
2014-01-27 16:22:08 +00:00
|
|
|
{
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope cs(&stream_lock_);
|
2018-11-15 08:05:16 +01:00
|
|
|
receive_counters_.fec.AddPacket(packet);
|
2017-08-14 05:51:02 -07:00
|
|
|
counters = receive_counters_;
|
2014-01-27 16:22:08 +00:00
|
|
|
}
|
2018-11-23 11:03:25 +01:00
|
|
|
if (rtp_callback_)
|
|
|
|
|
rtp_callback_->DataCountersUpdated(counters, ssrc_);
|
2013-08-15 23:38:54 +00:00
|
|
|
}
|
|
|
|
|
|
2013-09-06 13:40:11 +00:00
|
|
|
void StreamStatisticianImpl::SetMaxReorderingThreshold(
|
|
|
|
|
int max_reordering_threshold) {
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope cs(&stream_lock_);
|
2013-09-06 13:40:11 +00:00
|
|
|
max_reordering_threshold_ = max_reordering_threshold;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-27 13:27:05 +02:00
|
|
|
void StreamStatisticianImpl::EnableRetransmitDetection(bool enable) {
|
|
|
|
|
rtc::CritScope cs(&stream_lock_);
|
|
|
|
|
enable_retransmit_detection_ = enable;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 13:26:02 +00:00
|
|
|
bool StreamStatisticianImpl::GetStatistics(RtcpStatistics* statistics,
|
Revert "Update packetsLost and jitter stats any time a packet is received."
This reverts commit 84916937b70472715efe5682bc273e91c3a72695.
Reason for revert: breaking downstream projects.
Original change's description:
> Update packetsLost and jitter stats any time a packet is received.
>
> Before this CL, the packetsLost and jitter stats (as returned by
> GetStats, at the API level) were only being updated when an RTCP SR or
> RR is generated. According to the stats spec, "local" stats like this
> should be updated any time a packet is received.
>
> This CL also fixes some minor issues with the calculation of packetsLost
> (and fractionLost):
> * Packets weren't being count as lost if lost over a sequence number
> rollover.
> * Temporary periods of "negative" loss (caused by duplicate or out of
> order packets) weren't being accumulated into the cumulative loss
> counter. Example:
> Period 1: Received packets 1, 2, 4
> Loss over that period: 1 (expected 4 packets, got 3)
> Reported cumulative loss: 1
> Period 2: Received packets 3, 5
> Loss over that period: -1 (expected 1 packet, got 2)
> Reported cumulative loss: 1 (should be 0!)
>
> Landing with NOTRY because Android compile bots are broken for an
> unrelated reason.
> NOTRY=True
>
> Bug: webrtc:8804
> Change-Id: I840ba34de8957b1276f6bdaf93718f805629f5c8
> Reviewed-on: https://webrtc-review.googlesource.com/50020
> Commit-Queue: Taylor Brandstetter <deadbeef@webrtc.org>
> Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
> Reviewed-by: Oskar Sundbom <ossu@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#23731}
TBR=danilchap@webrtc.org,deadbeef@webrtc.org,ossu@webrtc.org
# Not skipping CQ checks because original CL landed > 1 day ago.
Landing with NOTRY because ios64_sim_ios10_dbg bot is broken.
Passing all other bots.
NOTRY=True
Bug: webrtc:8804
Change-Id: I07bd6b1206d5a8d211792ad392842f9ed6c505e9
Reviewed-on: https://webrtc-review.googlesource.com/95280
Commit-Queue: Qingsi Wang <qingsi@webrtc.org>
Reviewed-by: Qingsi Wang <qingsi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24370}
2018-08-21 14:24:26 -07:00
|
|
|
bool reset) {
|
2014-01-21 16:33:37 +00:00
|
|
|
{
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope cs(&stream_lock_);
|
2018-12-05 14:55:46 +00:00
|
|
|
if (!ReceivedRtpPacket()) {
|
2013-08-15 23:38:54 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2014-01-21 16:33:37 +00:00
|
|
|
|
Revert "Update packetsLost and jitter stats any time a packet is received."
This reverts commit 84916937b70472715efe5682bc273e91c3a72695.
Reason for revert: breaking downstream projects.
Original change's description:
> Update packetsLost and jitter stats any time a packet is received.
>
> Before this CL, the packetsLost and jitter stats (as returned by
> GetStats, at the API level) were only being updated when an RTCP SR or
> RR is generated. According to the stats spec, "local" stats like this
> should be updated any time a packet is received.
>
> This CL also fixes some minor issues with the calculation of packetsLost
> (and fractionLost):
> * Packets weren't being count as lost if lost over a sequence number
> rollover.
> * Temporary periods of "negative" loss (caused by duplicate or out of
> order packets) weren't being accumulated into the cumulative loss
> counter. Example:
> Period 1: Received packets 1, 2, 4
> Loss over that period: 1 (expected 4 packets, got 3)
> Reported cumulative loss: 1
> Period 2: Received packets 3, 5
> Loss over that period: -1 (expected 1 packet, got 2)
> Reported cumulative loss: 1 (should be 0!)
>
> Landing with NOTRY because Android compile bots are broken for an
> unrelated reason.
> NOTRY=True
>
> Bug: webrtc:8804
> Change-Id: I840ba34de8957b1276f6bdaf93718f805629f5c8
> Reviewed-on: https://webrtc-review.googlesource.com/50020
> Commit-Queue: Taylor Brandstetter <deadbeef@webrtc.org>
> Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
> Reviewed-by: Oskar Sundbom <ossu@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#23731}
TBR=danilchap@webrtc.org,deadbeef@webrtc.org,ossu@webrtc.org
# Not skipping CQ checks because original CL landed > 1 day ago.
Landing with NOTRY because ios64_sim_ios10_dbg bot is broken.
Passing all other bots.
NOTRY=True
Bug: webrtc:8804
Change-Id: I07bd6b1206d5a8d211792ad392842f9ed6c505e9
Reviewed-on: https://webrtc-review.googlesource.com/95280
Commit-Queue: Qingsi Wang <qingsi@webrtc.org>
Reviewed-by: Qingsi Wang <qingsi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24370}
2018-08-21 14:24:26 -07:00
|
|
|
if (!reset) {
|
|
|
|
|
if (last_report_inorder_packets_ == 0) {
|
|
|
|
|
// No report.
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
// Just get last report.
|
|
|
|
|
*statistics = last_reported_statistics_;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2013-08-15 23:38:54 +00:00
|
|
|
|
Revert "Update packetsLost and jitter stats any time a packet is received."
This reverts commit 84916937b70472715efe5682bc273e91c3a72695.
Reason for revert: breaking downstream projects.
Original change's description:
> Update packetsLost and jitter stats any time a packet is received.
>
> Before this CL, the packetsLost and jitter stats (as returned by
> GetStats, at the API level) were only being updated when an RTCP SR or
> RR is generated. According to the stats spec, "local" stats like this
> should be updated any time a packet is received.
>
> This CL also fixes some minor issues with the calculation of packetsLost
> (and fractionLost):
> * Packets weren't being count as lost if lost over a sequence number
> rollover.
> * Temporary periods of "negative" loss (caused by duplicate or out of
> order packets) weren't being accumulated into the cumulative loss
> counter. Example:
> Period 1: Received packets 1, 2, 4
> Loss over that period: 1 (expected 4 packets, got 3)
> Reported cumulative loss: 1
> Period 2: Received packets 3, 5
> Loss over that period: -1 (expected 1 packet, got 2)
> Reported cumulative loss: 1 (should be 0!)
>
> Landing with NOTRY because Android compile bots are broken for an
> unrelated reason.
> NOTRY=True
>
> Bug: webrtc:8804
> Change-Id: I840ba34de8957b1276f6bdaf93718f805629f5c8
> Reviewed-on: https://webrtc-review.googlesource.com/50020
> Commit-Queue: Taylor Brandstetter <deadbeef@webrtc.org>
> Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
> Reviewed-by: Oskar Sundbom <ossu@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#23731}
TBR=danilchap@webrtc.org,deadbeef@webrtc.org,ossu@webrtc.org
# Not skipping CQ checks because original CL landed > 1 day ago.
Landing with NOTRY because ios64_sim_ios10_dbg bot is broken.
Passing all other bots.
NOTRY=True
Bug: webrtc:8804
Change-Id: I07bd6b1206d5a8d211792ad392842f9ed6c505e9
Reviewed-on: https://webrtc-review.googlesource.com/95280
Commit-Queue: Qingsi Wang <qingsi@webrtc.org>
Reviewed-by: Qingsi Wang <qingsi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24370}
2018-08-21 14:24:26 -07:00
|
|
|
*statistics = CalculateRtcpStatistics();
|
2018-06-25 15:50:26 -07:00
|
|
|
}
|
Revert "Update packetsLost and jitter stats any time a packet is received."
This reverts commit 84916937b70472715efe5682bc273e91c3a72695.
Reason for revert: breaking downstream projects.
Original change's description:
> Update packetsLost and jitter stats any time a packet is received.
>
> Before this CL, the packetsLost and jitter stats (as returned by
> GetStats, at the API level) were only being updated when an RTCP SR or
> RR is generated. According to the stats spec, "local" stats like this
> should be updated any time a packet is received.
>
> This CL also fixes some minor issues with the calculation of packetsLost
> (and fractionLost):
> * Packets weren't being count as lost if lost over a sequence number
> rollover.
> * Temporary periods of "negative" loss (caused by duplicate or out of
> order packets) weren't being accumulated into the cumulative loss
> counter. Example:
> Period 1: Received packets 1, 2, 4
> Loss over that period: 1 (expected 4 packets, got 3)
> Reported cumulative loss: 1
> Period 2: Received packets 3, 5
> Loss over that period: -1 (expected 1 packet, got 2)
> Reported cumulative loss: 1 (should be 0!)
>
> Landing with NOTRY because Android compile bots are broken for an
> unrelated reason.
> NOTRY=True
>
> Bug: webrtc:8804
> Change-Id: I840ba34de8957b1276f6bdaf93718f805629f5c8
> Reviewed-on: https://webrtc-review.googlesource.com/50020
> Commit-Queue: Taylor Brandstetter <deadbeef@webrtc.org>
> Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
> Reviewed-by: Oskar Sundbom <ossu@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#23731}
TBR=danilchap@webrtc.org,deadbeef@webrtc.org,ossu@webrtc.org
# Not skipping CQ checks because original CL landed > 1 day ago.
Landing with NOTRY because ios64_sim_ios10_dbg bot is broken.
Passing all other bots.
NOTRY=True
Bug: webrtc:8804
Change-Id: I07bd6b1206d5a8d211792ad392842f9ed6c505e9
Reviewed-on: https://webrtc-review.googlesource.com/95280
Commit-Queue: Qingsi Wang <qingsi@webrtc.org>
Reviewed-by: Qingsi Wang <qingsi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24370}
2018-08-21 14:24:26 -07:00
|
|
|
|
2018-11-23 11:03:25 +01:00
|
|
|
if (rtcp_callback_)
|
|
|
|
|
rtcp_callback_->StatisticsUpdated(*statistics, ssrc_);
|
2014-01-21 16:33:37 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-18 13:57:19 +02:00
|
|
|
bool StreamStatisticianImpl::GetActiveStatisticsAndReset(
|
|
|
|
|
RtcpStatistics* statistics) {
|
|
|
|
|
{
|
|
|
|
|
rtc::CritScope cs(&stream_lock_);
|
2018-11-26 10:20:01 +01:00
|
|
|
if (clock_->TimeInMilliseconds() - last_receive_time_ms_ >=
|
2017-09-18 13:57:19 +02:00
|
|
|
kStatisticsTimeoutMs) {
|
|
|
|
|
// Not active.
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-12-05 14:55:46 +00:00
|
|
|
if (!ReceivedRtpPacket()) {
|
2017-09-18 13:57:19 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
Revert "Update packetsLost and jitter stats any time a packet is received."
This reverts commit 84916937b70472715efe5682bc273e91c3a72695.
Reason for revert: breaking downstream projects.
Original change's description:
> Update packetsLost and jitter stats any time a packet is received.
>
> Before this CL, the packetsLost and jitter stats (as returned by
> GetStats, at the API level) were only being updated when an RTCP SR or
> RR is generated. According to the stats spec, "local" stats like this
> should be updated any time a packet is received.
>
> This CL also fixes some minor issues with the calculation of packetsLost
> (and fractionLost):
> * Packets weren't being count as lost if lost over a sequence number
> rollover.
> * Temporary periods of "negative" loss (caused by duplicate or out of
> order packets) weren't being accumulated into the cumulative loss
> counter. Example:
> Period 1: Received packets 1, 2, 4
> Loss over that period: 1 (expected 4 packets, got 3)
> Reported cumulative loss: 1
> Period 2: Received packets 3, 5
> Loss over that period: -1 (expected 1 packet, got 2)
> Reported cumulative loss: 1 (should be 0!)
>
> Landing with NOTRY because Android compile bots are broken for an
> unrelated reason.
> NOTRY=True
>
> Bug: webrtc:8804
> Change-Id: I840ba34de8957b1276f6bdaf93718f805629f5c8
> Reviewed-on: https://webrtc-review.googlesource.com/50020
> Commit-Queue: Taylor Brandstetter <deadbeef@webrtc.org>
> Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
> Reviewed-by: Oskar Sundbom <ossu@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#23731}
TBR=danilchap@webrtc.org,deadbeef@webrtc.org,ossu@webrtc.org
# Not skipping CQ checks because original CL landed > 1 day ago.
Landing with NOTRY because ios64_sim_ios10_dbg bot is broken.
Passing all other bots.
NOTRY=True
Bug: webrtc:8804
Change-Id: I07bd6b1206d5a8d211792ad392842f9ed6c505e9
Reviewed-on: https://webrtc-review.googlesource.com/95280
Commit-Queue: Qingsi Wang <qingsi@webrtc.org>
Reviewed-by: Qingsi Wang <qingsi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24370}
2018-08-21 14:24:26 -07:00
|
|
|
*statistics = CalculateRtcpStatistics();
|
2017-09-18 13:57:19 +02:00
|
|
|
}
|
|
|
|
|
|
2018-11-23 11:03:25 +01:00
|
|
|
if (rtcp_callback_)
|
|
|
|
|
rtcp_callback_->StatisticsUpdated(*statistics, ssrc_);
|
2017-09-18 13:57:19 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
Revert "Update packetsLost and jitter stats any time a packet is received."
This reverts commit 84916937b70472715efe5682bc273e91c3a72695.
Reason for revert: breaking downstream projects.
Original change's description:
> Update packetsLost and jitter stats any time a packet is received.
>
> Before this CL, the packetsLost and jitter stats (as returned by
> GetStats, at the API level) were only being updated when an RTCP SR or
> RR is generated. According to the stats spec, "local" stats like this
> should be updated any time a packet is received.
>
> This CL also fixes some minor issues with the calculation of packetsLost
> (and fractionLost):
> * Packets weren't being count as lost if lost over a sequence number
> rollover.
> * Temporary periods of "negative" loss (caused by duplicate or out of
> order packets) weren't being accumulated into the cumulative loss
> counter. Example:
> Period 1: Received packets 1, 2, 4
> Loss over that period: 1 (expected 4 packets, got 3)
> Reported cumulative loss: 1
> Period 2: Received packets 3, 5
> Loss over that period: -1 (expected 1 packet, got 2)
> Reported cumulative loss: 1 (should be 0!)
>
> Landing with NOTRY because Android compile bots are broken for an
> unrelated reason.
> NOTRY=True
>
> Bug: webrtc:8804
> Change-Id: I840ba34de8957b1276f6bdaf93718f805629f5c8
> Reviewed-on: https://webrtc-review.googlesource.com/50020
> Commit-Queue: Taylor Brandstetter <deadbeef@webrtc.org>
> Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
> Reviewed-by: Oskar Sundbom <ossu@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#23731}
TBR=danilchap@webrtc.org,deadbeef@webrtc.org,ossu@webrtc.org
# Not skipping CQ checks because original CL landed > 1 day ago.
Landing with NOTRY because ios64_sim_ios10_dbg bot is broken.
Passing all other bots.
NOTRY=True
Bug: webrtc:8804
Change-Id: I07bd6b1206d5a8d211792ad392842f9ed6c505e9
Reviewed-on: https://webrtc-review.googlesource.com/95280
Commit-Queue: Qingsi Wang <qingsi@webrtc.org>
Reviewed-by: Qingsi Wang <qingsi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24370}
2018-08-21 14:24:26 -07:00
|
|
|
RtcpStatistics StreamStatisticianImpl::CalculateRtcpStatistics() {
|
|
|
|
|
RtcpStatistics stats;
|
|
|
|
|
// Calculate fraction lost.
|
2018-12-05 14:55:46 +00:00
|
|
|
int64_t exp_since_last = received_seq_max_ - last_report_seq_max_;
|
|
|
|
|
RTC_DCHECK_GE(exp_since_last, 0);
|
2013-12-19 13:26:02 +00:00
|
|
|
|
Revert "Update packetsLost and jitter stats any time a packet is received."
This reverts commit 84916937b70472715efe5682bc273e91c3a72695.
Reason for revert: breaking downstream projects.
Original change's description:
> Update packetsLost and jitter stats any time a packet is received.
>
> Before this CL, the packetsLost and jitter stats (as returned by
> GetStats, at the API level) were only being updated when an RTCP SR or
> RR is generated. According to the stats spec, "local" stats like this
> should be updated any time a packet is received.
>
> This CL also fixes some minor issues with the calculation of packetsLost
> (and fractionLost):
> * Packets weren't being count as lost if lost over a sequence number
> rollover.
> * Temporary periods of "negative" loss (caused by duplicate or out of
> order packets) weren't being accumulated into the cumulative loss
> counter. Example:
> Period 1: Received packets 1, 2, 4
> Loss over that period: 1 (expected 4 packets, got 3)
> Reported cumulative loss: 1
> Period 2: Received packets 3, 5
> Loss over that period: -1 (expected 1 packet, got 2)
> Reported cumulative loss: 1 (should be 0!)
>
> Landing with NOTRY because Android compile bots are broken for an
> unrelated reason.
> NOTRY=True
>
> Bug: webrtc:8804
> Change-Id: I840ba34de8957b1276f6bdaf93718f805629f5c8
> Reviewed-on: https://webrtc-review.googlesource.com/50020
> Commit-Queue: Taylor Brandstetter <deadbeef@webrtc.org>
> Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
> Reviewed-by: Oskar Sundbom <ossu@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#23731}
TBR=danilchap@webrtc.org,deadbeef@webrtc.org,ossu@webrtc.org
# Not skipping CQ checks because original CL landed > 1 day ago.
Landing with NOTRY because ios64_sim_ios10_dbg bot is broken.
Passing all other bots.
NOTRY=True
Bug: webrtc:8804
Change-Id: I07bd6b1206d5a8d211792ad392842f9ed6c505e9
Reviewed-on: https://webrtc-review.googlesource.com/95280
Commit-Queue: Qingsi Wang <qingsi@webrtc.org>
Reviewed-by: Qingsi Wang <qingsi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24370}
2018-08-21 14:24:26 -07:00
|
|
|
// Number of received RTP packets since last report, counts all packets but
|
|
|
|
|
// not re-transmissions.
|
|
|
|
|
uint32_t rec_since_last = (receive_counters_.transmitted.packets -
|
|
|
|
|
receive_counters_.retransmitted.packets) -
|
|
|
|
|
last_report_inorder_packets_;
|
|
|
|
|
|
|
|
|
|
// With NACK we don't know the expected retransmissions during the last
|
|
|
|
|
// second. We know how many "old" packets we have received. We just count
|
|
|
|
|
// the number of old received to estimate the loss, but it still does not
|
|
|
|
|
// guarantee an exact number since we run this based on time triggered by
|
|
|
|
|
// sending of an RTP packet. This should have a minimum effect.
|
|
|
|
|
|
|
|
|
|
// With NACK we don't count old packets as received since they are
|
|
|
|
|
// re-transmitted. We use RTT to decide if a packet is re-ordered or
|
|
|
|
|
// re-transmitted.
|
|
|
|
|
uint32_t retransmitted_packets =
|
|
|
|
|
receive_counters_.retransmitted.packets - last_report_old_packets_;
|
|
|
|
|
rec_since_last += retransmitted_packets;
|
|
|
|
|
|
|
|
|
|
int32_t missing = 0;
|
|
|
|
|
if (exp_since_last > rec_since_last) {
|
|
|
|
|
missing = (exp_since_last - rec_since_last);
|
|
|
|
|
}
|
|
|
|
|
uint8_t local_fraction_lost = 0;
|
|
|
|
|
if (exp_since_last) {
|
|
|
|
|
// Scale 0 to 255, where 255 is 100% loss.
|
|
|
|
|
local_fraction_lost = static_cast<uint8_t>(255 * missing / exp_since_last);
|
|
|
|
|
}
|
|
|
|
|
stats.fraction_lost = local_fraction_lost;
|
|
|
|
|
|
|
|
|
|
// We need a counter for cumulative loss too.
|
|
|
|
|
// TODO(danilchap): Ensure cumulative loss is below maximum value of 2^24.
|
|
|
|
|
cumulative_loss_ += missing;
|
|
|
|
|
stats.packets_lost = cumulative_loss_;
|
|
|
|
|
stats.extended_highest_sequence_number =
|
2018-12-05 14:55:46 +00:00
|
|
|
static_cast<uint32_t>(received_seq_max_);
|
2018-06-25 15:50:26 -07:00
|
|
|
// Note: internal jitter value is in Q4 and needs to be scaled by 1/16.
|
Revert "Update packetsLost and jitter stats any time a packet is received."
This reverts commit 84916937b70472715efe5682bc273e91c3a72695.
Reason for revert: breaking downstream projects.
Original change's description:
> Update packetsLost and jitter stats any time a packet is received.
>
> Before this CL, the packetsLost and jitter stats (as returned by
> GetStats, at the API level) were only being updated when an RTCP SR or
> RR is generated. According to the stats spec, "local" stats like this
> should be updated any time a packet is received.
>
> This CL also fixes some minor issues with the calculation of packetsLost
> (and fractionLost):
> * Packets weren't being count as lost if lost over a sequence number
> rollover.
> * Temporary periods of "negative" loss (caused by duplicate or out of
> order packets) weren't being accumulated into the cumulative loss
> counter. Example:
> Period 1: Received packets 1, 2, 4
> Loss over that period: 1 (expected 4 packets, got 3)
> Reported cumulative loss: 1
> Period 2: Received packets 3, 5
> Loss over that period: -1 (expected 1 packet, got 2)
> Reported cumulative loss: 1 (should be 0!)
>
> Landing with NOTRY because Android compile bots are broken for an
> unrelated reason.
> NOTRY=True
>
> Bug: webrtc:8804
> Change-Id: I840ba34de8957b1276f6bdaf93718f805629f5c8
> Reviewed-on: https://webrtc-review.googlesource.com/50020
> Commit-Queue: Taylor Brandstetter <deadbeef@webrtc.org>
> Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
> Reviewed-by: Oskar Sundbom <ossu@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#23731}
TBR=danilchap@webrtc.org,deadbeef@webrtc.org,ossu@webrtc.org
# Not skipping CQ checks because original CL landed > 1 day ago.
Landing with NOTRY because ios64_sim_ios10_dbg bot is broken.
Passing all other bots.
NOTRY=True
Bug: webrtc:8804
Change-Id: I07bd6b1206d5a8d211792ad392842f9ed6c505e9
Reviewed-on: https://webrtc-review.googlesource.com/95280
Commit-Queue: Qingsi Wang <qingsi@webrtc.org>
Reviewed-by: Qingsi Wang <qingsi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24370}
2018-08-21 14:24:26 -07:00
|
|
|
stats.jitter = jitter_q4_ >> 4;
|
|
|
|
|
|
|
|
|
|
// Store this report.
|
|
|
|
|
last_reported_statistics_ = stats;
|
2014-01-21 16:33:37 +00:00
|
|
|
|
Revert "Update packetsLost and jitter stats any time a packet is received."
This reverts commit 84916937b70472715efe5682bc273e91c3a72695.
Reason for revert: breaking downstream projects.
Original change's description:
> Update packetsLost and jitter stats any time a packet is received.
>
> Before this CL, the packetsLost and jitter stats (as returned by
> GetStats, at the API level) were only being updated when an RTCP SR or
> RR is generated. According to the stats spec, "local" stats like this
> should be updated any time a packet is received.
>
> This CL also fixes some minor issues with the calculation of packetsLost
> (and fractionLost):
> * Packets weren't being count as lost if lost over a sequence number
> rollover.
> * Temporary periods of "negative" loss (caused by duplicate or out of
> order packets) weren't being accumulated into the cumulative loss
> counter. Example:
> Period 1: Received packets 1, 2, 4
> Loss over that period: 1 (expected 4 packets, got 3)
> Reported cumulative loss: 1
> Period 2: Received packets 3, 5
> Loss over that period: -1 (expected 1 packet, got 2)
> Reported cumulative loss: 1 (should be 0!)
>
> Landing with NOTRY because Android compile bots are broken for an
> unrelated reason.
> NOTRY=True
>
> Bug: webrtc:8804
> Change-Id: I840ba34de8957b1276f6bdaf93718f805629f5c8
> Reviewed-on: https://webrtc-review.googlesource.com/50020
> Commit-Queue: Taylor Brandstetter <deadbeef@webrtc.org>
> Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
> Reviewed-by: Oskar Sundbom <ossu@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#23731}
TBR=danilchap@webrtc.org,deadbeef@webrtc.org,ossu@webrtc.org
# Not skipping CQ checks because original CL landed > 1 day ago.
Landing with NOTRY because ios64_sim_ios10_dbg bot is broken.
Passing all other bots.
NOTRY=True
Bug: webrtc:8804
Change-Id: I07bd6b1206d5a8d211792ad392842f9ed6c505e9
Reviewed-on: https://webrtc-review.googlesource.com/95280
Commit-Queue: Qingsi Wang <qingsi@webrtc.org>
Reviewed-by: Qingsi Wang <qingsi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24370}
2018-08-21 14:24:26 -07:00
|
|
|
// Only for report blocks in RTCP SR and RR.
|
|
|
|
|
last_report_inorder_packets_ = receive_counters_.transmitted.packets -
|
|
|
|
|
receive_counters_.retransmitted.packets;
|
|
|
|
|
last_report_old_packets_ = receive_counters_.retransmitted.packets;
|
|
|
|
|
last_report_seq_max_ = received_seq_max_;
|
2016-09-30 06:29:54 -07:00
|
|
|
BWE_TEST_LOGGING_PLOT_WITH_SSRC(1, "cumulative_loss_pkts",
|
2016-09-14 05:04:36 -07:00
|
|
|
clock_->TimeInMilliseconds(),
|
Revert "Update packetsLost and jitter stats any time a packet is received."
This reverts commit 84916937b70472715efe5682bc273e91c3a72695.
Reason for revert: breaking downstream projects.
Original change's description:
> Update packetsLost and jitter stats any time a packet is received.
>
> Before this CL, the packetsLost and jitter stats (as returned by
> GetStats, at the API level) were only being updated when an RTCP SR or
> RR is generated. According to the stats spec, "local" stats like this
> should be updated any time a packet is received.
>
> This CL also fixes some minor issues with the calculation of packetsLost
> (and fractionLost):
> * Packets weren't being count as lost if lost over a sequence number
> rollover.
> * Temporary periods of "negative" loss (caused by duplicate or out of
> order packets) weren't being accumulated into the cumulative loss
> counter. Example:
> Period 1: Received packets 1, 2, 4
> Loss over that period: 1 (expected 4 packets, got 3)
> Reported cumulative loss: 1
> Period 2: Received packets 3, 5
> Loss over that period: -1 (expected 1 packet, got 2)
> Reported cumulative loss: 1 (should be 0!)
>
> Landing with NOTRY because Android compile bots are broken for an
> unrelated reason.
> NOTRY=True
>
> Bug: webrtc:8804
> Change-Id: I840ba34de8957b1276f6bdaf93718f805629f5c8
> Reviewed-on: https://webrtc-review.googlesource.com/50020
> Commit-Queue: Taylor Brandstetter <deadbeef@webrtc.org>
> Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
> Reviewed-by: Oskar Sundbom <ossu@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#23731}
TBR=danilchap@webrtc.org,deadbeef@webrtc.org,ossu@webrtc.org
# Not skipping CQ checks because original CL landed > 1 day ago.
Landing with NOTRY because ios64_sim_ios10_dbg bot is broken.
Passing all other bots.
NOTRY=True
Bug: webrtc:8804
Change-Id: I07bd6b1206d5a8d211792ad392842f9ed6c505e9
Reviewed-on: https://webrtc-review.googlesource.com/95280
Commit-Queue: Qingsi Wang <qingsi@webrtc.org>
Reviewed-by: Qingsi Wang <qingsi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24370}
2018-08-21 14:24:26 -07:00
|
|
|
cumulative_loss_, ssrc_);
|
2016-09-14 05:04:36 -07:00
|
|
|
BWE_TEST_LOGGING_PLOT_WITH_SSRC(
|
2016-09-30 06:29:54 -07:00
|
|
|
1, "received_seq_max_pkts", clock_->TimeInMilliseconds(),
|
2016-09-14 05:04:36 -07:00
|
|
|
(received_seq_max_ - received_seq_first_), ssrc_);
|
2014-01-21 16:33:37 +00:00
|
|
|
|
Revert "Update packetsLost and jitter stats any time a packet is received."
This reverts commit 84916937b70472715efe5682bc273e91c3a72695.
Reason for revert: breaking downstream projects.
Original change's description:
> Update packetsLost and jitter stats any time a packet is received.
>
> Before this CL, the packetsLost and jitter stats (as returned by
> GetStats, at the API level) were only being updated when an RTCP SR or
> RR is generated. According to the stats spec, "local" stats like this
> should be updated any time a packet is received.
>
> This CL also fixes some minor issues with the calculation of packetsLost
> (and fractionLost):
> * Packets weren't being count as lost if lost over a sequence number
> rollover.
> * Temporary periods of "negative" loss (caused by duplicate or out of
> order packets) weren't being accumulated into the cumulative loss
> counter. Example:
> Period 1: Received packets 1, 2, 4
> Loss over that period: 1 (expected 4 packets, got 3)
> Reported cumulative loss: 1
> Period 2: Received packets 3, 5
> Loss over that period: -1 (expected 1 packet, got 2)
> Reported cumulative loss: 1 (should be 0!)
>
> Landing with NOTRY because Android compile bots are broken for an
> unrelated reason.
> NOTRY=True
>
> Bug: webrtc:8804
> Change-Id: I840ba34de8957b1276f6bdaf93718f805629f5c8
> Reviewed-on: https://webrtc-review.googlesource.com/50020
> Commit-Queue: Taylor Brandstetter <deadbeef@webrtc.org>
> Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
> Reviewed-by: Oskar Sundbom <ossu@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#23731}
TBR=danilchap@webrtc.org,deadbeef@webrtc.org,ossu@webrtc.org
# Not skipping CQ checks because original CL landed > 1 day ago.
Landing with NOTRY because ios64_sim_ios10_dbg bot is broken.
Passing all other bots.
NOTRY=True
Bug: webrtc:8804
Change-Id: I07bd6b1206d5a8d211792ad392842f9ed6c505e9
Reviewed-on: https://webrtc-review.googlesource.com/95280
Commit-Queue: Qingsi Wang <qingsi@webrtc.org>
Reviewed-by: Qingsi Wang <qingsi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24370}
2018-08-21 14:24:26 -07:00
|
|
|
return stats;
|
2013-08-15 23:38:54 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-21 20:58:21 +00:00
|
|
|
void StreamStatisticianImpl::GetDataCounters(size_t* bytes_received,
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
uint32_t* packets_received) const {
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope cs(&stream_lock_);
|
2013-08-15 23:38:54 +00:00
|
|
|
if (bytes_received) {
|
2015-01-22 09:39:59 +00:00
|
|
|
*bytes_received = receive_counters_.transmitted.payload_bytes +
|
|
|
|
|
receive_counters_.transmitted.header_bytes +
|
|
|
|
|
receive_counters_.transmitted.padding_bytes;
|
2013-08-15 23:38:54 +00:00
|
|
|
}
|
|
|
|
|
if (packets_received) {
|
2015-01-22 09:39:59 +00:00
|
|
|
*packets_received = receive_counters_.transmitted.packets;
|
2013-08-15 23:38:54 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-02 13:52:37 +02:00
|
|
|
absl::optional<int> StreamStatisticianImpl::GetFractionLostInPercent() const {
|
|
|
|
|
rtc::CritScope cs(&stream_lock_);
|
|
|
|
|
if (received_seq_max_ < 0) {
|
|
|
|
|
return absl::nullopt;
|
|
|
|
|
}
|
|
|
|
|
int64_t expected_packets = 1 + received_seq_max_ - received_seq_first_;
|
|
|
|
|
if (expected_packets <= 0) {
|
|
|
|
|
return absl::nullopt;
|
|
|
|
|
}
|
|
|
|
|
// Spec allows negative cumulative loss, but implementation uses uint32_t, so
|
|
|
|
|
// this expression is always non-negative.
|
|
|
|
|
return 100 * static_cast<int64_t>(cumulative_loss_) / expected_packets;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-27 07:38:56 +00:00
|
|
|
void StreamStatisticianImpl::GetReceiveStreamDataCounters(
|
|
|
|
|
StreamDataCounters* data_counters) const {
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope cs(&stream_lock_);
|
2014-11-27 07:38:56 +00:00
|
|
|
*data_counters = receive_counters_;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-21 20:58:21 +00:00
|
|
|
uint32_t StreamStatisticianImpl::BitrateReceived() const {
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope cs(&stream_lock_);
|
2016-07-13 09:11:28 -07:00
|
|
|
return incoming_bitrate_.Rate(clock_->TimeInMilliseconds()).value_or(0);
|
2013-08-21 20:58:21 +00:00
|
|
|
}
|
|
|
|
|
|
2013-09-06 13:40:11 +00:00
|
|
|
bool StreamStatisticianImpl::IsRetransmitOfOldPacket(
|
2018-11-22 11:28:45 +01:00
|
|
|
const RtpPacketReceived& packet,
|
|
|
|
|
int64_t now_ms) const {
|
2018-11-15 08:05:16 +01:00
|
|
|
uint32_t frequency_khz = packet.payload_type_frequency() / 1000;
|
2018-11-22 11:28:45 +01:00
|
|
|
RTC_DCHECK_GT(frequency_khz, 0);
|
2013-09-06 13:40:11 +00:00
|
|
|
|
2018-11-22 11:28:45 +01:00
|
|
|
int64_t time_diff_ms = now_ms - last_receive_time_ms_;
|
2013-09-06 13:40:11 +00:00
|
|
|
|
|
|
|
|
// Diff in time stamp since last received in order.
|
2018-11-15 08:05:16 +01:00
|
|
|
uint32_t timestamp_diff = packet.Timestamp() - last_received_timestamp_;
|
2015-01-12 21:51:21 +00:00
|
|
|
uint32_t rtp_time_stamp_diff_ms = timestamp_diff / frequency_khz;
|
2013-09-06 13:40:11 +00:00
|
|
|
|
2015-01-12 21:51:21 +00:00
|
|
|
int64_t max_delay_ms = 0;
|
2013-09-06 13:40:11 +00:00
|
|
|
|
2018-05-23 13:54:51 +02:00
|
|
|
// Jitter standard deviation in samples.
|
2019-04-23 08:50:04 +02:00
|
|
|
float jitter_std = std::sqrt(static_cast<float>(jitter_q4_ >> 4));
|
2013-09-06 13:40:11 +00:00
|
|
|
|
2018-05-23 13:54:51 +02:00
|
|
|
// 2 times the standard deviation => 95% confidence.
|
|
|
|
|
// And transform to milliseconds by dividing by the frequency in kHz.
|
|
|
|
|
max_delay_ms = static_cast<int64_t>((2 * jitter_std) / frequency_khz);
|
|
|
|
|
|
|
|
|
|
// Min max_delay_ms is 1.
|
|
|
|
|
if (max_delay_ms == 0) {
|
|
|
|
|
max_delay_ms = 1;
|
2013-09-06 13:40:11 +00:00
|
|
|
}
|
|
|
|
|
return time_diff_ms > rtp_time_stamp_diff_ms + max_delay_ms;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-23 11:03:25 +01:00
|
|
|
std::unique_ptr<ReceiveStatistics> ReceiveStatistics::Create(
|
|
|
|
|
Clock* clock,
|
|
|
|
|
RtcpStatisticsCallback* rtcp_callback,
|
|
|
|
|
StreamDataCountersCallback* rtp_callback) {
|
|
|
|
|
return absl::make_unique<ReceiveStatisticsImpl>(clock, rtcp_callback,
|
|
|
|
|
rtp_callback);
|
2013-08-21 20:58:21 +00:00
|
|
|
}
|
|
|
|
|
|
2018-11-23 11:03:25 +01:00
|
|
|
ReceiveStatisticsImpl::ReceiveStatisticsImpl(
|
|
|
|
|
Clock* clock,
|
|
|
|
|
RtcpStatisticsCallback* rtcp_callback,
|
|
|
|
|
StreamDataCountersCallback* rtp_callback)
|
2013-08-21 20:58:21 +00:00
|
|
|
: clock_(clock),
|
2018-01-16 11:07:18 +01:00
|
|
|
last_returned_ssrc_(0),
|
2018-11-22 14:04:02 +01:00
|
|
|
max_reordering_threshold_(kDefaultMaxReorderingThreshold),
|
2018-11-23 11:03:25 +01:00
|
|
|
rtcp_stats_callback_(rtcp_callback),
|
|
|
|
|
rtp_stats_callback_(rtp_callback) {}
|
2013-08-21 20:58:21 +00:00
|
|
|
|
|
|
|
|
ReceiveStatisticsImpl::~ReceiveStatisticsImpl() {
|
|
|
|
|
while (!statisticians_.empty()) {
|
|
|
|
|
delete statisticians_.begin()->second;
|
|
|
|
|
statisticians_.erase(statisticians_.begin());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-14 08:26:32 +02:00
|
|
|
void ReceiveStatisticsImpl::OnRtpPacket(const RtpPacketReceived& packet) {
|
2014-09-08 08:20:18 +00:00
|
|
|
// StreamStatisticianImpl instance is created once and only destroyed when
|
|
|
|
|
// this whole ReceiveStatisticsImpl is destroyed. StreamStatisticianImpl has
|
|
|
|
|
// it's own locking so don't hold receive_statistics_lock_ (potential
|
|
|
|
|
// deadlock).
|
2019-05-24 14:04:28 +02:00
|
|
|
GetOrCreateStatistician(packet.Ssrc())->OnRtpPacket(packet);
|
2014-01-23 10:00:39 +00:00
|
|
|
}
|
|
|
|
|
|
2018-09-14 08:26:32 +02:00
|
|
|
void ReceiveStatisticsImpl::FecPacketReceived(const RtpPacketReceived& packet) {
|
2019-05-24 14:04:28 +02:00
|
|
|
StreamStatisticianImpl* impl = GetStatistician(packet.Ssrc());
|
|
|
|
|
// Ignore FEC if it is the first packet.
|
|
|
|
|
if (impl) {
|
|
|
|
|
impl->FecPacketReceived(packet);
|
2014-09-08 08:20:18 +00:00
|
|
|
}
|
2013-08-21 20:58:21 +00:00
|
|
|
}
|
|
|
|
|
|
2019-05-24 14:04:28 +02:00
|
|
|
StreamStatisticianImpl* ReceiveStatisticsImpl::GetStatistician(
|
2013-08-21 20:58:21 +00:00
|
|
|
uint32_t ssrc) const {
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope cs(&receive_statistics_lock_);
|
2019-05-24 14:04:28 +02:00
|
|
|
const auto& it = statisticians_.find(ssrc);
|
2013-08-21 20:58:21 +00:00
|
|
|
if (it == statisticians_.end())
|
|
|
|
|
return NULL;
|
|
|
|
|
return it->second;
|
2013-08-21 16:22:21 +00:00
|
|
|
}
|
|
|
|
|
|
2019-05-24 14:04:28 +02:00
|
|
|
StreamStatisticianImpl* ReceiveStatisticsImpl::GetOrCreateStatistician(
|
|
|
|
|
uint32_t ssrc) {
|
|
|
|
|
rtc::CritScope cs(&receive_statistics_lock_);
|
|
|
|
|
StreamStatisticianImpl*& impl = statisticians_[ssrc];
|
|
|
|
|
if (impl == nullptr) { // new element
|
|
|
|
|
impl =
|
|
|
|
|
new StreamStatisticianImpl(ssrc, clock_, max_reordering_threshold_,
|
|
|
|
|
rtcp_stats_callback_, rtp_stats_callback_);
|
|
|
|
|
}
|
|
|
|
|
return impl;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-06 13:40:11 +00:00
|
|
|
void ReceiveStatisticsImpl::SetMaxReorderingThreshold(
|
|
|
|
|
int max_reordering_threshold) {
|
2018-11-22 14:04:02 +01:00
|
|
|
std::map<uint32_t, StreamStatisticianImpl*> statisticians;
|
|
|
|
|
{
|
|
|
|
|
rtc::CritScope cs(&receive_statistics_lock_);
|
|
|
|
|
max_reordering_threshold_ = max_reordering_threshold;
|
|
|
|
|
statisticians = statisticians_;
|
|
|
|
|
}
|
|
|
|
|
for (auto& statistician : statisticians) {
|
2017-09-18 13:57:19 +02:00
|
|
|
statistician.second->SetMaxReorderingThreshold(max_reordering_threshold);
|
2013-09-06 13:40:11 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-24 14:04:28 +02:00
|
|
|
void ReceiveStatisticsImpl::SetMaxReorderingThreshold(
|
|
|
|
|
uint32_t ssrc,
|
|
|
|
|
int max_reordering_threshold) {
|
|
|
|
|
GetOrCreateStatistician(ssrc)->SetMaxReorderingThreshold(
|
|
|
|
|
max_reordering_threshold);
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-27 13:27:05 +02:00
|
|
|
void ReceiveStatisticsImpl::EnableRetransmitDetection(uint32_t ssrc,
|
|
|
|
|
bool enable) {
|
2019-05-24 14:04:28 +02:00
|
|
|
GetOrCreateStatistician(ssrc)->EnableRetransmitDetection(enable);
|
2018-08-27 13:27:05 +02:00
|
|
|
}
|
|
|
|
|
|
2017-08-11 08:12:54 -07:00
|
|
|
std::vector<rtcp::ReportBlock> ReceiveStatisticsImpl::RtcpReportBlocks(
|
2017-07-27 04:44:18 -07:00
|
|
|
size_t max_blocks) {
|
2017-09-18 13:57:19 +02:00
|
|
|
std::map<uint32_t, StreamStatisticianImpl*> statisticians;
|
|
|
|
|
{
|
|
|
|
|
rtc::CritScope cs(&receive_statistics_lock_);
|
|
|
|
|
statisticians = statisticians_;
|
|
|
|
|
}
|
2017-07-27 04:44:18 -07:00
|
|
|
std::vector<rtcp::ReportBlock> result;
|
|
|
|
|
result.reserve(std::min(max_blocks, statisticians.size()));
|
2018-01-16 11:07:18 +01:00
|
|
|
auto add_report_block = [&result](uint32_t media_ssrc,
|
|
|
|
|
StreamStatisticianImpl* statistician) {
|
2017-07-27 04:44:18 -07:00
|
|
|
// Do we have receive statistics to send?
|
|
|
|
|
RtcpStatistics stats;
|
2018-01-16 11:07:18 +01:00
|
|
|
if (!statistician->GetActiveStatisticsAndReset(&stats))
|
|
|
|
|
return;
|
2017-07-27 04:44:18 -07:00
|
|
|
result.emplace_back();
|
|
|
|
|
rtcp::ReportBlock& block = result.back();
|
2018-01-16 11:07:18 +01:00
|
|
|
block.SetMediaSsrc(media_ssrc);
|
2017-07-27 04:44:18 -07:00
|
|
|
block.SetFractionLost(stats.fraction_lost);
|
2017-08-04 05:03:53 -07:00
|
|
|
if (!block.SetCumulativeLost(stats.packets_lost)) {
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_WARNING) << "Cumulative lost is oversized.";
|
2017-07-27 04:44:18 -07:00
|
|
|
result.pop_back();
|
2018-01-16 11:07:18 +01:00
|
|
|
return;
|
2017-07-27 04:44:18 -07:00
|
|
|
}
|
2017-08-04 05:03:53 -07:00
|
|
|
block.SetExtHighestSeqNum(stats.extended_highest_sequence_number);
|
2017-07-27 04:44:18 -07:00
|
|
|
block.SetJitter(stats.jitter);
|
2018-01-16 11:07:18 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const auto start_it = statisticians.upper_bound(last_returned_ssrc_);
|
|
|
|
|
for (auto it = start_it;
|
|
|
|
|
result.size() < max_blocks && it != statisticians.end(); ++it)
|
|
|
|
|
add_report_block(it->first, it->second);
|
|
|
|
|
for (auto it = statisticians.begin();
|
|
|
|
|
result.size() < max_blocks && it != start_it; ++it)
|
|
|
|
|
add_report_block(it->first, it->second);
|
|
|
|
|
|
|
|
|
|
if (!result.empty())
|
|
|
|
|
last_returned_ssrc_ = result.back().source_ssrc();
|
2017-07-27 04:44:18 -07:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-15 23:38:54 +00:00
|
|
|
} // namespace webrtc
|