Commit 1451d9c7 authored by Guillaume BIENKOWSKI's avatar Guillaume BIENKOWSKI
Browse files

Detect device orientation when initalizing iOS capture device

parent 6920f363
......@@ -34,6 +34,9 @@
#if !TARGET_IPHONE_SIMULATOR
static AVCaptureVideoOrientation Angle2AVCaptureVideoOrientation(int deviceOrientation);
static AVCaptureVideoOrientation UIDeviceOrientation2AVCaptureVideoOrientation( UIDeviceOrientation orientation );
// AVCaptureVideoPreviewLayer with AVCaptureSession creation
@interface AVCaptureVideoPreviewLayerEx : AVCaptureVideoPreviewLayer
......@@ -132,7 +135,8 @@ static void capture_queue_cleanup(void* p) {
/* Set the layer */
AVCaptureVideoPreviewLayer *previewLayer = (AVCaptureVideoPreviewLayer *)self.layer;
[previewLayer setOrientation:AVCaptureVideoOrientationPortrait];
AVCaptureVideoOrientation orientation = UIDeviceOrientation2AVCaptureVideoOrientation([[UIDevice currentDevice] orientation]);
[previewLayer setOrientation:orientation];
[previewLayer setBackgroundColor:[[UIColor clearColor] CGColor]];
[previewLayer setOpaque:YES];
start_time=0;
......@@ -358,7 +362,7 @@ static void capture_queue_cleanup(void* p) {
return 0;
}
static AVCaptureVideoOrientation deviceOrientation2AVCaptureVideoOrientation(int deviceOrientation) {
static AVCaptureVideoOrientation Angle2AVCaptureVideoOrientation(int deviceOrientation) {
switch (deviceOrientation) {
case 0: return AVCaptureVideoOrientationPortrait;
case 90: return AVCaptureVideoOrientationLandscapeLeft;
......@@ -373,6 +377,30 @@ static AVCaptureVideoOrientation deviceOrientation2AVCaptureVideoOrientation(int
return AVCaptureVideoOrientationPortrait;
}
static AVCaptureVideoOrientation UIDeviceOrientation2AVCaptureVideoOrientation( UIDeviceOrientation orientation ) {
switch (orientation) {
case UIDeviceOrientationPortraitUpsideDown:
return AVCaptureVideoOrientationPortraitUpsideDown;
// see http://stackoverflow.com/questions/7845520/why-does-avcapturevideoorientation-landscape-modes-result-in-upside-down-still-i
// landscape left on UI means landscape right on AVCapture.
case UIDeviceOrientationLandscapeLeft:
return AVCaptureVideoOrientationLandscapeRight;
case UIDeviceOrientationLandscapeRight:
return AVCaptureVideoOrientationLandscapeLeft;
case UIDeviceOrientationFaceUp:
case UIDeviceOrientationPortrait:
case UIDeviceOrientationUnknown:
case UIDeviceOrientationFaceDown:
default:
return AVCaptureVideoOrientationPortrait;
break;
}
}
- (void)configureSize:(MSVideoSize) outputSize
withSession:(AVCaptureSession *) session {
if (((outputSize.width * outputSize.height) == (MS_VIDEO_SIZE_1080P_W * MS_VIDEO_SIZE_1080P_H))
......@@ -642,7 +670,7 @@ static int ioscapture_set_device_orientation_display (MSFilter *f, void *arg) {
if (thiz != NULL) {
AVCaptureVideoPreviewLayer *previewLayer = (AVCaptureVideoPreviewLayer *)thiz.layer;
if ([previewLayer isOrientationSupported])
previewLayer.orientation = deviceOrientation2AVCaptureVideoOrientation(*(int*)(arg));
previewLayer.orientation = Angle2AVCaptureVideoOrientation(*(int*)(arg));
}
return 0;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment