• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright 2020 The WebRTC Project Authors. All rights reserved.
3  *
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
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #include "video/adaptation/quality_rampup_experiment_helper.h"
12 
13 #include <memory>
14 #include <utility>
15 
16 #include "rtc_base/logging.h"
17 
18 namespace webrtc {
19 
QualityRampUpExperimentHelper(QualityRampUpExperimentListener * experiment_listener,Clock * clock,QualityRampupExperiment experiment)20 QualityRampUpExperimentHelper::QualityRampUpExperimentHelper(
21     QualityRampUpExperimentListener* experiment_listener,
22     Clock* clock,
23     QualityRampupExperiment experiment)
24     : experiment_listener_(experiment_listener),
25       clock_(clock),
26       quality_rampup_experiment_(std::move(experiment)),
27       cpu_adapted_(false),
28       qp_resolution_adaptations_(0) {
29   RTC_DCHECK(experiment_listener_);
30   RTC_DCHECK(clock_);
31 }
32 
33 std::unique_ptr<QualityRampUpExperimentHelper>
CreateIfEnabled(QualityRampUpExperimentListener * experiment_listener,Clock * clock)34 QualityRampUpExperimentHelper::CreateIfEnabled(
35     QualityRampUpExperimentListener* experiment_listener,
36     Clock* clock) {
37   QualityRampupExperiment experiment = QualityRampupExperiment::ParseSettings();
38   if (experiment.Enabled()) {
39     return std::unique_ptr<QualityRampUpExperimentHelper>(
40         new QualityRampUpExperimentHelper(experiment_listener, clock,
41                                           experiment));
42   }
43   return nullptr;
44 }
45 
PerformQualityRampupExperiment(rtc::scoped_refptr<QualityScalerResource> quality_scaler_resource,DataRate bandwidth,DataRate encoder_target_bitrate,DataRate max_bitrate,int pixels)46 void QualityRampUpExperimentHelper::PerformQualityRampupExperiment(
47     rtc::scoped_refptr<QualityScalerResource> quality_scaler_resource,
48     DataRate bandwidth,
49     DataRate encoder_target_bitrate,
50     DataRate max_bitrate,
51     int pixels) {
52   if (!quality_scaler_resource->is_started())
53     return;
54 
55   int64_t now_ms = clock_->TimeInMilliseconds();
56   quality_rampup_experiment_.SetMaxBitrate(pixels, max_bitrate.kbps());
57 
58   bool try_quality_rampup = false;
59   if (quality_rampup_experiment_.BwHigh(now_ms, bandwidth.kbps())) {
60     // Verify that encoder is at max bitrate and the QP is low.
61     if (encoder_target_bitrate == max_bitrate &&
62         quality_scaler_resource->QpFastFilterLow()) {
63       try_quality_rampup = true;
64     }
65   }
66   if (try_quality_rampup && qp_resolution_adaptations_ > 0 && !cpu_adapted_) {
67     experiment_listener_->OnQualityRampUp();
68   }
69 }
70 
cpu_adapted(bool cpu_adapted)71 void QualityRampUpExperimentHelper::cpu_adapted(bool cpu_adapted) {
72   cpu_adapted_ = cpu_adapted;
73 }
74 
qp_resolution_adaptations(int qp_resolution_adaptations)75 void QualityRampUpExperimentHelper::qp_resolution_adaptations(
76     int qp_resolution_adaptations) {
77   qp_resolution_adaptations_ = qp_resolution_adaptations;
78 }
79 
80 }  // namespace webrtc
81