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 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 config.post_encode_callback, | 380 config.post_encode_callback, |
381 &stats_proxy_), | 381 &stats_proxy_), |
382 vie_encoder_(num_cpu_cores, | 382 vie_encoder_(num_cpu_cores, |
383 module_process_thread_, | 383 module_process_thread_, |
384 &stats_proxy_, | 384 &stats_proxy_, |
385 &overuse_detector_, | 385 &overuse_detector_, |
386 this), | 386 this), |
387 encoder_feedback_(Clock::GetRealTimeClock(), | 387 encoder_feedback_(Clock::GetRealTimeClock(), |
388 config.rtp.ssrcs, | 388 config.rtp.ssrcs, |
389 &vie_encoder_), | 389 &vie_encoder_), |
| 390 protection_bitrate_calculator_(Clock::GetRealTimeClock(), this), |
390 video_sender_(vie_encoder_.video_sender()), | 391 video_sender_(vie_encoder_.video_sender()), |
391 bandwidth_observer_(congestion_controller_->GetBitrateController() | 392 bandwidth_observer_(congestion_controller_->GetBitrateController() |
392 ->CreateRtcpBandwidthObserver()), | 393 ->CreateRtcpBandwidthObserver()), |
393 rtp_rtcp_modules_(CreateRtpRtcpModules( | 394 rtp_rtcp_modules_(CreateRtpRtcpModules( |
394 config.send_transport, | 395 config.send_transport, |
395 &encoder_feedback_, | 396 &encoder_feedback_, |
396 bandwidth_observer_.get(), | 397 bandwidth_observer_.get(), |
397 congestion_controller_->GetTransportFeedbackObserver(), | 398 congestion_controller_->GetTransportFeedbackObserver(), |
398 call_stats_->rtcp_rtt_stats(), | 399 call_stats_->rtcp_rtt_stats(), |
399 congestion_controller_->pacer(), | 400 congestion_controller_->pacer(), |
(...skipping 15 matching lines...) Expand all Loading... |
415 RTC_DCHECK(congestion_controller_); | 416 RTC_DCHECK(congestion_controller_); |
416 RTC_DCHECK(remb_); | 417 RTC_DCHECK(remb_); |
417 | 418 |
418 | 419 |
419 // RTP/RTCP initialization. | 420 // RTP/RTCP initialization. |
420 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { | 421 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { |
421 module_process_thread_->RegisterModule(rtp_rtcp); | 422 module_process_thread_->RegisterModule(rtp_rtcp); |
422 congestion_controller_->packet_router()->AddRtpModule(rtp_rtcp); | 423 congestion_controller_->packet_router()->AddRtpModule(rtp_rtcp); |
423 } | 424 } |
424 | 425 |
425 video_sender_->RegisterProtectionCallback(this); | |
426 | |
427 for (size_t i = 0; i < config_.rtp.extensions.size(); ++i) { | 426 for (size_t i = 0; i < config_.rtp.extensions.size(); ++i) { |
428 const std::string& extension = config_.rtp.extensions[i].uri; | 427 const std::string& extension = config_.rtp.extensions[i].uri; |
429 int id = config_.rtp.extensions[i].id; | 428 int id = config_.rtp.extensions[i].id; |
430 // One-byte-extension local identifiers are in the range 1-14 inclusive. | 429 // One-byte-extension local identifiers are in the range 1-14 inclusive. |
431 RTC_DCHECK_GE(id, 1); | 430 RTC_DCHECK_GE(id, 1); |
432 RTC_DCHECK_LE(id, 14); | 431 RTC_DCHECK_LE(id, 14); |
433 RTC_DCHECK(RtpExtension::IsSupportedForVideo(extension)); | 432 RTC_DCHECK(RtpExtension::IsSupportedForVideo(extension)); |
434 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { | 433 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { |
435 RTC_CHECK_EQ(0, rtp_rtcp->RegisterSendRtpHeaderExtension( | 434 RTC_CHECK_EQ(0, rtp_rtcp->RegisterSendRtpHeaderExtension( |
436 StringToRtpExtensionType(extension), id)); | 435 StringToRtpExtensionType(extension), id)); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 // vie_encoder_.SetEncoder must be called before this. | 563 // vie_encoder_.SetEncoder must be called before this. |
565 if (config_.suspend_below_min_bitrate) | 564 if (config_.suspend_below_min_bitrate) |
566 video_sender_->SuspendBelowMinBitrate(); | 565 video_sender_->SuspendBelowMinBitrate(); |
567 | 566 |
568 // Clear stats for disabled layers. | 567 // Clear stats for disabled layers. |
569 for (size_t i = encoder_settings->streams.size(); | 568 for (size_t i = encoder_settings->streams.size(); |
570 i < config_.rtp.ssrcs.size(); ++i) { | 569 i < config_.rtp.ssrcs.size(); ++i) { |
571 stats_proxy_.OnInactiveSsrc(config_.rtp.ssrcs[i]); | 570 stats_proxy_.OnInactiveSsrc(config_.rtp.ssrcs[i]); |
572 } | 571 } |
573 | 572 |
| 573 size_t number_of_temporal_layers = |
| 574 encoder_settings->streams.back() |
| 575 .temporal_layer_thresholds_bps.size() + |
| 576 1; |
| 577 protection_bitrate_calculator_.SetEncodingData( |
| 578 encoder_settings->video_codec.startBitrate * 1000, |
| 579 encoder_settings->video_codec.width, |
| 580 encoder_settings->video_codec.height, |
| 581 encoder_settings->video_codec.maxFramerate, number_of_temporal_layers, |
| 582 payload_router_.MaxPayloadLength()); |
| 583 |
574 // We might've gotten new settings while configuring the encoder settings, | 584 // We might've gotten new settings while configuring the encoder settings, |
575 // restart from the top to see if that's the case before trying to encode | 585 // restart from the top to see if that's the case before trying to encode |
576 // a frame (which might correspond to the last frame size). | 586 // a frame (which might correspond to the last frame size). |
577 encoder_wakeup_event_.Set(); | 587 encoder_wakeup_event_.Set(); |
578 continue; | 588 continue; |
579 } | 589 } |
580 | 590 |
581 VideoFrame frame; | 591 VideoFrame frame; |
582 if (input_.GetVideoFrame(&frame)) { | 592 if (input_.GetVideoFrame(&frame)) { |
583 // TODO(perkj): |pre_encode_callback| is only used by tests. Tests should | 593 // TODO(perkj): |pre_encode_callback| is only used by tests. Tests should |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 if (config_.overuse_callback) | 630 if (config_.overuse_callback) |
621 config_.overuse_callback->OnLoadUpdate(LoadObserver::kUnderuse); | 631 config_.overuse_callback->OnLoadUpdate(LoadObserver::kUnderuse); |
622 } | 632 } |
623 | 633 |
624 int32_t VideoSendStream::Encoded(const EncodedImage& encoded_image, | 634 int32_t VideoSendStream::Encoded(const EncodedImage& encoded_image, |
625 const CodecSpecificInfo* codec_specific_info, | 635 const CodecSpecificInfo* codec_specific_info, |
626 const RTPFragmentationHeader* fragmentation) { | 636 const RTPFragmentationHeader* fragmentation) { |
627 // |encoded_frame_proxy_| forwards frames to |config_.post_encode_callback|; | 637 // |encoded_frame_proxy_| forwards frames to |config_.post_encode_callback|; |
628 encoded_frame_proxy_.Encoded(encoded_image, codec_specific_info, | 638 encoded_frame_proxy_.Encoded(encoded_image, codec_specific_info, |
629 fragmentation); | 639 fragmentation); |
| 640 protection_bitrate_calculator_.UpdateWithEncodedData(encoded_image); |
630 int32_t return_value = payload_router_.Encoded( | 641 int32_t return_value = payload_router_.Encoded( |
631 encoded_image, codec_specific_info, fragmentation); | 642 encoded_image, codec_specific_info, fragmentation); |
632 | 643 |
633 if (kEnableFrameRecording) { | 644 if (kEnableFrameRecording) { |
634 int layer = codec_specific_info->codecType == kVideoCodecVP8 | 645 int layer = codec_specific_info->codecType == kVideoCodecVP8 |
635 ? codec_specific_info->codecSpecific.VP8.simulcastIdx | 646 ? codec_specific_info->codecSpecific.VP8.simulcastIdx |
636 : 0; | 647 : 0; |
637 IvfFileWriter* file_writer; | 648 IvfFileWriter* file_writer; |
638 { | 649 { |
639 if (file_writers_[layer] == nullptr) { | 650 if (file_writers_[layer] == nullptr) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
699 rtp_rtcp->SetStorePacketsStatus( | 710 rtp_rtcp->SetStorePacketsStatus( |
700 enable_protection_nack || congestion_controller_->pacer(), | 711 enable_protection_nack || congestion_controller_->pacer(), |
701 kMinSendSidePacketHistorySize); | 712 kMinSendSidePacketHistorySize); |
702 // Set FEC. | 713 // Set FEC. |
703 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { | 714 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { |
704 rtp_rtcp->SetGenericFECStatus(enable_protection_fec, payload_type_red, | 715 rtp_rtcp->SetGenericFECStatus(enable_protection_fec, payload_type_red, |
705 payload_type_fec); | 716 payload_type_fec); |
706 } | 717 } |
707 } | 718 } |
708 | 719 |
709 vie_encoder_.SetProtectionMethod(enable_protection_nack, | 720 protection_bitrate_calculator_.SetProtectionMethod(enable_protection_fec, |
710 enable_protection_fec); | 721 enable_protection_nack); |
711 } | 722 } |
712 | 723 |
713 void VideoSendStream::ConfigureSsrcs() { | 724 void VideoSendStream::ConfigureSsrcs() { |
714 // Configure regular SSRCs. | 725 // Configure regular SSRCs. |
715 for (size_t i = 0; i < config_.rtp.ssrcs.size(); ++i) { | 726 for (size_t i = 0; i < config_.rtp.ssrcs.size(); ++i) { |
716 uint32_t ssrc = config_.rtp.ssrcs[i]; | 727 uint32_t ssrc = config_.rtp.ssrcs[i]; |
717 RtpRtcp* const rtp_rtcp = rtp_rtcp_modules_[i]; | 728 RtpRtcp* const rtp_rtcp = rtp_rtcp_modules_[i]; |
718 rtp_rtcp->SetSSRC(ssrc); | 729 rtp_rtcp->SetSSRC(ssrc); |
719 | 730 |
720 // Restore RTP state if previous existed. | 731 // Restore RTP state if previous existed. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
778 } | 789 } |
779 | 790 |
780 int VideoSendStream::GetPaddingNeededBps() const { | 791 int VideoSendStream::GetPaddingNeededBps() const { |
781 return vie_encoder_.GetPaddingNeededBps(); | 792 return vie_encoder_.GetPaddingNeededBps(); |
782 } | 793 } |
783 | 794 |
784 void VideoSendStream::OnBitrateUpdated(uint32_t bitrate_bps, | 795 void VideoSendStream::OnBitrateUpdated(uint32_t bitrate_bps, |
785 uint8_t fraction_loss, | 796 uint8_t fraction_loss, |
786 int64_t rtt) { | 797 int64_t rtt) { |
787 payload_router_.SetTargetSendBitrate(bitrate_bps); | 798 payload_router_.SetTargetSendBitrate(bitrate_bps); |
788 vie_encoder_.OnBitrateUpdated(bitrate_bps, fraction_loss, rtt); | 799 // Get the encoder target rate. It is the estimated network rate - |
| 800 // protection overhead. |
| 801 uint32_t encoder_target_rate = protection_bitrate_calculator_.SetTargetRates( |
| 802 bitrate_bps, stats_proxy_.GetSendFrameRate(), fraction_loss, rtt); |
| 803 |
| 804 vie_encoder_.OnBitrateUpdated(encoder_target_rate, fraction_loss, rtt); |
789 } | 805 } |
790 | 806 |
791 int VideoSendStream::ProtectionRequest(const FecProtectionParams* delta_params, | 807 int VideoSendStream::ProtectionRequest(const FecProtectionParams* delta_params, |
792 const FecProtectionParams* key_params, | 808 const FecProtectionParams* key_params, |
793 uint32_t* sent_video_rate_bps, | 809 uint32_t* sent_video_rate_bps, |
794 uint32_t* sent_nack_rate_bps, | 810 uint32_t* sent_nack_rate_bps, |
795 uint32_t* sent_fec_rate_bps) { | 811 uint32_t* sent_fec_rate_bps) { |
796 *sent_video_rate_bps = 0; | 812 *sent_video_rate_bps = 0; |
797 *sent_nack_rate_bps = 0; | 813 *sent_nack_rate_bps = 0; |
798 *sent_fec_rate_bps = 0; | 814 *sent_fec_rate_bps = 0; |
799 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { | 815 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { |
800 uint32_t not_used = 0; | 816 uint32_t not_used = 0; |
801 uint32_t module_video_rate = 0; | 817 uint32_t module_video_rate = 0; |
802 uint32_t module_fec_rate = 0; | 818 uint32_t module_fec_rate = 0; |
803 uint32_t module_nack_rate = 0; | 819 uint32_t module_nack_rate = 0; |
804 rtp_rtcp->SetFecParameters(delta_params, key_params); | 820 rtp_rtcp->SetFecParameters(delta_params, key_params); |
805 rtp_rtcp->BitrateSent(¬_used, &module_video_rate, &module_fec_rate, | 821 rtp_rtcp->BitrateSent(¬_used, &module_video_rate, &module_fec_rate, |
806 &module_nack_rate); | 822 &module_nack_rate); |
807 *sent_video_rate_bps += module_video_rate; | 823 *sent_video_rate_bps += module_video_rate; |
808 *sent_nack_rate_bps += module_nack_rate; | 824 *sent_nack_rate_bps += module_nack_rate; |
809 *sent_fec_rate_bps += module_fec_rate; | 825 *sent_fec_rate_bps += module_fec_rate; |
810 } | 826 } |
811 return 0; | 827 return 0; |
812 } | 828 } |
813 | 829 |
814 } // namespace internal | 830 } // namespace internal |
815 } // namespace webrtc | 831 } // namespace webrtc |
OLD | NEW |