Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(519)

Unified Diff: talk/app/webrtc/objc/avfoundationvideocapturer.mm

Issue 1416303003: Handle iOS devices with no rear-facing camera (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Check back camera in new Objective-C API Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: talk/app/webrtc/objc/avfoundationvideocapturer.mm
diff --git a/talk/app/webrtc/objc/avfoundationvideocapturer.mm b/talk/app/webrtc/objc/avfoundationvideocapturer.mm
index 0f9dc6825e9135461a6d8d8c5ad713c00c2c01b3..ed9f662910509d05c0b214780338b4ed9632b1ab 100644
--- a/talk/app/webrtc/objc/avfoundationvideocapturer.mm
+++ b/talk/app/webrtc/objc/avfoundationvideocapturer.mm
@@ -53,6 +53,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;
tkchin_webrtc 2016/03/14 18:16:59 nit: move above useBackCamera
hjon 2016/03/14 18:31:44 Done.
// 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
@@ -105,10 +106,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.");
tkchin_webrtc 2016/03/14 18:16:59 import webrtc/base/RTCLogging and use RTCLog here
hjon 2016/03/14 18:31:44 Done.
+ return;
+ }
_useBackCamera = useBackCamera;
[self updateSessionInput];
}
@@ -203,10 +212,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;
@@ -218,18 +232,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;
tkchin_webrtc 2016/03/14 18:16:59 nil out error before _backDeviceInput = [AVCap.. i
hjon 2016/03/14 18:31:44 Done.
+ }
}
// Add the inputs.
if (![_captureSession canAddInput:_frontDeviceInput] ||
- ![_captureSession canAddInput:_backDeviceInput]) {
+ (_backDeviceInput && ![_captureSession canAddInput:_backDeviceInput])) {
NSLog(@"Session does not support capture inputs.");
return NO;
}
@@ -353,6 +370,10 @@ AVCaptureSession* AVFoundationVideoCapturer::GetCaptureSession() {
return _capturer.captureSession;
}
+bool AVFoundationVideoCapturer::CanUseBackCamera() const {
+ return _capturer.canUseBackCamera;
+}
+
void AVFoundationVideoCapturer::SetUseBackCamera(bool useBackCamera) {
_capturer.useBackCamera = useBackCamera;
}

Powered by Google App Engine
This is Rietveld 408576698