| 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 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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; | |
| 497 std::unique_ptr<video_coding::FrameObject> frame; | 494 std::unique_ptr<video_coding::FrameObject> frame; |
| 498 video_coding::FrameBuffer::ReturnReason res = | 495 video_coding::FrameBuffer::ReturnReason res = |
| 499 frame_buffer_->NextFrame(wait_ms, &frame, keyframe_required_); | 496 frame_buffer_->NextFrame(kMaxWaitForFrameMs, &frame); |
| 500 | 497 |
| 501 if (res == video_coding::FrameBuffer::ReturnReason::kStopped) { | 498 if (res == video_coding::FrameBuffer::ReturnReason::kStopped) { |
| 502 video_receiver_.DecodingStopped(); | 499 video_receiver_.DecodingStopped(); |
| 503 return false; | 500 return false; |
| 504 } | 501 } |
| 505 | 502 |
| 506 if (frame) { | 503 if (frame) { |
| 507 RTC_DCHECK_EQ(res, video_coding::FrameBuffer::ReturnReason::kFrameFound); | 504 RTC_DCHECK_EQ(res, video_coding::FrameBuffer::ReturnReason::kFrameFound); |
| 508 if (video_receiver_.Decode(frame.get()) == VCM_OK) { | 505 if (video_receiver_.Decode(frame.get()) == VCM_OK) |
| 509 keyframe_required_ = false; | |
| 510 rtp_video_stream_receiver_.FrameDecoded(frame->picture_id); | 506 rtp_video_stream_receiver_.FrameDecoded(frame->picture_id); |
| 511 } else { | |
| 512 keyframe_required_ = true; | |
| 513 } | |
| 514 } else { | 507 } else { |
| 515 RTC_DCHECK_EQ(res, video_coding::FrameBuffer::ReturnReason::kTimeout); | 508 RTC_DCHECK_EQ(res, video_coding::FrameBuffer::ReturnReason::kTimeout); |
| 516 int64_t now_ms = clock_->TimeInMilliseconds(); | 509 int64_t now_ms = clock_->TimeInMilliseconds(); |
| 517 rtc::Optional<int64_t> last_packet_ms = | 510 rtc::Optional<int64_t> last_packet_ms = |
| 518 rtp_video_stream_receiver_.LastReceivedPacketMs(); | 511 rtp_video_stream_receiver_.LastReceivedPacketMs(); |
| 519 rtc::Optional<int64_t> last_keyframe_packet_ms = | 512 rtc::Optional<int64_t> last_keyframe_packet_ms = |
| 520 rtp_video_stream_receiver_.LastReceivedKeyframePacketMs(); | 513 rtp_video_stream_receiver_.LastReceivedKeyframePacketMs(); |
| 521 | 514 |
| 522 // To avoid spamming keyframe requests for a stream that is not active we | 515 // To avoid spamming keyframe requests for a stream that is not active we |
| 523 // check if we have received a packet within the last 5 seconds. | 516 // check if we have received a packet within the last 5 seconds. |
| 524 bool stream_is_active = last_packet_ms && now_ms - *last_packet_ms < 5000; | 517 bool stream_is_active = last_packet_ms && now_ms - *last_packet_ms < 5000; |
| 525 | 518 |
| 526 // If we recently (within |kMaxWaitForFrameMs|) have been receiving packets | 519 // If we recently (within |kMaxWaitForFrameMs|) have been receiving packets |
| 527 // belonging to a keyframe then we assume a keyframe is being received right | 520 // belonging to a keyframe then we assume a keyframe is being received right |
| 528 // now. | 521 // now. |
| 529 bool receiving_keyframe = | 522 bool receiving_keyframe = |
| 530 last_keyframe_packet_ms && | 523 last_keyframe_packet_ms && |
| 531 now_ms - *last_keyframe_packet_ms < kMaxWaitForFrameMs; | 524 now_ms - *last_keyframe_packet_ms < kMaxWaitForFrameMs; |
| 532 | 525 |
| 533 if (stream_is_active && !receiving_keyframe) { | 526 if (stream_is_active && !receiving_keyframe) { |
| 534 LOG(LS_WARNING) << "No decodable frame in " << wait_ms | 527 LOG(LS_WARNING) << "No decodable frame in " << kMaxWaitForFrameMs |
| 535 << " ms, requesting keyframe."; | 528 << " ms, requesting keyframe."; |
| 536 RequestKeyFrame(); | 529 RequestKeyFrame(); |
| 537 } | 530 } |
| 538 } | 531 } |
| 539 return true; | 532 return true; |
| 540 } | 533 } |
| 541 } // namespace internal | 534 } // namespace internal |
| 542 } // namespace webrtc | 535 } // namespace webrtc |
| OLD | NEW |