| OLD | NEW |
| 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 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 } | 490 } |
| 491 | 491 |
| 492 void VideoReceiveStream::DecodeThreadFunction(void* ptr) { | 492 void VideoReceiveStream::DecodeThreadFunction(void* ptr) { |
| 493 while (static_cast<VideoReceiveStream*>(ptr)->Decode()) { | 493 while (static_cast<VideoReceiveStream*>(ptr)->Decode()) { |
| 494 } | 494 } |
| 495 } | 495 } |
| 496 | 496 |
| 497 bool VideoReceiveStream::Decode() { | 497 bool VideoReceiveStream::Decode() { |
| 498 TRACE_EVENT0("webrtc", "VideoReceiveStream::Decode"); | 498 TRACE_EVENT0("webrtc", "VideoReceiveStream::Decode"); |
| 499 static const int kMaxWaitForFrameMs = 3000; | 499 static const int kMaxWaitForFrameMs = 3000; |
| 500 static const int kMaxWaitForKeyFrameMs = 200; |
| 501 |
| 502 int wait_ms = keyframe_required_ ? kMaxWaitForKeyFrameMs : kMaxWaitForFrameMs; |
| 500 std::unique_ptr<video_coding::FrameObject> frame; | 503 std::unique_ptr<video_coding::FrameObject> frame; |
| 504 // TODO(philipel): Call NextFrame with |keyframe_required| argument when |
| 505 // downstream project has been fixed. |
| 501 video_coding::FrameBuffer::ReturnReason res = | 506 video_coding::FrameBuffer::ReturnReason res = |
| 502 frame_buffer_->NextFrame(kMaxWaitForFrameMs, &frame); | 507 frame_buffer_->NextFrame(wait_ms, &frame); |
| 503 | 508 |
| 504 if (res == video_coding::FrameBuffer::ReturnReason::kStopped) { | 509 if (res == video_coding::FrameBuffer::ReturnReason::kStopped) { |
| 505 video_receiver_.DecodingStopped(); | 510 video_receiver_.DecodingStopped(); |
| 506 return false; | 511 return false; |
| 507 } | 512 } |
| 508 | 513 |
| 509 if (frame) { | 514 if (frame) { |
| 510 RTC_DCHECK_EQ(res, video_coding::FrameBuffer::ReturnReason::kFrameFound); | 515 RTC_DCHECK_EQ(res, video_coding::FrameBuffer::ReturnReason::kFrameFound); |
| 511 if (video_receiver_.Decode(frame.get()) == VCM_OK) | 516 if (video_receiver_.Decode(frame.get()) == VCM_OK) { |
| 517 keyframe_required_ = false; |
| 518 frame_decoded_ = true; |
| 512 rtp_video_stream_receiver_.FrameDecoded(frame->picture_id); | 519 rtp_video_stream_receiver_.FrameDecoded(frame->picture_id); |
| 520 } else if (!keyframe_required_ || !frame_decoded_) { |
| 521 keyframe_required_ = true; |
| 522 // TODO(philipel): Remove this keyframe request when downstream project |
| 523 // has been fixed. |
| 524 RequestKeyFrame(); |
| 525 } |
| 513 } else { | 526 } else { |
| 514 RTC_DCHECK_EQ(res, video_coding::FrameBuffer::ReturnReason::kTimeout); | 527 RTC_DCHECK_EQ(res, video_coding::FrameBuffer::ReturnReason::kTimeout); |
| 515 int64_t now_ms = clock_->TimeInMilliseconds(); | 528 int64_t now_ms = clock_->TimeInMilliseconds(); |
| 516 rtc::Optional<int64_t> last_packet_ms = | 529 rtc::Optional<int64_t> last_packet_ms = |
| 517 rtp_video_stream_receiver_.LastReceivedPacketMs(); | 530 rtp_video_stream_receiver_.LastReceivedPacketMs(); |
| 518 rtc::Optional<int64_t> last_keyframe_packet_ms = | 531 rtc::Optional<int64_t> last_keyframe_packet_ms = |
| 519 rtp_video_stream_receiver_.LastReceivedKeyframePacketMs(); | 532 rtp_video_stream_receiver_.LastReceivedKeyframePacketMs(); |
| 520 | 533 |
| 521 // To avoid spamming keyframe requests for a stream that is not active we | 534 // To avoid spamming keyframe requests for a stream that is not active we |
| 522 // check if we have received a packet within the last 5 seconds. | 535 // check if we have received a packet within the last 5 seconds. |
| 523 bool stream_is_active = last_packet_ms && now_ms - *last_packet_ms < 5000; | 536 bool stream_is_active = last_packet_ms && now_ms - *last_packet_ms < 5000; |
| 524 | 537 |
| 525 // If we recently (within |kMaxWaitForFrameMs|) have been receiving packets | 538 // If we recently have been receiving packets belonging to a keyframe then |
| 526 // belonging to a keyframe then we assume a keyframe is being received right | 539 // we assume a keyframe is currently being received. |
| 527 // now. | |
| 528 bool receiving_keyframe = | 540 bool receiving_keyframe = |
| 529 last_keyframe_packet_ms && | 541 last_keyframe_packet_ms && |
| 530 now_ms - *last_keyframe_packet_ms < kMaxWaitForFrameMs; | 542 now_ms - *last_keyframe_packet_ms < kMaxWaitForKeyFrameMs; |
| 531 | 543 |
| 532 if (stream_is_active && !receiving_keyframe) { | 544 if (stream_is_active && !receiving_keyframe) { |
| 533 LOG(LS_WARNING) << "No decodable frame in " << kMaxWaitForFrameMs | 545 LOG(LS_WARNING) << "No decodable frame in " << wait_ms |
| 534 << " ms, requesting keyframe."; | 546 << " ms, requesting keyframe."; |
| 535 RequestKeyFrame(); | 547 RequestKeyFrame(); |
| 536 } | 548 } |
| 537 } | 549 } |
| 538 return true; | 550 return true; |
| 539 } | 551 } |
| 540 } // namespace internal | 552 } // namespace internal |
| 541 } // namespace webrtc | 553 } // namespace webrtc |
| OLD | NEW |