From 4f735d16ad56cb61f857c7ad813b6d33cd5a9c8a Mon Sep 17 00:00:00 2001 From: tkchin Date: Thu, 3 Mar 2016 17:54:28 -0800 Subject: [PATCH] Enable iOS AppRTCDemo send side BWE. BUG= Review URL: https://codereview.webrtc.org/1757173002 Cr-Commit-Position: refs/heads/master@{#11865} --- webrtc/base/BUILD.gn | 2 + webrtc/base/base.gyp | 2 + webrtc/base/objc/RTCFieldTrials.h | 21 +++++++++++ webrtc/base/objc/RTCFieldTrials.mm | 37 +++++++++++++++++++ .../objc/AppRTCDemo/ios/ARDAppDelegate.m | 2 + 5 files changed, 64 insertions(+) create mode 100644 webrtc/base/objc/RTCFieldTrials.h create mode 100644 webrtc/base/objc/RTCFieldTrials.mm diff --git a/webrtc/base/BUILD.gn b/webrtc/base/BUILD.gn index a056269c95..5726a26e6a 100644 --- a/webrtc/base/BUILD.gn +++ b/webrtc/base/BUILD.gn @@ -637,6 +637,8 @@ if (is_ios) { "objc/RTCCameraPreviewView.m", "objc/RTCDispatcher.h", "objc/RTCDispatcher.m", + "objc/RTCFieldTrials.h", + "objc/RTCFieldTrials.mm", "objc/RTCFileLogger.h", "objc/RTCFileLogger.mm", "objc/RTCLogging.h", diff --git a/webrtc/base/base.gyp b/webrtc/base/base.gyp index 3c569fae47..a6b2b1cd4a 100644 --- a/webrtc/base/base.gyp +++ b/webrtc/base/base.gyp @@ -36,6 +36,8 @@ 'objc/NSString+StdString.mm', 'objc/RTCDispatcher.h', 'objc/RTCDispatcher.m', + 'objc/RTCFieldTrials.h', + 'objc/RTCFieldTrials.mm', 'objc/RTCFileLogger.h', 'objc/RTCFileLogger.mm', 'objc/RTCLogging.h', diff --git a/webrtc/base/objc/RTCFieldTrials.h b/webrtc/base/objc/RTCFieldTrials.h new file mode 100644 index 0000000000..13b9ae4d52 --- /dev/null +++ b/webrtc/base/objc/RTCFieldTrials.h @@ -0,0 +1,21 @@ +/* + * Copyright 2016 The WebRTC Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "webrtc/base/objc/RTCMacros.h" + +typedef NS_OPTIONS(NSUInteger, RTCFieldTrialOptions) { + RTCFieldTrialOptionsNone = 0, + RTCFieldTrialOptionsSendSideBwe = 1 << 0, +}; + +/** Must be called before any other call into WebRTC. See: + * webrtc/system_wrappers/include/field_trial_default.h + */ +RTC_EXPORT void RTCInitFieldTrials(RTCFieldTrialOptions options); diff --git a/webrtc/base/objc/RTCFieldTrials.mm b/webrtc/base/objc/RTCFieldTrials.mm new file mode 100644 index 0000000000..331cb0bd75 --- /dev/null +++ b/webrtc/base/objc/RTCFieldTrials.mm @@ -0,0 +1,37 @@ +/* + * Copyright 2016 The WebRTC Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "webrtc/base/objc/RTCFieldTrials.h" + +#include +#include "webrtc/system_wrappers/include/field_trial_default.h" + +#import +#import "webrtc/base/objc/RTCLogging.h" + +static NSString * const kRTCEnableSendSideBweString = + @"WebRTC-SendSideBwe/Enabled/"; +static std::unique_ptr gFieldTrialInitString; + +void RTCInitFieldTrials(RTCFieldTrialOptions options) { + NSMutableString *fieldTrialInitString = [NSMutableString string]; + if (options & RTCFieldTrialOptionsSendSideBwe) { + [fieldTrialInitString appendString:kRTCEnableSendSideBweString]; + } + size_t len = fieldTrialInitString.length + 1; + gFieldTrialInitString.reset(new char[len]); + if (![fieldTrialInitString getCString:gFieldTrialInitString.get() + maxLength:len + encoding:NSUTF8StringEncoding]) { + RTCLogError(@"Failed to convert field trial string."); + return; + } + webrtc::field_trial::InitFieldTrialsFromString(gFieldTrialInitString.get()); +} diff --git a/webrtc/examples/objc/AppRTCDemo/ios/ARDAppDelegate.m b/webrtc/examples/objc/AppRTCDemo/ios/ARDAppDelegate.m index d815008cae..aa99cc08c8 100644 --- a/webrtc/examples/objc/AppRTCDemo/ios/ARDAppDelegate.m +++ b/webrtc/examples/objc/AppRTCDemo/ios/ARDAppDelegate.m @@ -10,6 +10,7 @@ #import "ARDAppDelegate.h" +#import "webrtc/base/objc/RTCFieldTrials.h" #import "webrtc/base/objc/RTCTracing.h" #import "RTCLogging.h" #import "RTCPeerConnectionFactory.h" @@ -24,6 +25,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + RTCInitFieldTrials(RTCFieldTrialOptionsSendSideBwe); [RTCPeerConnectionFactory initializeSSL]; RTCSetupInternalTracer(); _window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];