1*d9f75844SAndroid Build Coastguard Worker /* 2*d9f75844SAndroid Build Coastguard Worker * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. 3*d9f75844SAndroid Build Coastguard Worker * 4*d9f75844SAndroid Build Coastguard Worker * Use of this source code is governed by a BSD-style license 5*d9f75844SAndroid Build Coastguard Worker * that can be found in the LICENSE file in the root of the source 6*d9f75844SAndroid Build Coastguard Worker * tree. An additional intellectual property rights grant can be found 7*d9f75844SAndroid Build Coastguard Worker * in the file PATENTS. All contributing project authors may 8*d9f75844SAndroid Build Coastguard Worker * be found in the AUTHORS file in the root of the source tree. 9*d9f75844SAndroid Build Coastguard Worker */ 10*d9f75844SAndroid Build Coastguard Worker 11*d9f75844SAndroid Build Coastguard Worker #ifndef VIDEO_SEND_STATISTICS_PROXY_H_ 12*d9f75844SAndroid Build Coastguard Worker #define VIDEO_SEND_STATISTICS_PROXY_H_ 13*d9f75844SAndroid Build Coastguard Worker 14*d9f75844SAndroid Build Coastguard Worker #include <array> 15*d9f75844SAndroid Build Coastguard Worker #include <map> 16*d9f75844SAndroid Build Coastguard Worker #include <memory> 17*d9f75844SAndroid Build Coastguard Worker #include <string> 18*d9f75844SAndroid Build Coastguard Worker #include <vector> 19*d9f75844SAndroid Build Coastguard Worker 20*d9f75844SAndroid Build Coastguard Worker #include "api/field_trials_view.h" 21*d9f75844SAndroid Build Coastguard Worker #include "api/video/video_codec_constants.h" 22*d9f75844SAndroid Build Coastguard Worker #include "call/video_send_stream.h" 23*d9f75844SAndroid Build Coastguard Worker #include "modules/include/module_common_types_public.h" 24*d9f75844SAndroid Build Coastguard Worker #include "modules/rtp_rtcp/include/report_block_data.h" 25*d9f75844SAndroid Build Coastguard Worker #include "modules/video_coding/include/video_codec_interface.h" 26*d9f75844SAndroid Build Coastguard Worker #include "modules/video_coding/include/video_coding_defines.h" 27*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/numerics/exp_filter.h" 28*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/rate_tracker.h" 29*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/synchronization/mutex.h" 30*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/thread_annotations.h" 31*d9f75844SAndroid Build Coastguard Worker #include "system_wrappers/include/clock.h" 32*d9f75844SAndroid Build Coastguard Worker #include "video/config/video_encoder_config.h" 33*d9f75844SAndroid Build Coastguard Worker #include "video/quality_limitation_reason_tracker.h" 34*d9f75844SAndroid Build Coastguard Worker #include "video/report_block_stats.h" 35*d9f75844SAndroid Build Coastguard Worker #include "video/stats_counter.h" 36*d9f75844SAndroid Build Coastguard Worker #include "video/video_stream_encoder_observer.h" 37*d9f75844SAndroid Build Coastguard Worker 38*d9f75844SAndroid Build Coastguard Worker namespace webrtc { 39*d9f75844SAndroid Build Coastguard Worker 40*d9f75844SAndroid Build Coastguard Worker class SendStatisticsProxy : public VideoStreamEncoderObserver, 41*d9f75844SAndroid Build Coastguard Worker public ReportBlockDataObserver, 42*d9f75844SAndroid Build Coastguard Worker public RtcpPacketTypeCounterObserver, 43*d9f75844SAndroid Build Coastguard Worker public StreamDataCountersCallback, 44*d9f75844SAndroid Build Coastguard Worker public BitrateStatisticsObserver, 45*d9f75844SAndroid Build Coastguard Worker public FrameCountObserver, 46*d9f75844SAndroid Build Coastguard Worker public SendSideDelayObserver { 47*d9f75844SAndroid Build Coastguard Worker public: 48*d9f75844SAndroid Build Coastguard Worker static const int kStatsTimeoutMs; 49*d9f75844SAndroid Build Coastguard Worker // Number of required samples to be collected before a metric is added 50*d9f75844SAndroid Build Coastguard Worker // to a rtc histogram. 51*d9f75844SAndroid Build Coastguard Worker static const int kMinRequiredMetricsSamples = 200; 52*d9f75844SAndroid Build Coastguard Worker 53*d9f75844SAndroid Build Coastguard Worker SendStatisticsProxy(Clock* clock, 54*d9f75844SAndroid Build Coastguard Worker const VideoSendStream::Config& config, 55*d9f75844SAndroid Build Coastguard Worker VideoEncoderConfig::ContentType content_type, 56*d9f75844SAndroid Build Coastguard Worker const FieldTrialsView& field_trials); 57*d9f75844SAndroid Build Coastguard Worker ~SendStatisticsProxy() override; 58*d9f75844SAndroid Build Coastguard Worker 59*d9f75844SAndroid Build Coastguard Worker virtual VideoSendStream::Stats GetStats(); 60*d9f75844SAndroid Build Coastguard Worker 61*d9f75844SAndroid Build Coastguard Worker void OnSendEncodedImage(const EncodedImage& encoded_image, 62*d9f75844SAndroid Build Coastguard Worker const CodecSpecificInfo* codec_info) override; 63*d9f75844SAndroid Build Coastguard Worker 64*d9f75844SAndroid Build Coastguard Worker void OnEncoderImplementationChanged( 65*d9f75844SAndroid Build Coastguard Worker EncoderImplementation implementation) override; 66*d9f75844SAndroid Build Coastguard Worker 67*d9f75844SAndroid Build Coastguard Worker // Used to update incoming frame rate. 68*d9f75844SAndroid Build Coastguard Worker void OnIncomingFrame(int width, int height) override; 69*d9f75844SAndroid Build Coastguard Worker 70*d9f75844SAndroid Build Coastguard Worker // Dropped frame stats. 71*d9f75844SAndroid Build Coastguard Worker void OnFrameDropped(DropReason) override; 72*d9f75844SAndroid Build Coastguard Worker 73*d9f75844SAndroid Build Coastguard Worker // Adaptation stats. 74*d9f75844SAndroid Build Coastguard Worker void OnAdaptationChanged( 75*d9f75844SAndroid Build Coastguard Worker VideoAdaptationReason reason, 76*d9f75844SAndroid Build Coastguard Worker const VideoAdaptationCounters& cpu_counters, 77*d9f75844SAndroid Build Coastguard Worker const VideoAdaptationCounters& quality_counters) override; 78*d9f75844SAndroid Build Coastguard Worker void ClearAdaptationStats() override; 79*d9f75844SAndroid Build Coastguard Worker void UpdateAdaptationSettings(AdaptationSettings cpu_settings, 80*d9f75844SAndroid Build Coastguard Worker AdaptationSettings quality_settings) override; 81*d9f75844SAndroid Build Coastguard Worker 82*d9f75844SAndroid Build Coastguard Worker void OnBitrateAllocationUpdated( 83*d9f75844SAndroid Build Coastguard Worker const VideoCodec& codec, 84*d9f75844SAndroid Build Coastguard Worker const VideoBitrateAllocation& allocation) override; 85*d9f75844SAndroid Build Coastguard Worker 86*d9f75844SAndroid Build Coastguard Worker void OnEncoderInternalScalerUpdate(bool is_scaled) override; 87*d9f75844SAndroid Build Coastguard Worker 88*d9f75844SAndroid Build Coastguard Worker void OnMinPixelLimitReached() override; 89*d9f75844SAndroid Build Coastguard Worker void OnInitialQualityResolutionAdaptDown() override; 90*d9f75844SAndroid Build Coastguard Worker 91*d9f75844SAndroid Build Coastguard Worker void OnSuspendChange(bool is_suspended) override; 92*d9f75844SAndroid Build Coastguard Worker void OnInactiveSsrc(uint32_t ssrc); 93*d9f75844SAndroid Build Coastguard Worker 94*d9f75844SAndroid Build Coastguard Worker // Used to indicate change in content type, which may require a change in 95*d9f75844SAndroid Build Coastguard Worker // how stats are collected. 96*d9f75844SAndroid Build Coastguard Worker void OnEncoderReconfigured(const VideoEncoderConfig& encoder_config, 97*d9f75844SAndroid Build Coastguard Worker const std::vector<VideoStream>& streams) override; 98*d9f75844SAndroid Build Coastguard Worker 99*d9f75844SAndroid Build Coastguard Worker // Used to update the encoder target rate. 100*d9f75844SAndroid Build Coastguard Worker void OnSetEncoderTargetRate(uint32_t bitrate_bps); 101*d9f75844SAndroid Build Coastguard Worker 102*d9f75844SAndroid Build Coastguard Worker // Implements CpuOveruseMetricsObserver. 103*d9f75844SAndroid Build Coastguard Worker void OnEncodedFrameTimeMeasured(int encode_time_ms, 104*d9f75844SAndroid Build Coastguard Worker int encode_usage_percent) override; 105*d9f75844SAndroid Build Coastguard Worker 106*d9f75844SAndroid Build Coastguard Worker int GetInputFrameRate() const override; 107*d9f75844SAndroid Build Coastguard Worker int GetSendFrameRate() const; 108*d9f75844SAndroid Build Coastguard Worker 109*d9f75844SAndroid Build Coastguard Worker protected: 110*d9f75844SAndroid Build Coastguard Worker // From ReportBlockDataObserver. 111*d9f75844SAndroid Build Coastguard Worker void OnReportBlockDataUpdated(ReportBlockData report_block_data) override; 112*d9f75844SAndroid Build Coastguard Worker // From RtcpPacketTypeCounterObserver. 113*d9f75844SAndroid Build Coastguard Worker void RtcpPacketTypesCounterUpdated( 114*d9f75844SAndroid Build Coastguard Worker uint32_t ssrc, 115*d9f75844SAndroid Build Coastguard Worker const RtcpPacketTypeCounter& packet_counter) override; 116*d9f75844SAndroid Build Coastguard Worker // From StreamDataCountersCallback. 117*d9f75844SAndroid Build Coastguard Worker void DataCountersUpdated(const StreamDataCounters& counters, 118*d9f75844SAndroid Build Coastguard Worker uint32_t ssrc) override; 119*d9f75844SAndroid Build Coastguard Worker 120*d9f75844SAndroid Build Coastguard Worker // From BitrateStatisticsObserver. 121*d9f75844SAndroid Build Coastguard Worker void Notify(uint32_t total_bitrate_bps, 122*d9f75844SAndroid Build Coastguard Worker uint32_t retransmit_bitrate_bps, 123*d9f75844SAndroid Build Coastguard Worker uint32_t ssrc) override; 124*d9f75844SAndroid Build Coastguard Worker 125*d9f75844SAndroid Build Coastguard Worker // From FrameCountObserver. 126*d9f75844SAndroid Build Coastguard Worker void FrameCountUpdated(const FrameCounts& frame_counts, 127*d9f75844SAndroid Build Coastguard Worker uint32_t ssrc) override; 128*d9f75844SAndroid Build Coastguard Worker 129*d9f75844SAndroid Build Coastguard Worker // From SendSideDelayObserver. 130*d9f75844SAndroid Build Coastguard Worker void SendSideDelayUpdated(int avg_delay_ms, 131*d9f75844SAndroid Build Coastguard Worker int max_delay_ms, 132*d9f75844SAndroid Build Coastguard Worker uint32_t ssrc) override; 133*d9f75844SAndroid Build Coastguard Worker 134*d9f75844SAndroid Build Coastguard Worker private: 135*d9f75844SAndroid Build Coastguard Worker class SampleCounter { 136*d9f75844SAndroid Build Coastguard Worker public: SampleCounter()137*d9f75844SAndroid Build Coastguard Worker SampleCounter() : sum(0), num_samples(0) {} ~SampleCounter()138*d9f75844SAndroid Build Coastguard Worker ~SampleCounter() {} 139*d9f75844SAndroid Build Coastguard Worker void Add(int sample); 140*d9f75844SAndroid Build Coastguard Worker int Avg(int64_t min_required_samples) const; 141*d9f75844SAndroid Build Coastguard Worker 142*d9f75844SAndroid Build Coastguard Worker private: 143*d9f75844SAndroid Build Coastguard Worker int64_t sum; 144*d9f75844SAndroid Build Coastguard Worker int64_t num_samples; 145*d9f75844SAndroid Build Coastguard Worker }; 146*d9f75844SAndroid Build Coastguard Worker class BoolSampleCounter { 147*d9f75844SAndroid Build Coastguard Worker public: BoolSampleCounter()148*d9f75844SAndroid Build Coastguard Worker BoolSampleCounter() : sum(0), num_samples(0) {} ~BoolSampleCounter()149*d9f75844SAndroid Build Coastguard Worker ~BoolSampleCounter() {} 150*d9f75844SAndroid Build Coastguard Worker void Add(bool sample); 151*d9f75844SAndroid Build Coastguard Worker void Add(bool sample, int64_t count); 152*d9f75844SAndroid Build Coastguard Worker int Percent(int64_t min_required_samples) const; 153*d9f75844SAndroid Build Coastguard Worker int Permille(int64_t min_required_samples) const; 154*d9f75844SAndroid Build Coastguard Worker 155*d9f75844SAndroid Build Coastguard Worker private: 156*d9f75844SAndroid Build Coastguard Worker int Fraction(int64_t min_required_samples, float multiplier) const; 157*d9f75844SAndroid Build Coastguard Worker int64_t sum; 158*d9f75844SAndroid Build Coastguard Worker int64_t num_samples; 159*d9f75844SAndroid Build Coastguard Worker }; 160*d9f75844SAndroid Build Coastguard Worker struct StatsUpdateTimes { StatsUpdateTimesStatsUpdateTimes161*d9f75844SAndroid Build Coastguard Worker StatsUpdateTimes() : resolution_update_ms(0), bitrate_update_ms(0) {} 162*d9f75844SAndroid Build Coastguard Worker int64_t resolution_update_ms; 163*d9f75844SAndroid Build Coastguard Worker int64_t bitrate_update_ms; 164*d9f75844SAndroid Build Coastguard Worker }; 165*d9f75844SAndroid Build Coastguard Worker struct TargetRateUpdates { TargetRateUpdatesTargetRateUpdates166*d9f75844SAndroid Build Coastguard Worker TargetRateUpdates() 167*d9f75844SAndroid Build Coastguard Worker : pause_resume_events(0), last_paused_or_resumed(false), last_ms(-1) {} 168*d9f75844SAndroid Build Coastguard Worker int pause_resume_events; 169*d9f75844SAndroid Build Coastguard Worker bool last_paused_or_resumed; 170*d9f75844SAndroid Build Coastguard Worker int64_t last_ms; 171*d9f75844SAndroid Build Coastguard Worker }; 172*d9f75844SAndroid Build Coastguard Worker struct FallbackEncoderInfo { 173*d9f75844SAndroid Build Coastguard Worker FallbackEncoderInfo(); 174*d9f75844SAndroid Build Coastguard Worker bool is_possible = true; 175*d9f75844SAndroid Build Coastguard Worker bool is_active = false; 176*d9f75844SAndroid Build Coastguard Worker int on_off_events = 0; 177*d9f75844SAndroid Build Coastguard Worker int64_t elapsed_ms = 0; 178*d9f75844SAndroid Build Coastguard Worker absl::optional<int64_t> last_update_ms; 179*d9f75844SAndroid Build Coastguard Worker const int max_frame_diff_ms = 2000; 180*d9f75844SAndroid Build Coastguard Worker }; 181*d9f75844SAndroid Build Coastguard Worker struct FallbackEncoderInfoDisabled { 182*d9f75844SAndroid Build Coastguard Worker bool is_possible = true; 183*d9f75844SAndroid Build Coastguard Worker bool min_pixel_limit_reached = false; 184*d9f75844SAndroid Build Coastguard Worker }; 185*d9f75844SAndroid Build Coastguard Worker struct StatsTimer { 186*d9f75844SAndroid Build Coastguard Worker void Start(int64_t now_ms); 187*d9f75844SAndroid Build Coastguard Worker void Stop(int64_t now_ms); 188*d9f75844SAndroid Build Coastguard Worker void Restart(int64_t now_ms); 189*d9f75844SAndroid Build Coastguard Worker int64_t start_ms = -1; 190*d9f75844SAndroid Build Coastguard Worker int64_t total_ms = 0; 191*d9f75844SAndroid Build Coastguard Worker }; 192*d9f75844SAndroid Build Coastguard Worker struct QpCounters { 193*d9f75844SAndroid Build Coastguard Worker SampleCounter vp8; // QP range: 0-127. 194*d9f75844SAndroid Build Coastguard Worker SampleCounter vp9; // QP range: 0-255. 195*d9f75844SAndroid Build Coastguard Worker SampleCounter h264; // QP range: 0-51. 196*d9f75844SAndroid Build Coastguard Worker }; 197*d9f75844SAndroid Build Coastguard Worker struct AdaptChanges { 198*d9f75844SAndroid Build Coastguard Worker int down = 0; 199*d9f75844SAndroid Build Coastguard Worker int up = 0; 200*d9f75844SAndroid Build Coastguard Worker }; 201*d9f75844SAndroid Build Coastguard Worker 202*d9f75844SAndroid Build Coastguard Worker // Map holding encoded frames (mapped by timestamp). 203*d9f75844SAndroid Build Coastguard Worker // If simulcast layers are encoded on different threads, there is no guarantee 204*d9f75844SAndroid Build Coastguard Worker // that one frame of all layers are encoded before the next start. 205*d9f75844SAndroid Build Coastguard Worker struct TimestampOlderThan { operatorTimestampOlderThan206*d9f75844SAndroid Build Coastguard Worker bool operator()(uint32_t ts1, uint32_t ts2) const { 207*d9f75844SAndroid Build Coastguard Worker return IsNewerTimestamp(ts2, ts1); 208*d9f75844SAndroid Build Coastguard Worker } 209*d9f75844SAndroid Build Coastguard Worker }; 210*d9f75844SAndroid Build Coastguard Worker struct Frame { FrameFrame211*d9f75844SAndroid Build Coastguard Worker Frame(int64_t send_ms, uint32_t width, uint32_t height, int simulcast_idx) 212*d9f75844SAndroid Build Coastguard Worker : send_ms(send_ms), 213*d9f75844SAndroid Build Coastguard Worker max_width(width), 214*d9f75844SAndroid Build Coastguard Worker max_height(height), 215*d9f75844SAndroid Build Coastguard Worker max_simulcast_idx(simulcast_idx) {} 216*d9f75844SAndroid Build Coastguard Worker const int64_t 217*d9f75844SAndroid Build Coastguard Worker send_ms; // Time when first frame with this timestamp is sent. 218*d9f75844SAndroid Build Coastguard Worker uint32_t max_width; // Max width with this timestamp. 219*d9f75844SAndroid Build Coastguard Worker uint32_t max_height; // Max height with this timestamp. 220*d9f75844SAndroid Build Coastguard Worker int max_simulcast_idx; // Max simulcast index with this timestamp. 221*d9f75844SAndroid Build Coastguard Worker }; 222*d9f75844SAndroid Build Coastguard Worker typedef std::map<uint32_t, Frame, TimestampOlderThan> EncodedFrameMap; 223*d9f75844SAndroid Build Coastguard Worker 224*d9f75844SAndroid Build Coastguard Worker void PurgeOldStats() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_); 225*d9f75844SAndroid Build Coastguard Worker VideoSendStream::StreamStats* GetStatsEntry(uint32_t ssrc) 226*d9f75844SAndroid Build Coastguard Worker RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_); 227*d9f75844SAndroid Build Coastguard Worker 228*d9f75844SAndroid Build Coastguard Worker struct MaskedAdaptationCounts { 229*d9f75844SAndroid Build Coastguard Worker absl::optional<int> resolution_adaptations = absl::nullopt; 230*d9f75844SAndroid Build Coastguard Worker absl::optional<int> num_framerate_reductions = absl::nullopt; 231*d9f75844SAndroid Build Coastguard Worker }; 232*d9f75844SAndroid Build Coastguard Worker 233*d9f75844SAndroid Build Coastguard Worker struct Adaptations { 234*d9f75844SAndroid Build Coastguard Worker public: 235*d9f75844SAndroid Build Coastguard Worker MaskedAdaptationCounts MaskedCpuCounts() const; 236*d9f75844SAndroid Build Coastguard Worker MaskedAdaptationCounts MaskedQualityCounts() const; 237*d9f75844SAndroid Build Coastguard Worker 238*d9f75844SAndroid Build Coastguard Worker void set_cpu_counts(const VideoAdaptationCounters& cpu_counts); 239*d9f75844SAndroid Build Coastguard Worker void set_quality_counts(const VideoAdaptationCounters& quality_counts); 240*d9f75844SAndroid Build Coastguard Worker 241*d9f75844SAndroid Build Coastguard Worker VideoAdaptationCounters cpu_counts() const; 242*d9f75844SAndroid Build Coastguard Worker VideoAdaptationCounters quality_counts() const; 243*d9f75844SAndroid Build Coastguard Worker 244*d9f75844SAndroid Build Coastguard Worker void UpdateMaskingSettings(AdaptationSettings cpu_settings, 245*d9f75844SAndroid Build Coastguard Worker AdaptationSettings quality_settings); 246*d9f75844SAndroid Build Coastguard Worker 247*d9f75844SAndroid Build Coastguard Worker private: 248*d9f75844SAndroid Build Coastguard Worker VideoAdaptationCounters cpu_counts_; 249*d9f75844SAndroid Build Coastguard Worker AdaptationSettings cpu_settings_; 250*d9f75844SAndroid Build Coastguard Worker VideoAdaptationCounters quality_counts_; 251*d9f75844SAndroid Build Coastguard Worker AdaptationSettings quality_settings_; 252*d9f75844SAndroid Build Coastguard Worker 253*d9f75844SAndroid Build Coastguard Worker MaskedAdaptationCounts Mask(const VideoAdaptationCounters& counters, 254*d9f75844SAndroid Build Coastguard Worker const AdaptationSettings& settings) const; 255*d9f75844SAndroid Build Coastguard Worker }; 256*d9f75844SAndroid Build Coastguard Worker 257*d9f75844SAndroid Build Coastguard Worker void SetAdaptTimer(const MaskedAdaptationCounts& counts, StatsTimer* timer) 258*d9f75844SAndroid Build Coastguard Worker RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_); 259*d9f75844SAndroid Build Coastguard Worker void UpdateAdaptationStats() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_); 260*d9f75844SAndroid Build Coastguard Worker void TryUpdateInitialQualityResolutionAdaptUp( 261*d9f75844SAndroid Build Coastguard Worker absl::optional<int> old_quality_downscales, 262*d9f75844SAndroid Build Coastguard Worker absl::optional<int> updated_quality_downscales) 263*d9f75844SAndroid Build Coastguard Worker RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_); 264*d9f75844SAndroid Build Coastguard Worker 265*d9f75844SAndroid Build Coastguard Worker void UpdateEncoderFallbackStats(const CodecSpecificInfo* codec_info, 266*d9f75844SAndroid Build Coastguard Worker int pixels, 267*d9f75844SAndroid Build Coastguard Worker int simulcast_index) 268*d9f75844SAndroid Build Coastguard Worker RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_); 269*d9f75844SAndroid Build Coastguard Worker void UpdateFallbackDisabledStats(const CodecSpecificInfo* codec_info, 270*d9f75844SAndroid Build Coastguard Worker int pixels, 271*d9f75844SAndroid Build Coastguard Worker int simulcast_index) 272*d9f75844SAndroid Build Coastguard Worker RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_); 273*d9f75844SAndroid Build Coastguard Worker 274*d9f75844SAndroid Build Coastguard Worker Clock* const clock_; 275*d9f75844SAndroid Build Coastguard Worker const std::string payload_name_; 276*d9f75844SAndroid Build Coastguard Worker const RtpConfig rtp_config_; 277*d9f75844SAndroid Build Coastguard Worker const absl::optional<int> fallback_max_pixels_; 278*d9f75844SAndroid Build Coastguard Worker const absl::optional<int> fallback_max_pixels_disabled_; 279*d9f75844SAndroid Build Coastguard Worker mutable Mutex mutex_; 280*d9f75844SAndroid Build Coastguard Worker VideoEncoderConfig::ContentType content_type_ RTC_GUARDED_BY(mutex_); 281*d9f75844SAndroid Build Coastguard Worker const int64_t start_ms_; 282*d9f75844SAndroid Build Coastguard Worker VideoSendStream::Stats stats_ RTC_GUARDED_BY(mutex_); 283*d9f75844SAndroid Build Coastguard Worker std::map<uint32_t, StatsUpdateTimes> update_times_ RTC_GUARDED_BY(mutex_); 284*d9f75844SAndroid Build Coastguard Worker rtc::ExpFilter encode_time_ RTC_GUARDED_BY(mutex_); 285*d9f75844SAndroid Build Coastguard Worker QualityLimitationReasonTracker quality_limitation_reason_tracker_ 286*d9f75844SAndroid Build Coastguard Worker RTC_GUARDED_BY(mutex_); 287*d9f75844SAndroid Build Coastguard Worker rtc::RateTracker media_byte_rate_tracker_ RTC_GUARDED_BY(mutex_); 288*d9f75844SAndroid Build Coastguard Worker rtc::RateTracker encoded_frame_rate_tracker_ RTC_GUARDED_BY(mutex_); 289*d9f75844SAndroid Build Coastguard Worker // Rate trackers mapped by ssrc. 290*d9f75844SAndroid Build Coastguard Worker std::map<uint32_t, std::unique_ptr<rtc::RateTracker>> 291*d9f75844SAndroid Build Coastguard Worker encoded_frame_rate_trackers_ RTC_GUARDED_BY(mutex_); 292*d9f75844SAndroid Build Coastguard Worker 293*d9f75844SAndroid Build Coastguard Worker absl::optional<int64_t> last_outlier_timestamp_ RTC_GUARDED_BY(mutex_); 294*d9f75844SAndroid Build Coastguard Worker 295*d9f75844SAndroid Build Coastguard Worker int last_num_spatial_layers_ RTC_GUARDED_BY(mutex_); 296*d9f75844SAndroid Build Coastguard Worker int last_num_simulcast_streams_ RTC_GUARDED_BY(mutex_); 297*d9f75844SAndroid Build Coastguard Worker std::array<bool, kMaxSpatialLayers> last_spatial_layer_use_ 298*d9f75844SAndroid Build Coastguard Worker RTC_GUARDED_BY(mutex_); 299*d9f75844SAndroid Build Coastguard Worker // Indicates if the latest bitrate allocation had layers disabled by low 300*d9f75844SAndroid Build Coastguard Worker // available bandwidth. 301*d9f75844SAndroid Build Coastguard Worker bool bw_limited_layers_ RTC_GUARDED_BY(mutex_); 302*d9f75844SAndroid Build Coastguard Worker // Indicastes if the encoder internally downscales input image. 303*d9f75844SAndroid Build Coastguard Worker bool internal_encoder_scaler_ RTC_GUARDED_BY(mutex_); 304*d9f75844SAndroid Build Coastguard Worker Adaptations adaptation_limitations_ RTC_GUARDED_BY(mutex_); 305*d9f75844SAndroid Build Coastguard Worker 306*d9f75844SAndroid Build Coastguard Worker struct EncoderChangeEvent { 307*d9f75844SAndroid Build Coastguard Worker std::string previous_encoder_implementation; 308*d9f75844SAndroid Build Coastguard Worker std::string new_encoder_implementation; 309*d9f75844SAndroid Build Coastguard Worker }; 310*d9f75844SAndroid Build Coastguard Worker // Stores the last change in encoder implementation in an optional, so that 311*d9f75844SAndroid Build Coastguard Worker // the event can be consumed. 312*d9f75844SAndroid Build Coastguard Worker absl::optional<EncoderChangeEvent> encoder_changed_; 313*d9f75844SAndroid Build Coastguard Worker 314*d9f75844SAndroid Build Coastguard Worker // Contains stats used for UMA histograms. These stats will be reset if 315*d9f75844SAndroid Build Coastguard Worker // content type changes between real-time video and screenshare, since these 316*d9f75844SAndroid Build Coastguard Worker // will be reported separately. 317*d9f75844SAndroid Build Coastguard Worker struct UmaSamplesContainer { 318*d9f75844SAndroid Build Coastguard Worker UmaSamplesContainer(const char* prefix, 319*d9f75844SAndroid Build Coastguard Worker const VideoSendStream::Stats& start_stats, 320*d9f75844SAndroid Build Coastguard Worker Clock* clock); 321*d9f75844SAndroid Build Coastguard Worker ~UmaSamplesContainer(); 322*d9f75844SAndroid Build Coastguard Worker 323*d9f75844SAndroid Build Coastguard Worker void UpdateHistograms(const RtpConfig& rtp_config, 324*d9f75844SAndroid Build Coastguard Worker const VideoSendStream::Stats& current_stats); 325*d9f75844SAndroid Build Coastguard Worker 326*d9f75844SAndroid Build Coastguard Worker void InitializeBitrateCounters(const VideoSendStream::Stats& stats); 327*d9f75844SAndroid Build Coastguard Worker 328*d9f75844SAndroid Build Coastguard Worker bool InsertEncodedFrame(const EncodedImage& encoded_frame, 329*d9f75844SAndroid Build Coastguard Worker int simulcast_idx); 330*d9f75844SAndroid Build Coastguard Worker void RemoveOld(int64_t now_ms); 331*d9f75844SAndroid Build Coastguard Worker 332*d9f75844SAndroid Build Coastguard Worker const std::string uma_prefix_; 333*d9f75844SAndroid Build Coastguard Worker Clock* const clock_; 334*d9f75844SAndroid Build Coastguard Worker SampleCounter input_width_counter_; 335*d9f75844SAndroid Build Coastguard Worker SampleCounter input_height_counter_; 336*d9f75844SAndroid Build Coastguard Worker SampleCounter sent_width_counter_; 337*d9f75844SAndroid Build Coastguard Worker SampleCounter sent_height_counter_; 338*d9f75844SAndroid Build Coastguard Worker SampleCounter encode_time_counter_; 339*d9f75844SAndroid Build Coastguard Worker BoolSampleCounter key_frame_counter_; 340*d9f75844SAndroid Build Coastguard Worker BoolSampleCounter quality_limited_frame_counter_; 341*d9f75844SAndroid Build Coastguard Worker SampleCounter quality_downscales_counter_; 342*d9f75844SAndroid Build Coastguard Worker BoolSampleCounter cpu_limited_frame_counter_; 343*d9f75844SAndroid Build Coastguard Worker BoolSampleCounter bw_limited_frame_counter_; 344*d9f75844SAndroid Build Coastguard Worker SampleCounter bw_resolutions_disabled_counter_; 345*d9f75844SAndroid Build Coastguard Worker SampleCounter delay_counter_; 346*d9f75844SAndroid Build Coastguard Worker SampleCounter max_delay_counter_; 347*d9f75844SAndroid Build Coastguard Worker rtc::RateTracker input_frame_rate_tracker_; 348*d9f75844SAndroid Build Coastguard Worker RateCounter input_fps_counter_; 349*d9f75844SAndroid Build Coastguard Worker RateCounter sent_fps_counter_; 350*d9f75844SAndroid Build Coastguard Worker RateAccCounter total_byte_counter_; 351*d9f75844SAndroid Build Coastguard Worker RateAccCounter media_byte_counter_; 352*d9f75844SAndroid Build Coastguard Worker RateAccCounter rtx_byte_counter_; 353*d9f75844SAndroid Build Coastguard Worker RateAccCounter padding_byte_counter_; 354*d9f75844SAndroid Build Coastguard Worker RateAccCounter retransmit_byte_counter_; 355*d9f75844SAndroid Build Coastguard Worker RateAccCounter fec_byte_counter_; 356*d9f75844SAndroid Build Coastguard Worker int64_t first_rtcp_stats_time_ms_; 357*d9f75844SAndroid Build Coastguard Worker int64_t first_rtp_stats_time_ms_; 358*d9f75844SAndroid Build Coastguard Worker StatsTimer cpu_adapt_timer_; 359*d9f75844SAndroid Build Coastguard Worker StatsTimer quality_adapt_timer_; 360*d9f75844SAndroid Build Coastguard Worker BoolSampleCounter paused_time_counter_; 361*d9f75844SAndroid Build Coastguard Worker TargetRateUpdates target_rate_updates_; 362*d9f75844SAndroid Build Coastguard Worker BoolSampleCounter fallback_active_counter_; 363*d9f75844SAndroid Build Coastguard Worker FallbackEncoderInfo fallback_info_; 364*d9f75844SAndroid Build Coastguard Worker FallbackEncoderInfoDisabled fallback_info_disabled_; 365*d9f75844SAndroid Build Coastguard Worker ReportBlockStats report_block_stats_; 366*d9f75844SAndroid Build Coastguard Worker const VideoSendStream::Stats start_stats_; 367*d9f75844SAndroid Build Coastguard Worker size_t num_streams_; // Number of configured streams to encoder. 368*d9f75844SAndroid Build Coastguard Worker size_t num_pixels_highest_stream_; 369*d9f75844SAndroid Build Coastguard Worker EncodedFrameMap encoded_frames_; 370*d9f75844SAndroid Build Coastguard Worker AdaptChanges initial_quality_changes_; 371*d9f75844SAndroid Build Coastguard Worker 372*d9f75844SAndroid Build Coastguard Worker std::map<int, QpCounters> 373*d9f75844SAndroid Build Coastguard Worker qp_counters_; // QP counters mapped by spatial idx. 374*d9f75844SAndroid Build Coastguard Worker }; 375*d9f75844SAndroid Build Coastguard Worker 376*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<UmaSamplesContainer> uma_container_ RTC_GUARDED_BY(mutex_); 377*d9f75844SAndroid Build Coastguard Worker }; 378*d9f75844SAndroid Build Coastguard Worker 379*d9f75844SAndroid Build Coastguard Worker } // namespace webrtc 380*d9f75844SAndroid Build Coastguard Worker #endif // VIDEO_SEND_STATISTICS_PROXY_H_ 381