From f824ef8062933507e46730d8ee48c1c79b5f8557 Mon Sep 17 00:00:00 2001 From: dharmesh Date: Mon, 20 Jul 2020 14:40:28 +0530 Subject: [PATCH] Disable switch camera and route change buttons when processing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When user touches switch camera it takes a while for camera to switch. So disabled switch camera button on touch and enabled it back when switch camera is done. It also gives visual feedback to user. Did same change for route change button as well. Route change operation is relatively fast but making this change make it robust in case the operation takes time. Also changed image color and background color highlight color for touch highlight. Bug: webrtc:11778 Change-Id: I037b830f7a02b49bf292b8838bd245db585dbd22 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/179041 Commit-Queue: Kári Helgason Reviewed-by: Kári Helgason Cr-Commit-Position: refs/heads/master@{#31910} --- .../objc/AppRTCMobile/ARDCaptureController.h | 2 ++ .../objc/AppRTCMobile/ARDCaptureController.m | 13 ++++++-- .../objc/AppRTCMobile/ios/ARDVideoCallView.h | 6 ++-- .../objc/AppRTCMobile/ios/ARDVideoCallView.m | 33 ++++++++++++++----- .../ios/ARDVideoCallViewController.m | 12 ++++--- 5 files changed, 49 insertions(+), 17 deletions(-) diff --git a/examples/objc/AppRTCMobile/ARDCaptureController.h b/examples/objc/AppRTCMobile/ARDCaptureController.h index 66302b533d..5bc99af1bb 100644 --- a/examples/objc/AppRTCMobile/ARDCaptureController.h +++ b/examples/objc/AppRTCMobile/ARDCaptureController.h @@ -18,7 +18,9 @@ - (instancetype)initWithCapturer:(RTC_OBJC_TYPE(RTCCameraVideoCapturer) *)capturer settings:(ARDSettingsModel *)settings; - (void)startCapture; +- (void)startCapture:(void (^)(NSError *))completion; - (void)stopCapture; - (void)switchCamera; +- (void)switchCamera:(void (^)(NSError *))completion; @end diff --git a/examples/objc/AppRTCMobile/ARDCaptureController.m b/examples/objc/AppRTCMobile/ARDCaptureController.m index f1ce008b1d..222a5026f2 100644 --- a/examples/objc/AppRTCMobile/ARDCaptureController.m +++ b/examples/objc/AppRTCMobile/ARDCaptureController.m @@ -34,6 +34,10 @@ const Float64 kFramerateLimit = 30.0; } - (void)startCapture { + [self startCapture:nil]; +} + +- (void)startCapture:(void (^)(NSError *))completion { AVCaptureDevicePosition position = _usingFrontCamera ? AVCaptureDevicePositionFront : AVCaptureDevicePositionBack; AVCaptureDevice *device = [self findDeviceForPosition:position]; @@ -48,7 +52,7 @@ const Float64 kFramerateLimit = 30.0; NSInteger fps = [self selectFpsForFormat:format]; - [_capturer startCaptureWithDevice:device format:format fps:fps]; + [_capturer startCaptureWithDevice:device format:format fps:fps completionHandler:completion]; } - (void)stopCapture { @@ -57,7 +61,12 @@ const Float64 kFramerateLimit = 30.0; - (void)switchCamera { _usingFrontCamera = !_usingFrontCamera; - [self startCapture]; + [self startCapture:nil]; +} + +- (void)switchCamera:(void (^)(NSError *))completion { + _usingFrontCamera = !_usingFrontCamera; + [self startCapture:completion]; } #pragma mark - Private diff --git a/examples/objc/AppRTCMobile/ios/ARDVideoCallView.h b/examples/objc/AppRTCMobile/ios/ARDVideoCallView.h index 43f432df59..a5943cce4c 100644 --- a/examples/objc/AppRTCMobile/ios/ARDVideoCallView.h +++ b/examples/objc/AppRTCMobile/ios/ARDVideoCallView.h @@ -19,10 +19,12 @@ @protocol ARDVideoCallViewDelegate // Called when the camera switch button is pressed. -- (void)videoCallViewDidSwitchCamera:(ARDVideoCallView *)view; +- (void)videoCallView:(ARDVideoCallView *)view + shouldSwitchCameraWithCompletion:(void (^)(NSError *))completion; // Called when the route change button is pressed. -- (void)videoCallViewDidChangeRoute:(ARDVideoCallView *)view; +- (void)videoCallView:(ARDVideoCallView *)view + shouldChangeRouteWithCompletion:(void (^)(void))completion; // Called when the hangup button is pressed. - (void)videoCallViewDidHangup:(ARDVideoCallView *)view; diff --git a/examples/objc/AppRTCMobile/ios/ARDVideoCallView.m b/examples/objc/AppRTCMobile/ios/ARDVideoCallView.m index 45cfa9cb61..2ae18a616a 100644 --- a/examples/objc/AppRTCMobile/ios/ARDVideoCallView.m +++ b/examples/objc/AppRTCMobile/ios/ARDVideoCallView.m @@ -63,10 +63,11 @@ static CGFloat const kStatusBarHeight = 20; [self addSubview:_statsView]; _routeChangeButton = [UIButton buttonWithType:UIButtonTypeCustom]; - _routeChangeButton.backgroundColor = [UIColor whiteColor]; + _routeChangeButton.backgroundColor = [UIColor grayColor]; _routeChangeButton.layer.cornerRadius = kButtonSize / 2; _routeChangeButton.layer.masksToBounds = YES; - UIImage *image = [UIImage imageNamed:@"ic_surround_sound_black_24dp.png"]; + UIImage *image = [UIImage imageForName:@"ic_surround_sound_black_24dp.png" + color:[UIColor whiteColor]]; [_routeChangeButton setImage:image forState:UIControlStateNormal]; [_routeChangeButton addTarget:self action:@selector(onRouteChange:) @@ -75,10 +76,10 @@ static CGFloat const kStatusBarHeight = 20; // TODO(tkchin): don't display this if we can't actually do camera switch. _cameraSwitchButton = [UIButton buttonWithType:UIButtonTypeCustom]; - _cameraSwitchButton.backgroundColor = [UIColor whiteColor]; + _cameraSwitchButton.backgroundColor = [UIColor grayColor]; _cameraSwitchButton.layer.cornerRadius = kButtonSize / 2; _cameraSwitchButton.layer.masksToBounds = YES; - image = [UIImage imageNamed:@"ic_switch_video_black_24dp.png"]; + image = [UIImage imageForName:@"ic_switch_video_black_24dp.png" color:[UIColor whiteColor]]; [_cameraSwitchButton setImage:image forState:UIControlStateNormal]; [_cameraSwitchButton addTarget:self action:@selector(onCameraSwitch:) @@ -187,12 +188,28 @@ static CGFloat const kStatusBarHeight = 20; #pragma mark - Private -- (void)onCameraSwitch:(id)sender { - [_delegate videoCallViewDidSwitchCamera:self]; +- (void)onCameraSwitch:(UIButton *)sender { + sender.enabled = false; + [_delegate videoCallView:self + shouldSwitchCameraWithCompletion:^(NSError *error) { + dispatch_async(dispatch_get_main_queue(), ^(void) { + sender.enabled = true; + }); + }]; } -- (void)onRouteChange:(id)sender { - [_delegate videoCallViewDidChangeRoute:self]; +- (void)onRouteChange:(UIButton *)sender { + sender.enabled = false; + __weak ARDVideoCallView *weakSelf = self; + [_delegate videoCallView:self + shouldChangeRouteWithCompletion:^(void) { + ARDVideoCallView *strongSelf = weakSelf; + if (strongSelf) { + dispatch_async(dispatch_get_main_queue(), ^(void) { + sender.enabled = true; + }); + } + }]; } - (void)onHangup:(id)sender { diff --git a/examples/objc/AppRTCMobile/ios/ARDVideoCallViewController.m b/examples/objc/AppRTCMobile/ios/ARDVideoCallViewController.m index 4eb38878e0..bb3bc096c7 100644 --- a/examples/objc/AppRTCMobile/ios/ARDVideoCallViewController.m +++ b/examples/objc/AppRTCMobile/ios/ARDVideoCallViewController.m @@ -152,13 +152,14 @@ [self hangup]; } -- (void)videoCallViewDidSwitchCamera:(ARDVideoCallView *)view { - // TODO(tkchin): Rate limit this so you can't tap continously on it. - // Probably through an animation. - [_captureController switchCamera]; +- (void)videoCallView:(ARDVideoCallView *)view + shouldSwitchCameraWithCompletion:(void (^)(NSError *))completion { + [_captureController switchCamera:completion]; } -- (void)videoCallViewDidChangeRoute:(ARDVideoCallView *)view { +- (void)videoCallView:(ARDVideoCallView *)view + shouldChangeRouteWithCompletion:(void (^)(void))completion { + NSParameterAssert(completion); AVAudioSessionPortOverride override = AVAudioSessionPortOverrideNone; if (_portOverride == AVAudioSessionPortOverrideNone) { override = AVAudioSessionPortOverrideSpeaker; @@ -177,6 +178,7 @@ error.localizedDescription); } [session unlockForConfiguration]; + completion(); }]; }