@@ -42,7 +42,7 @@ @implementation RTC_OBJC_TYPE (RTCCameraVideoCapturer) {
42
42
FourCharCode _outputPixelFormat;
43
43
RTCVideoRotation _rotation;
44
44
#if TARGET_OS_IPHONE
45
- UIDeviceOrientation _orientation;
45
+ UIInterfaceOrientation _orientation;
46
46
BOOL _generatingOrientationNotifications;
47
47
#endif
48
48
}
@@ -75,7 +75,7 @@ - (instancetype)initWithDelegate:(__weak id<RTC_OBJC_TYPE(RTCVideoCapturerDelega
75
75
}
76
76
NSNotificationCenter *center = [NSNotificationCenter defaultCenter ];
77
77
#if TARGET_OS_IPHONE
78
- _orientation = UIDeviceOrientationPortrait ;
78
+ _orientation = UIInterfaceOrientationPortrait ;
79
79
_rotation = RTCVideoRotation_90;
80
80
[center addObserver: self
81
81
selector: @selector (deviceOrientationDidChange: )
@@ -166,6 +166,8 @@ - (void)startCaptureWithDevice:(AVCaptureDevice *)device
166
166
[[UIDevice currentDevice ] beginGeneratingDeviceOrientationNotifications ];
167
167
self->_generatingOrientationNotifications = YES ;
168
168
}
169
+ // Must be called on main
170
+ [self updateOrientation ];
169
171
});
170
172
#endif
171
173
@@ -183,7 +185,6 @@ - (void)startCaptureWithDevice:(AVCaptureDevice *)device
183
185
return ;
184
186
}
185
187
[self reconfigureCaptureSessionInput ];
186
- [self updateOrientation ];
187
188
[self updateDeviceCaptureFormat: format fps: fps];
188
189
[self updateVideoDataOutputPixelFormat: format];
189
190
[self .captureSession startRunning ];
@@ -226,10 +227,7 @@ - (void)stopCaptureWithCompletionHandler:(nullable void (^)(void))completionHand
226
227
227
228
#if TARGET_OS_IPHONE
228
229
- (void )deviceOrientationDidChange:(NSNotification *)notification {
229
- [RTC_OBJC_TYPE (RTCDispatcher) dispatchAsyncOnType: RTCDispatcherTypeCaptureSession
230
- block: ^{
231
- [self updateOrientation ];
232
- }];
230
+ [self updateOrientation ];
233
231
}
234
232
#endif
235
233
@@ -265,22 +263,20 @@ - (void)captureOutput:(AVCaptureOutput *)captureOutput
265
263
usingFrontCamera = AVCaptureDevicePositionFront == deviceInput.device .position ;
266
264
}
267
265
switch (_orientation) {
268
- case UIDeviceOrientationPortrait :
266
+ case UIInterfaceOrientationPortrait :
269
267
_rotation = RTCVideoRotation_90;
270
268
break ;
271
- case UIDeviceOrientationPortraitUpsideDown :
269
+ case UIInterfaceOrientationPortraitUpsideDown :
272
270
_rotation = RTCVideoRotation_270;
273
271
break ;
274
- case UIDeviceOrientationLandscapeLeft:
275
- _rotation = usingFrontCamera ? RTCVideoRotation_180 : RTCVideoRotation_0;
276
- break ;
277
- case UIDeviceOrientationLandscapeRight:
272
+ case UIInterfaceOrientationLandscapeLeft:
278
273
_rotation = usingFrontCamera ? RTCVideoRotation_0 : RTCVideoRotation_180;
279
274
break ;
280
- case UIDeviceOrientationFaceUp:
281
- case UIDeviceOrientationFaceDown:
282
- case UIDeviceOrientationUnknown:
283
- // Ignore.
275
+ case UIInterfaceOrientationLandscapeRight:
276
+ _rotation = usingFrontCamera ? RTCVideoRotation_180 : RTCVideoRotation_0;
277
+ break ;
278
+ case UIInterfaceOrientationUnknown:
279
+ _rotation = RTCVideoRotation_0;
284
280
break ;
285
281
}
286
282
#else
@@ -495,8 +491,8 @@ - (void)updateDeviceCaptureFormat:(AVCaptureDeviceFormat *)format fps:(NSInteger
495
491
@" updateDeviceCaptureFormat must be called on the capture queue." );
496
492
@try {
497
493
_currentDevice.activeFormat = format;
498
- if (![NSStringFromClass ([_currentDevice class ]) isEqualToString: @" AVCaptureDALDevice" ]) {
499
- _currentDevice.activeVideoMinFrameDuration = CMTimeMake (1 , fps);
494
+ if (![NSStringFromClass ([_currentDevice class ]) isEqualToString: @" AVCaptureDALDevice" ]) {
495
+ _currentDevice.activeVideoMinFrameDuration = CMTimeMake (1 , fps);
500
496
}
501
497
} @catch (NSException *exception) {
502
498
RTCLogError (@" Failed to set active format!\n User info:%@ " , exception.userInfo );
@@ -508,8 +504,8 @@ - (void)reconfigureCaptureSessionInput {
508
504
NSAssert ([RTC_OBJC_TYPE (RTCDispatcher) isOnQueueForType: RTCDispatcherTypeCaptureSession],
509
505
@" reconfigureCaptureSessionInput must be called on the capture queue." );
510
506
NSError *error = nil ;
511
- AVCaptureDeviceInput *input =
512
- [AVCaptureDeviceInput deviceInputWithDevice: _currentDevice error: &error];
507
+ AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice: _currentDevice
508
+ error: &error];
513
509
if (!input) {
514
510
RTCLogError (@" Failed to create front camera input: %@ " , error.localizedDescription );
515
511
return ;
@@ -526,12 +522,19 @@ - (void)reconfigureCaptureSessionInput {
526
522
[_captureSession commitConfiguration ];
527
523
}
528
524
529
- - (void )updateOrientation {
530
- NSAssert ([RTC_OBJC_TYPE (RTCDispatcher) isOnQueueForType: RTCDispatcherTypeCaptureSession],
531
- @" updateOrientation must be called on the capture queue." );
532
525
#if TARGET_OS_IPHONE
533
- _orientation = [UIDevice currentDevice ].orientation ;
534
- #endif
526
+ - (void )updateOrientation {
527
+ NSAssert ([RTC_OBJC_TYPE (RTCDispatcher) isOnQueueForType: RTCDispatcherTypeMain],
528
+ @" statusBarOrientation must be called on the main queue." );
529
+ // statusBarOrientation must be called on the main queue
530
+ UIInterfaceOrientation newOrientation = [UIApplication sharedApplication ].statusBarOrientation ;
531
+
532
+ [RTC_OBJC_TYPE (RTCDispatcher) dispatchAsyncOnType: RTCDispatcherTypeCaptureSession
533
+ block: ^{
534
+ // Must be called on the capture queue
535
+ self->_orientation = newOrientation;
536
+ }];
535
537
}
538
+ #endif
536
539
537
540
@end
0 commit comments