blob: ef4b5879df7f4c68c6e1d9d09b5a3a7d94eafea0 [file] [log] [blame]
Åsa Perssonf3d828e2019-05-06 12:22:49 +02001/*
2 * Copyright 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#ifndef RTC_BASE_EXPERIMENTS_BALANCED_DEGRADATION_SETTINGS_H_
12#define RTC_BASE_EXPERIMENTS_BALANCED_DEGRADATION_SETTINGS_H_
13
14#include <vector>
15
Åsa Persson12314192019-06-20 15:45:07 +020016#include "absl/types/optional.h"
17#include "api/video_codecs/video_encoder.h"
18
Åsa Perssonf3d828e2019-05-06 12:22:49 +020019namespace webrtc {
20
21class BalancedDegradationSettings {
22 public:
23 BalancedDegradationSettings();
24 ~BalancedDegradationSettings();
25
Åsa Persson12314192019-06-20 15:45:07 +020026 struct QpThreshold {
27 QpThreshold() {}
28 QpThreshold(int low, int high) : low(low), high(high) {}
Åsa Perssonf3d828e2019-05-06 12:22:49 +020029
Åsa Persson12314192019-06-20 15:45:07 +020030 bool operator==(const QpThreshold& o) const {
31 return low == o.low && high == o.high;
Åsa Perssonf3d828e2019-05-06 12:22:49 +020032 }
33
Åsa Persson12314192019-06-20 15:45:07 +020034 absl::optional<int> GetLow() const;
35 absl::optional<int> GetHigh() const;
36 int low = 0;
37 int high = 0;
38 };
39
40 struct Config {
41 Config();
42 Config(int pixels,
43 int fps,
44 QpThreshold vp8,
45 QpThreshold vp9,
46 QpThreshold h264,
47 QpThreshold generic);
48
49 bool operator==(const Config& o) const {
50 return pixels == o.pixels && fps == o.fps && vp8 == o.vp8 &&
51 vp9 == o.vp9 && h264 == o.h264 && generic == o.generic;
52 }
53
54 int pixels = 0; // The video frame size.
55 int fps = 0; // The framerate and thresholds to be used if the frame
56 QpThreshold vp8; // size is less than or equal to |pixels|.
57 QpThreshold vp9;
58 QpThreshold h264;
59 QpThreshold generic;
Åsa Perssonf3d828e2019-05-06 12:22:49 +020060 };
61
62 // Returns configurations from field trial on success (default on failure).
63 std::vector<Config> GetConfigs() const;
64
65 // Gets the min/max framerate from |configs_| based on |pixels|.
66 int MinFps(int pixels) const;
67 int MaxFps(int pixels) const;
68
Åsa Persson12314192019-06-20 15:45:07 +020069 // Gets QpThresholds for the codec |type| based on |pixels|.
70 absl::optional<VideoEncoder::QpThresholds> GetQpThresholds(
71 VideoCodecType type,
72 int pixels) const;
73
Åsa Perssonf3d828e2019-05-06 12:22:49 +020074 private:
Åsa Persson12314192019-06-20 15:45:07 +020075 Config GetConfig(int pixels) const;
76
Åsa Perssonf3d828e2019-05-06 12:22:49 +020077 std::vector<Config> configs_;
78};
79
80} // namespace webrtc
81
82#endif // RTC_BASE_EXPERIMENTS_BALANCED_DEGRADATION_SETTINGS_H_