blob: a7f9c594dc84535ff3a9d94d66132e2279a08880 [file] [log] [blame]
Jon Hjelleda99da82016-01-20 13:40:30 -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 "RTCPeerConnectionFactory.h"
12
Tze Kwang Chinf3cb49f2016-03-22 10:57:40 -070013#if defined(WEBRTC_IOS)
14#import "webrtc/api/objc/RTCAVFoundationVideoSource+Private.h"
15#endif
16#import "webrtc/api/objc/RTCAudioTrack+Private.h"
17#import "webrtc/api/objc/RTCMediaStream+Private.h"
18#import "webrtc/api/objc/RTCPeerConnection+Private.h"
Jon Hjelleda99da82016-01-20 13:40:30 -080019#import "webrtc/api/objc/RTCPeerConnectionFactory+Private.h"
Tze Kwang Chinf3cb49f2016-03-22 10:57:40 -070020#import "webrtc/api/objc/RTCVideoSource+Private.h"
21#import "webrtc/api/objc/RTCVideoTrack+Private.h"
22#import "webrtc/base/objc/NSString+StdString.h"
Jon Hjelleda99da82016-01-20 13:40:30 -080023
24@implementation RTCPeerConnectionFactory {
25 rtc::scoped_ptr<rtc::Thread> _signalingThread;
26 rtc::scoped_ptr<rtc::Thread> _workerThread;
27}
28
29@synthesize nativeFactory = _nativeFactory;
30
31- (instancetype)init {
32 if ((self = [super init])) {
33 _signalingThread.reset(new rtc::Thread());
34 BOOL result = _signalingThread->Start();
35 NSAssert(result, @"Failed to start signaling thread.");
36 _workerThread.reset(new rtc::Thread());
37 result = _workerThread->Start();
38 NSAssert(result, @"Failed to start worker thread.");
39
40 _nativeFactory = webrtc::CreatePeerConnectionFactory(
41 _workerThread.get(), _signalingThread.get(), nullptr, nullptr, nullptr);
42 NSAssert(_nativeFactory, @"Failed to initialize PeerConnectionFactory!");
43 }
44 return self;
45}
46
Tze Kwang Chinf3cb49f2016-03-22 10:57:40 -070047#if defined(WEBRTC_IOS)
48- (RTCAVFoundationVideoSource *)avFoundationVideoSourceWithConstraints:
49 (nullable RTCMediaConstraints *)constraints {
50 return [[RTCAVFoundationVideoSource alloc] initWithFactory:self
51 constraints:constraints];
52}
53#endif
54
55- (RTCAudioTrack *)audioTrackWithTrackId:(NSString *)trackId {
56 return [[RTCAudioTrack alloc] initWithFactory:self
57 trackId:trackId];
58}
59
60- (RTCVideoTrack *)videoTrackWithSource:(RTCVideoSource *)source
61 trackId:(NSString *)trackId {
62 return [[RTCVideoTrack alloc] initWithFactory:self
63 source:source
64 trackId:trackId];
65}
66
67- (RTCMediaStream *)mediaStreamWithStreamId:(NSString *)streamId {
68 return [[RTCMediaStream alloc] initWithFactory:self
69 streamId:streamId];
70}
71
72- (RTCPeerConnection *)peerConnectionWithConfiguration:
73 (RTCConfiguration *)configuration
74 constraints:
75 (RTCMediaConstraints *)constraints
76 delegate:
77 (nullable id<RTCPeerConnectionDelegate>)delegate {
78 return [[RTCPeerConnection alloc] initWithFactory:self
79 configuration:configuration
80 constraints:constraints
81 delegate:delegate];
82}
83
Jon Hjelleda99da82016-01-20 13:40:30 -080084@end