Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(643)

Side by Side Diff: webrtc/video/send_statistics_proxy.h

Issue 1478253002: Add histogram stats for send delay for a sent video stream. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 17 matching lines...) Expand all
28 28
29 namespace webrtc { 29 namespace webrtc {
30 30
31 class SendStatisticsProxy : public CpuOveruseMetricsObserver, 31 class SendStatisticsProxy : public CpuOveruseMetricsObserver,
32 public RtcpStatisticsCallback, 32 public RtcpStatisticsCallback,
33 public RtcpPacketTypeCounterObserver, 33 public RtcpPacketTypeCounterObserver,
34 public StreamDataCountersCallback, 34 public StreamDataCountersCallback,
35 public BitrateStatisticsObserver, 35 public BitrateStatisticsObserver,
36 public FrameCountObserver, 36 public FrameCountObserver,
37 public VideoEncoderRateObserver, 37 public VideoEncoderRateObserver,
38 public SendSideDelayObserver { 38 public SendSideDelayObserver,
39 public SendPacketObserver {
39 public: 40 public:
40 static const int kStatsTimeoutMs; 41 static const int kStatsTimeoutMs;
41 42
42 SendStatisticsProxy(Clock* clock, 43 SendStatisticsProxy(Clock* clock,
43 const VideoSendStream::Config& config, 44 const VideoSendStream::Config& config,
44 VideoEncoderConfig::ContentType content_type); 45 VideoEncoderConfig::ContentType content_type);
45 virtual ~SendStatisticsProxy(); 46 virtual ~SendStatisticsProxy();
46 47
47 VideoSendStream::Stats GetStats(); 48 VideoSendStream::Stats GetStats();
48 49
49 virtual void OnSendEncodedImage(const EncodedImage& encoded_image, 50 virtual void OnSendEncodedImage(const EncodedImage& encoded_image,
50 const RTPVideoHeader* rtp_video_header); 51 const RTPVideoHeader* rtp_video_header);
51 // Used to update incoming frame rate. 52 // Used to update incoming frame rate.
52 void OnIncomingFrame(int width, int height); 53 void OnIncomingFrame(int width, int height);
53 54
54 // Used to update encode time of frames. 55 // Used to update encode time of frames.
55 void OnEncodedFrame(int encode_time_ms); 56 void OnEncodedFrame(int encode_time_ms);
56 57
57 // From VideoEncoderRateObserver. 58 // From VideoEncoderRateObserver.
58 void OnSetRates(uint32_t bitrate_bps, int framerate) override; 59 void OnSetRates(uint32_t bitrate_bps, int framerate) override;
59 60
60 void OnOutgoingRate(uint32_t framerate, uint32_t bitrate); 61 void OnOutgoingRate(uint32_t framerate, uint32_t bitrate);
61 void OnSuspendChange(bool is_suspended); 62 void OnSuspendChange(bool is_suspended);
62 void OnInactiveSsrc(uint32_t ssrc); 63 void OnInactiveSsrc(uint32_t ssrc);
63 64
64 // Used to indicate change in content type, which may require a change in 65 // Used to indicate change in content type, which may require a change in
65 // how stats are collected. 66 // how stats are collected.
66 void SetContentType(VideoEncoderConfig::ContentType content_type); 67 void SetContentType(VideoEncoderConfig::ContentType content_type);
67 68
69 bool OnSentPacket(int packet_id);
70
68 protected: 71 protected:
69 // From CpuOveruseMetricsObserver. 72 // From CpuOveruseMetricsObserver.
70 void CpuOveruseMetricsUpdated(const CpuOveruseMetrics& metrics) override; 73 void CpuOveruseMetricsUpdated(const CpuOveruseMetrics& metrics) override;
71 // From RtcpStatisticsCallback. 74 // From RtcpStatisticsCallback.
72 void StatisticsUpdated(const RtcpStatistics& statistics, 75 void StatisticsUpdated(const RtcpStatistics& statistics,
73 uint32_t ssrc) override; 76 uint32_t ssrc) override;
74 void CNameChanged(const char* cname, uint32_t ssrc) override; 77 void CNameChanged(const char* cname, uint32_t ssrc) override;
75 // From RtcpPacketTypeCounterObserver. 78 // From RtcpPacketTypeCounterObserver.
76 void RtcpPacketTypesCounterUpdated( 79 void RtcpPacketTypesCounterUpdated(
77 uint32_t ssrc, 80 uint32_t ssrc,
78 const RtcpPacketTypeCounter& packet_counter) override; 81 const RtcpPacketTypeCounter& packet_counter) override;
79 // From StreamDataCountersCallback. 82 // From StreamDataCountersCallback.
80 void DataCountersUpdated(const StreamDataCounters& counters, 83 void DataCountersUpdated(const StreamDataCounters& counters,
81 uint32_t ssrc) override; 84 uint32_t ssrc) override;
82 85
83 // From BitrateStatisticsObserver. 86 // From BitrateStatisticsObserver.
84 void Notify(const BitrateStatistics& total_stats, 87 void Notify(const BitrateStatistics& total_stats,
85 const BitrateStatistics& retransmit_stats, 88 const BitrateStatistics& retransmit_stats,
86 uint32_t ssrc) override; 89 uint32_t ssrc) override;
87 90
88 // From FrameCountObserver. 91 // From FrameCountObserver.
89 void FrameCountUpdated(const FrameCounts& frame_counts, 92 void FrameCountUpdated(const FrameCounts& frame_counts,
90 uint32_t ssrc) override; 93 uint32_t ssrc) override;
91 94
92 void SendSideDelayUpdated(int avg_delay_ms, 95 void SendSideDelayUpdated(int avg_delay_ms,
93 int max_delay_ms, 96 int max_delay_ms,
94 uint32_t ssrc) override; 97 uint32_t ssrc) override;
95 98
99 void OnSendPacket(uint16_t packet_id,
100 int64_t capture_time_ms,
101 uint32_t ssrc) override;
102
96 private: 103 private:
104 // Map holding sent packets (mapped by packet id).
105 class PacketIdLessThan {
106 public:
107 bool operator()(uint16_t seq1, uint16_t seq2) const {
108 return IsNewerSequenceNumber(seq2, seq1);
109 }
110 };
111 struct Packet {
112 Packet() : ssrc(0), cap_time_ms(-1), send_time_ms(-1) {}
113 uint32_t ssrc;
114 int64_t cap_time_ms;
stefan-webrtc 2015/12/10 08:37:50 capture_time_ms
åsapersson 2015/12/15 14:28:27 Done.
115 int64_t send_time_ms;
116 };
117 typedef std::map<uint16_t, Packet, PacketIdLessThan> PacketMap;
118
97 class SampleCounter { 119 class SampleCounter {
98 public: 120 public:
99 SampleCounter() : sum(0), num_samples(0) {} 121 SampleCounter() : sum(0), num_samples(0) {}
100 ~SampleCounter() {} 122 ~SampleCounter() {}
101 void Add(int sample); 123 void Add(int sample);
102 int Avg(int min_required_samples) const; 124 int Avg(int min_required_samples) const;
103 125
104 private: 126 private:
105 int sum; 127 int sum;
106 int num_samples; 128 int num_samples;
(...skipping 12 matching lines...) Expand all
119 int num_samples; 141 int num_samples;
120 }; 142 };
121 struct StatsUpdateTimes { 143 struct StatsUpdateTimes {
122 StatsUpdateTimes() : resolution_update_ms(0), bitrate_update_ms(0) {} 144 StatsUpdateTimes() : resolution_update_ms(0), bitrate_update_ms(0) {}
123 int64_t resolution_update_ms; 145 int64_t resolution_update_ms;
124 int64_t bitrate_update_ms; 146 int64_t bitrate_update_ms;
125 }; 147 };
126 void PurgeOldStats() EXCLUSIVE_LOCKS_REQUIRED(crit_); 148 void PurgeOldStats() EXCLUSIVE_LOCKS_REQUIRED(crit_);
127 VideoSendStream::StreamStats* GetStatsEntry(uint32_t ssrc) 149 VideoSendStream::StreamStats* GetStatsEntry(uint32_t ssrc)
128 EXCLUSIVE_LOCKS_REQUIRED(crit_); 150 EXCLUSIVE_LOCKS_REQUIRED(crit_);
151 void RemoveOld(int64_t now, PacketMap* packets)
152 EXCLUSIVE_LOCKS_REQUIRED(crit_);
129 153
130 Clock* const clock_; 154 Clock* const clock_;
131 const VideoSendStream::Config config_; 155 const VideoSendStream::Config config_;
132 mutable rtc::CriticalSection crit_; 156 mutable rtc::CriticalSection crit_;
133 VideoEncoderConfig::ContentType content_type_ GUARDED_BY(crit_); 157 VideoEncoderConfig::ContentType content_type_ GUARDED_BY(crit_);
134 VideoSendStream::Stats stats_ GUARDED_BY(crit_); 158 VideoSendStream::Stats stats_ GUARDED_BY(crit_);
135 uint32_t last_sent_frame_timestamp_ GUARDED_BY(crit_); 159 uint32_t last_sent_frame_timestamp_ GUARDED_BY(crit_);
136 std::map<uint32_t, StatsUpdateTimes> update_times_ GUARDED_BY(crit_); 160 std::map<uint32_t, StatsUpdateTimes> update_times_ GUARDED_BY(crit_);
137 rtc::ExpFilter encode_time_ GUARDED_BY(crit_); 161 rtc::ExpFilter encode_time_ GUARDED_BY(crit_);
162 PacketMap packets_ GUARDED_BY(crit_);
138 163
139 // Contains stats used for UMA histograms. These stats will be reset if 164 // Contains stats used for UMA histograms. These stats will be reset if
140 // content type changes between real-time video and screenshare, since these 165 // content type changes between real-time video and screenshare, since these
141 // will be reported separately. 166 // will be reported separately.
142 struct UmaSamplesContainer { 167 struct UmaSamplesContainer {
143 explicit UmaSamplesContainer(const char* prefix); 168 explicit UmaSamplesContainer(const char* prefix);
144 ~UmaSamplesContainer(); 169 ~UmaSamplesContainer();
145 170
146 void UpdateHistograms(); 171 void UpdateHistograms();
147 172
148 const std::string uma_prefix_; 173 const std::string uma_prefix_;
149 int max_sent_width_per_timestamp_; 174 int max_sent_width_per_timestamp_;
150 int max_sent_height_per_timestamp_; 175 int max_sent_height_per_timestamp_;
151 SampleCounter input_width_counter_; 176 SampleCounter input_width_counter_;
152 SampleCounter input_height_counter_; 177 SampleCounter input_height_counter_;
153 SampleCounter sent_width_counter_; 178 SampleCounter sent_width_counter_;
154 SampleCounter sent_height_counter_; 179 SampleCounter sent_height_counter_;
155 SampleCounter encode_time_counter_; 180 SampleCounter encode_time_counter_;
156 BoolSampleCounter key_frame_counter_; 181 BoolSampleCounter key_frame_counter_;
157 BoolSampleCounter quality_limited_frame_counter_; 182 BoolSampleCounter quality_limited_frame_counter_;
158 SampleCounter quality_downscales_counter_; 183 SampleCounter quality_downscales_counter_;
159 BoolSampleCounter bw_limited_frame_counter_; 184 BoolSampleCounter bw_limited_frame_counter_;
160 SampleCounter bw_resolutions_disabled_counter_; 185 SampleCounter bw_resolutions_disabled_counter_;
161 SampleCounter delay_counter_; 186 SampleCounter delay_counter_;
162 SampleCounter max_delay_counter_; 187 SampleCounter max_delay_counter_;
163 rtc::RateTracker input_frame_rate_tracker_; 188 rtc::RateTracker input_frame_rate_tracker_;
164 rtc::RateTracker sent_frame_rate_tracker_; 189 rtc::RateTracker sent_frame_rate_tracker_;
190 std::map<uint32_t, SampleCounter> send_delay_counters_; // Mapped by SSRC.
165 }; 191 };
166 192
167 rtc::scoped_ptr<UmaSamplesContainer> uma_container_ GUARDED_BY(crit_); 193 rtc::scoped_ptr<UmaSamplesContainer> uma_container_ GUARDED_BY(crit_);
168 }; 194 };
169 195
170 } // namespace webrtc 196 } // namespace webrtc
171 #endif // WEBRTC_VIDEO_SEND_STATISTICS_PROXY_H_ 197 #endif // WEBRTC_VIDEO_SEND_STATISTICS_PROXY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698