OLD | NEW |
---|---|
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 Loading... | |
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 public: | |
113 Packet(uint32_t ssrc, int64_t capture_time_ms, int64_t send_time_ms) | |
114 : ssrc_(ssrc), | |
115 capture_time_ms_(capture_time_ms), | |
116 send_time_ms_(send_time_ms) {} | |
117 uint32_t ssrc_; | |
118 int64_t capture_time_ms_; | |
119 int64_t send_time_ms_; | |
stefan-webrtc
2016/01/18 19:48:26
I prefer to remove the trailing _ since this is a
åsapersson
2016/04/06 14:52:37
Done.
| |
120 }; | |
121 typedef std::map<uint16_t, Packet, PacketIdLessThan> PacketMap; | |
122 | |
97 class SampleCounter { | 123 class SampleCounter { |
98 public: | 124 public: |
99 SampleCounter() : sum(0), num_samples(0) {} | 125 SampleCounter() : sum(0), num_samples(0) {} |
100 ~SampleCounter() {} | 126 ~SampleCounter() {} |
101 void Add(int sample); | 127 void Add(int sample); |
102 int Avg(int min_required_samples) const; | 128 int Avg(int min_required_samples) const; |
103 | 129 |
104 private: | 130 private: |
105 int sum; | 131 int sum; |
106 int num_samples; | 132 int num_samples; |
(...skipping 12 matching lines...) Expand all Loading... | |
119 int num_samples; | 145 int num_samples; |
120 }; | 146 }; |
121 struct StatsUpdateTimes { | 147 struct StatsUpdateTimes { |
122 StatsUpdateTimes() : resolution_update_ms(0), bitrate_update_ms(0) {} | 148 StatsUpdateTimes() : resolution_update_ms(0), bitrate_update_ms(0) {} |
123 int64_t resolution_update_ms; | 149 int64_t resolution_update_ms; |
124 int64_t bitrate_update_ms; | 150 int64_t bitrate_update_ms; |
125 }; | 151 }; |
126 void PurgeOldStats() EXCLUSIVE_LOCKS_REQUIRED(crit_); | 152 void PurgeOldStats() EXCLUSIVE_LOCKS_REQUIRED(crit_); |
127 VideoSendStream::StreamStats* GetStatsEntry(uint32_t ssrc) | 153 VideoSendStream::StreamStats* GetStatsEntry(uint32_t ssrc) |
128 EXCLUSIVE_LOCKS_REQUIRED(crit_); | 154 EXCLUSIVE_LOCKS_REQUIRED(crit_); |
155 void RemoveOld(int64_t now, PacketMap* packets) | |
156 EXCLUSIVE_LOCKS_REQUIRED(crit_); | |
129 | 157 |
130 Clock* const clock_; | 158 Clock* const clock_; |
131 const VideoSendStream::Config config_; | 159 const VideoSendStream::Config config_; |
132 mutable rtc::CriticalSection crit_; | 160 mutable rtc::CriticalSection crit_; |
133 VideoEncoderConfig::ContentType content_type_ GUARDED_BY(crit_); | 161 VideoEncoderConfig::ContentType content_type_ GUARDED_BY(crit_); |
134 VideoSendStream::Stats stats_ GUARDED_BY(crit_); | 162 VideoSendStream::Stats stats_ GUARDED_BY(crit_); |
135 uint32_t last_sent_frame_timestamp_ GUARDED_BY(crit_); | 163 uint32_t last_sent_frame_timestamp_ GUARDED_BY(crit_); |
136 std::map<uint32_t, StatsUpdateTimes> update_times_ GUARDED_BY(crit_); | 164 std::map<uint32_t, StatsUpdateTimes> update_times_ GUARDED_BY(crit_); |
137 rtc::ExpFilter encode_time_ GUARDED_BY(crit_); | 165 rtc::ExpFilter encode_time_ GUARDED_BY(crit_); |
166 PacketMap packets_ GUARDED_BY(crit_); | |
138 | 167 |
139 // Contains stats used for UMA histograms. These stats will be reset if | 168 // Contains stats used for UMA histograms. These stats will be reset if |
140 // content type changes between real-time video and screenshare, since these | 169 // content type changes between real-time video and screenshare, since these |
141 // will be reported separately. | 170 // will be reported separately. |
142 struct UmaSamplesContainer { | 171 struct UmaSamplesContainer { |
143 explicit UmaSamplesContainer(const char* prefix); | 172 explicit UmaSamplesContainer(const char* prefix); |
144 ~UmaSamplesContainer(); | 173 ~UmaSamplesContainer(); |
145 | 174 |
146 void UpdateHistograms(); | 175 void UpdateHistograms(); |
147 | 176 |
148 const std::string uma_prefix_; | 177 const std::string uma_prefix_; |
149 int max_sent_width_per_timestamp_; | 178 int max_sent_width_per_timestamp_; |
150 int max_sent_height_per_timestamp_; | 179 int max_sent_height_per_timestamp_; |
151 SampleCounter input_width_counter_; | 180 SampleCounter input_width_counter_; |
152 SampleCounter input_height_counter_; | 181 SampleCounter input_height_counter_; |
153 SampleCounter sent_width_counter_; | 182 SampleCounter sent_width_counter_; |
154 SampleCounter sent_height_counter_; | 183 SampleCounter sent_height_counter_; |
155 SampleCounter encode_time_counter_; | 184 SampleCounter encode_time_counter_; |
156 BoolSampleCounter key_frame_counter_; | 185 BoolSampleCounter key_frame_counter_; |
157 BoolSampleCounter quality_limited_frame_counter_; | 186 BoolSampleCounter quality_limited_frame_counter_; |
158 SampleCounter quality_downscales_counter_; | 187 SampleCounter quality_downscales_counter_; |
159 BoolSampleCounter bw_limited_frame_counter_; | 188 BoolSampleCounter bw_limited_frame_counter_; |
160 SampleCounter bw_resolutions_disabled_counter_; | 189 SampleCounter bw_resolutions_disabled_counter_; |
161 SampleCounter delay_counter_; | 190 SampleCounter delay_counter_; |
162 SampleCounter max_delay_counter_; | 191 SampleCounter max_delay_counter_; |
163 rtc::RateTracker input_frame_rate_tracker_; | 192 rtc::RateTracker input_frame_rate_tracker_; |
164 rtc::RateTracker sent_frame_rate_tracker_; | 193 rtc::RateTracker sent_frame_rate_tracker_; |
194 std::map<uint32_t, SampleCounter> send_delay_counters_; // Mapped by SSRC. | |
165 }; | 195 }; |
166 | 196 |
167 rtc::scoped_ptr<UmaSamplesContainer> uma_container_ GUARDED_BY(crit_); | 197 rtc::scoped_ptr<UmaSamplesContainer> uma_container_ GUARDED_BY(crit_); |
168 }; | 198 }; |
169 | 199 |
170 } // namespace webrtc | 200 } // namespace webrtc |
171 #endif // WEBRTC_VIDEO_SEND_STATISTICS_PROXY_H_ | 201 #endif // WEBRTC_VIDEO_SEND_STATISTICS_PROXY_H_ |
OLD | NEW |