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 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 config_(config), | 389 config_(config), |
390 suspended_ssrcs_(suspended_ssrcs), | 390 suspended_ssrcs_(suspended_ssrcs), |
391 module_process_thread_(module_process_thread), | 391 module_process_thread_(module_process_thread), |
392 call_stats_(call_stats), | 392 call_stats_(call_stats), |
393 congestion_controller_(congestion_controller), | 393 congestion_controller_(congestion_controller), |
394 bitrate_allocator_(bitrate_allocator), | 394 bitrate_allocator_(bitrate_allocator), |
395 remb_(remb), | 395 remb_(remb), |
396 encoder_thread_(EncoderThreadFunction, this, "EncoderThread"), | 396 encoder_thread_(EncoderThreadFunction, this, "EncoderThread"), |
397 encoder_wakeup_event_(false, false), | 397 encoder_wakeup_event_(false, false), |
398 stop_encoder_thread_(0), | 398 stop_encoder_thread_(0), |
| 399 encoder_max_bitrate_bps_(0), |
399 state_(State::kStopped), | 400 state_(State::kStopped), |
400 overuse_detector_( | 401 overuse_detector_( |
401 Clock::GetRealTimeClock(), | 402 Clock::GetRealTimeClock(), |
402 GetCpuOveruseOptions(config.encoder_settings.full_overuse_time), | 403 GetCpuOveruseOptions(config.encoder_settings.full_overuse_time), |
403 this, | 404 this, |
404 config.post_encode_callback, | 405 config.post_encode_callback, |
405 &stats_proxy_), | 406 &stats_proxy_), |
406 vie_encoder_(num_cpu_cores, | 407 vie_encoder_(num_cpu_cores, |
407 module_process_thread_, | 408 module_process_thread_, |
408 &stats_proxy_, | 409 &stats_proxy_, |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 current_encoder_settings_->video_codec.maxBitrate * 1000, | 625 current_encoder_settings_->video_codec.maxBitrate * 1000, |
625 CalulcateMaxPadBitrateBps(current_encoder_settings_->config, | 626 CalulcateMaxPadBitrateBps(current_encoder_settings_->config, |
626 config_.suspend_below_min_bitrate), | 627 config_.suspend_below_min_bitrate), |
627 !config_.suspend_below_min_bitrate); | 628 !config_.suspend_below_min_bitrate); |
628 vie_encoder_.SendKeyFrame(); | 629 vie_encoder_.SendKeyFrame(); |
629 state_ = State::kStarted; | 630 state_ = State::kStarted; |
630 LOG_F(LS_INFO) << "Encoder started."; | 631 LOG_F(LS_INFO) << "Encoder started."; |
631 } else if (*pending_state_change == State::kStopped) { | 632 } else if (*pending_state_change == State::kStopped) { |
632 bitrate_allocator_->RemoveObserver(this); | 633 bitrate_allocator_->RemoveObserver(this); |
633 vie_encoder_.OnBitrateUpdated(0, 0, 0); | 634 vie_encoder_.OnBitrateUpdated(0, 0, 0); |
| 635 stats_proxy_.OnSetEncoderTargetRate(0); |
634 state_ = State::kStopped; | 636 state_ = State::kStopped; |
635 LOG_F(LS_INFO) << "Encoder stopped."; | 637 LOG_F(LS_INFO) << "Encoder stopped."; |
636 } | 638 } |
637 encoder_wakeup_event_.Set(); | 639 encoder_wakeup_event_.Set(); |
638 continue; | 640 continue; |
639 } | 641 } |
640 | 642 |
641 // Check if the encoder has produced anything the last kEncoderTimeOutMs. | 643 // Check if the encoder has produced anything the last kEncoderTimeOutMs. |
642 // If not, deregister as BitrateAllocatorObserver. | 644 // If not, deregister as BitrateAllocatorObserver. |
643 if (state_ == State::kStarted && | 645 if (state_ == State::kStarted && |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 void VideoSendStream::ReconfigureVideoEncoder( | 679 void VideoSendStream::ReconfigureVideoEncoder( |
678 const VideoEncoderConfig& config) { | 680 const VideoEncoderConfig& config) { |
679 TRACE_EVENT0("webrtc", "VideoSendStream::(Re)configureVideoEncoder"); | 681 TRACE_EVENT0("webrtc", "VideoSendStream::(Re)configureVideoEncoder"); |
680 LOG(LS_INFO) << "(Re)configureVideoEncoder: " << config.ToString(); | 682 LOG(LS_INFO) << "(Re)configureVideoEncoder: " << config.ToString(); |
681 RTC_DCHECK_GE(config_.rtp.ssrcs.size(), config.streams.size()); | 683 RTC_DCHECK_GE(config_.rtp.ssrcs.size(), config.streams.size()); |
682 VideoCodec video_codec = VideoEncoderConfigToVideoCodec( | 684 VideoCodec video_codec = VideoEncoderConfigToVideoCodec( |
683 config, config_.encoder_settings.payload_name, | 685 config, config_.encoder_settings.payload_name, |
684 config_.encoder_settings.payload_type); | 686 config_.encoder_settings.payload_type); |
685 { | 687 { |
686 rtc::CritScope lock(&encoder_settings_crit_); | 688 rtc::CritScope lock(&encoder_settings_crit_); |
| 689 encoder_max_bitrate_bps_ = video_codec.maxBitrate * 1000; |
687 pending_encoder_settings_.reset(new EncoderSettings({video_codec, config})); | 690 pending_encoder_settings_.reset(new EncoderSettings({video_codec, config})); |
688 } | 691 } |
689 encoder_wakeup_event_.Set(); | 692 encoder_wakeup_event_.Set(); |
690 } | 693 } |
691 | 694 |
692 VideoSendStream::Stats VideoSendStream::GetStats() { | 695 VideoSendStream::Stats VideoSendStream::GetStats() { |
693 return stats_proxy_.GetStats(); | 696 return stats_proxy_.GetStats(); |
694 } | 697 } |
695 | 698 |
696 void VideoSendStream::OveruseDetected() { | 699 void VideoSendStream::OveruseDetected() { |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 | 871 |
869 uint32_t VideoSendStream::OnBitrateUpdated(uint32_t bitrate_bps, | 872 uint32_t VideoSendStream::OnBitrateUpdated(uint32_t bitrate_bps, |
870 uint8_t fraction_loss, | 873 uint8_t fraction_loss, |
871 int64_t rtt) { | 874 int64_t rtt) { |
872 payload_router_.SetTargetSendBitrate(bitrate_bps); | 875 payload_router_.SetTargetSendBitrate(bitrate_bps); |
873 // Get the encoder target rate. It is the estimated network rate - | 876 // Get the encoder target rate. It is the estimated network rate - |
874 // protection overhead. | 877 // protection overhead. |
875 uint32_t encoder_target_rate_bps = | 878 uint32_t encoder_target_rate_bps = |
876 protection_bitrate_calculator_.SetTargetRates( | 879 protection_bitrate_calculator_.SetTargetRates( |
877 bitrate_bps, stats_proxy_.GetSendFrameRate(), fraction_loss, rtt); | 880 bitrate_bps, stats_proxy_.GetSendFrameRate(), fraction_loss, rtt); |
| 881 |
| 882 uint32_t protection_bitrate = bitrate_bps - encoder_target_rate_bps; |
| 883 { |
| 884 // Limit the target bitrate to the configured max bitrate. |
| 885 rtc::CritScope lock(&encoder_settings_crit_); |
| 886 encoder_target_rate_bps = |
| 887 std::min(encoder_max_bitrate_bps_, encoder_target_rate_bps); |
| 888 } |
878 vie_encoder_.OnBitrateUpdated(encoder_target_rate_bps, fraction_loss, rtt); | 889 vie_encoder_.OnBitrateUpdated(encoder_target_rate_bps, fraction_loss, rtt); |
| 890 stats_proxy_.OnSetEncoderTargetRate(encoder_target_rate_bps); |
879 | 891 |
880 return bitrate_bps - encoder_target_rate_bps; | 892 return protection_bitrate; |
881 } | 893 } |
882 | 894 |
883 int VideoSendStream::ProtectionRequest(const FecProtectionParams* delta_params, | 895 int VideoSendStream::ProtectionRequest(const FecProtectionParams* delta_params, |
884 const FecProtectionParams* key_params, | 896 const FecProtectionParams* key_params, |
885 uint32_t* sent_video_rate_bps, | 897 uint32_t* sent_video_rate_bps, |
886 uint32_t* sent_nack_rate_bps, | 898 uint32_t* sent_nack_rate_bps, |
887 uint32_t* sent_fec_rate_bps) { | 899 uint32_t* sent_fec_rate_bps) { |
888 *sent_video_rate_bps = 0; | 900 *sent_video_rate_bps = 0; |
889 *sent_nack_rate_bps = 0; | 901 *sent_nack_rate_bps = 0; |
890 *sent_fec_rate_bps = 0; | 902 *sent_fec_rate_bps = 0; |
891 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { | 903 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { |
892 uint32_t not_used = 0; | 904 uint32_t not_used = 0; |
893 uint32_t module_video_rate = 0; | 905 uint32_t module_video_rate = 0; |
894 uint32_t module_fec_rate = 0; | 906 uint32_t module_fec_rate = 0; |
895 uint32_t module_nack_rate = 0; | 907 uint32_t module_nack_rate = 0; |
896 rtp_rtcp->SetFecParameters(delta_params, key_params); | 908 rtp_rtcp->SetFecParameters(delta_params, key_params); |
897 rtp_rtcp->BitrateSent(¬_used, &module_video_rate, &module_fec_rate, | 909 rtp_rtcp->BitrateSent(¬_used, &module_video_rate, &module_fec_rate, |
898 &module_nack_rate); | 910 &module_nack_rate); |
899 *sent_video_rate_bps += module_video_rate; | 911 *sent_video_rate_bps += module_video_rate; |
900 *sent_nack_rate_bps += module_nack_rate; | 912 *sent_nack_rate_bps += module_nack_rate; |
901 *sent_fec_rate_bps += module_fec_rate; | 913 *sent_fec_rate_bps += module_fec_rate; |
902 } | 914 } |
903 return 0; | 915 return 0; |
904 } | 916 } |
905 | 917 |
906 } // namespace internal | 918 } // namespace internal |
907 } // namespace webrtc | 919 } // namespace webrtc |
OLD | NEW |