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 16 matching lines...) Expand all Loading... |
27 | 27 |
28 namespace webrtc { | 28 namespace webrtc { |
29 | 29 |
30 class SendStatisticsProxy : public CpuOveruseMetricsObserver, | 30 class SendStatisticsProxy : public CpuOveruseMetricsObserver, |
31 public RtcpStatisticsCallback, | 31 public RtcpStatisticsCallback, |
32 public RtcpPacketTypeCounterObserver, | 32 public RtcpPacketTypeCounterObserver, |
33 public StreamDataCountersCallback, | 33 public StreamDataCountersCallback, |
34 public BitrateStatisticsObserver, | 34 public BitrateStatisticsObserver, |
35 public FrameCountObserver, | 35 public FrameCountObserver, |
36 public VideoEncoderRateObserver, | 36 public VideoEncoderRateObserver, |
37 public SendSideDelayObserver { | 37 public SendSideDelayObserver, |
| 38 public SendPacketObserver { |
38 public: | 39 public: |
39 static const int kStatsTimeoutMs; | 40 static const int kStatsTimeoutMs; |
40 | 41 |
41 SendStatisticsProxy(Clock* clock, const VideoSendStream::Config& config); | 42 SendStatisticsProxy(Clock* clock, const VideoSendStream::Config& config); |
42 virtual ~SendStatisticsProxy(); | 43 virtual ~SendStatisticsProxy(); |
43 | 44 |
44 VideoSendStream::Stats GetStats(); | 45 VideoSendStream::Stats GetStats(); |
45 | 46 |
46 virtual void OnSendEncodedImage(const EncodedImage& encoded_image, | 47 virtual void OnSendEncodedImage(const EncodedImage& encoded_image, |
47 const RTPVideoHeader* rtp_video_header); | 48 const RTPVideoHeader* rtp_video_header); |
48 // Used to update incoming frame rate. | 49 // Used to update incoming frame rate. |
49 void OnIncomingFrame(int width, int height); | 50 void OnIncomingFrame(int width, int height); |
50 | 51 |
51 // Used to update encode time of frames. | 52 // Used to update encode time of frames. |
52 void OnEncodedFrame(int encode_time_ms); | 53 void OnEncodedFrame(int encode_time_ms); |
53 | 54 |
54 // From VideoEncoderRateObserver. | 55 // From VideoEncoderRateObserver. |
55 void OnSetRates(uint32_t bitrate_bps, int framerate) override; | 56 void OnSetRates(uint32_t bitrate_bps, int framerate) override; |
56 | 57 |
57 void OnOutgoingRate(uint32_t framerate, uint32_t bitrate); | 58 void OnOutgoingRate(uint32_t framerate, uint32_t bitrate); |
58 void OnSuspendChange(bool is_suspended); | 59 void OnSuspendChange(bool is_suspended); |
59 void OnInactiveSsrc(uint32_t ssrc); | 60 void OnInactiveSsrc(uint32_t ssrc); |
60 | 61 |
| 62 bool OnSentPacket(int packet_id); |
| 63 |
61 protected: | 64 protected: |
62 // From CpuOveruseMetricsObserver. | 65 // From CpuOveruseMetricsObserver. |
63 void CpuOveruseMetricsUpdated(const CpuOveruseMetrics& metrics) override; | 66 void CpuOveruseMetricsUpdated(const CpuOveruseMetrics& metrics) override; |
64 // From RtcpStatisticsCallback. | 67 // From RtcpStatisticsCallback. |
65 void StatisticsUpdated(const RtcpStatistics& statistics, | 68 void StatisticsUpdated(const RtcpStatistics& statistics, |
66 uint32_t ssrc) override; | 69 uint32_t ssrc) override; |
67 void CNameChanged(const char* cname, uint32_t ssrc) override; | 70 void CNameChanged(const char* cname, uint32_t ssrc) override; |
68 // From RtcpPacketTypeCounterObserver. | 71 // From RtcpPacketTypeCounterObserver. |
69 void RtcpPacketTypesCounterUpdated( | 72 void RtcpPacketTypesCounterUpdated( |
70 uint32_t ssrc, | 73 uint32_t ssrc, |
71 const RtcpPacketTypeCounter& packet_counter) override; | 74 const RtcpPacketTypeCounter& packet_counter) override; |
72 // From StreamDataCountersCallback. | 75 // From StreamDataCountersCallback. |
73 void DataCountersUpdated(const StreamDataCounters& counters, | 76 void DataCountersUpdated(const StreamDataCounters& counters, |
74 uint32_t ssrc) override; | 77 uint32_t ssrc) override; |
75 | 78 |
76 // From BitrateStatisticsObserver. | 79 // From BitrateStatisticsObserver. |
77 void Notify(const BitrateStatistics& total_stats, | 80 void Notify(const BitrateStatistics& total_stats, |
78 const BitrateStatistics& retransmit_stats, | 81 const BitrateStatistics& retransmit_stats, |
79 uint32_t ssrc) override; | 82 uint32_t ssrc) override; |
80 | 83 |
81 // From FrameCountObserver. | 84 // From FrameCountObserver. |
82 void FrameCountUpdated(const FrameCounts& frame_counts, | 85 void FrameCountUpdated(const FrameCounts& frame_counts, |
83 uint32_t ssrc) override; | 86 uint32_t ssrc) override; |
84 | 87 |
85 void SendSideDelayUpdated(int avg_delay_ms, | 88 void SendSideDelayUpdated(int avg_delay_ms, |
86 int max_delay_ms, | 89 int max_delay_ms, |
87 uint32_t ssrc) override; | 90 uint32_t ssrc) override; |
88 | 91 |
| 92 void OnSendPacket(uint16_t packet_id, |
| 93 int64_t capture_time_ms, |
| 94 uint32_t ssrc) override; |
| 95 |
89 private: | 96 private: |
| 97 // Map holding sent packets (mapped by packet id). |
| 98 class PacketIdLessThan { |
| 99 public: |
| 100 bool operator()(uint16_t seq1, uint16_t seq2) const { |
| 101 return IsNewerSequenceNumber(seq2, seq1); |
| 102 } |
| 103 }; |
| 104 struct Packet { |
| 105 Packet() : cap_time_ms(-1), send_time_ms(-1) {} |
| 106 int64_t cap_time_ms; |
| 107 int64_t send_time_ms; |
| 108 }; |
| 109 typedef std::map<uint16_t, Packet, PacketIdLessThan> PacketMap; |
| 110 |
90 class SampleCounter { | 111 class SampleCounter { |
91 public: | 112 public: |
92 SampleCounter() : sum(0), num_samples(0) {} | 113 SampleCounter() : sum(0), num_samples(0) {} |
93 ~SampleCounter() {} | 114 ~SampleCounter() {} |
94 void Add(int sample); | 115 void Add(int sample); |
95 int Avg(int min_required_samples) const; | 116 int Avg(int min_required_samples) const; |
96 | 117 |
97 private: | 118 private: |
98 int sum; | 119 int sum; |
99 int num_samples; | 120 int num_samples; |
(...skipping 13 matching lines...) Expand all Loading... |
113 }; | 134 }; |
114 struct StatsUpdateTimes { | 135 struct StatsUpdateTimes { |
115 StatsUpdateTimes() : resolution_update_ms(0) {} | 136 StatsUpdateTimes() : resolution_update_ms(0) {} |
116 int64_t resolution_update_ms; | 137 int64_t resolution_update_ms; |
117 int64_t bitrate_update_ms; | 138 int64_t bitrate_update_ms; |
118 }; | 139 }; |
119 void PurgeOldStats() EXCLUSIVE_LOCKS_REQUIRED(crit_); | 140 void PurgeOldStats() EXCLUSIVE_LOCKS_REQUIRED(crit_); |
120 VideoSendStream::StreamStats* GetStatsEntry(uint32_t ssrc) | 141 VideoSendStream::StreamStats* GetStatsEntry(uint32_t ssrc) |
121 EXCLUSIVE_LOCKS_REQUIRED(crit_); | 142 EXCLUSIVE_LOCKS_REQUIRED(crit_); |
122 void UpdateHistograms() EXCLUSIVE_LOCKS_REQUIRED(crit_); | 143 void UpdateHistograms() EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| 144 void RemoveOld(int64_t now, PacketMap* packets) |
| 145 EXCLUSIVE_LOCKS_REQUIRED(crit_); |
123 | 146 |
124 Clock* const clock_; | 147 Clock* const clock_; |
125 const VideoSendStream::Config config_; | 148 const VideoSendStream::Config config_; |
126 mutable rtc::CriticalSection crit_; | 149 mutable rtc::CriticalSection crit_; |
127 VideoSendStream::Stats stats_ GUARDED_BY(crit_); | 150 VideoSendStream::Stats stats_ GUARDED_BY(crit_); |
128 rtc::RateTracker input_frame_rate_tracker_ GUARDED_BY(crit_); | 151 rtc::RateTracker input_frame_rate_tracker_ GUARDED_BY(crit_); |
129 rtc::RateTracker sent_frame_rate_tracker_ GUARDED_BY(crit_); | 152 rtc::RateTracker sent_frame_rate_tracker_ GUARDED_BY(crit_); |
130 uint32_t last_sent_frame_timestamp_ GUARDED_BY(crit_); | 153 uint32_t last_sent_frame_timestamp_ GUARDED_BY(crit_); |
131 std::map<uint32_t, StatsUpdateTimes> update_times_ GUARDED_BY(crit_); | 154 std::map<uint32_t, StatsUpdateTimes> update_times_ GUARDED_BY(crit_); |
132 | 155 |
133 int max_sent_width_per_timestamp_ GUARDED_BY(crit_); | 156 int max_sent_width_per_timestamp_ GUARDED_BY(crit_); |
134 int max_sent_height_per_timestamp_ GUARDED_BY(crit_); | 157 int max_sent_height_per_timestamp_ GUARDED_BY(crit_); |
135 SampleCounter input_width_counter_ GUARDED_BY(crit_); | 158 SampleCounter input_width_counter_ GUARDED_BY(crit_); |
136 SampleCounter input_height_counter_ GUARDED_BY(crit_); | 159 SampleCounter input_height_counter_ GUARDED_BY(crit_); |
137 SampleCounter sent_width_counter_ GUARDED_BY(crit_); | 160 SampleCounter sent_width_counter_ GUARDED_BY(crit_); |
138 SampleCounter sent_height_counter_ GUARDED_BY(crit_); | 161 SampleCounter sent_height_counter_ GUARDED_BY(crit_); |
139 SampleCounter encode_time_counter_ GUARDED_BY(crit_); | 162 SampleCounter encode_time_counter_ GUARDED_BY(crit_); |
140 BoolSampleCounter key_frame_counter_ GUARDED_BY(crit_); | 163 BoolSampleCounter key_frame_counter_ GUARDED_BY(crit_); |
141 BoolSampleCounter quality_limited_frame_counter_ GUARDED_BY(crit_); | 164 BoolSampleCounter quality_limited_frame_counter_ GUARDED_BY(crit_); |
142 SampleCounter quality_downscales_counter_ GUARDED_BY(crit_); | 165 SampleCounter quality_downscales_counter_ GUARDED_BY(crit_); |
143 BoolSampleCounter bw_limited_frame_counter_ GUARDED_BY(crit_); | 166 BoolSampleCounter bw_limited_frame_counter_ GUARDED_BY(crit_); |
144 SampleCounter bw_resolutions_disabled_counter_ GUARDED_BY(crit_); | 167 SampleCounter bw_resolutions_disabled_counter_ GUARDED_BY(crit_); |
145 SampleCounter delay_counter_ GUARDED_BY(crit_); | 168 SampleCounter delay_counter_ GUARDED_BY(crit_); |
146 SampleCounter max_delay_counter_ GUARDED_BY(crit_); | 169 SampleCounter max_delay_counter_ GUARDED_BY(crit_); |
| 170 |
| 171 SampleCounter send_delay_counter_ GUARDED_BY(crit_); |
| 172 PacketMap packets_ GUARDED_BY(crit_); |
147 }; | 173 }; |
148 | 174 |
149 } // namespace webrtc | 175 } // namespace webrtc |
150 #endif // WEBRTC_VIDEO_SEND_STATISTICS_PROXY_H_ | 176 #endif // WEBRTC_VIDEO_SEND_STATISTICS_PROXY_H_ |
OLD | NEW |