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

Side by Side Diff: webrtc/modules/video_capture/objc/rtc_video_capture_objc.mm

Issue 2534553002: Replace VideoCaptureDataCallback by VideoSinkInterface. (Closed)
Patch Set: Add webrtc/media/base to video_capturer include_rules. Created 4 years 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 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
(...skipping 15 matching lines...) Expand all
26 using namespace webrtc::videocapturemodule; 26 using namespace webrtc::videocapturemodule;
27 27
28 @interface RTCVideoCaptureIosObjC (hidden) 28 @interface RTCVideoCaptureIosObjC (hidden)
29 - (int)changeCaptureInputWithName:(NSString*)captureDeviceName; 29 - (int)changeCaptureInputWithName:(NSString*)captureDeviceName;
30 @end 30 @end
31 31
32 @implementation RTCVideoCaptureIosObjC { 32 @implementation RTCVideoCaptureIosObjC {
33 webrtc::videocapturemodule::VideoCaptureIos* _owner; 33 webrtc::videocapturemodule::VideoCaptureIos* _owner;
34 webrtc::VideoCaptureCapability _capability; 34 webrtc::VideoCaptureCapability _capability;
35 AVCaptureSession* _captureSession; 35 AVCaptureSession* _captureSession;
36 int _captureId;
37 BOOL _orientationHasChanged; 36 BOOL _orientationHasChanged;
38 AVCaptureConnection* _connection; 37 AVCaptureConnection* _connection;
39 BOOL _captureChanging; // Guarded by _captureChangingCondition. 38 BOOL _captureChanging; // Guarded by _captureChangingCondition.
40 NSCondition* _captureChangingCondition; 39 NSCondition* _captureChangingCondition;
41 } 40 }
42 41
43 @synthesize frameRotation = _framRotation; 42 @synthesize frameRotation = _framRotation;
44 43
45 - (id)initWithOwner:(VideoCaptureIos*)owner captureId:(int)captureId { 44 - (id)initWithOwner:(VideoCaptureIos*)owner {
46 if (self == [super init]) { 45 if (self == [super init]) {
47 _owner = owner; 46 _owner = owner;
48 _captureId = captureId;
49 _captureSession = [[AVCaptureSession alloc] init]; 47 _captureSession = [[AVCaptureSession alloc] init];
50 #if defined(WEBRTC_IOS) 48 #if defined(WEBRTC_IOS)
51 _captureSession.usesApplicationAudioSession = NO; 49 _captureSession.usesApplicationAudioSession = NO;
52 #endif 50 #endif
53 _captureChanging = NO; 51 _captureChanging = NO;
54 _captureChangingCondition = [[NSCondition alloc] init]; 52 _captureChangingCondition = [[NSCondition alloc] init];
55 53
56 if (!_captureSession || !_captureChangingCondition) { 54 if (!_captureSession || !_captureChangingCondition) {
57 return nil; 55 return nil;
58 } 56 }
59 57
60 // create and configure a new output (using callbacks) 58 // create and configure a new output (using callbacks)
61 AVCaptureVideoDataOutput* captureOutput = 59 AVCaptureVideoDataOutput* captureOutput =
62 [[AVCaptureVideoDataOutput alloc] init]; 60 [[AVCaptureVideoDataOutput alloc] init];
63 NSString* key = (NSString*)kCVPixelBufferPixelFormatTypeKey; 61 NSString* key = (NSString*)kCVPixelBufferPixelFormatTypeKey;
64 62
65 NSNumber* val = [NSNumber 63 NSNumber* val = [NSNumber
66 numberWithUnsignedInt:kCVPixelFormatType_420YpCbCr8BiPlanarFullRange]; 64 numberWithUnsignedInt:kCVPixelFormatType_420YpCbCr8BiPlanarFullRange];
67 NSDictionary* videoSettings = 65 NSDictionary* videoSettings =
68 [NSDictionary dictionaryWithObject:val forKey:key]; 66 [NSDictionary dictionaryWithObject:val forKey:key];
69 captureOutput.videoSettings = videoSettings; 67 captureOutput.videoSettings = videoSettings;
70 68
71 // add new output 69 // add new output
72 if ([_captureSession canAddOutput:captureOutput]) { 70 if ([_captureSession canAddOutput:captureOutput]) {
73 [_captureSession addOutput:captureOutput]; 71 [_captureSession addOutput:captureOutput];
74 } else { 72 } else {
75 WEBRTC_TRACE(kTraceError, kTraceVideoCapture, _captureId, 73 WEBRTC_TRACE(kTraceError, kTraceVideoCapture, 0,
76 "%s:%s:%d Could not add output to AVCaptureSession ", 74 "%s:%s:%d Could not add output to AVCaptureSession ",
77 __FILE__, __FUNCTION__, __LINE__); 75 __FILE__, __FUNCTION__, __LINE__);
78 } 76 }
79 77
80 #ifdef WEBRTC_IOS 78 #ifdef WEBRTC_IOS
81 [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 79 [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
82 80
83 NSNotificationCenter* notify = [NSNotificationCenter defaultCenter]; 81 NSNotificationCenter* notify = [NSNotificationCenter defaultCenter];
84 [notify addObserver:self 82 [notify addObserver:self
85 selector:@selector(onVideoError:) 83 selector:@selector(onVideoError:)
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 _connection.videoOrientation = AVCaptureVideoOrientationPortrait; 236 _connection.videoOrientation = AVCaptureVideoOrientationPortrait;
239 } 237 }
240 break; 238 break;
241 } 239 }
242 #endif 240 #endif
243 } 241 }
244 242
245 - (void)onVideoError:(NSNotification*)notification { 243 - (void)onVideoError:(NSNotification*)notification {
246 NSLog(@"onVideoError: %@", notification); 244 NSLog(@"onVideoError: %@", notification);
247 // TODO(sjlee): make the specific error handling with this notification. 245 // TODO(sjlee): make the specific error handling with this notification.
248 WEBRTC_TRACE(kTraceError, kTraceVideoCapture, _captureId, 246 WEBRTC_TRACE(kTraceError, kTraceVideoCapture, 0,
249 "%s:%s:%d [AVCaptureSession startRunning] error.", __FILE__, 247 "%s:%s:%d [AVCaptureSession startRunning] error.", __FILE__,
250 __FUNCTION__, __LINE__); 248 __FUNCTION__, __LINE__);
251 } 249 }
252 250
253 - (BOOL)stopCapture { 251 - (BOOL)stopCapture {
254 #ifdef WEBRTC_IOS 252 #ifdef WEBRTC_IOS
255 [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; 253 [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
256 #endif 254 #endif
257 _orientationHasChanged = NO; 255 _orientationHasChanged = NO;
258 [self waitForCaptureChangeToFinish]; 256 [self waitForCaptureChangeToFinish];
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 300
303 // now create capture session input out of AVCaptureDevice 301 // now create capture session input out of AVCaptureDevice
304 NSError* deviceError = nil; 302 NSError* deviceError = nil;
305 AVCaptureDeviceInput* newCaptureInput = 303 AVCaptureDeviceInput* newCaptureInput =
306 [AVCaptureDeviceInput deviceInputWithDevice:captureDevice 304 [AVCaptureDeviceInput deviceInputWithDevice:captureDevice
307 error:&deviceError]; 305 error:&deviceError];
308 306
309 if (!newCaptureInput) { 307 if (!newCaptureInput) {
310 const char* errorMessage = [[deviceError localizedDescription] UTF8String]; 308 const char* errorMessage = [[deviceError localizedDescription] UTF8String];
311 309
312 WEBRTC_TRACE(kTraceError, kTraceVideoCapture, _captureId, 310 WEBRTC_TRACE(kTraceError, kTraceVideoCapture, 0,
313 "%s:%s:%d deviceInputWithDevice error:%s", __FILE__, 311 "%s:%s:%d deviceInputWithDevice error:%s", __FILE__,
314 __FUNCTION__, __LINE__, errorMessage); 312 __FUNCTION__, __LINE__, errorMessage);
315 313
316 return NO; 314 return NO;
317 } 315 }
318 316
319 // try to add our new capture device to the capture session 317 // try to add our new capture device to the capture session
320 [_captureSession beginConfiguration]; 318 [_captureSession beginConfiguration];
321 319
322 BOOL addedCaptureInput = NO; 320 BOOL addedCaptureInput = NO;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 } 374 }
377 375
378 - (void)waitForCaptureChangeToFinish { 376 - (void)waitForCaptureChangeToFinish {
379 [_captureChangingCondition lock]; 377 [_captureChangingCondition lock];
380 while (_captureChanging) { 378 while (_captureChanging) {
381 [_captureChangingCondition wait]; 379 [_captureChangingCondition wait];
382 } 380 }
383 [_captureChangingCondition unlock]; 381 [_captureChangingCondition unlock];
384 } 382 }
385 @end 383 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698