| Index: webrtc/api/objc/avfoundationvideocapturer.mm
|
| diff --git a/webrtc/api/objc/avfoundationvideocapturer.mm b/webrtc/api/objc/avfoundationvideocapturer.mm
|
| index a3f0f44160b2e5c885da1bf6d66a2b9eb142b3d5..fc89fdfc8c638b35729d550790d010b88b1d8220 100644
|
| --- a/webrtc/api/objc/avfoundationvideocapturer.mm
|
| +++ b/webrtc/api/objc/avfoundationvideocapturer.mm
|
| @@ -36,6 +36,7 @@ static cricket::VideoFormat const kDefaultFormat =
|
| @property(nonatomic, readonly) AVCaptureSession *captureSession;
|
| @property(nonatomic, readonly) BOOL isRunning;
|
| @property(nonatomic, assign) BOOL useBackCamera; // Defaults to NO.
|
| +@property(nonatomic, readonly) BOOL canUseBackCamera;
|
|
|
| // We keep a pointer back to AVFoundationVideoCapturer to make callbacks on it
|
| // when we receive frames. This is safe because this object should be owned by
|
| @@ -88,10 +89,18 @@ static cricket::VideoFormat const kDefaultFormat =
|
| _capturer = nullptr;
|
| }
|
|
|
| +- (BOOL)canUseBackCamera {
|
| + return _backDeviceInput != nil;
|
| +}
|
| +
|
| - (void)setUseBackCamera:(BOOL)useBackCamera {
|
| if (_useBackCamera == useBackCamera) {
|
| return;
|
| }
|
| + if (!self.canUseBackCamera) {
|
| + NSLog(@"No rear-facing camera exists or it cannot be used; not switching.");
|
| + return;
|
| + }
|
| _useBackCamera = useBackCamera;
|
| [self updateSessionInput];
|
| }
|
| @@ -186,10 +195,15 @@ static cricket::VideoFormat const kDefaultFormat =
|
| frontCaptureDevice = captureDevice;
|
| }
|
| }
|
| - if (!frontCaptureDevice || !backCaptureDevice) {
|
| - NSLog(@"Failed to get capture devices.");
|
| + if (!frontCaptureDevice) {
|
| + NSLog(@"Failed to get front capture device.");
|
| return NO;
|
| }
|
| + if (!backCaptureDevice) {
|
| + NSLog(@"Failed to get back capture device");
|
| + // Don't return NO here because devices exist (16GB 5th generation iPod
|
| + // Touch) that don't have a rear-facing camera.
|
| + }
|
|
|
| // Set up the session inputs.
|
| NSError *error = nil;
|
| @@ -201,18 +215,21 @@ static cricket::VideoFormat const kDefaultFormat =
|
| error.localizedDescription);
|
| return NO;
|
| }
|
| - _backDeviceInput =
|
| - [AVCaptureDeviceInput deviceInputWithDevice:backCaptureDevice
|
| - error:&error];
|
| - if (!_backDeviceInput) {
|
| - NSLog(@"Failed to get capture device input: %@",
|
| - error.localizedDescription);
|
| - return NO;
|
| + if (backCaptureDevice) {
|
| + _backDeviceInput =
|
| + [AVCaptureDeviceInput deviceInputWithDevice:backCaptureDevice
|
| + error:&error];
|
| + if (error) {
|
| + NSLog(@"Failed to get capture device input: %@",
|
| + error.localizedDescription);
|
| + _backDeviceInput = nil;
|
| + error = nil;
|
| + }
|
| }
|
|
|
| // Add the inputs.
|
| if (![_captureSession canAddInput:_frontDeviceInput] ||
|
| - ![_captureSession canAddInput:_backDeviceInput]) {
|
| + (_backDeviceInput && ![_captureSession canAddInput:_backDeviceInput])) {
|
| NSLog(@"Session does not support capture inputs.");
|
| return NO;
|
| }
|
| @@ -336,6 +353,10 @@ AVCaptureSession* AVFoundationVideoCapturer::GetCaptureSession() {
|
| return _capturer.captureSession;
|
| }
|
|
|
| +bool AVFoundationVideoCapturer::CanUseBackCamera() const {
|
| + return _capturer.canUseBackCamera;
|
| +}
|
| +
|
| void AVFoundationVideoCapturer::SetUseBackCamera(bool useBackCamera) {
|
| _capturer.useBackCamera = useBackCamera;
|
| }
|
|
|