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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RECEIVE_STATISTICS_IMPL_H_
|
|
|
|
|
#define WEBRTC_MODULES_RTP_RTCP_SOURCE_RECEIVE_STATISTICS_IMPL_H_
|
|
|
|
|
|
2015-11-04 08:31:52 +01:00
|
|
|
#include "webrtc/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>
|
2013-08-15 23:38:54 +00:00
|
|
|
|
2015-02-26 14:34:55 +00:00
|
|
|
#include "webrtc/base/scoped_ptr.h"
|
2013-08-15 23:38:54 +00:00
|
|
|
#include "webrtc/modules/rtp_rtcp/source/bitrate.h"
|
2015-10-28 18:17:40 +01:00
|
|
|
#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
|
2013-08-15 23:38:54 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
class CriticalSectionWrapper;
|
|
|
|
|
|
2013-08-21 20:58:21 +00:00
|
|
|
class StreamStatisticianImpl : public StreamStatistician {
|
2013-08-15 23:38:54 +00:00
|
|
|
public:
|
2014-01-23 10:00:39 +00:00
|
|
|
StreamStatisticianImpl(Clock* clock,
|
|
|
|
|
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
|
|
|
void ProcessBitrate();
|
|
|
|
|
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;
|
2014-01-27 10:42:48 +00:00
|
|
|
RtcpStatistics CalculateRtcpStatistics();
|
2014-01-23 10:00:39 +00:00
|
|
|
void UpdateJitter(const RTPHeader& header,
|
|
|
|
|
uint32_t receive_time_secs,
|
|
|
|
|
uint32_t receive_time_frac);
|
2014-01-27 16:22:08 +00:00
|
|
|
void UpdateCounters(const RTPHeader& rtp_header,
|
2014-12-09 09:47:53 +00:00
|
|
|
size_t packet_length,
|
2014-01-27 16:22:08 +00:00
|
|
|
bool retransmitted);
|
|
|
|
|
void NotifyRtpCallback() LOCKS_EXCLUDED(stream_lock_.get());
|
|
|
|
|
void NotifyRtcpCallback() LOCKS_EXCLUDED(stream_lock_.get());
|
2013-09-06 13:40:11 +00:00
|
|
|
|
2013-08-21 19:44:13 +00:00
|
|
|
Clock* clock_;
|
2015-02-26 14:34:55 +00:00
|
|
|
rtc::scoped_ptr<CriticalSectionWrapper> stream_lock_;
|
2013-08-15 23:38:54 +00:00
|
|
|
Bitrate incoming_bitrate_;
|
|
|
|
|
uint32_t ssrc_;
|
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_;
|
2013-08-21 20:58:21 +00:00
|
|
|
uint32_t last_receive_time_secs_;
|
|
|
|
|
uint32_t last_receive_time_frac_;
|
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_;
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
// Implement Module.
|
2015-03-04 12:58:35 +00:00
|
|
|
int32_t Process() override;
|
|
|
|
|
int64_t TimeUntilNextProcess() 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;
|
|
|
|
|
|
|
|
|
|
Clock* clock_;
|
2015-02-26 14:34:55 +00:00
|
|
|
rtc::scoped_ptr<CriticalSectionWrapper> receive_statistics_lock_;
|
2013-08-21 20:58:21 +00:00
|
|
|
int64_t last_rate_update_ms_;
|
|
|
|
|
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
|
|
|
|
|
#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RECEIVE_STATISTICS_IMPL_H_
|