blob: 96c5c3649a4a13f9ed4f9ee2504c068d643831b6 [file] [log] [blame]
Jon Hjelle7ac8bab2016-01-21 11:44:55 -08001/*
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
tkchin9eeb6242016-04-27 01:54:20 -070013#import "RTCMediaConstraints+Private.h"
14#import "RTCPeerConnectionFactory+Private.h"
15#import "RTCVideoSource+Private.h"
Jon Hjelle7ac8bab2016-01-21 11:44:55 -080016
nisse2ded9b12016-04-08 02:23:55 -070017@implementation RTCAVFoundationVideoSource {
18 webrtc::AVFoundationVideoCapturer *_capturer;
19}
Jon Hjelle7ac8bab2016-01-21 11:44:55 -080020
21- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory
22 constraints:(RTCMediaConstraints *)constraints {
23 NSParameterAssert(factory);
nisse2ded9b12016-04-08 02:23:55 -070024 // 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();
perkja3ede6c2016-03-08 01:27:48 +010028 rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> source =
29 factory.nativeFactory->CreateVideoSource(
nisse2ded9b12016-04-08 02:23:55 -070030 _capturer, constraints.nativeConstraints.get());
31
Jon Hjelle7ac8bab2016-01-21 11:44:55 -080032 return [super initWithNativeVideoSource:source];
33}
34
kthelgason2bc324c2016-12-01 01:36:16 -080035- (void)adaptOutputFormatToWidth:(int)width
36 height:(int)height
37 fps:(int)fps {
38 self.capturer->AdaptOutputFormat(width, height, fps);
39}
40
hjona1cf3662016-03-14 20:55:22 -070041- (BOOL)canUseBackCamera {
42 return self.capturer->CanUseBackCamera();
43}
44
Jon Hjelle7ac8bab2016-01-21 11:44:55 -080045- (BOOL)useBackCamera {
46 return self.capturer->GetUseBackCamera();
47}
48
49- (void)setUseBackCamera:(BOOL)useBackCamera {
50 self.capturer->SetUseBackCamera(useBackCamera);
51}
52
53- (AVCaptureSession *)captureSession {
54 return self.capturer->GetCaptureSession();
55}
56
57- (webrtc::AVFoundationVideoCapturer *)capturer {
nisse2ded9b12016-04-08 02:23:55 -070058 return _capturer;
Jon Hjelle7ac8bab2016-01-21 11:44:55 -080059}
60
61@end