sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 1 | /* |
| 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 Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef VIDEO_RECEIVE_STATISTICS_PROXY_H_ |
| 12 | #define VIDEO_RECEIVE_STATISTICS_PROXY_H_ |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 13 | |
sprang | 0ab8e81 | 2016-02-24 01:35:40 -0800 | [diff] [blame] | 14 | #include <map> |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 15 | #include <memory> |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 16 | #include <string> |
Ilya Nikolaevskiy | daa4f7a | 2017-10-06 12:29:47 +0200 | [diff] [blame] | 17 | #include <vector> |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 18 | |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 19 | #include "absl/types/optional.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 20 | #include "call/video_receive_stream.h" |
Niels Möller | 834a554 | 2019-09-23 10:31:16 +0200 | [diff] [blame] | 21 | #include "modules/include/module_common_types.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 22 | #include "modules/video_coding/include/video_coding_defines.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 23 | #include "rtc_base/critical_section.h" |
Karl Wiberg | 65c3922 | 2017-11-22 12:25:14 +0100 | [diff] [blame] | 24 | #include "rtc_base/numerics/histogram_percentile_counter.h" |
| 25 | #include "rtc_base/numerics/moving_max_counter.h" |
Ilya Nikolaevskiy | 0beed5d | 2018-05-22 10:54:30 +0200 | [diff] [blame] | 26 | #include "rtc_base/numerics/sample_counter.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 27 | #include "rtc_base/rate_statistics.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 28 | #include "rtc_base/rate_tracker.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 29 | #include "rtc_base/thread_annotations.h" |
Tommi | 132e28e | 2018-02-24 17:57:33 +0100 | [diff] [blame] | 30 | #include "rtc_base/thread_checker.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 31 | #include "video/quality_threshold.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 32 | #include "video/stats_counter.h" |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 33 | #include "video/video_quality_observer.h" |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 34 | |
| 35 | namespace webrtc { |
| 36 | |
| 37 | class Clock; |
asapersson | 86b0160 | 2015-10-20 23:55:26 -0700 | [diff] [blame] | 38 | struct CodecSpecificInfo; |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 39 | |
pbos | f42376c | 2015-08-28 07:35:32 -0700 | [diff] [blame] | 40 | class ReceiveStatisticsProxy : public VCMReceiveStatisticsCallback, |
Niels Möller | 4d7c405 | 2019-08-05 12:45:19 +0200 | [diff] [blame] | 41 | public RtcpCnameCallback, |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 +0000 | [diff] [blame] | 42 | public RtcpPacketTypeCounterObserver, |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 43 | public CallStatsObserver { |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 44 | public: |
Tommi | 733b547 | 2016-06-10 17:58:01 +0200 | [diff] [blame] | 45 | ReceiveStatisticsProxy(const VideoReceiveStream::Config* config, |
sprang | 0ab8e81 | 2016-02-24 01:35:40 -0800 | [diff] [blame] | 46 | Clock* clock); |
Niels Möller | 9a9f18a | 2019-08-02 13:52:37 +0200 | [diff] [blame] | 47 | ~ReceiveStatisticsProxy() = default; |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 48 | |
| 49 | VideoReceiveStream::Stats GetStats() const; |
| 50 | |
Sergey Silkin | 278f825 | 2019-01-09 14:37:40 +0100 | [diff] [blame] | 51 | void OnDecodedFrame(const VideoFrame& frame, |
| 52 | absl::optional<uint8_t> qp, |
Johannes Kron | bfd343b | 2019-07-01 10:07:50 +0200 | [diff] [blame] | 53 | int32_t decode_time_ms, |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 54 | VideoContentType content_type); |
Åsa Persson | fcf79cc | 2019-10-22 15:23:44 +0200 | [diff] [blame] | 55 | void OnSyncOffsetUpdated(int64_t video_playout_ntp_ms, |
| 56 | int64_t sync_offset_ms, |
| 57 | double estimated_freq_khz); |
asapersson | 1490f7a | 2016-09-23 02:09:46 -0700 | [diff] [blame] | 58 | void OnRenderedFrame(const VideoFrame& frame); |
pbos | f42376c | 2015-08-28 07:35:32 -0700 | [diff] [blame] | 59 | void OnIncomingPayloadType(int payload_type); |
Peter Boström | b7d9a97 | 2015-12-18 16:01:11 +0100 | [diff] [blame] | 60 | void OnDecoderImplementationName(const char* implementation_name); |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 61 | |
Niels Möller | 147013a | 2018-10-01 15:56:33 +0200 | [diff] [blame] | 62 | void OnPreDecode(VideoCodecType codec_type, int qp); |
asapersson | 86b0160 | 2015-10-20 23:55:26 -0700 | [diff] [blame] | 63 | |
Ilya Nikolaevskiy | d397a0d | 2018-02-21 15:57:09 +0100 | [diff] [blame] | 64 | void OnUniqueFramesCounted(int num_unique_frames); |
| 65 | |
sprang | 3e86e7e | 2017-08-22 09:23:28 -0700 | [diff] [blame] | 66 | // Indicates video stream has been paused (no incoming packets). |
| 67 | void OnStreamInactive(); |
| 68 | |
asapersson | d89920b | 2015-07-22 06:52:00 -0700 | [diff] [blame] | 69 | // Overrides VCMReceiveStatisticsCallback. |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 70 | void OnCompleteFrame(bool is_keyframe, |
| 71 | size_t size_bytes, |
| 72 | VideoContentType content_type) override; |
Johannes Kron | 0c141c5 | 2019-08-26 15:04:43 +0200 | [diff] [blame] | 73 | void OnDroppedFrames(uint32_t frames_dropped) override; |
Johannes Kron | bfd343b | 2019-07-01 10:07:50 +0200 | [diff] [blame] | 74 | void OnFrameBufferTimingsUpdated(int max_decode_ms, |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 75 | int current_delay_ms, |
| 76 | int target_delay_ms, |
| 77 | int jitter_buffer_ms, |
| 78 | int min_playout_delay_ms, |
| 79 | int render_delay_ms) override; |
pbos@webrtc.org | 5570769 | 2014-12-19 15:45:03 +0000 | [diff] [blame] | 80 | |
ilnik | 2edc684 | 2017-07-06 03:06:50 -0700 | [diff] [blame] | 81 | void OnTimingFrameInfoUpdated(const TimingFrameInfo& info) override; |
| 82 | |
Niels Möller | 4d7c405 | 2019-08-05 12:45:19 +0200 | [diff] [blame] | 83 | // Overrides RtcpCnameCallback. |
| 84 | void OnCname(uint32_t ssrc, absl::string_view cname) override; |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 85 | |
asapersson | d89920b | 2015-07-22 06:52:00 -0700 | [diff] [blame] | 86 | // Overrides RtcpPacketTypeCounterObserver. |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 87 | void RtcpPacketTypesCounterUpdated( |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 +0000 | [diff] [blame] | 88 | uint32_t ssrc, |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 89 | const RtcpPacketTypeCounter& packet_counter) override; |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 90 | |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 91 | // Implements CallStatsObserver. |
| 92 | void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) override; |
| 93 | |
Tommi | 132e28e | 2018-02-24 17:57:33 +0100 | [diff] [blame] | 94 | // Notification methods that are used to check our internal state and validate |
| 95 | // threading assumptions. These are called by VideoReceiveStream. |
| 96 | void DecoderThreadStarting(); |
| 97 | void DecoderThreadStopped(); |
| 98 | |
Niels Möller | 9a9f18a | 2019-08-02 13:52:37 +0200 | [diff] [blame] | 99 | // Produce histograms. Must be called after DecoderThreadStopped(), typically |
| 100 | // at the end of the call. |
Niels Möller | d781965 | 2019-08-13 14:43:02 +0200 | [diff] [blame] | 101 | void UpdateHistograms(absl::optional<int> fraction_lost, |
| 102 | const StreamDataCounters& rtp_stats, |
| 103 | const StreamDataCounters* rtx_stats); |
Niels Möller | 9a9f18a | 2019-08-02 13:52:37 +0200 | [diff] [blame] | 104 | |
pbos@webrtc.org | ce4e9a3 | 2014-12-18 13:50:16 +0000 | [diff] [blame] | 105 | private: |
asapersson | 86b0160 | 2015-10-20 23:55:26 -0700 | [diff] [blame] | 106 | struct QpCounters { |
Ilya Nikolaevskiy | 0beed5d | 2018-05-22 10:54:30 +0200 | [diff] [blame] | 107 | rtc::SampleCounter vp8; |
asapersson | 86b0160 | 2015-10-20 23:55:26 -0700 | [diff] [blame] | 108 | }; |
asapersson | d89920b | 2015-07-22 06:52:00 -0700 | [diff] [blame] | 109 | |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 110 | struct ContentSpecificStats { |
Ilya Nikolaevskiy | daa4f7a | 2017-10-06 12:29:47 +0200 | [diff] [blame] | 111 | ContentSpecificStats(); |
Mirko Bonadei | 8fdcac3 | 2018-08-28 16:30:18 +0200 | [diff] [blame] | 112 | ~ContentSpecificStats(); |
Ilya Nikolaevskiy | daa4f7a | 2017-10-06 12:29:47 +0200 | [diff] [blame] | 113 | |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 114 | void Add(const ContentSpecificStats& other); |
| 115 | |
Ilya Nikolaevskiy | 0beed5d | 2018-05-22 10:54:30 +0200 | [diff] [blame] | 116 | rtc::SampleCounter e2e_delay_counter; |
| 117 | rtc::SampleCounter interframe_delay_counter; |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 118 | int64_t flow_duration_ms = 0; |
| 119 | int64_t total_media_bytes = 0; |
Ilya Nikolaevskiy | 0beed5d | 2018-05-22 10:54:30 +0200 | [diff] [blame] | 120 | rtc::SampleCounter received_width; |
| 121 | rtc::SampleCounter received_height; |
| 122 | rtc::SampleCounter qp_counter; |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 123 | FrameCounts frame_counts; |
Ilya Nikolaevskiy | ed23be9 | 2017-10-12 12:38:01 +0200 | [diff] [blame] | 124 | rtc::HistogramPercentileCounter interframe_delay_percentiles; |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 125 | }; |
| 126 | |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 127 | void QualitySample() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_); |
palmkvist | 349092b | 2016-12-13 02:45:57 -0800 | [diff] [blame] | 128 | |
asapersson | 0255acb | 2017-03-28 02:44:58 -0700 | [diff] [blame] | 129 | // Removes info about old frames and then updates the framerate. |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 130 | void UpdateFramerate(int64_t now_ms) const |
| 131 | RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_); |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 132 | |
Johannes Kron | e76b3ab | 2019-10-22 13:22:26 +0200 | [diff] [blame] | 133 | void UpdateDecodeTimeHistograms(int width, |
| 134 | int height, |
| 135 | int decode_time_ms) const |
| 136 | RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| 137 | |
Åsa Persson | fcf79cc | 2019-10-22 15:23:44 +0200 | [diff] [blame] | 138 | absl::optional<int64_t> GetCurrentEstimatedPlayoutNtpTimestampMs( |
| 139 | int64_t now_ms) const RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| 140 | |
pbos@webrtc.org | de1429e | 2014-04-28 13:00:21 +0000 | [diff] [blame] | 141 | Clock* const clock_; |
Tommi | 733b547 | 2016-06-10 17:58:01 +0200 | [diff] [blame] | 142 | // Ownership of this object lies with the owner of the ReceiveStatisticsProxy |
| 143 | // instance. Lifetime is guaranteed to outlive |this|. |
| 144 | // TODO(tommi): In practice the config_ reference is only used for accessing |
brandtr | b5f2c3f | 2016-10-04 23:28:39 -0700 | [diff] [blame] | 145 | // config_.rtp.ulpfec.ulpfec_payload_type. Instead of holding a pointer back, |
Tommi | 733b547 | 2016-06-10 17:58:01 +0200 | [diff] [blame] | 146 | // we could just store the value of ulpfec_payload_type and change the |
| 147 | // ReceiveStatisticsProxy() ctor to accept a const& of Config (since we'll |
| 148 | // then no longer store a pointer to the object). |
| 149 | const VideoReceiveStream::Config& config_; |
asapersson | 4374a09 | 2016-07-27 00:39:09 -0700 | [diff] [blame] | 150 | const int64_t start_ms_; |
Johannes Kron | e76b3ab | 2019-10-22 13:22:26 +0200 | [diff] [blame] | 151 | const bool enable_decode_time_histograms_; |
pbos@webrtc.org | de1429e | 2014-04-28 13:00:21 +0000 | [diff] [blame] | 152 | |
pbos | 5ad935c | 2016-01-25 03:52:44 -0800 | [diff] [blame] | 153 | rtc::CriticalSection crit_; |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 154 | int64_t last_sample_time_ RTC_GUARDED_BY(crit_); |
| 155 | QualityThreshold fps_threshold_ RTC_GUARDED_BY(crit_); |
| 156 | QualityThreshold qp_threshold_ RTC_GUARDED_BY(crit_); |
| 157 | QualityThreshold variance_threshold_ RTC_GUARDED_BY(crit_); |
Ilya Nikolaevskiy | 0beed5d | 2018-05-22 10:54:30 +0200 | [diff] [blame] | 158 | rtc::SampleCounter qp_sample_ RTC_GUARDED_BY(crit_); |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 159 | int num_bad_states_ RTC_GUARDED_BY(crit_); |
| 160 | int num_certain_states_ RTC_GUARDED_BY(crit_); |
Niels Möller | d781965 | 2019-08-13 14:43:02 +0200 | [diff] [blame] | 161 | // Note: The |stats_.rtp_stats| member is not used or populated by this class. |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 162 | mutable VideoReceiveStream::Stats stats_ RTC_GUARDED_BY(crit_); |
| 163 | RateStatistics decode_fps_estimator_ RTC_GUARDED_BY(crit_); |
| 164 | RateStatistics renders_fps_estimator_ RTC_GUARDED_BY(crit_); |
| 165 | rtc::RateTracker render_fps_tracker_ RTC_GUARDED_BY(crit_); |
| 166 | rtc::RateTracker render_pixel_tracker_ RTC_GUARDED_BY(crit_); |
Ilya Nikolaevskiy | 0beed5d | 2018-05-22 10:54:30 +0200 | [diff] [blame] | 167 | rtc::SampleCounter sync_offset_counter_ RTC_GUARDED_BY(crit_); |
| 168 | rtc::SampleCounter decode_time_counter_ RTC_GUARDED_BY(crit_); |
| 169 | rtc::SampleCounter jitter_buffer_delay_counter_ RTC_GUARDED_BY(crit_); |
| 170 | rtc::SampleCounter target_delay_counter_ RTC_GUARDED_BY(crit_); |
| 171 | rtc::SampleCounter current_delay_counter_ RTC_GUARDED_BY(crit_); |
| 172 | rtc::SampleCounter delay_counter_ RTC_GUARDED_BY(crit_); |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 173 | std::unique_ptr<VideoQualityObserver> video_quality_observer_ |
| 174 | RTC_GUARDED_BY(crit_); |
ilnik | a79cc28 | 2017-08-23 05:24:10 -0700 | [diff] [blame] | 175 | mutable rtc::MovingMaxCounter<int> interframe_delay_max_moving_ |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 176 | RTC_GUARDED_BY(crit_); |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 177 | std::map<VideoContentType, ContentSpecificStats> content_specific_stats_ |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 178 | RTC_GUARDED_BY(crit_); |
| 179 | MaxCounter freq_offset_counter_ RTC_GUARDED_BY(crit_); |
Tommi | 132e28e | 2018-02-24 17:57:33 +0100 | [diff] [blame] | 180 | QpCounters qp_counters_ RTC_GUARDED_BY(decode_thread_); |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 181 | int64_t avg_rtt_ms_ RTC_GUARDED_BY(crit_); |
| 182 | mutable std::map<int64_t, size_t> frame_window_ RTC_GUARDED_BY(&crit_); |
| 183 | VideoContentType last_content_type_ RTC_GUARDED_BY(&crit_); |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 184 | VideoCodecType last_codec_type_ RTC_GUARDED_BY(&crit_); |
Benjamin Wright | 514f084 | 2018-12-10 09:55:17 -0800 | [diff] [blame] | 185 | absl::optional<int64_t> first_frame_received_time_ms_ RTC_GUARDED_BY(&crit_); |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 186 | absl::optional<int64_t> first_decoded_frame_time_ms_ RTC_GUARDED_BY(&crit_); |
| 187 | absl::optional<int64_t> last_decoded_frame_time_ms_ RTC_GUARDED_BY(&crit_); |
Åsa Persson | 81327d5 | 2018-06-05 13:34:33 +0200 | [diff] [blame] | 188 | size_t num_delayed_frames_rendered_ RTC_GUARDED_BY(&crit_); |
| 189 | int64_t sum_missed_render_deadline_ms_ RTC_GUARDED_BY(&crit_); |
ilnik | 75204c5 | 2017-09-04 03:35:40 -0700 | [diff] [blame] | 190 | // Mutable because calling Max() on MovingMaxCounter is not const. Yet it is |
| 191 | // called from const GetStats(). |
| 192 | mutable rtc::MovingMaxCounter<TimingFrameInfo> timing_frame_info_counter_ |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 193 | RTC_GUARDED_BY(&crit_); |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 194 | absl::optional<int> num_unique_frames_ RTC_GUARDED_BY(crit_); |
Åsa Persson | fcf79cc | 2019-10-22 15:23:44 +0200 | [diff] [blame] | 195 | absl::optional<int64_t> last_estimated_playout_ntp_timestamp_ms_ |
| 196 | RTC_GUARDED_BY(&crit_); |
| 197 | absl::optional<int64_t> last_estimated_playout_time_ms_ |
| 198 | RTC_GUARDED_BY(&crit_); |
Tommi | 132e28e | 2018-02-24 17:57:33 +0100 | [diff] [blame] | 199 | rtc::ThreadChecker decode_thread_; |
| 200 | rtc::ThreadChecker network_thread_; |
| 201 | rtc::ThreadChecker main_thread_; |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 202 | }; |
| 203 | |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 204 | } // namespace webrtc |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 205 | #endif // VIDEO_RECEIVE_STATISTICS_PROXY_H_ |