niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 11 | #include "webrtc/modules/video_coding/timing.h" |
stefan@webrtc.org | a678a3b | 2013-01-21 07:42:11 +0000 | [diff] [blame] | 12 | |
philipel | 5908c71 | 2015-12-21 08:23:20 -0800 | [diff] [blame] | 13 | #include <algorithm> |
| 14 | |
Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 15 | #include "webrtc/modules/video_coding/internal_defines.h" |
| 16 | #include "webrtc/modules/video_coding/jitter_buffer_common.h" |
Henrik Kjellander | 98f5351 | 2015-10-28 18:17:40 +0100 | [diff] [blame] | 17 | #include "webrtc/system_wrappers/include/clock.h" |
| 18 | #include "webrtc/system_wrappers/include/metrics.h" |
| 19 | #include "webrtc/system_wrappers/include/timestamp_extrapolator.h" |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 20 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 21 | namespace webrtc { |
| 22 | |
philipel | 5908c71 | 2015-12-21 08:23:20 -0800 | [diff] [blame] | 23 | VCMTiming::VCMTiming(Clock* clock, VCMTiming* master_timing) |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 24 | : crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 25 | clock_(clock), |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 26 | master_(false), |
| 27 | ts_extrapolator_(), |
magjed | 2943f01 | 2016-03-22 05:12:09 -0700 | [diff] [blame] | 28 | codec_timer_(new VCMCodecTimer()), |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 29 | render_delay_ms_(kDefaultRenderDelayMs), |
mikhal@webrtc.org | adc64a7 | 2013-05-30 16:20:18 +0000 | [diff] [blame] | 30 | min_playout_delay_ms_(0), |
| 31 | jitter_delay_ms_(0), |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 32 | current_delay_ms_(0), |
fischman@webrtc.org | 37bb497 | 2013-10-23 23:59:45 +0000 | [diff] [blame] | 33 | last_decode_ms_(0), |
asapersson@webrtc.org | f244760 | 2014-12-09 14:13:26 +0000 | [diff] [blame] | 34 | prev_frame_timestamp_(0), |
| 35 | num_decoded_frames_(0), |
| 36 | num_delayed_decoded_frames_(0), |
| 37 | first_decoded_frame_ms_(-1), |
| 38 | sum_missed_render_deadline_ms_(0) { |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 39 | if (master_timing == NULL) { |
| 40 | master_ = true; |
wu@webrtc.org | 66773a0 | 2014-05-07 17:09:44 +0000 | [diff] [blame] | 41 | ts_extrapolator_ = new TimestampExtrapolator(clock_->TimeInMilliseconds()); |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 42 | } else { |
| 43 | ts_extrapolator_ = master_timing->ts_extrapolator_; |
| 44 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 45 | } |
| 46 | |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 47 | VCMTiming::~VCMTiming() { |
asapersson@webrtc.org | f244760 | 2014-12-09 14:13:26 +0000 | [diff] [blame] | 48 | UpdateHistograms(); |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 49 | if (master_) { |
| 50 | delete ts_extrapolator_; |
| 51 | } |
| 52 | delete crit_sect_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 53 | } |
| 54 | |
asapersson@webrtc.org | f244760 | 2014-12-09 14:13:26 +0000 | [diff] [blame] | 55 | void VCMTiming::UpdateHistograms() const { |
| 56 | CriticalSectionScoped cs(crit_sect_); |
| 57 | if (num_decoded_frames_ == 0) { |
| 58 | return; |
| 59 | } |
| 60 | int64_t elapsed_sec = |
| 61 | (clock_->TimeInMilliseconds() - first_decoded_frame_ms_) / 1000; |
| 62 | if (elapsed_sec < metrics::kMinRunTimeInSeconds) { |
| 63 | return; |
| 64 | } |
asapersson | 58d992e | 2016-03-29 02:15:06 -0700 | [diff] [blame^] | 65 | RTC_LOGGED_HISTOGRAM_COUNTS_100( |
asapersson | 5380532 | 2015-12-21 01:46:20 -0800 | [diff] [blame] | 66 | "WebRTC.Video.DecodedFramesPerSecond", |
asapersson@webrtc.org | f244760 | 2014-12-09 14:13:26 +0000 | [diff] [blame] | 67 | static_cast<int>((num_decoded_frames_ / elapsed_sec) + 0.5f)); |
asapersson | 58d992e | 2016-03-29 02:15:06 -0700 | [diff] [blame^] | 68 | RTC_LOGGED_HISTOGRAM_PERCENTAGE( |
asapersson | 5380532 | 2015-12-21 01:46:20 -0800 | [diff] [blame] | 69 | "WebRTC.Video.DelayedFramesToRenderer", |
asapersson@webrtc.org | f244760 | 2014-12-09 14:13:26 +0000 | [diff] [blame] | 70 | num_delayed_decoded_frames_ * 100 / num_decoded_frames_); |
| 71 | if (num_delayed_decoded_frames_ > 0) { |
asapersson | 58d992e | 2016-03-29 02:15:06 -0700 | [diff] [blame^] | 72 | RTC_LOGGED_HISTOGRAM_COUNTS_1000( |
asapersson@webrtc.org | f244760 | 2014-12-09 14:13:26 +0000 | [diff] [blame] | 73 | "WebRTC.Video.DelayedFramesToRenderer_AvgDelayInMs", |
asapersson | 5380532 | 2015-12-21 01:46:20 -0800 | [diff] [blame] | 74 | sum_missed_render_deadline_ms_ / num_delayed_decoded_frames_); |
asapersson@webrtc.org | f244760 | 2014-12-09 14:13:26 +0000 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 78 | void VCMTiming::Reset() { |
| 79 | CriticalSectionScoped cs(crit_sect_); |
wu@webrtc.org | ed4cb56 | 2014-05-06 04:50:49 +0000 | [diff] [blame] | 80 | ts_extrapolator_->Reset(clock_->TimeInMilliseconds()); |
magjed | 2943f01 | 2016-03-22 05:12:09 -0700 | [diff] [blame] | 81 | codec_timer_.reset(new VCMCodecTimer()); |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 82 | render_delay_ms_ = kDefaultRenderDelayMs; |
mikhal@webrtc.org | adc64a7 | 2013-05-30 16:20:18 +0000 | [diff] [blame] | 83 | min_playout_delay_ms_ = 0; |
| 84 | jitter_delay_ms_ = 0; |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 85 | current_delay_ms_ = 0; |
| 86 | prev_frame_timestamp_ = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 87 | } |
| 88 | |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 89 | void VCMTiming::ResetDecodeTime() { |
pbos@webrtc.org | 0422100 | 2014-07-10 15:25:37 +0000 | [diff] [blame] | 90 | CriticalSectionScoped lock(crit_sect_); |
magjed | 2943f01 | 2016-03-22 05:12:09 -0700 | [diff] [blame] | 91 | codec_timer_.reset(new VCMCodecTimer()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 92 | } |
| 93 | |
mikhal@webrtc.org | adc64a7 | 2013-05-30 16:20:18 +0000 | [diff] [blame] | 94 | void VCMTiming::set_render_delay(uint32_t render_delay_ms) { |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 95 | CriticalSectionScoped cs(crit_sect_); |
| 96 | render_delay_ms_ = render_delay_ms; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 97 | } |
| 98 | |
mikhal@webrtc.org | adc64a7 | 2013-05-30 16:20:18 +0000 | [diff] [blame] | 99 | void VCMTiming::set_min_playout_delay(uint32_t min_playout_delay_ms) { |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 100 | CriticalSectionScoped cs(crit_sect_); |
mikhal@webrtc.org | adc64a7 | 2013-05-30 16:20:18 +0000 | [diff] [blame] | 101 | min_playout_delay_ms_ = min_playout_delay_ms; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 102 | } |
| 103 | |
mikhal@webrtc.org | adc64a7 | 2013-05-30 16:20:18 +0000 | [diff] [blame] | 104 | void VCMTiming::SetJitterDelay(uint32_t jitter_delay_ms) { |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 105 | CriticalSectionScoped cs(crit_sect_); |
mikhal@webrtc.org | adc64a7 | 2013-05-30 16:20:18 +0000 | [diff] [blame] | 106 | if (jitter_delay_ms != jitter_delay_ms_) { |
mikhal@webrtc.org | adc64a7 | 2013-05-30 16:20:18 +0000 | [diff] [blame] | 107 | jitter_delay_ms_ = jitter_delay_ms; |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 108 | // When in initial state, set current delay to minimum delay. |
| 109 | if (current_delay_ms_ == 0) { |
mikhal@webrtc.org | adc64a7 | 2013-05-30 16:20:18 +0000 | [diff] [blame] | 110 | current_delay_ms_ = jitter_delay_ms_; |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 111 | } |
| 112 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 113 | } |
| 114 | |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 115 | void VCMTiming::UpdateCurrentDelay(uint32_t frame_timestamp) { |
| 116 | CriticalSectionScoped cs(crit_sect_); |
| 117 | uint32_t target_delay_ms = TargetDelayInternal(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 118 | |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 119 | if (current_delay_ms_ == 0) { |
| 120 | // Not initialized, set current delay to target. |
| 121 | current_delay_ms_ = target_delay_ms; |
| 122 | } else if (target_delay_ms != current_delay_ms_) { |
philipel | 5908c71 | 2015-12-21 08:23:20 -0800 | [diff] [blame] | 123 | int64_t delay_diff_ms = |
| 124 | static_cast<int64_t>(target_delay_ms) - current_delay_ms_; |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 125 | // Never change the delay with more than 100 ms every second. If we're |
| 126 | // changing the delay in too large steps we will get noticeable freezes. By |
| 127 | // limiting the change we can increase the delay in smaller steps, which |
| 128 | // will be experienced as the video is played in slow motion. When lowering |
| 129 | // the delay the video will be played at a faster pace. |
| 130 | int64_t max_change_ms = 0; |
| 131 | if (frame_timestamp < 0x0000ffff && prev_frame_timestamp_ > 0xffff0000) { |
| 132 | // wrap |
philipel | 5908c71 | 2015-12-21 08:23:20 -0800 | [diff] [blame] | 133 | max_change_ms = kDelayMaxChangeMsPerS * |
| 134 | (frame_timestamp + (static_cast<int64_t>(1) << 32) - |
| 135 | prev_frame_timestamp_) / |
| 136 | 90000; |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 137 | } else { |
| 138 | max_change_ms = kDelayMaxChangeMsPerS * |
philipel | 5908c71 | 2015-12-21 08:23:20 -0800 | [diff] [blame] | 139 | (frame_timestamp - prev_frame_timestamp_) / 90000; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 140 | } |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 141 | if (max_change_ms <= 0) { |
| 142 | // Any changes less than 1 ms are truncated and |
| 143 | // will be postponed. Negative change will be due |
| 144 | // to reordering and should be ignored. |
| 145 | return; |
| 146 | } |
| 147 | delay_diff_ms = std::max(delay_diff_ms, -max_change_ms); |
| 148 | delay_diff_ms = std::min(delay_diff_ms, max_change_ms); |
mikhal@webrtc.org | 6faba6e | 2013-04-30 15:39:34 +0000 | [diff] [blame] | 149 | |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 150 | current_delay_ms_ = current_delay_ms_ + static_cast<int32_t>(delay_diff_ms); |
| 151 | } |
| 152 | prev_frame_timestamp_ = frame_timestamp; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 153 | } |
| 154 | |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 155 | void VCMTiming::UpdateCurrentDelay(int64_t render_time_ms, |
| 156 | int64_t actual_decode_time_ms) { |
| 157 | CriticalSectionScoped cs(crit_sect_); |
| 158 | uint32_t target_delay_ms = TargetDelayInternal(); |
magjed | 2943f01 | 2016-03-22 05:12:09 -0700 | [diff] [blame] | 159 | int64_t delayed_ms = |
| 160 | actual_decode_time_ms - |
| 161 | (render_time_ms - RequiredDecodeTimeMs() - render_delay_ms_); |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 162 | if (delayed_ms < 0) { |
| 163 | return; |
| 164 | } |
| 165 | if (current_delay_ms_ + delayed_ms <= target_delay_ms) { |
| 166 | current_delay_ms_ += static_cast<uint32_t>(delayed_ms); |
| 167 | } else { |
| 168 | current_delay_ms_ = target_delay_ms; |
| 169 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 170 | } |
| 171 | |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 172 | int32_t VCMTiming::StopDecodeTimer(uint32_t time_stamp, |
Per | 327d8ba | 2015-11-10 14:00:27 +0100 | [diff] [blame] | 173 | int32_t decode_time_ms, |
asapersson@webrtc.org | f244760 | 2014-12-09 14:13:26 +0000 | [diff] [blame] | 174 | int64_t now_ms, |
| 175 | int64_t render_time_ms) { |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 176 | CriticalSectionScoped cs(crit_sect_); |
magjed | 2943f01 | 2016-03-22 05:12:09 -0700 | [diff] [blame] | 177 | codec_timer_->AddTiming(decode_time_ms, now_ms); |
Per | 327d8ba | 2015-11-10 14:00:27 +0100 | [diff] [blame] | 178 | assert(decode_time_ms >= 0); |
| 179 | last_decode_ms_ = decode_time_ms; |
asapersson@webrtc.org | f244760 | 2014-12-09 14:13:26 +0000 | [diff] [blame] | 180 | |
| 181 | // Update stats. |
| 182 | ++num_decoded_frames_; |
| 183 | if (num_decoded_frames_ == 1) { |
| 184 | first_decoded_frame_ms_ = now_ms; |
| 185 | } |
| 186 | int time_until_rendering_ms = render_time_ms - render_delay_ms_ - now_ms; |
| 187 | if (time_until_rendering_ms < 0) { |
| 188 | sum_missed_render_deadline_ms_ += -time_until_rendering_ms; |
| 189 | ++num_delayed_decoded_frames_; |
| 190 | } |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 191 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 192 | } |
| 193 | |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 194 | void VCMTiming::IncomingTimestamp(uint32_t time_stamp, int64_t now_ms) { |
| 195 | CriticalSectionScoped cs(crit_sect_); |
stefan@webrtc.org | 34c5da6 | 2014-04-11 14:08:35 +0000 | [diff] [blame] | 196 | ts_extrapolator_->Update(now_ms, time_stamp); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 197 | } |
| 198 | |
philipel | 5908c71 | 2015-12-21 08:23:20 -0800 | [diff] [blame] | 199 | int64_t VCMTiming::RenderTimeMs(uint32_t frame_timestamp, |
| 200 | int64_t now_ms) const { |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 201 | CriticalSectionScoped cs(crit_sect_); |
| 202 | const int64_t render_time_ms = RenderTimeMsInternal(frame_timestamp, now_ms); |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 203 | return render_time_ms; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 204 | } |
| 205 | |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 206 | int64_t VCMTiming::RenderTimeMsInternal(uint32_t frame_timestamp, |
| 207 | int64_t now_ms) const { |
| 208 | int64_t estimated_complete_time_ms = |
philipel | 5908c71 | 2015-12-21 08:23:20 -0800 | [diff] [blame] | 209 | ts_extrapolator_->ExtrapolateLocalTime(frame_timestamp); |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 210 | if (estimated_complete_time_ms == -1) { |
| 211 | estimated_complete_time_ms = now_ms; |
| 212 | } |
mikhal@webrtc.org | 6faba6e | 2013-04-30 15:39:34 +0000 | [diff] [blame] | 213 | |
mikhal@webrtc.org | adc64a7 | 2013-05-30 16:20:18 +0000 | [diff] [blame] | 214 | // Make sure that we have at least the playout delay. |
| 215 | uint32_t actual_delay = std::max(current_delay_ms_, min_playout_delay_ms_); |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 216 | return estimated_complete_time_ms + actual_delay; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 217 | } |
| 218 | |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 219 | // Must be called from inside a critical section. |
magjed | 2943f01 | 2016-03-22 05:12:09 -0700 | [diff] [blame] | 220 | int64_t VCMTiming::RequiredDecodeTimeMs() const { |
| 221 | const int64_t decode_time_ms = codec_timer_->RequiredDecodeTimeMs(); |
stefan@webrtc.org | 34c5da6 | 2014-04-11 14:08:35 +0000 | [diff] [blame] | 222 | assert(decode_time_ms >= 0); |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 223 | return decode_time_ms; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 224 | } |
| 225 | |
philipel | 5908c71 | 2015-12-21 08:23:20 -0800 | [diff] [blame] | 226 | uint32_t VCMTiming::MaxWaitingTime(int64_t render_time_ms, |
| 227 | int64_t now_ms) const { |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 228 | CriticalSectionScoped cs(crit_sect_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 229 | |
philipel | 5908c71 | 2015-12-21 08:23:20 -0800 | [diff] [blame] | 230 | const int64_t max_wait_time_ms = |
magjed | 2943f01 | 2016-03-22 05:12:09 -0700 | [diff] [blame] | 231 | render_time_ms - now_ms - RequiredDecodeTimeMs() - render_delay_ms_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 232 | |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 233 | if (max_wait_time_ms < 0) { |
| 234 | return 0; |
| 235 | } |
| 236 | return static_cast<uint32_t>(max_wait_time_ms); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 237 | } |
| 238 | |
philipel | 5908c71 | 2015-12-21 08:23:20 -0800 | [diff] [blame] | 239 | bool VCMTiming::EnoughTimeToDecode( |
| 240 | uint32_t available_processing_time_ms) const { |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 241 | CriticalSectionScoped cs(crit_sect_); |
magjed | 2943f01 | 2016-03-22 05:12:09 -0700 | [diff] [blame] | 242 | int64_t required_decode_time_ms = RequiredDecodeTimeMs(); |
| 243 | if (required_decode_time_ms < 0) { |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 244 | // Haven't decoded any frames yet, try decoding one to get an estimate |
| 245 | // of the decode time. |
| 246 | return true; |
magjed | 2943f01 | 2016-03-22 05:12:09 -0700 | [diff] [blame] | 247 | } else if (required_decode_time_ms == 0) { |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 248 | // Decode time is less than 1, set to 1 for now since |
| 249 | // we don't have any better precision. Count ticks later? |
magjed | 2943f01 | 2016-03-22 05:12:09 -0700 | [diff] [blame] | 250 | required_decode_time_ms = 1; |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 251 | } |
magjed | 2943f01 | 2016-03-22 05:12:09 -0700 | [diff] [blame] | 252 | return static_cast<int64_t>(available_processing_time_ms) - |
| 253 | required_decode_time_ms > |
philipel | 5908c71 | 2015-12-21 08:23:20 -0800 | [diff] [blame] | 254 | 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 255 | } |
| 256 | |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 257 | uint32_t VCMTiming::TargetVideoDelay() const { |
| 258 | CriticalSectionScoped cs(crit_sect_); |
| 259 | return TargetDelayInternal(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 260 | } |
| 261 | |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 262 | uint32_t VCMTiming::TargetDelayInternal() const { |
mikhal@webrtc.org | adc64a7 | 2013-05-30 16:20:18 +0000 | [diff] [blame] | 263 | return std::max(min_playout_delay_ms_, |
magjed | 2943f01 | 2016-03-22 05:12:09 -0700 | [diff] [blame] | 264 | jitter_delay_ms_ + |
| 265 | static_cast<uint32_t>(RequiredDecodeTimeMs()) + |
| 266 | render_delay_ms_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 267 | } |
| 268 | |
fischman@webrtc.org | 37bb497 | 2013-10-23 23:59:45 +0000 | [diff] [blame] | 269 | void VCMTiming::GetTimings(int* decode_ms, |
| 270 | int* max_decode_ms, |
| 271 | int* current_delay_ms, |
| 272 | int* target_delay_ms, |
| 273 | int* jitter_buffer_ms, |
| 274 | int* min_playout_delay_ms, |
| 275 | int* render_delay_ms) const { |
| 276 | CriticalSectionScoped cs(crit_sect_); |
| 277 | *decode_ms = last_decode_ms_; |
magjed | 2943f01 | 2016-03-22 05:12:09 -0700 | [diff] [blame] | 278 | *max_decode_ms = static_cast<int>(RequiredDecodeTimeMs()); |
fischman@webrtc.org | 37bb497 | 2013-10-23 23:59:45 +0000 | [diff] [blame] | 279 | *current_delay_ms = current_delay_ms_; |
| 280 | *target_delay_ms = TargetDelayInternal(); |
| 281 | *jitter_buffer_ms = jitter_delay_ms_; |
| 282 | *min_playout_delay_ms = min_playout_delay_ms_; |
| 283 | *render_delay_ms = render_delay_ms_; |
| 284 | } |
| 285 | |
mikhal@webrtc.org | 2eaf98b | 2013-05-21 17:58:43 +0000 | [diff] [blame] | 286 | } // namespace webrtc |