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