OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 const int kVideoRtpBufferSize = 65536; | 364 const int kVideoRtpBufferSize = 65536; |
365 | 365 |
366 // This constant is really an on/off, lower-level configurable NACK history | 366 // This constant is really an on/off, lower-level configurable NACK history |
367 // duration hasn't been implemented. | 367 // duration hasn't been implemented. |
368 static const int kNackHistoryMs = 1000; | 368 static const int kNackHistoryMs = 1000; |
369 | 369 |
370 static const int kDefaultQpMax = 56; | 370 static const int kDefaultQpMax = 56; |
371 | 371 |
372 static const int kDefaultRtcpReceiverReportSsrc = 1; | 372 static const int kDefaultRtcpReceiverReportSsrc = 1; |
373 | 373 |
| 374 // Down grade resolution at most 2 times for CPU reasons. |
| 375 static const int kMaxCpuDowngrades = 2; |
| 376 |
374 std::vector<VideoCodec> DefaultVideoCodecList() { | 377 std::vector<VideoCodec> DefaultVideoCodecList() { |
375 std::vector<VideoCodec> codecs; | 378 std::vector<VideoCodec> codecs; |
376 codecs.push_back(MakeVideoCodecWithDefaultFeedbackParams(kDefaultVp8PlType, | 379 codecs.push_back(MakeVideoCodecWithDefaultFeedbackParams(kDefaultVp8PlType, |
377 kVp8CodecName)); | 380 kVp8CodecName)); |
378 codecs.push_back( | 381 codecs.push_back( |
379 VideoCodec::CreateRtxCodec(kDefaultRtxVp8PlType, kDefaultVp8PlType)); | 382 VideoCodec::CreateRtxCodec(kDefaultRtxVp8PlType, kDefaultVp8PlType)); |
380 if (CodecIsInternallySupported(kVp9CodecName)) { | 383 if (CodecIsInternallySupported(kVp9CodecName)) { |
381 codecs.push_back(MakeVideoCodecWithDefaultFeedbackParams(kDefaultVp9PlType, | 384 codecs.push_back(MakeVideoCodecWithDefaultFeedbackParams(kDefaultVp9PlType, |
382 kVp9CodecName)); | 385 kVp9CodecName)); |
383 codecs.push_back( | 386 codecs.push_back( |
(...skipping 1441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1825 recreate_stream = false; // SetCodec has already recreated the stream. | 1828 recreate_stream = false; // SetCodec has already recreated the stream. |
1826 } else if (params.conference_mode && parameters_.codec_settings) { | 1829 } else if (params.conference_mode && parameters_.codec_settings) { |
1827 SetCodec(*parameters_.codec_settings); | 1830 SetCodec(*parameters_.codec_settings); |
1828 recreate_stream = false; // SetCodec has already recreated the stream. | 1831 recreate_stream = false; // SetCodec has already recreated the stream. |
1829 } | 1832 } |
1830 if (recreate_stream) { | 1833 if (recreate_stream) { |
1831 LOG(LS_INFO) | 1834 LOG(LS_INFO) |
1832 << "RecreateWebRtcStream (send) because of SetSendParameters"; | 1835 << "RecreateWebRtcStream (send) because of SetSendParameters"; |
1833 RecreateWebRtcStream(); | 1836 RecreateWebRtcStream(); |
1834 } | 1837 } |
1835 } // release |lock_| | 1838 } // release |lock_| |
1836 | 1839 |
1837 // |capturer_->AddOrUpdateSink| may not be called while holding |lock_| since | 1840 // |capturer_->AddOrUpdateSink| may not be called while holding |lock_| since |
1838 // that might cause a lock order inversion. | 1841 // that might cause a lock order inversion. |
1839 if (params.rtp_header_extensions) { | 1842 if (params.rtp_header_extensions) { |
1840 sink_wants_.rotation_applied = !ContainsHeaderExtension( | 1843 sink_wants_.rotation_applied = !ContainsHeaderExtension( |
1841 *params.rtp_header_extensions, kRtpVideoRotationHeaderExtension); | 1844 *params.rtp_header_extensions, kRtpVideoRotationHeaderExtension); |
1842 if (capturer_) { | 1845 if (capturer_) { |
1843 capturer_->AddOrUpdateSink(this, sink_wants_); | 1846 capturer_->AddOrUpdateSink(this, sink_wants_); |
1844 } | 1847 } |
1845 } | 1848 } |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2016 : "false") | 2019 : "false") |
2017 : "unset"); | 2020 : "unset"); |
2018 // Do not adapt resolution for screen content as this will likely result in | 2021 // Do not adapt resolution for screen content as this will likely result in |
2019 // blurry and unreadable text. | 2022 // blurry and unreadable text. |
2020 if (parameters_.options.is_screencast.value_or(false)) | 2023 if (parameters_.options.is_screencast.value_or(false)) |
2021 return; | 2024 return; |
2022 | 2025 |
2023 rtc::Optional<int> max_pixel_count; | 2026 rtc::Optional<int> max_pixel_count; |
2024 rtc::Optional<int> max_pixel_count_step_up; | 2027 rtc::Optional<int> max_pixel_count_step_up; |
2025 if (load == kOveruse) { | 2028 if (load == kOveruse) { |
2026 max_pixel_count = rtc::Optional<int>( | 2029 if (cpu_restricted_counter_ >= kMaxCpuDowngrades) { |
2027 (last_dimensions_.height * last_dimensions_.width) / 2); | 2030 return; |
| 2031 } |
| 2032 // The input video frame size will have a resolution with less than or |
| 2033 // equal to |max_pixel_count| depending on how the capturer can scale the |
| 2034 // input frame size. |
| 2035 max_pixel_count = rtc::Optional<int>( |
| 2036 (last_dimensions_.height * last_dimensions_.width * 3) / 5); |
2028 // Increase |number_of_cpu_adapt_changes_| if | 2037 // Increase |number_of_cpu_adapt_changes_| if |
2029 // sink_wants_.max_pixel_count will be changed since | 2038 // sink_wants_.max_pixel_count will be changed since |
2030 // last time |capturer_->AddOrUpdateSink| was called. That is, this will | 2039 // last time |capturer_->AddOrUpdateSink| was called. That is, this will |
2031 // result in a new request for the capturer to change resolution. | 2040 // result in a new request for the capturer to change resolution. |
2032 if (!sink_wants_.max_pixel_count || | 2041 if (!sink_wants_.max_pixel_count || |
2033 *sink_wants_.max_pixel_count > *max_pixel_count) { | 2042 *sink_wants_.max_pixel_count > *max_pixel_count) { |
2034 ++number_of_cpu_adapt_changes_; | 2043 ++number_of_cpu_adapt_changes_; |
2035 ++cpu_restricted_counter_; | 2044 ++cpu_restricted_counter_; |
2036 } | 2045 } |
2037 } else { | 2046 } else { |
2038 RTC_DCHECK(load == kUnderuse); | 2047 RTC_DCHECK(load == kUnderuse); |
| 2048 // The input video frame size will have a resolution with "one step up" |
| 2049 // pixels than |max_pixel_count_step_up| where "one step up" depends on |
| 2050 // how the capturer can scale the input frame size. |
2039 max_pixel_count_step_up = rtc::Optional<int>(last_dimensions_.height * | 2051 max_pixel_count_step_up = rtc::Optional<int>(last_dimensions_.height * |
2040 last_dimensions_.width); | 2052 last_dimensions_.width); |
2041 // Increase |number_of_cpu_adapt_changes_| if | 2053 // Increase |number_of_cpu_adapt_changes_| if |
2042 // sink_wants_.max_pixel_count_step_up will be changed since | 2054 // sink_wants_.max_pixel_count_step_up will be changed since |
2043 // last time |capturer_->AddOrUpdateSink| was called. That is, this will | 2055 // last time |capturer_->AddOrUpdateSink| was called. That is, this will |
2044 // result in a new request for the capturer to change resolution. | 2056 // result in a new request for the capturer to change resolution. |
2045 if (sink_wants_.max_pixel_count || | 2057 if (sink_wants_.max_pixel_count || |
2046 (sink_wants_.max_pixel_count_step_up && | 2058 (sink_wants_.max_pixel_count_step_up && |
2047 *sink_wants_.max_pixel_count_step_up < *max_pixel_count_step_up)) { | 2059 *sink_wants_.max_pixel_count_step_up < *max_pixel_count_step_up)) { |
2048 ++number_of_cpu_adapt_changes_; | 2060 ++number_of_cpu_adapt_changes_; |
(...skipping 29 matching lines...) Expand all Loading... |
2078 parameters_.encoder_config.streams[i].target_bitrate_bps; | 2090 parameters_.encoder_config.streams[i].target_bitrate_bps; |
2079 } | 2091 } |
2080 } | 2092 } |
2081 | 2093 |
2082 if (stream_ == NULL) | 2094 if (stream_ == NULL) |
2083 return info; | 2095 return info; |
2084 | 2096 |
2085 stats = stream_->GetStats(); | 2097 stats = stream_->GetStats(); |
2086 } | 2098 } |
2087 info.adapt_changes = number_of_cpu_adapt_changes_; | 2099 info.adapt_changes = number_of_cpu_adapt_changes_; |
2088 info.adapt_reason = cpu_restricted_counter_ <= 0 | 2100 info.adapt_reason = |
2089 ? CoordinatedVideoAdapter::ADAPTREASON_NONE | 2101 cpu_restricted_counter_ <= 0 ? ADAPTREASON_NONE : ADAPTREASON_CPU; |
2090 : CoordinatedVideoAdapter::ADAPTREASON_CPU; | |
2091 | 2102 |
2092 // Get bandwidth limitation info from stream_->GetStats(). | 2103 // Get bandwidth limitation info from stream_->GetStats(). |
2093 // Input resolution (output from video_adapter) can be further scaled down or | 2104 // Input resolution (output from video_adapter) can be further scaled down or |
2094 // higher video layer(s) can be dropped due to bitrate constraints. | 2105 // higher video layer(s) can be dropped due to bitrate constraints. |
2095 // Note, adapt_changes only include changes from the video_adapter. | 2106 // Note, adapt_changes only include changes from the video_adapter. |
2096 if (stats.bw_limited_resolution) | 2107 if (stats.bw_limited_resolution) |
2097 info.adapt_reason |= CoordinatedVideoAdapter::ADAPTREASON_BANDWIDTH; | 2108 info.adapt_reason |= ADAPTREASON_BANDWIDTH; |
2098 | 2109 |
2099 info.encoder_implementation_name = stats.encoder_implementation_name; | 2110 info.encoder_implementation_name = stats.encoder_implementation_name; |
2100 info.ssrc_groups = ssrc_groups_; | 2111 info.ssrc_groups = ssrc_groups_; |
2101 info.framerate_input = stats.input_frame_rate; | 2112 info.framerate_input = stats.input_frame_rate; |
2102 info.framerate_sent = stats.encode_frame_rate; | 2113 info.framerate_sent = stats.encode_frame_rate; |
2103 info.avg_encode_ms = stats.avg_encode_time_ms; | 2114 info.avg_encode_ms = stats.avg_encode_time_ms; |
2104 info.encode_usage_percent = stats.encode_usage_percent; | 2115 info.encode_usage_percent = stats.encode_usage_percent; |
2105 | 2116 |
2106 info.nominal_bitrate = stats.media_bitrate_bps; | 2117 info.nominal_bitrate = stats.media_bitrate_bps; |
2107 | 2118 |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2586 rtx_mapping[video_codecs[i].codec.id] != | 2597 rtx_mapping[video_codecs[i].codec.id] != |
2587 fec_settings.red_payload_type) { | 2598 fec_settings.red_payload_type) { |
2588 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; | 2599 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; |
2589 } | 2600 } |
2590 } | 2601 } |
2591 | 2602 |
2592 return video_codecs; | 2603 return video_codecs; |
2593 } | 2604 } |
2594 | 2605 |
2595 } // namespace cricket | 2606 } // namespace cricket |
OLD | NEW |