Skip to content

Commit 5c34815

Browse files
committed
camera: Disable iOS device orientation tracking.
iOS manages this and gives us right-side up frames of video by default.
1 parent fe43cc0 commit 5c34815

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/camera/coremedia/SDL_camera_coremedia.m

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,15 @@
2929
#import <AVFoundation/AVFoundation.h>
3030
#import <CoreMedia/CoreMedia.h>
3131

32+
// this is a codepath that tracks iOS device orientation to try to correct
33+
// video frame rotation, but currently it looks like iOS is doing this work
34+
// for us, and better. This is disabled for now, so the code lives in revision
35+
// control before I remove it outright.
3236
#if defined(SDL_PLATFORM_IOS) && !defined(SDL_PLATFORM_TVOS)
37+
//#define USE_UIKIT_DEVICE_ROTATION
38+
#endif
39+
40+
#ifdef USE_UIKIT_DEVICE_ROTATION
3341
#import <UIKit/UIKit.h>
3442
#endif
3543

@@ -81,7 +89,7 @@ @interface SDLPrivateCameraData : NSObject
8189
@property(nonatomic, retain) AVCaptureSession *session;
8290
@property(nonatomic, retain) SDLCaptureVideoDataOutputSampleBufferDelegate *delegate;
8391
@property(nonatomic, assign) CMSampleBufferRef current_sample;
84-
#if defined(SDL_PLATFORM_IOS) && !defined(SDL_PLATFORM_TVOS)
92+
#ifdef USE_UIKIT_DEVICE_ROTATION
8593
@property(nonatomic, assign) UIDeviceOrientation last_device_orientation;
8694
#endif
8795
@end
@@ -226,9 +234,7 @@ static SDL_CameraFrameResult COREMEDIA_AcquireFrame(SDL_Camera *device, SDL_Surf
226234

227235
CVPixelBufferUnlockBaseAddress(image, 0);
228236

229-
// As of this writing, all known iOS devices provide portrait orientation camera data, so we just need to know how to rotate between that and the current device orientation.
230-
// macOS currently assumes you don't ever rotate images because the camera is always positioned right-side up (for now).
231-
#if defined(SDL_PLATFORM_IOS) && !defined(SDL_PLATFORM_TVOS)
237+
#ifdef USE_UIKIT_DEVICE_ROTATION
232238
UIDeviceOrientation device_orientation = [[UIDevice currentDevice] orientation];
233239
if (!UIDeviceOrientationIsValidInterfaceOrientation(device_orientation)) {
234240
device_orientation = hidden.last_device_orientation; // possible the phone is laying flat or something went wrong, just stay with the last known-good orientation.
@@ -257,7 +263,7 @@ static void COREMEDIA_ReleaseFrame(SDL_Camera *device, SDL_Surface *frame)
257263
static void COREMEDIA_CloseDevice(SDL_Camera *device)
258264
{
259265
if (device && device->hidden) {
260-
#if defined(SDL_PLATFORM_IOS) && !defined(SDL_PLATFORM_TVOS)
266+
#ifdef USE_UIKIT_DEVICE_ROTATION
261267
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
262268
#endif
263269

@@ -389,7 +395,7 @@ static bool COREMEDIA_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *spec)
389395
hidden.delegate = delegate;
390396
hidden.current_sample = NULL;
391397

392-
#if defined(SDL_PLATFORM_IOS) && !defined(SDL_PLATFORM_TVOS)
398+
#ifdef USE_UIKIT_DEVICE_ROTATION
393399
// When using a camera, we turn on device orientation tracking. The docs note that this turns on
394400
// the device's accelerometer, so I assume this burns power, so we don't leave this running all
395401
// the time. These calls nest, so we just need to call the matching `end` message when we close.

0 commit comments

Comments
 (0)