Fixing crash in Mac client when no cameras are available.

Bug: webrtc:8348
Change-Id: Ibf84ca76812d8c002fae9bd7bcf616abc53c78b1
Reviewed-on: https://webrtc-review.googlesource.com/7340
Reviewed-by: Kári Helgason <kthelgason@webrtc.org>
Reviewed-by: Daniela Jovanoska Petrenko <denicija@webrtc.org>
Commit-Queue: Peter Hanspers <peterhanspers@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20392}
This commit is contained in:
Peter Hanspers
2017-10-23 14:30:25 +02:00
committed by Commit Bot
parent 93bc308f31
commit d92e0b5923
3 changed files with 30 additions and 7 deletions

View File

@ -11,6 +11,7 @@
#import "ARDCaptureController.h" #import "ARDCaptureController.h"
#import "ARDSettingsModel.h" #import "ARDSettingsModel.h"
#import "WebRTC/RTCLogging.h"
@implementation ARDCaptureController { @implementation ARDCaptureController {
RTCCameraVideoCapturer *_capturer; RTCCameraVideoCapturer *_capturer;
@ -34,6 +35,14 @@
_usingFrontCamera ? AVCaptureDevicePositionFront : AVCaptureDevicePositionBack; _usingFrontCamera ? AVCaptureDevicePositionFront : AVCaptureDevicePositionBack;
AVCaptureDevice *device = [self findDeviceForPosition:position]; AVCaptureDevice *device = [self findDeviceForPosition:position];
AVCaptureDeviceFormat *format = [self selectFormatForDevice:device]; AVCaptureDeviceFormat *format = [self selectFormatForDevice:device];
if (format == nil) {
RTCLogError(@"No valid formats for device %@", device);
NSAssert(NO, @"");
return;
}
NSInteger fps = [self selectFpsForFormat:format]; NSInteger fps = [self selectFpsForFormat:format];
[_capturer startCaptureWithDevice:device format:format fps:fps]; [_capturer startCaptureWithDevice:device format:format fps:fps];
@ -77,7 +86,6 @@
} }
} }
NSAssert(selectedFormat != nil, @"No suitable capture format found.");
return selectedFormat; return selectedFormat;
} }

View File

@ -151,11 +151,11 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - #pragma mark -
- (NSString *)defaultVideoResolutionSetting { - (NSString *)defaultVideoResolutionSetting {
return [self availableVideoResolutions][0]; return [self availableVideoResolutions].firstObject;
} }
- (RTCVideoCodecInfo *)defaultVideoCodecSetting { - (RTCVideoCodecInfo *)defaultVideoCodecSetting {
return [self availableVideoCodecs][0]; return [self availableVideoCodecs].firstObject;
} }
- (int)videoResolutionComponentAtIndex:(int)index inString:(NSString *)resolution { - (int)videoResolutionComponentAtIndex:(int)index inString:(NSString *)resolution {
@ -170,11 +170,21 @@ NS_ASSUME_NONNULL_BEGIN
} }
- (void)registerStoreDefaults { - (void)registerStoreDefaults {
NSString *defaultVideoResolutionSetting = [self defaultVideoResolutionSetting];
BOOL audioOnly = (defaultVideoResolutionSetting.length == 0);
// The iOS simulator doesn't provide any sort of camera capture
// support or emulation (http://goo.gl/rHAnC1) so don't bother
// trying to open a local stream.
#if TARGET_IPHONE_SIMULATOR
audioOnly = YES;
#endif
NSData *codecData = [NSKeyedArchiver archivedDataWithRootObject:[self defaultVideoCodecSetting]]; NSData *codecData = [NSKeyedArchiver archivedDataWithRootObject:[self defaultVideoCodecSetting]];
[ARDSettingsStore setDefaultsForVideoResolution:[self defaultVideoResolutionSetting] [ARDSettingsStore setDefaultsForVideoResolution:[self defaultVideoResolutionSetting]
videoCodec:codecData videoCodec:codecData
bitrate:nil bitrate:nil
audioOnly:NO audioOnly:audioOnly
createAecDump:NO createAecDump:NO
useLevelController:NO useLevelController:NO
useManualAudioConfig:YES]; useManualAudioConfig:YES];

View File

@ -35,15 +35,20 @@ NS_ASSUME_NONNULL_BEGIN
useLevelController:(BOOL)useLevelController useLevelController:(BOOL)useLevelController
useManualAudioConfig:(BOOL)useManualAudioConfig { useManualAudioConfig:(BOOL)useManualAudioConfig {
NSMutableDictionary<NSString *, id> *defaultsDictionary = [@{ NSMutableDictionary<NSString *, id> *defaultsDictionary = [@{
kVideoResolutionKey : videoResolution,
kVideoCodecKey : videoCodec,
kAudioOnlyKey : @(audioOnly), kAudioOnlyKey : @(audioOnly),
kCreateAecDumpKey : @(createAecDump), kCreateAecDumpKey : @(createAecDump),
kUseLevelControllerKey : @(useLevelController), kUseLevelControllerKey : @(useLevelController),
kUseManualAudioConfigKey : @(useManualAudioConfig) kUseManualAudioConfigKey : @(useManualAudioConfig)
} mutableCopy]; } mutableCopy];
if (videoResolution) {
defaultsDictionary[kVideoResolutionKey] = videoResolution;
}
if (videoCodec) {
defaultsDictionary[kVideoCodecKey] = videoCodec;
}
if (bitrate) { if (bitrate) {
[defaultsDictionary setObject:bitrate forKey:kBitrateKey]; defaultsDictionary[kBitrateKey] = bitrate;
} }
[[NSUserDefaults standardUserDefaults] registerDefaults:defaultsDictionary]; [[NSUserDefaults standardUserDefaults] registerDefaults:defaultsDictionary];
} }