|
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. |
36 | 32 | #if defined(SDL_PLATFORM_IOS) && !defined(SDL_PLATFORM_TVOS) |
37 | | -//#define USE_UIKIT_DEVICE_ROTATION |
| 33 | +#define USE_UIKIT_DEVICE_ROTATION |
38 | 34 | #endif |
39 | 35 |
|
40 | 36 | #ifdef USE_UIKIT_DEVICE_ROTATION |
@@ -242,12 +238,26 @@ static SDL_CameraFrameResult COREMEDIA_AcquireFrame(SDL_Camera *device, SDL_Surf |
242 | 238 | hidden.last_device_orientation = device_orientation; // update the last known-good orientation for later. |
243 | 239 | } |
244 | 240 |
|
245 | | - switch (device_orientation) { |
246 | | - case UIDeviceOrientationPortrait: *rotation = 0; break; |
247 | | - case UIDeviceOrientationPortraitUpsideDown: *rotation = 180; break; |
248 | | - case UIDeviceOrientationLandscapeRight: *rotation = 90; break; // !!! FIXME: might be backwards. |
249 | | - case UIDeviceOrientationLandscapeLeft: *rotation = 270; break; // !!! FIXME: might be backwards. |
250 | | - default: SDL_assert(!"Unexpected device orientation!"); *rotation = 0; break; |
| 241 | + const UIInterfaceOrientation ui_orientation = [UIApplication sharedApplication].statusBarOrientation; |
| 242 | + |
| 243 | + // there is probably math for this, but this is easy to slap into a table. |
| 244 | + // rotation = rotations[uiorientation-1][devorientation-1]; |
| 245 | + if (device->position == SDL_CAMERA_POSITION_BACK_FACING) { |
| 246 | + static const int back_rotations[4][4] = { |
| 247 | + { 90, 90, 90, 90 }, // ui portrait |
| 248 | + { 270, 270, 270, 270 }, // ui portait upside down |
| 249 | + { 0, 0, 0, 0 }, // ui landscape left |
| 250 | + { 180, 180, 180, 180 } // ui landscape right |
| 251 | + }; |
| 252 | + *rotation = back_rotations[ui_orientation - 1][device_orientation - 1]; |
| 253 | + } else { |
| 254 | + static const int front_rotations[4][4] = { |
| 255 | + { 90, 90, 270, 270 }, // ui portrait |
| 256 | + { 270, 270, 90, 90 }, // ui portait upside down |
| 257 | + { 0, 0, 180, 180 }, // ui landscape left |
| 258 | + { 180, 180, 0, 0 } // ui landscape right |
| 259 | + }; |
| 260 | + *rotation = front_rotations[ui_orientation - 1][device_orientation - 1]; |
251 | 261 | } |
252 | 262 | #endif |
253 | 263 |
|
|
0 commit comments