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
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/rtp_rtcp/include/receive_statistics.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
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/criticalsection.h"
|
|
|
|
|
#include "rtc_base/rate_statistics.h"
|
|
|
|
|
#include "system_wrappers/include/ntp_time.h"
|
2013-08-15 23:38:54 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2013-08-21 20:58:21 +00:00
|
|
|
class StreamStatisticianImpl : public StreamStatistician {
|
2013-08-15 23:38:54 +00:00
|
|
|
public:
|
2017-08-14 05:51:02 -07:00
|
|
|
StreamStatisticianImpl(uint32_t ssrc,
|
|
|
|
|
Clock* clock,
|
2014-01-23 10:00:39 +00:00
|
|
|
RtcpStatisticsCallback* rtcp_callback,
|
|
|
|
|
StreamDataCountersCallback* rtp_callback);
|
2013-08-21 20:58:21 +00:00
|
|
|
virtual ~StreamStatisticianImpl() {}
|
2013-08-21 16:22:21 +00:00
|
|
|
|
2015-03-04 12:58:35 +00:00
|
|
|
bool GetStatistics(RtcpStatistics* statistics, bool reset) override;
|
|
|
|
|
void GetDataCounters(size_t* bytes_received,
|
|
|
|
|
uint32_t* packets_received) const override;
|
|
|
|
|
void GetReceiveStreamDataCounters(
|
|
|
|
|
StreamDataCounters* data_counters) const override;
|
|
|
|
|
uint32_t BitrateReceived() const override;
|
|
|
|
|
bool IsRetransmitOfOldPacket(const RTPHeader& header,
|
|
|
|
|
int64_t min_rtt) const override;
|
|
|
|
|
bool IsPacketInOrder(uint16_t sequence_number) const override;
|
2013-08-21 20:58:21 +00:00
|
|
|
|
2014-01-23 10:00:39 +00:00
|
|
|
void IncomingPacket(const RTPHeader& rtp_header,
|
2014-12-09 09:47:53 +00:00
|
|
|
size_t packet_length,
|
2013-09-06 13:40:11 +00:00
|
|
|
bool retransmitted);
|
2015-01-27 12:17:29 +00:00
|
|
|
void FecPacketReceived(const RTPHeader& header, size_t packet_length);
|
2013-09-06 13:40:11 +00:00
|
|
|
void SetMaxReorderingThreshold(int max_reordering_threshold);
|
2013-08-21 20:58:21 +00:00
|
|
|
virtual void LastReceiveTimeNtp(uint32_t* secs, uint32_t* frac) const;
|
2013-08-15 23:38:54 +00:00
|
|
|
|
|
|
|
|
private:
|
2013-09-06 13:40:11 +00:00
|
|
|
bool InOrderPacketInternal(uint16_t sequence_number) const;
|
2017-08-14 05:51:02 -07:00
|
|
|
RtcpStatistics CalculateRtcpStatistics()
|
2017-09-07 07:53:45 -07:00
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(stream_lock_);
|
2015-12-21 11:06:50 -08:00
|
|
|
void UpdateJitter(const RTPHeader& header, NtpTime receive_time);
|
2017-08-14 05:51:02 -07:00
|
|
|
StreamDataCounters UpdateCounters(const RTPHeader& rtp_header,
|
|
|
|
|
size_t packet_length,
|
|
|
|
|
bool retransmitted);
|
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_;
|
2016-07-13 09:11:28 -07:00
|
|
|
RateStatistics incoming_bitrate_;
|
2013-09-06 13:40:11 +00:00
|
|
|
int max_reordering_threshold_; // In number of packets or sequence numbers.
|
2013-08-21 20:58:21 +00:00
|
|
|
|
2013-08-15 23:38:54 +00:00
|
|
|
// Stats on received RTP packets.
|
|
|
|
|
uint32_t jitter_q4_;
|
|
|
|
|
uint32_t cumulative_loss_;
|
|
|
|
|
uint32_t jitter_q4_transmission_time_offset_;
|
|
|
|
|
|
2013-09-06 13:40:11 +00:00
|
|
|
int64_t last_receive_time_ms_;
|
2015-12-21 11:06:50 -08:00
|
|
|
NtpTime last_receive_time_ntp_;
|
2013-08-15 23:38:54 +00:00
|
|
|
uint32_t last_received_timestamp_;
|
|
|
|
|
int32_t last_received_transmission_time_offset_;
|
|
|
|
|
uint16_t received_seq_first_;
|
|
|
|
|
uint16_t received_seq_max_;
|
|
|
|
|
uint16_t received_seq_wraps_;
|
|
|
|
|
|
|
|
|
|
// Current counter values.
|
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
|
|
|
size_t received_packet_overhead_;
|
2014-01-23 10:00:39 +00:00
|
|
|
StreamDataCounters receive_counters_;
|
2013-08-15 23:38:54 +00:00
|
|
|
|
|
|
|
|
// Counter values when we sent the last report.
|
|
|
|
|
uint32_t last_report_inorder_packets_;
|
|
|
|
|
uint32_t last_report_old_packets_;
|
|
|
|
|
uint16_t last_report_seq_max_;
|
2013-12-19 13:26:02 +00:00
|
|
|
RtcpStatistics last_reported_statistics_;
|
|
|
|
|
|
2017-08-14 05:51:02 -07:00
|
|
|
// stream_lock_ shouldn't be held when calling callbacks.
|
2013-12-19 13:26:02 +00:00
|
|
|
RtcpStatisticsCallback* const rtcp_callback_;
|
2014-01-23 10:00:39 +00:00
|
|
|
StreamDataCountersCallback* const rtp_callback_;
|
2013-08-21 20:58:21 +00:00
|
|
|
};
|
|
|
|
|
|
2013-12-19 13:26:02 +00:00
|
|
|
class ReceiveStatisticsImpl : public ReceiveStatistics,
|
2014-01-23 10:00:39 +00:00
|
|
|
public RtcpStatisticsCallback,
|
|
|
|
|
public StreamDataCountersCallback {
|
2013-08-21 20:58:21 +00:00
|
|
|
public:
|
|
|
|
|
explicit ReceiveStatisticsImpl(Clock* clock);
|
|
|
|
|
|
|
|
|
|
~ReceiveStatisticsImpl();
|
|
|
|
|
|
2017-08-11 08:12:54 -07:00
|
|
|
// Implement ReceiveStatisticsProvider.
|
|
|
|
|
std::vector<rtcp::ReportBlock> RtcpReportBlocks(size_t max_blocks) override;
|
|
|
|
|
|
2013-08-21 20:58:21 +00:00
|
|
|
// Implement ReceiveStatistics.
|
2015-03-04 12:58:35 +00:00
|
|
|
void IncomingPacket(const RTPHeader& header,
|
|
|
|
|
size_t packet_length,
|
|
|
|
|
bool retransmitted) override;
|
|
|
|
|
void FecPacketReceived(const RTPHeader& header,
|
|
|
|
|
size_t packet_length) override;
|
|
|
|
|
StatisticianMap GetActiveStatisticians() const override;
|
|
|
|
|
StreamStatistician* GetStatistician(uint32_t ssrc) const override;
|
|
|
|
|
void SetMaxReorderingThreshold(int max_reordering_threshold) override;
|
2013-08-21 20:58:21 +00:00
|
|
|
|
2015-03-04 12:58:35 +00:00
|
|
|
void RegisterRtcpStatisticsCallback(
|
|
|
|
|
RtcpStatisticsCallback* callback) override;
|
2013-12-19 13:26:02 +00:00
|
|
|
|
2015-03-04 12:58:35 +00:00
|
|
|
void RegisterRtpStatisticsCallback(
|
|
|
|
|
StreamDataCountersCallback* callback) override;
|
2014-01-23 10:00:39 +00:00
|
|
|
|
|
|
|
|
private:
|
2015-03-04 12:58:35 +00:00
|
|
|
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;
|
2013-12-19 13:26:02 +00:00
|
|
|
|
2013-08-21 20:58:21 +00:00
|
|
|
typedef std::map<uint32_t, StreamStatisticianImpl*> StatisticianImplMap;
|
|
|
|
|
|
2016-07-13 09:11:28 -07:00
|
|
|
Clock* const clock_;
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CriticalSection receive_statistics_lock_;
|
2013-08-21 20:58:21 +00:00
|
|
|
StatisticianImplMap statisticians_;
|
2013-12-19 13:26:02 +00:00
|
|
|
|
|
|
|
|
RtcpStatisticsCallback* rtcp_stats_callback_;
|
2014-01-23 10:00:39 +00:00
|
|
|
StreamDataCountersCallback* 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_
|