blob: 852aeeec846851132d2943faf0e36e331bf0becd [file] [log] [blame]
tkchin4f735d12016-03-03 17:54:28 -08001/*
2 * Copyright 2016 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
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020011#import "RTCFieldTrials.h"
tkchin4f735d12016-03-03 17:54:28 -080012
13#include <memory>
tkchin4f735d12016-03-03 17:54:28 -080014
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020015#import "base/RTCLogging.h"
tkchin9eeb6242016-04-27 01:54:20 -070016
Mirko Bonadei17f48782018-09-28 08:51:10 +020017#include "system_wrappers/include/field_trial.h"
tkchin4f735d12016-03-03 17:54:28 -080018
Alex Narest789221f2018-06-13 13:29:21 +020019NSString * const kRTCFieldTrialAudioForceNoTWCCKey = @"WebRTC-Audio-ForceNoTWCC";
Alex Narest0bd7bf02018-06-27 12:35:52 +020020NSString * const kRTCFieldTrialAudioForceABWENoTWCCKey = @"WebRTC-Audio-ABWENoTWCC";
haysc148e3702017-01-25 10:02:20 -080021NSString * const kRTCFieldTrialSendSideBweWithOverheadKey = @"WebRTC-SendSideBwe-WithOverhead";
brandtr340e3fd2017-02-28 15:43:10 -080022NSString * const kRTCFieldTrialFlexFec03AdvertisedKey = @"WebRTC-FlexFEC-03-Advertised";
tkchin4cd62212016-12-15 13:17:54 -080023NSString * const kRTCFieldTrialFlexFec03Key = @"WebRTC-FlexFEC-03";
magjedb4ad6032016-12-17 23:50:17 -080024NSString * const kRTCFieldTrialH264HighProfileKey = @"WebRTC-H264HighProfile";
Kári Tristan Helgason6d3e8662017-05-31 17:28:11 +020025NSString * const kRTCFieldTrialMinimizeResamplingOnMobileKey =
Kári Tristan Helgason0a0a2f12017-05-31 15:35:21 +020026 @"WebRTC-Audio-MinimizeResamplingOnMobile";
Taylor Brandstetterea7fbfb2020-08-19 16:41:54 -070027NSString *const kRTCFieldTrialUseNWPathMonitor = @"WebRTC-Network-UseNWPathMonitor";
tkchin4cd62212016-12-15 13:17:54 -080028NSString * const kRTCFieldTrialEnabledValue = @"Enabled";
29
Byoungchan Lee524a4222021-11-19 19:03:49 +090030// InitFieldTrialsFromString stores the char*, so the char array must outlive
31// the application.
32static char *gFieldTrialInitString = nullptr;
tkchin4f735d12016-03-03 17:54:28 -080033
tkchin4cd62212016-12-15 13:17:54 -080034void RTCInitFieldTrialDictionary(NSDictionary<NSString *, NSString *> *fieldTrials) {
35 if (!fieldTrials) {
36 RTCLogWarning(@"No fieldTrials provided.");
37 return;
38 }
39 // Assemble the keys and values into the field trial string.
40 // We don't perform any extra format checking. That should be done by the underlying WebRTC calls.
tkchin4f735d12016-03-03 17:54:28 -080041 NSMutableString *fieldTrialInitString = [NSMutableString string];
tkchin4cd62212016-12-15 13:17:54 -080042 for (NSString *key in fieldTrials) {
43 NSString *fieldTrialEntry = [NSString stringWithFormat:@"%@/%@/", key, fieldTrials[key]];
44 [fieldTrialInitString appendString:fieldTrialEntry];
brandtr96385e02016-11-21 23:43:18 -080045 }
tkchind924ff32016-11-08 15:39:13 -080046 size_t len = fieldTrialInitString.length + 1;
Byoungchan Lee524a4222021-11-19 19:03:49 +090047 if (gFieldTrialInitString != nullptr) {
48 delete[] gFieldTrialInitString;
49 }
50 gFieldTrialInitString = new char[len];
51 if (![fieldTrialInitString getCString:gFieldTrialInitString
tkchin4f735d12016-03-03 17:54:28 -080052 maxLength:len
53 encoding:NSUTF8StringEncoding]) {
54 RTCLogError(@"Failed to convert field trial string.");
55 return;
56 }
Byoungchan Lee524a4222021-11-19 19:03:49 +090057 webrtc::field_trial::InitFieldTrialsFromString(gFieldTrialInitString);
tkchin4f735d12016-03-03 17:54:28 -080058}