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}
This commit is contained in:
sakal 2017-03-28 01:22:48 -07:00 committed by Commit bot
parent bcbaf74643
commit c4adacfb15
11 changed files with 34 additions and 46 deletions

View File

@ -221,6 +221,11 @@ if (is_ios || (is_mac && target_cpu != "x86")) {
"objc/AppRTCMobile/ARDRoomServerClient.h",
"objc/AppRTCMobile/ARDSDPUtils.h",
"objc/AppRTCMobile/ARDSDPUtils.m",
"objc/AppRTCMobile/ARDSettingsModel+Private.h",
"objc/AppRTCMobile/ARDSettingsModel.h",
"objc/AppRTCMobile/ARDSettingsModel.m",
"objc/AppRTCMobile/ARDSettingsStore.h",
"objc/AppRTCMobile/ARDSettingsStore.m",
"objc/AppRTCMobile/ARDSignalingChannel.h",
"objc/AppRTCMobile/ARDSignalingMessage.h",
"objc/AppRTCMobile/ARDSignalingMessage.m",
@ -264,11 +269,6 @@ if (is_ios || (is_mac && target_cpu != "x86")) {
"objc/AppRTCMobile/ios/ARDMainView.m",
"objc/AppRTCMobile/ios/ARDMainViewController.h",
"objc/AppRTCMobile/ios/ARDMainViewController.m",
"objc/AppRTCMobile/ios/ARDSettingsModel+Private.h",
"objc/AppRTCMobile/ios/ARDSettingsModel.h",
"objc/AppRTCMobile/ios/ARDSettingsModel.m",
"objc/AppRTCMobile/ios/ARDSettingsStore.h",
"objc/AppRTCMobile/ios/ARDSettingsStore.m",
"objc/AppRTCMobile/ios/ARDSettingsViewController.h",
"objc/AppRTCMobile/ios/ARDSettingsViewController.m",
"objc/AppRTCMobile/ios/ARDStatsView.h",

View File

@ -23,6 +23,7 @@ typedef NS_ENUM(NSInteger, ARDAppClientState) {
};
@class ARDAppClient;
@class ARDSettingsModel;
@class RTCMediaConstraints;
// The delegate is informed of pertinent events and will be called on the
@ -60,22 +61,17 @@ typedef NS_ENUM(NSInteger, ARDAppClientState) {
@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

View File

@ -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 @@ static int const kKbpsMultiplier = 1000;
@implementation ARDAppClient {
RTCFileLogger *_fileLogger;
ARDTimerProxy *_statsTimer;
RTCMediaConstraints *_cameraConstraints;
NSNumber *_maxBitrate;
NSString *_videoCodec;
ARDSettingsModel *_settings;
}
@synthesize shouldGetStats = _shouldGetStats;
@ -129,15 +128,13 @@ static int const kKbpsMultiplier = 1000;
@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 @@ static int const kKbpsMultiplier = 1000;
}
- (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 @@ static int const kKbpsMultiplier = 1000;
#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 @@ static int const kKbpsMultiplier = 1000;
// 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 @@ static int const kKbpsMultiplier = 1000;
// 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 @@ static int const kKbpsMultiplier = 1000;
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 @@ static int const kKbpsMultiplier = 1000;
}
- (RTCMediaConstraints *)cameraConstraints {
return _cameraConstraints;
RTCMediaConstraints *cameraConstraints = [[RTCMediaConstraints alloc]
initWithMandatoryConstraints:nil
optionalConstraints:[_settings currentMediaConstraintFromStoreAsRTCDictionary]];
return cameraConstraints;
}
- (RTCMediaConstraints *)defaultAnswerConstraints {

View File

@ -19,7 +19,7 @@ NS_ASSUME_NONNULL_BEGIN
*/
@interface ARDSettingsStore : NSObject
@property(nonatomic) NSString* videoCodec;
@property(nonatomic) NSString *videoCodec;
/**
* Returns current video resolution media constraint string stored in the store.

View File

@ -18,7 +18,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface ARDSettingsStore () {
NSUserDefaults *_storage;
}
@property(nonatomic, strong) NSUserDefaults *storage;
@property(nonatomic, strong, readonly) NSUserDefaults *storage;
@end
@implementation ARDSettingsStore

View File

@ -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

View File

@ -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 @@ static NSUInteger const kBottomViewHeight = 200;
}
[_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

View File

@ -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