Chromium Code Reviews

Side by Side Diff: talk/app/webrtc/objc/avfoundationvideocapturer.mm

Issue 1497393002: Add new view that renders local video using AVCaptureLayerPreview. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Removed commented line. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
1 /* 1 /*
2 * libjingle 2 * libjingle
3 * Copyright 2015 Google Inc. 3 * Copyright 2015 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 36 matching lines...)
47 static dispatch_queue_t kBackgroundQueue = nil; 47 static dispatch_queue_t kBackgroundQueue = nil;
48 48
49 // This class used to capture frames using AVFoundation APIs on iOS. It is meant 49 // This class used to capture frames using AVFoundation APIs on iOS. It is meant
50 // to be owned by an instance of AVFoundationVideoCapturer. The reason for this 50 // to be owned by an instance of AVFoundationVideoCapturer. The reason for this
51 // because other webrtc objects own cricket::VideoCapturer, which is not 51 // because other webrtc objects own cricket::VideoCapturer, which is not
52 // ref counted. To prevent bad behavior we do not expose this class directly. 52 // ref counted. To prevent bad behavior we do not expose this class directly.
53 @interface RTCAVFoundationVideoCapturerInternal : NSObject 53 @interface RTCAVFoundationVideoCapturerInternal : NSObject
54 <AVCaptureVideoDataOutputSampleBufferDelegate> 54 <AVCaptureVideoDataOutputSampleBufferDelegate>
55 55
56 @property(nonatomic, readonly) AVCaptureSession* captureSession; 56 @property(nonatomic, readonly) AVCaptureSession* captureSession;
57 @property(nonatomic, readonly) dispatch_queue_t captureSessionQueue;
57 @property(nonatomic, readonly) BOOL isRunning; 58 @property(nonatomic, readonly) BOOL isRunning;
58 @property(nonatomic, assign) BOOL useBackCamera; // Defaults to NO. 59 @property(nonatomic, assign) BOOL useBackCamera; // Defaults to NO.
59 60
60 // We keep a pointer back to AVFoundationVideoCapturer to make callbacks on it 61 // We keep a pointer back to AVFoundationVideoCapturer to make callbacks on it
61 // when we receive frames. This is safe because this object should be owned by 62 // when we receive frames. This is safe because this object should be owned by
62 // it. 63 // it.
63 - (instancetype)initWithCapturer:(webrtc::AVFoundationVideoCapturer*)capturer; 64 - (instancetype)initWithCapturer:(webrtc::AVFoundationVideoCapturer*)capturer;
64 - (void)startCaptureAsync; 65 - (void)startCaptureAsync;
65 - (void)stopCaptureAsync; 66 - (void)stopCaptureAsync;
66 67
(...skipping 43 matching lines...)
110 } 111 }
111 return self; 112 return self;
112 } 113 }
113 114
114 - (void)dealloc { 115 - (void)dealloc {
115 [self stopCaptureAsync]; 116 [self stopCaptureAsync];
116 [[NSNotificationCenter defaultCenter] removeObserver:self]; 117 [[NSNotificationCenter defaultCenter] removeObserver:self];
117 _capturer = nullptr; 118 _capturer = nullptr;
118 } 119 }
119 120
121 - (dispatch_queue_t)captureSessionQueue {
122 return kBackgroundQueue;
123 }
124
120 - (void)setUseBackCamera:(BOOL)useBackCamera { 125 - (void)setUseBackCamera:(BOOL)useBackCamera {
121 if (_useBackCamera == useBackCamera) { 126 if (_useBackCamera == useBackCamera) {
122 return; 127 return;
123 } 128 }
124 _useBackCamera = useBackCamera; 129 _useBackCamera = useBackCamera;
125 [self updateSessionInput]; 130 [self updateSessionInput];
126 } 131 }
127 132
128 - (void)startCaptureAsync { 133 - (void)startCaptureAsync {
129 if (_isRunning) { 134 if (_isRunning) {
(...skipping 234 matching lines...)
364 } 369 }
365 370
366 void AVFoundationVideoCapturer::SetUseBackCamera(bool useBackCamera) { 371 void AVFoundationVideoCapturer::SetUseBackCamera(bool useBackCamera) {
367 _capturer.useBackCamera = useBackCamera; 372 _capturer.useBackCamera = useBackCamera;
368 } 373 }
369 374
370 bool AVFoundationVideoCapturer::GetUseBackCamera() const { 375 bool AVFoundationVideoCapturer::GetUseBackCamera() const {
371 return _capturer.useBackCamera; 376 return _capturer.useBackCamera;
372 } 377 }
373 378
379 dispatch_queue_t AVFoundationVideoCapturer::GetCaptureSessionQueue() {
380 return _capturer.captureSessionQueue;
381 }
382
374 void AVFoundationVideoCapturer::CaptureSampleBuffer( 383 void AVFoundationVideoCapturer::CaptureSampleBuffer(
375 CMSampleBufferRef sampleBuffer) { 384 CMSampleBufferRef sampleBuffer) {
376 if (CMSampleBufferGetNumSamples(sampleBuffer) != 1 || 385 if (CMSampleBufferGetNumSamples(sampleBuffer) != 1 ||
377 !CMSampleBufferIsValid(sampleBuffer) || 386 !CMSampleBufferIsValid(sampleBuffer) ||
378 !CMSampleBufferDataIsReady(sampleBuffer)) { 387 !CMSampleBufferDataIsReady(sampleBuffer)) {
379 return; 388 return;
380 } 389 }
381 390
382 CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer); 391 CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
383 if (imageBuffer == NULL) { 392 if (imageBuffer == NULL) {
(...skipping 54 matching lines...)
438 447
439 void AVFoundationVideoCapturer::SignalFrameCapturedOnStartThread( 448 void AVFoundationVideoCapturer::SignalFrameCapturedOnStartThread(
440 const cricket::CapturedFrame* frame) { 449 const cricket::CapturedFrame* frame) {
441 RTC_DCHECK(_startThread->IsCurrent()); 450 RTC_DCHECK(_startThread->IsCurrent());
442 // This will call a superclass method that will perform the frame conversion 451 // This will call a superclass method that will perform the frame conversion
443 // to I420. 452 // to I420.
444 SignalFrameCaptured(this, frame); 453 SignalFrameCaptured(this, frame);
445 } 454 }
446 455
447 } // namespace webrtc 456 } // namespace webrtc
OLDNEW

Powered by Google App Engine