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

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

Issue 2871623002: Update video adaptation stats to support degradations in both resolution and framerate. (Closed)
Patch Set: address comments Created 3 years, 7 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 if (kbps > 0) { 65 if (kbps > 0) {
66 if (kbps < 300 /* qvga */) { 66 if (kbps < 300 /* qvga */) {
67 return 320 * 240; 67 return 320 * 240;
68 } else if (kbps < 500 /* vga */) { 68 } else if (kbps < 500 /* vga */) {
69 return 640 * 480; 69 return 640 * 480;
70 } 70 }
71 } 71 }
72 return std::numeric_limits<uint32_t>::max(); 72 return std::numeric_limits<uint32_t>::max();
73 } 73 }
74 74
75 bool IsResolutionScalingEnabled(
76 VideoSendStream::DegradationPreference degradation_preference) {
77 return degradation_preference ==
78 VideoSendStream::DegradationPreference::kMaintainFramerate ||
79 degradation_preference ==
80 VideoSendStream::DegradationPreference::kBalanced;
81 }
82
83 bool IsFramerateScalingEnabled(
84 VideoSendStream::DegradationPreference degradation_preference) {
85 return degradation_preference ==
86 VideoSendStream::DegradationPreference::kMaintainResolution ||
87 degradation_preference ==
88 VideoSendStream::DegradationPreference::kBalanced;
89 }
90
75 } // namespace 91 } // namespace
76 92
77 class ViEEncoder::ConfigureEncoderTask : public rtc::QueuedTask { 93 class ViEEncoder::ConfigureEncoderTask : public rtc::QueuedTask {
78 public: 94 public:
79 ConfigureEncoderTask(ViEEncoder* vie_encoder, 95 ConfigureEncoderTask(ViEEncoder* vie_encoder,
80 VideoEncoderConfig config, 96 VideoEncoderConfig config,
81 size_t max_data_payload_length, 97 size_t max_data_payload_length,
82 bool nack_enabled) 98 bool nack_enabled)
83 : vie_encoder_(vie_encoder), 99 : vie_encoder_(vie_encoder),
84 config_(std::move(config)), 100 config_(std::move(config)),
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 RTC_DCHECK_RUN_ON(&thread_checker_); 428 RTC_DCHECK_RUN_ON(&thread_checker_);
413 encoder_queue_.PostTask([this, bitrate_observer] { 429 encoder_queue_.PostTask([this, bitrate_observer] {
414 RTC_DCHECK_RUN_ON(&encoder_queue_); 430 RTC_DCHECK_RUN_ON(&encoder_queue_);
415 RTC_DCHECK(!bitrate_observer_); 431 RTC_DCHECK(!bitrate_observer_);
416 bitrate_observer_ = bitrate_observer; 432 bitrate_observer_ = bitrate_observer;
417 }); 433 });
418 } 434 }
419 435
420 void ViEEncoder::SetSource( 436 void ViEEncoder::SetSource(
421 rtc::VideoSourceInterface<VideoFrame>* source, 437 rtc::VideoSourceInterface<VideoFrame>* source,
422 const VideoSendStream::VideoSendStream::DegradationPreference& 438 const VideoSendStream::DegradationPreference& degradation_preference) {
423 degradation_preference) {
424 RTC_DCHECK_RUN_ON(&thread_checker_); 439 RTC_DCHECK_RUN_ON(&thread_checker_);
425 source_proxy_->SetSource(source, degradation_preference); 440 source_proxy_->SetSource(source, degradation_preference);
426 encoder_queue_.PostTask([this, degradation_preference] { 441 encoder_queue_.PostTask([this, degradation_preference] {
427 RTC_DCHECK_RUN_ON(&encoder_queue_); 442 RTC_DCHECK_RUN_ON(&encoder_queue_);
428 if (degradation_preference_ != degradation_preference) { 443 if (degradation_preference_ != degradation_preference) {
429 // Reset adaptation state, so that we're not tricked into thinking there's 444 // Reset adaptation state, so that we're not tricked into thinking there's
430 // an already pending request of the same type. 445 // an already pending request of the same type.
431 last_adaptation_request_.reset(); 446 last_adaptation_request_.reset();
432 } 447 }
433 degradation_preference_ = degradation_preference; 448 degradation_preference_ = degradation_preference;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 RTC_DCHECK_RUN_ON(&encoder_queue_); 554 RTC_DCHECK_RUN_ON(&encoder_queue_);
540 const auto scaling_settings = settings_.encoder->GetScalingSettings(); 555 const auto scaling_settings = settings_.encoder->GetScalingSettings();
541 const bool degradation_preference_allows_scaling = 556 const bool degradation_preference_allows_scaling =
542 degradation_preference_ == 557 degradation_preference_ ==
543 VideoSendStream::DegradationPreference::kMaintainFramerate || 558 VideoSendStream::DegradationPreference::kMaintainFramerate ||
544 degradation_preference_ == 559 degradation_preference_ ==
545 VideoSendStream::DegradationPreference::kBalanced; 560 VideoSendStream::DegradationPreference::kBalanced;
546 const bool quality_scaling_allowed = 561 const bool quality_scaling_allowed =
547 degradation_preference_allows_scaling && scaling_settings.enabled; 562 degradation_preference_allows_scaling && scaling_settings.enabled;
548 563
549 const std::vector<int>& scale_counters = GetScaleCounters();
550 stats_proxy_->SetCpuScalingStats(
551 degradation_preference_allows_scaling ? scale_counters[kCpu] : -1);
552 stats_proxy_->SetQualityScalingStats(
553 quality_scaling_allowed ? scale_counters[kQuality] : -1);
554
555 if (quality_scaling_allowed) { 564 if (quality_scaling_allowed) {
556 // Abort if quality scaler has already been configured. 565 if (quality_scaler_.get() == nullptr) {
557 if (quality_scaler_.get() != nullptr) 566 // Quality scaler has not already been configured.
558 return; 567 // Drop frames and scale down until desired quality is achieved.
559 // Drop frames and scale down until desired quality is achieved. 568 if (scaling_settings.thresholds) {
560 if (scaling_settings.thresholds) { 569 quality_scaler_.reset(
561 quality_scaler_.reset( 570 new QualityScaler(this, *(scaling_settings.thresholds)));
562 new QualityScaler(this, *(scaling_settings.thresholds))); 571 } else {
563 } else { 572 quality_scaler_.reset(new QualityScaler(this, codec_type_));
564 quality_scaler_.reset(new QualityScaler(this, codec_type_)); 573 }
565 } 574 }
566 } else { 575 } else {
567 quality_scaler_.reset(nullptr); 576 quality_scaler_.reset(nullptr);
568 initial_rampup_ = kMaxInitialFramedrop; 577 initial_rampup_ = kMaxInitialFramedrop;
569 } 578 }
579
580 stats_proxy_->SetAdaptationStats(GetActiveCounts(kCpu),
581 GetActiveCounts(kQuality));
570 } 582 }
571 583
572 void ViEEncoder::OnFrame(const VideoFrame& video_frame) { 584 void ViEEncoder::OnFrame(const VideoFrame& video_frame) {
573 RTC_DCHECK_RUNS_SERIALIZED(&incoming_frame_race_checker_); 585 RTC_DCHECK_RUNS_SERIALIZED(&incoming_frame_race_checker_);
574 VideoFrame incoming_frame = video_frame; 586 VideoFrame incoming_frame = video_frame;
575 587
576 // Local time in webrtc time base. 588 // Local time in webrtc time base.
577 int64_t current_time_us = clock_->TimeInMicroseconds(); 589 int64_t current_time_us = clock_->TimeInMicroseconds();
578 int64_t current_time_ms = current_time_us / rtc::kNumMicrosecsPerMillisec; 590 int64_t current_time_ms = current_time_us / rtc::kNumMicrosecsPerMillisec;
579 // TODO(nisse): This always overrides the incoming timestamp. Don't 591 // TODO(nisse): This always overrides the incoming timestamp. Don't
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 stats_proxy_->OnSuspendChange(video_is_suspended); 804 stats_proxy_->OnSuspendChange(video_is_suspended);
793 } 805 }
794 } 806 }
795 807
796 void ViEEncoder::AdaptDown(AdaptReason reason) { 808 void ViEEncoder::AdaptDown(AdaptReason reason) {
797 RTC_DCHECK_RUN_ON(&encoder_queue_); 809 RTC_DCHECK_RUN_ON(&encoder_queue_);
798 AdaptationRequest adaptation_request = { 810 AdaptationRequest adaptation_request = {
799 last_frame_info_->pixel_count(), 811 last_frame_info_->pixel_count(),
800 stats_proxy_->GetStats().input_frame_rate, 812 stats_proxy_->GetStats().input_frame_rate,
801 AdaptationRequest::Mode::kAdaptDown}; 813 AdaptationRequest::Mode::kAdaptDown};
814
802 bool downgrade_requested = 815 bool downgrade_requested =
803 last_adaptation_request_ && 816 last_adaptation_request_ &&
804 last_adaptation_request_->mode_ == AdaptationRequest::Mode::kAdaptDown; 817 last_adaptation_request_->mode_ == AdaptationRequest::Mode::kAdaptDown;
805 818
806 int max_downgrades = 0; 819 int max_downgrades = 0;
807 switch (degradation_preference_) { 820 switch (degradation_preference_) {
808 case VideoSendStream::DegradationPreference::kBalanced: 821 case VideoSendStream::DegradationPreference::kBalanced:
809 FALLTHROUGH(); 822 FALLTHROUGH();
810 case VideoSendStream::DegradationPreference::kMaintainFramerate: 823 case VideoSendStream::DegradationPreference::kMaintainFramerate:
811 max_downgrades = kMaxCpuResolutionDowngrades; 824 max_downgrades = kMaxCpuResolutionDowngrades;
(...skipping 17 matching lines...) Expand all
829 // make the same kind of limitations as for resolution, but trust the 842 // make the same kind of limitations as for resolution, but trust the
830 // overuse detector to not trigger too often. 843 // overuse detector to not trigger too often.
831 return; 844 return;
832 } 845 }
833 break; 846 break;
834 case VideoSendStream::DegradationPreference::kDegradationDisabled: 847 case VideoSendStream::DegradationPreference::kDegradationDisabled:
835 return; 848 return;
836 } 849 }
837 850
838 if (reason == kCpu) { 851 if (reason == kCpu) {
839 const int cpu_scale_counter = GetScaleCounters()[reason]; 852 if (GetConstAdaptCounter().TotalCount(kCpu) >= max_downgrades)
840 if (cpu_scale_counter >= max_downgrades)
841 return; 853 return;
842 } 854 }
843 855
844 switch (degradation_preference_) { 856 switch (degradation_preference_) {
845 case VideoSendStream::DegradationPreference::kBalanced: 857 case VideoSendStream::DegradationPreference::kBalanced:
846 FALLTHROUGH(); 858 FALLTHROUGH();
847 case VideoSendStream::DegradationPreference::kMaintainFramerate: 859 case VideoSendStream::DegradationPreference::kMaintainFramerate:
848 if (!source_proxy_->RequestResolutionLowerThan( 860 if (!source_proxy_->RequestResolutionLowerThan(
849 adaptation_request.input_pixel_count_)) { 861 adaptation_request.input_pixel_count_)) {
850 return; 862 return;
851 } 863 }
852 LOG(LS_INFO) << "Scaling down resolution."; 864 LOG(LS_INFO) << "Scaling down resolution.";
865 GetAdaptCounter().IncrementResolution(reason, 1);
853 break; 866 break;
854 case VideoSendStream::DegradationPreference::kMaintainResolution: 867 case VideoSendStream::DegradationPreference::kMaintainResolution:
855 source_proxy_->RequestFramerateLowerThan( 868 source_proxy_->RequestFramerateLowerThan(
856 adaptation_request.framerate_fps_); 869 adaptation_request.framerate_fps_);
857 LOG(LS_INFO) << "Scaling down framerate."; 870 LOG(LS_INFO) << "Scaling down framerate.";
871 GetAdaptCounter().IncrementFramerate(reason, 1);
858 break; 872 break;
859 case VideoSendStream::DegradationPreference::kDegradationDisabled: 873 case VideoSendStream::DegradationPreference::kDegradationDisabled:
860 RTC_NOTREACHED(); 874 RTC_NOTREACHED();
861 } 875 }
862 876
863 last_adaptation_request_.emplace(adaptation_request); 877 last_adaptation_request_.emplace(adaptation_request);
864 878
865 IncrementScaleCounter(reason, 1); 879 UpdateAdaptationStats(reason);
866 880
867 // Update stats. 881 LOG(LS_INFO) << GetConstAdaptCounter().ToString();
868 const std::vector<int>& scale_counters = GetScaleCounters();
869 switch (reason) {
870 case kQuality:
871 stats_proxy_->OnQualityRestrictedResolutionChanged(
872 scale_counters[reason]);
873 break;
874 case kCpu:
875 stats_proxy_->OnCpuRestrictedResolutionChanged(true);
876 break;
877 }
878
879 for (size_t i = 0; i < kScaleReasonSize; ++i) {
880 LOG(LS_INFO) << "Scaled " << scale_counters[i]
881 << " times for reason: " << (i ? "cpu" : "quality");
882 }
883 } 882 }
884 883
885 void ViEEncoder::AdaptUp(AdaptReason reason) { 884 void ViEEncoder::AdaptUp(AdaptReason reason) {
886 RTC_DCHECK_RUN_ON(&encoder_queue_); 885 RTC_DCHECK_RUN_ON(&encoder_queue_);
887 int scale_counter = GetScaleCounters()[reason]; 886
888 if (scale_counter == 0) 887 const AdaptCounter& adapt_counter = GetConstAdaptCounter();
888 int num_downgrades = adapt_counter.TotalCount(reason);
889 if (num_downgrades == 0)
889 return; 890 return;
890 RTC_DCHECK_GT(scale_counter, 0); 891 RTC_DCHECK_GT(num_downgrades, 0);
892
891 AdaptationRequest adaptation_request = { 893 AdaptationRequest adaptation_request = {
892 last_frame_info_->pixel_count(), 894 last_frame_info_->pixel_count(),
893 stats_proxy_->GetStats().input_frame_rate, 895 stats_proxy_->GetStats().input_frame_rate,
894 AdaptationRequest::Mode::kAdaptUp}; 896 AdaptationRequest::Mode::kAdaptUp};
895 897
896 bool adapt_up_requested = 898 bool adapt_up_requested =
897 last_adaptation_request_ && 899 last_adaptation_request_ &&
898 last_adaptation_request_->mode_ == AdaptationRequest::Mode::kAdaptUp; 900 last_adaptation_request_->mode_ == AdaptationRequest::Mode::kAdaptUp;
901
899 switch (degradation_preference_) { 902 switch (degradation_preference_) {
900 case VideoSendStream::DegradationPreference::kBalanced: 903 case VideoSendStream::DegradationPreference::kBalanced:
901 FALLTHROUGH(); 904 FALLTHROUGH();
902 case VideoSendStream::DegradationPreference::kMaintainFramerate: 905 case VideoSendStream::DegradationPreference::kMaintainFramerate:
903 if (adapt_up_requested && 906 if (adapt_up_requested &&
904 adaptation_request.input_pixel_count_ <= 907 adaptation_request.input_pixel_count_ <=
905 last_adaptation_request_->input_pixel_count_) { 908 last_adaptation_request_->input_pixel_count_) {
906 // Don't request higher resolution if the current resolution is not 909 // Don't request higher resolution if the current resolution is not
907 // higher than the last time we asked for the resolution to be higher. 910 // higher than the last time we asked for the resolution to be higher.
908 return; 911 return;
909 } 912 }
910 break; 913 break;
911 case VideoSendStream::DegradationPreference::kMaintainResolution: 914 case VideoSendStream::DegradationPreference::kMaintainResolution:
912 // TODO(sprang): Don't request higher framerate if we are already at 915 // TODO(sprang): Don't request higher framerate if we are already at
913 // max requested fps? 916 // max requested fps?
914 break; 917 break;
915 case VideoSendStream::DegradationPreference::kDegradationDisabled: 918 case VideoSendStream::DegradationPreference::kDegradationDisabled:
916 return; 919 return;
917 } 920 }
918 921
919 // Decrease counter of how many times we have scaled down, for this
920 // degradation preference mode and reason.
921 IncrementScaleCounter(reason, -1);
922
923 // Get a sum of how many times have scaled down, in total, for this
924 // degradation preference mode. If it is 0, remove any restraints.
925 const std::vector<int>& scale_counters = GetScaleCounters();
926 const int scale_sum =
927 std::accumulate(scale_counters.begin(), scale_counters.end(), 0);
928 switch (degradation_preference_) { 922 switch (degradation_preference_) {
929 case VideoSendStream::DegradationPreference::kBalanced: 923 case VideoSendStream::DegradationPreference::kBalanced:
930 FALLTHROUGH(); 924 FALLTHROUGH();
931 case VideoSendStream::DegradationPreference::kMaintainFramerate: 925 case VideoSendStream::DegradationPreference::kMaintainFramerate:
932 if (scale_sum == 0) { 926 if (adapt_counter.TotalCount() == 1) {
933 LOG(LS_INFO) << "Removing resolution down-scaling setting."; 927 LOG(LS_INFO) << "Removing resolution down-scaling setting.";
934 source_proxy_->RequestHigherResolutionThan( 928 source_proxy_->RequestHigherResolutionThan(
935 std::numeric_limits<int>::max()); 929 std::numeric_limits<int>::max());
936 } else { 930 } else {
937 source_proxy_->RequestHigherResolutionThan( 931 source_proxy_->RequestHigherResolutionThan(
938 adaptation_request.input_pixel_count_); 932 adaptation_request.input_pixel_count_);
939 LOG(LS_INFO) << "Scaling up resolution."; 933 LOG(LS_INFO) << "Scaling up resolution.";
940 } 934 }
935 GetAdaptCounter().IncrementResolution(reason, -1);
941 break; 936 break;
942 case VideoSendStream::DegradationPreference::kMaintainResolution: 937 case VideoSendStream::DegradationPreference::kMaintainResolution:
943 if (scale_sum == 0) { 938 if (adapt_counter.TotalCount() == 1) {
944 LOG(LS_INFO) << "Removing framerate down-scaling setting."; 939 LOG(LS_INFO) << "Removing framerate down-scaling setting.";
945 source_proxy_->RequestHigherFramerateThan( 940 source_proxy_->RequestHigherFramerateThan(
946 std::numeric_limits<int>::max()); 941 std::numeric_limits<int>::max());
947 } else { 942 } else {
948 source_proxy_->RequestHigherFramerateThan( 943 source_proxy_->RequestHigherFramerateThan(
949 adaptation_request.framerate_fps_); 944 adaptation_request.framerate_fps_);
950 LOG(LS_INFO) << "Scaling up framerate."; 945 LOG(LS_INFO) << "Scaling up framerate.";
951 } 946 }
947 GetAdaptCounter().IncrementFramerate(reason, -1);
952 break; 948 break;
953 case VideoSendStream::DegradationPreference::kDegradationDisabled: 949 case VideoSendStream::DegradationPreference::kDegradationDisabled:
954 RTC_NOTREACHED(); 950 RTC_NOTREACHED();
955 } 951 }
956 952
957 last_adaptation_request_.emplace(adaptation_request); 953 last_adaptation_request_.emplace(adaptation_request);
958 954
959 // Update stats. 955 UpdateAdaptationStats(reason);
956
957 LOG(LS_INFO) << adapt_counter.ToString();
958 }
959
960 void ViEEncoder::UpdateAdaptationStats(AdaptReason reason) {
960 switch (reason) { 961 switch (reason) {
962 case kCpu:
963 stats_proxy_->OnCpuAdaptationChanged(GetActiveCounts(kCpu),
964 GetActiveCounts(kQuality));
965 break;
961 case kQuality: 966 case kQuality:
962 stats_proxy_->OnQualityRestrictedResolutionChanged( 967 stats_proxy_->OnQualityAdaptationChanged(GetActiveCounts(kCpu),
963 scale_counters[reason]); 968 GetActiveCounts(kQuality));
964 break; 969 break;
965 case kCpu:
966 stats_proxy_->OnCpuRestrictedResolutionChanged(scale_counters[reason] >
967 0);
968 break;
969 }
970
971 for (size_t i = 0; i < kScaleReasonSize; ++i) {
972 LOG(LS_INFO) << "Scaled " << scale_counters[i]
973 << " times for reason: " << (i ? "cpu" : "quality");
974 } 970 }
975 } 971 }
976 972
977 const std::vector<int>& ViEEncoder::GetScaleCounters() { 973 ViEEncoder::AdaptCounts ViEEncoder::GetActiveCounts(AdaptReason reason) {
978 auto it = scale_counters_.find(degradation_preference_); 974 ViEEncoder::AdaptCounts counts = GetConstAdaptCounter().Counts(reason);
979 if (it == scale_counters_.end()) { 975 switch (reason) {
980 scale_counters_[degradation_preference_].resize(kScaleReasonSize); 976 case kCpu:
981 return scale_counters_[degradation_preference_]; 977 if (!IsFramerateScalingEnabled(degradation_preference_))
978 counts.fps = -1;
979 if (!IsResolutionScalingEnabled(degradation_preference_))
980 counts.resolution = -1;
981 break;
982 case kQuality:
983 if (!IsFramerateScalingEnabled(degradation_preference_) ||
984 !quality_scaler_) {
985 counts.fps = -1;
986 }
987 if (!IsResolutionScalingEnabled(degradation_preference_) ||
988 !quality_scaler_) {
989 counts.resolution = -1;
990 }
991 break;
982 } 992 }
983 return it->second; 993 return counts;
984 } 994 }
985 995
986 void ViEEncoder::IncrementScaleCounter(int reason, int delta) { 996 ViEEncoder::AdaptCounter& ViEEncoder::GetAdaptCounter() {
987 // Get the counters and validate. This may also lazily initialize the state. 997 return adapt_counters_[degradation_preference_];
988 const std::vector<int>& counter = GetScaleCounters(); 998 }
989 if (delta < 0) { 999
990 RTC_DCHECK_GE(counter[reason], delta); 1000 const ViEEncoder::AdaptCounter& ViEEncoder::GetConstAdaptCounter() {
1001 return adapt_counters_[degradation_preference_];
1002 }
1003
1004 // Class holding adaptation information.
1005 ViEEncoder::AdaptCounter::AdaptCounter() {
1006 fps_counters_.resize(kScaleReasonSize);
1007 resolution_counters_.resize(kScaleReasonSize);
1008 }
1009
1010 ViEEncoder::AdaptCounter::~AdaptCounter() {}
1011
1012 std::string ViEEncoder::AdaptCounter::ToString() const {
1013 std::stringstream ss;
1014 ss << "Downgrade counts: fps: {" << ToString(fps_counters_);
1015 ss << "}, resolution: {" << ToString(resolution_counters_) << "}";
1016 return ss.str();
1017 }
1018
1019 ViEEncoder::AdaptCounts ViEEncoder::AdaptCounter::Counts(int reason) const {
1020 AdaptCounts counts;
1021 counts.fps = fps_counters_[reason];
1022 counts.resolution = resolution_counters_[reason];
1023 return counts;
1024 }
1025
1026 void ViEEncoder::AdaptCounter::IncrementFramerate(int reason, int delta) {
1027 fps_counters_[reason] += delta;
1028 }
1029
1030 void ViEEncoder::AdaptCounter::IncrementResolution(int reason, int delta) {
1031 resolution_counters_[reason] += delta;
1032 }
1033
1034 int ViEEncoder::AdaptCounter::FramerateCount() const {
1035 return Count(fps_counters_);
1036 }
1037
1038 int ViEEncoder::AdaptCounter::ResolutionCount() const {
1039 return Count(resolution_counters_);
1040 }
1041
1042 int ViEEncoder::AdaptCounter::TotalCount() const {
1043 return FramerateCount() + ResolutionCount();
1044 }
1045
1046 int ViEEncoder::AdaptCounter::FramerateCount(int reason) const {
1047 return fps_counters_[reason];
1048 }
1049
1050 int ViEEncoder::AdaptCounter::ResolutionCount(int reason) const {
1051 return resolution_counters_[reason];
1052 }
1053
1054 int ViEEncoder::AdaptCounter::TotalCount(int reason) const {
1055 return FramerateCount(reason) + ResolutionCount(reason);
1056 }
1057
1058 int ViEEncoder::AdaptCounter::Count(const std::vector<int>& counters) const {
1059 return std::accumulate(counters.begin(), counters.end(), 0);
1060 }
1061
1062 std::string ViEEncoder::AdaptCounter::ToString(
1063 const std::vector<int>& counters) const {
1064 std::stringstream ss;
1065 for (size_t reason = 0; reason < kScaleReasonSize; ++reason) {
1066 ss << (reason ? " cpu" : "quality") << ":" << counters[reason];
991 } 1067 }
992 scale_counters_[degradation_preference_][reason] += delta; 1068 return ss.str();
993 } 1069 }
994 1070
995 } // namespace webrtc 1071 } // 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