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 #import "NSString+StdString.h" | 13 #import "NSString+StdString.h" |
14 #import "RTCAudioSource+Private.h" | 14 #import "RTCAudioSource+Private.h" |
15 #import "RTCAudioTrack+Private.h" | 15 #import "RTCAudioTrack+Private.h" |
16 #import "RTCMediaConstraints+Private.h" | 16 #import "RTCMediaConstraints+Private.h" |
17 #import "RTCMediaStream+Private.h" | 17 #import "RTCMediaStream+Private.h" |
18 #import "RTCPeerConnection+Private.h" | 18 #import "RTCPeerConnection+Private.h" |
19 #import "RTCVideoSource+Private.h" | 19 #import "RTCVideoSource+Private.h" |
20 #import "RTCVideoTrack+Private.h" | 20 #import "RTCVideoTrack+Private.h" |
21 #import "RTCAVFoundationVideoSource+Private.h" | 21 #import "RTCAVFoundationVideoSource+Private.h" |
22 #import "WebRTC/RTCLogging.h" | 22 #import "WebRTC/RTCLogging.h" |
23 | 23 |
24 #include "Video/objcvideotracksource.h" | 24 #include "Video/objcvideotracksource.h" |
25 #include "VideoToolbox/videocodecfactory.h" | 25 #include "VideoToolbox/videocodecfactory.h" |
26 #include "webrtc/api/videosourceproxy.h" | 26 #include "webrtc/api/videosourceproxy.h" |
27 | 27 |
28 @implementation RTCPeerConnectionFactory { | 28 @implementation RTCPeerConnectionFactory |
29 std::unique_ptr<rtc::Thread> _networkThread; | |
30 std::unique_ptr<rtc::Thread> _workerThread; | |
31 std::unique_ptr<rtc::Thread> _signalingThread; | |
32 BOOL _hasStartedAecDump; | |
33 } | |
34 | 29 |
35 @synthesize nativeFactory = _nativeFactory; | 30 @synthesize nativeFactory = _nativeFactory; |
36 | 31 |
37 - (instancetype)init { | 32 - (RTCPeerConnection *)peerConnectionWithConfiguration:(RTCConfiguration *)confi guration |
tkchin_webrtc
2017/06/20 21:51:24
designated initializer *must* be implemented in th
Taylor Brandstetter
2017/06/25 17:41:56
If I understand designated initializers correctly,
| |
38 if ((self = [super init])) { | 33 constraints:(RTCMediaConstraints *)co nstraints |
39 _networkThread = rtc::Thread::CreateWithSocketServer(); | 34 delegate: |
40 BOOL result = _networkThread->Start(); | 35 (nullable id<RTCPeerConnection Delegate>)delegate { |
41 NSAssert(result, @"Failed to start network thread."); | 36 return [[RTCPeerConnection alloc] initWithFactory:self |
42 | 37 configuration:configuration |
43 _workerThread = rtc::Thread::Create(); | 38 constraints:constraints |
44 result = _workerThread->Start(); | 39 delegate:delegate]; |
45 NSAssert(result, @"Failed to start worker thread."); | |
46 | |
47 _signalingThread = rtc::Thread::Create(); | |
48 result = _signalingThread->Start(); | |
49 NSAssert(result, @"Failed to start signaling thread."); | |
50 | |
51 const auto encoder_factory = new webrtc::VideoToolboxVideoEncoderFactory(); | |
52 const auto decoder_factory = new webrtc::VideoToolboxVideoDecoderFactory(); | |
53 | |
54 // Ownership of encoder/decoder factories is passed on to the | |
55 // peerconnectionfactory, that handles deleting them. | |
56 _nativeFactory = webrtc::CreatePeerConnectionFactory( | |
57 _networkThread.get(), _workerThread.get(), _signalingThread.get(), | |
58 nullptr, encoder_factory, decoder_factory); | |
59 NSAssert(_nativeFactory, @"Failed to initialize PeerConnectionFactory!"); | |
60 } | |
61 return self; | |
62 } | 40 } |
63 | 41 |
64 - (RTCAudioSource *)audioSourceWithConstraints:(nullable RTCMediaConstraints *)c onstraints { | 42 - (RTCAudioSource *)audioSourceWithConstraints:(nullable RTCMediaConstraints *)c onstraints { |
65 std::unique_ptr<webrtc::MediaConstraints> nativeConstraints; | 43 std::unique_ptr<webrtc::MediaConstraints> nativeConstraints; |
66 if (constraints) { | 44 if (constraints) { |
67 nativeConstraints = constraints.nativeConstraints; | 45 nativeConstraints = constraints.nativeConstraints; |
68 } | 46 } |
69 rtc::scoped_refptr<webrtc::AudioSourceInterface> source = | 47 rtc::scoped_refptr<webrtc::AudioSourceInterface> source = |
70 _nativeFactory->CreateAudioSource(nativeConstraints.get()); | 48 _nativeFactory->CreateAudioSource(nativeConstraints.get()); |
71 return [[RTCAudioSource alloc] initWithNativeAudioSource:source]; | 49 return [[RTCAudioSource alloc] initWithNativeAudioSource:source]; |
72 } | 50 } |
73 | 51 |
74 - (RTCAudioTrack *)audioTrackWithTrackId:(NSString *)trackId { | 52 - (RTCAudioTrack *)audioTrackWithTrackId:(NSString *)trackId { |
75 RTCAudioSource *audioSource = [self audioSourceWithConstraints:nil]; | 53 RTCAudioSource *audioSource = [self audioSourceWithConstraints:nil]; |
76 return [self audioTrackWithSource:audioSource trackId:trackId]; | 54 return [self audioTrackWithSource:audioSource trackId:trackId]; |
77 } | 55 } |
78 | 56 |
79 - (RTCAudioTrack *)audioTrackWithSource:(RTCAudioSource *)source | 57 - (RTCAudioTrack *)audioTrackWithSource:(RTCAudioSource *)source trackId:(NSStri ng *)trackId { |
80 trackId:(NSString *)trackId { | 58 return [[RTCAudioTrack alloc] initWithFactory:self source:source trackId:track Id]; |
81 return [[RTCAudioTrack alloc] initWithFactory:self | |
82 source:source | |
83 trackId:trackId]; | |
84 } | |
85 | |
86 - (RTCAVFoundationVideoSource *)avFoundationVideoSourceWithConstraints: | |
87 (nullable RTCMediaConstraints *)constraints { | |
88 return [[RTCAVFoundationVideoSource alloc] initWithFactory:self | |
89 constraints:constraints]; | |
90 } | |
91 | |
92 - (RTCVideoSource *)videoSource { | |
93 rtc::scoped_refptr<webrtc::ObjcVideoTrackSource> objcVideoTrackSource( | |
94 new rtc::RefCountedObject<webrtc::ObjcVideoTrackSource>()); | |
95 return [[RTCVideoSource alloc] | |
96 initWithNativeVideoSource:webrtc::VideoTrackSourceProxy::Create(_signaling Thread.get(), | |
97 _workerThr ead.get(), | |
98 objcVideoT rackSource)]; | |
99 } | |
100 | |
101 - (RTCVideoTrack *)videoTrackWithSource:(RTCVideoSource *)source | |
102 trackId:(NSString *)trackId { | |
103 return [[RTCVideoTrack alloc] initWithFactory:self | |
104 source:source | |
105 trackId:trackId]; | |
106 } | |
107 | |
108 - (RTCMediaStream *)mediaStreamWithStreamId:(NSString *)streamId { | |
109 return [[RTCMediaStream alloc] initWithFactory:self | |
110 streamId:streamId]; | |
111 } | |
112 | |
113 - (RTCPeerConnection *)peerConnectionWithConfiguration: | |
114 (RTCConfiguration *)configuration | |
115 constraints: | |
116 (RTCMediaConstraints *)constraints | |
117 delegate: | |
118 (nullable id<RTCPeerConnectionDelegate>)delegate { | |
119 return [[RTCPeerConnection alloc] initWithFactory:self | |
120 configuration:configuration | |
121 constraints:constraints | |
122 delegate:delegate]; | |
123 } | 59 } |
124 | 60 |
125 - (BOOL)startAecDumpWithFilePath:(NSString *)filePath | 61 - (BOOL)startAecDumpWithFilePath:(NSString *)filePath |
126 maxSizeInBytes:(int64_t)maxSizeInBytes { | 62 maxSizeInBytes:(int64_t)maxSizeInBytes { |
127 RTC_DCHECK(filePath.length); | 63 RTC_DCHECK(filePath.length); |
128 RTC_DCHECK_GT(maxSizeInBytes, 0); | 64 RTC_DCHECK_GT(maxSizeInBytes, 0); |
129 | 65 |
130 if (_hasStartedAecDump) { | 66 if (_hasStartedAecDump) { |
131 RTCLogError(@"Aec dump already started."); | 67 RTCLogError(@"Aec dump already started."); |
132 return NO; | 68 return NO; |
133 } | 69 } |
134 int fd = open(filePath.UTF8String, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_I WUSR); | 70 int fd = open(filePath.UTF8String, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_I WUSR); |
135 if (fd < 0) { | 71 if (fd < 0) { |
136 RTCLogError(@"Error opening file: %@. Error: %d", filePath, errno); | 72 RTCLogError(@"Error opening file: %@. Error: %d", filePath, errno); |
137 return NO; | 73 return NO; |
138 } | 74 } |
139 _hasStartedAecDump = _nativeFactory->StartAecDump(fd, maxSizeInBytes); | 75 _hasStartedAecDump = _nativeFactory->StartAecDump(fd, maxSizeInBytes); |
140 return _hasStartedAecDump; | 76 return _hasStartedAecDump; |
141 } | 77 } |
142 | 78 |
143 - (void)stopAecDump { | 79 - (void)stopAecDump { |
144 _nativeFactory->StopAecDump(); | 80 _nativeFactory->StopAecDump(); |
145 _hasStartedAecDump = NO; | 81 _hasStartedAecDump = NO; |
146 } | 82 } |
147 | 83 |
148 @end | 84 @end |
OLD | NEW |