blob: e29b7d5ff540e3455c666e4a80fb4740f3704303 [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 Persson48284b82019-07-08 10:01:12 +020026 struct CodecTypeSpecific {
27 CodecTypeSpecific() {}
28 CodecTypeSpecific(int qp_low, int qp_high, int fps)
29 : qp_low(qp_low), qp_high(qp_high), fps(fps) {}
Åsa Perssonf3d828e2019-05-06 12:22:49 +020030
Åsa Persson48284b82019-07-08 10:01:12 +020031 bool operator==(const CodecTypeSpecific& o) const {
32 return qp_low == o.qp_low && qp_high == o.qp_high && fps == o.fps;
Åsa Perssonf3d828e2019-05-06 12:22:49 +020033 }
34
Åsa Persson48284b82019-07-08 10:01:12 +020035 absl::optional<int> GetQpLow() const;
36 absl::optional<int> GetQpHigh() const;
37 absl::optional<int> GetFps() const;
38 int qp_low = 0;
39 int qp_high = 0;
40 int fps = 0;
Åsa Persson12314192019-06-20 15:45:07 +020041 };
42
43 struct Config {
44 Config();
45 Config(int pixels,
46 int fps,
Åsa Persson1b247f12019-08-14 17:26:39 +020047 int kbps,
Åsa Persson48284b82019-07-08 10:01:12 +020048 CodecTypeSpecific vp8,
49 CodecTypeSpecific vp9,
50 CodecTypeSpecific h264,
51 CodecTypeSpecific generic);
Åsa Persson12314192019-06-20 15:45:07 +020052
53 bool operator==(const Config& o) const {
Åsa Persson1b247f12019-08-14 17:26:39 +020054 return pixels == o.pixels && fps == o.fps && kbps == o.kbps &&
55 vp8 == o.vp8 && vp9 == o.vp9 && h264 == o.h264 &&
56 generic == o.generic;
Åsa Persson12314192019-06-20 15:45:07 +020057 }
58
Åsa Persson1b247f12019-08-14 17:26:39 +020059 int pixels = 0; // Video frame size.
60 // If the frame size is less than or equal to |pixels|:
61 int fps = 0; // Min framerate to be used.
62 int kbps = 0; // Min bitrate needed to adapt up to this resolution.
63 CodecTypeSpecific vp8;
Åsa Persson48284b82019-07-08 10:01:12 +020064 CodecTypeSpecific vp9;
65 CodecTypeSpecific h264;
66 CodecTypeSpecific generic;
Åsa Perssonf3d828e2019-05-06 12:22:49 +020067 };
68
69 // Returns configurations from field trial on success (default on failure).
70 std::vector<Config> GetConfigs() const;
71
72 // Gets the min/max framerate from |configs_| based on |pixels|.
Åsa Persson48284b82019-07-08 10:01:12 +020073 int MinFps(VideoCodecType type, int pixels) const;
74 int MaxFps(VideoCodecType type, int pixels) const;
Åsa Perssonf3d828e2019-05-06 12:22:49 +020075
Åsa Persson1b247f12019-08-14 17:26:39 +020076 // Gets the bitrate for the first resolution above |pixels|.
77 absl::optional<int> NextHigherBitrateKbps(int pixels) const;
78
Åsa Persson12314192019-06-20 15:45:07 +020079 // Gets QpThresholds for the codec |type| based on |pixels|.
80 absl::optional<VideoEncoder::QpThresholds> GetQpThresholds(
81 VideoCodecType type,
82 int pixels) const;
83
Åsa Perssonf3d828e2019-05-06 12:22:49 +020084 private:
Åsa Persson48284b82019-07-08 10:01:12 +020085 absl::optional<Config> GetMinFpsConfig(int pixels) const;
86 absl::optional<Config> GetMaxFpsConfig(int pixels) const;
Åsa Persson12314192019-06-20 15:45:07 +020087 Config GetConfig(int pixels) const;
88
Åsa Perssonf3d828e2019-05-06 12:22:49 +020089 std::vector<Config> configs_;
90};
91
92} // namespace webrtc
93
94#endif // RTC_BASE_EXPERIMENTS_BALANCED_DEGRADATION_SETTINGS_H_