webrtc_m130/modules/rtp_rtcp/source/receive_statistics_impl.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

142 lines
5.6 KiB
C
Raw Normal View History

/*
* 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.
*/
#ifndef MODULES_RTP_RTCP_SOURCE_RECEIVE_STATISTICS_IMPL_H_
#define MODULES_RTP_RTCP_SOURCE_RECEIVE_STATISTICS_IMPL_H_
#include "modules/rtp_rtcp/include/receive_statistics.h"
#include <algorithm>
#include <map>
#include <vector>
#include "rtc_base/criticalsection.h"
#include "rtc_base/rate_statistics.h"
#include "system_wrappers/include/ntp_time.h"
namespace webrtc {
class StreamStatisticianImpl : public StreamStatistician,
public RtpPacketSinkInterface {
public:
StreamStatisticianImpl(uint32_t ssrc,
Clock* clock,
bool enable_retransmit_detection,
RtcpStatisticsCallback* rtcp_callback,
StreamDataCountersCallback* rtp_callback);
~StreamStatisticianImpl() override;
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;
bool GetActiveStatisticsAndReset(RtcpStatistics* statistics);
void GetDataCounters(size_t* bytes_received,
uint32_t* packets_received) const override;
void GetReceiveStreamDataCounters(
StreamDataCounters* data_counters) const override;
uint32_t BitrateReceived() const override;
// Implements RtpPacketSinkInterface
void OnRtpPacket(const RtpPacketReceived& packet) override;
void FecPacketReceived(const RtpPacketReceived& packet);
void SetMaxReorderingThreshold(int max_reordering_threshold);
void EnableRetransmitDetection(bool enable);
private:
bool IsRetransmitOfOldPacket(const RtpPacketReceived& packet) const
RTC_EXCLUSIVE_LOCKS_REQUIRED(stream_lock_);
bool InOrderPacketInternal(uint16_t sequence_number) const
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()
RTC_EXCLUSIVE_LOCKS_REQUIRED(stream_lock_);
void UpdateJitter(const RtpPacketReceived& packet, NtpTime receive_time)
RTC_EXCLUSIVE_LOCKS_REQUIRED(stream_lock_);
StreamDataCounters UpdateCounters(const RtpPacketReceived& packet,
bool retransmitted)
RTC_EXCLUSIVE_LOCKS_REQUIRED(stream_lock_);
const uint32_t ssrc_;
Clock* const clock_;
rtc::CriticalSection stream_lock_;
RateStatistics incoming_bitrate_ RTC_GUARDED_BY(&stream_lock_);
// In number of packets or sequence numbers.
int max_reordering_threshold_ RTC_GUARDED_BY(&stream_lock_);
bool enable_retransmit_detection_ RTC_GUARDED_BY(&stream_lock_);
// Stats on received RTP packets.
uint32_t jitter_q4_ RTC_GUARDED_BY(&stream_lock_);
uint32_t cumulative_loss_ RTC_GUARDED_BY(&stream_lock_);
int64_t last_receive_time_ms_ RTC_GUARDED_BY(&stream_lock_);
NtpTime last_receive_time_ntp_ RTC_GUARDED_BY(&stream_lock_);
uint32_t last_received_timestamp_ RTC_GUARDED_BY(&stream_lock_);
uint16_t received_seq_first_ RTC_GUARDED_BY(&stream_lock_);
uint16_t received_seq_max_ RTC_GUARDED_BY(&stream_lock_);
uint16_t received_seq_wraps_ RTC_GUARDED_BY(&stream_lock_);
// Current counter values.
size_t received_packet_overhead_ RTC_GUARDED_BY(&stream_lock_);
StreamDataCounters receive_counters_ RTC_GUARDED_BY(&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
// Counter values when we sent the last report.
uint32_t last_report_inorder_packets_ RTC_GUARDED_BY(&stream_lock_);
uint32_t last_report_old_packets_ RTC_GUARDED_BY(&stream_lock_);
uint16_t last_report_seq_max_ RTC_GUARDED_BY(&stream_lock_);
RtcpStatistics last_reported_statistics_ RTC_GUARDED_BY(&stream_lock_);
// stream_lock_ shouldn't be held when calling callbacks.
RtcpStatisticsCallback* const rtcp_callback_;
StreamDataCountersCallback* const rtp_callback_;
};
class ReceiveStatisticsImpl : public ReceiveStatistics,
public RtcpStatisticsCallback,
public StreamDataCountersCallback {
public:
explicit ReceiveStatisticsImpl(Clock* clock);
~ReceiveStatisticsImpl() override;
// Implements ReceiveStatisticsProvider.
std::vector<rtcp::ReportBlock> RtcpReportBlocks(size_t max_blocks) override;
// Implements RtpPacketSinkInterface
void OnRtpPacket(const RtpPacketReceived& packet) override;
// Implements ReceiveStatistics.
void FecPacketReceived(const RtpPacketReceived& packet) override;
StreamStatistician* GetStatistician(uint32_t ssrc) const override;
void SetMaxReorderingThreshold(int max_reordering_threshold) override;
void EnableRetransmitDetection(uint32_t ssrc, bool enable) override;
void RegisterRtcpStatisticsCallback(
RtcpStatisticsCallback* callback) override;
void RegisterRtpStatisticsCallback(
StreamDataCountersCallback* callback) override;
private:
void StatisticsUpdated(const RtcpStatistics& statistics,
uint32_t ssrc) override;
void CNameChanged(const char* cname, uint32_t ssrc) override;
void DataCountersUpdated(const StreamDataCounters& counters,
uint32_t ssrc) override;
Clock* const clock_;
rtc::CriticalSection receive_statistics_lock_;
uint32_t last_returned_ssrc_;
std::map<uint32_t, StreamStatisticianImpl*> statisticians_;
RtcpStatisticsCallback* rtcp_stats_callback_;
StreamDataCountersCallback* rtp_stats_callback_;
};
} // namespace webrtc
#endif // MODULES_RTP_RTCP_SOURCE_RECEIVE_STATISTICS_IMPL_H_