1 /*
2  *  Copyright 2018 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/normalize_simulcast_size_experiment.h"
12 
13 #include <stdio.h>
14 
15 #include <string>
16 
17 #include "rtc_base/logging.h"
18 #include "system_wrappers/include/field_trial.h"
19 
20 namespace webrtc {
21 namespace {
22 constexpr char kFieldTrial[] = "WebRTC-NormalizeSimulcastResolution";
23 constexpr int kMinSetting = 0;
24 constexpr int kMaxSetting = 5;
25 }  // namespace
26 
GetBase2Exponent()27 absl::optional<int> NormalizeSimulcastSizeExperiment::GetBase2Exponent() {
28   if (!webrtc::field_trial::IsEnabled(kFieldTrial))
29     return absl::nullopt;
30 
31   const std::string group = webrtc::field_trial::FindFullName(kFieldTrial);
32   if (group.empty())
33     return absl::nullopt;
34 
35   int exponent;
36   if (sscanf(group.c_str(), "Enabled-%d", &exponent) != 1) {
37     RTC_LOG(LS_WARNING) << "No parameter provided.";
38     return absl::nullopt;
39   }
40 
41   if (exponent < kMinSetting || exponent > kMaxSetting) {
42     RTC_LOG(LS_WARNING) << "Unsupported exp value provided, value ignored.";
43     return absl::nullopt;
44   }
45 
46   return absl::optional<int>(exponent);
47 }
48 
49 }  // namespace webrtc
50