• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2019 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 "rtc_base/experiments/quality_scaler_settings.h"
12 
13 #include "api/transport/field_trial_based_config.h"
14 #include "rtc_base/logging.h"
15 
16 namespace webrtc {
17 namespace {
18 const int kMinFrames = 10;
19 const double kMinScaleFactor = 0.01;
20 }  // namespace
21 
QualityScalerSettings(const WebRtcKeyValueConfig * const key_value_config)22 QualityScalerSettings::QualityScalerSettings(
23     const WebRtcKeyValueConfig* const key_value_config)
24     : min_frames_("min_frames"),
25       initial_scale_factor_("initial_scale_factor"),
26       scale_factor_("scale_factor"),
27       initial_bitrate_interval_ms_("initial_bitrate_interval_ms"),
28       initial_bitrate_factor_("initial_bitrate_factor") {
29   ParseFieldTrial(
30       {&min_frames_, &initial_scale_factor_, &scale_factor_,
31        &initial_bitrate_interval_ms_, &initial_bitrate_factor_},
32       key_value_config->Lookup("WebRTC-Video-QualityScalerSettings"));
33 }
34 
ParseFromFieldTrials()35 QualityScalerSettings QualityScalerSettings::ParseFromFieldTrials() {
36   FieldTrialBasedConfig field_trial_config;
37   return QualityScalerSettings(&field_trial_config);
38 }
39 
MinFrames() const40 absl::optional<int> QualityScalerSettings::MinFrames() const {
41   if (min_frames_ && min_frames_.Value() < kMinFrames) {
42     RTC_LOG(LS_WARNING) << "Unsupported min_frames value, ignored.";
43     return absl::nullopt;
44   }
45   return min_frames_.GetOptional();
46 }
47 
InitialScaleFactor() const48 absl::optional<double> QualityScalerSettings::InitialScaleFactor() const {
49   if (initial_scale_factor_ &&
50       initial_scale_factor_.Value() < kMinScaleFactor) {
51     RTC_LOG(LS_WARNING) << "Unsupported initial_scale_factor value, ignored.";
52     return absl::nullopt;
53   }
54   return initial_scale_factor_.GetOptional();
55 }
56 
ScaleFactor() const57 absl::optional<double> QualityScalerSettings::ScaleFactor() const {
58   if (scale_factor_ && scale_factor_.Value() < kMinScaleFactor) {
59     RTC_LOG(LS_WARNING) << "Unsupported scale_factor value, ignored.";
60     return absl::nullopt;
61   }
62   return scale_factor_.GetOptional();
63 }
64 
InitialBitrateIntervalMs() const65 absl::optional<int> QualityScalerSettings::InitialBitrateIntervalMs() const {
66   if (initial_bitrate_interval_ms_ &&
67       initial_bitrate_interval_ms_.Value() < 0) {
68     RTC_LOG(LS_WARNING) << "Unsupported bitrate_interval value, ignored.";
69     return absl::nullopt;
70   }
71   return initial_bitrate_interval_ms_.GetOptional();
72 }
73 
InitialBitrateFactor() const74 absl::optional<double> QualityScalerSettings::InitialBitrateFactor() const {
75   if (initial_bitrate_factor_ &&
76       initial_bitrate_factor_.Value() < kMinScaleFactor) {
77     RTC_LOG(LS_WARNING) << "Unsupported initial_bitrate_factor value, ignored.";
78     return absl::nullopt;
79   }
80   return initial_bitrate_factor_.GetOptional();
81 }
82 
83 }  // namespace webrtc
84