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 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
376 this, | 376 this, |
377 config.post_encode_callback, | 377 config.post_encode_callback, |
378 &stats_proxy_), | 378 &stats_proxy_), |
379 vie_encoder_(num_cpu_cores, | 379 vie_encoder_(num_cpu_cores, |
380 module_process_thread_, | 380 module_process_thread_, |
381 &stats_proxy_, | 381 &stats_proxy_, |
382 &overuse_detector_), | 382 &overuse_detector_), |
383 encoder_feedback_(Clock::GetRealTimeClock(), | 383 encoder_feedback_(Clock::GetRealTimeClock(), |
384 config.rtp.ssrcs, | 384 config.rtp.ssrcs, |
385 &vie_encoder_), | 385 &vie_encoder_), |
386 post_encode_protection_(Clock::GetRealTimeClock(), this), | |
386 video_sender_(vie_encoder_.video_sender()), | 387 video_sender_(vie_encoder_.video_sender()), |
387 bandwidth_observer_(congestion_controller_->GetBitrateController() | 388 bandwidth_observer_(congestion_controller_->GetBitrateController() |
388 ->CreateRtcpBandwidthObserver()), | 389 ->CreateRtcpBandwidthObserver()), |
389 rtp_rtcp_modules_(CreateRtpRtcpModules( | 390 rtp_rtcp_modules_(CreateRtpRtcpModules( |
390 config.send_transport, | 391 config.send_transport, |
391 &encoder_feedback_, | 392 &encoder_feedback_, |
392 bandwidth_observer_.get(), | 393 bandwidth_observer_.get(), |
393 congestion_controller_->GetTransportFeedbackObserver(), | 394 congestion_controller_->GetTransportFeedbackObserver(), |
394 call_stats_->rtcp_rtt_stats(), | 395 call_stats_->rtcp_rtt_stats(), |
395 congestion_controller_->pacer(), | 396 congestion_controller_->pacer(), |
(...skipping 14 matching lines...) Expand all Loading... | |
410 RTC_DCHECK(congestion_controller_); | 411 RTC_DCHECK(congestion_controller_); |
411 RTC_DCHECK(remb_); | 412 RTC_DCHECK(remb_); |
412 | 413 |
413 | 414 |
414 // RTP/RTCP initialization. | 415 // RTP/RTCP initialization. |
415 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { | 416 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { |
416 module_process_thread_->RegisterModule(rtp_rtcp); | 417 module_process_thread_->RegisterModule(rtp_rtcp); |
417 congestion_controller_->packet_router()->AddRtpModule(rtp_rtcp); | 418 congestion_controller_->packet_router()->AddRtpModule(rtp_rtcp); |
418 } | 419 } |
419 | 420 |
420 video_sender_->RegisterProtectionCallback(this); | |
421 | |
422 for (size_t i = 0; i < config_.rtp.extensions.size(); ++i) { | 421 for (size_t i = 0; i < config_.rtp.extensions.size(); ++i) { |
423 const std::string& extension = config_.rtp.extensions[i].name; | 422 const std::string& extension = config_.rtp.extensions[i].name; |
424 int id = config_.rtp.extensions[i].id; | 423 int id = config_.rtp.extensions[i].id; |
425 // One-byte-extension local identifiers are in the range 1-14 inclusive. | 424 // One-byte-extension local identifiers are in the range 1-14 inclusive. |
426 RTC_DCHECK_GE(id, 1); | 425 RTC_DCHECK_GE(id, 1); |
427 RTC_DCHECK_LE(id, 14); | 426 RTC_DCHECK_LE(id, 14); |
428 RTC_DCHECK(RtpExtension::IsSupportedForVideo(extension)); | 427 RTC_DCHECK(RtpExtension::IsSupportedForVideo(extension)); |
429 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { | 428 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { |
430 RTC_CHECK_EQ(0, rtp_rtcp->RegisterSendRtpHeaderExtension( | 429 RTC_CHECK_EQ(0, rtp_rtcp->RegisterSendRtpHeaderExtension( |
431 StringToRtpExtensionType(extension), id)); | 430 StringToRtpExtensionType(extension), id)); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
559 // vie_encoder_.SetEncoder must be called before this. | 558 // vie_encoder_.SetEncoder must be called before this. |
560 if (config_.suspend_below_min_bitrate) | 559 if (config_.suspend_below_min_bitrate) |
561 video_sender_->SuspendBelowMinBitrate(); | 560 video_sender_->SuspendBelowMinBitrate(); |
562 | 561 |
563 // Clear stats for disabled layers. | 562 // Clear stats for disabled layers. |
564 for (size_t i = encoder_settings->streams.size(); | 563 for (size_t i = encoder_settings->streams.size(); |
565 i < config_.rtp.ssrcs.size(); ++i) { | 564 i < config_.rtp.ssrcs.size(); ++i) { |
566 stats_proxy_.OnInactiveSsrc(config_.rtp.ssrcs[i]); | 565 stats_proxy_.OnInactiveSsrc(config_.rtp.ssrcs[i]); |
567 } | 566 } |
568 | 567 |
568 post_encode_protection_.SetEncodingData( | |
569 encoder_settings->video_codec.startBitrate * 1000, | |
570 encoder_settings->video_codec.width, | |
571 encoder_settings->video_codec.height, | |
572 encoder_settings->video_codec.maxFramerate, | |
573 encoder_settings->streams.size(), payload_router_.MaxPayloadLength()); | |
stefan-webrtc
2016/05/19 12:52:40
num_layers should be the number of temporal layers
perkj_webrtc
2016/06/01 20:55:23
Done.
| |
574 | |
569 // We might've gotten new settings while configuring the encoder settings, | 575 // We might've gotten new settings while configuring the encoder settings, |
570 // restart from the top to see if that's the case before trying to encode | 576 // restart from the top to see if that's the case before trying to encode |
571 // a frame (which might correspond to the last frame size). | 577 // a frame (which might correspond to the last frame size). |
572 encoder_wakeup_event_.Set(); | 578 encoder_wakeup_event_.Set(); |
573 continue; | 579 continue; |
574 } | 580 } |
575 | 581 |
576 VideoFrame frame; | 582 VideoFrame frame; |
577 if (input_.GetVideoFrame(&frame)) { | 583 if (input_.GetVideoFrame(&frame)) { |
578 // TODO(perkj): |pre_encode_callback| is only used by tests. Tests should | 584 // 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... | |
615 if (config_.overuse_callback) | 621 if (config_.overuse_callback) |
616 config_.overuse_callback->OnLoadUpdate(LoadObserver::kUnderuse); | 622 config_.overuse_callback->OnLoadUpdate(LoadObserver::kUnderuse); |
617 } | 623 } |
618 | 624 |
619 int32_t VideoSendStream::Encoded(const EncodedImage& encoded_image, | 625 int32_t VideoSendStream::Encoded(const EncodedImage& encoded_image, |
620 const CodecSpecificInfo* codec_specific_info, | 626 const CodecSpecificInfo* codec_specific_info, |
621 const RTPFragmentationHeader* fragmentation) { | 627 const RTPFragmentationHeader* fragmentation) { |
622 // |encoded_frame_proxy_| forwards frames to |config_.post_encode_callback|; | 628 // |encoded_frame_proxy_| forwards frames to |config_.post_encode_callback|; |
623 encoded_frame_proxy_.Encoded(encoded_image, codec_specific_info, | 629 encoded_frame_proxy_.Encoded(encoded_image, codec_specific_info, |
624 fragmentation); | 630 fragmentation); |
631 post_encode_protection_.UpdateWithEncodedData(encoded_image); | |
625 int32_t return_value = payload_router_.Encoded( | 632 int32_t return_value = payload_router_.Encoded( |
626 encoded_image, codec_specific_info, fragmentation); | 633 encoded_image, codec_specific_info, fragmentation); |
627 | 634 |
628 if (kEnableFrameRecording) { | 635 if (kEnableFrameRecording) { |
629 int layer = codec_specific_info->codecType == kVideoCodecVP8 | 636 int layer = codec_specific_info->codecType == kVideoCodecVP8 |
630 ? codec_specific_info->codecSpecific.VP8.simulcastIdx | 637 ? codec_specific_info->codecSpecific.VP8.simulcastIdx |
631 : 0; | 638 : 0; |
632 IvfFileWriter* file_writer; | 639 IvfFileWriter* file_writer; |
633 { | 640 { |
634 if (file_writers_[layer] == nullptr) { | 641 if (file_writers_[layer] == nullptr) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
694 rtp_rtcp->SetStorePacketsStatus( | 701 rtp_rtcp->SetStorePacketsStatus( |
695 enable_protection_nack || congestion_controller_->pacer(), | 702 enable_protection_nack || congestion_controller_->pacer(), |
696 kMinSendSidePacketHistorySize); | 703 kMinSendSidePacketHistorySize); |
697 // Set FEC. | 704 // Set FEC. |
698 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { | 705 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { |
699 rtp_rtcp->SetGenericFECStatus(enable_protection_fec, payload_type_red, | 706 rtp_rtcp->SetGenericFECStatus(enable_protection_fec, payload_type_red, |
700 payload_type_fec); | 707 payload_type_fec); |
701 } | 708 } |
702 } | 709 } |
703 | 710 |
704 vie_encoder_.SetProtectionMethod(enable_protection_nack, | 711 post_encode_protection_.SetProtectionMethod(enable_protection_fec, |
705 enable_protection_fec); | 712 enable_protection_nack); |
706 } | 713 } |
707 | 714 |
708 void VideoSendStream::ConfigureSsrcs() { | 715 void VideoSendStream::ConfigureSsrcs() { |
709 // Configure regular SSRCs. | 716 // Configure regular SSRCs. |
710 for (size_t i = 0; i < config_.rtp.ssrcs.size(); ++i) { | 717 for (size_t i = 0; i < config_.rtp.ssrcs.size(); ++i) { |
711 uint32_t ssrc = config_.rtp.ssrcs[i]; | 718 uint32_t ssrc = config_.rtp.ssrcs[i]; |
712 RtpRtcp* const rtp_rtcp = rtp_rtcp_modules_[i]; | 719 RtpRtcp* const rtp_rtcp = rtp_rtcp_modules_[i]; |
713 rtp_rtcp->SetSSRC(ssrc); | 720 rtp_rtcp->SetSSRC(ssrc); |
714 | 721 |
715 // Restore RTP state if previous existed. | 722 // Restore RTP state if previous existed. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
773 } | 780 } |
774 | 781 |
775 int VideoSendStream::GetPaddingNeededBps() const { | 782 int VideoSendStream::GetPaddingNeededBps() const { |
776 return vie_encoder_.GetPaddingNeededBps(); | 783 return vie_encoder_.GetPaddingNeededBps(); |
777 } | 784 } |
778 | 785 |
779 void VideoSendStream::OnBitrateUpdated(uint32_t bitrate_bps, | 786 void VideoSendStream::OnBitrateUpdated(uint32_t bitrate_bps, |
780 uint8_t fraction_loss, | 787 uint8_t fraction_loss, |
781 int64_t rtt) { | 788 int64_t rtt) { |
782 payload_router_.SetTargetSendBitrate(bitrate_bps); | 789 payload_router_.SetTargetSendBitrate(bitrate_bps); |
783 vie_encoder_.OnBitrateUpdated(bitrate_bps, fraction_loss, rtt); | 790 // Get the encoder target rate. It is the estimated network rate - |
791 // protection overhead. | |
792 uint32_t encoder_target_rate = | |
793 post_encode_protection_.SetTargetRates(bitrate_bps, fraction_loss, rtt); | |
794 | |
795 vie_encoder_.OnBitrateUpdated(encoder_target_rate, fraction_loss, rtt); | |
784 } | 796 } |
785 | 797 |
786 int VideoSendStream::ProtectionRequest(const FecProtectionParams* delta_params, | 798 int VideoSendStream::ProtectionRequest(const FecProtectionParams* delta_params, |
787 const FecProtectionParams* key_params, | 799 const FecProtectionParams* key_params, |
788 uint32_t* sent_video_rate_bps, | 800 uint32_t* sent_video_rate_bps, |
789 uint32_t* sent_nack_rate_bps, | 801 uint32_t* sent_nack_rate_bps, |
790 uint32_t* sent_fec_rate_bps) { | 802 uint32_t* sent_fec_rate_bps) { |
791 *sent_video_rate_bps = 0; | 803 *sent_video_rate_bps = 0; |
792 *sent_nack_rate_bps = 0; | 804 *sent_nack_rate_bps = 0; |
793 *sent_fec_rate_bps = 0; | 805 *sent_fec_rate_bps = 0; |
794 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { | 806 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { |
795 uint32_t not_used = 0; | 807 uint32_t not_used = 0; |
796 uint32_t module_video_rate = 0; | 808 uint32_t module_video_rate = 0; |
797 uint32_t module_fec_rate = 0; | 809 uint32_t module_fec_rate = 0; |
798 uint32_t module_nack_rate = 0; | 810 uint32_t module_nack_rate = 0; |
799 rtp_rtcp->SetFecParameters(delta_params, key_params); | 811 rtp_rtcp->SetFecParameters(delta_params, key_params); |
800 rtp_rtcp->BitrateSent(¬_used, &module_video_rate, &module_fec_rate, | 812 rtp_rtcp->BitrateSent(¬_used, &module_video_rate, &module_fec_rate, |
801 &module_nack_rate); | 813 &module_nack_rate); |
802 *sent_video_rate_bps += module_video_rate; | 814 *sent_video_rate_bps += module_video_rate; |
803 *sent_nack_rate_bps += module_nack_rate; | 815 *sent_nack_rate_bps += module_nack_rate; |
804 *sent_fec_rate_bps += module_fec_rate; | 816 *sent_fec_rate_bps += module_fec_rate; |
805 } | 817 } |
806 return 0; | 818 return 0; |
807 } | 819 } |
808 | 820 |
809 } // namespace internal | 821 } // namespace internal |
810 } // namespace webrtc | 822 } // namespace webrtc |
OLD | NEW |