OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #import "WebRTC/RTCCameraPreviewView.h" | 11 #import "WebRTC/RTCCameraPreviewView.h" |
12 | 12 |
13 #import <AVFoundation/AVFoundation.h> | 13 #import <AVFoundation/AVFoundation.h> |
14 #import <UIKit/UIKit.h> | |
14 | 15 |
15 #import "RTCDispatcher+Private.h" | 16 #import "RTCDispatcher+Private.h" |
16 | 17 |
17 @implementation RTCCameraPreviewView | 18 @implementation RTCCameraPreviewView |
18 | 19 |
19 @synthesize captureSession = _captureSession; | 20 @synthesize captureSession = _captureSession; |
21 @synthesize shouldAutoRotate = _shouldAutoRotate; | |
20 | 22 |
21 + (Class)layerClass { | 23 + (Class)layerClass { |
22 return [AVCaptureVideoPreviewLayer class]; | 24 return [AVCaptureVideoPreviewLayer class]; |
23 } | 25 } |
24 | 26 |
25 - (void)setCaptureSession:(AVCaptureSession *)captureSession { | 27 - (void)setCaptureSession:(AVCaptureSession *)captureSession { |
26 if (_captureSession == captureSession) { | 28 if (_captureSession == captureSession) { |
27 return; | 29 return; |
28 } | 30 } |
29 _captureSession = captureSession; | 31 _captureSession = captureSession; |
30 AVCaptureVideoPreviewLayer *previewLayer = [self previewLayer]; | 32 AVCaptureVideoPreviewLayer *previewLayer = [self previewLayer]; |
31 [RTCDispatcher dispatchAsyncOnType:RTCDispatcherTypeCaptureSession | 33 [RTCDispatcher dispatchAsyncOnType:RTCDispatcherTypeCaptureSession |
32 block:^{ | 34 block:^{ |
33 previewLayer.session = captureSession; | 35 previewLayer.session = captureSession; |
34 }]; | 36 }]; |
35 } | 37 } |
36 | 38 |
39 - (void) setShouldAutoRotate:(BOOL)shouldAutoRotate { | |
daniela-webrtc
2017/04/06 09:45:37
Remove space.
Hint: use `git cl format before` sub
tkchin_webrtc
2017/04/06 17:39:22
Is that what your team has decided on now? Is ther
meetAkshay99
2017/04/07 05:19:29
I tried that but got following error:
YAML:8:11: e
| |
40 if (shouldAutoRotate) { | |
daniela-webrtc
2017/04/06 09:45:37
You are not assigning the synthesized ivar _should
meetAkshay99
2017/04/06 10:24:34
My bad. Yes thats required.
| |
41 [[NSNotificationCenter defaultCenter] addObserver:self | |
daniela-webrtc
2017/04/06 09:45:37
This seems like overhead - (Un)Registering for not
meetAkshay99
2017/04/06 10:24:34
That is what I was having earlier. A method was de
daniela-webrtc
2017/04/06 14:44:46
I think the other reviewers meant that there is no
meetAkshay99
2017/04/07 05:19:29
Yeah, updating to call setCorrectVideoOrientation
| |
42 selector:@selector(deviceOrient ationDidChange:) | |
43 name:UIDeviceOrientationDid ChangeNotification | |
44 object:nil]; | |
45 [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications] ; | |
46 } else { | |
47 [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; | |
48 [[NSNotificationCenter defaultCenter] removeObserver:self | |
49 name:UIDeviceOrientationDidC hangeNotification | |
50 object:nil]; | |
51 } | |
52 } | |
53 | |
54 - (void)deviceOrientationDidChange:(NSNotification *)notification { | |
55 // Get current device orientation. | |
56 UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation ; | |
57 AVCaptureVideoPreviewLayer *previewLayer = [self previewLayer]; | |
58 | |
59 // Set the video orientation based on device orientation. | |
60 if (deviceOrientation == UIInterfaceOrientationPortraitUpsideDown) { | |
Chuck
2017/04/06 19:06:46
This header docs say you should only set this prop
meetAkshay99
2017/04/07 05:19:29
Added a check for the same.
| |
61 [previewLayer.connection setVideoOrientation:AVCaptureVideoOrientationPo rtraitUpsideDown]; | |
Chuck
2017/04/06 19:06:46
Please use property syntax here:
previewLayer.conn
meetAkshay99
2017/04/07 05:19:29
I would update it to property syntax, but would li
Chuck
2017/04/07 12:57:40
It's modern objective-c syntax and to match the st
| |
62 } else if (deviceOrientation == UIInterfaceOrientationPortrait) { | |
63 [previewLayer.connection setVideoOrientation:AVCaptureVideoOrientationPo rtrait]; | |
64 } else if (deviceOrientation == UIInterfaceOrientationLandscapeLeft) { | |
65 [previewLayer.connection setVideoOrientation:AVCaptureVideoOrientationLa ndscapeLeft]; | |
66 } else { | |
67 [previewLayer.connection setVideoOrientation:AVCaptureVideoOrientationLa ndscapeRight]; | |
68 } | |
69 } | |
70 | |
37 #pragma mark - Private | 71 #pragma mark - Private |
38 | 72 |
39 - (AVCaptureVideoPreviewLayer *)previewLayer { | 73 - (AVCaptureVideoPreviewLayer *)previewLayer { |
40 return (AVCaptureVideoPreviewLayer *)self.layer; | 74 return (AVCaptureVideoPreviewLayer *)self.layer; |
41 } | 75 } |
42 | 76 |
43 @end | 77 @end |
OLD | NEW |