| 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 "RTCAVFoundationVideoSource+Private.h" | 11 #import "RTCAVFoundationVideoSource+Private.h" |
| 12 | 12 |
| 13 #import "webrtc/api/objc/RTCMediaConstraints+Private.h" | 13 #import "webrtc/api/objc/RTCMediaConstraints+Private.h" |
| 14 #import "webrtc/api/objc/RTCPeerConnectionFactory+Private.h" | 14 #import "webrtc/api/objc/RTCPeerConnectionFactory+Private.h" |
| 15 #import "webrtc/api/objc/RTCVideoSource+Private.h" | 15 #import "webrtc/api/objc/RTCVideoSource+Private.h" |
| 16 | 16 |
| 17 @implementation RTCAVFoundationVideoSource | 17 @implementation RTCAVFoundationVideoSource { |
| 18 webrtc::AVFoundationVideoCapturer *_capturer; |
| 19 } |
| 18 | 20 |
| 19 - (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory | 21 - (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory |
| 20 constraints:(RTCMediaConstraints *)constraints { | 22 constraints:(RTCMediaConstraints *)constraints { |
| 21 NSParameterAssert(factory); | 23 NSParameterAssert(factory); |
| 22 rtc::scoped_ptr<webrtc::AVFoundationVideoCapturer> capturer; | 24 // We pass ownership of the capturer to the source, but since we own |
| 23 capturer.reset(new webrtc::AVFoundationVideoCapturer()); | 25 // the source, it should be ok to keep a raw pointer to the |
| 26 // capturer. |
| 27 _capturer = new webrtc::AVFoundationVideoCapturer(); |
| 24 rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> source = | 28 rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> source = |
| 25 factory.nativeFactory->CreateVideoSource( | 29 factory.nativeFactory->CreateVideoSource( |
| 26 capturer.release(), constraints.nativeConstraints.get()); | 30 _capturer, constraints.nativeConstraints.get()); |
| 31 |
| 27 return [super initWithNativeVideoSource:source]; | 32 return [super initWithNativeVideoSource:source]; |
| 28 } | 33 } |
| 29 | 34 |
| 30 - (BOOL)canUseBackCamera { | 35 - (BOOL)canUseBackCamera { |
| 31 return self.capturer->CanUseBackCamera(); | 36 return self.capturer->CanUseBackCamera(); |
| 32 } | 37 } |
| 33 | 38 |
| 34 - (BOOL)useBackCamera { | 39 - (BOOL)useBackCamera { |
| 35 return self.capturer->GetUseBackCamera(); | 40 return self.capturer->GetUseBackCamera(); |
| 36 } | 41 } |
| 37 | 42 |
| 38 - (void)setUseBackCamera:(BOOL)useBackCamera { | 43 - (void)setUseBackCamera:(BOOL)useBackCamera { |
| 39 self.capturer->SetUseBackCamera(useBackCamera); | 44 self.capturer->SetUseBackCamera(useBackCamera); |
| 40 } | 45 } |
| 41 | 46 |
| 42 - (AVCaptureSession *)captureSession { | 47 - (AVCaptureSession *)captureSession { |
| 43 return self.capturer->GetCaptureSession(); | 48 return self.capturer->GetCaptureSession(); |
| 44 } | 49 } |
| 45 | 50 |
| 46 - (webrtc::AVFoundationVideoCapturer *)capturer { | 51 - (webrtc::AVFoundationVideoCapturer *)capturer { |
| 47 cricket::VideoCapturer *capturer = self.nativeVideoSource->GetVideoCapturer(); | 52 return _capturer; |
| 48 // This should be safe because no one should have changed the underlying video | |
| 49 // source. | |
| 50 webrtc::AVFoundationVideoCapturer *foundationCapturer = | |
| 51 static_cast<webrtc::AVFoundationVideoCapturer *>(capturer); | |
| 52 return foundationCapturer; | |
| 53 } | 53 } |
| 54 | 54 |
| 55 @end | 55 @end |
| OLD | NEW |