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