2014-02-07 12:06:29 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#ifndef VIDEO_RECEIVE_STATISTICS_PROXY_H_
|
|
|
|
|
#define VIDEO_RECEIVE_STATISTICS_PROXY_H_
|
2014-02-07 12:06:29 +00:00
|
|
|
|
2016-02-24 01:35:40 -08:00
|
|
|
#include <map>
|
2018-05-23 11:53:19 +02:00
|
|
|
#include <memory>
|
2014-02-07 12:06:29 +00:00
|
|
|
#include <string>
|
2017-10-06 12:29:47 +02:00
|
|
|
#include <vector>
|
2014-02-07 12:06:29 +00:00
|
|
|
|
2018-06-15 12:28:07 +02:00
|
|
|
#include "absl/types/optional.h"
|
2022-03-29 11:04:48 +02:00
|
|
|
#include "api/field_trials_view.h"
|
2021-02-10 14:31:24 +01:00
|
|
|
#include "api/sequence_checker.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "call/video_receive_stream.h"
|
2019-09-23 10:31:16 +02:00
|
|
|
#include "modules/include/module_common_types.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/video_coding/include/video_coding_defines.h"
|
2017-11-22 12:25:14 +01:00
|
|
|
#include "rtc_base/numerics/histogram_percentile_counter.h"
|
|
|
|
|
#include "rtc_base/numerics/moving_max_counter.h"
|
2018-05-22 10:54:30 +02:00
|
|
|
#include "rtc_base/numerics/sample_counter.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/rate_statistics.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/rate_tracker.h"
|
2020-07-08 13:13:32 +02:00
|
|
|
#include "rtc_base/synchronization/mutex.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/thread_annotations.h"
|
|
|
|
|
#include "video/quality_threshold.h"
|
|
|
|
|
#include "video/stats_counter.h"
|
2018-05-23 11:53:19 +02:00
|
|
|
#include "video/video_quality_observer.h"
|
2014-02-07 12:06:29 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
class Clock;
|
2015-10-20 23:55:26 -07:00
|
|
|
struct CodecSpecificInfo;
|
2014-02-07 12:06:29 +00:00
|
|
|
|
2015-08-28 07:35:32 -07:00
|
|
|
class ReceiveStatisticsProxy : public VCMReceiveStatisticsCallback,
|
2019-08-05 12:45:19 +02:00
|
|
|
public RtcpCnameCallback,
|
2015-02-19 12:47:00 +00:00
|
|
|
public RtcpPacketTypeCounterObserver,
|
2017-02-22 05:30:39 -08:00
|
|
|
public CallStatsObserver {
|
2014-02-07 12:06:29 +00:00
|
|
|
public:
|
2022-03-14 12:52:48 +01:00
|
|
|
ReceiveStatisticsProxy(uint32_t remote_ssrc,
|
|
|
|
|
Clock* clock,
|
2022-03-29 11:04:48 +02:00
|
|
|
const FieldTrialsView* field_trials = nullptr);
|
2020-04-07 18:02:39 +00:00
|
|
|
~ReceiveStatisticsProxy() = default;
|
2014-02-07 12:06:29 +00:00
|
|
|
|
|
|
|
|
VideoReceiveStream::Stats GetStats() const;
|
|
|
|
|
|
2019-01-09 14:37:40 +01:00
|
|
|
void OnDecodedFrame(const VideoFrame& frame,
|
|
|
|
|
absl::optional<uint8_t> qp,
|
2019-07-01 10:07:50 +02:00
|
|
|
int32_t decode_time_ms,
|
2018-05-23 11:53:19 +02:00
|
|
|
VideoContentType content_type);
|
2019-10-22 15:23:44 +02:00
|
|
|
void OnSyncOffsetUpdated(int64_t video_playout_ntp_ms,
|
|
|
|
|
int64_t sync_offset_ms,
|
|
|
|
|
double estimated_freq_khz);
|
2016-09-23 02:09:46 -07:00
|
|
|
void OnRenderedFrame(const VideoFrame& frame);
|
2015-08-28 07:35:32 -07:00
|
|
|
void OnIncomingPayloadType(int payload_type);
|
2015-12-18 16:01:11 +01:00
|
|
|
void OnDecoderImplementationName(const char* implementation_name);
|
2014-02-07 12:06:29 +00:00
|
|
|
|
2018-10-01 15:56:33 +02:00
|
|
|
void OnPreDecode(VideoCodecType codec_type, int qp);
|
2015-10-20 23:55:26 -07:00
|
|
|
|
2018-02-21 15:57:09 +01:00
|
|
|
void OnUniqueFramesCounted(int num_unique_frames);
|
|
|
|
|
|
2017-08-22 09:23:28 -07:00
|
|
|
// Indicates video stream has been paused (no incoming packets).
|
|
|
|
|
void OnStreamInactive();
|
|
|
|
|
|
2015-07-22 06:52:00 -07:00
|
|
|
// Overrides VCMReceiveStatisticsCallback.
|
2017-08-30 03:32:14 -07:00
|
|
|
void OnCompleteFrame(bool is_keyframe,
|
|
|
|
|
size_t size_bytes,
|
|
|
|
|
VideoContentType content_type) override;
|
2019-08-26 15:04:43 +02:00
|
|
|
void OnDroppedFrames(uint32_t frames_dropped) override;
|
2019-07-01 10:07:50 +02:00
|
|
|
void OnFrameBufferTimingsUpdated(int max_decode_ms,
|
2017-02-22 05:30:39 -08:00
|
|
|
int current_delay_ms,
|
|
|
|
|
int target_delay_ms,
|
|
|
|
|
int jitter_buffer_ms,
|
|
|
|
|
int min_playout_delay_ms,
|
|
|
|
|
int render_delay_ms) override;
|
2014-12-19 15:45:03 +00:00
|
|
|
|
2017-07-06 03:06:50 -07:00
|
|
|
void OnTimingFrameInfoUpdated(const TimingFrameInfo& info) override;
|
|
|
|
|
|
2019-08-05 12:45:19 +02:00
|
|
|
// Overrides RtcpCnameCallback.
|
|
|
|
|
void OnCname(uint32_t ssrc, absl::string_view cname) override;
|
2014-02-07 12:06:29 +00:00
|
|
|
|
2015-07-22 06:52:00 -07:00
|
|
|
// Overrides RtcpPacketTypeCounterObserver.
|
2015-03-04 12:58:35 +00:00
|
|
|
void RtcpPacketTypesCounterUpdated(
|
2015-02-19 12:47:00 +00:00
|
|
|
uint32_t ssrc,
|
2015-03-04 12:58:35 +00:00
|
|
|
const RtcpPacketTypeCounter& packet_counter) override;
|
2014-02-07 12:06:29 +00:00
|
|
|
|
2017-02-22 05:30:39 -08:00
|
|
|
// Implements CallStatsObserver.
|
|
|
|
|
void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) override;
|
|
|
|
|
|
2018-02-24 17:57:33 +01:00
|
|
|
// Notification methods that are used to check our internal state and validate
|
|
|
|
|
// threading assumptions. These are called by VideoReceiveStream.
|
|
|
|
|
void DecoderThreadStarting();
|
|
|
|
|
void DecoderThreadStopped();
|
|
|
|
|
|
2019-08-02 13:52:37 +02:00
|
|
|
// Produce histograms. Must be called after DecoderThreadStopped(), typically
|
|
|
|
|
// at the end of the call.
|
2019-08-13 14:43:02 +02:00
|
|
|
void UpdateHistograms(absl::optional<int> fraction_lost,
|
|
|
|
|
const StreamDataCounters& rtp_stats,
|
|
|
|
|
const StreamDataCounters* rtx_stats);
|
2019-08-02 13:52:37 +02:00
|
|
|
|
2014-12-18 13:50:16 +00:00
|
|
|
private:
|
2015-10-20 23:55:26 -07:00
|
|
|
struct QpCounters {
|
2018-05-22 10:54:30 +02:00
|
|
|
rtc::SampleCounter vp8;
|
2015-10-20 23:55:26 -07:00
|
|
|
};
|
2015-07-22 06:52:00 -07:00
|
|
|
|
2017-08-30 03:32:14 -07:00
|
|
|
struct ContentSpecificStats {
|
2017-10-06 12:29:47 +02:00
|
|
|
ContentSpecificStats();
|
2018-08-28 16:30:18 +02:00
|
|
|
~ContentSpecificStats();
|
2017-10-06 12:29:47 +02:00
|
|
|
|
2017-08-30 03:32:14 -07:00
|
|
|
void Add(const ContentSpecificStats& other);
|
|
|
|
|
|
2018-05-22 10:54:30 +02:00
|
|
|
rtc::SampleCounter e2e_delay_counter;
|
|
|
|
|
rtc::SampleCounter interframe_delay_counter;
|
2017-08-30 03:32:14 -07:00
|
|
|
int64_t flow_duration_ms = 0;
|
|
|
|
|
int64_t total_media_bytes = 0;
|
2018-05-22 10:54:30 +02:00
|
|
|
rtc::SampleCounter received_width;
|
|
|
|
|
rtc::SampleCounter received_height;
|
|
|
|
|
rtc::SampleCounter qp_counter;
|
2017-08-30 03:32:14 -07:00
|
|
|
FrameCounts frame_counts;
|
2017-10-12 12:38:01 +02:00
|
|
|
rtc::HistogramPercentileCounter interframe_delay_percentiles;
|
2017-08-30 03:32:14 -07:00
|
|
|
};
|
|
|
|
|
|
2020-07-08 13:13:32 +02:00
|
|
|
void QualitySample() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
|
2016-12-13 02:45:57 -08:00
|
|
|
|
2017-03-28 02:44:58 -07:00
|
|
|
// Removes info about old frames and then updates the framerate.
|
2017-09-09 04:17:22 -07:00
|
|
|
void UpdateFramerate(int64_t now_ms) const
|
2020-07-08 13:13:32 +02:00
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
|
2017-02-22 05:30:39 -08:00
|
|
|
|
2019-10-22 13:22:26 +02:00
|
|
|
void UpdateDecodeTimeHistograms(int width,
|
|
|
|
|
int height,
|
|
|
|
|
int decode_time_ms) const
|
2020-07-08 13:13:32 +02:00
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
|
2019-10-22 13:22:26 +02:00
|
|
|
|
2019-10-22 15:23:44 +02:00
|
|
|
absl::optional<int64_t> GetCurrentEstimatedPlayoutNtpTimestampMs(
|
2020-07-08 13:13:32 +02:00
|
|
|
int64_t now_ms) const RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
|
2019-10-22 15:23:44 +02:00
|
|
|
|
2014-04-28 13:00:21 +00:00
|
|
|
Clock* const clock_;
|
2016-07-27 00:39:09 -07:00
|
|
|
const int64_t start_ms_;
|
2019-10-22 13:22:26 +02:00
|
|
|
const bool enable_decode_time_histograms_;
|
2014-04-28 13:00:21 +00:00
|
|
|
|
2020-07-08 13:13:32 +02:00
|
|
|
mutable Mutex mutex_;
|
|
|
|
|
int64_t last_sample_time_ RTC_GUARDED_BY(mutex_);
|
|
|
|
|
QualityThreshold fps_threshold_ RTC_GUARDED_BY(mutex_);
|
|
|
|
|
QualityThreshold qp_threshold_ RTC_GUARDED_BY(mutex_);
|
|
|
|
|
QualityThreshold variance_threshold_ RTC_GUARDED_BY(mutex_);
|
|
|
|
|
rtc::SampleCounter qp_sample_ RTC_GUARDED_BY(mutex_);
|
|
|
|
|
int num_bad_states_ RTC_GUARDED_BY(mutex_);
|
|
|
|
|
int num_certain_states_ RTC_GUARDED_BY(mutex_);
|
2021-08-10 01:22:31 +02:00
|
|
|
// Note: The `stats_.rtp_stats` member is not used or populated by this class.
|
2020-07-08 13:13:32 +02:00
|
|
|
mutable VideoReceiveStream::Stats stats_ RTC_GUARDED_BY(mutex_);
|
|
|
|
|
RateStatistics decode_fps_estimator_ RTC_GUARDED_BY(mutex_);
|
|
|
|
|
RateStatistics renders_fps_estimator_ RTC_GUARDED_BY(mutex_);
|
|
|
|
|
rtc::RateTracker render_fps_tracker_ RTC_GUARDED_BY(mutex_);
|
|
|
|
|
rtc::RateTracker render_pixel_tracker_ RTC_GUARDED_BY(mutex_);
|
|
|
|
|
rtc::SampleCounter sync_offset_counter_ RTC_GUARDED_BY(mutex_);
|
|
|
|
|
rtc::SampleCounter decode_time_counter_ RTC_GUARDED_BY(mutex_);
|
|
|
|
|
rtc::SampleCounter jitter_buffer_delay_counter_ RTC_GUARDED_BY(mutex_);
|
|
|
|
|
rtc::SampleCounter target_delay_counter_ RTC_GUARDED_BY(mutex_);
|
|
|
|
|
rtc::SampleCounter current_delay_counter_ RTC_GUARDED_BY(mutex_);
|
|
|
|
|
rtc::SampleCounter delay_counter_ RTC_GUARDED_BY(mutex_);
|
2018-05-23 11:53:19 +02:00
|
|
|
std::unique_ptr<VideoQualityObserver> video_quality_observer_
|
2020-07-08 13:13:32 +02:00
|
|
|
RTC_GUARDED_BY(mutex_);
|
2017-08-23 05:24:10 -07:00
|
|
|
mutable rtc::MovingMaxCounter<int> interframe_delay_max_moving_
|
2020-07-08 13:13:32 +02:00
|
|
|
RTC_GUARDED_BY(mutex_);
|
2017-08-30 03:32:14 -07:00
|
|
|
std::map<VideoContentType, ContentSpecificStats> content_specific_stats_
|
2020-07-08 13:13:32 +02:00
|
|
|
RTC_GUARDED_BY(mutex_);
|
|
|
|
|
MaxCounter freq_offset_counter_ RTC_GUARDED_BY(mutex_);
|
2020-04-07 18:02:39 +00:00
|
|
|
QpCounters qp_counters_ RTC_GUARDED_BY(decode_thread_);
|
2020-07-08 13:13:32 +02:00
|
|
|
int64_t avg_rtt_ms_ RTC_GUARDED_BY(mutex_);
|
|
|
|
|
mutable std::map<int64_t, size_t> frame_window_ RTC_GUARDED_BY(&mutex_);
|
|
|
|
|
VideoContentType last_content_type_ RTC_GUARDED_BY(&mutex_);
|
|
|
|
|
VideoCodecType last_codec_type_ RTC_GUARDED_BY(&mutex_);
|
|
|
|
|
absl::optional<int64_t> first_frame_received_time_ms_ RTC_GUARDED_BY(&mutex_);
|
|
|
|
|
absl::optional<int64_t> first_decoded_frame_time_ms_ RTC_GUARDED_BY(&mutex_);
|
|
|
|
|
absl::optional<int64_t> last_decoded_frame_time_ms_ RTC_GUARDED_BY(&mutex_);
|
|
|
|
|
size_t num_delayed_frames_rendered_ RTC_GUARDED_BY(&mutex_);
|
|
|
|
|
int64_t sum_missed_render_deadline_ms_ RTC_GUARDED_BY(&mutex_);
|
2017-09-04 03:35:40 -07:00
|
|
|
// Mutable because calling Max() on MovingMaxCounter is not const. Yet it is
|
|
|
|
|
// called from const GetStats().
|
|
|
|
|
mutable rtc::MovingMaxCounter<TimingFrameInfo> timing_frame_info_counter_
|
2020-07-08 13:13:32 +02:00
|
|
|
RTC_GUARDED_BY(&mutex_);
|
|
|
|
|
absl::optional<int> num_unique_frames_ RTC_GUARDED_BY(mutex_);
|
2019-10-22 15:23:44 +02:00
|
|
|
absl::optional<int64_t> last_estimated_playout_ntp_timestamp_ms_
|
2020-07-08 13:13:32 +02:00
|
|
|
RTC_GUARDED_BY(&mutex_);
|
2019-10-22 15:23:44 +02:00
|
|
|
absl::optional<int64_t> last_estimated_playout_time_ms_
|
2020-07-08 13:13:32 +02:00
|
|
|
RTC_GUARDED_BY(&mutex_);
|
2021-02-02 10:57:19 +01:00
|
|
|
SequenceChecker decode_thread_;
|
|
|
|
|
SequenceChecker network_thread_;
|
|
|
|
|
SequenceChecker main_thread_;
|
2014-02-07 12:06:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // VIDEO_RECEIVE_STATISTICS_PROXY_H_
|