OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 |
11 #include "webrtc/video/vie_encoder.h" | 11 #include "webrtc/video/vie_encoder.h" |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
14 #include <limits> | 14 #include <limits> |
15 #include <utility> | 15 #include <utility> |
16 | 16 |
17 #include "webrtc/modules/video_coding/include/video_codec_initializer.h" | |
18 #include "webrtc/base/arraysize.h" | 17 #include "webrtc/base/arraysize.h" |
19 #include "webrtc/base/checks.h" | 18 #include "webrtc/base/checks.h" |
20 #include "webrtc/base/logging.h" | 19 #include "webrtc/base/logging.h" |
21 #include "webrtc/base/trace_event.h" | 20 #include "webrtc/base/trace_event.h" |
22 #include "webrtc/base/timeutils.h" | 21 #include "webrtc/base/timeutils.h" |
23 #include "webrtc/common_video/include/video_bitrate_allocator.h" | 22 #include "webrtc/common_video/include/video_bitrate_allocator.h" |
24 #include "webrtc/modules/pacing/paced_sender.h" | 23 #include "webrtc/modules/pacing/paced_sender.h" |
25 #include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h" | 24 #include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h" |
| 25 #include "webrtc/modules/video_coding/include/video_codec_initializer.h" |
26 #include "webrtc/modules/video_coding/include/video_coding.h" | 26 #include "webrtc/modules/video_coding/include/video_coding.h" |
27 #include "webrtc/modules/video_coding/include/video_coding_defines.h" | 27 #include "webrtc/modules/video_coding/include/video_coding_defines.h" |
28 #include "webrtc/video/overuse_frame_detector.h" | 28 #include "webrtc/video/overuse_frame_detector.h" |
29 #include "webrtc/video/send_statistics_proxy.h" | 29 #include "webrtc/video/send_statistics_proxy.h" |
30 #include "webrtc/video_frame.h" | 30 #include "webrtc/video_frame.h" |
31 namespace webrtc { | 31 namespace webrtc { |
32 | 32 |
33 namespace { | 33 namespace { |
| 34 using DegradationPreference = VideoSendStream::DegradationPreference; |
| 35 |
34 // Time interval for logging frame counts. | 36 // Time interval for logging frame counts. |
35 const int64_t kFrameLogIntervalMs = 60000; | 37 const int64_t kFrameLogIntervalMs = 60000; |
36 // We will never ask for a resolution lower than this. | 38 // We will never ask for a resolution lower than this. |
37 #if defined(WEBRTC_ANDROID) | 39 #if defined(WEBRTC_ANDROID) |
38 // TODO(kthelgason): Lower this limit when better testing | 40 // TODO(kthelgason): Lower this limit when better testing |
39 // on MediaCodec and fallback implementations are in place. | 41 // on MediaCodec and fallback implementations are in place. |
40 const int kMinPixelsPerFrame = 320 * 180; | 42 const int kMinPixelsPerFrame = 320 * 180; |
41 #else | 43 #else |
42 const int kMinPixelsPerFrame = 120 * 90; | 44 const int kMinPixelsPerFrame = 120 * 90; |
43 #endif | 45 #endif |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 }; | 129 }; |
128 | 130 |
129 // VideoSourceProxy is responsible ensuring thread safety between calls to | 131 // VideoSourceProxy is responsible ensuring thread safety between calls to |
130 // ViEEncoder::SetSource that will happen on libjingle's worker thread when a | 132 // ViEEncoder::SetSource that will happen on libjingle's worker thread when a |
131 // video capturer is connected to the encoder and the encoder task queue | 133 // video capturer is connected to the encoder and the encoder task queue |
132 // (encoder_queue_) where the encoder reports its VideoSinkWants. | 134 // (encoder_queue_) where the encoder reports its VideoSinkWants. |
133 class ViEEncoder::VideoSourceProxy { | 135 class ViEEncoder::VideoSourceProxy { |
134 public: | 136 public: |
135 explicit VideoSourceProxy(ViEEncoder* vie_encoder) | 137 explicit VideoSourceProxy(ViEEncoder* vie_encoder) |
136 : vie_encoder_(vie_encoder), | 138 : vie_encoder_(vie_encoder), |
137 degradation_preference_( | 139 degradation_preference_(DegradationPreference::kMaintainResolution), |
138 VideoSendStream::DegradationPreference::kMaintainResolution), | |
139 source_(nullptr) {} | 140 source_(nullptr) {} |
140 | 141 |
141 void SetSource( | 142 void SetSource(rtc::VideoSourceInterface<VideoFrame>* source, |
142 rtc::VideoSourceInterface<VideoFrame>* source, | 143 const DegradationPreference& degradation_preference) { |
143 const VideoSendStream::DegradationPreference& degradation_preference) { | |
144 // Called on libjingle's worker thread. | 144 // Called on libjingle's worker thread. |
145 RTC_DCHECK_CALLED_SEQUENTIALLY(&main_checker_); | 145 RTC_DCHECK_CALLED_SEQUENTIALLY(&main_checker_); |
146 rtc::VideoSourceInterface<VideoFrame>* old_source = nullptr; | 146 rtc::VideoSourceInterface<VideoFrame>* old_source = nullptr; |
147 rtc::VideoSinkWants wants; | 147 rtc::VideoSinkWants wants; |
148 { | 148 { |
149 rtc::CritScope lock(&crit_); | 149 rtc::CritScope lock(&crit_); |
150 old_source = source_; | 150 old_source = source_; |
151 source_ = source; | 151 source_ = source; |
152 degradation_preference_ = degradation_preference; | 152 degradation_preference_ = degradation_preference; |
153 wants = current_wants(); | 153 wants = current_wants(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 sink_wants_.max_pixel_count_step_up = rtc::Optional<int>(); | 192 sink_wants_.max_pixel_count_step_up = rtc::Optional<int>(); |
193 if (source_) | 193 if (source_) |
194 source_->AddOrUpdateSink(vie_encoder_, sink_wants_); | 194 source_->AddOrUpdateSink(vie_encoder_, sink_wants_); |
195 } | 195 } |
196 | 196 |
197 void RequestHigherResolutionThan(int pixel_count) { | 197 void RequestHigherResolutionThan(int pixel_count) { |
198 rtc::CritScope lock(&crit_); | 198 rtc::CritScope lock(&crit_); |
199 if (!IsResolutionScalingEnabledLocked()) { | 199 if (!IsResolutionScalingEnabledLocked()) { |
200 // This can happen since |degradation_preference_| is set on | 200 // This can happen since |degradation_preference_| is set on |
201 // libjingle's worker thread but the adaptation is done on the encoder | 201 // libjingle's worker thread but the adaptation is done on the encoder |
202 // task | 202 // task queue. |
203 // queue. | |
204 return; | 203 return; |
205 } | 204 } |
206 // The input video frame size will have a resolution with "one step up" | 205 // The input video frame size will have a resolution with "one step up" |
207 // pixels than |max_pixel_count_step_up| where "one step up" depends on | 206 // pixels than |max_pixel_count_step_up| where "one step up" depends on |
208 // how the source can scale the input frame size. | 207 // how the source can scale the input frame size. |
209 sink_wants_.max_pixel_count = rtc::Optional<int>(); | 208 sink_wants_.max_pixel_count = rtc::Optional<int>(); |
210 sink_wants_.max_pixel_count_step_up = rtc::Optional<int>(pixel_count); | 209 sink_wants_.max_pixel_count_step_up = rtc::Optional<int>(pixel_count); |
211 if (source_) | 210 if (source_) |
212 source_->AddOrUpdateSink(vie_encoder_, sink_wants_); | 211 source_->AddOrUpdateSink(vie_encoder_, sink_wants_); |
213 } | 212 } |
214 | 213 |
215 private: | 214 private: |
216 bool IsResolutionScalingEnabledLocked() const | 215 bool IsResolutionScalingEnabledLocked() const |
217 EXCLUSIVE_LOCKS_REQUIRED(&crit_) { | 216 EXCLUSIVE_LOCKS_REQUIRED(&crit_) { |
218 return degradation_preference_ != | 217 return degradation_preference_ != |
219 VideoSendStream::DegradationPreference::kMaintainResolution; | 218 DegradationPreference::kMaintainResolution; |
220 } | 219 } |
221 | 220 |
222 const rtc::VideoSinkWants& current_wants() const | 221 const rtc::VideoSinkWants& current_wants() const |
223 EXCLUSIVE_LOCKS_REQUIRED(&crit_) { | 222 EXCLUSIVE_LOCKS_REQUIRED(&crit_) { |
224 return IsResolutionScalingEnabledLocked() ? sink_wants_ | 223 return IsResolutionScalingEnabledLocked() ? sink_wants_ |
225 : disabled_scaling_sink_wants_; | 224 : disabled_scaling_sink_wants_; |
226 } | 225 } |
227 | 226 |
228 rtc::CriticalSection crit_; | 227 rtc::CriticalSection crit_; |
229 rtc::SequencedTaskChecker main_checker_; | 228 rtc::SequencedTaskChecker main_checker_; |
230 ViEEncoder* const vie_encoder_; | 229 ViEEncoder* const vie_encoder_; |
231 rtc::VideoSinkWants sink_wants_ GUARDED_BY(&crit_); | 230 rtc::VideoSinkWants sink_wants_ GUARDED_BY(&crit_); |
232 rtc::VideoSinkWants disabled_scaling_sink_wants_ GUARDED_BY(&crit_); | 231 rtc::VideoSinkWants disabled_scaling_sink_wants_ GUARDED_BY(&crit_); |
233 VideoSendStream::DegradationPreference degradation_preference_ | 232 DegradationPreference degradation_preference_ GUARDED_BY(&crit_); |
234 GUARDED_BY(&crit_); | |
235 rtc::VideoSourceInterface<VideoFrame>* source_ GUARDED_BY(&crit_); | 233 rtc::VideoSourceInterface<VideoFrame>* source_ GUARDED_BY(&crit_); |
236 | 234 |
237 RTC_DISALLOW_COPY_AND_ASSIGN(VideoSourceProxy); | 235 RTC_DISALLOW_COPY_AND_ASSIGN(VideoSourceProxy); |
238 }; | 236 }; |
239 | 237 |
240 ViEEncoder::ViEEncoder(uint32_t number_of_cores, | 238 ViEEncoder::ViEEncoder(uint32_t number_of_cores, |
241 SendStatisticsProxy* stats_proxy, | 239 SendStatisticsProxy* stats_proxy, |
242 const VideoSendStream::Config::EncoderSettings& settings, | 240 const VideoSendStream::Config::EncoderSettings& settings, |
243 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback, | 241 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback, |
244 EncodedFrameObserver* encoder_timing) | 242 EncodedFrameObserver* encoder_timing) |
(...skipping 17 matching lines...) Expand all Loading... |
262 max_data_payload_length_(0), | 260 max_data_payload_length_(0), |
263 nack_enabled_(false), | 261 nack_enabled_(false), |
264 last_observed_bitrate_bps_(0), | 262 last_observed_bitrate_bps_(0), |
265 encoder_paused_and_dropped_frame_(false), | 263 encoder_paused_and_dropped_frame_(false), |
266 has_received_sli_(false), | 264 has_received_sli_(false), |
267 picture_id_sli_(0), | 265 picture_id_sli_(0), |
268 has_received_rpsi_(false), | 266 has_received_rpsi_(false), |
269 picture_id_rpsi_(0), | 267 picture_id_rpsi_(0), |
270 clock_(Clock::GetRealTimeClock()), | 268 clock_(Clock::GetRealTimeClock()), |
271 scale_counter_(kScaleReasonSize, 0), | 269 scale_counter_(kScaleReasonSize, 0), |
| 270 degradation_preference_(DegradationPreference::kMaintainResolution), |
272 last_captured_timestamp_(0), | 271 last_captured_timestamp_(0), |
273 delta_ntp_internal_ms_(clock_->CurrentNtpInMilliseconds() - | 272 delta_ntp_internal_ms_(clock_->CurrentNtpInMilliseconds() - |
274 clock_->TimeInMilliseconds()), | 273 clock_->TimeInMilliseconds()), |
275 last_frame_log_ms_(clock_->TimeInMilliseconds()), | 274 last_frame_log_ms_(clock_->TimeInMilliseconds()), |
276 captured_frame_count_(0), | 275 captured_frame_count_(0), |
277 dropped_frame_count_(0), | 276 dropped_frame_count_(0), |
278 bitrate_observer_(nullptr), | 277 bitrate_observer_(nullptr), |
279 encoder_queue_("EncoderQueue") { | 278 encoder_queue_("EncoderQueue") { |
280 encoder_queue_.PostTask([this] { | 279 encoder_queue_.PostTask([this] { |
281 RTC_DCHECK_RUN_ON(&encoder_queue_); | 280 RTC_DCHECK_RUN_ON(&encoder_queue_); |
282 overuse_detector_.StartCheckForOveruse(); | 281 overuse_detector_.StartCheckForOveruse(); |
283 video_sender_.RegisterExternalEncoder( | 282 video_sender_.RegisterExternalEncoder( |
284 settings_.encoder, settings_.payload_type, settings_.internal_source); | 283 settings_.encoder, settings_.payload_type, settings_.internal_source); |
285 }); | 284 }); |
286 } | 285 } |
287 | 286 |
288 ViEEncoder::~ViEEncoder() { | 287 ViEEncoder::~ViEEncoder() { |
289 RTC_DCHECK_RUN_ON(&thread_checker_); | 288 RTC_DCHECK_RUN_ON(&thread_checker_); |
290 RTC_DCHECK(shutdown_event_.Wait(0)) | 289 RTC_DCHECK(shutdown_event_.Wait(0)) |
291 << "Must call ::Stop() before destruction."; | 290 << "Must call ::Stop() before destruction."; |
292 } | 291 } |
293 | 292 |
294 void ViEEncoder::Stop() { | 293 void ViEEncoder::Stop() { |
295 RTC_DCHECK_RUN_ON(&thread_checker_); | 294 RTC_DCHECK_RUN_ON(&thread_checker_); |
296 source_proxy_->SetSource(nullptr, VideoSendStream::DegradationPreference()); | 295 source_proxy_->SetSource(nullptr, DegradationPreference()); |
297 encoder_queue_.PostTask([this] { | 296 encoder_queue_.PostTask([this] { |
298 RTC_DCHECK_RUN_ON(&encoder_queue_); | 297 RTC_DCHECK_RUN_ON(&encoder_queue_); |
299 overuse_detector_.StopCheckForOveruse(); | 298 overuse_detector_.StopCheckForOveruse(); |
300 rate_allocator_.reset(); | 299 rate_allocator_.reset(); |
301 bitrate_observer_ = nullptr; | 300 bitrate_observer_ = nullptr; |
302 video_sender_.RegisterExternalEncoder(nullptr, settings_.payload_type, | 301 video_sender_.RegisterExternalEncoder(nullptr, settings_.payload_type, |
303 false); | 302 false); |
304 quality_scaler_ = nullptr; | 303 quality_scaler_ = nullptr; |
305 shutdown_event_.Set(); | 304 shutdown_event_.Set(); |
306 }); | 305 }); |
(...skipping 24 matching lines...) Expand all Loading... |
331 }); | 330 }); |
332 } | 331 } |
333 | 332 |
334 void ViEEncoder::SetSource( | 333 void ViEEncoder::SetSource( |
335 rtc::VideoSourceInterface<VideoFrame>* source, | 334 rtc::VideoSourceInterface<VideoFrame>* source, |
336 const VideoSendStream::DegradationPreference& degradation_preference) { | 335 const VideoSendStream::DegradationPreference& degradation_preference) { |
337 RTC_DCHECK_RUN_ON(&thread_checker_); | 336 RTC_DCHECK_RUN_ON(&thread_checker_); |
338 source_proxy_->SetSource(source, degradation_preference); | 337 source_proxy_->SetSource(source, degradation_preference); |
339 encoder_queue_.PostTask([this, degradation_preference] { | 338 encoder_queue_.PostTask([this, degradation_preference] { |
340 RTC_DCHECK_RUN_ON(&encoder_queue_); | 339 RTC_DCHECK_RUN_ON(&encoder_queue_); |
341 scaling_enabled_ = (degradation_preference != | 340 degradation_preference_ = degradation_preference; |
342 VideoSendStream::DegradationPreference::kMaintainResolution); | |
343 stats_proxy_->SetResolutionRestrictionStats( | 341 stats_proxy_->SetResolutionRestrictionStats( |
344 scaling_enabled_, scale_counter_[kCpu] > 0, scale_counter_[kQuality]); | 342 degradation_preference != |
| 343 VideoSendStream::DegradationPreference::kMaintainResolution, |
| 344 scale_counter_[kCpu] > 0, scale_counter_[kQuality]); |
345 }); | 345 }); |
346 } | 346 } |
347 | 347 |
348 void ViEEncoder::SetSink(EncoderSink* sink, bool rotation_applied) { | 348 void ViEEncoder::SetSink(EncoderSink* sink, bool rotation_applied) { |
349 source_proxy_->SetWantsRotationApplied(rotation_applied); | 349 source_proxy_->SetWantsRotationApplied(rotation_applied); |
350 encoder_queue_.PostTask([this, sink] { | 350 encoder_queue_.PostTask([this, sink] { |
351 RTC_DCHECK_RUN_ON(&encoder_queue_); | 351 RTC_DCHECK_RUN_ON(&encoder_queue_); |
352 sink_ = sink; | 352 sink_ = sink; |
353 }); | 353 }); |
354 } | 354 } |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 stats_proxy_->OnEncoderReconfigured( | 430 stats_proxy_->OnEncoderReconfigured( |
431 encoder_config_, rate_allocator_->GetPreferredBitrateBps(framerate)); | 431 encoder_config_, rate_allocator_->GetPreferredBitrateBps(framerate)); |
432 } | 432 } |
433 | 433 |
434 pending_encoder_reconfiguration_ = false; | 434 pending_encoder_reconfiguration_ = false; |
435 | 435 |
436 sink_->OnEncoderConfigurationChanged( | 436 sink_->OnEncoderConfigurationChanged( |
437 std::move(streams), encoder_config_.min_transmit_bitrate_bps); | 437 std::move(streams), encoder_config_.min_transmit_bitrate_bps); |
438 | 438 |
439 const auto scaling_settings = settings_.encoder->GetScalingSettings(); | 439 const auto scaling_settings = settings_.encoder->GetScalingSettings(); |
440 if (scaling_enabled_ && scaling_settings.enabled) { | 440 if (degradation_preference_ != DegradationPreference::kMaintainResolution && |
| 441 scaling_settings.enabled) { |
441 if (scaling_settings.thresholds) { | 442 if (scaling_settings.thresholds) { |
442 quality_scaler_.reset( | 443 quality_scaler_.reset( |
443 new QualityScaler(this, *(scaling_settings.thresholds))); | 444 new QualityScaler(this, *(scaling_settings.thresholds))); |
444 } else { | 445 } else { |
445 quality_scaler_.reset(new QualityScaler(this, codec_type_)); | 446 quality_scaler_.reset(new QualityScaler(this, codec_type_)); |
446 } | 447 } |
447 } else { | 448 } else { |
448 quality_scaler_.reset(nullptr); | 449 quality_scaler_.reset(nullptr); |
449 stats_proxy_->SetResolutionRestrictionStats( | 450 stats_proxy_->SetResolutionRestrictionStats( |
450 false, scale_counter_[kCpu] > 0, scale_counter_[kQuality]); | 451 false, scale_counter_[kCpu] > 0, scale_counter_[kQuality]); |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 bool video_suspension_changed = video_is_suspended != EncoderPaused(); | 692 bool video_suspension_changed = video_is_suspended != EncoderPaused(); |
692 last_observed_bitrate_bps_ = bitrate_bps; | 693 last_observed_bitrate_bps_ = bitrate_bps; |
693 | 694 |
694 if (stats_proxy_ && video_suspension_changed) { | 695 if (stats_proxy_ && video_suspension_changed) { |
695 LOG(LS_INFO) << "Video suspend state changed to: " | 696 LOG(LS_INFO) << "Video suspend state changed to: " |
696 << (video_is_suspended ? "suspended" : "not suspended"); | 697 << (video_is_suspended ? "suspended" : "not suspended"); |
697 stats_proxy_->OnSuspendChange(video_is_suspended); | 698 stats_proxy_->OnSuspendChange(video_is_suspended); |
698 } | 699 } |
699 } | 700 } |
700 | 701 |
701 void ViEEncoder::ScaleDown(ScaleReason reason) { | 702 void ViEEncoder::AdaptDown(AdaptReason reason) { |
702 RTC_DCHECK_RUN_ON(&encoder_queue_); | 703 RTC_DCHECK_RUN_ON(&encoder_queue_); |
703 if (!scaling_enabled_) | 704 if (degradation_preference_ != DegradationPreference::kBalanced) |
704 return; | 705 return; |
705 // Request lower resolution if the current resolution is lower than last time | 706 // Request lower resolution if the current resolution is lower than last time |
706 // we asked for the resolution to be lowered. | 707 // we asked for the resolution to be lowered. |
707 int current_pixel_count = | 708 int current_pixel_count = |
708 last_frame_info_ ? last_frame_info_->pixel_count() : 0; | 709 last_frame_info_ ? last_frame_info_->pixel_count() : 0; |
709 if (max_pixel_count_ && current_pixel_count >= *max_pixel_count_) | 710 if (max_pixel_count_ && current_pixel_count >= *max_pixel_count_) |
710 return; | 711 return; |
711 switch (reason) { | 712 switch (reason) { |
712 case kQuality: | 713 case kQuality: |
713 stats_proxy_->OnQualityRestrictedResolutionChanged( | 714 stats_proxy_->OnQualityRestrictedResolutionChanged( |
(...skipping 10 matching lines...) Expand all Loading... |
724 max_pixel_count_step_up_ = rtc::Optional<int>(); | 725 max_pixel_count_step_up_ = rtc::Optional<int>(); |
725 ++scale_counter_[reason]; | 726 ++scale_counter_[reason]; |
726 source_proxy_->RequestResolutionLowerThan(current_pixel_count); | 727 source_proxy_->RequestResolutionLowerThan(current_pixel_count); |
727 LOG(LS_INFO) << "Scaling down resolution."; | 728 LOG(LS_INFO) << "Scaling down resolution."; |
728 for (size_t i = 0; i < kScaleReasonSize; ++i) { | 729 for (size_t i = 0; i < kScaleReasonSize; ++i) { |
729 LOG(LS_INFO) << "Scaled " << scale_counter_[i] | 730 LOG(LS_INFO) << "Scaled " << scale_counter_[i] |
730 << " times for reason: " << (i ? "cpu" : "quality"); | 731 << " times for reason: " << (i ? "cpu" : "quality"); |
731 } | 732 } |
732 } | 733 } |
733 | 734 |
734 void ViEEncoder::ScaleUp(ScaleReason reason) { | 735 void ViEEncoder::AdaptUp(AdaptReason reason) { |
735 RTC_DCHECK_RUN_ON(&encoder_queue_); | 736 RTC_DCHECK_RUN_ON(&encoder_queue_); |
736 if (scale_counter_[reason] == 0 || !scaling_enabled_) | 737 if (scale_counter_[reason] == 0 || |
| 738 degradation_preference_ != DegradationPreference::kBalanced) { |
737 return; | 739 return; |
| 740 } |
738 // Only scale if resolution is higher than last time | 741 // Only scale if resolution is higher than last time |
739 // we requested higher resolution. | 742 // we requested higher resolution. |
740 int current_pixel_count = | 743 int current_pixel_count = |
741 last_frame_info_ ? last_frame_info_->pixel_count() : 0; | 744 last_frame_info_ ? last_frame_info_->pixel_count() : 0; |
742 if (current_pixel_count <= max_pixel_count_step_up_.value_or(0)) | 745 if (current_pixel_count <= max_pixel_count_step_up_.value_or(0)) |
743 return; | 746 return; |
744 switch (reason) { | 747 switch (reason) { |
745 case kQuality: | 748 case kQuality: |
746 stats_proxy_->OnQualityRestrictedResolutionChanged( | 749 stats_proxy_->OnQualityRestrictedResolutionChanged( |
747 scale_counter_[reason] - 1); | 750 scale_counter_[reason] - 1); |
748 break; | 751 break; |
749 case kCpu: | 752 case kCpu: |
750 // Update stats accordingly. | 753 // Update stats accordingly. |
751 stats_proxy_->OnCpuRestrictedResolutionChanged(scale_counter_[reason] > | 754 stats_proxy_->OnCpuRestrictedResolutionChanged(scale_counter_[reason] > |
752 1); | 755 1); |
753 break; | 756 break; |
754 } | 757 } |
755 max_pixel_count_ = rtc::Optional<int>(); | 758 max_pixel_count_ = rtc::Optional<int>(); |
756 max_pixel_count_step_up_ = rtc::Optional<int>(current_pixel_count); | 759 max_pixel_count_step_up_ = rtc::Optional<int>(current_pixel_count); |
757 --scale_counter_[reason]; | 760 --scale_counter_[reason]; |
758 source_proxy_->RequestHigherResolutionThan(current_pixel_count); | 761 source_proxy_->RequestHigherResolutionThan(current_pixel_count); |
759 LOG(LS_INFO) << "Scaling up resolution."; | 762 LOG(LS_INFO) << "Scaling up resolution."; |
760 for (size_t i = 0; i < kScaleReasonSize; ++i) { | 763 for (size_t i = 0; i < kScaleReasonSize; ++i) { |
761 LOG(LS_INFO) << "Scaled " << scale_counter_[i] | 764 LOG(LS_INFO) << "Scaled " << scale_counter_[i] |
762 << " times for reason: " << (i ? "cpu" : "quality"); | 765 << " times for reason: " << (i ? "cpu" : "quality"); |
763 } | 766 } |
764 } | 767 } |
765 | 768 |
766 } // namespace webrtc | 769 } // namespace webrtc |
OLD | NEW |