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 29 matching lines...) Expand all Loading... |
40 static const int kStatsTimeoutMs; | 40 static const int kStatsTimeoutMs; |
41 | 41 |
42 SendStatisticsProxy(Clock* clock, const VideoSendStream::Config& config); | 42 SendStatisticsProxy(Clock* clock, const VideoSendStream::Config& config); |
43 virtual ~SendStatisticsProxy(); | 43 virtual ~SendStatisticsProxy(); |
44 | 44 |
45 VideoSendStream::Stats GetStats(); | 45 VideoSendStream::Stats GetStats(); |
46 | 46 |
47 virtual void OnSendEncodedImage(const EncodedImage& encoded_image, | 47 virtual void OnSendEncodedImage(const EncodedImage& encoded_image, |
48 const RTPVideoHeader* rtp_video_header); | 48 const RTPVideoHeader* rtp_video_header); |
49 // Used to update incoming frame rate. | 49 // Used to update incoming frame rate. |
50 void OnIncomingFrame(); | 50 void OnIncomingFrame(int width, int height); |
51 | 51 |
52 // From VideoEncoderRateObserver. | 52 // From VideoEncoderRateObserver. |
53 void OnSetRates(uint32_t bitrate_bps, int framerate) override; | 53 void OnSetRates(uint32_t bitrate_bps, int framerate) override; |
54 | 54 |
55 void OnInactiveSsrc(uint32_t ssrc); | 55 void OnInactiveSsrc(uint32_t ssrc); |
56 | 56 |
57 protected: | 57 protected: |
58 // From CpuOveruseMetricsObserver. | 58 // From CpuOveruseMetricsObserver. |
59 void CpuOveruseMetricsUpdated(const CpuOveruseMetrics& metrics) override; | 59 void CpuOveruseMetricsUpdated(const CpuOveruseMetrics& metrics) override; |
60 // From RtcpStatisticsCallback. | 60 // From RtcpStatisticsCallback. |
61 void StatisticsUpdated(const RtcpStatistics& statistics, | 61 void StatisticsUpdated(const RtcpStatistics& statistics, |
62 uint32_t ssrc) override; | 62 uint32_t ssrc) override; |
63 void CNameChanged(const char* cname, uint32_t ssrc) override; | 63 void CNameChanged(const char* cname, uint32_t ssrc) override; |
64 // From RtcpPacketTypeCounterObserver | 64 // From RtcpPacketTypeCounterObserver. |
65 void RtcpPacketTypesCounterUpdated( | 65 void RtcpPacketTypesCounterUpdated( |
66 uint32_t ssrc, | 66 uint32_t ssrc, |
67 const RtcpPacketTypeCounter& packet_counter) override; | 67 const RtcpPacketTypeCounter& packet_counter) override; |
68 // From StreamDataCountersCallback. | 68 // From StreamDataCountersCallback. |
69 void DataCountersUpdated(const StreamDataCounters& counters, | 69 void DataCountersUpdated(const StreamDataCounters& counters, |
70 uint32_t ssrc) override; | 70 uint32_t ssrc) override; |
71 | 71 |
72 // From BitrateStatisticsObserver. | 72 // From BitrateStatisticsObserver. |
73 void Notify(const BitrateStatistics& total_stats, | 73 void Notify(const BitrateStatistics& total_stats, |
74 const BitrateStatistics& retransmit_stats, | 74 const BitrateStatistics& retransmit_stats, |
75 uint32_t ssrc) override; | 75 uint32_t ssrc) override; |
76 | 76 |
77 // From FrameCountObserver. | 77 // From FrameCountObserver. |
78 void FrameCountUpdated(const FrameCounts& frame_counts, | 78 void FrameCountUpdated(const FrameCounts& frame_counts, |
79 uint32_t ssrc) override; | 79 uint32_t ssrc) override; |
80 | 80 |
81 // From ViEEncoderObserver. | 81 // From ViEEncoderObserver. |
82 void OutgoingRate(const int video_channel, | 82 void OutgoingRate(const int video_channel, |
83 const unsigned int framerate, | 83 const unsigned int framerate, |
84 const unsigned int bitrate) override; | 84 const unsigned int bitrate) override; |
85 | 85 |
86 void SuspendChange(int video_channel, bool is_suspended) override; | 86 void SuspendChange(int video_channel, bool is_suspended) override; |
87 | 87 |
88 void SendSideDelayUpdated(int avg_delay_ms, | 88 void SendSideDelayUpdated(int avg_delay_ms, |
89 int max_delay_ms, | 89 int max_delay_ms, |
90 uint32_t ssrc) override; | 90 uint32_t ssrc) override; |
91 | 91 |
92 private: | 92 private: |
| 93 struct SampleCounter { |
| 94 SampleCounter() : sum(0), num(0) {} |
| 95 void Add(int sample) { |
| 96 sum += sample; |
| 97 ++num; |
| 98 } |
| 99 int Avg(int min_required_samples) const { |
| 100 if (num < min_required_samples || num == 0) return -1; |
| 101 return sum / num; |
| 102 } |
| 103 private: |
| 104 int sum; |
| 105 int num; |
| 106 }; |
93 struct StatsUpdateTimes { | 107 struct StatsUpdateTimes { |
94 StatsUpdateTimes() : resolution_update_ms(0) {} | 108 StatsUpdateTimes() : resolution_update_ms(0) {} |
95 int64_t resolution_update_ms; | 109 int64_t resolution_update_ms; |
96 int64_t bitrate_update_ms; | 110 int64_t bitrate_update_ms; |
97 }; | 111 }; |
98 void PurgeOldStats() EXCLUSIVE_LOCKS_REQUIRED(crit_); | 112 void PurgeOldStats() EXCLUSIVE_LOCKS_REQUIRED(crit_); |
99 VideoSendStream::StreamStats* GetStatsEntry(uint32_t ssrc) | 113 VideoSendStream::StreamStats* GetStatsEntry(uint32_t ssrc) |
100 EXCLUSIVE_LOCKS_REQUIRED(crit_); | 114 EXCLUSIVE_LOCKS_REQUIRED(crit_); |
101 void UpdateHistograms() EXCLUSIVE_LOCKS_REQUIRED(crit_); | 115 void UpdateHistograms() EXCLUSIVE_LOCKS_REQUIRED(crit_); |
102 | 116 |
103 Clock* const clock_; | 117 Clock* const clock_; |
104 const VideoSendStream::Config config_; | 118 const VideoSendStream::Config config_; |
105 mutable rtc::CriticalSection crit_; | 119 mutable rtc::CriticalSection crit_; |
106 VideoSendStream::Stats stats_ GUARDED_BY(crit_); | 120 VideoSendStream::Stats stats_ GUARDED_BY(crit_); |
107 rtc::RateTracker input_frame_rate_tracker_ GUARDED_BY(crit_); | 121 rtc::RateTracker input_frame_rate_tracker_ GUARDED_BY(crit_); |
108 rtc::RateTracker input_frame_rate_tracker_total_ GUARDED_BY(crit_); | 122 rtc::RateTracker input_frame_rate_tracker_total_ GUARDED_BY(crit_); |
109 rtc::RateTracker sent_frame_rate_tracker_total_ GUARDED_BY(crit_); | 123 rtc::RateTracker sent_frame_rate_tracker_total_ GUARDED_BY(crit_); |
110 uint32_t last_sent_frame_timestamp_ GUARDED_BY(crit_); | 124 uint32_t last_sent_frame_timestamp_ GUARDED_BY(crit_); |
111 std::map<uint32_t, StatsUpdateTimes> update_times_ GUARDED_BY(crit_); | 125 std::map<uint32_t, StatsUpdateTimes> update_times_ GUARDED_BY(crit_); |
| 126 |
| 127 int max_sent_width_per_timestamp_ GUARDED_BY(crit_); |
| 128 int max_sent_height_per_timestamp_ GUARDED_BY(crit_); |
| 129 SampleCounter input_width_counter_ GUARDED_BY(crit_); |
| 130 SampleCounter input_height_counter_ GUARDED_BY(crit_); |
| 131 SampleCounter sent_width_counter_ GUARDED_BY(crit_); |
| 132 SampleCounter sent_height_counter_ GUARDED_BY(crit_); |
112 }; | 133 }; |
113 | 134 |
114 } // namespace webrtc | 135 } // namespace webrtc |
115 #endif // WEBRTC_VIDEO_SEND_STATISTICS_PROXY_H_ | 136 #endif // WEBRTC_VIDEO_SEND_STATISTICS_PROXY_H_ |
OLD | NEW |