Pass settings model to ARDAppClient instead of individual settings.

Moves settings model and related classes to code common for both iOS
and Mac.

BUG=webrtc:7177,webrtc:6494

Review-Url: https://codereview.webrtc.org/2770113004
Cr-Commit-Position: refs/heads/master@{#17408}
diff --git a/webrtc/examples/objc/AppRTCMobile/ARDAppClient.h b/webrtc/examples/objc/AppRTCMobile/ARDAppClient.h
index 0feb015..933dc6b 100644
--- a/webrtc/examples/objc/AppRTCMobile/ARDAppClient.h
+++ b/webrtc/examples/objc/AppRTCMobile/ARDAppClient.h
@@ -23,6 +23,7 @@
 };
 
 @class ARDAppClient;
+@class ARDSettingsModel;
 @class RTCMediaConstraints;
 
 // The delegate is informed of pertinent events and will be called on the
@@ -60,22 +61,17 @@
 @property(nonatomic, weak) id<ARDAppClientDelegate> delegate;
 // Convenience constructor since all expected use cases will need a delegate
 // in order to receive remote tracks.
-- (instancetype)initWithDelegate:(id<ARDAppClientDelegate>)delegate
-                preferVideoCodec:(NSString*)codec;
-
-// Sets camera constraints.
-- (void)setCameraConstraints:(RTCMediaConstraints *)mediaConstraints;
-
-// Sets maximum bitrate the rtp sender should use.
-- (void)setMaxBitrate:(NSNumber *)maxBitrate;
+- (instancetype)initWithDelegate:(id<ARDAppClientDelegate>)delegate;
 
 // Establishes a connection with the AppRTC servers for the given room id.
+// |settings| is an object containing settings such as video codec for the call.
 // If |isLoopback| is true, the call will connect to itself.
 // If |isAudioOnly| is true, video will be disabled for the call.
 // If |shouldMakeAecDump| is true, an aecdump will be created for the call.
 // If |shouldUseLevelControl| is true, the level controller will be used
 // in the call.
 - (void)connectToRoomWithId:(NSString *)roomId
+                   settings:(ARDSettingsModel *)settings
                  isLoopback:(BOOL)isLoopback
                 isAudioOnly:(BOOL)isAudioOnly
           shouldMakeAecDump:(BOOL)shouldMakeAecDump
diff --git a/webrtc/examples/objc/AppRTCMobile/ARDAppClient.m b/webrtc/examples/objc/AppRTCMobile/ARDAppClient.m
index 497a137..ef38138 100644
--- a/webrtc/examples/objc/AppRTCMobile/ARDAppClient.m
+++ b/webrtc/examples/objc/AppRTCMobile/ARDAppClient.m
@@ -23,11 +23,12 @@
 #import "WebRTC/RTCTracing.h"
 
 #import "ARDAppEngineClient.h"
-#import "ARDTURNClient+Internal.h"
 #import "ARDJoinResponse.h"
 #import "ARDMessageResponse.h"
 #import "ARDSDPUtils.h"
+#import "ARDSettingsModel.h"
 #import "ARDSignalingMessage.h"
+#import "ARDTURNClient+Internal.h"
 #import "ARDUtilities.h"
 #import "ARDWebSocketChannel.h"
 #import "RTCIceCandidate+JSON.h"
@@ -98,9 +99,7 @@
 @implementation ARDAppClient {
   RTCFileLogger *_fileLogger;
   ARDTimerProxy *_statsTimer;
-  RTCMediaConstraints *_cameraConstraints;
-  NSNumber *_maxBitrate;
-  NSString *_videoCodec;
+  ARDSettingsModel *_settings;
 }
 
 @synthesize shouldGetStats = _shouldGetStats;
@@ -129,15 +128,13 @@
 @synthesize shouldUseLevelControl = _shouldUseLevelControl;
 
 - (instancetype)init {
-  return [self initWithDelegate:nil preferVideoCodec:@"H264"];
+  return [self initWithDelegate:nil];
 }
 
