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 |
11 #ifndef WEBRTC_VIDEO_OVERUSE_FRAME_DETECTOR_H_ | 11 #ifndef WEBRTC_VIDEO_OVERUSE_FRAME_DETECTOR_H_ |
12 #define WEBRTC_VIDEO_OVERUSE_FRAME_DETECTOR_H_ | 12 #define WEBRTC_VIDEO_OVERUSE_FRAME_DETECTOR_H_ |
13 | 13 |
14 #include <list> | 14 #include <list> |
15 #include <memory> | 15 #include <memory> |
16 | 16 |
17 #include "webrtc/base/constructormagic.h" | 17 #include "webrtc/base/constructormagic.h" |
18 #include "webrtc/base/numerics/exp_filter.h" | 18 #include "webrtc/base/numerics/exp_filter.h" |
19 #include "webrtc/base/optional.h" | 19 #include "webrtc/base/optional.h" |
20 #include "webrtc/base/sequenced_task_checker.h" | 20 #include "webrtc/base/sequenced_task_checker.h" |
21 #include "webrtc/base/task_queue.h" | 21 #include "webrtc/base/task_queue.h" |
22 #include "webrtc/base/thread_annotations.h" | 22 #include "webrtc/base/thread_annotations.h" |
23 #include "webrtc/modules/video_coding/utility/quality_scaler.h" | 23 #include "webrtc/modules/video_coding/utility/quality_scaler.h" |
24 | 24 |
25 namespace webrtc { | 25 namespace webrtc { |
26 | 26 |
27 class Clock; | |
28 class EncodedFrameObserver; | 27 class EncodedFrameObserver; |
29 class VideoFrame; | 28 class VideoFrame; |
30 | 29 |
31 struct CpuOveruseOptions { | 30 struct CpuOveruseOptions { |
32 CpuOveruseOptions(); | 31 CpuOveruseOptions(); |
33 | 32 |
34 int low_encode_usage_threshold_percent; // Threshold for triggering underuse. | 33 int low_encode_usage_threshold_percent; // Threshold for triggering underuse. |
35 int high_encode_usage_threshold_percent; // Threshold for triggering overuse. | 34 int high_encode_usage_threshold_percent; // Threshold for triggering overuse. |
36 // General settings. | 35 // General settings. |
37 int frame_timeout_interval_ms; // The maximum allowed interval between two | 36 int frame_timeout_interval_ms; // The maximum allowed interval between two |
(...skipping 20 matching lines...) Expand all Loading... |
58 const CpuOveruseMetrics& metrics) = 0; | 57 const CpuOveruseMetrics& metrics) = 0; |
59 }; | 58 }; |
60 | 59 |
61 // Use to detect system overuse based on the send-side processing time of | 60 // Use to detect system overuse based on the send-side processing time of |
62 // incoming frames. All methods must be called on a single task queue but it can | 61 // incoming frames. All methods must be called on a single task queue but it can |
63 // be created and destroyed on an arbitrary thread. | 62 // be created and destroyed on an arbitrary thread. |
64 // OveruseFrameDetector::StartCheckForOveruse must be called to periodically | 63 // OveruseFrameDetector::StartCheckForOveruse must be called to periodically |
65 // check for overuse. | 64 // check for overuse. |
66 class OveruseFrameDetector { | 65 class OveruseFrameDetector { |
67 public: | 66 public: |
68 OveruseFrameDetector(Clock* clock, | 67 OveruseFrameDetector(const CpuOveruseOptions& options, |
69 const CpuOveruseOptions& options, | |
70 ScalingObserverInterface* overuse_observer, | 68 ScalingObserverInterface* overuse_observer, |
71 EncodedFrameObserver* encoder_timing_, | 69 EncodedFrameObserver* encoder_timing_, |
72 CpuOveruseMetricsObserver* metrics_observer); | 70 CpuOveruseMetricsObserver* metrics_observer); |
73 ~OveruseFrameDetector(); | 71 ~OveruseFrameDetector(); |
74 | 72 |
75 // Start to periodically check for overuse. | 73 // Start to periodically check for overuse. |
76 void StartCheckForOveruse(); | 74 void StartCheckForOveruse(); |
77 | 75 |
78 // StopCheckForOveruse must be called before destruction if | 76 // StopCheckForOveruse must be called before destruction if |
79 // StartCheckForOveruse has been called. | 77 // StartCheckForOveruse has been called. |
80 void StopCheckForOveruse(); | 78 void StopCheckForOveruse(); |
81 | 79 |
82 // Called for each captured frame. | 80 // Called for each captured frame. |
83 void FrameCaptured(const VideoFrame& frame, int64_t time_when_first_seen_ms); | 81 void FrameCaptured(const VideoFrame& frame, int64_t time_when_first_seen_us); |
84 | 82 |
85 // Called for each sent frame. | 83 // Called for each sent frame. |
86 void FrameSent(uint32_t timestamp, int64_t time_sent_in_ms); | 84 void FrameSent(uint32_t timestamp, int64_t time_sent_in_us); |
87 | 85 |
88 protected: | 86 protected: |
89 void CheckForOveruse(); // Protected for test purposes. | 87 void CheckForOveruse(); // Protected for test purposes. |
90 | 88 |
91 private: | 89 private: |
92 class SendProcessingUsage; | 90 class SendProcessingUsage; |
93 class CheckOveruseTask; | 91 class CheckOveruseTask; |
94 struct FrameTiming { | 92 struct FrameTiming { |
95 FrameTiming(int64_t capture_ntp_ms, uint32_t timestamp, int64_t now) | 93 FrameTiming(int64_t capture_time_us, uint32_t timestamp, int64_t now) |
96 : capture_ntp_ms(capture_ntp_ms), | 94 : capture_time_us(capture_time_us), |
97 timestamp(timestamp), | 95 timestamp(timestamp), |
98 capture_ms(now), | 96 capture_us(now), |
99 last_send_ms(-1) {} | 97 last_send_us(-1) {} |
100 int64_t capture_ntp_ms; | 98 int64_t capture_time_us; |
101 uint32_t timestamp; | 99 uint32_t timestamp; |
102 int64_t capture_ms; | 100 int64_t capture_us; |
103 int64_t last_send_ms; | 101 int64_t last_send_us; |
104 }; | 102 }; |
105 | 103 |
106 void EncodedFrameTimeMeasured(int encode_duration_ms); | 104 void EncodedFrameTimeMeasured(int encode_duration_ms); |
107 bool IsOverusing(const CpuOveruseMetrics& metrics); | 105 bool IsOverusing(const CpuOveruseMetrics& metrics); |
108 bool IsUnderusing(const CpuOveruseMetrics& metrics, int64_t time_now); | 106 bool IsUnderusing(const CpuOveruseMetrics& metrics, int64_t time_now); |
109 | 107 |
110 bool FrameTimeoutDetected(int64_t now) const; | 108 bool FrameTimeoutDetected(int64_t now) const; |
111 bool FrameSizeChanged(int num_pixels) const; | 109 bool FrameSizeChanged(int num_pixels) const; |
112 | 110 |
113 void ResetAll(int num_pixels); | 111 void ResetAll(int num_pixels); |
114 | 112 |
115 rtc::SequencedTaskChecker task_checker_; | 113 rtc::SequencedTaskChecker task_checker_; |
116 // Owned by the task queue from where StartCheckForOveruse is called. | 114 // Owned by the task queue from where StartCheckForOveruse is called. |
117 CheckOveruseTask* check_overuse_task_; | 115 CheckOveruseTask* check_overuse_task_; |
118 | 116 |
119 const CpuOveruseOptions options_; | 117 const CpuOveruseOptions options_; |
120 | 118 |
121 // Observer getting overuse reports. | 119 // Observer getting overuse reports. |
122 ScalingObserverInterface* const observer_; | 120 ScalingObserverInterface* const observer_; |
123 EncodedFrameObserver* const encoder_timing_; | 121 EncodedFrameObserver* const encoder_timing_; |
124 | 122 |
125 // Stats metrics. | 123 // Stats metrics. |
126 CpuOveruseMetricsObserver* const metrics_observer_; | 124 CpuOveruseMetricsObserver* const metrics_observer_; |
127 rtc::Optional<CpuOveruseMetrics> metrics_ GUARDED_BY(task_checker_); | 125 rtc::Optional<CpuOveruseMetrics> metrics_ GUARDED_BY(task_checker_); |
128 Clock* const clock_; | |
129 | 126 |
130 int64_t num_process_times_ GUARDED_BY(task_checker_); | 127 int64_t num_process_times_ GUARDED_BY(task_checker_); |
131 | 128 |
132 int64_t last_capture_time_ms_ GUARDED_BY(task_checker_); | 129 int64_t last_capture_time_us_ GUARDED_BY(task_checker_); |
133 int64_t last_processed_capture_time_ms_ GUARDED_BY(task_checker_); | 130 int64_t last_processed_capture_time_us_ GUARDED_BY(task_checker_); |
134 | 131 |
135 // Number of pixels of last captured frame. | 132 // Number of pixels of last captured frame. |
136 int num_pixels_ GUARDED_BY(task_checker_); | 133 int num_pixels_ GUARDED_BY(task_checker_); |
137 int64_t last_overuse_time_ms_ GUARDED_BY(task_checker_); | 134 int64_t last_overuse_time_ms_ GUARDED_BY(task_checker_); |
138 int checks_above_threshold_ GUARDED_BY(task_checker_); | 135 int checks_above_threshold_ GUARDED_BY(task_checker_); |
139 int num_overuse_detections_ GUARDED_BY(task_checker_); | 136 int num_overuse_detections_ GUARDED_BY(task_checker_); |
140 int64_t last_rampup_time_ms_ GUARDED_BY(task_checker_); | 137 int64_t last_rampup_time_ms_ GUARDED_BY(task_checker_); |
141 bool in_quick_rampup_ GUARDED_BY(task_checker_); | 138 bool in_quick_rampup_ GUARDED_BY(task_checker_); |
142 int current_rampup_delay_ms_ GUARDED_BY(task_checker_); | 139 int current_rampup_delay_ms_ GUARDED_BY(task_checker_); |
143 | 140 |
144 // TODO(asapersson): Can these be regular members (avoid separate heap | 141 // TODO(asapersson): Can these be regular members (avoid separate heap |
145 // allocs)? | 142 // allocs)? |
146 const std::unique_ptr<SendProcessingUsage> usage_ GUARDED_BY(task_checker_); | 143 const std::unique_ptr<SendProcessingUsage> usage_ GUARDED_BY(task_checker_); |
147 std::list<FrameTiming> frame_timing_ GUARDED_BY(task_checker_); | 144 std::list<FrameTiming> frame_timing_ GUARDED_BY(task_checker_); |
148 | 145 |
149 RTC_DISALLOW_COPY_AND_ASSIGN(OveruseFrameDetector); | 146 RTC_DISALLOW_COPY_AND_ASSIGN(OveruseFrameDetector); |
150 }; | 147 }; |
151 | 148 |
152 } // namespace webrtc | 149 } // namespace webrtc |
153 | 150 |
154 #endif // WEBRTC_VIDEO_OVERUSE_FRAME_DETECTOR_H_ | 151 #endif // WEBRTC_VIDEO_OVERUSE_FRAME_DETECTOR_H_ |
OLD | NEW |