Åsa Persson | f3d828e | 2019-05-06 12:22:49 +0200 | [diff] [blame] | 1 | /* |
| 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 Persson | 1231419 | 2019-06-20 15:45:07 +0200 | [diff] [blame] | 16 | #include "absl/types/optional.h" |
| 17 | #include "api/video_codecs/video_encoder.h" |
| 18 | |
Åsa Persson | f3d828e | 2019-05-06 12:22:49 +0200 | [diff] [blame] | 19 | namespace webrtc { |
| 20 | |
| 21 | class BalancedDegradationSettings { |
| 22 | public: |
| 23 | BalancedDegradationSettings(); |
| 24 | ~BalancedDegradationSettings(); |
| 25 | |
Åsa Persson | 48284b8 | 2019-07-08 10:01:12 +0200 | [diff] [blame] | 26 | 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 Persson | f3d828e | 2019-05-06 12:22:49 +0200 | [diff] [blame] | 30 | |
Åsa Persson | 48284b8 | 2019-07-08 10:01:12 +0200 | [diff] [blame] | 31 | bool operator==(const CodecTypeSpecific& o) const { |
| 32 | return qp_low == o.qp_low && qp_high == o.qp_high && fps == o.fps; |
Åsa Persson | f3d828e | 2019-05-06 12:22:49 +0200 | [diff] [blame] | 33 | } |
| 34 | |
Åsa Persson | 48284b8 | 2019-07-08 10:01:12 +0200 | [diff] [blame] | 35 | 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 Persson | 1231419 | 2019-06-20 15:45:07 +0200 | [diff] [blame] | 41 | }; |
| 42 | |
| 43 | struct Config { |
| 44 | Config(); |
| 45 | Config(int pixels, |
| 46 | int fps, |
Åsa Persson | 48284b8 | 2019-07-08 10:01:12 +0200 | [diff] [blame] | 47 | CodecTypeSpecific vp8, |
| 48 | CodecTypeSpecific vp9, |
| 49 | CodecTypeSpecific h264, |
| 50 | CodecTypeSpecific generic); |
Åsa Persson | 1231419 | 2019-06-20 15:45:07 +0200 | [diff] [blame] | 51 | |
| 52 | bool operator==(const Config& o) const { |
| 53 | return pixels == o.pixels && fps == o.fps && vp8 == o.vp8 && |
| 54 | vp9 == o.vp9 && h264 == o.h264 && generic == o.generic; |
| 55 | } |
| 56 | |
Åsa Persson | 48284b8 | 2019-07-08 10:01:12 +0200 | [diff] [blame] | 57 | int pixels = 0; // The video frame size. |
| 58 | int fps = 0; // The framerate and thresholds to be used if the |
| 59 | CodecTypeSpecific vp8; // frame size is less than or equal to |pixels|. |
| 60 | CodecTypeSpecific vp9; |
| 61 | CodecTypeSpecific h264; |
| 62 | CodecTypeSpecific generic; |
Åsa Persson | f3d828e | 2019-05-06 12:22:49 +0200 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | // Returns configurations from field trial on success (default on failure). |
| 66 | std::vector<Config> GetConfigs() const; |
| 67 | |
| 68 | // Gets the min/max framerate from |configs_| based on |pixels|. |
Åsa Persson | 48284b8 | 2019-07-08 10:01:12 +0200 | [diff] [blame] | 69 | int MinFps(VideoCodecType type, int pixels) const; |
| 70 | int MaxFps(VideoCodecType type, int pixels) const; |
Åsa Persson | f3d828e | 2019-05-06 12:22:49 +0200 | [diff] [blame] | 71 | |
Åsa Persson | 1231419 | 2019-06-20 15:45:07 +0200 | [diff] [blame] | 72 | // Gets QpThresholds for the codec |type| based on |pixels|. |
| 73 | absl::optional<VideoEncoder::QpThresholds> GetQpThresholds( |
| 74 | VideoCodecType type, |
| 75 | int pixels) const; |
| 76 | |
Åsa Persson | f3d828e | 2019-05-06 12:22:49 +0200 | [diff] [blame] | 77 | private: |
Åsa Persson | 48284b8 | 2019-07-08 10:01:12 +0200 | [diff] [blame] | 78 | absl::optional<Config> GetMinFpsConfig(int pixels) const; |
| 79 | absl::optional<Config> GetMaxFpsConfig(int pixels) const; |
Åsa Persson | 1231419 | 2019-06-20 15:45:07 +0200 | [diff] [blame] | 80 | Config GetConfig(int pixels) const; |
| 81 | |
Åsa Persson | f3d828e | 2019-05-06 12:22:49 +0200 | [diff] [blame] | 82 | std::vector<Config> configs_; |
| 83 | }; |
| 84 | |
| 85 | } // namespace webrtc |
| 86 | |
| 87 | #endif // RTC_BASE_EXPERIMENTS_BALANCED_DEGRADATION_SETTINGS_H_ |