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" |
| 23 |
| 24 #include "webrtc/base/checks.h" |
20 | 25 |
21 @implementation RTCPeerConnectionFactory { | 26 @implementation RTCPeerConnectionFactory { |
22 std::unique_ptr<rtc::Thread> _networkThread; | 27 std::unique_ptr<rtc::Thread> _networkThread; |
23 std::unique_ptr<rtc::Thread> _workerThread; | 28 std::unique_ptr<rtc::Thread> _workerThread; |
24 std::unique_ptr<rtc::Thread> _signalingThread; | 29 std::unique_ptr<rtc::Thread> _signalingThread; |
| 30 BOOL _hasStartedRtcEventLog; |
25 } | 31 } |
26 | 32 |
27 @synthesize nativeFactory = _nativeFactory; | 33 @synthesize nativeFactory = _nativeFactory; |
28 | 34 |
29 - (instancetype)init { | 35 - (instancetype)init { |
30 if ((self = [super init])) { | 36 if ((self = [super init])) { |
31 _networkThread = rtc::Thread::CreateWithSocketServer(); | 37 _networkThread = rtc::Thread::CreateWithSocketServer(); |
32 BOOL result = _networkThread->Start(); | 38 BOOL result = _networkThread->Start(); |
33 NSAssert(result, @"Failed to start network thread."); | 39 NSAssert(result, @"Failed to start network thread."); |
34 | 40 |
35 _workerThread = rtc::Thread::Create(); | 41 _workerThread = rtc::Thread::Create(); |
36 result = _workerThread->Start(); | 42 result = _workerThread->Start(); |
37 NSAssert(result, @"Failed to start worker thread."); | 43 NSAssert(result, @"Failed to start worker thread."); |
38 | 44 |
39 _signalingThread = rtc::Thread::Create(); | 45 _signalingThread = rtc::Thread::Create(); |
40 result = _signalingThread->Start(); | 46 result = _signalingThread->Start(); |
41 NSAssert(result, @"Failed to start signaling thread."); | 47 NSAssert(result, @"Failed to start signaling thread."); |
42 | 48 |
43 _nativeFactory = webrtc::CreatePeerConnectionFactory( | 49 _nativeFactory = webrtc::CreatePeerConnectionFactory( |
44 _networkThread.get(), _workerThread.get(), _signalingThread.get(), | 50 _networkThread.get(), _workerThread.get(), _signalingThread.get(), |
45 nullptr, nullptr, nullptr); | 51 nullptr, nullptr, nullptr); |
46 NSAssert(_nativeFactory, @"Failed to initialize PeerConnectionFactory!"); | 52 NSAssert(_nativeFactory, @"Failed to initialize PeerConnectionFactory!"); |
47 } | 53 } |
48 return self; | 54 return self; |
49 } | 55 } |
50 | 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 |
51 - (RTCAVFoundationVideoSource *)avFoundationVideoSourceWithConstraints: | 80 - (RTCAVFoundationVideoSource *)avFoundationVideoSourceWithConstraints: |
52 (nullable RTCMediaConstraints *)constraints { | 81 (nullable RTCMediaConstraints *)constraints { |
53 return [[RTCAVFoundationVideoSource alloc] initWithFactory:self | 82 return [[RTCAVFoundationVideoSource alloc] initWithFactory:self |
54 constraints:constraints]; | 83 constraints:constraints]; |
55 } | 84 } |
56 | 85 |
57 - (RTCAudioTrack *)audioTrackWithTrackId:(NSString *)trackId { | 86 - (RTCAudioTrack *)audioTrackWithTrackId:(NSString *)trackId { |
58 return [[RTCAudioTrack alloc] initWithFactory:self | 87 return [[RTCAudioTrack alloc] initWithFactory:self |
59 trackId:trackId]; | 88 trackId:trackId]; |
60 } | 89 } |
(...skipping 16 matching lines...) Loading... |
77 (RTCMediaConstraints *)constraints | 106 (RTCMediaConstraints *)constraints |
78 delegate: | 107 delegate: |
79 (nullable id<RTCPeerConnectionDelegate>)delegate { | 108 (nullable id<RTCPeerConnectionDelegate>)delegate { |
80 return [[RTCPeerConnection alloc] initWithFactory:self | 109 return [[RTCPeerConnection alloc] initWithFactory:self |
81 configuration:configuration | 110 configuration:configuration |
82 constraints:constraints | 111 constraints:constraints |
83 delegate:delegate]; | 112 delegate:delegate]; |
84 } | 113 } |
85 | 114 |
86 @end | 115 @end |
OLD | NEW |