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
|
|
|
#ifndef MODULES_RTP_RTCP_SOURCE_RECEIVE_STATISTICS_IMPL_H_
|
|
|
|
|
#define MODULES_RTP_RTCP_SOURCE_RECEIVE_STATISTICS_IMPL_H_
|
2013-08-15 23:38:54 +00:00
|
|
|
|
|
|
|
|
#include <algorithm>
|
2015-12-10 05:05:27 -08:00
|
|
|
#include <map>
|
2017-08-11 08:12:54 -07:00
|
|
|
#include <vector>
|
2013-08-15 23:38:54 +00:00
|
|
|
|
2018-12-05 14:55:46 +00:00
|
|
|
#include "absl/types/optional.h"
|
|
|
|
|
#include "modules/include/module_common_types_public.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/rtp_rtcp/include/receive_statistics.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/critical_section.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/rate_statistics.h"
|
2018-11-22 14:04:02 +01:00
|
|
|
#include "rtc_base/thread_annotations.h"
|
2013-08-15 23:38:54 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2018-11-15 08:05:16 +01:00
|
|
|
class StreamStatisticianImpl : public StreamStatistician,
|
|
|
|
|
public RtpPacketSinkInterface {
|
2013-08-15 23:38:54 +00:00
|
|
|
public:
|
2017-08-14 05:51:02 -07:00
|
|
|
StreamStatisticianImpl(uint32_t ssrc,
|
|
|
|
|
Clock* clock,
|
2018-11-22 14:04:02 +01:00
|
|
|
int max_reordering_threshold,
|
2014-01-23 10:00:39 +00:00
|
|
|
StreamDataCountersCallback* rtp_callback);
|
2018-02-07 09:38:31 +01:00
|
|
|
~StreamStatisticianImpl() override;
|
2013-08-21 16:22:21 +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
|
|
|
// |reset| here and in next method restarts calculation of fraction_lost stat.
|
|
|
|
|
bool GetStatistics(RtcpStatistics* statistics, bool reset) override;
|
2017-09-18 13:57:19 +02:00
|
|
|
bool GetActiveStatisticsAndReset(RtcpStatistics* statistics);
|
2019-08-02 13:52:37 +02:00
|
|
|
absl::optional<int> GetFractionLostInPercent() const override;
|
2019-08-12 12:16:31 +02:00
|
|
|
StreamDataCounters GetReceiveStreamDataCounters() const override;
|
2015-03-04 12:58:35 +00:00
|
|
|
uint32_t BitrateReceived() const override;
|
2013-08-21 20:58:21 +00:00
|
|
|
|
2018-11-15 08:05:16 +01:00
|
|
|
// Implements RtpPacketSinkInterface
|
|
|
|
|
void OnRtpPacket(const RtpPacketReceived& packet) override;
|
|
|
|
|
|
|
|
|
|
void FecPacketReceived(const RtpPacketReceived& packet);
|
2013-09-06 13:40:11 +00:00
|
|
|
void SetMaxReorderingThreshold(int max_reordering_threshold);
|
2018-08-27 13:27:05 +02:00
|
|
|
void EnableRetransmitDetection(bool enable);
|
2013-08-15 23:38:54 +00:00
|
|
|
|
|
|
|
|
private:
|
2018-11-22 11:28:45 +01:00
|
|
|
bool IsRetransmitOfOldPacket(const RtpPacketReceived& packet,
|
|
|
|
|
int64_t now_ms) const
|
2018-08-27 12:32:21 +02:00
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(stream_lock_);
|
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 CalculateRtcpStatistics()
|
2017-09-07 07:53:45 -07:00
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(stream_lock_);
|
2018-11-26 10:20:01 +01:00
|
|
|
void UpdateJitter(const RtpPacketReceived& packet, int64_t receive_time_ms)
|
2018-08-27 12:32:21 +02:00
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(stream_lock_);
|
2018-12-05 14:55:46 +00:00
|
|
|
// Updates StreamStatistician for out of order packets.
|
|
|
|
|
// Returns true if packet considered to be out of order.
|
|
|
|
|
bool UpdateOutOfOrder(const RtpPacketReceived& packet,
|
|
|
|
|
int64_t sequence_number,
|
|
|
|
|
int64_t now_ms)
|
|
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(stream_lock_);
|
|
|
|
|
// Updates StreamStatistician for incoming packets.
|
2018-11-22 11:28:45 +01:00
|
|
|
StreamDataCounters UpdateCounters(const RtpPacketReceived& packet);
|
2018-12-05 14:55:46 +00:00
|
|
|
// Checks if this StreamStatistician received any rtp packets.
|
|
|
|
|
bool ReceivedRtpPacket() const RTC_EXCLUSIVE_LOCKS_REQUIRED(stream_lock_) {
|
|
|
|
|
return received_seq_max_ >= 0;
|
|
|
|
|
}
|
2013-09-06 13:40:11 +00:00
|
|
|
|
2017-08-14 05:51:02 -07:00
|
|
|
const uint32_t ssrc_;
|
2016-07-13 09:11:28 -07:00
|
|
|
Clock* const clock_;
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CriticalSection stream_lock_;
|
2018-08-27 12:32:21 +02:00
|
|
|
RateStatistics incoming_bitrate_ RTC_GUARDED_BY(&stream_lock_);
|
|
|
|
|
// In number of packets or sequence numbers.
|
|
|
|
|
int max_reordering_threshold_ RTC_GUARDED_BY(&stream_lock_);
|
2018-08-27 13:27:05 +02:00
|
|
|
bool enable_retransmit_detection_ RTC_GUARDED_BY(&stream_lock_);
|
2013-08-21 20:58:21 +00:00
|
|
|
|
2013-08-15 23:38:54 +00:00
|
|
|
// Stats on received RTP packets.
|
2018-08-27 12:32:21 +02:00
|
|
|
uint32_t jitter_q4_ RTC_GUARDED_BY(&stream_lock_);
|
|
|
|
|
uint32_t cumulative_loss_ RTC_GUARDED_BY(&stream_lock_);
|
2013-08-15 23:38:54 +00:00
|
|
|
|
2018-08-27 12:32:21 +02:00
|
|
|
int64_t last_receive_time_ms_ RTC_GUARDED_BY(&stream_lock_);
|
|
|
|
|
uint32_t last_received_timestamp_ RTC_GUARDED_BY(&stream_lock_);
|
2018-12-05 14:55:46 +00:00
|
|
|
SequenceNumberUnwrapper seq_unwrapper_ RTC_GUARDED_BY(&stream_lock_);
|
|
|
|
|
int64_t received_seq_first_ RTC_GUARDED_BY(&stream_lock_);
|
|
|
|
|
int64_t received_seq_max_ RTC_GUARDED_BY(&stream_lock_);
|
|
|
|
|
// Assume that the other side restarted when there are two sequential packets
|
|
|
|
|
// with large jump from received_seq_max_.
|
|
|
|
|
absl::optional<uint16_t> received_seq_out_of_order_
|
|
|
|
|
RTC_GUARDED_BY(&stream_lock_);
|
2013-08-15 23:38:54 +00:00
|
|
|
|
|
|
|
|
// Current counter values.
|
2018-08-27 12:32:21 +02:00
|
|
|
StreamDataCounters receive_counters_ RTC_GUARDED_BY(&stream_lock_);
|
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
|
|
|
// Counter values when we sent the last report.
|
2018-08-27 12:32:21 +02:00
|
|
|
uint32_t last_report_inorder_packets_ RTC_GUARDED_BY(&stream_lock_);
|
|
|
|
|
uint32_t last_report_old_packets_ RTC_GUARDED_BY(&stream_lock_);
|
2018-12-05 14:55:46 +00:00
|
|
|
int64_t last_report_seq_max_ RTC_GUARDED_BY(&stream_lock_);
|
2018-08-27 12:32:21 +02:00
|
|
|
RtcpStatistics last_reported_statistics_ RTC_GUARDED_BY(&stream_lock_);
|
2013-12-19 13:26:02 +00:00
|
|
|
|
2017-08-14 05:51:02 -07:00
|
|
|
// stream_lock_ shouldn't be held when calling callbacks.
|
2014-01-23 10:00:39 +00:00
|
|
|
StreamDataCountersCallback* const rtp_callback_;
|
2013-08-21 20:58:21 +00:00
|
|
|
};
|
|
|
|
|
|
2018-11-23 11:03:25 +01:00
|
|
|
class ReceiveStatisticsImpl : public ReceiveStatistics {
|
2013-08-21 20:58:21 +00:00
|
|
|
public:
|
2018-11-23 11:03:25 +01:00
|
|
|
ReceiveStatisticsImpl(Clock* clock,
|
|
|
|
|
StreamDataCountersCallback* rtp_callback);
|
2013-08-21 20:58:21 +00:00
|
|
|
|
2018-02-07 09:38:31 +01:00
|
|
|
~ReceiveStatisticsImpl() override;
|
2013-08-21 20:58:21 +00:00
|
|
|
|
2018-11-15 08:05:16 +01:00
|
|
|
// Implements ReceiveStatisticsProvider.
|
2017-08-11 08:12:54 -07:00
|
|
|
std::vector<rtcp::ReportBlock> RtcpReportBlocks(size_t max_blocks) override;
|
|
|
|
|
|
2018-11-15 08:05:16 +01:00
|
|
|
// Implements RtpPacketSinkInterface
|
2018-09-14 08:26:32 +02:00
|
|
|
void OnRtpPacket(const RtpPacketReceived& packet) override;
|
|
|
|
|
|
2018-11-15 08:05:16 +01:00
|
|
|
// Implements ReceiveStatistics.
|
2018-09-14 08:26:32 +02:00
|
|
|
void FecPacketReceived(const RtpPacketReceived& packet) override;
|
2019-05-24 14:04:28 +02:00
|
|
|
// Note: More specific return type for use in the implementation.
|
|
|
|
|
StreamStatisticianImpl* GetStatistician(uint32_t ssrc) const override;
|
2015-03-04 12:58:35 +00:00
|
|
|
void SetMaxReorderingThreshold(int max_reordering_threshold) override;
|
2019-05-24 14:04:28 +02:00
|
|
|
void SetMaxReorderingThreshold(uint32_t ssrc,
|
|
|
|
|
int max_reordering_threshold) override;
|
2018-08-27 13:27:05 +02:00
|
|
|
void EnableRetransmitDetection(uint32_t ssrc, bool enable) override;
|
2013-08-21 20:58:21 +00:00
|
|
|
|
2014-01-23 10:00:39 +00:00
|
|
|
private:
|
2019-05-24 14:04:28 +02:00
|
|
|
StreamStatisticianImpl* GetOrCreateStatistician(uint32_t ssrc);
|
|
|
|
|
|
2016-07-13 09:11:28 -07:00
|
|
|
Clock* const clock_;
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CriticalSection receive_statistics_lock_;
|
2018-01-16 11:07:18 +01:00
|
|
|
uint32_t last_returned_ssrc_;
|
2018-11-22 14:04:02 +01:00
|
|
|
int max_reordering_threshold_ RTC_GUARDED_BY(receive_statistics_lock_);
|
|
|
|
|
std::map<uint32_t, StreamStatisticianImpl*> statisticians_
|
|
|
|
|
RTC_GUARDED_BY(receive_statistics_lock_);
|
2013-12-19 13:26:02 +00:00
|
|
|
|
2018-11-23 11:03:25 +01:00
|
|
|
StreamDataCountersCallback* const rtp_stats_callback_;
|
2013-08-15 23:38:54 +00:00
|
|
|
};
|
|
|
|
|
} // namespace webrtc
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // MODULES_RTP_RTCP_SOURCE_RECEIVE_STATISTICS_IMPL_H_
|