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

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

Issue 2564373002: Properly report number of quality downscales in stats. (Closed)
Patch Set: tests passing Created 4 years 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) 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" 17 #include "webrtc/modules/video_coding/include/video_codec_initializer.h"
18 #include "webrtc/base/arraysize.h"
18 #include "webrtc/base/checks.h" 19 #include "webrtc/base/checks.h"
19 #include "webrtc/base/logging.h" 20 #include "webrtc/base/logging.h"
20 #include "webrtc/base/trace_event.h" 21 #include "webrtc/base/trace_event.h"
21 #include "webrtc/base/timeutils.h" 22 #include "webrtc/base/timeutils.h"
22 #include "webrtc/common_video/include/video_bitrate_allocator.h" 23 #include "webrtc/common_video/include/video_bitrate_allocator.h"
23 #include "webrtc/modules/pacing/paced_sender.h" 24 #include "webrtc/modules/pacing/paced_sender.h"
24 #include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h" 25 #include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h"
25 #include "webrtc/modules/video_coding/include/video_coding.h" 26 #include "webrtc/modules/video_coding/include/video_coding.h"
26 #include "webrtc/modules/video_coding/include/video_coding_defines.h" 27 #include "webrtc/modules/video_coding/include/video_coding_defines.h"
27 #include "webrtc/video/overuse_frame_detector.h" 28 #include "webrtc/video/overuse_frame_detector.h"
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 encoder_start_bitrate_bps_(0), 256 encoder_start_bitrate_bps_(0),
256 max_data_payload_length_(0), 257 max_data_payload_length_(0),
257 nack_enabled_(false), 258 nack_enabled_(false),
258 last_observed_bitrate_bps_(0), 259 last_observed_bitrate_bps_(0),
259 encoder_paused_and_dropped_frame_(false), 260 encoder_paused_and_dropped_frame_(false),
260 has_received_sli_(false), 261 has_received_sli_(false),
261 picture_id_sli_(0), 262 picture_id_sli_(0),
262 has_received_rpsi_(false), 263 has_received_rpsi_(false),
263 picture_id_rpsi_(0), 264 picture_id_rpsi_(0),
264 clock_(Clock::GetRealTimeClock()), 265 clock_(Clock::GetRealTimeClock()),
266 scale_counter_(kScaleReasonSize, 0),
265 last_frame_width_(0), 267 last_frame_width_(0),
266 last_frame_height_(0), 268 last_frame_height_(0),
267 last_captured_timestamp_(0), 269 last_captured_timestamp_(0),
268 delta_ntp_internal_ms_(clock_->CurrentNtpInMilliseconds() - 270 delta_ntp_internal_ms_(clock_->CurrentNtpInMilliseconds() -
269 clock_->TimeInMilliseconds()), 271 clock_->TimeInMilliseconds()),
270 last_frame_log_ms_(clock_->TimeInMilliseconds()), 272 last_frame_log_ms_(clock_->TimeInMilliseconds()),
271 captured_frame_count_(0), 273 captured_frame_count_(0),
272 dropped_frame_count_(0), 274 dropped_frame_count_(0),
273 bitrate_observer_(nullptr), 275 bitrate_observer_(nullptr),
274 encoder_queue_("EncoderQueue") { 276 encoder_queue_("EncoderQueue") {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 rtc::VideoSourceInterface<VideoFrame>* source, 332 rtc::VideoSourceInterface<VideoFrame>* source,
331 const VideoSendStream::DegradationPreference& degradation_preference) { 333 const VideoSendStream::DegradationPreference& degradation_preference) {
332 RTC_DCHECK_RUN_ON(&thread_checker_); 334 RTC_DCHECK_RUN_ON(&thread_checker_);
333 source_proxy_->SetSource(source, degradation_preference); 335 source_proxy_->SetSource(source, degradation_preference);
334 encoder_queue_.PostTask([this, degradation_preference] { 336 encoder_queue_.PostTask([this, degradation_preference] {
335 RTC_DCHECK_RUN_ON(&encoder_queue_); 337 RTC_DCHECK_RUN_ON(&encoder_queue_);
336 scaling_enabled_ = 338 scaling_enabled_ =
337 (degradation_preference != 339 (degradation_preference !=
338 VideoSendStream::DegradationPreference::kMaintainResolution); 340 VideoSendStream::DegradationPreference::kMaintainResolution);
339 stats_proxy_->SetResolutionRestrictionStats( 341 stats_proxy_->SetResolutionRestrictionStats(
340 scaling_enabled_ && scale_counter_[kQuality] > 0, 342 scaling_enabled_, scale_counter_[kCpu] > 0, scale_counter_[kQuality]);
341 scaling_enabled_ && scale_counter_[kCpu] > 0);
342 }); 343 });
343 } 344 }
344 345
345 void ViEEncoder::SetSink(EncoderSink* sink, bool rotation_applied) { 346 void ViEEncoder::SetSink(EncoderSink* sink, bool rotation_applied) {
346 source_proxy_->SetWantsRotationApplied(rotation_applied); 347 source_proxy_->SetWantsRotationApplied(rotation_applied);
347 encoder_queue_.PostTask([this, sink] { 348 encoder_queue_.PostTask([this, sink] {
348 RTC_DCHECK_RUN_ON(&encoder_queue_); 349 RTC_DCHECK_RUN_ON(&encoder_queue_);
349 sink_ = sink; 350 sink_ = sink;
350 }); 351 });
351 } 352 }
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 video_sender_.IntraFrameRequest(0); 584 video_sender_.IntraFrameRequest(0);
584 } 585 }
585 586
586 EncodedImageCallback::Result ViEEncoder::OnEncodedImage( 587 EncodedImageCallback::Result ViEEncoder::OnEncodedImage(
587 const EncodedImage& encoded_image, 588 const EncodedImage& encoded_image,
588 const CodecSpecificInfo* codec_specific_info, 589 const CodecSpecificInfo* codec_specific_info,
589 const RTPFragmentationHeader* fragmentation) { 590 const RTPFragmentationHeader* fragmentation) {
590 // Encoded is called on whatever thread the real encoder implementation run 591 // Encoded is called on whatever thread the real encoder implementation run
591 // on. In the case of hardware encoders, there might be several encoders 592 // on. In the case of hardware encoders, there might be several encoders
592 // running in parallel on different threads. 593 // running in parallel on different threads.
593 if (stats_proxy_) { 594 if (stats_proxy_)
594 stats_proxy_->OnSendEncodedImage(encoded_image, codec_specific_info); 595 stats_proxy_->OnSendEncodedImage(encoded_image, codec_specific_info);
595 }
596 596
597 EncodedImageCallback::Result result = 597 EncodedImageCallback::Result result =
598 sink_->OnEncodedImage(encoded_image, codec_specific_info, fragmentation); 598 sink_->OnEncodedImage(encoded_image, codec_specific_info, fragmentation);
599 599
600 int64_t time_sent = clock_->TimeInMilliseconds(); 600 int64_t time_sent = clock_->TimeInMilliseconds();
601 uint32_t timestamp = encoded_image._timeStamp; 601 uint32_t timestamp = encoded_image._timeStamp;
602 const int qp = encoded_image.qp_; 602 const int qp = encoded_image.qp_;
603 encoder_queue_.PostTask([this, timestamp, time_sent, qp] { 603 encoder_queue_.PostTask([this, timestamp, time_sent, qp] {
604 RTC_DCHECK_RUN_ON(&encoder_queue_); 604 RTC_DCHECK_RUN_ON(&encoder_queue_);
605 overuse_detector_.FrameSent(timestamp, time_sent); 605 overuse_detector_.FrameSent(timestamp, time_sent);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 RTC_DCHECK_RUN_ON(&encoder_queue_); 694 RTC_DCHECK_RUN_ON(&encoder_queue_);
695 if (!scaling_enabled_) 695 if (!scaling_enabled_)
696 return; 696 return;
697 // Request lower resolution if the current resolution is lower than last time 697 // Request lower resolution if the current resolution is lower than last time
698 // we asked for the resolution to be lowered. 698 // we asked for the resolution to be lowered.
699 int current_pixel_count = last_frame_height_ * last_frame_width_; 699 int current_pixel_count = last_frame_height_ * last_frame_width_;
700 if (max_pixel_count_ && current_pixel_count >= *max_pixel_count_) 700 if (max_pixel_count_ && current_pixel_count >= *max_pixel_count_)
701 return; 701 return;
702 switch (reason) { 702 switch (reason) {
703 case kQuality: 703 case kQuality:
704 stats_proxy_->OnQualityRestrictedResolutionChanged(true); 704 stats_proxy_->OnQualityRestrictedResolutionChanged(
705 scale_counter_[reason] + 1);
705 break; 706 break;
706 case kCpu: 707 case kCpu:
707 if (scale_counter_[reason] >= kMaxCpuDowngrades) 708 if (scale_counter_[reason] >= kMaxCpuDowngrades)
708 return; 709 return;
709 // Update stats accordingly. 710 // Update stats accordingly.
710 stats_proxy_->OnCpuRestrictedResolutionChanged(true); 711 stats_proxy_->OnCpuRestrictedResolutionChanged(true);
711 break; 712 break;
712 } 713 }
713 max_pixel_count_ = rtc::Optional<int>(current_pixel_count); 714 max_pixel_count_ = rtc::Optional<int>(current_pixel_count);
714 max_pixel_count_step_up_ = rtc::Optional<int>(); 715 max_pixel_count_step_up_ = rtc::Optional<int>();
(...skipping 11 matching lines...) Expand all
726 if (scale_counter_[reason] == 0 || !scaling_enabled_) 727 if (scale_counter_[reason] == 0 || !scaling_enabled_)
727 return; 728 return;
728 // Only scale if resolution is higher than last time 729 // Only scale if resolution is higher than last time
729 // we requested higher resolution. 730 // we requested higher resolution.
730 int current_pixel_count = last_frame_height_ * last_frame_width_; 731 int current_pixel_count = last_frame_height_ * last_frame_width_;
731 if (current_pixel_count <= max_pixel_count_step_up_.value_or(0)) 732 if (current_pixel_count <= max_pixel_count_step_up_.value_or(0))
732 return; 733 return;
733 switch (reason) { 734 switch (reason) {
734 case kQuality: 735 case kQuality:
735 stats_proxy_->OnQualityRestrictedResolutionChanged( 736 stats_proxy_->OnQualityRestrictedResolutionChanged(
736 scale_counter_[reason] > 1); 737 scale_counter_[reason] - 1);
737 break; 738 break;
738 case kCpu: 739 case kCpu:
739 // Update stats accordingly. 740 // Update stats accordingly.
740 stats_proxy_->OnCpuRestrictedResolutionChanged(scale_counter_[reason] > 741 stats_proxy_->OnCpuRestrictedResolutionChanged(scale_counter_[reason] >
741 1); 742 1);
742 break; 743 break;
743 } 744 }
744 max_pixel_count_ = rtc::Optional<int>(); 745 max_pixel_count_ = rtc::Optional<int>();
745 max_pixel_count_step_up_ = rtc::Optional<int>(current_pixel_count); 746 max_pixel_count_step_up_ = rtc::Optional<int>(current_pixel_count);
746 --scale_counter_[reason]; 747 --scale_counter_[reason];
747 source_proxy_->RequestHigherResolutionThan(current_pixel_count); 748 source_proxy_->RequestHigherResolutionThan(current_pixel_count);
748 LOG(LS_INFO) << "Scaling up resolution."; 749 LOG(LS_INFO) << "Scaling up resolution.";
749 for (size_t i = 0; i < kScaleReasonSize; ++i) { 750 for (size_t i = 0; i < kScaleReasonSize; ++i) {
750 LOG(LS_INFO) << "Scaled " << scale_counter_[i] 751 LOG(LS_INFO) << "Scaled " << scale_counter_[i]
751 << " times for reason: " << (i ? "quality" : "cpu"); 752 << " times for reason: " << (i ? "quality" : "cpu");
752 } 753 }
753 } 754 }
754 755
755 } // namespace webrtc 756 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698