Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(747)

Side by Side Diff: webrtc/examples/objc/AppRTCDemo/ios/ARDMainView.m

Issue 1822543002: Support delayed AudioUnit initialization. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebase Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2015 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #import "ARDMainView.h" 11 #import "ARDMainView.h"
12 12
13 #import <AVFoundation/AVFoundation.h>
14
15 #import "UIImage+ARDUtilities.h" 13 #import "UIImage+ARDUtilities.h"
16 14
17 // TODO(tkchin): retrieve status bar height dynamically. 15 // TODO(tkchin): retrieve status bar height dynamically.
18 static CGFloat const kStatusBarHeight = 20; 16 static CGFloat const kStatusBarHeight = 20;
19 17
20 static CGFloat const kRoomTextButtonSize = 40; 18 static CGFloat const kRoomTextButtonSize = 40;
21 static CGFloat const kRoomTextFieldHeight = 40; 19 static CGFloat const kRoomTextFieldHeight = 40;
22 static CGFloat const kRoomTextFieldMargin = 8; 20 static CGFloat const kRoomTextFieldMargin = 8;
23 static CGFloat const kCallControlMargin = 8; 21 static CGFloat const kCallControlMargin = 8;
24 static CGFloat const kAppLabelHeight = 20; 22 static CGFloat const kAppLabelHeight = 20;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 @end 115 @end
118 116
119 @implementation ARDMainView { 117 @implementation ARDMainView {
120 UILabel *_appLabel; 118 UILabel *_appLabel;
121 ARDRoomTextField *_roomText; 119 ARDRoomTextField *_roomText;
122 UILabel *_callOptionsLabel; 120 UILabel *_callOptionsLabel;
123 UISwitch *_audioOnlySwitch; 121 UISwitch *_audioOnlySwitch;
124 UILabel *_audioOnlyLabel; 122 UILabel *_audioOnlyLabel;
125 UISwitch *_loopbackSwitch; 123 UISwitch *_loopbackSwitch;
126 UILabel *_loopbackLabel; 124 UILabel *_loopbackLabel;
125 UISwitch *_audioConfigDelaySwitch;
126 UILabel *_audioConfigDelayLabel;
127 UIButton *_startCallButton; 127 UIButton *_startCallButton;
128 UIButton *_audioLoopButton; 128 UIButton *_audioLoopButton;
129 AVAudioPlayer *_audioPlayer;
130 } 129 }
131 130
132 @synthesize delegate = _delegate; 131 @synthesize delegate = _delegate;
132 @synthesize isAudioLoopPlaying = _isAudioLoopPlaying;
133 133
134 - (instancetype)initWithFrame:(CGRect)frame { 134 - (instancetype)initWithFrame:(CGRect)frame {
135 if (self = [super initWithFrame:frame]) { 135 if (self = [super initWithFrame:frame]) {
136 NSString *audioFilePath =
137 [[NSBundle mainBundle] pathForResource:@"mozart" ofType:@"mp3"];
138 NSURL *audioFileURL = [NSURL URLWithString:audioFilePath];
139 _audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:audioFileURL
140 error:nil];
141 _audioPlayer.numberOfLoops = -1;
142 _audioPlayer.volume = 1.0;
143 [_audioPlayer prepareToPlay];
144
145 _appLabel = [[UILabel alloc] initWithFrame:CGRectZero]; 136 _appLabel = [[UILabel alloc] initWithFrame:CGRectZero];
146 _appLabel.text = @"AppRTCDemo"; 137 _appLabel.text = @"AppRTCDemo";
147 _appLabel.font = [UIFont fontWithName:@"Roboto" size:34]; 138 _appLabel.font = [UIFont fontWithName:@"Roboto" size:34];
148 _appLabel.textColor = [UIColor colorWithWhite:0 alpha:.2]; 139 _appLabel.textColor = [UIColor colorWithWhite:0 alpha:.2];
149 [_appLabel sizeToFit]; 140 [_appLabel sizeToFit];
150 [self addSubview:_appLabel]; 141 [self addSubview:_appLabel];
151 142
152 _roomText = [[ARDRoomTextField alloc] initWithFrame:CGRectZero]; 143 _roomText = [[ARDRoomTextField alloc] initWithFrame:CGRectZero];
153 [self addSubview:_roomText]; 144 [self addSubview:_roomText];
154 145
(...skipping 22 matching lines...) Expand all
177 [_loopbackSwitch sizeToFit]; 168 [_loopbackSwitch sizeToFit];
178 [self addSubview:_loopbackSwitch]; 169 [self addSubview:_loopbackSwitch];
179 170
180 _loopbackLabel = [[UILabel alloc] initWithFrame:CGRectZero]; 171 _loopbackLabel = [[UILabel alloc] initWithFrame:CGRectZero];
181 _loopbackLabel.text = @"Loopback mode"; 172 _loopbackLabel.text = @"Loopback mode";
182 _loopbackLabel.font = controlFont; 173 _loopbackLabel.font = controlFont;
183 _loopbackLabel.textColor = controlFontColor; 174 _loopbackLabel.textColor = controlFontColor;
184 [_loopbackLabel sizeToFit]; 175 [_loopbackLabel sizeToFit];
185 [self addSubview:_loopbackLabel]; 176 [self addSubview:_loopbackLabel];
186 177
178 _audioConfigDelaySwitch = [[UISwitch alloc] initWithFrame:CGRectZero];
179 [_audioConfigDelaySwitch sizeToFit];
180 _audioConfigDelaySwitch.on = YES;
181 [self addSubview:_audioConfigDelaySwitch];
182
183 _audioConfigDelayLabel = [[UILabel alloc] initWithFrame:CGRectZero];
184 _audioConfigDelayLabel.text = @"Delay audio config";
185 _audioConfigDelayLabel.font = controlFont;
186 _audioConfigDelayLabel.textColor = controlFontColor;
187 [_audioConfigDelayLabel sizeToFit];
188 [self addSubview:_audioConfigDelayLabel];
189
187 _startCallButton = [UIButton buttonWithType:UIButtonTypeSystem]; 190 _startCallButton = [UIButton buttonWithType:UIButtonTypeSystem];
188 _startCallButton.backgroundColor = [UIColor blueColor]; 191 _startCallButton.backgroundColor = [UIColor blueColor];
189 _startCallButton.layer.cornerRadius = 10; 192 _startCallButton.layer.cornerRadius = 10;
190 _startCallButton.clipsToBounds = YES; 193 _startCallButton.clipsToBounds = YES;
191 _startCallButton.contentEdgeInsets = UIEdgeInsetsMake(5, 10, 5, 10); 194 _startCallButton.contentEdgeInsets = UIEdgeInsetsMake(5, 10, 5, 10);
192 [_startCallButton setTitle:@"Start call" 195 [_startCallButton setTitle:@"Start call"
193 forState:UIControlStateNormal]; 196 forState:UIControlStateNormal];
194 _startCallButton.titleLabel.font = controlFont; 197 _startCallButton.titleLabel.font = controlFont;
195 [_startCallButton setTitleColor:[UIColor whiteColor] 198 [_startCallButton setTitleColor:[UIColor whiteColor]
196 forState:UIControlStateNormal]; 199 forState:UIControlStateNormal];
(...skipping 19 matching lines...) Expand all
216 [_audioLoopButton addTarget:self 219 [_audioLoopButton addTarget:self
217 action:@selector(onToggleAudioLoop:) 220 action:@selector(onToggleAudioLoop:)
218 forControlEvents:UIControlEventTouchUpInside]; 221 forControlEvents:UIControlEventTouchUpInside];
219 [self addSubview:_audioLoopButton]; 222 [self addSubview:_audioLoopButton];
220 223
221 self.backgroundColor = [UIColor whiteColor]; 224 self.backgroundColor = [UIColor whiteColor];
222 } 225 }
223 return self; 226 return self;
224 } 227 }
225 228
229 - (void)setIsAudioLoopPlaying:(BOOL)isAudioLoopPlaying {
230 if (_isAudioLoopPlaying == isAudioLoopPlaying) {
231 return;
232 }
233 _isAudioLoopPlaying = isAudioLoopPlaying;
234 [self updateAudioLoopButton];
235 }
236
226 - (void)layoutSubviews { 237 - (void)layoutSubviews {
227 CGRect bounds = self.bounds; 238 CGRect bounds = self.bounds;
228 CGFloat roomTextWidth = bounds.size.width - 2 * kRoomTextFieldMargin; 239 CGFloat roomTextWidth = bounds.size.width - 2 * kRoomTextFieldMargin;
229 CGFloat roomTextHeight = [_roomText sizeThatFits:bounds.size].height; 240 CGFloat roomTextHeight = [_roomText sizeThatFits:bounds.size].height;
230 _roomText.frame = CGRectMake(kRoomTextFieldMargin, 241 _roomText.frame = CGRectMake(kRoomTextFieldMargin,
231 kStatusBarHeight + kRoomTextFieldMargin, 242 kStatusBarHeight + kRoomTextFieldMargin,
232 roomTextWidth, 243 roomTextWidth,
233 roomTextHeight); 244 roomTextHeight);
234 _appLabel.center = CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds)); 245 _appLabel.center = CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds));
235 246
(...skipping 21 matching lines...) Expand all
257 CGRect loopbackModeRect = CGRectMake(kCallControlMargin * 3, 268 CGRect loopbackModeRect = CGRectMake(kCallControlMargin * 3,
258 loopbackModeTop, 269 loopbackModeTop,
259 _loopbackSwitch.frame.size.width, 270 _loopbackSwitch.frame.size.width,
260 _loopbackSwitch.frame.size.height); 271 _loopbackSwitch.frame.size.height);
261 _loopbackSwitch.frame = loopbackModeRect; 272 _loopbackSwitch.frame = loopbackModeRect;
262 CGFloat loopbackModeLabelCenterX = CGRectGetMaxX(loopbackModeRect) + 273 CGFloat loopbackModeLabelCenterX = CGRectGetMaxX(loopbackModeRect) +
263 kCallControlMargin + _loopbackLabel.frame.size.width / 2; 274 kCallControlMargin + _loopbackLabel.frame.size.width / 2;
264 _loopbackLabel.center = CGPointMake(loopbackModeLabelCenterX, 275 _loopbackLabel.center = CGPointMake(loopbackModeLabelCenterX,
265 CGRectGetMidY(loopbackModeRect)); 276 CGRectGetMidY(loopbackModeRect));
266 277
278 CGFloat audioConfigDelayTop =
279 CGRectGetMaxY(_loopbackSwitch.frame) + kCallControlMargin;
280 CGRect audioConfigDelayRect =
281 CGRectMake(kCallControlMargin * 3,
282 audioConfigDelayTop,
283 _audioConfigDelaySwitch.frame.size.width,
284 _audioConfigDelaySwitch.frame.size.height);
285 _audioConfigDelaySwitch.frame = audioConfigDelayRect;
286 CGFloat audioConfigDelayLabelCenterX = CGRectGetMaxX(audioConfigDelayRect) +
287 kCallControlMargin + _audioConfigDelayLabel.frame.size.width / 2;
288 _audioConfigDelayLabel.center =
289 CGPointMake(audioConfigDelayLabelCenterX,
290 CGRectGetMidY(audioConfigDelayRect));
291
267 CGFloat audioLoopTop = 292 CGFloat audioLoopTop =
268 CGRectGetMaxY(loopbackModeRect) + kCallControlMargin * 3; 293 CGRectGetMaxY(audioConfigDelayRect) + kCallControlMargin * 3;
269 _audioLoopButton.frame = CGRectMake(kCallControlMargin, 294 _audioLoopButton.frame = CGRectMake(kCallControlMargin,
270 audioLoopTop, 295 audioLoopTop,
271 _audioLoopButton.frame.size.width, 296 _audioLoopButton.frame.size.width,
272 _audioLoopButton.frame.size.height); 297 _audioLoopButton.frame.size.height);
273 298
274 CGFloat startCallTop = 299 CGFloat startCallTop =
275 CGRectGetMaxY(_audioLoopButton.frame) + kCallControlMargin * 3; 300 CGRectGetMaxY(_audioLoopButton.frame) + kCallControlMargin * 3;
276 _startCallButton.frame = CGRectMake(kCallControlMargin, 301 _startCallButton.frame = CGRectMake(kCallControlMargin,
277 startCallTop, 302 startCallTop,
278 _startCallButton.frame.size.width, 303 _startCallButton.frame.size.width,
279 _startCallButton.frame.size.height); 304 _startCallButton.frame.size.height);
280 } 305 }
281 306
282 #pragma mark - Private 307 #pragma mark - Private
283 308
284 - (void)updateAudioLoopButton { 309 - (void)updateAudioLoopButton {
285 if (_audioPlayer.playing) { 310 if (_isAudioLoopPlaying) {
286 _audioLoopButton.backgroundColor = [UIColor redColor]; 311 _audioLoopButton.backgroundColor = [UIColor redColor];
287 [_audioLoopButton setTitle:@"Stop sound" 312 [_audioLoopButton setTitle:@"Stop sound"
288 forState:UIControlStateNormal]; 313 forState:UIControlStateNormal];
289 [_audioLoopButton sizeToFit]; 314 [_audioLoopButton sizeToFit];
290 } else { 315 } else {
291 _audioLoopButton.backgroundColor = [UIColor greenColor]; 316 _audioLoopButton.backgroundColor = [UIColor greenColor];
292 [_audioLoopButton setTitle:@"Play sound" 317 [_audioLoopButton setTitle:@"Play sound"
293 forState:UIControlStateNormal]; 318 forState:UIControlStateNormal];
294 [_audioLoopButton sizeToFit]; 319 [_audioLoopButton sizeToFit];
295 } 320 }
296 } 321 }
297 322
298 - (void)onToggleAudioLoop:(id)sender { 323 - (void)onToggleAudioLoop:(id)sender {
299 if (_audioPlayer.playing) { 324 [_delegate mainViewDidToggleAudioLoop:self];
300 [_audioPlayer stop];
301 } else {
302 [_audioPlayer play];
303 }
304 [self updateAudioLoopButton];
305 } 325 }
306 326
307 - (void)onStartCall:(id)sender { 327 - (void)onStartCall:(id)sender {
308 NSString *room = _roomText.roomText; 328 NSString *room = _roomText.roomText;
309 // If this is a loopback call, allow a generated room name. 329 // If this is a loopback call, allow a generated room name.
310 if (!room.length && _loopbackSwitch.isOn) { 330 if (!room.length && _loopbackSwitch.isOn) {
311 room = [[NSUUID UUID] UUIDString]; 331 room = [[NSUUID UUID] UUIDString];
312 } 332 }
313 room = [room stringByReplacingOccurrencesOfString:@"-" withString:@""]; 333 room = [room stringByReplacingOccurrencesOfString:@"-" withString:@""];
314 [_delegate mainView:self 334 [_delegate mainView:self
315 didInputRoom:room 335 didInputRoom:room
316 isLoopback:_loopbackSwitch.isOn 336 isLoopback:_loopbackSwitch.isOn
317 isAudioOnly:_audioOnlySwitch.isOn]; 337 isAudioOnly:_audioOnlySwitch.isOn
338 shouldDelayAudioConfig:_audioConfigDelaySwitch.isOn];
318 } 339 }
319 340
320 @end 341 @end
OLDNEW
« no previous file with comments | « webrtc/examples/objc/AppRTCDemo/ios/ARDMainView.h ('k') | webrtc/examples/objc/AppRTCDemo/ios/ARDMainViewController.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698