| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #import "RTCPeerConnectionFactory+Private.h" | 11 #import "RTCPeerConnectionFactory+Private.h" |
| 12 | 12 |
| 13 #include <memory> |
| 14 |
| 13 #import "NSString+StdString.h" | 15 #import "NSString+StdString.h" |
| 14 #import "RTCAVFoundationVideoSource+Private.h" | 16 #import "RTCAVFoundationVideoSource+Private.h" |
| 15 #import "RTCAudioTrack+Private.h" | 17 #import "RTCAudioTrack+Private.h" |
| 16 #import "RTCMediaStream+Private.h" | 18 #import "RTCMediaStream+Private.h" |
| 17 #import "RTCPeerConnection+Private.h" | 19 #import "RTCPeerConnection+Private.h" |
| 18 #import "RTCVideoSource+Private.h" | 20 #import "RTCVideoSource+Private.h" |
| 19 #import "RTCVideoTrack+Private.h" | 21 #import "RTCVideoTrack+Private.h" |
| 22 #import "WebRTC/RTCLogging.h" |
| 20 | 23 |
| 21 #include <memory> | 24 #include "webrtc/base/checks.h" |
| 22 | 25 |
| 23 @implementation RTCPeerConnectionFactory { | 26 @implementation RTCPeerConnectionFactory { |
| 24 std::unique_ptr<rtc::Thread> _networkThread; | 27 std::unique_ptr<rtc::Thread> _networkThread; |
| 25 std::unique_ptr<rtc::Thread> _workerThread; | 28 std::unique_ptr<rtc::Thread> _workerThread; |
| 26 std::unique_ptr<rtc::Thread> _signalingThread; | 29 std::unique_ptr<rtc::Thread> _signalingThread; |
| 30 BOOL _hasStartedRtcEventLog; |
| 27 } | 31 } |
| 28 | 32 |
| 29 @synthesize nativeFactory = _nativeFactory; | 33 @synthesize nativeFactory = _nativeFactory; |
| 30 | 34 |
| 31 - (instancetype)init { | 35 - (instancetype)init { |
| 32 if ((self = [super init])) { | 36 if ((self = [super init])) { |
| 33 _networkThread = rtc::Thread::CreateWithSocketServer(); | 37 _networkThread = rtc::Thread::CreateWithSocketServer(); |
| 34 BOOL result = _networkThread->Start(); | 38 BOOL result = _networkThread->Start(); |
| 35 NSAssert(result, @"Failed to start network thread."); | 39 NSAssert(result, @"Failed to start network thread."); |
| 36 | 40 |
| 37 _workerThread = rtc::Thread::Create(); | 41 _workerThread = rtc::Thread::Create(); |
| 38 result = _workerThread->Start(); | 42 result = _workerThread->Start(); |
| 39 NSAssert(result, @"Failed to start worker thread."); | 43 NSAssert(result, @"Failed to start worker thread."); |
| 40 | 44 |
| 41 _signalingThread = rtc::Thread::Create(); | 45 _signalingThread = rtc::Thread::Create(); |
| 42 result = _signalingThread->Start(); | 46 result = _signalingThread->Start(); |
| 43 NSAssert(result, @"Failed to start signaling thread."); | 47 NSAssert(result, @"Failed to start signaling thread."); |
| 44 | 48 |
| 45 _nativeFactory = webrtc::CreatePeerConnectionFactory( | 49 _nativeFactory = webrtc::CreatePeerConnectionFactory( |
| 46 _networkThread.get(), _workerThread.get(), _signalingThread.get(), | 50 _networkThread.get(), _workerThread.get(), _signalingThread.get(), |
| 47 nullptr, nullptr, nullptr); | 51 nullptr, nullptr, nullptr); |
| 48 NSAssert(_nativeFactory, @"Failed to initialize PeerConnectionFactory!"); | 52 NSAssert(_nativeFactory, @"Failed to initialize PeerConnectionFactory!"); |
| 49 } | 53 } |
| 50 return self; | 54 return self; |
| 51 } | 55 } |
| 52 | 56 |
| 57 - (BOOL)startRtcEventLogWithFilePath:(NSString *)filePath |
| 58 maxSizeInBytes:(int64_t)maxSizeInBytes { |
| 59 RTC_DCHECK(filePath.length); |
| 60 RTC_DCHECK_GT(maxSizeInBytes, 0); |
| 61 RTC_DCHECK(!_hasStartedRtcEventLog); |
| 62 if (_hasStartedRtcEventLog) { |
| 63 RTCLogError(@"Event logging already started."); |
| 64 return NO; |
| 65 } |
| 66 int fd = open(filePath.UTF8String, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_I
WUSR); |
| 67 if (fd < 0) { |
| 68 RTCLogError(@"Error opening file: %@. Error: %d", filePath, errno); |
| 69 return NO; |
| 70 } |
| 71 _hasStartedRtcEventLog = _nativeFactory->StartRtcEventLog(fd, maxSizeInBytes); |
| 72 return _hasStartedRtcEventLog; |
| 73 } |
| 74 |
| 75 - (void)stopRtcEventLog { |
| 76 _nativeFactory->StopRtcEventLog(); |
| 77 _hasStartedRtcEventLog = NO; |
| 78 } |
| 79 |
| 53 - (RTCAVFoundationVideoSource *)avFoundationVideoSourceWithConstraints: | 80 - (RTCAVFoundationVideoSource *)avFoundationVideoSourceWithConstraints: |
| 54 (nullable RTCMediaConstraints *)constraints { | 81 (nullable RTCMediaConstraints *)constraints { |
| 55 return [[RTCAVFoundationVideoSource alloc] initWithFactory:self | 82 return [[RTCAVFoundationVideoSource alloc] initWithFactory:self |
| 56 constraints:constraints]; | 83 constraints:constraints]; |
| 57 } | 84 } |
| 58 | 85 |
| 59 - (RTCAudioTrack *)audioTrackWithTrackId:(NSString *)trackId { | 86 - (RTCAudioTrack *)audioTrackWithTrackId:(NSString *)trackId { |
| 60 return [[RTCAudioTrack alloc] initWithFactory:self | 87 return [[RTCAudioTrack alloc] initWithFactory:self |
| 61 trackId:trackId]; | 88 trackId:trackId]; |
| 62 } | 89 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 79 (RTCMediaConstraints *)constraints | 106 (RTCMediaConstraints *)constraints |
| 80 delegate: | 107 delegate: |
| 81 (nullable id<RTCPeerConnectionDelegate>)delegate { | 108 (nullable id<RTCPeerConnectionDelegate>)delegate { |
| 82 return [[RTCPeerConnection alloc] initWithFactory:self | 109 return [[RTCPeerConnection alloc] initWithFactory:self |
| 83 configuration:configuration | 110 configuration:configuration |
| 84 constraints:constraints | 111 constraints:constraints |
| 85 delegate:delegate]; | 112 delegate:delegate]; |
| 86 } | 113 } |
| 87 | 114 |
| 88 @end | 115 @end |
| OLD | NEW |