1/* 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 11#import "RTCFieldTrials.h" 12 13#include <memory> 14 15#import "base/RTCLogging.h" 16 17#include "system_wrappers/include/field_trial.h" 18 19NSString * const kRTCFieldTrialAudioSendSideBweKey = @"WebRTC-Audio-SendSideBwe"; 20NSString * const kRTCFieldTrialAudioForceNoTWCCKey = @"WebRTC-Audio-ForceNoTWCC"; 21NSString * const kRTCFieldTrialAudioForceABWENoTWCCKey = @"WebRTC-Audio-ABWENoTWCC"; 22NSString * const kRTCFieldTrialSendSideBweWithOverheadKey = @"WebRTC-SendSideBwe-WithOverhead"; 23NSString * const kRTCFieldTrialFlexFec03AdvertisedKey = @"WebRTC-FlexFEC-03-Advertised"; 24NSString * const kRTCFieldTrialFlexFec03Key = @"WebRTC-FlexFEC-03"; 25NSString * const kRTCFieldTrialH264HighProfileKey = @"WebRTC-H264HighProfile"; 26NSString * const kRTCFieldTrialMinimizeResamplingOnMobileKey = 27 @"WebRTC-Audio-MinimizeResamplingOnMobile"; 28NSString * const kRTCFieldTrialEnabledValue = @"Enabled"; 29 30static std::unique_ptr<char[]> gFieldTrialInitString; 31 32void 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. 39 NSMutableString *fieldTrialInitString = [NSMutableString string]; 40 for (NSString *key in fieldTrials) { 41 NSString *fieldTrialEntry = [NSString stringWithFormat:@"%@/%@/", key, fieldTrials[key]]; 42 [fieldTrialInitString appendString:fieldTrialEntry]; 43 } 44 size_t len = fieldTrialInitString.length + 1; 45 gFieldTrialInitString.reset(new char[len]); 46 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} 54