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

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

Issue 1569853002: Measure encoding time on encode callbacks. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: remove unused variable Created 4 years, 11 months 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
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>
15
14 #include "webrtc/base/constructormagic.h" 16 #include "webrtc/base/constructormagic.h"
15 #include "webrtc/base/criticalsection.h" 17 #include "webrtc/base/criticalsection.h"
16 #include "webrtc/base/scoped_ptr.h" 18 #include "webrtc/base/scoped_ptr.h"
17 #include "webrtc/base/exp_filter.h" 19 #include "webrtc/base/exp_filter.h"
18 #include "webrtc/base/thread_annotations.h" 20 #include "webrtc/base/thread_annotations.h"
19 #include "webrtc/base/thread_checker.h" 21 #include "webrtc/base/thread_checker.h"
20 #include "webrtc/modules/include/module.h" 22 #include "webrtc/modules/include/module.h"
21 23
22 namespace webrtc { 24 namespace webrtc {
23 25
24 class Clock; 26 class Clock;
27 class EncodedFrameObserver;
28 class VideoFrame;
25 29
26 // CpuOveruseObserver is called when a system overuse is detected and 30 // CpuOveruseObserver is called when a system overuse is detected and
27 // VideoEngine cannot keep up the encoding frequency. 31 // VideoEngine cannot keep up the encoding frequency.
28 class CpuOveruseObserver { 32 class CpuOveruseObserver {
29 public: 33 public:
30 // Called as soon as an overuse is detected. 34 // Called as soon as an overuse is detected.
31 virtual void OveruseDetected() = 0; 35 virtual void OveruseDetected() = 0;
32 // Called periodically when the system is not overused any longer. 36 // Called periodically when the system is not overused any longer.
33 virtual void NormalUsage() = 0; 37 virtual void NormalUsage() = 0;
34 38
(...skipping 26 matching lines...) Expand all
61 struct CpuOveruseMetrics { 65 struct CpuOveruseMetrics {
62 CpuOveruseMetrics() : encode_usage_percent(-1) {} 66 CpuOveruseMetrics() : encode_usage_percent(-1) {}
63 67
64 int encode_usage_percent; // Average encode time divided by the average time 68 int encode_usage_percent; // Average encode time divided by the average time
65 // difference between incoming captured frames. 69 // difference between incoming captured frames.
66 }; 70 };
67 71
68 class CpuOveruseMetricsObserver { 72 class CpuOveruseMetricsObserver {
69 public: 73 public:
70 virtual ~CpuOveruseMetricsObserver() {} 74 virtual ~CpuOveruseMetricsObserver() {}
71 virtual void CpuOveruseMetricsUpdated(const CpuOveruseMetrics& metrics) = 0; 75 virtual void OnEncodedFrameTimeMeasured(int encode_duration_ms,
76 const CpuOveruseMetrics& metrics) = 0;
72 }; 77 };
73 78
74
75 // Use to detect system overuse based on the send-side processing time of 79 // Use to detect system overuse based on the send-side processing time of
76 // incoming frames. 80 // incoming frames.
77 class OveruseFrameDetector : public Module { 81 class OveruseFrameDetector : public Module {
78 public: 82 public:
79 OveruseFrameDetector(Clock* clock, 83 OveruseFrameDetector(Clock* clock,
80 const CpuOveruseOptions& options, 84 const CpuOveruseOptions& options,
81 CpuOveruseObserver* overuse_observer, 85 CpuOveruseObserver* overuse_observer,
86 EncodedFrameObserver* encoder_timing_,
82 CpuOveruseMetricsObserver* metrics_observer); 87 CpuOveruseMetricsObserver* metrics_observer);
83 ~OveruseFrameDetector(); 88 ~OveruseFrameDetector();
84 89
85 // Called for each captured frame. 90 // Called for each captured frame.
86 void FrameCaptured(int width, int height, int64_t capture_time_ms); 91 void FrameCaptured(const VideoFrame& frame);
87 92
88 // Called for each sent frame. 93 // Called for each sent frame.
89 void FrameSent(int64_t capture_time_ms); 94 void FrameSent(uint32_t timestamp);
90
91 // Only public for testing.
92 int LastProcessingTimeMs() const;
93 int FramesInQueue() const;
94 95
95 // Implements Module. 96 // Implements Module.
96 int64_t TimeUntilNextProcess() override; 97 int64_t TimeUntilNextProcess() override;
97 int32_t Process() override; 98 int32_t Process() override;
98 99
99 private: 100 private:
100 class SendProcessingUsage; 101 class SendProcessingUsage;
101 class FrameQueue; 102 struct FrameTiming {
103 FrameTiming(int64_t capture_ntp_ms, uint32_t timestamp, int64_t now)
104 : capture_ntp_ms(capture_ntp_ms),
105 timestamp(timestamp),
106 capture_ms(now),
107 last_send_ms(-1) {}
108 int64_t capture_ntp_ms;
109 uint32_t timestamp;
110 int64_t capture_ms;
111 int64_t last_send_ms;
112 };
102 113
103 void UpdateCpuOveruseMetrics() EXCLUSIVE_LOCKS_REQUIRED(crit_); 114 void EncodedFrameTimeMeasured(int encode_duration_ms)
115 EXCLUSIVE_LOCKS_REQUIRED(crit_);
104 116
105 // TODO(asapersson): This method is only used on one thread, so it shouldn't 117 // TODO(asapersson): This method is only used on one thread, so it shouldn't
106 // need a guard. 118 // need a guard.
107 void AddProcessingTime(int elapsed_ms) EXCLUSIVE_LOCKS_REQUIRED(crit_); 119 void AddProcessingTime(int elapsed_ms) EXCLUSIVE_LOCKS_REQUIRED(crit_);
108 120
109 // Only called on the processing thread. 121 // Only called on the processing thread.
110 bool IsOverusing(const CpuOveruseMetrics& metrics); 122 bool IsOverusing(const CpuOveruseMetrics& metrics);
111 bool IsUnderusing(const CpuOveruseMetrics& metrics, int64_t time_now); 123 bool IsUnderusing(const CpuOveruseMetrics& metrics, int64_t time_now);
112 124
113 bool FrameTimeoutDetected(int64_t now) const EXCLUSIVE_LOCKS_REQUIRED(crit_); 125 bool FrameTimeoutDetected(int64_t now) const EXCLUSIVE_LOCKS_REQUIRED(crit_);
114 bool FrameSizeChanged(int num_pixels) const EXCLUSIVE_LOCKS_REQUIRED(crit_); 126 bool FrameSizeChanged(int num_pixels) const EXCLUSIVE_LOCKS_REQUIRED(crit_);
115 127
116 void ResetAll(int num_pixels) EXCLUSIVE_LOCKS_REQUIRED(crit_); 128 void ResetAll(int num_pixels) EXCLUSIVE_LOCKS_REQUIRED(crit_);
117 129
118 // Protecting all members except const and those that are only accessed on the 130 // Protecting all members except const and those that are only accessed on the
119 // processing thread. 131 // processing thread.
120 // TODO(asapersson): See if we can reduce locking. As is, video frame 132 // TODO(asapersson): See if we can reduce locking. As is, video frame
121 // processing contends with reading stats and the processing thread. 133 // processing contends with reading stats and the processing thread.
122 mutable rtc::CriticalSection crit_; 134 mutable rtc::CriticalSection crit_;
123 135
124 const CpuOveruseOptions options_; 136 const CpuOveruseOptions options_;
125 137
126 // Observer getting overuse reports. 138 // Observer getting overuse reports.
127 CpuOveruseObserver* const observer_; 139 CpuOveruseObserver* const observer_;
140 EncodedFrameObserver* const encoder_timing_;
128 141
129 // Stats metrics. 142 // Stats metrics.
130 CpuOveruseMetricsObserver* const metrics_observer_; 143 CpuOveruseMetricsObserver* const metrics_observer_;
131 CpuOveruseMetrics metrics_ GUARDED_BY(crit_); 144 CpuOveruseMetrics metrics_ GUARDED_BY(crit_);
132 145
133 Clock* const clock_; 146 Clock* const clock_;
134 int64_t num_process_times_ GUARDED_BY(crit_); 147 int64_t num_process_times_ GUARDED_BY(crit_);
135 148
136 int64_t last_capture_time_ GUARDED_BY(crit_); 149 int64_t last_capture_time_ GUARDED_BY(crit_);
137 150
138 // Number of pixels of last captured frame. 151 // Number of pixels of last captured frame.
139 int num_pixels_ GUARDED_BY(crit_); 152 int num_pixels_ GUARDED_BY(crit_);
140 153
141 // These seven members are only accessed on the processing thread. 154 // These seven members are only accessed on the processing thread.
142 int64_t next_process_time_; 155 int64_t next_process_time_;
143 int64_t last_overuse_time_; 156 int64_t last_overuse_time_;
144 int checks_above_threshold_; 157 int checks_above_threshold_;
145 int num_overuse_detections_; 158 int num_overuse_detections_;
146 int64_t last_rampup_time_; 159 int64_t last_rampup_time_;
147 bool in_quick_rampup_; 160 bool in_quick_rampup_;
148 int current_rampup_delay_ms_; 161 int current_rampup_delay_ms_;
149 162
150 int64_t last_sample_time_ms_; // Only accessed by one thread. 163 int64_t last_sample_time_ms_; // Only accessed by one thread.
151 164
152 // TODO(asapersson): Can these be regular members (avoid separate heap 165 // TODO(asapersson): Can these be regular members (avoid separate heap
153 // allocs)? 166 // allocs)?
154 const rtc::scoped_ptr<SendProcessingUsage> usage_ GUARDED_BY(crit_); 167 const rtc::scoped_ptr<SendProcessingUsage> usage_ GUARDED_BY(crit_);
155 const rtc::scoped_ptr<FrameQueue> frame_queue_ GUARDED_BY(crit_); 168 std::list<FrameTiming> frame_timing_ GUARDED_BY(crit_);
156 169
157 rtc::ThreadChecker processing_thread_; 170 rtc::ThreadChecker processing_thread_;
158 171
159 RTC_DISALLOW_COPY_AND_ASSIGN(OveruseFrameDetector); 172 RTC_DISALLOW_COPY_AND_ASSIGN(OveruseFrameDetector);
160 }; 173 };
161 174
162 } // namespace webrtc 175 } // namespace webrtc
163 176
164 #endif // WEBRTC_VIDEO_OVERUSE_FRAME_DETECTOR_H_ 177 #endif // WEBRTC_VIDEO_OVERUSE_FRAME_DETECTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698