blob: 91ffdf642418b61af5600063a77e37c0fed4e17a [file] [log] [blame]
sprang@webrtc.org09315702014-02-07 12:06:291/*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei92ea95e2017-09-15 04:47:3111#ifndef VIDEO_RECEIVE_STATISTICS_PROXY_H_
12#define VIDEO_RECEIVE_STATISTICS_PROXY_H_
sprang@webrtc.org09315702014-02-07 12:06:2913
sprang0ab8e812016-02-24 09:35:4014#include <map>
Ilya Nikolaevskiy94150ee2018-05-23 09:53:1915#include <memory>
sprang@webrtc.org09315702014-02-07 12:06:2916#include <string>
Ilya Nikolaevskiydaa4f7a2017-10-06 10:29:4717#include <vector>
sprang@webrtc.org09315702014-02-07 12:06:2918
Danil Chapovalovb9b146c2018-06-15 10:28:0719#include "absl/types/optional.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3120#include "call/video_receive_stream.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3121#include "modules/video_coding/include/video_coding_defines.h"
Steve Anton10542f22019-01-11 17:11:0022#include "rtc_base/critical_section.h"
Karl Wiberg65c39222017-11-22 11:25:1423#include "rtc_base/numerics/histogram_percentile_counter.h"
24#include "rtc_base/numerics/moving_max_counter.h"
Ilya Nikolaevskiy0beed5d2018-05-22 08:54:3025#include "rtc_base/numerics/sample_counter.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3126#include "rtc_base/rate_statistics.h"
Steve Anton10542f22019-01-11 17:11:0027#include "rtc_base/rate_tracker.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3128#include "rtc_base/thread_annotations.h"
Tommi132e28e2018-02-24 16:57:3329#include "rtc_base/thread_checker.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3130#include "video/quality_threshold.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3131#include "video/stats_counter.h"
Ilya Nikolaevskiy94150ee2018-05-23 09:53:1932#include "video/video_quality_observer.h"
sprang@webrtc.org09315702014-02-07 12:06:2933
34namespace webrtc {
35
36class Clock;
asapersson86b01602015-10-21 06:55:2637struct CodecSpecificInfo;
sprang@webrtc.org09315702014-02-07 12:06:2938
pbosf42376c2015-08-28 14:35:3239class ReceiveStatisticsProxy : public VCMReceiveStatisticsCallback,
Niels Möller4d7c4052019-08-05 10:45:1940 public RtcpCnameCallback,
pbos@webrtc.org1d0fa5d2015-02-19 12:47:0041 public RtcpPacketTypeCounterObserver,
philipela45102f2017-02-22 13:30:3942 public CallStatsObserver {
sprang@webrtc.org09315702014-02-07 12:06:2943 public:
Tommi733b5472016-06-10 15:58:0144 ReceiveStatisticsProxy(const VideoReceiveStream::Config* config,
sprang0ab8e812016-02-24 09:35:4045 Clock* clock);
Niels Möller9a9f18a2019-08-02 11:52:3746 ~ReceiveStatisticsProxy() = default;
sprang@webrtc.org09315702014-02-07 12:06:2947
48 VideoReceiveStream::Stats GetStats() const;
49
Sergey Silkin278f8252019-01-09 13:37:4050 void OnDecodedFrame(const VideoFrame& frame,
51 absl::optional<uint8_t> qp,
Johannes Kronbfd343b2019-07-01 08:07:5052 int32_t decode_time_ms,
Ilya Nikolaevskiy94150ee2018-05-23 09:53:1953 VideoContentType content_type);
asaperssonde9e5ff2016-11-02 14:14:0354 void OnSyncOffsetUpdated(int64_t sync_offset_ms, double estimated_freq_khz);
asapersson1490f7a2016-09-23 09:09:4655 void OnRenderedFrame(const VideoFrame& frame);
pbosf42376c2015-08-28 14:35:3256 void OnIncomingPayloadType(int payload_type);
Peter Boströmb7d9a972015-12-18 15:01:1157 void OnDecoderImplementationName(const char* implementation_name);
sprang@webrtc.org09315702014-02-07 12:06:2958
Niels Möller147013a2018-10-01 13:56:3359 void OnPreDecode(VideoCodecType codec_type, int qp);
asapersson86b01602015-10-21 06:55:2660
Ilya Nikolaevskiyd397a0d2018-02-21 14:57:0961 void OnUniqueFramesCounted(int num_unique_frames);
62
sprang3e86e7e2017-08-22 16:23:2863 // Indicates video stream has been paused (no incoming packets).
64 void OnStreamInactive();
65
asaperssond89920b2015-07-22 13:52:0066 // Overrides VCMReceiveStatisticsCallback.
ilnik6d5b4d62017-08-30 10:32:1467 void OnCompleteFrame(bool is_keyframe,
68 size_t size_bytes,
69 VideoContentType content_type) override;
Johannes Kron0c141c52019-08-26 13:04:4370 void OnDroppedFrames(uint32_t frames_dropped) override;
Johannes Kronbfd343b2019-07-01 08:07:5071 void OnFrameBufferTimingsUpdated(int max_decode_ms,
philipela45102f2017-02-22 13:30:3972 int current_delay_ms,
73 int target_delay_ms,
74 int jitter_buffer_ms,
75 int min_playout_delay_ms,
76 int render_delay_ms) override;
pbos@webrtc.org55707692014-12-19 15:45:0377
ilnik2edc6842017-07-06 10:06:5078 void OnTimingFrameInfoUpdated(const TimingFrameInfo& info) override;
79
Niels Möller4d7c4052019-08-05 10:45:1980 // Overrides RtcpCnameCallback.
81 void OnCname(uint32_t ssrc, absl::string_view cname) override;
sprang@webrtc.org09315702014-02-07 12:06:2982
asaperssond89920b2015-07-22 13:52:0083 // Overrides RtcpPacketTypeCounterObserver.
kjellander@webrtc.org14665ff2015-03-04 12:58:3584 void RtcpPacketTypesCounterUpdated(
pbos@webrtc.org1d0fa5d2015-02-19 12:47:0085 uint32_t ssrc,
kjellander@webrtc.org14665ff2015-03-04 12:58:3586 const RtcpPacketTypeCounter& packet_counter) override;
sprang@webrtc.org09315702014-02-07 12:06:2987
philipela45102f2017-02-22 13:30:3988 // Implements CallStatsObserver.
89 void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) override;
90
Tommi132e28e2018-02-24 16:57:3391 // Notification methods that are used to check our internal state and validate
92 // threading assumptions. These are called by VideoReceiveStream.
93 void DecoderThreadStarting();
94 void DecoderThreadStopped();
95
Niels Möller9a9f18a2019-08-02 11:52:3796 // Produce histograms. Must be called after DecoderThreadStopped(), typically
97 // at the end of the call.
Niels Möllerd7819652019-08-13 12:43:0298 void UpdateHistograms(absl::optional<int> fraction_lost,
99 const StreamDataCounters& rtp_stats,
100 const StreamDataCounters* rtx_stats);
Niels Möller9a9f18a2019-08-02 11:52:37101
pbos@webrtc.orgce4e9a32014-12-18 13:50:16102 private:
asapersson86b01602015-10-21 06:55:26103 struct QpCounters {
Ilya Nikolaevskiy0beed5d2018-05-22 08:54:30104 rtc::SampleCounter vp8;
asapersson86b01602015-10-21 06:55:26105 };
asaperssond89920b2015-07-22 13:52:00106
ilnik6d5b4d62017-08-30 10:32:14107 struct ContentSpecificStats {
Ilya Nikolaevskiydaa4f7a2017-10-06 10:29:47108 ContentSpecificStats();
Mirko Bonadei8fdcac32018-08-28 14:30:18109 ~ContentSpecificStats();
Ilya Nikolaevskiydaa4f7a2017-10-06 10:29:47110
ilnik6d5b4d62017-08-30 10:32:14111 void Add(const ContentSpecificStats& other);
112
Ilya Nikolaevskiy0beed5d2018-05-22 08:54:30113 rtc::SampleCounter e2e_delay_counter;
114 rtc::SampleCounter interframe_delay_counter;
ilnik6d5b4d62017-08-30 10:32:14115 int64_t flow_duration_ms = 0;
116 int64_t total_media_bytes = 0;
Ilya Nikolaevskiy0beed5d2018-05-22 08:54:30117 rtc::SampleCounter received_width;
118 rtc::SampleCounter received_height;
119 rtc::SampleCounter qp_counter;
ilnik6d5b4d62017-08-30 10:32:14120 FrameCounts frame_counts;
Ilya Nikolaevskiyed23be92017-10-12 10:38:01121 rtc::HistogramPercentileCounter interframe_delay_percentiles;
ilnik6d5b4d62017-08-30 10:32:14122 };
123
danilchapa37de392017-09-09 11:17:22124 void QualitySample() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
palmkvist349092b2016-12-13 10:45:57125
asapersson0255acb2017-03-28 09:44:58126 // Removes info about old frames and then updates the framerate.
danilchapa37de392017-09-09 11:17:22127 void UpdateFramerate(int64_t now_ms) const
128 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
philipela45102f2017-02-22 13:30:39129
pbos@webrtc.orgde1429e2014-04-28 13:00:21130 Clock* const clock_;
Tommi733b5472016-06-10 15:58:01131 // Ownership of this object lies with the owner of the ReceiveStatisticsProxy
132 // instance. Lifetime is guaranteed to outlive |this|.
133 // TODO(tommi): In practice the config_ reference is only used for accessing
brandtrb5f2c3f2016-10-05 06:28:39134 // config_.rtp.ulpfec.ulpfec_payload_type. Instead of holding a pointer back,
Tommi733b5472016-06-10 15:58:01135 // we could just store the value of ulpfec_payload_type and change the
136 // ReceiveStatisticsProxy() ctor to accept a const& of Config (since we'll
137 // then no longer store a pointer to the object).
138 const VideoReceiveStream::Config& config_;
asapersson4374a092016-07-27 07:39:09139 const int64_t start_ms_;
pbos@webrtc.orgde1429e2014-04-28 13:00:21140
pbos5ad935c2016-01-25 11:52:44141 rtc::CriticalSection crit_;
danilchapa37de392017-09-09 11:17:22142 int64_t last_sample_time_ RTC_GUARDED_BY(crit_);
143 QualityThreshold fps_threshold_ RTC_GUARDED_BY(crit_);
144 QualityThreshold qp_threshold_ RTC_GUARDED_BY(crit_);
145 QualityThreshold variance_threshold_ RTC_GUARDED_BY(crit_);
Ilya Nikolaevskiy0beed5d2018-05-22 08:54:30146 rtc::SampleCounter qp_sample_ RTC_GUARDED_BY(crit_);
danilchapa37de392017-09-09 11:17:22147 int num_bad_states_ RTC_GUARDED_BY(crit_);
148 int num_certain_states_ RTC_GUARDED_BY(crit_);
Niels Möllerd7819652019-08-13 12:43:02149 // Note: The |stats_.rtp_stats| member is not used or populated by this class.
danilchapa37de392017-09-09 11:17:22150 mutable VideoReceiveStream::Stats stats_ RTC_GUARDED_BY(crit_);
151 RateStatistics decode_fps_estimator_ RTC_GUARDED_BY(crit_);
152 RateStatistics renders_fps_estimator_ RTC_GUARDED_BY(crit_);
153 rtc::RateTracker render_fps_tracker_ RTC_GUARDED_BY(crit_);
154 rtc::RateTracker render_pixel_tracker_ RTC_GUARDED_BY(crit_);
Ilya Nikolaevskiy0beed5d2018-05-22 08:54:30155 rtc::SampleCounter sync_offset_counter_ RTC_GUARDED_BY(crit_);
156 rtc::SampleCounter decode_time_counter_ RTC_GUARDED_BY(crit_);
157 rtc::SampleCounter jitter_buffer_delay_counter_ RTC_GUARDED_BY(crit_);
158 rtc::SampleCounter target_delay_counter_ RTC_GUARDED_BY(crit_);
159 rtc::SampleCounter current_delay_counter_ RTC_GUARDED_BY(crit_);
160 rtc::SampleCounter delay_counter_ RTC_GUARDED_BY(crit_);
Ilya Nikolaevskiy94150ee2018-05-23 09:53:19161 std::unique_ptr<VideoQualityObserver> video_quality_observer_
162 RTC_GUARDED_BY(crit_);
ilnika79cc282017-08-23 12:24:10163 mutable rtc::MovingMaxCounter<int> interframe_delay_max_moving_
danilchapa37de392017-09-09 11:17:22164 RTC_GUARDED_BY(crit_);
ilnik6d5b4d62017-08-30 10:32:14165 std::map<VideoContentType, ContentSpecificStats> content_specific_stats_
danilchapa37de392017-09-09 11:17:22166 RTC_GUARDED_BY(crit_);
167 MaxCounter freq_offset_counter_ RTC_GUARDED_BY(crit_);
Tommi132e28e2018-02-24 16:57:33168 QpCounters qp_counters_ RTC_GUARDED_BY(decode_thread_);
danilchapa37de392017-09-09 11:17:22169 int64_t avg_rtt_ms_ RTC_GUARDED_BY(crit_);
170 mutable std::map<int64_t, size_t> frame_window_ RTC_GUARDED_BY(&crit_);
171 VideoContentType last_content_type_ RTC_GUARDED_BY(&crit_);
Ilya Nikolaevskiy94150ee2018-05-23 09:53:19172 VideoCodecType last_codec_type_ RTC_GUARDED_BY(&crit_);
Benjamin Wright514f0842018-12-10 17:55:17173 absl::optional<int64_t> first_frame_received_time_ms_ RTC_GUARDED_BY(&crit_);
Danil Chapovalovb9b146c2018-06-15 10:28:07174 absl::optional<int64_t> first_decoded_frame_time_ms_ RTC_GUARDED_BY(&crit_);
175 absl::optional<int64_t> last_decoded_frame_time_ms_ RTC_GUARDED_BY(&crit_);
Åsa Persson81327d52018-06-05 11:34:33176 size_t num_delayed_frames_rendered_ RTC_GUARDED_BY(&crit_);
177 int64_t sum_missed_render_deadline_ms_ RTC_GUARDED_BY(&crit_);
ilnik75204c52017-09-04 10:35:40178 // Mutable because calling Max() on MovingMaxCounter is not const. Yet it is
179 // called from const GetStats().
180 mutable rtc::MovingMaxCounter<TimingFrameInfo> timing_frame_info_counter_
danilchapa37de392017-09-09 11:17:22181 RTC_GUARDED_BY(&crit_);
Danil Chapovalovb9b146c2018-06-15 10:28:07182 absl::optional<int> num_unique_frames_ RTC_GUARDED_BY(crit_);
Tommi132e28e2018-02-24 16:57:33183 rtc::ThreadChecker decode_thread_;
184 rtc::ThreadChecker network_thread_;
185 rtc::ThreadChecker main_thread_;
sprang@webrtc.org09315702014-02-07 12:06:29186};
187
sprang@webrtc.org09315702014-02-07 12:06:29188} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 04:47:31189#endif // VIDEO_RECEIVE_STATISTICS_PROXY_H_