Disable switch camera and route change buttons when processing

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 <kthelgason@webrtc.org>
Reviewed-by: Kári Helgason <kthelgason@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31910}
This commit is contained in:
dharmesh
2020-07-20 14:40:28 +05:30
committed by Commit Bot
parent bcb42f1e4b
commit f824ef8062
5 changed files with 49 additions and 17 deletions

View File

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

View File

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

View File

@ -19,10 +19,12 @@
@protocol ARDVideoCallViewDelegate <NSObject>
// 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;

View File

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

View File

@ -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();
}];
}