| 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 14 matching lines...) Expand all Loading... |
| 25 #include "webrtc/modules/utility/include/process_thread.h" | 25 #include "webrtc/modules/utility/include/process_thread.h" |
| 26 #include "webrtc/modules/video_coding/frame_object.h" | 26 #include "webrtc/modules/video_coding/frame_object.h" |
| 27 #include "webrtc/modules/video_coding/include/video_coding.h" | 27 #include "webrtc/modules/video_coding/include/video_coding.h" |
| 28 #include "webrtc/modules/video_coding/jitter_estimator.h" | 28 #include "webrtc/modules/video_coding/jitter_estimator.h" |
| 29 #include "webrtc/modules/video_coding/timing.h" | 29 #include "webrtc/modules/video_coding/timing.h" |
| 30 #include "webrtc/modules/video_coding/utility/ivf_file_writer.h" | 30 #include "webrtc/modules/video_coding/utility/ivf_file_writer.h" |
| 31 #include "webrtc/rtc_base/checks.h" | 31 #include "webrtc/rtc_base/checks.h" |
| 32 #include "webrtc/rtc_base/location.h" | 32 #include "webrtc/rtc_base/location.h" |
| 33 #include "webrtc/rtc_base/logging.h" | 33 #include "webrtc/rtc_base/logging.h" |
| 34 #include "webrtc/rtc_base/optional.h" | 34 #include "webrtc/rtc_base/optional.h" |
| 35 #include "webrtc/rtc_base/timeutils.h" |
| 35 #include "webrtc/rtc_base/trace_event.h" | 36 #include "webrtc/rtc_base/trace_event.h" |
| 36 #include "webrtc/system_wrappers/include/clock.h" | 37 #include "webrtc/system_wrappers/include/clock.h" |
| 37 #include "webrtc/system_wrappers/include/field_trial.h" | 38 #include "webrtc/system_wrappers/include/field_trial.h" |
| 38 #include "webrtc/video/call_stats.h" | 39 #include "webrtc/video/call_stats.h" |
| 39 #include "webrtc/video/receive_statistics_proxy.h" | 40 #include "webrtc/video/receive_statistics_proxy.h" |
| 40 #include "webrtc/video_receive_stream.h" | 41 #include "webrtc/video_receive_stream.h" |
| 41 | 42 |
| 42 namespace webrtc { | 43 namespace webrtc { |
| 43 | 44 |
| 44 std::string VideoReceiveStream::Decoder::ToString() const { | 45 std::string VideoReceiveStream::Decoder::ToString() const { |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 | 300 |
| 300 video_stream_decoder_.reset(new VideoStreamDecoder( | 301 video_stream_decoder_.reset(new VideoStreamDecoder( |
| 301 &video_receiver_, &rtp_video_stream_receiver_, | 302 &video_receiver_, &rtp_video_stream_receiver_, |
| 302 &rtp_video_stream_receiver_, | 303 &rtp_video_stream_receiver_, |
| 303 rtp_video_stream_receiver_.IsRetransmissionsEnabled(), protected_by_fec, | 304 rtp_video_stream_receiver_.IsRetransmissionsEnabled(), protected_by_fec, |
| 304 &stats_proxy_, renderer)); | 305 &stats_proxy_, renderer)); |
| 305 // Register the channel to receive stats updates. | 306 // Register the channel to receive stats updates. |
| 306 call_stats_->RegisterStatsObserver(video_stream_decoder_.get()); | 307 call_stats_->RegisterStatsObserver(video_stream_decoder_.get()); |
| 307 | 308 |
| 308 process_thread_->RegisterModule(&video_receiver_, RTC_FROM_HERE); | 309 process_thread_->RegisterModule(&video_receiver_, RTC_FROM_HERE); |
| 310 video_receiver_.DecoderThreadStarting(); |
| 309 | 311 |
| 310 // Start the decode thread | 312 // Start the decode thread |
| 311 decode_thread_.Start(); | 313 decode_thread_.Start(); |
| 312 rtp_video_stream_receiver_.StartReceive(); | 314 rtp_video_stream_receiver_.StartReceive(); |
| 313 } | 315 } |
| 314 | 316 |
| 315 void VideoReceiveStream::Stop() { | 317 void VideoReceiveStream::Stop() { |
| 316 RTC_DCHECK_RUN_ON(&worker_thread_checker_); | 318 RTC_DCHECK_RUN_ON(&worker_thread_checker_); |
| 317 rtp_video_stream_receiver_.StopReceive(); | 319 rtp_video_stream_receiver_.StopReceive(); |
| 318 | 320 |
| 319 frame_buffer_->Stop(); | 321 frame_buffer_->Stop(); |
| 320 call_stats_->DeregisterStatsObserver(this); | 322 call_stats_->DeregisterStatsObserver(this); |
| 321 call_stats_->DeregisterStatsObserver(&rtp_video_stream_receiver_); | 323 call_stats_->DeregisterStatsObserver(&rtp_video_stream_receiver_); |
| 322 process_thread_->DeRegisterModule(&video_receiver_); | 324 process_thread_->DeRegisterModule(&video_receiver_); |
| 323 | 325 |
| 324 if (decode_thread_.IsRunning()) { | 326 if (decode_thread_.IsRunning()) { |
| 325 // TriggerDecoderShutdown will release any waiting decoder thread and make | 327 // TriggerDecoderShutdown will release any waiting decoder thread and make |
| 326 // it stop immediately, instead of waiting for a timeout. Needs to be called | 328 // it stop immediately, instead of waiting for a timeout. Needs to be called |
| 327 // before joining the decoder thread. | 329 // before joining the decoder thread. |
| 328 video_receiver_.TriggerDecoderShutdown(); | 330 video_receiver_.TriggerDecoderShutdown(); |
| 329 | 331 |
| 330 decode_thread_.Stop(); | 332 decode_thread_.Stop(); |
| 333 video_receiver_.DecoderThreadStopped(); |
| 331 // Deregister external decoders so they are no longer running during | 334 // Deregister external decoders so they are no longer running during |
| 332 // destruction. This effectively stops the VCM since the decoder thread is | 335 // destruction. This effectively stops the VCM since the decoder thread is |
| 333 // stopped, the VCM is deregistered and no asynchronous decoder threads are | 336 // stopped, the VCM is deregistered and no asynchronous decoder threads are |
| 334 // running. | 337 // running. |
| 335 for (const Decoder& decoder : config_.decoders) | 338 for (const Decoder& decoder : config_.decoders) |
| 336 video_receiver_.RegisterExternalDecoder(nullptr, decoder.payload_type); | 339 video_receiver_.RegisterExternalDecoder(nullptr, decoder.payload_type); |
| 337 } | 340 } |
| 338 | 341 |
| 339 call_stats_->DeregisterStatsObserver(video_stream_decoder_.get()); | 342 call_stats_->DeregisterStatsObserver(video_stream_decoder_.get()); |
| 340 video_stream_decoder_.reset(); | 343 video_stream_decoder_.reset(); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 static const int kMaxWaitForFrameMs = 3000; | 502 static const int kMaxWaitForFrameMs = 3000; |
| 500 static const int kMaxWaitForKeyFrameMs = 200; | 503 static const int kMaxWaitForKeyFrameMs = 200; |
| 501 | 504 |
| 502 int wait_ms = keyframe_required_ ? kMaxWaitForKeyFrameMs : kMaxWaitForFrameMs; | 505 int wait_ms = keyframe_required_ ? kMaxWaitForKeyFrameMs : kMaxWaitForFrameMs; |
| 503 std::unique_ptr<video_coding::FrameObject> frame; | 506 std::unique_ptr<video_coding::FrameObject> frame; |
| 504 // TODO(philipel): Call NextFrame with |keyframe_required| argument when | 507 // TODO(philipel): Call NextFrame with |keyframe_required| argument when |
| 505 // downstream project has been fixed. | 508 // downstream project has been fixed. |
| 506 video_coding::FrameBuffer::ReturnReason res = | 509 video_coding::FrameBuffer::ReturnReason res = |
| 507 frame_buffer_->NextFrame(wait_ms, &frame); | 510 frame_buffer_->NextFrame(wait_ms, &frame); |
| 508 | 511 |
| 509 if (res == video_coding::FrameBuffer::ReturnReason::kStopped) { | 512 video_coding::FrameBuffer::ReturnReason res; |
| 510 video_receiver_.DecodingStopped(); | 513 #if defined(WEBRTC_ANDROID) |
| 514 // This is a temporary workaround for video capture on Android in order to |
| 515 // deliver asynchronously delivered frames, on the decoder thread. |
| 516 // More details here: |
| 517 // https://bugs.chromium.org/p/webrtc/issues/detail?id=7361 |
| 518 static const int kPollIntervalMs = 10; |
| 519 int time_remaining = kMaxWaitForFrameMs; |
| 520 do { |
| 521 res = frame_buffer_->NextFrame(kPollIntervalMs, &frame); |
| 522 if (res != video_coding::FrameBuffer::ReturnReason::kTimeout) |
| 523 break; |
| 524 time_remaining -= kPollIntervalMs; |
| 525 video_receiver_.PollDecodedFrames(); |
| 526 } while (time_remaining > 0); |
| 527 #else |
| 528 res = frame_buffer_->NextFrame(kMaxWaitForFrameMs, &frame); |
| 529 #endif |
| 530 |
| 531 if (res == video_coding::FrameBuffer::ReturnReason::kStopped) |
| 511 return false; | 532 return false; |
| 512 } | |
| 513 | 533 |
| 514 if (frame) { | 534 if (frame) { |
| 515 RTC_DCHECK_EQ(res, video_coding::FrameBuffer::ReturnReason::kFrameFound); | 535 RTC_DCHECK_EQ(res, video_coding::FrameBuffer::ReturnReason::kFrameFound); |
| 516 if (video_receiver_.Decode(frame.get()) == VCM_OK) { | 536 if (video_receiver_.Decode(frame.get()) == VCM_OK) { |
| 517 keyframe_required_ = false; | 537 keyframe_required_ = false; |
| 518 rtp_video_stream_receiver_.FrameDecoded(frame->picture_id); | 538 rtp_video_stream_receiver_.FrameDecoded(frame->picture_id); |
| 519 } else if (keyframe_required_ == false) { | 539 } else if (keyframe_required_ == false) { |
| 520 keyframe_required_ = true; | 540 keyframe_required_ = true; |
| 521 // TODO(philipel): Remove this keyframe request when downstream project | 541 // TODO(philipel): Remove this keyframe request when downstream project |
| 522 // has been fixed. | 542 // has been fixed. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 539 bool receiving_keyframe = | 559 bool receiving_keyframe = |
| 540 last_keyframe_packet_ms && | 560 last_keyframe_packet_ms && |
| 541 now_ms - *last_keyframe_packet_ms < kMaxWaitForKeyFrameMs; | 561 now_ms - *last_keyframe_packet_ms < kMaxWaitForKeyFrameMs; |
| 542 | 562 |
| 543 if (stream_is_active && !receiving_keyframe) { | 563 if (stream_is_active && !receiving_keyframe) { |
| 544 LOG(LS_WARNING) << "No decodable frame in " << wait_ms | 564 LOG(LS_WARNING) << "No decodable frame in " << wait_ms |
| 545 << " ms, requesting keyframe."; | 565 << " ms, requesting keyframe."; |
| 546 RequestKeyFrame(); | 566 RequestKeyFrame(); |
| 547 } | 567 } |
| 548 } | 568 } |
| 569 |
| 549 return true; | 570 return true; |
| 550 } | 571 } |
| 551 } // namespace internal | 572 } // namespace internal |
| 552 } // namespace webrtc | 573 } // namespace webrtc |
| OLD | NEW |