Jon Hjelle | 7ac8bab | 2016-01-21 11:44:55 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #import "RTCAVFoundationVideoSource+Private.h" |
| 12 | |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 13 | #import "RTCMediaConstraints+Private.h" |
| 14 | #import "RTCPeerConnectionFactory+Private.h" |
| 15 | #import "RTCVideoSource+Private.h" |
Jon Hjelle | 7ac8bab | 2016-01-21 11:44:55 -0800 | [diff] [blame] | 16 | |
nisse | 2ded9b1 | 2016-04-08 02:23:55 -0700 | [diff] [blame] | 17 | @implementation RTCAVFoundationVideoSource { |
| 18 | webrtc::AVFoundationVideoCapturer *_capturer; |
| 19 | } |
Jon Hjelle | 7ac8bab | 2016-01-21 11:44:55 -0800 | [diff] [blame] | 20 | |
| 21 | - (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory |
| 22 | constraints:(RTCMediaConstraints *)constraints { |
| 23 | NSParameterAssert(factory); |
nisse | 2ded9b1 | 2016-04-08 02:23:55 -0700 | [diff] [blame] | 24 | // We pass ownership of the capturer to the source, but since we own |
| 25 | // the source, it should be ok to keep a raw pointer to the |
| 26 | // capturer. |
| 27 | _capturer = new webrtc::AVFoundationVideoCapturer(); |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 28 | rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> source = |
| 29 | factory.nativeFactory->CreateVideoSource( |
nisse | 2ded9b1 | 2016-04-08 02:23:55 -0700 | [diff] [blame] | 30 | _capturer, constraints.nativeConstraints.get()); |
| 31 | |
Jon Hjelle | 7ac8bab | 2016-01-21 11:44:55 -0800 | [diff] [blame] | 32 | return [super initWithNativeVideoSource:source]; |
| 33 | } |
| 34 | |
hjon | a1cf366 | 2016-03-14 20:55:22 -0700 | [diff] [blame] | 35 | - (BOOL)canUseBackCamera { |
| 36 | return self.capturer->CanUseBackCamera(); |
| 37 | } |
| 38 | |
Jon Hjelle | 7ac8bab | 2016-01-21 11:44:55 -0800 | [diff] [blame] | 39 | - (BOOL)useBackCamera { |
| 40 | return self.capturer->GetUseBackCamera(); |
| 41 | } |
| 42 | |
| 43 | - (void)setUseBackCamera:(BOOL)useBackCamera { |
| 44 | self.capturer->SetUseBackCamera(useBackCamera); |
| 45 | } |
| 46 | |
| 47 | - (AVCaptureSession *)captureSession { |
| 48 | return self.capturer->GetCaptureSession(); |
| 49 | } |
| 50 | |
| 51 | - (webrtc::AVFoundationVideoCapturer *)capturer { |
nisse | 2ded9b1 | 2016-04-08 02:23:55 -0700 | [diff] [blame] | 52 | return _capturer; |
Jon Hjelle | 7ac8bab | 2016-01-21 11:44:55 -0800 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | @end |