Update iOS AppRTCDemo to use level controller.

NOTRY=True
BUG=

Review-Url: https://codereview.webrtc.org/2294913003
Cr-Commit-Position: refs/heads/master@{#13977}
This commit is contained in:
tkchin
2016-08-30 12:35:05 -07:00
committed by Commit bot
parent d4bfbfc75a
commit ab1293ad76
12 changed files with 92 additions and 18 deletions

View File

@ -45,6 +45,7 @@
@property(nonatomic, readonly) BOOL isAudioOnly; @property(nonatomic, readonly) BOOL isAudioOnly;
@property(nonatomic, readonly) BOOL shouldMakeAecDump; @property(nonatomic, readonly) BOOL shouldMakeAecDump;
@property(nonatomic, assign) BOOL isAecDumpActive; @property(nonatomic, assign) BOOL isAecDumpActive;
@property(nonatomic, readonly) BOOL shouldUseLevelControl;
@property(nonatomic, strong) @property(nonatomic, strong)
RTCMediaConstraints *defaultPeerConnectionConstraints; RTCMediaConstraints *defaultPeerConnectionConstraints;

View File

@ -65,10 +65,13 @@ typedef NS_ENUM(NSInteger, ARDAppClientState) {
// If |isLoopback| is true, the call will connect to itself. // If |isLoopback| is true, the call will connect to itself.
// If |isAudioOnly| is true, video will be disabled for the call. // If |isAudioOnly| is true, video will be disabled for the call.
// If |shouldMakeAecDump| is true, an aecdump will be created 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 - (void)connectToRoomWithId:(NSString *)roomId
isLoopback:(BOOL)isLoopback isLoopback:(BOOL)isLoopback
isAudioOnly:(BOOL)isAudioOnly isAudioOnly:(BOOL)isAudioOnly
shouldMakeAecDump:(BOOL)shouldMakeAecDump; shouldMakeAecDump:(BOOL)shouldMakeAecDump
shouldUseLevelControl:(BOOL)shouldUseLevelControl;
// Disconnects from the AppRTC servers and any connected clients. // Disconnects from the AppRTC servers and any connected clients.
- (void)disconnect; - (void)disconnect;

View File

@ -131,6 +131,7 @@ static int64_t const kARDAppClientRtcEventLogMaxSizeInBytes = 5e6; // 5 MB.
@synthesize isAudioOnly = _isAudioOnly; @synthesize isAudioOnly = _isAudioOnly;
@synthesize shouldMakeAecDump = _shouldMakeAecDump; @synthesize shouldMakeAecDump = _shouldMakeAecDump;
@synthesize isAecDumpActive = _isAecDumpActive; @synthesize isAecDumpActive = _isAecDumpActive;
@synthesize shouldUseLevelControl = _shouldUseLevelControl;
- (instancetype)init { - (instancetype)init {
if (self = [super init]) { if (self = [super init]) {
@ -223,12 +224,14 @@ static int64_t const kARDAppClientRtcEventLogMaxSizeInBytes = 5e6; // 5 MB.
- (void)connectToRoomWithId:(NSString *)roomId - (void)connectToRoomWithId:(NSString *)roomId
isLoopback:(BOOL)isLoopback isLoopback:(BOOL)isLoopback
isAudioOnly:(BOOL)isAudioOnly isAudioOnly:(BOOL)isAudioOnly
shouldMakeAecDump:(BOOL)shouldMakeAecDump { shouldMakeAecDump:(BOOL)shouldMakeAecDump
shouldUseLevelControl:(BOOL)shouldUseLevelControl {
NSParameterAssert(roomId.length); NSParameterAssert(roomId.length);
NSParameterAssert(_state == kARDAppClientStateDisconnected); NSParameterAssert(_state == kARDAppClientStateDisconnected);
_isLoopback = isLoopback; _isLoopback = isLoopback;
_isAudioOnly = isAudioOnly; _isAudioOnly = isAudioOnly;
_shouldMakeAecDump = shouldMakeAecDump; _shouldMakeAecDump = shouldMakeAecDump;
_shouldUseLevelControl = shouldUseLevelControl;
self.state = kARDAppClientStateConnecting; self.state = kARDAppClientStateConnecting;
#if defined(WEBRTC_IOS) #if defined(WEBRTC_IOS)
@ -689,10 +692,13 @@ static int64_t const kARDAppClientRtcEventLogMaxSizeInBytes = 5e6; // 5 MB.
} }
- (RTCRtpSender *)createAudioSender { - (RTCRtpSender *)createAudioSender {
RTCMediaConstraints *constraints = [self defaultMediaAudioConstraints];
RTCAudioSource *source = [_factory audioSourceWithConstraints:constraints];
RTCAudioTrack *track = [_factory audioTrackWithSource:source
trackId:kARDAudioTrackId];
RTCRtpSender *sender = RTCRtpSender *sender =
[_peerConnection senderWithKind:kRTCMediaStreamTrackKindAudio [_peerConnection senderWithKind:kRTCMediaStreamTrackKindAudio
streamId:kARDMediaStreamId]; streamId:kARDMediaStreamId];
RTCAudioTrack *track = [_factory audioTrackWithTrackId:kARDAudioTrackId];
sender.track = track; sender.track = track;
return sender; return sender;
} }
@ -744,6 +750,16 @@ static int64_t const kARDAppClientRtcEventLogMaxSizeInBytes = 5e6; // 5 MB.
#pragma mark - Defaults #pragma mark - Defaults
- (RTCMediaConstraints *)defaultMediaAudioConstraints {
NSString *valueLevelControl = _shouldUseLevelControl ?
kRTCMediaConstraintsValueTrue : kRTCMediaConstraintsValueFalse;
NSDictionary *mandatoryConstraints = @{ kRTCMediaConstraintsLevelControl : valueLevelControl };
RTCMediaConstraints* constraints =
[[RTCMediaConstraints alloc] initWithMandatoryConstraints:mandatoryConstraints
optionalConstraints:nil];
return constraints;
}
- (RTCMediaConstraints *)defaultMediaStreamConstraints { - (RTCMediaConstraints *)defaultMediaStreamConstraints {
RTCMediaConstraints* constraints = RTCMediaConstraints* constraints =
[[RTCMediaConstraints alloc] [[RTCMediaConstraints alloc]

View File

@ -15,11 +15,12 @@
@protocol ARDMainViewDelegate <NSObject> @protocol ARDMainViewDelegate <NSObject>
- (void)mainView:(ARDMainView *)mainView - (void)mainView:(ARDMainView *)mainView
didInputRoom:(NSString *)room didInputRoom:(NSString *)room
isLoopback:(BOOL)isLoopback isLoopback:(BOOL)isLoopback
isAudioOnly:(BOOL)isAudioOnly isAudioOnly:(BOOL)isAudioOnly
shouldMakeAecDump:(BOOL)shouldMakeAecDump shouldMakeAecDump:(BOOL)shouldMakeAecDump
useManualAudio:(BOOL)useManualAudio; shouldUseLevelControl:(BOOL)shouldUseLevelControl
useManualAudio:(BOOL)useManualAudio;
- (void)mainViewDidToggleAudioLoop:(ARDMainView *)mainView; - (void)mainViewDidToggleAudioLoop:(ARDMainView *)mainView;

View File

@ -121,6 +121,8 @@ static CGFloat const kCallControlMargin = 8;
UILabel *_audioOnlyLabel; UILabel *_audioOnlyLabel;
UISwitch *_aecdumpSwitch; UISwitch *_aecdumpSwitch;
UILabel *_aecdumpLabel; UILabel *_aecdumpLabel;
UISwitch *_levelControlSwitch;
UILabel *_levelControlLabel;
UISwitch *_loopbackSwitch; UISwitch *_loopbackSwitch;
UILabel *_loopbackLabel; UILabel *_loopbackLabel;
UISwitch *_useManualAudioSwitch; UISwitch *_useManualAudioSwitch;
@ -187,6 +189,17 @@ static CGFloat const kCallControlMargin = 8;
[_aecdumpLabel sizeToFit]; [_aecdumpLabel sizeToFit];
[self addSubview:_aecdumpLabel]; [self addSubview:_aecdumpLabel];
_levelControlSwitch = [[UISwitch alloc] initWithFrame:CGRectZero];
[_levelControlSwitch sizeToFit];
[self addSubview:_levelControlSwitch];
_levelControlLabel = [[UILabel alloc] initWithFrame:CGRectZero];
_levelControlLabel.text = @"Use level controller";
_levelControlLabel.font = controlFont;
_levelControlLabel.textColor = controlFontColor;
[_levelControlLabel sizeToFit];
[self addSubview:_levelControlLabel];
_useManualAudioSwitch = [[UISwitch alloc] initWithFrame:CGRectZero]; _useManualAudioSwitch = [[UISwitch alloc] initWithFrame:CGRectZero];
[_useManualAudioSwitch sizeToFit]; [_useManualAudioSwitch sizeToFit];
_useManualAudioSwitch.on = YES; _useManualAudioSwitch.on = YES;
@ -299,9 +312,20 @@ static CGFloat const kCallControlMargin = 8;
_aecdumpLabel.center = CGPointMake(aecdumpModeLabelCenterX, _aecdumpLabel.center = CGPointMake(aecdumpModeLabelCenterX,
CGRectGetMidY(aecdumpModeRect)); CGRectGetMidY(aecdumpModeRect));
CGFloat levelControlModeTop =
CGRectGetMaxY(_aecdumpSwitch.frame) + kCallControlMargin;
CGRect levelControlModeRect = CGRectMake(kCallControlMargin * 3,
levelControlModeTop,
_levelControlSwitch.frame.size.width,
_levelControlSwitch.frame.size.height);
_levelControlSwitch.frame = levelControlModeRect;
CGFloat levelControlModeLabelCenterX = CGRectGetMaxX(levelControlModeRect) +
kCallControlMargin + _levelControlLabel.frame.size.width / 2;
_levelControlLabel.center = CGPointMake(levelControlModeLabelCenterX,
CGRectGetMidY(levelControlModeRect));
CGFloat useManualAudioTop = CGFloat useManualAudioTop =
CGRectGetMaxY(_aecdumpSwitch.frame) + kCallControlMargin; CGRectGetMaxY(_levelControlSwitch.frame) + kCallControlMargin;
CGRect useManualAudioRect = CGRect useManualAudioRect =
CGRectMake(kCallControlMargin * 3, CGRectMake(kCallControlMargin * 3,
useManualAudioTop, useManualAudioTop,
@ -361,6 +385,7 @@ static CGFloat const kCallControlMargin = 8;
isLoopback:_loopbackSwitch.isOn isLoopback:_loopbackSwitch.isOn
isAudioOnly:_audioOnlySwitch.isOn isAudioOnly:_audioOnlySwitch.isOn
shouldMakeAecDump:_aecdumpSwitch.isOn shouldMakeAecDump:_aecdumpSwitch.isOn
shouldUseLevelControl:_levelControlSwitch.isOn
useManualAudio:_useManualAudioSwitch.isOn]; useManualAudio:_useManualAudioSwitch.isOn];
} }

View File

@ -54,11 +54,12 @@
#pragma mark - ARDMainViewDelegate #pragma mark - ARDMainViewDelegate
- (void)mainView:(ARDMainView *)mainView - (void)mainView:(ARDMainView *)mainView
didInputRoom:(NSString *)room didInputRoom:(NSString *)room
isLoopback:(BOOL)isLoopback isLoopback:(BOOL)isLoopback
isAudioOnly:(BOOL)isAudioOnly isAudioOnly:(BOOL)isAudioOnly
shouldMakeAecDump:(BOOL)shouldMakeAecDump shouldMakeAecDump:(BOOL)shouldMakeAecDump
useManualAudio:(BOOL)useManualAudio { shouldUseLevelControl:(BOOL)shouldUseLevelControl
useManualAudio:(BOOL)useManualAudio {
if (!room.length) { if (!room.length) {
[self showAlertWithMessage:@"Missing room name."]; [self showAlertWithMessage:@"Missing room name."];
return; return;
@ -98,6 +99,7 @@
isLoopback:isLoopback isLoopback:isLoopback
isAudioOnly:isAudioOnly isAudioOnly:isAudioOnly
shouldMakeAecDump:shouldMakeAecDump shouldMakeAecDump:shouldMakeAecDump
shouldUseLevelControl:shouldUseLevelControl
delegate:self]; delegate:self];
videoCallViewController.modalTransitionStyle = videoCallViewController.modalTransitionStyle =
UIModalTransitionStyleCrossDissolve; UIModalTransitionStyleCrossDissolve;

View File

@ -25,6 +25,7 @@
isLoopback:(BOOL)isLoopback isLoopback:(BOOL)isLoopback
isAudioOnly:(BOOL)isAudioOnly isAudioOnly:(BOOL)isAudioOnly
shouldMakeAecDump:(BOOL)shouldMakeAecDump shouldMakeAecDump:(BOOL)shouldMakeAecDump
shouldUseLevelControl:(BOOL)shouldUseLevelControl
delegate:(id<ARDVideoCallViewControllerDelegate>)delegate; delegate:(id<ARDVideoCallViewControllerDelegate>)delegate;
@end @end

View File

@ -40,6 +40,7 @@
isLoopback:(BOOL)isLoopback isLoopback:(BOOL)isLoopback
isAudioOnly:(BOOL)isAudioOnly isAudioOnly:(BOOL)isAudioOnly
shouldMakeAecDump:(BOOL)shouldMakeAecDump shouldMakeAecDump:(BOOL)shouldMakeAecDump
shouldUseLevelControl:(BOOL)shouldUseLevelControl
delegate:(id<ARDVideoCallViewControllerDelegate>)delegate { delegate:(id<ARDVideoCallViewControllerDelegate>)delegate {
if (self = [super init]) { if (self = [super init]) {
_delegate = delegate; _delegate = delegate;
@ -47,7 +48,8 @@
[_client connectToRoomWithId:room [_client connectToRoomWithId:room
isLoopback:isLoopback isLoopback:isLoopback
isAudioOnly:isAudioOnly isAudioOnly:isAudioOnly
shouldMakeAecDump:shouldMakeAecDump]; shouldMakeAecDump:shouldMakeAecDump
shouldUseLevelControl:shouldUseLevelControl];
} }
return self; return self;
} }

View File

@ -284,7 +284,11 @@ static NSUInteger const kLogViewHeight = 280;
didEnterRoomId:(NSString*)roomId { didEnterRoomId:(NSString*)roomId {
[_client disconnect]; [_client disconnect];
ARDAppClient *client = [[ARDAppClient alloc] initWithDelegate:self]; ARDAppClient *client = [[ARDAppClient alloc] initWithDelegate:self];
[client connectToRoomWithId:roomId isLoopback:NO isAudioOnly:NO shouldMakeAecDump:NO]; [client connectToRoomWithId:roomId
isLoopback:NO
isAudioOnly:NO
shouldMakeAecDump:NO
shouldUseLevelControl:NO];
_client = client; _client = client;
} }

View File

@ -283,8 +283,16 @@
weakAnswerer = answerer; weakAnswerer = answerer;
// Kick off connection. // Kick off connection.
[caller connectToRoomWithId:roomId isLoopback:NO isAudioOnly:NO shouldMakeAecDump:NO]; [caller connectToRoomWithId:roomId
[answerer connectToRoomWithId:roomId isLoopback:NO isAudioOnly:NO shouldMakeAecDump:NO]; isLoopback:NO
isAudioOnly:NO
shouldMakeAecDump:NO
shouldUseLevelControl:NO];
[answerer connectToRoomWithId:roomId
isLoopback:NO
isAudioOnly:NO
shouldMakeAecDump:NO
shouldUseLevelControl:NO];
[self waitForExpectationsWithTimeout:20 handler:^(NSError *error) { [self waitForExpectationsWithTimeout:20 handler:^(NSError *error) {
if (error) { if (error) {
NSLog(@"Expectations error: %@", error); NSLog(@"Expectations error: %@", error);

View File

@ -30,6 +30,13 @@ NSString * const kRTCMediaConstraintsMinFrameRate =
@(webrtc::MediaConstraintsInterface::kMinFrameRate); @(webrtc::MediaConstraintsInterface::kMinFrameRate);
NSString * const kRTCMediaConstraintsMaxFrameRate = NSString * const kRTCMediaConstraintsMaxFrameRate =
@(webrtc::MediaConstraintsInterface::kMaxFrameRate); @(webrtc::MediaConstraintsInterface::kMaxFrameRate);
NSString * const kRTCMediaConstraintsLevelControl =
@(webrtc::MediaConstraintsInterface::kLevelControl);
NSString * const kRTCMediaConstraintsValueTrue =
@(webrtc::MediaConstraintsInterface::kValueTrue);
NSString * const kRTCMediaConstraintsValueFalse =
@(webrtc::MediaConstraintsInterface::kValueFalse);
namespace webrtc { namespace webrtc {

View File

@ -22,6 +22,10 @@ RTC_EXTERN NSString * const kRTCMediaConstraintsMaxHeight;
RTC_EXTERN NSString * const kRTCMediaConstraintsMinHeight; RTC_EXTERN NSString * const kRTCMediaConstraintsMinHeight;
RTC_EXTERN NSString * const kRTCMediaConstraintsMaxFrameRate; RTC_EXTERN NSString * const kRTCMediaConstraintsMaxFrameRate;
RTC_EXTERN NSString * const kRTCMediaConstraintsMinFrameRate; RTC_EXTERN NSString * const kRTCMediaConstraintsMinFrameRate;
RTC_EXTERN NSString * const kRTCMediaConstraintsLevelControl;
RTC_EXTERN NSString * const kRTCMediaConstraintsValueTrue;
RTC_EXTERN NSString * const kRTCMediaConstraintsValueFalse;
RTC_EXPORT RTC_EXPORT
@interface RTCMediaConstraints : NSObject @interface RTCMediaConstraints : NSObject