Jon Hjelle | da99da8 | 2016-01-20 13:40:30 -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 "RTCPeerConnectionFactory.h" |
| 12 | |
Tze Kwang Chin | f3cb49f | 2016-03-22 10:57:40 -0700 | [diff] [blame^] | 13 | #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 Hjelle | da99da8 | 2016-01-20 13:40:30 -0800 | [diff] [blame] | 19 | #import "webrtc/api/objc/RTCPeerConnectionFactory+Private.h" |
Tze Kwang Chin | f3cb49f | 2016-03-22 10:57:40 -0700 | [diff] [blame^] | 20 | #import "webrtc/api/objc/RTCVideoSource+Private.h" |
| 21 | #import "webrtc/api/objc/RTCVideoTrack+Private.h" |
| 22 | #import "webrtc/base/objc/NSString+StdString.h" |
Jon Hjelle | da99da8 | 2016-01-20 13:40:30 -0800 | [diff] [blame] | 23 | |
| 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 Chin | f3cb49f | 2016-03-22 10:57:40 -0700 | [diff] [blame^] | 47 | #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 Hjelle | da99da8 | 2016-01-20 13:40:30 -0800 | [diff] [blame] | 84 | @end |