Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
BC
public
mediastreamer2
Commits
1451d9c7
Commit
1451d9c7
authored
Dec 20, 2013
by
Guillaume BIENKOWSKI
Browse files
Detect device orientation when initalizing iOS capture device
parent
6920f363
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
3 deletions
+31
-3
src/videofilters/ioscapture.m
src/videofilters/ioscapture.m
+31
-3
No files found.
src/videofilters/ioscapture.m
View file @
1451d9c7
...
...
@@ -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
deviceOrientation
2AVCaptureVideoOrientation
(
int
deviceOrientation
)
{
static
AVCaptureVideoOrientation
Angle
2AVCaptureVideoOrientation
(
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
=
deviceOrientation
2AVCaptureVideoOrientation
(
*
(
int
*
)(
arg
));
previewLayer
.
orientation
=
Angle
2AVCaptureVideoOrientation
(
*
(
int
*
)(
arg
));
}
return
0
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment