blob: 445a731f240c61eb257a569ed52a4ba67bd5baab [file] [log] [blame]
sprang@webrtc.org09315702014-02-07 12:06:29 +00001/*
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
11#ifndef WEBRTC_VIDEO_RECEIVE_STATISTICS_PROXY_H_
12#define WEBRTC_VIDEO_RECEIVE_STATISTICS_PROXY_H_
13
sprang0ab8e812016-02-24 01:35:40 -080014#include <map>
sprang@webrtc.org09315702014-02-07 12:06:29 +000015#include <string>
16
Peter Boströmf2f82832015-05-01 13:00:41 +020017#include "webrtc/base/criticalsection.h"
tkchinf75d0082016-02-23 22:49:42 -080018#include "webrtc/base/rate_statistics.h"
asaperssond89920b2015-07-22 06:52:00 -070019#include "webrtc/base/ratetracker.h"
pbos@webrtc.org38344ed2014-09-24 06:05:00 +000020#include "webrtc/base/thread_annotations.h"
sprang@webrtc.org09315702014-02-07 12:06:29 +000021#include "webrtc/common_types.h"
pbosa96b60b2016-04-18 21:12:48 -070022#include "webrtc/common_video/include/frame_callback.h"
Henrik Kjellander2557b862015-11-18 22:00:21 +010023#include "webrtc/modules/video_coding/include/video_coding_defines.h"
Peter Boström7623ce42015-12-09 12:13:30 +010024#include "webrtc/video/report_block_stats.h"
asaperssonde9e5ff2016-11-02 07:14:03 -070025#include "webrtc/video/stats_counter.h"
mflodmancfc8e3b2016-05-03 21:22:04 -070026#include "webrtc/video/video_stream_decoder.h"
sprang@webrtc.org09315702014-02-07 12:06:29 +000027#include "webrtc/video_receive_stream.h"
sprang@webrtc.org09315702014-02-07 12:06:29 +000028
29namespace webrtc {
30
31class Clock;
sprang@webrtc.org09315702014-02-07 12:06:29 +000032class ViECodec;
33class ViEDecoderObserver;
asapersson86b01602015-10-20 23:55:26 -070034struct CodecSpecificInfo;
sprang@webrtc.org09315702014-02-07 12:06:29 +000035
pbosf42376c2015-08-28 07:35:32 -070036class ReceiveStatisticsProxy : public VCMReceiveStatisticsCallback,
sprang@webrtc.org09315702014-02-07 12:06:29 +000037 public RtcpStatisticsCallback,
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +000038 public RtcpPacketTypeCounterObserver,
pbos@webrtc.org55707692014-12-19 15:45:03 +000039 public StreamDataCountersCallback {
sprang@webrtc.org09315702014-02-07 12:06:29 +000040 public:
Tommi733b5472016-06-10 17:58:01 +020041 ReceiveStatisticsProxy(const VideoReceiveStream::Config* config,
sprang0ab8e812016-02-24 01:35:40 -080042 Clock* clock);
sprang@webrtc.org09315702014-02-07 12:06:29 +000043 virtual ~ReceiveStatisticsProxy();
44
45 VideoReceiveStream::Stats GetStats() const;
46
47 void OnDecodedFrame();
asaperssonde9e5ff2016-11-02 07:14:03 -070048 void OnSyncOffsetUpdated(int64_t sync_offset_ms, double estimated_freq_khz);
asapersson1490f7a2016-09-23 02:09:46 -070049 void OnRenderedFrame(const VideoFrame& frame);
pbosf42376c2015-08-28 07:35:32 -070050 void OnIncomingPayloadType(int payload_type);
Peter Boströmb7d9a972015-12-18 16:01:11 +010051 void OnDecoderImplementationName(const char* implementation_name);
pbosf42376c2015-08-28 07:35:32 -070052 void OnIncomingRate(unsigned int framerate, unsigned int bitrate_bps);
53 void OnDecoderTiming(int decode_ms,
54 int max_decode_ms,
55 int current_delay_ms,
56 int target_delay_ms,
57 int jitter_buffer_ms,
58 int min_playout_delay_ms,
asapersson13c433c2015-10-06 04:08:15 -070059 int render_delay_ms,
60 int64_t rtt_ms);
sprang@webrtc.org09315702014-02-07 12:06:29 +000061
asapersson86b01602015-10-20 23:55:26 -070062 void OnPreDecode(const EncodedImage& encoded_image,
63 const CodecSpecificInfo* codec_specific_info);
64
asaperssond89920b2015-07-22 06:52:00 -070065 // Overrides VCMReceiveStatisticsCallback.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000066 void OnReceiveRatesUpdated(uint32_t bitRate, uint32_t frameRate) override;
67 void OnFrameCountsUpdated(const FrameCounts& frame_counts) override;
68 void OnDiscardedPacketsUpdated(int discarded_packets) override;
pbos@webrtc.org55707692014-12-19 15:45:03 +000069
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +000070 // Overrides RtcpStatisticsCallback.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000071 void StatisticsUpdated(const webrtc::RtcpStatistics& statistics,
72 uint32_t ssrc) override;
73 void CNameChanged(const char* cname, uint32_t ssrc) override;
sprang@webrtc.org09315702014-02-07 12:06:29 +000074
asaperssond89920b2015-07-22 06:52:00 -070075 // Overrides RtcpPacketTypeCounterObserver.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000076 void RtcpPacketTypesCounterUpdated(
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +000077 uint32_t ssrc,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000078 const RtcpPacketTypeCounter& packet_counter) override;
sprang@webrtc.org09315702014-02-07 12:06:29 +000079 // Overrides StreamDataCountersCallback.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000080 void DataCountersUpdated(const webrtc::StreamDataCounters& counters,
81 uint32_t ssrc) override;
sprang@webrtc.org09315702014-02-07 12:06:29 +000082
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +000083 private:
asaperssond89920b2015-07-22 06:52:00 -070084 struct SampleCounter {
85 SampleCounter() : sum(0), num_samples(0) {}
86 void Add(int sample);
87 int Avg(int min_required_samples) const;
88
89 private:
90 int sum;
91 int num_samples;
92 };
asapersson86b01602015-10-20 23:55:26 -070093 struct QpCounters {
94 SampleCounter vp8;
95 };
asaperssond89920b2015-07-22 06:52:00 -070096
97 void UpdateHistograms() EXCLUSIVE_LOCKS_REQUIRED(crit_);
98
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +000099 Clock* const clock_;
Tommi733b5472016-06-10 17:58:01 +0200100 // Ownership of this object lies with the owner of the ReceiveStatisticsProxy
101 // instance. Lifetime is guaranteed to outlive |this|.
102 // TODO(tommi): In practice the config_ reference is only used for accessing
brandtrb5f2c3f2016-10-04 23:28:39 -0700103 // config_.rtp.ulpfec.ulpfec_payload_type. Instead of holding a pointer back,
Tommi733b5472016-06-10 17:58:01 +0200104 // we could just store the value of ulpfec_payload_type and change the
105 // ReceiveStatisticsProxy() ctor to accept a const& of Config (since we'll
106 // then no longer store a pointer to the object).
107 const VideoReceiveStream::Config& config_;
asapersson4374a092016-07-27 00:39:09 -0700108 const int64_t start_ms_;
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +0000109
pbos5ad935c2016-01-25 03:52:44 -0800110 rtc::CriticalSection crit_;
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +0000111 VideoReceiveStream::Stats stats_ GUARDED_BY(crit_);
112 RateStatistics decode_fps_estimator_ GUARDED_BY(crit_);
113 RateStatistics renders_fps_estimator_ GUARDED_BY(crit_);
Tim Psiaki63046262015-09-14 10:38:08 -0700114 rtc::RateTracker render_fps_tracker_ GUARDED_BY(crit_);
asaperssonf839dcc2015-10-08 00:41:59 -0700115 rtc::RateTracker render_pixel_tracker_ GUARDED_BY(crit_);
asaperssond89920b2015-07-22 06:52:00 -0700116 SampleCounter render_width_counter_ GUARDED_BY(crit_);
117 SampleCounter render_height_counter_ GUARDED_BY(crit_);
asaperssonf8cdd182016-03-15 01:00:47 -0700118 SampleCounter sync_offset_counter_ GUARDED_BY(crit_);
asapersson6718e972015-07-24 00:20:58 -0700119 SampleCounter decode_time_counter_ GUARDED_BY(crit_);
asapersson8688a4e2016-04-27 23:42:35 -0700120 SampleCounter jitter_buffer_delay_counter_ GUARDED_BY(crit_);
121 SampleCounter target_delay_counter_ GUARDED_BY(crit_);
122 SampleCounter current_delay_counter_ GUARDED_BY(crit_);
asapersson13c433c2015-10-06 04:08:15 -0700123 SampleCounter delay_counter_ GUARDED_BY(crit_);
asapersson1490f7a2016-09-23 02:09:46 -0700124 SampleCounter e2e_delay_counter_ GUARDED_BY(crit_);
asaperssonde9e5ff2016-11-02 07:14:03 -0700125 MaxCounter freq_offset_counter_ GUARDED_BY(crit_);
Åsa Persson3c391cb2015-04-27 10:09:49 +0200126 ReportBlockStats report_block_stats_ GUARDED_BY(crit_);
asapersson86b01602015-10-20 23:55:26 -0700127 QpCounters qp_counters_; // Only accessed on the decoding thread.
sprang0ab8e812016-02-24 01:35:40 -0800128 std::map<uint32_t, StreamDataCounters> rtx_stats_ GUARDED_BY(crit_);
sprang@webrtc.org09315702014-02-07 12:06:29 +0000129};
130
sprang@webrtc.org09315702014-02-07 12:06:29 +0000131} // namespace webrtc
132#endif // WEBRTC_VIDEO_RECEIVE_STATISTICS_PROXY_H_