-- (instancetype)initWithDelegate:(id<ARDAppClientDelegate>)delegate
-                preferVideoCodec:(NSString *)codec {
+- (instancetype)initWithDelegate:(id<ARDAppClientDelegate>)delegate {
   if (self = [super init]) {
     _roomServerClient = [[ARDAppEngineClient alloc] init];
     _delegate = delegate;
-    _videoCodec = codec;
     NSURL *turnRequestURL = [NSURL URLWithString:kARDIceServerRequestUrl];
     _turnClient = [[ARDTURNClient alloc] initWithURL:turnRequestURL];
     [self configure];
@@ -213,12 +210,14 @@
 }
 
 - (void)connectToRoomWithId:(NSString *)roomId
+                   settings:(ARDSettingsModel *)settings
                  isLoopback:(BOOL)isLoopback
                 isAudioOnly:(BOOL)isAudioOnly
           shouldMakeAecDump:(BOOL)shouldMakeAecDump
       shouldUseLevelControl:(BOOL)shouldUseLevelControl {
   NSParameterAssert(roomId.length);
   NSParameterAssert(_state == kARDAppClientStateDisconnected);
+  _settings = settings;
   _isLoopback = isLoopback;
   _isAudioOnly = isAudioOnly;
   _shouldMakeAecDump = shouldMakeAecDump;
@@ -319,14 +318,6 @@
 #endif
 }
 
-- (void)setCameraConstraints:(RTCMediaConstraints *)mediaConstraints {
-  _cameraConstraints = mediaConstraints;
-}
-
-- (void)setMaxBitrate:(NSNumber *)maxBitrate {
-  _maxBitrate = maxBitrate;
-}
-
 #pragma mark - ARDSignalingChannelDelegate
 
 - (void)channel:(id<ARDSignalingChannel>)channel
@@ -458,7 +449,7 @@
     // Prefer codec from settings if available.
     RTCSessionDescription *sdpPreferringCodec =
         [ARDSDPUtils descriptionForDescription:sdp
-                           preferredVideoCodec:_videoCodec];
+                           preferredVideoCodec:[_settings currentVideoCodecSettingFromStore]];
     __weak ARDAppClient *weakSelf = self;
     [_peerConnection setLocalDescription:sdpPreferringCodec
                        completionHandler:^(NSError *error) {
@@ -612,7 +603,7 @@
       // Prefer codec from settings if available.
       RTCSessionDescription *sdpPreferringCodec =
           [ARDSDPUtils descriptionForDescription:description
-                             preferredVideoCodec:_videoCodec];
+                             preferredVideoCodec:[_settings currentVideoCodecSettingFromStore]];
       __weak ARDAppClient *weakSelf = self;
       [_peerConnection setRemoteDescription:sdpPreferringCodec
                           completionHandler:^(NSError *error) {
@@ -688,7 +679,7 @@
   for (RTCRtpSender *sender in _peerConnection.senders) {
     if (sender.track != nil) {
       if ([sender.track.kind isEqualToString:kARDVideoTrackKind]) {
-        [self setMaxBitrate:_maxBitrate forVideoSender:sender];
+        [self setMaxBitrate:[_settings currentMaxBitrateSettingFromStore] forVideoSender:sender];
       }
     }
   }
@@ -774,7 +765,10 @@
 }
 
 - (RTCMediaConstraints *)cameraConstraints {
-  return _cameraConstraints;
+  RTCMediaConstraints *cameraConstraints = [[RTCMediaConstraints alloc]
+      initWithMandatoryConstraints:nil
+               optionalConstraints:[_settings currentMediaConstraintFromStoreAsRTCDictionary]];
+  return cameraConstraints;
 }
 
 - (RTCMediaConstraints *)defaultAnswerConstraints {
diff --git a/webrtc/examples/objc/AppRTCMobile/ios/ARDSettingsModel+Private.h b/webrtc/examples/objc/AppRTCMobile/ARDSettingsModel+Private.h
similarity index 100%
rename from webrtc/examples/objc/AppRTCMobile/ios/ARDSettingsModel+Private.h
rename to webrtc/examples/objc/AppRTCMobile/ARDSettingsModel+Private.h
diff --git a/webrtc/examples/objc/AppRTCMobile/ios/ARDSettingsModel.h b/webrtc/examples/objc/AppRTCMobile/ARDSettingsModel.h
similarity index 100%
rename from webrtc/examples/objc/AppRTCMobile/ios/ARDSettingsModel.h
rename to webrtc/examples/objc/AppRTCMobile/ARDSettingsModel.h
diff --git a/webrtc/examples/objc/AppRTCMobile/ios/ARDSettingsModel.m b/webrtc/examples/objc/AppRTCMobile/ARDSettingsModel.m
similarity index 100%
rename from webrtc/examples/objc/AppRTCMobile/ios/ARDSettingsModel.m
rename to webrtc/examples/objc/AppRTCMobile/ARDSettingsModel.m
diff --git a/webrtc/examples/objc/AppRTCMobile/ios/ARDSettingsStore.h b/webrtc/examples/objc/AppRTCMobile/ARDSettingsStore.h
similarity index 96%
rename from webrtc/examples/objc/AppRTCMobile/ios/ARDSettingsStore.h
rename to webrtc/examples/objc/AppRTCMobile/ARDSettingsStore.h
index b82ec70..b010b7f 100644
--- a/webrtc/examples/objc/AppRTCMobile/ios/ARDSettingsStore.h
+++ b/webrtc/examples/objc/AppRTCMobile/ARDSettingsStore.h
@@ -19,7 +19,7 @@
  */
 @interface ARDSettingsStore : NSObject
 
-@property(nonatomic) NSString* videoCodec;
+@property(nonatomic) NSString *videoCodec;
 
 /**
  * Returns current video resolution media constraint string stored in the store.
diff --git a/webrtc/examples/objc/AppRTCMobile/ios/ARDSettingsStore.m b/webrtc/examples/objc/AppRTCMobile/ARDSettingsStore.m
similarity index 96%
rename from webrtc/examples/objc/AppRTCMobile/ios/ARDSettingsStore.m
rename to webrtc/examples/objc/AppRTCMobile/ARDSettingsStore.m
index c05df44..6d9fa5b 100644
--- a/webrtc/examples/objc/AppRTCMobile/ios/ARDSettingsStore.m
+++ b/webrtc/examples/objc/AppRTCMobile/ARDSettingsStore.m
@@ -18,7 +18,7 @@
 @interface ARDSettingsStore () {
   NSUserDefaults *_storage;
 }
-@property(nonatomic, strong) NSUserDefaults *storage;
+@property(nonatomic, strong, readonly) NSUserDefaults *storage;
 @end
 
 @implementation ARDSettingsStore
diff --git a/webrtc/examples/objc/AppRTCMobile/ios/ARDVideoCallViewController.m b/webrtc/examples/objc/AppRTCMobile/ios/ARDVideoCallViewController.m
index f58ee66..d1ae3f9 100644
--- a/webrtc/examples/objc/AppRTCMobile/ios/ARDVideoCallViewController.m
+++ b/webrtc/examples/objc/AppRTCMobile/ios/ARDVideoCallViewController.m
@@ -45,17 +45,10 @@
                    delegate:(id<ARDVideoCallViewControllerDelegate>)delegate {
   if (self = [super init]) {
     ARDSettingsModel *settingsModel = [[ARDSettingsModel alloc] init];
-    NSString* videoCodec = [settingsModel currentVideoCodecSettingFromStore];
     _delegate = delegate;
-    _client = [[ARDAppClient alloc] initWithDelegate:self
-                                    preferVideoCodec:videoCodec];
-    RTCMediaConstraints *cameraConstraints = [[RTCMediaConstraints alloc]
-        initWithMandatoryConstraints:nil
-                 optionalConstraints:[settingsModel
-                                         currentMediaConstraintFromStoreAsRTCDictionary]];
-    [_client setMaxBitrate:[settingsModel currentMaxBitrateSettingFromStore]];
-    [_client setCameraConstraints:cameraConstraints];
+    _client = [[ARDAppClient alloc] initWithDelegate:self];
     [_client connectToRoomWithId:room
+                        settings:settingsModel
                       isLoopback:isLoopback
                      isAudioOnly:isAudioOnly
                shouldMakeAecDump:shouldMakeAecDump
diff --git a/webrtc/examples/objc/AppRTCMobile/mac/APPRTCViewController.m b/webrtc/examples/objc/AppRTCMobile/mac/APPRTCViewController.m
index bcf26b2..69c537a 100644
--- a/webrtc/examples/objc/AppRTCMobile/mac/APPRTCViewController.m
+++ b/webrtc/examples/objc/AppRTCMobile/mac/APPRTCViewController.m
@@ -16,6 +16,7 @@
 #import "WebRTC/RTCVideoTrack.h"
 
 #import "ARDAppClient.h"
+#import "ARDSettingsModel.h"
 
 static NSUInteger const kContentWidth = 900;
 static NSUInteger const kRoomFieldWidth = 200;
@@ -369,9 +370,9 @@
   }
 
   [_client disconnect];
-  ARDAppClient *client = [[ARDAppClient alloc] initWithDelegate:self
-                                               preferVideoCodec:@"H264"];
+  ARDAppClient* client = [[ARDAppClient alloc] initWithDelegate:self];
   [client connectToRoomWithId:roomId
+                     settings:[[ARDSettingsModel alloc] init]  // Use default settings.
                    isLoopback:isLoopback
                   isAudioOnly:NO
             shouldMakeAecDump:NO
diff --git a/webrtc/examples/objc/AppRTCMobile/tests/ARDAppClient_xctest.mm b/webrtc/examples/objc/AppRTCMobile/tests/ARDAppClient_xctest.mm
index c2cd9e3..fc7b768 100644
--- a/webrtc/examples/objc/AppRTCMobile/tests/ARDAppClient_xctest.mm
+++ b/webrtc/examples/objc/AppRTCMobile/tests/ARDAppClient_xctest.mm
@@ -22,6 +22,7 @@
 #import "ARDJoinResponse+Internal.h"
 #import "ARDMessageResponse+Internal.h"
 #import "ARDSDPUtils.h"
+#import "ARDSettingsModel.h"
 
 @interface ARDAppClientTest : XCTestCase
 @end
@@ -209,11 +210,13 @@
 
   // Kick off connection.
   [caller connectToRoomWithId:roomId
+                     settings:[[ARDSettingsModel alloc] init]
                    isLoopback:NO
                   isAudioOnly:NO
             shouldMakeAecDump:NO
         shouldUseLevelControl:NO];
   [answerer connectToRoomWithId:roomId
+                       settings:[[ARDSettingsModel alloc] init]
                      isLoopback:NO
                     isAudioOnly:NO
               shouldMakeAecDump:NO
@@ -250,6 +253,7 @@
 
   // Kick off connection.
   [caller connectToRoomWithId:roomId
+                     settings:[[ARDSettingsModel alloc] init]
                    isLoopback:NO
                   isAudioOnly:NO
             shouldMakeAecDump:NO