Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(420)

Side by Side Diff: webrtc/media/engine/webrtcvideoengine2.cc

Issue 1836043004: Cleanup the VideoAdapter (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Addressed nits. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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
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 if (capturer_) { 2103 if (capturer_) {
2093 VideoFormat last_captured_frame_format; 2104 VideoFormat last_captured_frame_format;
2094 capturer_->GetStats(&last_captured_frame_format); 2105 capturer_->GetStats(&last_captured_frame_format);
2095 info.input_frame_width = last_captured_frame_format.width; 2106 info.input_frame_width = last_captured_frame_format.width;
2096 info.input_frame_height = last_captured_frame_format.height; 2107 info.input_frame_height = last_captured_frame_format.height;
2097 } 2108 }
2098 2109
2099 // Get bandwidth limitation info from stream_->GetStats(). 2110 // Get bandwidth limitation info from stream_->GetStats().
2100 // Input resolution (output from video_adapter) can be further scaled down or 2111 // Input resolution (output from video_adapter) can be further scaled down or
2101 // higher video layer(s) can be dropped due to bitrate constraints. 2112 // higher video layer(s) can be dropped due to bitrate constraints.
2102 // Note, adapt_changes only include changes from the video_adapter. 2113 // Note, adapt_changes only include changes from the video_adapter.
2103 if (stats.bw_limited_resolution) 2114 if (stats.bw_limited_resolution)
2104 info.adapt_reason |= CoordinatedVideoAdapter::ADAPTREASON_BANDWIDTH; 2115 info.adapt_reason |= ADAPTREASON_BANDWIDTH;
2105 2116
2106 info.encoder_implementation_name = stats.encoder_implementation_name; 2117 info.encoder_implementation_name = stats.encoder_implementation_name;
2107 info.ssrc_groups = ssrc_groups_; 2118 info.ssrc_groups = ssrc_groups_;
2108 info.framerate_input = stats.input_frame_rate; 2119 info.framerate_input = stats.input_frame_rate;
2109 info.framerate_sent = stats.encode_frame_rate; 2120 info.framerate_sent = stats.encode_frame_rate;
2110 info.avg_encode_ms = stats.avg_encode_time_ms; 2121 info.avg_encode_ms = stats.avg_encode_time_ms;
2111 info.encode_usage_percent = stats.encode_usage_percent; 2122 info.encode_usage_percent = stats.encode_usage_percent;
2112 2123
2113 info.nominal_bitrate = stats.media_bitrate_bps; 2124 info.nominal_bitrate = stats.media_bitrate_bps;
2114 2125
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
2593 rtx_mapping[video_codecs[i].codec.id] != 2604 rtx_mapping[video_codecs[i].codec.id] !=
2594 fec_settings.red_payload_type) { 2605 fec_settings.red_payload_type) {
2595 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; 2606 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id];
2596 } 2607 }
2597 } 2608 }
2598 2609
2599 return video_codecs; 2610 return video_codecs;
2600 } 2611 }
2601 2612
2602 } // namespace cricket 2613 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698