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

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

Issue 2937243002: Validate references of frames inserted into FrameBuffer2. (Closed)
Patch Set: to --> too Created 3 years, 6 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) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 stopped_ = false; 231 stopped_ = false;
232 } 232 }
233 233
234 void FrameBuffer::Stop() { 234 void FrameBuffer::Stop() {
235 TRACE_EVENT0("webrtc", "FrameBuffer::Stop"); 235 TRACE_EVENT0("webrtc", "FrameBuffer::Stop");
236 rtc::CritScope lock(&crit_); 236 rtc::CritScope lock(&crit_);
237 stopped_ = true; 237 stopped_ = true;
238 new_continuous_frame_event_.Set(); 238 new_continuous_frame_event_.Set();
239 } 239 }
240 240
241 bool FrameBuffer::ValidReferences(const FrameObject& frame) const {
242 for (size_t i = 0; i < frame.num_references; ++i) {
243 if (AheadOrAt(frame.references[i], frame.picture_id))
244 return false;
245 for (size_t j = i + 1; j < frame.num_references; ++j) {
246 if (frame.references[i] == frame.references[j])
247 return false;
248 }
249 }
250
251 if (frame.inter_layer_predicted && frame.spatial_layer == 0)
252 return false;
253
254 return true;
255 }
256
241 void FrameBuffer::UpdatePlayoutDelays(const FrameObject& frame) { 257 void FrameBuffer::UpdatePlayoutDelays(const FrameObject& frame) {
242 TRACE_EVENT0("webrtc", "FrameBuffer::UpdatePlayoutDelays"); 258 TRACE_EVENT0("webrtc", "FrameBuffer::UpdatePlayoutDelays");
243 PlayoutDelay playout_delay = frame.EncodedImage().playout_delay_; 259 PlayoutDelay playout_delay = frame.EncodedImage().playout_delay_;
244 if (playout_delay.min_ms >= 0) 260 if (playout_delay.min_ms >= 0)
245 timing_->set_min_playout_delay(playout_delay.min_ms); 261 timing_->set_min_playout_delay(playout_delay.min_ms);
246 262
247 if (playout_delay.max_ms >= 0) 263 if (playout_delay.max_ms >= 0)
248 timing_->set_max_playout_delay(playout_delay.max_ms); 264 timing_->set_max_playout_delay(playout_delay.max_ms);
249 } 265 }
250 266
251 int FrameBuffer::InsertFrame(std::unique_ptr<FrameObject> frame) { 267 int FrameBuffer::InsertFrame(std::unique_ptr<FrameObject> frame) {
252 TRACE_EVENT0("webrtc", "FrameBuffer::InsertFrame"); 268 TRACE_EVENT0("webrtc", "FrameBuffer::InsertFrame");
253 RTC_DCHECK(frame); 269 RTC_DCHECK(frame);
254 if (stats_callback_) 270 if (stats_callback_)
255 stats_callback_->OnCompleteFrame(frame->num_references == 0, frame->size()); 271 stats_callback_->OnCompleteFrame(frame->num_references == 0, frame->size());
256 FrameKey key(frame->picture_id, frame->spatial_layer); 272 FrameKey key(frame->picture_id, frame->spatial_layer);
257 273
258 rtc::CritScope lock(&crit_); 274 rtc::CritScope lock(&crit_);
259 275
260 int last_continuous_picture_id = 276 int last_continuous_picture_id =
261 last_continuous_frame_it_ == frames_.end() 277 last_continuous_frame_it_ == frames_.end()
262 ? -1 278 ? -1
263 : last_continuous_frame_it_->first.picture_id; 279 : last_continuous_frame_it_->first.picture_id;
264 280
281 if (!ValidReferences(*frame)) {
282 LOG(LS_WARNING) << "Frame with (picture_id:spatial_id) (" << key.picture_id
283 << ":" << static_cast<int>(key.spatial_layer)
284 << ") has invalid frame references, dropping frame.";
285 return last_continuous_picture_id;
286 }
287
265 if (num_frames_buffered_ >= kMaxFramesBuffered) { 288 if (num_frames_buffered_ >= kMaxFramesBuffered) {
266 LOG(LS_WARNING) << "Frame with (picture_id:spatial_id) (" << key.picture_id 289 LOG(LS_WARNING) << "Frame with (picture_id:spatial_id) (" << key.picture_id
267 << ":" << static_cast<int>(key.spatial_layer) 290 << ":" << static_cast<int>(key.spatial_layer)
268 << ") could not be inserted due to the frame " 291 << ") could not be inserted due to the frame "
269 << "buffer being full, dropping frame."; 292 << "buffer being full, dropping frame.";
270 return last_continuous_picture_id; 293 return last_continuous_picture_id;
271 } 294 }
272 295
273 if (frame->inter_layer_predicted && frame->spatial_layer == 0) {
274 LOG(LS_WARNING) << "Frame with (picture_id:spatial_id) (" << key.picture_id
275 << ":" << static_cast<int>(key.spatial_layer)
276 << ") is marked as inter layer predicted, dropping frame.";
277 return last_continuous_picture_id;
278 }
279
280 if (last_decoded_frame_it_ != frames_.end() && 296 if (last_decoded_frame_it_ != frames_.end() &&
281 key <= last_decoded_frame_it_->first) { 297 key <= last_decoded_frame_it_->first) {
282 if (AheadOf(frame->timestamp, last_decoded_frame_timestamp_) && 298 if (AheadOf(frame->timestamp, last_decoded_frame_timestamp_) &&
283 frame->num_references == 0) { 299 frame->num_references == 0) {
284 // If this frame has a newer timestamp but an earlier picture id then we 300 // If this frame has a newer timestamp but an earlier picture id then we
285 // assume there has been a jump in the picture id due to some encoder 301 // assume there has been a jump in the picture id due to some encoder
286 // reconfiguration or some other reason. Even though this is not according 302 // reconfiguration or some other reason. Even though this is not according
287 // to spec we can still continue to decode from this frame if it is a 303 // to spec we can still continue to decode from this frame if it is a
288 // keyframe. 304 // keyframe.
289 LOG(LS_WARNING) << "A jump in picture id was detected, clearing buffer."; 305 LOG(LS_WARNING) << "A jump in picture id was detected, clearing buffer.";
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 auto frame = continuous_frames.front(); 372 auto frame = continuous_frames.front();
357 continuous_frames.pop(); 373 continuous_frames.pop();
358 374
359 if (last_continuous_frame_it_->first < frame->first) 375 if (last_continuous_frame_it_->first < frame->first)
360 last_continuous_frame_it_ = frame; 376 last_continuous_frame_it_ = frame;
361 377
362 // Loop through all dependent frames, and if that frame no longer has 378 // Loop through all dependent frames, and if that frame no longer has
363 // any unfulfilled dependencies then that frame is continuous as well. 379 // any unfulfilled dependencies then that frame is continuous as well.
364 for (size_t d = 0; d < frame->second.num_dependent_frames; ++d) { 380 for (size_t d = 0; d < frame->second.num_dependent_frames; ++d) {
365 auto frame_ref = frames_.find(frame->second.dependent_frames[d]); 381 auto frame_ref = frames_.find(frame->second.dependent_frames[d]);
366 --frame_ref->second.num_missing_continuous; 382 RTC_DCHECK(frame_ref != frames_.end());
367 383
368 if (frame_ref->second.num_missing_continuous == 0) { 384 // TODO(philipel): Look into why we've seen this happen.
369 frame_ref->second.continuous = true; 385 if (frame_ref != frames_.end()) {
370 continuous_frames.push(frame_ref); 386 --frame_ref->second.num_missing_continuous;
387 if (frame_ref->second.num_missing_continuous == 0) {
388 frame_ref->second.continuous = true;
389 continuous_frames.push(frame_ref);
390 }
371 } 391 }
372 } 392 }
373 } 393 }
374 } 394 }
375 395
376 void FrameBuffer::PropagateDecodability(const FrameInfo& info) { 396 void FrameBuffer::PropagateDecodability(const FrameInfo& info) {
377 TRACE_EVENT0("webrtc", "FrameBuffer::PropagateDecodability"); 397 TRACE_EVENT0("webrtc", "FrameBuffer::PropagateDecodability");
378 RTC_CHECK(info.num_dependent_frames < FrameInfo::kMaxNumDependentFrames); 398 RTC_CHECK(info.num_dependent_frames < FrameInfo::kMaxNumDependentFrames);
379 for (size_t d = 0; d < info.num_dependent_frames; ++d) { 399 for (size_t d = 0; d < info.num_dependent_frames; ++d) {
380 auto ref_info = frames_.find(info.dependent_frames[d]); 400 auto ref_info = frames_.find(info.dependent_frames[d]);
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 frames_.clear(); 539 frames_.clear();
520 last_decoded_frame_it_ = frames_.end(); 540 last_decoded_frame_it_ = frames_.end();
521 last_continuous_frame_it_ = frames_.end(); 541 last_continuous_frame_it_ = frames_.end();
522 next_frame_it_ = frames_.end(); 542 next_frame_it_ = frames_.end();
523 num_frames_history_ = 0; 543 num_frames_history_ = 0;
524 num_frames_buffered_ = 0; 544 num_frames_buffered_ = 0;
525 } 545 }
526 546
527 } // namespace video_coding 547 } // namespace video_coding
528 } // namespace webrtc 548 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/video_coding/frame_buffer2.h ('k') | webrtc/modules/video_coding/frame_buffer2_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698