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

Side by Side Diff: webrtc/video/video_receive_stream.cc

Issue 2996823002: Reland of quest keyframes more frequently on stream start/decoding error. (Closed)
Patch Set: Fix Created 3 years, 4 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) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 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 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 } 484 }
485 485
486 void VideoReceiveStream::DecodeThreadFunction(void* ptr) { 486 void VideoReceiveStream::DecodeThreadFunction(void* ptr) {
487 while (static_cast<VideoReceiveStream*>(ptr)->Decode()) { 487 while (static_cast<VideoReceiveStream*>(ptr)->Decode()) {
488 } 488 }
489 } 489 }
490 490
491 bool VideoReceiveStream::Decode() { 491 bool VideoReceiveStream::Decode() {
492 TRACE_EVENT0("webrtc", "VideoReceiveStream::Decode"); 492 TRACE_EVENT0("webrtc", "VideoReceiveStream::Decode");
493 static const int kMaxWaitForFrameMs = 3000; 493 static const int kMaxWaitForFrameMs = 3000;
494 static const int kMaxWaitForKeyFrameMs = 200;
495
496 int wait_ms = keyframe_required_ ? kMaxWaitForKeyFrameMs : kMaxWaitForFrameMs;
494 std::unique_ptr<video_coding::FrameObject> frame; 497 std::unique_ptr<video_coding::FrameObject> frame;
498 // TODO(philipel): Call NextFrame with |keyframe_required| argument when
499 // downstream project has been fixed.
495 video_coding::FrameBuffer::ReturnReason res = 500 video_coding::FrameBuffer::ReturnReason res =
496 frame_buffer_->NextFrame(kMaxWaitForFrameMs, &frame); 501 frame_buffer_->NextFrame(wait_ms, &frame);
497 502
498 if (res == video_coding::FrameBuffer::ReturnReason::kStopped) { 503 if (res == video_coding::FrameBuffer::ReturnReason::kStopped) {
499 video_receiver_.DecodingStopped(); 504 video_receiver_.DecodingStopped();
500 return false; 505 return false;
501 } 506 }
502 507
503 if (frame) { 508 if (frame) {
504 RTC_DCHECK_EQ(res, video_coding::FrameBuffer::ReturnReason::kFrameFound); 509 RTC_DCHECK_EQ(res, video_coding::FrameBuffer::ReturnReason::kFrameFound);
505 if (video_receiver_.Decode(frame.get()) == VCM_OK) 510 if (video_receiver_.Decode(frame.get()) == VCM_OK) {
511 keyframe_required_ = false;
506 rtp_video_stream_receiver_.FrameDecoded(frame->picture_id); 512 rtp_video_stream_receiver_.FrameDecoded(frame->picture_id);
513 } else if (keyframe_required_ == false) {
stefan-webrtc 2017/08/11 09:27:59 !keyframe_required_
514 keyframe_required_ = true;
515 // TODO(philipel): Remove this keyframe request when downstream project
516 // has been fixed.
517 RequestKeyFrame();
518 }
507 } else { 519 } else {
508 RTC_DCHECK_EQ(res, video_coding::FrameBuffer::ReturnReason::kTimeout); 520 RTC_DCHECK_EQ(res, video_coding::FrameBuffer::ReturnReason::kTimeout);
509 int64_t now_ms = clock_->TimeInMilliseconds(); 521 int64_t now_ms = clock_->TimeInMilliseconds();
510 rtc::Optional<int64_t> last_packet_ms = 522 rtc::Optional<int64_t> last_packet_ms =
511 rtp_video_stream_receiver_.LastReceivedPacketMs(); 523 rtp_video_stream_receiver_.LastReceivedPacketMs();
512 rtc::Optional<int64_t> last_keyframe_packet_ms = 524 rtc::Optional<int64_t> last_keyframe_packet_ms =
513 rtp_video_stream_receiver_.LastReceivedKeyframePacketMs(); 525 rtp_video_stream_receiver_.LastReceivedKeyframePacketMs();
514 526
515 // To avoid spamming keyframe requests for a stream that is not active we 527 // To avoid spamming keyframe requests for a stream that is not active we
516 // check if we have received a packet within the last 5 seconds. 528 // check if we have received a packet within the last 5 seconds.
517 bool stream_is_active = last_packet_ms && now_ms - *last_packet_ms < 5000; 529 bool stream_is_active = last_packet_ms && now_ms - *last_packet_ms < 5000;
518 530
519 // If we recently (within |kMaxWaitForFrameMs|) have been receiving packets 531 // If we recently have been receiving packets belonging to a keyframe then
520 // belonging to a keyframe then we assume a keyframe is being received right 532 // we assume a keyframe is currently being received.
521 // now.
522 bool receiving_keyframe = 533 bool receiving_keyframe =
523 last_keyframe_packet_ms && 534 last_keyframe_packet_ms &&
524 now_ms - *last_keyframe_packet_ms < kMaxWaitForFrameMs; 535 now_ms - *last_keyframe_packet_ms < kMaxWaitForKeyFrameMs;
525 536
526 if (stream_is_active && !receiving_keyframe) { 537 if (stream_is_active && !receiving_keyframe) {
527 LOG(LS_WARNING) << "No decodable frame in " << kMaxWaitForFrameMs 538 LOG(LS_WARNING) << "No decodable frame in " << wait_ms
528 << " ms, requesting keyframe."; 539 << " ms, requesting keyframe.";
529 RequestKeyFrame(); 540 RequestKeyFrame();
530 } 541 }
531 } 542 }
532 return true; 543 return true;
533 } 544 }
534 } // namespace internal 545 } // namespace internal
535 } // namespace webrtc 546 } // namespace webrtc
OLDNEW
« webrtc/modules/video_coding/video_receiver.cc ('K') | « webrtc/video/video_receive_stream.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698