blob: 280dc5a0b08dee456ccfb867b5652130062f654e [file] [log] [blame]
philipelbe7a9e52016-05-19 12:19:35 +02001/*
2 * Copyright (c) 2016 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
11#include "webrtc/modules/video_coding/frame_buffer2.h"
12
13#include <algorithm>
philipele0b2f152016-09-28 10:23:49 +020014#include <cstring>
15#include <queue>
philipelbe7a9e52016-05-19 12:19:35 +020016
17#include "webrtc/base/checks.h"
philipele0b2f152016-09-28 10:23:49 +020018#include "webrtc/base/logging.h"
tommidb23ea62017-03-03 07:21:18 -080019#include "webrtc/base/trace_event.h"
philipela45102f2017-02-22 05:30:39 -080020#include "webrtc/modules/video_coding/include/video_coding_defines.h"
philipelbe7a9e52016-05-19 12:19:35 +020021#include "webrtc/modules/video_coding/jitter_estimator.h"
philipelbe7a9e52016-05-19 12:19:35 +020022#include "webrtc/modules/video_coding/timing.h"
23#include "webrtc/system_wrappers/include/clock.h"
philipel266f0a42016-11-28 08:49:07 -080024#include "webrtc/system_wrappers/include/metrics.h"
philipelbe7a9e52016-05-19 12:19:35 +020025
26namespace webrtc {
27namespace video_coding {
28
29namespace {
philipele0b2f152016-09-28 10:23:49 +020030// Max number of frames the buffer will hold.
31constexpr int kMaxFramesBuffered = 600;
philipelbe7a9e52016-05-19 12:19:35 +020032
philipele0b2f152016-09-28 10:23:49 +020033// Max number of decoded frame info that will be saved.
philipelfd5a20f2016-11-15 00:57:57 -080034constexpr int kMaxFramesHistory = 50;
philipelbe7a9e52016-05-19 12:19:35 +020035} // namespace
36
philipelbe7a9e52016-05-19 12:19:35 +020037FrameBuffer::FrameBuffer(Clock* clock,
38 VCMJitterEstimator* jitter_estimator,
philipela45102f2017-02-22 05:30:39 -080039 VCMTiming* timing,
40 VCMReceiveStatisticsCallback* stats_callback)
philipelbe7a9e52016-05-19 12:19:35 +020041 : clock_(clock),
tommi0a735642017-03-14 06:23:57 -070042 new_continuous_frame_event_(false, false),
philipelbe7a9e52016-05-19 12:19:35 +020043 jitter_estimator_(jitter_estimator),
44 timing_(timing),
philipel4f6cd6a2016-08-03 10:59:32 +020045 inter_frame_delay_(clock_->TimeInMilliseconds()),
philipele0b2f152016-09-28 10:23:49 +020046 last_decoded_frame_it_(frames_.end()),
47 last_continuous_frame_it_(frames_.end()),
48 num_frames_history_(0),
49 num_frames_buffered_(0),
philipel29f730e2017-03-15 08:10:08 -070050 stopped_(false),
philipela45102f2017-02-22 05:30:39 -080051 protection_mode_(kProtectionNack),
52 stats_callback_(stats_callback) {}
philipel266f0a42016-11-28 08:49:07 -080053
philipela45102f2017-02-22 05:30:39 -080054FrameBuffer::~FrameBuffer() {}
philipelbe7a9e52016-05-19 12:19:35 +020055
philipel75562822016-09-05 10:57:41 +020056FrameBuffer::ReturnReason FrameBuffer::NextFrame(
57 int64_t max_wait_time_ms,
58 std::unique_ptr<FrameObject>* frame_out) {
tommidb23ea62017-03-03 07:21:18 -080059 TRACE_EVENT0("webrtc", "FrameBuffer::NextFrame");
philipel1c056252017-01-31 09:53:12 -080060 int64_t latest_return_time_ms =
61 clock_->TimeInMilliseconds() + max_wait_time_ms;
philipel504c47d2016-06-30 17:33:02 +020062 int64_t wait_ms = max_wait_time_ms;
philipel29f730e2017-03-15 08:10:08 -070063 int64_t now_ms = 0;
philipele0b2f152016-09-28 10:23:49 +020064
65 do {
philipel29f730e2017-03-15 08:10:08 -070066 now_ms = clock_->TimeInMilliseconds();
philipel504c47d2016-06-30 17:33:02 +020067 {
68 rtc::CritScope lock(&crit_);
tommi0a735642017-03-14 06:23:57 -070069 new_continuous_frame_event_.Reset();
philipel29f730e2017-03-15 08:10:08 -070070 if (stopped_)
71 return kStopped;
72
73 wait_ms = max_wait_time_ms;
74
philipele0b2f152016-09-28 10:23:49 +020075 // Need to hold |crit_| in order to use |frames_|, therefore we
76 // set it here in the loop instead of outside the loop in order to not
77 // acquire the lock unnecesserily.
philipel1c056252017-01-31 09:53:12 -080078 next_frame_it_ = frames_.end();
philipelbe7a9e52016-05-19 12:19:35 +020079
philipele0b2f152016-09-28 10:23:49 +020080 // |frame_it| points to the first frame after the
81 // |last_decoded_frame_it_|.
82 auto frame_it = frames_.end();
83 if (last_decoded_frame_it_ == frames_.end()) {
84 frame_it = frames_.begin();
philipelbe7a9e52016-05-19 12:19:35 +020085 } else {
philipele0b2f152016-09-28 10:23:49 +020086 frame_it = last_decoded_frame_it_;
87 ++frame_it;
philipelbe7a9e52016-05-19 12:19:35 +020088 }
philipele0b2f152016-09-28 10:23:49 +020089
90 // |continuous_end_it| points to the first frame after the
91 // |last_continuous_frame_it_|.
92 auto continuous_end_it = last_continuous_frame_it_;
93 if (continuous_end_it != frames_.end())
94 ++continuous_end_it;
95
philipel146a48b2017-04-20 04:04:38 -070096 for (; frame_it != continuous_end_it && frame_it != frames_.end();
97 ++frame_it) {
philipel93e451b2016-10-06 12:25:13 +020098 if (!frame_it->second.continuous ||
99 frame_it->second.num_missing_decodable > 0) {
philipele0b2f152016-09-28 10:23:49 +0200100 continue;
philipel93e451b2016-10-06 12:25:13 +0200101 }
philipele0b2f152016-09-28 10:23:49 +0200102
103 FrameObject* frame = frame_it->second.frame.get();
philipel1c056252017-01-31 09:53:12 -0800104 next_frame_it_ = frame_it;
philipele0b2f152016-09-28 10:23:49 +0200105 if (frame->RenderTime() == -1)
106 frame->SetRenderTime(timing_->RenderTimeMs(frame->timestamp, now_ms));
107 wait_ms = timing_->MaxWaitingTime(frame->RenderTime(), now_ms);
108
109 // This will cause the frame buffer to prefer high framerate rather
110 // than high resolution in the case of the decoder not decoding fast
111 // enough and the stream has multiple spatial and temporal layers.
112 if (wait_ms == 0)
113 continue;
114
115 break;
116 }
117 } // rtc::Critscope lock(&crit_);
118
philipel1c056252017-01-31 09:53:12 -0800119 wait_ms = std::min<int64_t>(wait_ms, latest_return_time_ms - now_ms);
philipele0b2f152016-09-28 10:23:49 +0200120 wait_ms = std::max<int64_t>(wait_ms, 0);
tommi0a735642017-03-14 06:23:57 -0700121 } while (new_continuous_frame_event_.Wait(wait_ms));
philipele0b2f152016-09-28 10:23:49 +0200122
philipel29f730e2017-03-15 08:10:08 -0700123 {
124 rtc::CritScope lock(&crit_);
125 now_ms = clock_->TimeInMilliseconds();
126 if (next_frame_it_ != frames_.end()) {
127 std::unique_ptr<FrameObject> frame =
128 std::move(next_frame_it_->second.frame);
philipele0b2f152016-09-28 10:23:49 +0200129
philipel29f730e2017-03-15 08:10:08 -0700130 if (!frame->delayed_by_retransmission()) {
131 int64_t frame_delay;
philipele0754302017-01-25 08:56:23 -0800132
philipel29f730e2017-03-15 08:10:08 -0700133 if (inter_frame_delay_.CalculateDelay(frame->timestamp, &frame_delay,
134 frame->ReceivedTime())) {
135 jitter_estimator_->UpdateEstimate(frame_delay, frame->size());
136 }
137
138 float rtt_mult = protection_mode_ == kProtectionNackFEC ? 0.0 : 1.0;
139 timing_->SetJitterDelay(jitter_estimator_->GetJitterEstimate(rtt_mult));
140 timing_->UpdateCurrentDelay(frame->RenderTime(), now_ms);
philipele0754302017-01-25 08:56:23 -0800141 }
142
philipel29f730e2017-03-15 08:10:08 -0700143 UpdateJitterDelay();
philipel29f730e2017-03-15 08:10:08 -0700144 PropagateDecodability(next_frame_it_->second);
brandtr9078d8c2017-04-27 07:07:27 -0700145
146 // Sanity check for RTP timestamp monotonicity.
147 if (last_decoded_frame_it_ != frames_.end()) {
148 const FrameKey& last_decoded_frame_key = last_decoded_frame_it_->first;
149 const FrameKey& frame_key = next_frame_it_->first;
150
151 const bool frame_is_higher_spatial_layer_of_last_decoded_frame =
152 last_decoded_frame_timestamp_ == frame->timestamp &&
153 last_decoded_frame_key.picture_id == frame_key.picture_id &&
154 last_decoded_frame_key.spatial_layer < frame_key.spatial_layer;
155
156 if (AheadOrAt(last_decoded_frame_timestamp_, frame->timestamp) &&
157 !frame_is_higher_spatial_layer_of_last_decoded_frame) {
158 // TODO(brandtr): Consider clearing the entire buffer when we hit
159 // these conditions.
160 LOG(LS_WARNING) << "Frame with (timestamp:picture_id:spatial_id) ("
161 << frame->timestamp << ":" << frame->picture_id << ":"
162 << static_cast<int>(frame->spatial_layer) << ")"
163 << " sent to decoder after frame with"
164 << " (timestamp:picture_id:spatial_id) ("
165 << last_decoded_frame_timestamp_ << ":"
166 << last_decoded_frame_key.picture_id << ":"
167 << static_cast<int>(
168 last_decoded_frame_key.spatial_layer)
169 << ").";
170 }
171 }
172
philipel29f730e2017-03-15 08:10:08 -0700173 AdvanceLastDecodedFrame(next_frame_it_);
174 last_decoded_frame_timestamp_ = frame->timestamp;
175 *frame_out = std::move(frame);
176 return kFrameFound;
philipelbe7a9e52016-05-19 12:19:35 +0200177 }
tommi0a735642017-03-14 06:23:57 -0700178 }
179
180 if (latest_return_time_ms - now_ms > 0) {
philipel1c056252017-01-31 09:53:12 -0800181 // If |next_frame_it_ == frames_.end()| and there is still time left, it
182 // means that the frame buffer was cleared as the thread in this function
183 // was waiting to acquire |crit_| in order to return. Wait for the
184 // remaining time and then return.
185 return NextFrame(latest_return_time_ms - now_ms, frame_out);
philipelbe7a9e52016-05-19 12:19:35 +0200186 }
tommi0a735642017-03-14 06:23:57 -0700187
188 return kTimeout;
philipelbe7a9e52016-05-19 12:19:35 +0200189}
190
philipel4f6cd6a2016-08-03 10:59:32 +0200191void FrameBuffer::SetProtectionMode(VCMVideoProtection mode) {
tommidb23ea62017-03-03 07:21:18 -0800192 TRACE_EVENT0("webrtc", "FrameBuffer::SetProtectionMode");
philipel4f6cd6a2016-08-03 10:59:32 +0200193 rtc::CritScope lock(&crit_);
194 protection_mode_ = mode;
195}
196
philipel504c47d2016-06-30 17:33:02 +0200197void FrameBuffer::Start() {
tommidb23ea62017-03-03 07:21:18 -0800198 TRACE_EVENT0("webrtc", "FrameBuffer::Start");
philipel29f730e2017-03-15 08:10:08 -0700199 rtc::CritScope lock(&crit_);
200 stopped_ = false;
philipel504c47d2016-06-30 17:33:02 +0200201}
202
203void FrameBuffer::Stop() {
tommidb23ea62017-03-03 07:21:18 -0800204 TRACE_EVENT0("webrtc", "FrameBuffer::Stop");
philipel29f730e2017-03-15 08:10:08 -0700205 rtc::CritScope lock(&crit_);
206 stopped_ = true;
tommi0a735642017-03-14 06:23:57 -0700207 new_continuous_frame_event_.Set();
philipel504c47d2016-06-30 17:33:02 +0200208}
209
philipele0b2f152016-09-28 10:23:49 +0200210int FrameBuffer::InsertFrame(std::unique_ptr<FrameObject> frame) {
tommidb23ea62017-03-03 07:21:18 -0800211 TRACE_EVENT0("webrtc", "FrameBuffer::InsertFrame");
philipel93e451b2016-10-06 12:25:13 +0200212 RTC_DCHECK(frame);
philipela45102f2017-02-22 05:30:39 -0800213 if (stats_callback_)
214 stats_callback_->OnCompleteFrame(frame->num_references == 0, frame->size());
philipelbe7a9e52016-05-19 12:19:35 +0200215 FrameKey key(frame->picture_id, frame->spatial_layer);
tommi0a735642017-03-14 06:23:57 -0700216
217 rtc::CritScope lock(&crit_);
philipel29f730e2017-03-15 08:10:08 -0700218
philipele0b2f152016-09-28 10:23:49 +0200219 int last_continuous_picture_id =
220 last_continuous_frame_it_ == frames_.end()
221 ? -1
222 : last_continuous_frame_it_->first.picture_id;
223
224 if (num_frames_buffered_ >= kMaxFramesBuffered) {
225 LOG(LS_WARNING) << "Frame with (picture_id:spatial_id) (" << key.picture_id
226 << ":" << static_cast<int>(key.spatial_layer)
227 << ") could not be inserted due to the frame "
228 << "buffer being full, dropping frame.";
229 return last_continuous_picture_id;
230 }
231
232 if (frame->inter_layer_predicted && frame->spatial_layer == 0) {
233 LOG(LS_WARNING) << "Frame with (picture_id:spatial_id) (" << key.picture_id
234 << ":" << static_cast<int>(key.spatial_layer)
235 << ") is marked as inter layer predicted, dropping frame.";
236 return last_continuous_picture_id;
237 }
238
239 if (last_decoded_frame_it_ != frames_.end() &&
240 key < last_decoded_frame_it_->first) {
philipelfcc60062017-01-18 05:35:20 -0800241 if (AheadOf(frame->timestamp, last_decoded_frame_timestamp_) &&
242 frame->num_references == 0) {
243 // If this frame has a newer timestamp but an earlier picture id then we
244 // assume there has been a jump in the picture id due to some encoder
245 // reconfiguration or some other reason. Even though this is not according
246 // to spec we can still continue to decode from this frame if it is a
247 // keyframe.
248 LOG(LS_WARNING) << "A jump in picture id was detected, clearing buffer.";
249 ClearFramesAndHistory();
250 last_continuous_picture_id = -1;
251 } else {
252 LOG(LS_WARNING) << "Frame with (picture_id:spatial_id) ("
253 << key.picture_id << ":"
254 << static_cast<int>(key.spatial_layer)
255 << ") inserted after frame ("
256 << last_decoded_frame_it_->first.picture_id << ":"
257 << static_cast<int>(
258 last_decoded_frame_it_->first.spatial_layer)
259 << ") was handed off for decoding, dropping frame.";
260 return last_continuous_picture_id;
261 }
philipele0b2f152016-09-28 10:23:49 +0200262 }
263
philipel146a48b2017-04-20 04:04:38 -0700264 // Test if inserting this frame would cause the order of the frames to become
265 // ambiguous (covering more than half the interval of 2^16). This can happen
266 // when the picture id make large jumps mid stream.
267 if (!frames_.empty() &&
268 key < frames_.begin()->first &&
269 frames_.rbegin()->first < key) {
270 LOG(LS_WARNING) << "A jump in picture id was detected, clearing buffer.";
271 ClearFramesAndHistory();
272 last_continuous_picture_id = -1;
273 }
274
philipele0b2f152016-09-28 10:23:49 +0200275 auto info = frames_.insert(std::make_pair(key, FrameInfo())).first;
276
philipel93e451b2016-10-06 12:25:13 +0200277 if (info->second.frame) {
278 LOG(LS_WARNING) << "Frame with (picture_id:spatial_id) (" << key.picture_id
279 << ":" << static_cast<int>(key.spatial_layer)
280 << ") already inserted, dropping frame.";
philipele0b2f152016-09-28 10:23:49 +0200281 return last_continuous_picture_id;
282 }
283
philipel93e451b2016-10-06 12:25:13 +0200284 if (!UpdateFrameInfoWithIncomingFrame(*frame, info))
285 return last_continuous_picture_id;
286
philipele0b2f152016-09-28 10:23:49 +0200287 info->second.frame = std::move(frame);
288 ++num_frames_buffered_;
289
290 if (info->second.num_missing_continuous == 0) {
291 info->second.continuous = true;
292 PropagateContinuity(info);
293 last_continuous_picture_id = last_continuous_frame_it_->first.picture_id;
294
295 // Since we now have new continuous frames there might be a better frame
296 // to return from NextFrame. Signal that thread so that it again can choose
297 // which frame to return.
tommi0a735642017-03-14 06:23:57 -0700298 new_continuous_frame_event_.Set();
philipele0b2f152016-09-28 10:23:49 +0200299 }
300
301 return last_continuous_picture_id;
philipelbe7a9e52016-05-19 12:19:35 +0200302}
303
philipele0b2f152016-09-28 10:23:49 +0200304void FrameBuffer::PropagateContinuity(FrameMap::iterator start) {
tommidb23ea62017-03-03 07:21:18 -0800305 TRACE_EVENT0("webrtc", "FrameBuffer::PropagateContinuity");
philipele0b2f152016-09-28 10:23:49 +0200306 RTC_DCHECK(start->second.continuous);
307 if (last_continuous_frame_it_ == frames_.end())
308 last_continuous_frame_it_ = start;
309
310 std::queue<FrameMap::iterator> continuous_frames;
311 continuous_frames.push(start);
312
313 // A simple BFS to traverse continuous frames.
314 while (!continuous_frames.empty()) {
315 auto frame = continuous_frames.front();
316 continuous_frames.pop();
317
318 if (last_continuous_frame_it_->first < frame->first)
319 last_continuous_frame_it_ = frame;
320
321 // Loop through all dependent frames, and if that frame no longer has
322 // any unfulfilled dependencies then that frame is continuous as well.
323 for (size_t d = 0; d < frame->second.num_dependent_frames; ++d) {
324 auto frame_ref = frames_.find(frame->second.dependent_frames[d]);
325 --frame_ref->second.num_missing_continuous;
326
327 if (frame_ref->second.num_missing_continuous == 0) {
328 frame_ref->second.continuous = true;
329 continuous_frames.push(frame_ref);
330 }
331 }
332 }
333}
334
335void FrameBuffer::PropagateDecodability(const FrameInfo& info) {
tommidb23ea62017-03-03 07:21:18 -0800336 TRACE_EVENT0("webrtc", "FrameBuffer::PropagateDecodability");
philipele0b2f152016-09-28 10:23:49 +0200337 for (size_t d = 0; d < info.num_dependent_frames; ++d) {
338 auto ref_info = frames_.find(info.dependent_frames[d]);
philipel93e451b2016-10-06 12:25:13 +0200339 RTC_DCHECK(ref_info != frames_.end());
philipele0b2f152016-09-28 10:23:49 +0200340 RTC_DCHECK_GT(ref_info->second.num_missing_decodable, 0U);
341 --ref_info->second.num_missing_decodable;
342 }
343}
344
345void FrameBuffer::AdvanceLastDecodedFrame(FrameMap::iterator decoded) {
tommidb23ea62017-03-03 07:21:18 -0800346 TRACE_EVENT0("webrtc", "FrameBuffer::AdvanceLastDecodedFrame");
philipele0b2f152016-09-28 10:23:49 +0200347 if (last_decoded_frame_it_ == frames_.end()) {
348 last_decoded_frame_it_ = frames_.begin();
349 } else {
350 RTC_DCHECK(last_decoded_frame_it_->first < decoded->first);
351 ++last_decoded_frame_it_;
352 }
353 --num_frames_buffered_;
354 ++num_frames_history_;
355
356 // First, delete non-decoded frames from the history.
357 while (last_decoded_frame_it_ != decoded) {
358 if (last_decoded_frame_it_->second.frame)
359 --num_frames_buffered_;
360 last_decoded_frame_it_ = frames_.erase(last_decoded_frame_it_);
philipelbe7a9e52016-05-19 12:19:35 +0200361 }
362
philipele0b2f152016-09-28 10:23:49 +0200363 // Then remove old history if we have too much history saved.
364 if (num_frames_history_ > kMaxFramesHistory) {
365 frames_.erase(frames_.begin());
366 --num_frames_history_;
367 }
368}
369
370bool FrameBuffer::UpdateFrameInfoWithIncomingFrame(const FrameObject& frame,
371 FrameMap::iterator info) {
tommidb23ea62017-03-03 07:21:18 -0800372 TRACE_EVENT0("webrtc", "FrameBuffer::UpdateFrameInfoWithIncomingFrame");
philipele0b2f152016-09-28 10:23:49 +0200373 FrameKey key(frame.picture_id, frame.spatial_layer);
374 info->second.num_missing_continuous = frame.num_references;
375 info->second.num_missing_decodable = frame.num_references;
376
377 RTC_DCHECK(last_decoded_frame_it_ == frames_.end() ||
378 last_decoded_frame_it_->first < info->first);
379
380 // Check how many dependencies that have already been fulfilled.
381 for (size_t i = 0; i < frame.num_references; ++i) {
382 FrameKey ref_key(frame.references[i], frame.spatial_layer);
383 auto ref_info = frames_.find(ref_key);
384
385 // Does |frame| depend on a frame earlier than the last decoded frame?
386 if (last_decoded_frame_it_ != frames_.end() &&
387 ref_key <= last_decoded_frame_it_->first) {
388 if (ref_info == frames_.end()) {
389 LOG(LS_WARNING) << "Frame with (picture_id:spatial_id) ("
390 << key.picture_id << ":"
391 << static_cast<int>(key.spatial_layer)
392 << " depends on a non-decoded frame more previous than "
393 << "the last decoded frame, dropping frame.";
394 return false;
395 }
396
397 --info->second.num_missing_continuous;
398 --info->second.num_missing_decodable;
399 } else {
400 if (ref_info == frames_.end())
401 ref_info = frames_.insert(std::make_pair(ref_key, FrameInfo())).first;
402
403 if (ref_info->second.continuous)
404 --info->second.num_missing_continuous;
405
406 // Add backwards reference so |frame| can be updated when new
407 // frames are inserted or decoded.
408 ref_info->second.dependent_frames[ref_info->second.num_dependent_frames] =
409 key;
410 ++ref_info->second.num_dependent_frames;
411 }
philipel93e451b2016-10-06 12:25:13 +0200412 RTC_DCHECK_LE(ref_info->second.num_missing_continuous,
413 ref_info->second.num_missing_decodable);
philipelbe7a9e52016-05-19 12:19:35 +0200414 }
415
philipele0b2f152016-09-28 10:23:49 +0200416 // Check if we have the lower spatial layer frame.
philipelbe7a9e52016-05-19 12:19:35 +0200417 if (frame.inter_layer_predicted) {
philipele0b2f152016-09-28 10:23:49 +0200418 ++info->second.num_missing_continuous;
419 ++info->second.num_missing_decodable;
420
philipelbe7a9e52016-05-19 12:19:35 +0200421 FrameKey ref_key(frame.picture_id, frame.spatial_layer - 1);
philipele0b2f152016-09-28 10:23:49 +0200422 // Gets or create the FrameInfo for the referenced frame.
423 auto ref_info = frames_.insert(std::make_pair(ref_key, FrameInfo())).first;
424 if (ref_info->second.continuous)
425 --info->second.num_missing_continuous;
426
427 if (ref_info == last_decoded_frame_it_) {
428 --info->second.num_missing_decodable;
429 } else {
430 ref_info->second.dependent_frames[ref_info->second.num_dependent_frames] =
431 key;
432 ++ref_info->second.num_dependent_frames;
433 }
philipel93e451b2016-10-06 12:25:13 +0200434 RTC_DCHECK_LE(ref_info->second.num_missing_continuous,
435 ref_info->second.num_missing_decodable);
philipelbe7a9e52016-05-19 12:19:35 +0200436 }
437
philipel93e451b2016-10-06 12:25:13 +0200438 RTC_DCHECK_LE(info->second.num_missing_continuous,
439 info->second.num_missing_decodable);
440
philipelbe7a9e52016-05-19 12:19:35 +0200441 return true;
442}
443
philipelbe742702016-11-30 01:31:40 -0800444void FrameBuffer::UpdateJitterDelay() {
tommidb23ea62017-03-03 07:21:18 -0800445 TRACE_EVENT0("webrtc", "FrameBuffer::UpdateJitterDelay");
philipela45102f2017-02-22 05:30:39 -0800446 if (!stats_callback_)
447 return;
philipelbe742702016-11-30 01:31:40 -0800448
philipela45102f2017-02-22 05:30:39 -0800449 int decode_ms;
450 int max_decode_ms;
451 int current_delay_ms;
452 int target_delay_ms;
453 int jitter_buffer_ms;
454 int min_playout_delay_ms;
455 int render_delay_ms;
456 if (timing_->GetTimings(&decode_ms, &max_decode_ms, &current_delay_ms,
457 &target_delay_ms, &jitter_buffer_ms,
458 &min_playout_delay_ms, &render_delay_ms)) {
459 stats_callback_->OnFrameBufferTimingsUpdated(
460 decode_ms, max_decode_ms, current_delay_ms, target_delay_ms,
461 jitter_buffer_ms, min_playout_delay_ms, render_delay_ms);
philipelbe742702016-11-30 01:31:40 -0800462 }
philipel266f0a42016-11-28 08:49:07 -0800463}
464
philipelfcc60062017-01-18 05:35:20 -0800465void FrameBuffer::ClearFramesAndHistory() {
tommidb23ea62017-03-03 07:21:18 -0800466 TRACE_EVENT0("webrtc", "FrameBuffer::UpdateJitterDelay");
philipelfcc60062017-01-18 05:35:20 -0800467 frames_.clear();
468 last_decoded_frame_it_ = frames_.end();
469 last_continuous_frame_it_ = frames_.end();
philipel1c056252017-01-31 09:53:12 -0800470 next_frame_it_ = frames_.end();
philipelfcc60062017-01-18 05:35:20 -0800471 num_frames_history_ = 0;
472 num_frames_buffered_ = 0;
473}
474
philipelbe7a9e52016-05-19 12:19:35 +0200475} // namespace video_coding
476} // namespace webrtc