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

Side by Side Diff: webrtc/modules/video_coding/timing.cc

Issue 1808693002: Revert of VCMCodecTimer: Change filter from max to 95th percentile (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « webrtc/modules/video_coding/timing.h ('k') | webrtc/modules/video_coding/timing_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2011 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 #include "webrtc/modules/video_coding/timing.h" 11 #include "webrtc/modules/video_coding/timing.h"
12 12
13 #include <algorithm> 13 #include <algorithm>
14 14
15 #include "webrtc/modules/video_coding/internal_defines.h" 15 #include "webrtc/modules/video_coding/internal_defines.h"
16 #include "webrtc/modules/video_coding/jitter_buffer_common.h" 16 #include "webrtc/modules/video_coding/jitter_buffer_common.h"
17 #include "webrtc/system_wrappers/include/clock.h" 17 #include "webrtc/system_wrappers/include/clock.h"
18 #include "webrtc/system_wrappers/include/metrics.h" 18 #include "webrtc/system_wrappers/include/metrics.h"
19 #include "webrtc/system_wrappers/include/timestamp_extrapolator.h" 19 #include "webrtc/system_wrappers/include/timestamp_extrapolator.h"
20 20
21 namespace webrtc { 21 namespace webrtc {
22 22
23 VCMTiming::VCMTiming(Clock* clock, VCMTiming* master_timing) 23 VCMTiming::VCMTiming(Clock* clock, VCMTiming* master_timing)
24 : crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), 24 : crit_sect_(CriticalSectionWrapper::CreateCriticalSection()),
25 clock_(clock), 25 clock_(clock),
26 master_(false), 26 master_(false),
27 ts_extrapolator_(), 27 ts_extrapolator_(),
28 codec_timer_(new VCMCodecTimer()), 28 codec_timer_(),
29 render_delay_ms_(kDefaultRenderDelayMs), 29 render_delay_ms_(kDefaultRenderDelayMs),
30 min_playout_delay_ms_(0), 30 min_playout_delay_ms_(0),
31 jitter_delay_ms_(0), 31 jitter_delay_ms_(0),
32 current_delay_ms_(0), 32 current_delay_ms_(0),
33 last_decode_ms_(0), 33 last_decode_ms_(0),
34 prev_frame_timestamp_(0), 34 prev_frame_timestamp_(0),
35 num_decoded_frames_(0), 35 num_decoded_frames_(0),
36 num_delayed_decoded_frames_(0), 36 num_delayed_decoded_frames_(0),
37 first_decoded_frame_ms_(-1), 37 first_decoded_frame_ms_(-1),
38 sum_missed_render_deadline_ms_(0) { 38 sum_missed_render_deadline_ms_(0) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 if (num_delayed_decoded_frames_ > 0) { 71 if (num_delayed_decoded_frames_ > 0) {
72 RTC_HISTOGRAM_COUNTS_1000( 72 RTC_HISTOGRAM_COUNTS_1000(
73 "WebRTC.Video.DelayedFramesToRenderer_AvgDelayInMs", 73 "WebRTC.Video.DelayedFramesToRenderer_AvgDelayInMs",
74 sum_missed_render_deadline_ms_ / num_delayed_decoded_frames_); 74 sum_missed_render_deadline_ms_ / num_delayed_decoded_frames_);
75 } 75 }
76 } 76 }
77 77
78 void VCMTiming::Reset() { 78 void VCMTiming::Reset() {
79 CriticalSectionScoped cs(crit_sect_); 79 CriticalSectionScoped cs(crit_sect_);
80 ts_extrapolator_->Reset(clock_->TimeInMilliseconds()); 80 ts_extrapolator_->Reset(clock_->TimeInMilliseconds());
81 codec_timer_.reset(new VCMCodecTimer()); 81 codec_timer_.Reset();
82 render_delay_ms_ = kDefaultRenderDelayMs; 82 render_delay_ms_ = kDefaultRenderDelayMs;
83 min_playout_delay_ms_ = 0; 83 min_playout_delay_ms_ = 0;
84 jitter_delay_ms_ = 0; 84 jitter_delay_ms_ = 0;
85 current_delay_ms_ = 0; 85 current_delay_ms_ = 0;
86 prev_frame_timestamp_ = 0; 86 prev_frame_timestamp_ = 0;
87 } 87 }
88 88
89 void VCMTiming::ResetDecodeTime() { 89 void VCMTiming::ResetDecodeTime() {
90 CriticalSectionScoped lock(crit_sect_); 90 CriticalSectionScoped lock(crit_sect_);
91 codec_timer_.reset(new VCMCodecTimer()); 91 codec_timer_.Reset();
92 } 92 }
93 93
94 void VCMTiming::set_render_delay(uint32_t render_delay_ms) { 94 void VCMTiming::set_render_delay(uint32_t render_delay_ms) {
95 CriticalSectionScoped cs(crit_sect_); 95 CriticalSectionScoped cs(crit_sect_);
96 render_delay_ms_ = render_delay_ms; 96 render_delay_ms_ = render_delay_ms;
97 } 97 }
98 98
99 void VCMTiming::set_min_playout_delay(uint32_t min_playout_delay_ms) { 99 void VCMTiming::set_min_playout_delay(uint32_t min_playout_delay_ms) {
100 CriticalSectionScoped cs(crit_sect_); 100 CriticalSectionScoped cs(crit_sect_);
101 min_playout_delay_ms_ = min_playout_delay_ms; 101 min_playout_delay_ms_ = min_playout_delay_ms;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 149
150 current_delay_ms_ = current_delay_ms_ + static_cast<int32_t>(delay_diff_ms); 150 current_delay_ms_ = current_delay_ms_ + static_cast<int32_t>(delay_diff_ms);
151 } 151 }
152 prev_frame_timestamp_ = frame_timestamp; 152 prev_frame_timestamp_ = frame_timestamp;
153 } 153 }
154 154
155 void VCMTiming::UpdateCurrentDelay(int64_t render_time_ms, 155 void VCMTiming::UpdateCurrentDelay(int64_t render_time_ms,
156 int64_t actual_decode_time_ms) { 156 int64_t actual_decode_time_ms) {
157 CriticalSectionScoped cs(crit_sect_); 157 CriticalSectionScoped cs(crit_sect_);
158 uint32_t target_delay_ms = TargetDelayInternal(); 158 uint32_t target_delay_ms = TargetDelayInternal();
159 int64_t delayed_ms = 159 int64_t delayed_ms = actual_decode_time_ms -
160 actual_decode_time_ms - 160 (render_time_ms - MaxDecodeTimeMs() - render_delay_ms_);
161 (render_time_ms - RequiredDecodeTimeMs() - render_delay_ms_);
162 if (delayed_ms < 0) { 161 if (delayed_ms < 0) {
163 return; 162 return;
164 } 163 }
165 if (current_delay_ms_ + delayed_ms <= target_delay_ms) { 164 if (current_delay_ms_ + delayed_ms <= target_delay_ms) {
166 current_delay_ms_ += static_cast<uint32_t>(delayed_ms); 165 current_delay_ms_ += static_cast<uint32_t>(delayed_ms);
167 } else { 166 } else {
168 current_delay_ms_ = target_delay_ms; 167 current_delay_ms_ = target_delay_ms;
169 } 168 }
170 } 169 }
171 170
172 int32_t VCMTiming::StopDecodeTimer(uint32_t time_stamp, 171 int32_t VCMTiming::StopDecodeTimer(uint32_t time_stamp,
173 int32_t decode_time_ms, 172 int32_t decode_time_ms,
174 int64_t now_ms, 173 int64_t now_ms,
175 int64_t render_time_ms) { 174 int64_t render_time_ms) {
176 CriticalSectionScoped cs(crit_sect_); 175 CriticalSectionScoped cs(crit_sect_);
177 codec_timer_->AddTiming(decode_time_ms, now_ms); 176 codec_timer_.MaxFilter(decode_time_ms, now_ms);
178 assert(decode_time_ms >= 0); 177 assert(decode_time_ms >= 0);
179 last_decode_ms_ = decode_time_ms; 178 last_decode_ms_ = decode_time_ms;
180 179
181 // Update stats. 180 // Update stats.
182 ++num_decoded_frames_; 181 ++num_decoded_frames_;
183 if (num_decoded_frames_ == 1) { 182 if (num_decoded_frames_ == 1) {
184 first_decoded_frame_ms_ = now_ms; 183 first_decoded_frame_ms_ = now_ms;
185 } 184 }
186 int time_until_rendering_ms = render_time_ms - render_delay_ms_ - now_ms; 185 int time_until_rendering_ms = render_time_ms - render_delay_ms_ - now_ms;
187 if (time_until_rendering_ms < 0) { 186 if (time_until_rendering_ms < 0) {
(...skipping 22 matching lines...) Expand all
210 if (estimated_complete_time_ms == -1) { 209 if (estimated_complete_time_ms == -1) {
211 estimated_complete_time_ms = now_ms; 210 estimated_complete_time_ms = now_ms;
212 } 211 }
213 212
214 // Make sure that we have at least the playout delay. 213 // Make sure that we have at least the playout delay.
215 uint32_t actual_delay = std::max(current_delay_ms_, min_playout_delay_ms_); 214 uint32_t actual_delay = std::max(current_delay_ms_, min_playout_delay_ms_);
216 return estimated_complete_time_ms + actual_delay; 215 return estimated_complete_time_ms + actual_delay;
217 } 216 }
218 217
219 // Must be called from inside a critical section. 218 // Must be called from inside a critical section.
220 int64_t VCMTiming::RequiredDecodeTimeMs() const { 219 int32_t VCMTiming::MaxDecodeTimeMs(
221 const int64_t decode_time_ms = codec_timer_->RequiredDecodeTimeMs(); 220 FrameType frame_type /*= kVideoFrameDelta*/) const {
221 const int32_t decode_time_ms = codec_timer_.RequiredDecodeTimeMs(frame_type);
222 assert(decode_time_ms >= 0); 222 assert(decode_time_ms >= 0);
223 return decode_time_ms; 223 return decode_time_ms;
224 } 224 }
225 225
226 uint32_t VCMTiming::MaxWaitingTime(int64_t render_time_ms, 226 uint32_t VCMTiming::MaxWaitingTime(int64_t render_time_ms,
227 int64_t now_ms) const { 227 int64_t now_ms) const {
228 CriticalSectionScoped cs(crit_sect_); 228 CriticalSectionScoped cs(crit_sect_);
229 229
230 const int64_t max_wait_time_ms = 230 const int64_t max_wait_time_ms =
231 render_time_ms - now_ms - RequiredDecodeTimeMs() - render_delay_ms_; 231 render_time_ms - now_ms - MaxDecodeTimeMs() - render_delay_ms_;
232 232
233 if (max_wait_time_ms < 0) { 233 if (max_wait_time_ms < 0) {
234 return 0; 234 return 0;
235 } 235 }
236 return static_cast<uint32_t>(max_wait_time_ms); 236 return static_cast<uint32_t>(max_wait_time_ms);
237 } 237 }
238 238
239 bool VCMTiming::EnoughTimeToDecode( 239 bool VCMTiming::EnoughTimeToDecode(
240 uint32_t available_processing_time_ms) const { 240 uint32_t available_processing_time_ms) const {
241 CriticalSectionScoped cs(crit_sect_); 241 CriticalSectionScoped cs(crit_sect_);
242 int64_t required_decode_time_ms = RequiredDecodeTimeMs(); 242 int32_t max_decode_time_ms = MaxDecodeTimeMs();
243 if (required_decode_time_ms < 0) { 243 if (max_decode_time_ms < 0) {
244 // Haven't decoded any frames yet, try decoding one to get an estimate 244 // Haven't decoded any frames yet, try decoding one to get an estimate
245 // of the decode time. 245 // of the decode time.
246 return true; 246 return true;
247 } else if (required_decode_time_ms == 0) { 247 } else if (max_decode_time_ms == 0) {
248 // Decode time is less than 1, set to 1 for now since 248 // Decode time is less than 1, set to 1 for now since
249 // we don't have any better precision. Count ticks later? 249 // we don't have any better precision. Count ticks later?
250 required_decode_time_ms = 1; 250 max_decode_time_ms = 1;
251 } 251 }
252 return static_cast<int64_t>(available_processing_time_ms) - 252 return static_cast<int32_t>(available_processing_time_ms) -
253 required_decode_time_ms > 253 max_decode_time_ms >
254 0; 254 0;
255 } 255 }
256 256
257 uint32_t VCMTiming::TargetVideoDelay() const { 257 uint32_t VCMTiming::TargetVideoDelay() const {
258 CriticalSectionScoped cs(crit_sect_); 258 CriticalSectionScoped cs(crit_sect_);
259 return TargetDelayInternal(); 259 return TargetDelayInternal();
260 } 260 }
261 261
262 uint32_t VCMTiming::TargetDelayInternal() const { 262 uint32_t VCMTiming::TargetDelayInternal() const {
263 return std::max(min_playout_delay_ms_, 263 return std::max(min_playout_delay_ms_,
264 jitter_delay_ms_ + 264 jitter_delay_ms_ + MaxDecodeTimeMs() + render_delay_ms_);
265 static_cast<uint32_t>(RequiredDecodeTimeMs()) +
266 render_delay_ms_);
267 } 265 }
268 266
269 void VCMTiming::GetTimings(int* decode_ms, 267 void VCMTiming::GetTimings(int* decode_ms,
270 int* max_decode_ms, 268 int* max_decode_ms,
271 int* current_delay_ms, 269 int* current_delay_ms,
272 int* target_delay_ms, 270 int* target_delay_ms,
273 int* jitter_buffer_ms, 271 int* jitter_buffer_ms,
274 int* min_playout_delay_ms, 272 int* min_playout_delay_ms,
275 int* render_delay_ms) const { 273 int* render_delay_ms) const {
276 CriticalSectionScoped cs(crit_sect_); 274 CriticalSectionScoped cs(crit_sect_);
277 *decode_ms = last_decode_ms_; 275 *decode_ms = last_decode_ms_;
278 *max_decode_ms = static_cast<int>(RequiredDecodeTimeMs()); 276 *max_decode_ms = MaxDecodeTimeMs();
279 *current_delay_ms = current_delay_ms_; 277 *current_delay_ms = current_delay_ms_;
280 *target_delay_ms = TargetDelayInternal(); 278 *target_delay_ms = TargetDelayInternal();
281 *jitter_buffer_ms = jitter_delay_ms_; 279 *jitter_buffer_ms = jitter_delay_ms_;
282 *min_playout_delay_ms = min_playout_delay_ms_; 280 *min_playout_delay_ms = min_playout_delay_ms_;
283 *render_delay_ms = render_delay_ms_; 281 *render_delay_ms = render_delay_ms_;
284 } 282 }
285 283
286 } // namespace webrtc 284 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/video_coding/timing.h ('k') | webrtc/modules/video_coding/timing_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698