Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Unified Diff: webrtc/sdk/objc/Framework/Classes/RTCCameraVideoCapturer.m

Issue 2815823002: Add unit test class for RTCCameraVideoCapturer. (Closed)
Patch Set: Add tests that test only the public interface Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/sdk/objc/Framework/Classes/RTCCameraVideoCapturer.m
diff --git a/webrtc/sdk/objc/Framework/Classes/RTCCameraVideoCapturer.m b/webrtc/sdk/objc/Framework/Classes/RTCCameraVideoCapturer.m
index 16ddc13c9eaba1f5aaf42176a66c5444a4740e3e..de092e6da4ec5bd4837b31154c8751dce990ea13 100644
--- a/webrtc/sdk/objc/Framework/Classes/RTCCameraVideoCapturer.m
+++ b/webrtc/sdk/objc/Framework/Classes/RTCCameraVideoCapturer.m
@@ -27,22 +27,26 @@ static inline BOOL IsMediaSubTypeSupported(FourCharCode mediaSubType) {
}
@interface RTCCameraVideoCapturer ()<AVCaptureVideoDataOutputSampleBufferDelegate>
-@property(nonatomic, readonly) dispatch_queue_t frameQueue;
+@property(nonatomic, strong) AVCaptureVideoDataOutput *videoDataOutput;
magjed_webrtc 2017/04/26 14:12:08 Should we revert these changes and only have them
daniela-webrtc 2017/04/27 09:40:19 Done.
+@property(nonatomic, strong) AVCaptureDevice *currentDevice;
+@property(nonatomic, strong) dispatch_queue_t frameQueue;
magjed_webrtc 2017/04/26 14:12:08 I would like to make frameQueue readonly again.
daniela-webrtc 2017/04/27 09:40:19 Done.
+@property(nonatomic, assign) RTCVideoRotation rotation;
+// Will the session be running once all asynchronous operations have been completed?
+@property(nonatomic, assign) BOOL willBeRunning;
+
@end
@implementation RTCCameraVideoCapturer {
- AVCaptureVideoDataOutput *_videoDataOutput;
- AVCaptureSession *_captureSession;
- AVCaptureDevice *_currentDevice;
- RTCVideoRotation _rotation;
BOOL _hasRetriedOnFatalError;
BOOL _isRunning;
- // Will the session be running once all asynchronous operations have been completed?
- BOOL _willBeRunning;
}
-@synthesize frameQueue = _frameQueue;
@synthesize captureSession = _captureSession;
+@synthesize currentDevice = _currentDevice;
+@synthesize frameQueue = _frameQueue;
+@synthesize rotation = _rotation;
+@synthesize videoDataOutput = _videoDataOutput;
+@synthesize willBeRunning = _willBeRunning;
- (instancetype)initWithDelegate:(__weak id<RTCVideoCapturerDelegate>)delegate {
if (self = [super initWithDelegate:delegate]) {
@@ -121,28 +125,10 @@ static inline BOOL IsMediaSubTypeSupported(FourCharCode mediaSubType) {
dispatchAsyncOnType:RTCDispatcherTypeCaptureSession
block:^{
RTCLogInfo("startCaptureWithDevice %@ @ %d fps", format, fps);
-
#if TARGET_OS_IPHONE
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
#endif
-
- _currentDevice = device;
-
- NSError *error = nil;
- if ([_currentDevice lockForConfiguration:&error]) {
- [self updateDeviceCaptureFormat:format fps:fps];
- } else {
- RTCLogError(@"Failed to lock device %@. Error: %@", _currentDevice,
- error.userInfo);
- return;
- }
-
- [self reconfigureCaptureSessionInput];
- [self updateOrientation];
- [_captureSession startRunning];
-
- [_currentDevice unlockForConfiguration];
- _isRunning = true;
+ _isRunning = [self tryStartCaptureWithDevice:device format:format fps:fps];
}];
}
@@ -360,6 +346,27 @@ static inline BOOL IsMediaSubTypeSupported(FourCharCode mediaSubType) {
#pragma mark - Private, called inside capture queue
+- (BOOL)tryStartCaptureWithDevice:(AVCaptureDevice *)device
+ format:(AVCaptureDeviceFormat *)format
+ fps:(int)fps {
+ _currentDevice = device;
+
+ NSError *error = nil;
+ if ([_currentDevice lockForConfiguration:&error]) {
+ [self updateDeviceCaptureFormat:format fps:fps];
+ } else {
+ RTCLogError(@"Failed to lock device %@. Error: %@", _currentDevice, error.userInfo);
+ return NO;
+ }
+
+ [self reconfigureCaptureSessionInput];
+ [self updateOrientation];
+ [_captureSession startRunning];
+
+ [_currentDevice unlockForConfiguration];
+ return YES;
+}
+
- (void)updateDeviceCaptureFormat:(AVCaptureDeviceFormat *)format fps:(int)fps {
@try {
_currentDevice.activeFormat = format;
@@ -392,8 +399,14 @@ static inline BOOL IsMediaSubTypeSupported(FourCharCode mediaSubType) {
- (void)updateOrientation {
#if TARGET_OS_IPHONE
+ [self updateOrientation:[UIDevice currentDevice].orientation];
+#endif
+}
+
+#if TARGET_OS_IPHONE
+- (void)updateOrientation:(UIDeviceOrientation)orientation {
BOOL usingFrontCamera = _currentDevice.position == AVCaptureDevicePositionFront;
- switch ([UIDevice currentDevice].orientation) {
+ switch (orientation) {
case UIDeviceOrientationPortrait:
_rotation = RTCVideoRotation_90;
break;
@@ -412,7 +425,7 @@ static inline BOOL IsMediaSubTypeSupported(FourCharCode mediaSubType) {
// Ignore.
break;
}
-#endif
}
+#endif
@end

Powered by Google App Engine
This is Rietveld 408576698