|
29 | 29 | #import <AVFoundation/AVFoundation.h> |
30 | 30 | #import <CoreMedia/CoreMedia.h> |
31 | 31 |
|
| 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. |
32 | 36 | #if defined(SDL_PLATFORM_IOS) && !defined(SDL_PLATFORM_TVOS) |
| 37 | +//#define USE_UIKIT_DEVICE_ROTATION |
| 38 | +#endif |
| 39 | + |
| 40 | +#ifdef USE_UIKIT_DEVICE_ROTATION |
33 | 41 | #import <UIKit/UIKit.h> |
34 | 42 | #endif |
35 | 43 |
|
@@ -81,7 +89,7 @@ @interface SDLPrivateCameraData : NSObject |
81 | 89 | @property(nonatomic, retain) AVCaptureSession *session; |
82 | 90 | @property(nonatomic, retain) SDLCaptureVideoDataOutputSampleBufferDelegate *delegate; |
83 | 91 | @property(nonatomic, assign) CMSampleBufferRef current_sample; |
84 | | -#if defined(SDL_PLATFORM_IOS) && !defined(SDL_PLATFORM_TVOS) |
| 92 | +#ifdef USE_UIKIT_DEVICE_ROTATION |
85 | 93 | @property(nonatomic, assign) UIDeviceOrientation last_device_orientation; |
86 | 94 | #endif |
87 | 95 | @end |
@@ -226,9 +234,7 @@ static SDL_CameraFrameResult COREMEDIA_AcquireFrame(SDL_Camera *device, SDL_Surf |
226 | 234 |
|
227 | 235 | CVPixelBufferUnlockBaseAddress(image, 0); |
228 | 236 |
|
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 |
232 | 238 | UIDeviceOrientation device_orientation = [[UIDevice currentDevice] orientation]; |
233 | 239 | if (!UIDeviceOrientationIsValidInterfaceOrientation(device_orientation)) { |
234 | 240 | 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) |
257 | 263 | static void COREMEDIA_CloseDevice(SDL_Camera *device) |
258 | 264 | { |
259 | 265 | if (device && device->hidden) { |
260 | | - #if defined(SDL_PLATFORM_IOS) && !defined(SDL_PLATFORM_TVOS) |
| 266 | + #ifdef USE_UIKIT_DEVICE_ROTATION |
261 | 267 | [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; |
262 | 268 | #endif |
263 | 269 |
|
@@ -389,7 +395,7 @@ static bool COREMEDIA_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *spec) |
389 | 395 | hidden.delegate = delegate; |
390 | 396 | hidden.current_sample = NULL; |
391 | 397 |
|
392 | | - #if defined(SDL_PLATFORM_IOS) && !defined(SDL_PLATFORM_TVOS) |
| 398 | + #ifdef USE_UIKIT_DEVICE_ROTATION |
393 | 399 | // When using a camera, we turn on device orientation tracking. The docs note that this turns on |
394 | 400 | // the device's accelerometer, so I assume this burns power, so we don't leave this running all |
395 | 401 | // the time. These calls nest, so we just need to call the matching `end` message when we close. |
|
0 commit comments