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

Side by Side Diff: webrtc/video/vie_encoder.cc

Issue 2672793002: Change rtc::VideoSinkWants to have target and a max pixel count (Closed)
Patch Set: Fixed incorrect behavior in VideoAdapter, updated test Created 3 years, 10 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
« no previous file with comments | « webrtc/video/vie_encoder.h ('k') | webrtc/video/vie_encoder_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 // task queue. 182 // task queue.
183 return; 183 return;
184 } 184 }
185 // The input video frame size will have a resolution with less than or 185 // The input video frame size will have a resolution with less than or
186 // equal to |max_pixel_count| depending on how the source can scale the 186 // equal to |max_pixel_count| depending on how the source can scale the
187 // input frame size. 187 // input frame size.
188 const int pixels_wanted = (pixel_count * 3) / 5; 188 const int pixels_wanted = (pixel_count * 3) / 5;
189 if (pixels_wanted < kMinPixelsPerFrame) 189 if (pixels_wanted < kMinPixelsPerFrame)
190 return; 190 return;
191 sink_wants_.max_pixel_count = rtc::Optional<int>(pixels_wanted); 191 sink_wants_.max_pixel_count = rtc::Optional<int>(pixels_wanted);
192 sink_wants_.max_pixel_count_step_up = rtc::Optional<int>(); 192 sink_wants_.target_pixel_count = rtc::Optional<int>();
perkj_webrtc 2017/02/13 08:48:03 nit: isn the word target_pixel_count here equally
sprang_webrtc 2017/02/13 09:29:20 I think it makes sense, since we want the source t
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 queue. 202 // task queue.
203 return; 203 return;
204 } 204 }
205 // 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"
206 // 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
207 // how the source can scale the input frame size. 207 // how the source can scale the input frame size. We still cap the step up
208 sink_wants_.max_pixel_count = rtc::Optional<int>(); 208 // to be at most twice the number of pixels.
perkj_webrtc 2017/02/13 08:48:03 nope, you have limited to be 4* times the number
sprang_webrtc 2017/02/13 09:29:20 This whole comment is misleading. I'll put up CL t
209 sink_wants_.max_pixel_count_step_up = rtc::Optional<int>(pixel_count); 209 sink_wants_.target_pixel_count = rtc::Optional<int>((pixel_count * 5) / 3);
210 sink_wants_.max_pixel_count = rtc::Optional<int>(pixel_count * 4);
210 if (source_) 211 if (source_)
211 source_->AddOrUpdateSink(vie_encoder_, sink_wants_); 212 source_->AddOrUpdateSink(vie_encoder_, sink_wants_);
212 } 213 }
213 214
214 private: 215 private:
215 bool IsResolutionScalingEnabledLocked() const 216 bool IsResolutionScalingEnabledLocked() const
216 EXCLUSIVE_LOCKS_REQUIRED(&crit_) { 217 EXCLUSIVE_LOCKS_REQUIRED(&crit_) {
217 return degradation_preference_ != 218 return degradation_preference_ !=
218 DegradationPreference::kMaintainResolution; 219 DegradationPreference::kMaintainResolution;
219 } 220 }
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 610
610 EncodedImageCallback::Result result = 611 EncodedImageCallback::Result result =
611 sink_->OnEncodedImage(encoded_image, codec_specific_info, fragmentation); 612 sink_->OnEncodedImage(encoded_image, codec_specific_info, fragmentation);
612 613
613 int64_t time_sent_us = rtc::TimeMicros(); 614 int64_t time_sent_us = rtc::TimeMicros();
614 uint32_t timestamp = encoded_image._timeStamp; 615 uint32_t timestamp = encoded_image._timeStamp;
615 const int qp = encoded_image.qp_; 616 const int qp = encoded_image.qp_;
616 encoder_queue_.PostTask([this, timestamp, time_sent_us, qp] { 617 encoder_queue_.PostTask([this, timestamp, time_sent_us, qp] {
617 RTC_DCHECK_RUN_ON(&encoder_queue_); 618 RTC_DCHECK_RUN_ON(&encoder_queue_);
618 overuse_detector_.FrameSent(timestamp, time_sent_us); 619 overuse_detector_.FrameSent(timestamp, time_sent_us);
619 if (quality_scaler_) 620 if (quality_scaler_ && qp >= 0)
perkj_webrtc 2017/02/13 08:48:03 correct cl? Does this fix a bug?
sprang_webrtc 2017/02/13 09:29:20 Yes, if fixes a bug but it only seems to be trigge
620 quality_scaler_->ReportQP(qp); 621 quality_scaler_->ReportQP(qp);
621 }); 622 });
622 623
623 return result; 624 return result;
624 } 625 }
625 626
626 void ViEEncoder::OnDroppedFrame() { 627 void ViEEncoder::OnDroppedFrame() {
627 encoder_queue_.PostTask([this] { 628 encoder_queue_.PostTask([this] {
628 RTC_DCHECK_RUN_ON(&encoder_queue_); 629 RTC_DCHECK_RUN_ON(&encoder_queue_);
629 if (quality_scaler_) 630 if (quality_scaler_)
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 699
699 if (stats_proxy_ && video_suspension_changed) { 700 if (stats_proxy_ && video_suspension_changed) {
700 LOG(LS_INFO) << "Video suspend state changed to: " 701 LOG(LS_INFO) << "Video suspend state changed to: "
701 << (video_is_suspended ? "suspended" : "not suspended"); 702 << (video_is_suspended ? "suspended" : "not suspended");
702 stats_proxy_->OnSuspendChange(video_is_suspended); 703 stats_proxy_->OnSuspendChange(video_is_suspended);
703 } 704 }
704 } 705 }
705 706
706 void ViEEncoder::AdaptDown(AdaptReason reason) { 707 void ViEEncoder::AdaptDown(AdaptReason reason) {
707 RTC_DCHECK_RUN_ON(&encoder_queue_); 708 RTC_DCHECK_RUN_ON(&encoder_queue_);
708 if (degradation_preference_ != DegradationPreference::kBalanced) 709 if (degradation_preference_ != DegradationPreference::kBalanced ||
710 !last_frame_info_) {
perkj_webrtc 2017/02/13 08:48:03 Looks like a bug if last_frame_info_ = nullptr. Ho
sprang_webrtc 2017/02/13 09:29:20 I think some test triggered that. I may want to fi
709 return; 711 return;
710 // Request lower resolution if the current resolution is lower than last time 712 }
711 // we asked for the resolution to be lowered. 713 int current_pixel_count = last_frame_info_->pixel_count();
712 int current_pixel_count = 714 if (last_adaptation_request_ &&
713 last_frame_info_ ? last_frame_info_->pixel_count() : 0; 715 last_adaptation_request_->mode_ == AdaptationRequest::Mode::kAdaptDown &&
714 if (max_pixel_count_ && current_pixel_count >= *max_pixel_count_) 716 current_pixel_count >= last_adaptation_request_->input_pixel_count_) {
717 // Don't request lower resolution if the current resolution is not lower
718 // than the last time we asked for the resolution to be lowered.
715 return; 719 return;
720 }
721 last_adaptation_request_.emplace(AdaptationRequest{
722 current_pixel_count, AdaptationRequest::Mode::kAdaptDown});
723
716 switch (reason) { 724 switch (reason) {
717 case kQuality: 725 case kQuality:
718 stats_proxy_->OnQualityRestrictedResolutionChanged( 726 stats_proxy_->OnQualityRestrictedResolutionChanged(
719 scale_counter_[reason] + 1); 727 scale_counter_[reason] + 1);
720 break; 728 break;
721 case kCpu: 729 case kCpu:
722 if (scale_counter_[reason] >= kMaxCpuDowngrades) 730 if (scale_counter_[reason] >= kMaxCpuDowngrades)
723 return; 731 return;
724 // Update stats accordingly. 732 // Update stats accordingly.
725 stats_proxy_->OnCpuRestrictedResolutionChanged(true); 733 stats_proxy_->OnCpuRestrictedResolutionChanged(true);
726 break; 734 break;
727 } 735 }
728 max_pixel_count_ = rtc::Optional<int>(current_pixel_count);
729 max_pixel_count_step_up_ = rtc::Optional<int>();
730 ++scale_counter_[reason]; 736 ++scale_counter_[reason];
731 source_proxy_->RequestResolutionLowerThan(current_pixel_count); 737 source_proxy_->RequestResolutionLowerThan(current_pixel_count);
732 LOG(LS_INFO) << "Scaling down resolution."; 738 LOG(LS_INFO) << "Scaling down resolution.";
733 for (size_t i = 0; i < kScaleReasonSize; ++i) { 739 for (size_t i = 0; i < kScaleReasonSize; ++i) {
734 LOG(LS_INFO) << "Scaled " << scale_counter_[i] 740 LOG(LS_INFO) << "Scaled " << scale_counter_[i]
735 << " times for reason: " << (i ? "cpu" : "quality"); 741 << " times for reason: " << (i ? "cpu" : "quality");
736 } 742 }
737 } 743 }
738 744
739 void ViEEncoder::AdaptUp(AdaptReason reason) { 745 void ViEEncoder::AdaptUp(AdaptReason reason) {
740 RTC_DCHECK_RUN_ON(&encoder_queue_); 746 RTC_DCHECK_RUN_ON(&encoder_queue_);
741 if (scale_counter_[reason] == 0 || 747 if (scale_counter_[reason] == 0 ||
742 degradation_preference_ != DegradationPreference::kBalanced) { 748 degradation_preference_ != DegradationPreference::kBalanced ||
749 !last_frame_info_) {
743 return; 750 return;
744 } 751 }
745 // Only scale if resolution is higher than last time 752 // Only scale if resolution is higher than last time we requested higher
746 // we requested higher resolution. 753 // resolution.
747 int current_pixel_count = 754 int current_pixel_count = last_frame_info_->pixel_count();
748 last_frame_info_ ? last_frame_info_->pixel_count() : 0; 755 if (last_adaptation_request_ &&
749 if (current_pixel_count <= max_pixel_count_step_up_.value_or(0)) 756 last_adaptation_request_->mode_ == AdaptationRequest::Mode::kAdaptUp &&
757 current_pixel_count <= last_adaptation_request_->input_pixel_count_) {
758 // Don't request higher resolution if the current resolution is not higher
759 // than the last time we asked for the resolution to be higher.
750 return; 760 return;
761 }
762 last_adaptation_request_.emplace(AdaptationRequest{
763 current_pixel_count, AdaptationRequest::Mode::kAdaptUp});
764
751 switch (reason) { 765 switch (reason) {
752 case kQuality: 766 case kQuality:
753 stats_proxy_->OnQualityRestrictedResolutionChanged( 767 stats_proxy_->OnQualityRestrictedResolutionChanged(
754 scale_counter_[reason] - 1); 768 scale_counter_[reason] - 1);
755 break; 769 break;
756 case kCpu: 770 case kCpu:
757 // Update stats accordingly. 771 // Update stats accordingly.
758 stats_proxy_->OnCpuRestrictedResolutionChanged(scale_counter_[reason] > 772 stats_proxy_->OnCpuRestrictedResolutionChanged(scale_counter_[reason] >
759 1); 773 1);
760 break; 774 break;
761 } 775 }
762 max_pixel_count_ = rtc::Optional<int>();
763 max_pixel_count_step_up_ = rtc::Optional<int>(current_pixel_count);
764 --scale_counter_[reason]; 776 --scale_counter_[reason];
765 source_proxy_->RequestHigherResolutionThan(current_pixel_count); 777 source_proxy_->RequestHigherResolutionThan(current_pixel_count);
766 LOG(LS_INFO) << "Scaling up resolution."; 778 LOG(LS_INFO) << "Scaling up resolution.";
767 for (size_t i = 0; i < kScaleReasonSize; ++i) { 779 for (size_t i = 0; i < kScaleReasonSize; ++i) {
768 LOG(LS_INFO) << "Scaled " << scale_counter_[i] 780 LOG(LS_INFO) << "Scaled " << scale_counter_[i]
769 << " times for reason: " << (i ? "cpu" : "quality"); 781 << " times for reason: " << (i ? "cpu" : "quality");
770 } 782 }
771 } 783 }
772 784
773 } // namespace webrtc 785 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/vie_encoder.h ('k') | webrtc/video/vie_encoder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698