OLD | NEW |
---|---|
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 |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 = actual_decode_time_ms - | 159 int64_t delayed_ms = |
160 (render_time_ms - MaxDecodeTimeMs() - render_delay_ms_); | 160 actual_decode_time_ms - |
161 (render_time_ms - RequiredDecodeTimeMs() - render_delay_ms_); | |
161 if (delayed_ms < 0) { | 162 if (delayed_ms < 0) { |
162 return; | 163 return; |
163 } | 164 } |
164 if (current_delay_ms_ + delayed_ms <= target_delay_ms) { | 165 if (current_delay_ms_ + delayed_ms <= target_delay_ms) { |
165 current_delay_ms_ += static_cast<uint32_t>(delayed_ms); | 166 current_delay_ms_ += static_cast<uint32_t>(delayed_ms); |
166 } else { | 167 } else { |
167 current_delay_ms_ = target_delay_ms; | 168 current_delay_ms_ = target_delay_ms; |
168 } | 169 } |
169 } | 170 } |
170 | 171 |
171 int32_t VCMTiming::StopDecodeTimer(uint32_t time_stamp, | 172 int32_t VCMTiming::StopDecodeTimer(uint32_t time_stamp, |
172 int32_t decode_time_ms, | 173 int32_t decode_time_ms, |
173 int64_t now_ms, | 174 int64_t now_ms, |
174 int64_t render_time_ms) { | 175 int64_t render_time_ms) { |
175 CriticalSectionScoped cs(crit_sect_); | 176 CriticalSectionScoped cs(crit_sect_); |
176 codec_timer_.MaxFilter(decode_time_ms, now_ms); | 177 codec_timer_.AddTiming(decode_time_ms, now_ms); |
177 assert(decode_time_ms >= 0); | 178 assert(decode_time_ms >= 0); |
178 last_decode_ms_ = decode_time_ms; | 179 last_decode_ms_ = decode_time_ms; |
179 | 180 |
180 // Update stats. | 181 // Update stats. |
181 ++num_decoded_frames_; | 182 ++num_decoded_frames_; |
182 if (num_decoded_frames_ == 1) { | 183 if (num_decoded_frames_ == 1) { |
183 first_decoded_frame_ms_ = now_ms; | 184 first_decoded_frame_ms_ = now_ms; |
184 } | 185 } |
185 int time_until_rendering_ms = render_time_ms - render_delay_ms_ - now_ms; | 186 int time_until_rendering_ms = render_time_ms - render_delay_ms_ - now_ms; |
186 if (time_until_rendering_ms < 0) { | 187 if (time_until_rendering_ms < 0) { |
(...skipping 22 matching lines...) Expand all Loading... | |
209 if (estimated_complete_time_ms == -1) { | 210 if (estimated_complete_time_ms == -1) { |
210 estimated_complete_time_ms = now_ms; | 211 estimated_complete_time_ms = now_ms; |
211 } | 212 } |
212 | 213 |
213 // Make sure that we have at least the playout delay. | 214 // Make sure that we have at least the playout delay. |
214 uint32_t actual_delay = std::max(current_delay_ms_, min_playout_delay_ms_); | 215 uint32_t actual_delay = std::max(current_delay_ms_, min_playout_delay_ms_); |
215 return estimated_complete_time_ms + actual_delay; | 216 return estimated_complete_time_ms + actual_delay; |
216 } | 217 } |
217 | 218 |
218 // Must be called from inside a critical section. | 219 // Must be called from inside a critical section. |
219 int32_t VCMTiming::MaxDecodeTimeMs( | 220 int64_t VCMTiming::RequiredDecodeTimeMs() const { |
220 FrameType frame_type /*= kVideoFrameDelta*/) const { | 221 const int64_t decode_time_ms = codec_timer_.RequiredDecodeTimeMs(); |
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 - MaxDecodeTimeMs() - render_delay_ms_; | 231 render_time_ms - now_ms - RequiredDecodeTimeMs() - 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 int32_t max_decode_time_ms = MaxDecodeTimeMs(); | 242 int64_t required_decode_time_ms = RequiredDecodeTimeMs(); |
243 if (max_decode_time_ms < 0) { | 243 if (required_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 (max_decode_time_ms == 0) { | 247 } else if (required_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 max_decode_time_ms = 1; | 250 required_decode_time_ms = 1; |
251 } | 251 } |
252 return static_cast<int32_t>(available_processing_time_ms) - | 252 return static_cast<int64_t>(available_processing_time_ms) - |
253 max_decode_time_ms > | 253 required_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_ + MaxDecodeTimeMs() + render_delay_ms_); | 264 jitter_delay_ms_ + |
265 static_cast<uint32_t>(RequiredDecodeTimeMs()) + | |
magjed_webrtc
2016/03/07 07:38:14
I have to delimit this CL somewhere, therefore the
| |
266 render_delay_ms_); | |
265 } | 267 } |
266 | 268 |
267 void VCMTiming::GetTimings(int* decode_ms, | 269 void VCMTiming::GetTimings(int* decode_ms, |
268 int* max_decode_ms, | 270 int* max_decode_ms, |
269 int* current_delay_ms, | 271 int* current_delay_ms, |
270 int* target_delay_ms, | 272 int* target_delay_ms, |
271 int* jitter_buffer_ms, | 273 int* jitter_buffer_ms, |
272 int* min_playout_delay_ms, | 274 int* min_playout_delay_ms, |
273 int* render_delay_ms) const { | 275 int* render_delay_ms) const { |
274 CriticalSectionScoped cs(crit_sect_); | 276 CriticalSectionScoped cs(crit_sect_); |
275 *decode_ms = last_decode_ms_; | 277 *decode_ms = last_decode_ms_; |
276 *max_decode_ms = MaxDecodeTimeMs(); | 278 *max_decode_ms = static_cast<int>(RequiredDecodeTimeMs()); |
magjed_webrtc
2016/03/07 07:38:14
ditto
| |
277 *current_delay_ms = current_delay_ms_; | 279 *current_delay_ms = current_delay_ms_; |
278 *target_delay_ms = TargetDelayInternal(); | 280 *target_delay_ms = TargetDelayInternal(); |
279 *jitter_buffer_ms = jitter_delay_ms_; | 281 *jitter_buffer_ms = jitter_delay_ms_; |
280 *min_playout_delay_ms = min_playout_delay_ms_; | 282 *min_playout_delay_ms = min_playout_delay_ms_; |
281 *render_delay_ms = render_delay_ms_; | 283 *render_delay_ms = render_delay_ms_; |
282 } | 284 } |
283 | 285 |
284 } // namespace webrtc | 286 } // namespace webrtc |
OLD | NEW |