Sebastian Jansson | fc8d26b | 2018-02-21 09:52:06 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 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 | #ifndef CALL_BITRATE_CONSTRAINTS_H_ |
| 12 | #define CALL_BITRATE_CONSTRAINTS_H_ |
| 13 | |
| 14 | #include <algorithm> |
| 15 | |
| 16 | #include "api/optional.h" |
| 17 | |
| 18 | namespace webrtc { |
| 19 | // TODO(srte): BitrateConstraints and BitrateConstraintsMask should be merged. |
| 20 | // Both represent the same kind data, but are using different default |
| 21 | // initializer and representation of unset values. |
| 22 | struct BitrateConstraints { |
| 23 | int min_bitrate_bps = 0; |
| 24 | int start_bitrate_bps = kDefaultStartBitrateBps; |
| 25 | int max_bitrate_bps = -1; |
| 26 | |
| 27 | private: |
| 28 | static constexpr int kDefaultStartBitrateBps = 300000; |
| 29 | }; |
| 30 | |
| 31 | // BitrateConstraintsMask is used for the local client's bitrate preferences. |
| 32 | // Semantically it carries the same kind of information as BitrateConstraints, |
| 33 | // but is used in a slightly different way. |
| 34 | struct BitrateConstraintsMask { |
| 35 | BitrateConstraintsMask(); |
| 36 | ~BitrateConstraintsMask(); |
| 37 | BitrateConstraintsMask(const BitrateConstraintsMask&); |
| 38 | rtc::Optional<int> min_bitrate_bps; |
| 39 | rtc::Optional<int> start_bitrate_bps; |
| 40 | rtc::Optional<int> max_bitrate_bps; |
| 41 | }; |
| 42 | |
| 43 | // Like std::min, but considers non-positive values to be unset. |
| 44 | template <typename T> |
| 45 | static T MinPositive(T a, T b) { |
| 46 | if (a <= 0) { |
| 47 | return b; |
| 48 | } |
| 49 | if (b <= 0) { |
| 50 | return a; |
| 51 | } |
| 52 | return std::min(a, b); |
| 53 | } |
| 54 | } // namespace webrtc |
| 55 | #endif // CALL_BITRATE_CONSTRAINTS_H_ |