blob: 4a30db2f70cf9608e673cda6e6f2072dde8aa02f [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
tkchin4cd62212016-12-15 13:17:54 -080019NSString * const kRTCFieldTrialAudioSendSideBweKey = @"WebRTC-Audio-SendSideBwe";
Alex Narest789221f2018-06-13 13:29:21 +020020NSString * const kRTCFieldTrialAudioForceNoTWCCKey = @"WebRTC-Audio-ForceNoTWCC";
Alex Narest0bd7bf02018-06-27 12:35:52 +020021NSString * const kRTCFieldTrialAudioForceABWENoTWCCKey = @"WebRTC-Audio-ABWENoTWCC";
haysc148e3702017-01-25 10:02:20 -080022NSString * const kRTCFieldTrialSendSideBweWithOverheadKey = @"WebRTC-SendSideBwe-WithOverhead";
brandtr340e3fd2017-02-28 15:43:10 -080023NSString * const kRTCFieldTrialFlexFec03AdvertisedKey = @"WebRTC-FlexFEC-03-Advertised";
tkchin4cd62212016-12-15 13:17:54 -080024NSString * const kRTCFieldTrialFlexFec03Key = @"WebRTC-FlexFEC-03";
magjedb4ad6032016-12-17 23:50:17 -080025NSString * const kRTCFieldTrialH264HighProfileKey = @"WebRTC-H264HighProfile";
Kári Tristan Helgason6d3e8662017-05-31 17:28:11 +020026NSString * const kRTCFieldTrialMinimizeResamplingOnMobileKey =
Kári Tristan Helgason0a0a2f12017-05-31 15:35:21 +020027 @"WebRTC-Audio-MinimizeResamplingOnMobile";
tkchin4cd62212016-12-15 13:17:54 -080028NSString * const kRTCFieldTrialEnabledValue = @"Enabled";
29
tkchin4f735d12016-03-03 17:54:28 -080030static std::unique_ptr<char[]> gFieldTrialInitString;
31
tkchin4cd62212016-12-15 13:17:54 -080032void RTCInitFieldTrialDictionary(NSDictionary<NSString *, NSString *> *fieldTrials) {
33 if (!fieldTrials) {
34 RTCLogWarning(@"No fieldTrials provided.");
35 return;
36 }
37 // Assemble the keys and values into the field trial string.
38 // We don't perform any extra format checking. That should be done by the underlying WebRTC calls.
tkchin4f735d12016-03-03 17:54:28 -080039 NSMutableString *fieldTrialInitString = [NSMutableString string];
tkchin4cd62212016-12-15 13:17:54 -080040 for (NSString *key in fieldTrials) {
41 NSString *fieldTrialEntry = [NSString stringWithFormat:@"%@/%@/", key, fieldTrials[key]];
42 [fieldTrialInitString appendString:fieldTrialEntry];
brandtr96385e02016-11-21 23:43:18 -080043 }
tkchind924ff32016-11-08 15:39:13 -080044 size_t len = fieldTrialInitString.length + 1;
45 gFieldTrialInitString.reset(new char[len]);
tkchin4f735d12016-03-03 17:54:28 -080046 if (![fieldTrialInitString getCString:gFieldTrialInitString.get()
47 maxLength:len
48 encoding:NSUTF8StringEncoding]) {
49 RTCLogError(@"Failed to convert field trial string.");
50 return;
51 }
52 webrtc::field_trial::InitFieldTrialsFromString(gFieldTrialInitString.get());
53}