blob: 1005c7dfa122c6528adc6b46cfb14644c430fc5f [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
13#import "webrtc/api/objc/RTCMediaConstraints+Private.h"
14#import "webrtc/api/objc/RTCPeerConnectionFactory+Private.h"
15#import "webrtc/api/objc/RTCVideoSource+Private.h"
16
17@implementation RTCAVFoundationVideoSource
18
19- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory
20 constraints:(RTCMediaConstraints *)constraints {
21 NSParameterAssert(factory);
22 rtc::scoped_ptr<webrtc::AVFoundationVideoCapturer> capturer;
23 capturer.reset(new webrtc::AVFoundationVideoCapturer());
perkja3ede6c2016-03-08 01:27:48 +010024 rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> source =
25 factory.nativeFactory->CreateVideoSource(
26 capturer.release(), constraints.nativeConstraints.get());
Jon Hjelle7ac8bab2016-01-21 11:44:55 -080027 return [super initWithNativeVideoSource:source];
28}
29
hjona1cf3662016-03-14 20:55:22 -070030- (BOOL)canUseBackCamera {
31 return self.capturer->CanUseBackCamera();
32}
33
Jon Hjelle7ac8bab2016-01-21 11:44:55 -080034- (BOOL)useBackCamera {
35 return self.capturer->GetUseBackCamera();
36}
37
38- (void)setUseBackCamera:(BOOL)useBackCamera {
39 self.capturer->SetUseBackCamera(useBackCamera);
40}
41
42- (AVCaptureSession *)captureSession {
43 return self.capturer->GetCaptureSession();
44}
45
46- (webrtc::AVFoundationVideoCapturer *)capturer {
47 cricket::VideoCapturer *capturer = self.nativeVideoSource->GetVideoCapturer();
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}
54
55@end