|
| 1 | +#ifndef LIB_WEBRTC_RTC_FIELD_TRIALS_HXX |
| 2 | +#define LIB_WEBRTC_RTC_FIELD_TRIALS_HXX |
| 3 | + |
| 4 | +#include "rtc_types.h" |
| 5 | + |
| 6 | +namespace libwebrtc { |
| 7 | + |
| 8 | +/** |
| 9 | + * The only valid value for the following keys, if set, is |
| 10 | + * kRTCFieldTrialEnabledValue. |
| 11 | + */ |
| 12 | +constexpr char kRTCFieldTrialAudioForceABWENoTWCCKey[] = |
| 13 | + "WebRTC-Audio-ABWENoTWCC"; |
| 14 | +constexpr char kRTCFieldTrialFlexFec03AdvertisedKey[] = |
| 15 | + "WebRTC-FlexFEC-03-Advertised"; |
| 16 | +constexpr char kRTCFieldTrialFlexFec03Key[] = "WebRTC-FlexFEC-03"; |
| 17 | +constexpr char kRTCFieldTrialH264HighProfileKey[] = "WebRTC-H264HighProfile"; |
| 18 | +constexpr char kRTCFieldTrialMinimizeResamplingOnMobileKey[] = |
| 19 | + "WebRTC-Audio-MinimizeResamplingOnMobile"; |
| 20 | +constexpr char kRTCFieldTrialUseNWPathMonitorKey[] = |
| 21 | + "WebRTC-Network-UseNWPathMonitor"; |
| 22 | +constexpr char kRTCFieldTrialIceHandshakeDtlsKey[] = "WebRTC-IceHandshakeDtls"; |
| 23 | + |
| 24 | +/** The valid value for the field trials above. */ |
| 25 | +constexpr char kRTCFieldTrialEnabledValue[] = "Enabled"; |
| 26 | + |
| 27 | +/** The value used to explicitly turn a field trial off. */ |
| 28 | +constexpr char kRTCFieldTrialDisabledValue[] = "Disabled"; |
| 29 | + |
| 30 | +/** |
| 31 | + * @class RTCFieldTrials |
| 32 | + * @brief Configures and queries the global WebRTC field trials. |
| 33 | + * |
| 34 | + * Field trials allow clients to turn on feature code that is not enabled by |
| 35 | + * default. They must be initialized before any other call into WebRTC, i.e. |
| 36 | + * before LibWebRTC::Initialize() and before any peer connection factory is |
| 37 | + * created, otherwise the objects already created keep using the previous |
| 38 | + * configuration. |
| 39 | + * |
| 40 | + * A field trial is described by a "Key/Value" pair, where the key is one of |
| 41 | + * the constants above (or any other trial name known to WebRTC) and the value |
| 42 | + * is the group to assign the process to, usually kRTCFieldTrialEnabledValue. |
| 43 | + * |
| 44 | + * See also: webrtc/system_wrappers/include/field_trial.h |
| 45 | + */ |
| 46 | +class RTCFieldTrials { |
| 47 | + public: |
| 48 | + /** |
| 49 | + * @brief Assembles a WebRTC field trial string out of a list of entries. |
| 50 | + * |
| 51 | + * Each entry is either "Key/Value" or "Key/Value/"; empty entries are |
| 52 | + * skipped. The returned string is the concatenation of all the entries in |
| 53 | + * the canonical "Key1/Value1/Key2/Value2/" form. No extra format checking is |
| 54 | + * performed here, that is done by the underlying WebRTC calls. |
| 55 | + * |
| 56 | + * @param field_trials The field trial entries. |
| 57 | + * @return The assembled field trial string. |
| 58 | + */ |
| 59 | + LIB_WEBRTC_API static string BuildFieldTrialsString( |
| 60 | + const vector<string>& field_trials); |
| 61 | + |
| 62 | + /** |
| 63 | + * @brief Initializes the global field trials from a list of entries. |
| 64 | + * |
| 65 | + * Convenience wrapper around BuildFieldTrialsString() followed by |
| 66 | + * InitFieldTrialsFromString(). Must be called before any other call into |
| 67 | + * WebRTC. |
| 68 | + * |
| 69 | + * @param field_trials The field trial entries, e.g. |
| 70 | + * {"WebRTC-FlexFEC-03/Enabled/"}. |
| 71 | + * @return true if the field trials were applied, false if the resulting |
| 72 | + * string is invalid. |
| 73 | + */ |
| 74 | + LIB_WEBRTC_API static bool InitFieldTrials( |
| 75 | + const vector<string>& field_trials); |
| 76 | + |
| 77 | + /** |
| 78 | + * @brief Initializes the global field trials from a string. |
| 79 | + * |
| 80 | + * The string must be in the "Key1/Value1/Key2/Value2/" form, note the |
| 81 | + * trailing separator. An empty string clears every previously configured |
| 82 | + * trial. Must be called before any other call into WebRTC. |
| 83 | + * |
| 84 | + * @param trials_string The field trial string. |
| 85 | + * @return true if the string is valid and was applied, false otherwise. |
| 86 | + */ |
| 87 | + LIB_WEBRTC_API static bool InitFieldTrialsFromString( |
| 88 | + const string& trials_string); |
| 89 | + |
| 90 | + /** |
| 91 | + * @brief Returns the field trial string currently in use, or an empty |
| 92 | + * string if none was configured. |
| 93 | + */ |
| 94 | + LIB_WEBRTC_API static string GetFieldTrialsString(); |
| 95 | + |
| 96 | + /** |
| 97 | + * @brief Returns the group the process is assigned to for `key`, or an |
| 98 | + * empty string if the trial is not configured. |
| 99 | + */ |
| 100 | + LIB_WEBRTC_API static string Lookup(const string& key); |
| 101 | + |
| 102 | + /** |
| 103 | + * @brief Returns true if the group configured for `key` starts with |
| 104 | + * "Enabled". |
| 105 | + */ |
| 106 | + LIB_WEBRTC_API static bool IsEnabled(const string& key); |
| 107 | + |
| 108 | + /** |
| 109 | + * @brief Returns true if the group configured for `key` starts with |
| 110 | + * "Disabled". |
| 111 | + */ |
| 112 | + LIB_WEBRTC_API static bool IsDisabled(const string& key); |
| 113 | +}; |
| 114 | + |
| 115 | +} // namespace libwebrtc |
| 116 | + |
| 117 | +#endif // LIB_WEBRTC_RTC_FIELD_TRIALS_HXX |
0 commit comments