xref: /aosp_15_r20/external/webrtc/sdk/objc/api/peerconnection/RTCFieldTrials.mm (revision d9f758449e529ab9291ac668be2861e7a55c2422)
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 kRTCFieldTrialAudioForceABWENoTWCCKey = @"WebRTC-Audio-ABWENoTWCC";
20NSString * const kRTCFieldTrialFlexFec03AdvertisedKey = @"WebRTC-FlexFEC-03-Advertised";
21NSString * const kRTCFieldTrialFlexFec03Key = @"WebRTC-FlexFEC-03";
22NSString * const kRTCFieldTrialH264HighProfileKey = @"WebRTC-H264HighProfile";
23NSString * const kRTCFieldTrialMinimizeResamplingOnMobileKey =
24    @"WebRTC-Audio-MinimizeResamplingOnMobile";
25NSString *const kRTCFieldTrialUseNWPathMonitor = @"WebRTC-Network-UseNWPathMonitor";
26NSString * const kRTCFieldTrialEnabledValue = @"Enabled";
27
28// InitFieldTrialsFromString stores the char*, so the char array must outlive
29// the application.
30static char *gFieldTrialInitString = nullptr;
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  if (gFieldTrialInitString != nullptr) {
46    delete[] gFieldTrialInitString;
47  }
48  gFieldTrialInitString = new char[len];
49  if (![fieldTrialInitString getCString:gFieldTrialInitString
50                              maxLength:len
51                               encoding:NSUTF8StringEncoding]) {
52    RTCLogError(@"Failed to convert field trial string.");
53    return;
54  }
55  webrtc::field_trial::InitFieldTrialsFromString(gFieldTrialInitString);
56}
57