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> |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 15 | #include <string> |
Ilya Nikolaevskiy | daa4f7a | 2017-10-06 12:29:47 +0200 | [diff] [blame] | 16 | #include <vector> |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 17 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 18 | #include "api/optional.h" |
| 19 | #include "call/video_receive_stream.h" |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 20 | #include "common_types.h" // NOLINT(build/include) |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 21 | #include "common_video/include/frame_callback.h" |
| 22 | #include "modules/video_coding/include/video_coding_defines.h" |
| 23 | #include "rtc_base/criticalsection.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" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 26 | #include "rtc_base/rate_statistics.h" |
| 27 | #include "rtc_base/ratetracker.h" |
| 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" |
| 33 | #include "video/video_stream_decoder.h" |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 34 | |
| 35 | namespace webrtc { |
| 36 | |
| 37 | class Clock; |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 38 | class ViECodec; |
| 39 | class ViEDecoderObserver; |
asapersson | 86b0160 | 2015-10-20 23:55:26 -0700 | [diff] [blame] | 40 | struct CodecSpecificInfo; |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 41 | |
pbos | f42376c | 2015-08-28 07:35:32 -0700 | [diff] [blame] | 42 | class ReceiveStatisticsProxy : public VCMReceiveStatisticsCallback, |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 43 | public RtcpStatisticsCallback, |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 +0000 | [diff] [blame] | 44 | public RtcpPacketTypeCounterObserver, |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 45 | public StreamDataCountersCallback, |
| 46 | public CallStatsObserver { |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 47 | public: |
Tommi | 733b547 | 2016-06-10 17:58:01 +0200 | [diff] [blame] | 48 | ReceiveStatisticsProxy(const VideoReceiveStream::Config* config, |
sprang | 0ab8e81 | 2016-02-24 01:35:40 -0800 | [diff] [blame] | 49 | Clock* clock); |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 50 | virtual ~ReceiveStatisticsProxy(); |
| 51 | |
| 52 | VideoReceiveStream::Stats GetStats() const; |
| 53 | |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 54 | void OnDecodedFrame(rtc::Optional<uint8_t> qp, 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); |
pbos | f42376c | 2015-08-28 07:35:32 -0700 | [diff] [blame] | 59 | void OnIncomingRate(unsigned int framerate, unsigned int bitrate_bps); |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 60 | |
asapersson | 86b0160 | 2015-10-20 23:55:26 -0700 | [diff] [blame] | 61 | void OnPreDecode(const EncodedImage& encoded_image, |
| 62 | const CodecSpecificInfo* codec_specific_info); |
| 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. |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 70 | void OnReceiveRatesUpdated(uint32_t bitRate, uint32_t frameRate) override; |
| 71 | void OnFrameCountsUpdated(const FrameCounts& frame_counts) override; |
| 72 | void OnDiscardedPacketsUpdated(int discarded_packets) override; |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 73 | void OnCompleteFrame(bool is_keyframe, |
| 74 | size_t size_bytes, |
| 75 | VideoContentType content_type) override; |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 76 | void OnFrameBufferTimingsUpdated(int decode_ms, |
| 77 | int max_decode_ms, |
| 78 | int current_delay_ms, |
| 79 | int target_delay_ms, |
| 80 | int jitter_buffer_ms, |
| 81 | int min_playout_delay_ms, |
| 82 | int render_delay_ms) override; |
pbos@webrtc.org | 5570769 | 2014-12-19 15:45:03 +0000 | [diff] [blame] | 83 | |
ilnik | 2edc684 | 2017-07-06 03:06:50 -0700 | [diff] [blame] | 84 | void OnTimingFrameInfoUpdated(const TimingFrameInfo& info) override; |
| 85 | |
pbos@webrtc.org | ce4e9a3 | 2014-12-18 13:50:16 +0000 | [diff] [blame] | 86 | // Overrides RtcpStatisticsCallback. |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 87 | void StatisticsUpdated(const webrtc::RtcpStatistics& statistics, |
| 88 | uint32_t ssrc) override; |
| 89 | void CNameChanged(const char* cname, uint32_t ssrc) override; |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 90 | |
asapersson | d89920b | 2015-07-22 06:52:00 -0700 | [diff] [blame] | 91 | // Overrides RtcpPacketTypeCounterObserver. |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 92 | void RtcpPacketTypesCounterUpdated( |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 +0000 | [diff] [blame] | 93 | uint32_t ssrc, |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 94 | const RtcpPacketTypeCounter& packet_counter) override; |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 95 | // Overrides StreamDataCountersCallback. |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 96 | void DataCountersUpdated(const webrtc::StreamDataCounters& counters, |
| 97 | uint32_t ssrc) override; |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 98 | |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 99 | // Implements CallStatsObserver. |
| 100 | void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) override; |
| 101 | |
Tommi | 132e28e | 2018-02-24 17:57:33 +0100 | [diff] [blame] | 102 | // Notification methods that are used to check our internal state and validate |
| 103 | // threading assumptions. These are called by VideoReceiveStream. |
| 104 | void DecoderThreadStarting(); |
| 105 | void DecoderThreadStopped(); |
| 106 | |
pbos@webrtc.org | ce4e9a3 | 2014-12-18 13:50:16 +0000 | [diff] [blame] | 107 | private: |
asapersson | d89920b | 2015-07-22 06:52:00 -0700 | [diff] [blame] | 108 | struct SampleCounter { |
| 109 | SampleCounter() : sum(0), num_samples(0) {} |
| 110 | void Add(int sample); |
asapersson | 6966bd5 | 2017-01-03 00:44:06 -0800 | [diff] [blame] | 111 | int Avg(int64_t min_required_samples) const; |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 112 | int Max() const; |
palmkvist | 349092b | 2016-12-13 02:45:57 -0800 | [diff] [blame] | 113 | void Reset(); |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 114 | void Add(const SampleCounter& other); |
asapersson | d89920b | 2015-07-22 06:52:00 -0700 | [diff] [blame] | 115 | |
| 116 | private: |
asapersson | 6966bd5 | 2017-01-03 00:44:06 -0800 | [diff] [blame] | 117 | int64_t sum; |
| 118 | int64_t num_samples; |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 119 | rtc::Optional<int> max; |
asapersson | d89920b | 2015-07-22 06:52:00 -0700 | [diff] [blame] | 120 | }; |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 121 | |
asapersson | 86b0160 | 2015-10-20 23:55:26 -0700 | [diff] [blame] | 122 | struct QpCounters { |
| 123 | SampleCounter vp8; |
| 124 | }; |
asapersson | d89920b | 2015-07-22 06:52:00 -0700 | [diff] [blame] | 125 | |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 126 | struct ContentSpecificStats { |
Ilya Nikolaevskiy | daa4f7a | 2017-10-06 12:29:47 +0200 | [diff] [blame] | 127 | ContentSpecificStats(); |
| 128 | |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 129 | void Add(const ContentSpecificStats& other); |
| 130 | |
| 131 | SampleCounter e2e_delay_counter; |
| 132 | SampleCounter interframe_delay_counter; |
| 133 | int64_t flow_duration_ms = 0; |
| 134 | int64_t total_media_bytes = 0; |
| 135 | SampleCounter received_width; |
| 136 | SampleCounter received_height; |
| 137 | SampleCounter qp_counter; |
| 138 | FrameCounts frame_counts; |
Ilya Nikolaevskiy | ed23be9 | 2017-10-12 12:38:01 +0200 | [diff] [blame] | 139 | rtc::HistogramPercentileCounter interframe_delay_percentiles; |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 140 | }; |
| 141 | |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 142 | void UpdateHistograms() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_); |
asapersson | d89920b | 2015-07-22 06:52:00 -0700 | [diff] [blame] | 143 | |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 144 | void QualitySample() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_); |
palmkvist | 349092b | 2016-12-13 02:45:57 -0800 | [diff] [blame] | 145 | |
asapersson | 0255acb | 2017-03-28 02:44:58 -0700 | [diff] [blame] | 146 | // Removes info about old frames and then updates the framerate. |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 147 | void UpdateFramerate(int64_t now_ms) const |
| 148 | RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_); |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 149 | |
pbos@webrtc.org | de1429e | 2014-04-28 13:00:21 +0000 | [diff] [blame] | 150 | Clock* const clock_; |
Tommi | 733b547 | 2016-06-10 17:58:01 +0200 | [diff] [blame] | 151 | // Ownership of this object lies with the owner of the ReceiveStatisticsProxy |
| 152 | // instance. Lifetime is guaranteed to outlive |this|. |
| 153 | // TODO(tommi): In practice the config_ reference is only used for accessing |
brandtr | b5f2c3f | 2016-10-04 23:28:39 -0700 | [diff] [blame] | 154 | // config_.rtp.ulpfec.ulpfec_payload_type. Instead of holding a pointer back, |
Tommi | 733b547 | 2016-06-10 17:58:01 +0200 | [diff] [blame] | 155 | // we could just store the value of ulpfec_payload_type and change the |
| 156 | // ReceiveStatisticsProxy() ctor to accept a const& of Config (since we'll |
| 157 | // then no longer store a pointer to the object). |
| 158 | const VideoReceiveStream::Config& config_; |
asapersson | 4374a09 | 2016-07-27 00:39:09 -0700 | [diff] [blame] | 159 | const int64_t start_ms_; |
pbos@webrtc.org | de1429e | 2014-04-28 13:00:21 +0000 | [diff] [blame] | 160 | |
pbos | 5ad935c | 2016-01-25 03:52:44 -0800 | [diff] [blame] | 161 | rtc::CriticalSection crit_; |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 162 | int64_t last_sample_time_ RTC_GUARDED_BY(crit_); |
| 163 | QualityThreshold fps_threshold_ RTC_GUARDED_BY(crit_); |
| 164 | QualityThreshold qp_threshold_ RTC_GUARDED_BY(crit_); |
| 165 | QualityThreshold variance_threshold_ RTC_GUARDED_BY(crit_); |
| 166 | SampleCounter qp_sample_ RTC_GUARDED_BY(crit_); |
| 167 | int num_bad_states_ RTC_GUARDED_BY(crit_); |
| 168 | int num_certain_states_ RTC_GUARDED_BY(crit_); |
| 169 | mutable VideoReceiveStream::Stats stats_ RTC_GUARDED_BY(crit_); |
| 170 | RateStatistics decode_fps_estimator_ RTC_GUARDED_BY(crit_); |
| 171 | RateStatistics renders_fps_estimator_ RTC_GUARDED_BY(crit_); |
| 172 | rtc::RateTracker render_fps_tracker_ RTC_GUARDED_BY(crit_); |
| 173 | rtc::RateTracker render_pixel_tracker_ RTC_GUARDED_BY(crit_); |
| 174 | rtc::RateTracker total_byte_tracker_ RTC_GUARDED_BY(crit_); |
| 175 | SampleCounter sync_offset_counter_ RTC_GUARDED_BY(crit_); |
| 176 | SampleCounter decode_time_counter_ RTC_GUARDED_BY(crit_); |
| 177 | SampleCounter jitter_buffer_delay_counter_ RTC_GUARDED_BY(crit_); |
| 178 | SampleCounter target_delay_counter_ RTC_GUARDED_BY(crit_); |
| 179 | SampleCounter current_delay_counter_ RTC_GUARDED_BY(crit_); |
| 180 | SampleCounter delay_counter_ RTC_GUARDED_BY(crit_); |
ilnik | a79cc28 | 2017-08-23 05:24:10 -0700 | [diff] [blame] | 181 | mutable rtc::MovingMaxCounter<int> interframe_delay_max_moving_ |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 182 | RTC_GUARDED_BY(crit_); |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 183 | std::map<VideoContentType, ContentSpecificStats> content_specific_stats_ |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 184 | RTC_GUARDED_BY(crit_); |
| 185 | MaxCounter freq_offset_counter_ RTC_GUARDED_BY(crit_); |
| 186 | int64_t first_report_block_time_ms_ RTC_GUARDED_BY(crit_); |
| 187 | ReportBlockStats report_block_stats_ RTC_GUARDED_BY(crit_); |
Tommi | 132e28e | 2018-02-24 17:57:33 +0100 | [diff] [blame] | 188 | QpCounters qp_counters_ RTC_GUARDED_BY(decode_thread_); |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 189 | std::map<uint32_t, StreamDataCounters> rtx_stats_ RTC_GUARDED_BY(crit_); |
| 190 | int64_t avg_rtt_ms_ RTC_GUARDED_BY(crit_); |
| 191 | mutable std::map<int64_t, size_t> frame_window_ RTC_GUARDED_BY(&crit_); |
| 192 | VideoContentType last_content_type_ RTC_GUARDED_BY(&crit_); |
Åsa Persson | b9b07ea | 2018-01-24 17:04:07 +0100 | [diff] [blame] | 193 | rtc::Optional<int64_t> first_decoded_frame_time_ms_ RTC_GUARDED_BY(&crit_); |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 194 | rtc::Optional<int64_t> last_decoded_frame_time_ms_ RTC_GUARDED_BY(&crit_); |
ilnik | 75204c5 | 2017-09-04 03:35:40 -0700 | [diff] [blame] | 195 | // Mutable because calling Max() on MovingMaxCounter is not const. Yet it is |
| 196 | // called from const GetStats(). |
| 197 | mutable rtc::MovingMaxCounter<TimingFrameInfo> timing_frame_info_counter_ |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 198 | RTC_GUARDED_BY(&crit_); |
Ilya Nikolaevskiy | d397a0d | 2018-02-21 15:57:09 +0100 | [diff] [blame] | 199 | rtc::Optional<int> num_unique_frames_ RTC_GUARDED_BY(crit_); |
Tommi | 132e28e | 2018-02-24 17:57:33 +0100 | [diff] [blame] | 200 | rtc::ThreadChecker decode_thread_; |
| 201 | rtc::ThreadChecker network_thread_; |
| 202 | rtc::ThreadChecker main_thread_; |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 203 | }; |
| 204 | |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 205 | } // namespace webrtc |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 206 | #endif // VIDEO_RECEIVE_STATISTICS_PROXY_H_ |