Updated iOS video capturer to take device orientation into consideration.
BUG=4122 R=tkchin@webrtc.org Review URL: https://webrtc-codereview.appspot.com/48769004 Patch from Jonas Martinsson <jonas.d.martinsson@gmail.com>. Cr-Commit-Position: refs/heads/master@{#8953}
This commit is contained in:
parent
1064679bba
commit
036b420db6
@ -31,6 +31,7 @@ using namespace webrtc::videocapturemodule;
|
|||||||
webrtc::VideoCaptureCapability _capability;
|
webrtc::VideoCaptureCapability _capability;
|
||||||
AVCaptureSession* _captureSession;
|
AVCaptureSession* _captureSession;
|
||||||
int _captureId;
|
int _captureId;
|
||||||
|
BOOL _orientationHasChanged;
|
||||||
AVCaptureConnection* _connection;
|
AVCaptureConnection* _connection;
|
||||||
BOOL _captureChanging; // Guarded by _captureChangingCondition.
|
BOOL _captureChanging; // Guarded by _captureChangingCondition.
|
||||||
NSCondition* _captureChangingCondition;
|
NSCondition* _captureChangingCondition;
|
||||||
@ -80,14 +81,16 @@ using namespace webrtc::videocapturemodule;
|
|||||||
__LINE__);
|
__LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
|
||||||
|
|
||||||
NSNotificationCenter* notify = [NSNotificationCenter defaultCenter];
|
NSNotificationCenter* notify = [NSNotificationCenter defaultCenter];
|
||||||
[notify addObserver:self
|
[notify addObserver:self
|
||||||
selector:@selector(onVideoError:)
|
selector:@selector(onVideoError:)
|
||||||
name:AVCaptureSessionRuntimeErrorNotification
|
name:AVCaptureSessionRuntimeErrorNotification
|
||||||
object:_captureSession];
|
object:_captureSession];
|
||||||
[notify addObserver:self
|
[notify addObserver:self
|
||||||
selector:@selector(statusBarOrientationDidChange:)
|
selector:@selector(deviceOrientationDidChange:)
|
||||||
name:@"StatusBarOrientationDidChange"
|
name:UIDeviceOrientationDidChangeNotification
|
||||||
object:nil];
|
object:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,7 +108,8 @@ using namespace webrtc::videocapturemodule;
|
|||||||
[[self currentOutput] setSampleBufferDelegate:nil queue:NULL];
|
[[self currentOutput] setSampleBufferDelegate:nil queue:NULL];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)statusBarOrientationDidChange:(NSNotification*)notification {
|
- (void)deviceOrientationDidChange:(NSNotification*)notification {
|
||||||
|
_orientationHasChanged = YES;
|
||||||
[self setRelativeVideoOrientation];
|
[self setRelativeVideoOrientation];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,6 +175,7 @@ using namespace webrtc::videocapturemodule;
|
|||||||
|
|
||||||
[self directOutputToSelf];
|
[self directOutputToSelf];
|
||||||
|
|
||||||
|
_orientationHasChanged = NO;
|
||||||
_captureChanging = YES;
|
_captureChanging = YES;
|
||||||
dispatch_async(
|
dispatch_async(
|
||||||
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
|
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
|
||||||
@ -238,24 +243,33 @@ using namespace webrtc::videocapturemodule;
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)setRelativeVideoOrientation {
|
- (void)setRelativeVideoOrientation {
|
||||||
if (!_connection.supportsVideoOrientation)
|
if (!_connection.supportsVideoOrientation) {
|
||||||
return;
|
return;
|
||||||
switch ([UIApplication sharedApplication].statusBarOrientation) {
|
}
|
||||||
case UIInterfaceOrientationPortrait:
|
|
||||||
#if defined(__IPHONE_8_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_8_0
|
switch ([UIDevice currentDevice].orientation) {
|
||||||
case UIInterfaceOrientationUnknown:
|
case UIDeviceOrientationPortrait:
|
||||||
#endif
|
|
||||||
_connection.videoOrientation = AVCaptureVideoOrientationPortrait;
|
|
||||||
break;
|
|
||||||
case UIInterfaceOrientationPortraitUpsideDown:
|
|
||||||
_connection.videoOrientation =
|
_connection.videoOrientation =
|
||||||
AVCaptureVideoOrientationPortraitUpsideDown;
|
AVCaptureVideoOrientationPortraitUpsideDown;
|
||||||
|
case UIDeviceOrientationPortraitUpsideDown:
|
||||||
|
_connection.videoOrientation =
|
||||||
|
AVCaptureVideoOrientationPortrait;
|
||||||
break;
|
break;
|
||||||
case UIInterfaceOrientationLandscapeLeft:
|
case UIDeviceOrientationLandscapeLeft:
|
||||||
_connection.videoOrientation = AVCaptureVideoOrientationLandscapeLeft;
|
_connection.videoOrientation =
|
||||||
|
AVCaptureVideoOrientationLandscapeRight;
|
||||||
break;
|
break;
|
||||||
case UIInterfaceOrientationLandscapeRight:
|
case UIDeviceOrientationLandscapeRight:
|
||||||
_connection.videoOrientation = AVCaptureVideoOrientationLandscapeRight;
|
_connection.videoOrientation =
|
||||||
|
AVCaptureVideoOrientationLandscapeLeft;
|
||||||
|
break;
|
||||||
|
case UIDeviceOrientationFaceUp:
|
||||||
|
case UIDeviceOrientationFaceDown:
|
||||||
|
case UIDeviceOrientationUnknown:
|
||||||
|
if (!_orientationHasChanged) {
|
||||||
|
_connection.videoOrientation =
|
||||||
|
AVCaptureVideoOrientationPortrait;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -273,6 +287,8 @@ using namespace webrtc::videocapturemodule;
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)stopCapture {
|
- (BOOL)stopCapture {
|
||||||
|
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
|
||||||
|
_orientationHasChanged = NO;
|
||||||
[self waitForCaptureChangeToFinish];
|
[self waitForCaptureChangeToFinish];
|
||||||
[self directOutputToNil];
|
[self directOutputToNil];
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user