blob: f32a2965a952c3d35b43494f84b4927b34c0ed36 [file] [log] [blame]
Åsa Persson517678c2019-05-06 14:17:35 +02001/*
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
16namespace webrtc {
17namespace {
18const int kMinFrames = 10;
19const double kMinScaleFactor = 0.01;
20} // namespace
21
22QualityScalerSettings::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 ParseFieldTrial(
28 {&min_frames_, &initial_scale_factor_, &scale_factor_},
29 key_value_config->Lookup("WebRTC-Video-QualityScalerSettings"));
30}
31
32QualityScalerSettings QualityScalerSettings::ParseFromFieldTrials() {
33 FieldTrialBasedConfig field_trial_config;
34 return QualityScalerSettings(&field_trial_config);
35}
36
37absl::optional<int> QualityScalerSettings::MinFrames() const {
38 if (min_frames_ && min_frames_.Value() < kMinFrames) {
39 RTC_LOG(LS_WARNING) << "Unsupported min_frames value, ignored.";
40 return absl::nullopt;
41 }
42 return min_frames_.GetOptional();
43}
44
45absl::optional<double> QualityScalerSettings::InitialScaleFactor() const {
46 if (initial_scale_factor_ &&
47 initial_scale_factor_.Value() < kMinScaleFactor) {
48 RTC_LOG(LS_WARNING) << "Unsupported initial_scale_factor value, ignored.";
49 return absl::nullopt;
50 }
51 return initial_scale_factor_.GetOptional();
52}
53
54absl::optional<double> QualityScalerSettings::ScaleFactor() const {
55 if (scale_factor_ && scale_factor_.Value() < kMinScaleFactor) {
56 RTC_LOG(LS_WARNING) << "Unsupported scale_factor value, ignored.";
57 return absl::nullopt;
58 }
59 return scale_factor_.GetOptional();
60}
61
62} // namespace webrtc