Å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 | 1231419 | 2019-06-20 15:45:07 +0200 | [diff] [blame^] | 26 | struct QpThreshold { |
| 27 | QpThreshold() {} |
| 28 | QpThreshold(int low, int high) : low(low), high(high) {} |
Åsa Persson | f3d828e | 2019-05-06 12:22:49 +0200 | [diff] [blame] | 29 | |
Åsa Persson | 1231419 | 2019-06-20 15:45:07 +0200 | [diff] [blame^] | 30 | bool operator==(const QpThreshold& o) const { |
| 31 | return low == o.low && high == o.high; |
Åsa Persson | f3d828e | 2019-05-06 12:22:49 +0200 | [diff] [blame] | 32 | } |
| 33 | |
Åsa Persson | 1231419 | 2019-06-20 15:45:07 +0200 | [diff] [blame^] | 34 | 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 Persson | f3d828e | 2019-05-06 12:22:49 +0200 | [diff] [blame] | 60 | }; |
| 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 Persson | 1231419 | 2019-06-20 15:45:07 +0200 | [diff] [blame^] | 69 | // Gets QpThresholds for the codec |type| based on |pixels|. |
| 70 | absl::optional<VideoEncoder::QpThresholds> GetQpThresholds( |
| 71 | VideoCodecType type, |
| 72 | int pixels) const; |
| 73 | |
Åsa Persson | f3d828e | 2019-05-06 12:22:49 +0200 | [diff] [blame] | 74 | private: |
Åsa Persson | 1231419 | 2019-06-20 15:45:07 +0200 | [diff] [blame^] | 75 | Config GetConfig(int pixels) const; |
| 76 | |
Åsa Persson | f3d828e | 2019-05-06 12:22:49 +0200 | [diff] [blame] | 77 | std::vector<Config> configs_; |
| 78 | }; |
| 79 | |
| 80 | } // namespace webrtc |
| 81 | |
| 82 | #endif // RTC_BASE_EXPERIMENTS_BALANCED_DEGRADATION_SETTINGS_H_ |