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