| Index: webrtc/api/objc/avfoundationvideocapturer.mm
|
| diff --git a/webrtc/api/objc/avfoundationvideocapturer.mm b/webrtc/api/objc/avfoundationvideocapturer.mm
|
| index a3f0f44160b2e5c885da1bf6d66a2b9eb142b3d5..c466512bd0ed4976e9927a8eb1d6b54990607624 100644
|
| --- a/webrtc/api/objc/avfoundationvideocapturer.mm
|
| +++ b/webrtc/api/objc/avfoundationvideocapturer.mm
|
| @@ -17,6 +17,7 @@
|
| #import <UIKit/UIKit.h>
|
|
|
| #import "webrtc/base/objc/RTCDispatcher.h"
|
| +#import "webrtc/base/objc/RTCLogging.h"
|
|
|
| // TODO(tkchin): support other formats.
|
| static NSString* const kDefaultPreset = AVCaptureSessionPreset640x480;
|
| @@ -35,6 +36,7 @@ static cricket::VideoFormat const kDefaultFormat =
|
|
|
| @property(nonatomic, readonly) AVCaptureSession *captureSession;
|
| @property(nonatomic, readonly) BOOL isRunning;
|
| +@property(nonatomic, readonly) BOOL canUseBackCamera;
|
| @property(nonatomic, assign) BOOL useBackCamera; // Defaults to NO.
|
|
|
| // We keep a pointer back to AVFoundationVideoCapturer to make callbacks on it
|
| @@ -88,10 +90,19 @@ static cricket::VideoFormat const kDefaultFormat =
|
| _capturer = nullptr;
|
| }
|
|
|
| +- (BOOL)canUseBackCamera {
|
| + return _backDeviceInput != nil;
|
| +}
|
| +
|
| - (void)setUseBackCamera:(BOOL)useBackCamera {
|
| if (_useBackCamera == useBackCamera) {
|
| return;
|
| }
|
| + if (!self.canUseBackCamera) {
|
| + RTCLog(@"No rear-facing camera exists or it cannot be used;"
|
| + "not switching.");
|
| + return;
|
| + }
|
| _useBackCamera = useBackCamera;
|
| [self updateSessionInput];
|
| }
|
| @@ -186,10 +197,15 @@ static cricket::VideoFormat const kDefaultFormat =
|
| frontCaptureDevice = captureDevice;
|
| }
|
| }
|
| - if (!frontCaptureDevice || !backCaptureDevice) {
|
| - NSLog(@"Failed to get capture devices.");
|
| + if (!frontCaptureDevice) {
|
| + RTCLog(@"Failed to get front capture device.");
|
| return NO;
|
| }
|
| + if (!backCaptureDevice) {
|
| + RTCLog(@"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 +217,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) {
|
| + error = nil;
|
| + _backDeviceInput =
|
| + [AVCaptureDeviceInput deviceInputWithDevice:backCaptureDevice
|
| + error:&error];
|
| + if (error) {
|
| + RTCLog(@"Failed to get capture device input: %@",
|
| + error.localizedDescription);
|
| + _backDeviceInput = 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 +355,10 @@ AVCaptureSession* AVFoundationVideoCapturer::GetCaptureSession() {
|
| return _capturer.captureSession;
|
| }
|
|
|
| +bool AVFoundationVideoCapturer::CanUseBackCamera() const {
|
| + return _capturer.canUseBackCamera;
|
| +}
|
| +
|
| void AVFoundationVideoCapturer::SetUseBackCamera(bool useBackCamera) {
|
| _capturer.useBackCamera = useBackCamera;
|
| }
|
|
|