Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: webrtc/pc/peerconnectionfactory.cc

Issue 2854123003: Build WebRTC with data channel only. (Closed)
Patch Set: Revert the android changes. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2004 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 #include "webrtc/pc/peerconnectionfactory.h" 11 #include "webrtc/pc/peerconnectionfactory.h"
12 12
13 #include <utility> 13 #include <utility>
14 14
15 #include "webrtc/api/audio_codecs/builtin_audio_decoder_factory.h"
16 #include "webrtc/api/audio_codecs/builtin_audio_encoder_factory.h"
17 #include "webrtc/api/mediaconstraintsinterface.h" 15 #include "webrtc/api/mediaconstraintsinterface.h"
18 #include "webrtc/api/mediastreamproxy.h" 16 #include "webrtc/api/mediastreamproxy.h"
19 #include "webrtc/api/mediastreamtrackproxy.h" 17 #include "webrtc/api/mediastreamtrackproxy.h"
20 #include "webrtc/api/peerconnectionfactoryproxy.h" 18 #include "webrtc/api/peerconnectionfactoryproxy.h"
21 #include "webrtc/api/peerconnectionproxy.h" 19 #include "webrtc/api/peerconnectionproxy.h"
22 #include "webrtc/api/videosourceproxy.h" 20 #include "webrtc/api/videosourceproxy.h"
23 #include "webrtc/base/bind.h" 21 #include "webrtc/base/bind.h"
24 #include "webrtc/base/checks.h" 22 #include "webrtc/base/checks.h"
25 #include "webrtc/media/engine/webrtcmediaengine.h" 23 #include "webrtc/logging/rtc_event_log/rtc_event_log.h"
26 #include "webrtc/media/engine/webrtcvideodecoderfactory.h" 24 // Adding 'nogncheck' to disable the gn include headers check to support modular
27 #include "webrtc/media/engine/webrtcvideoencoderfactory.h" 25 // WebRTC build targets.
Taylor Brandstetter 2017/06/14 01:54:16 Really, the solution here is to put the interface
Zhi Huang 2017/06/14 06:57:01 Done.
28 #include "webrtc/modules/audio_device/include/audio_device.h" 26 #include "webrtc/media/engine/webrtcmediaengine.h" // nogncheck
27 #include "webrtc/media/engine/webrtcvideodecoderfactory.h" // nogncheck
28 #include "webrtc/media/engine/webrtcvideoencoderfactory.h" // nogncheck
29 #include "webrtc/modules/audio_device/include/audio_device.h" // nogncheck
29 #include "webrtc/p2p/base/basicpacketsocketfactory.h" 30 #include "webrtc/p2p/base/basicpacketsocketfactory.h"
30 #include "webrtc/p2p/client/basicportallocator.h" 31 #include "webrtc/p2p/client/basicportallocator.h"
31 #include "webrtc/pc/audiotrack.h" 32 #include "webrtc/pc/audiotrack.h"
32 #include "webrtc/pc/localaudiosource.h" 33 #include "webrtc/pc/localaudiosource.h"
33 #include "webrtc/pc/mediastream.h" 34 #include "webrtc/pc/mediastream.h"
34 #include "webrtc/pc/peerconnection.h" 35 #include "webrtc/pc/peerconnection.h"
35 #include "webrtc/pc/videocapturertracksource.h" 36 #include "webrtc/pc/videocapturertracksource.h"
36 #include "webrtc/pc/videotrack.h" 37 #include "webrtc/pc/videotrack.h"
37 38
38 namespace webrtc { 39 namespace webrtc {
39 40
40 rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory(
41 rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory,
42 rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory) {
43 rtc::scoped_refptr<PeerConnectionFactory> pc_factory(
44 new rtc::RefCountedObject<PeerConnectionFactory>(audio_encoder_factory,
45 audio_decoder_factory));
46
47 RTC_CHECK(rtc::Thread::Current() == pc_factory->signaling_thread());
48 // The signaling thread is the current thread so we can
49 // safely call Initialize directly.
50 if (!pc_factory->Initialize()) {
51 return nullptr;
52 }
53 return PeerConnectionFactoryProxy::Create(pc_factory->signaling_thread(),
54 pc_factory);
55 }
56
57 rtc::scoped_refptr<PeerConnectionFactoryInterface> 41 rtc::scoped_refptr<PeerConnectionFactoryInterface>
58 CreatePeerConnectionFactory() { 42 CreateModularPeerConnectionFactory(
59 return CreatePeerConnectionFactory(CreateBuiltinAudioEncoderFactory(),
60 CreateBuiltinAudioDecoderFactory());
61 }
62
63 rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory(
64 rtc::Thread* network_thread, 43 rtc::Thread* network_thread,
65 rtc::Thread* worker_thread, 44 rtc::Thread* worker_thread,
66 rtc::Thread* signaling_thread, 45 rtc::Thread* signaling_thread,
67 AudioDeviceModule* default_adm,
68 rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory,
69 rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory,
70 cricket::WebRtcVideoEncoderFactory* video_encoder_factory,
71 cricket::WebRtcVideoDecoderFactory* video_decoder_factory) {
72 return CreatePeerConnectionFactoryWithAudioMixer(
73 network_thread, worker_thread, signaling_thread, default_adm,
74 audio_encoder_factory, audio_decoder_factory, video_encoder_factory,
75 video_decoder_factory, nullptr);
76 }
77
78 rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory(
79 rtc::Thread* network_thread,
80 rtc::Thread* worker_thread,
81 rtc::Thread* signaling_thread,
82 AudioDeviceModule* default_adm,
83 cricket::WebRtcVideoEncoderFactory* encoder_factory,
84 cricket::WebRtcVideoDecoderFactory* decoder_factory) {
85 return CreatePeerConnectionFactoryWithAudioMixer(
86 network_thread, worker_thread, signaling_thread, default_adm,
87 encoder_factory, decoder_factory, nullptr);
88 }
89
90 rtc::scoped_refptr<PeerConnectionFactoryInterface>
91 CreatePeerConnectionFactoryWithAudioMixer(
92 rtc::Thread* network_thread,
93 rtc::Thread* worker_thread,
94 rtc::Thread* signaling_thread,
95 AudioDeviceModule* default_adm, 46 AudioDeviceModule* default_adm,
96 rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory, 47 rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory,
97 rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory, 48 rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory,
98 cricket::WebRtcVideoEncoderFactory* video_encoder_factory, 49 cricket::WebRtcVideoEncoderFactory* video_encoder_factory,
99 cricket::WebRtcVideoDecoderFactory* video_decoder_factory, 50 cricket::WebRtcVideoDecoderFactory* video_decoder_factory,
100 rtc::scoped_refptr<AudioMixer> audio_mixer) { 51 rtc::scoped_refptr<AudioMixer> audio_mixer,
52 std::unique_ptr<cricket::MediaEngineInterface> media_engine,
53 std::unique_ptr<CallFactoryInterface> call_factory,
54 std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory) {
101 rtc::scoped_refptr<PeerConnectionFactory> pc_factory( 55 rtc::scoped_refptr<PeerConnectionFactory> pc_factory(
102 new rtc::RefCountedObject<PeerConnectionFactory>( 56 new rtc::RefCountedObject<PeerConnectionFactory>(
103 network_thread, worker_thread, signaling_thread, default_adm, 57 network_thread, worker_thread, signaling_thread, default_adm,
104 audio_encoder_factory, audio_decoder_factory, video_encoder_factory, 58 audio_encoder_factory, audio_decoder_factory, video_encoder_factory,
105 video_decoder_factory, audio_mixer)); 59 video_decoder_factory, audio_mixer, std::move(media_engine),
60 std::move(call_factory), std::move(event_log_factory)));
106 61
107 // Call Initialize synchronously but make sure it is executed on 62 // Call Initialize synchronously but make sure it is executed on
108 // |signaling_thread|. 63 // |signaling_thread|.
109 MethodCall0<PeerConnectionFactory, bool> call( 64 MethodCall0<PeerConnectionFactory, bool> call(
110 pc_factory.get(), &PeerConnectionFactory::Initialize); 65 pc_factory.get(), &PeerConnectionFactory::Initialize);
111 bool result = call.Marshal(RTC_FROM_HERE, signaling_thread); 66 bool result = call.Marshal(RTC_FROM_HERE, signaling_thread);
112 67
113 if (!result) { 68 if (!result) {
114 return nullptr; 69 return nullptr;
115 } 70 }
116 return PeerConnectionFactoryProxy::Create(signaling_thread, pc_factory); 71 return PeerConnectionFactoryProxy::Create(signaling_thread, pc_factory);
117 } 72 }
118 73
119 rtc::scoped_refptr<PeerConnectionFactoryInterface>
120 CreatePeerConnectionFactoryWithAudioMixer(
121 rtc::Thread* network_thread,
122 rtc::Thread* worker_thread,
123 rtc::Thread* signaling_thread,
124 AudioDeviceModule* default_adm,
125 cricket::WebRtcVideoEncoderFactory* encoder_factory,
126 cricket::WebRtcVideoDecoderFactory* decoder_factory,
127 rtc::scoped_refptr<AudioMixer> audio_mixer) {
128 return CreatePeerConnectionFactoryWithAudioMixer(
129 network_thread, worker_thread, signaling_thread, default_adm,
130 CreateBuiltinAudioEncoderFactory(), CreateBuiltinAudioDecoderFactory(),
131 encoder_factory, decoder_factory, audio_mixer);
132 }
133
134 PeerConnectionFactory::PeerConnectionFactory( 74 PeerConnectionFactory::PeerConnectionFactory(
135 rtc::scoped_refptr<webrtc::AudioEncoderFactory> audio_encoder_factory, 75 rtc::scoped_refptr<webrtc::AudioEncoderFactory> audio_encoder_factory,
136 rtc::scoped_refptr<webrtc::AudioDecoderFactory> audio_decoder_factory) 76 rtc::scoped_refptr<webrtc::AudioDecoderFactory> audio_decoder_factory)
137 : owns_ptrs_(true), 77 : PeerConnectionFactory(nullptr /*network_thread*/,
138 wraps_current_thread_(false), 78 rtc::Thread::Create().release(),
139 network_thread_(rtc::Thread::CreateWithSocketServer().release()), 79 nullptr /*signaling_thread*/,
140 worker_thread_(rtc::Thread::Create().release()), 80 nullptr /*default_adm */,
141 signaling_thread_(rtc::Thread::Current()), 81 audio_encoder_factory,
142 audio_encoder_factory_(audio_encoder_factory), 82 audio_decoder_factory,
143 audio_decoder_factory_(audio_decoder_factory) { 83 nullptr /*video_encoder_factory*/,
144 if (!signaling_thread_) { 84 nullptr /*video_decoder_factory*/,
145 signaling_thread_ = rtc::ThreadManager::Instance()->WrapCurrentThread(); 85 nullptr /*audio_mixer*/,
146 wraps_current_thread_ = true; 86 std::unique_ptr<cricket::MediaEngineInterface>(),
147 } 87 std::unique_ptr<webrtc::CallFactoryInterface>(),
148 network_thread_->Start(); 88 std::unique_ptr<RtcEventLogFactoryInterface>()) {
149 worker_thread_->Start(); 89 worker_thread_->Start();
150 } 90 }
151 91
152 PeerConnectionFactory::PeerConnectionFactory( 92 PeerConnectionFactory::PeerConnectionFactory(
153 rtc::Thread* network_thread, 93 rtc::Thread* network_thread,
154 rtc::Thread* worker_thread, 94 rtc::Thread* worker_thread,
155 rtc::Thread* signaling_thread, 95 rtc::Thread* signaling_thread,
156 AudioDeviceModule* default_adm, 96 AudioDeviceModule* default_adm,
157 rtc::scoped_refptr<webrtc::AudioEncoderFactory> audio_encoder_factory, 97 rtc::scoped_refptr<webrtc::AudioEncoderFactory> audio_encoder_factory,
158 rtc::scoped_refptr<webrtc::AudioDecoderFactory> audio_decoder_factory, 98 rtc::scoped_refptr<webrtc::AudioDecoderFactory> audio_decoder_factory,
159 cricket::WebRtcVideoEncoderFactory* video_encoder_factory, 99 cricket::WebRtcVideoEncoderFactory* video_encoder_factory,
160 cricket::WebRtcVideoDecoderFactory* video_decoder_factory, 100 cricket::WebRtcVideoDecoderFactory* video_decoder_factory,
161 rtc::scoped_refptr<AudioMixer> audio_mixer) 101 rtc::scoped_refptr<AudioMixer> audio_mixer)
102 : PeerConnectionFactory(network_thread,
103 worker_thread,
104 signaling_thread,
105 default_adm,
106 audio_encoder_factory,
107 audio_decoder_factory,
108 video_encoder_factory,
109 video_decoder_factory,
110 audio_mixer,
111 std::unique_ptr<cricket::MediaEngineInterface>(),
112 std::unique_ptr<webrtc::CallFactoryInterface>(),
113 std::unique_ptr<RtcEventLogFactoryInterface>()) {}
114
115 PeerConnectionFactory::PeerConnectionFactory(
116 rtc::Thread* network_thread,
117 rtc::Thread* worker_thread,
118 rtc::Thread* signaling_thread,
119 AudioDeviceModule* default_adm,
120 rtc::scoped_refptr<webrtc::AudioEncoderFactory> audio_encoder_factory,
121 rtc::scoped_refptr<webrtc::AudioDecoderFactory> audio_decoder_factory,
122 cricket::WebRtcVideoEncoderFactory* video_encoder_factory,
123 cricket::WebRtcVideoDecoderFactory* video_decoder_factory,
124 rtc::scoped_refptr<AudioMixer> audio_mixer,
125 std::unique_ptr<cricket::MediaEngineInterface> media_engine,
126 std::unique_ptr<webrtc::CallFactoryInterface> call_factory,
127 std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory)
162 : owns_ptrs_(false), 128 : owns_ptrs_(false),
163 wraps_current_thread_(false), 129 wraps_current_thread_(false),
164 network_thread_(network_thread), 130 network_thread_(network_thread),
165 worker_thread_(worker_thread), 131 worker_thread_(worker_thread),
166 signaling_thread_(signaling_thread), 132 signaling_thread_(signaling_thread),
167 default_adm_(default_adm), 133 default_adm_(default_adm),
168 audio_encoder_factory_(audio_encoder_factory), 134 audio_encoder_factory_(audio_encoder_factory),
169 audio_decoder_factory_(audio_decoder_factory), 135 audio_decoder_factory_(audio_decoder_factory),
170 video_encoder_factory_(video_encoder_factory), 136 video_encoder_factory_(video_encoder_factory),
171 video_decoder_factory_(video_decoder_factory), 137 video_decoder_factory_(video_decoder_factory),
172 external_audio_mixer_(audio_mixer) { 138 external_audio_mixer_(audio_mixer),
173 RTC_DCHECK(network_thread); 139 media_engine_(std::move(media_engine)),
140 call_factory_(std::move(call_factory)),
141 event_log_factory_(std::move(event_log_factory)) {
174 RTC_DCHECK(worker_thread); 142 RTC_DCHECK(worker_thread);
175 RTC_DCHECK(signaling_thread); 143
144 // Create the threads internally and own them.
145 if (!network_thread || !signaling_thread) {
146 owns_ptrs_ = true;
147 network_thread_ = rtc::Thread::CreateWithSocketServer().release();
148 signaling_thread_ = rtc::Thread::Current();
149
150 if (!signaling_thread_) {
151 signaling_thread_ = rtc::ThreadManager::Instance()->WrapCurrentThread();
152 wraps_current_thread_ = true;
153 }
154 network_thread_->Start();
155 }
156
176 // TODO: Currently there is no way creating an external adm in 157 // TODO: Currently there is no way creating an external adm in
177 // libjingle source tree. So we can 't currently assert if this is NULL. 158 // libjingle source tree. So we can 't currently assert if this is NULL.
178 // RTC_DCHECK(default_adm != NULL); 159 // RTC_DCHECK(default_adm != NULL);
179 } 160 }
180 161
181 PeerConnectionFactory::~PeerConnectionFactory() { 162 PeerConnectionFactory::~PeerConnectionFactory() {
182 RTC_DCHECK(signaling_thread_->IsCurrent()); 163 RTC_DCHECK(signaling_thread_->IsCurrent());
183 channel_manager_.reset(nullptr); 164 channel_manager_.reset(nullptr);
184 165
185 // Make sure |worker_thread_| and |signaling_thread_| outlive 166 // Make sure |worker_thread_| and |signaling_thread_| outlive
(...skipping 17 matching lines...) Expand all
203 if (!default_network_manager_) { 184 if (!default_network_manager_) {
204 return false; 185 return false;
205 } 186 }
206 187
207 default_socket_factory_.reset( 188 default_socket_factory_.reset(
208 new rtc::BasicPacketSocketFactory(network_thread_)); 189 new rtc::BasicPacketSocketFactory(network_thread_));
209 if (!default_socket_factory_) { 190 if (!default_socket_factory_) {
210 return false; 191 return false;
211 } 192 }
212 193
213 std::unique_ptr<cricket::MediaEngineInterface> media_engine =
214 worker_thread_->Invoke<std::unique_ptr<cricket::MediaEngineInterface>>(
215 RTC_FROM_HERE,
216 rtc::Bind(&PeerConnectionFactory::CreateMediaEngine_w, this));
217
218 channel_manager_.reset(new cricket::ChannelManager( 194 channel_manager_.reset(new cricket::ChannelManager(
219 std::move(media_engine), worker_thread_, network_thread_)); 195 std::move(media_engine_), worker_thread_, network_thread_));
220 196
221 channel_manager_->SetVideoRtxEnabled(true); 197 channel_manager_->SetVideoRtxEnabled(true);
222 if (!channel_manager_->Init()) { 198 if (!channel_manager_->Init()) {
223 return false; 199 return false;
224 } 200 }
225 201
226 return true; 202 return true;
227 } 203 }
228 204
229 void PeerConnectionFactory::SetOptions(const Options& options) { 205 void PeerConnectionFactory::SetOptions(const Options& options) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 } 289 }
314 290
315 if (!allocator) { 291 if (!allocator) {
316 allocator.reset(new cricket::BasicPortAllocator( 292 allocator.reset(new cricket::BasicPortAllocator(
317 default_network_manager_.get(), default_socket_factory_.get())); 293 default_network_manager_.get(), default_socket_factory_.get()));
318 } 294 }
319 network_thread_->Invoke<void>( 295 network_thread_->Invoke<void>(
320 RTC_FROM_HERE, rtc::Bind(&cricket::PortAllocator::SetNetworkIgnoreMask, 296 RTC_FROM_HERE, rtc::Bind(&cricket::PortAllocator::SetNetworkIgnoreMask,
321 allocator.get(), options_.network_ignore_mask)); 297 allocator.get(), options_.network_ignore_mask));
322 298
299 std::unique_ptr<RtcEventLog> event_log(new RtcEventLogNullImpl());
300 if (event_log_factory_) {
301 event_log = event_log_factory_->CreateRtcEventLog();
302 }
303
304 std::unique_ptr<Call> call = worker_thread_->Invoke<std::unique_ptr<Call>>(
305 RTC_FROM_HERE,
306 rtc::Bind(&PeerConnectionFactory::CreateCall_w, this, event_log.get()));
307
323 rtc::scoped_refptr<PeerConnection> pc( 308 rtc::scoped_refptr<PeerConnection> pc(
324 new rtc::RefCountedObject<PeerConnection>(this)); 309 new rtc::RefCountedObject<PeerConnection>(this, std::move(event_log),
310 std::move(call)));
325 311
326 if (!pc->Initialize(configuration, std::move(allocator), 312 if (!pc->Initialize(configuration, std::move(allocator),
327 std::move(cert_generator), observer)) { 313 std::move(cert_generator), observer)) {
328 return nullptr; 314 return nullptr;
329 } 315 }
330 return PeerConnectionProxy::Create(signaling_thread(), pc); 316 return PeerConnectionProxy::Create(signaling_thread(), pc);
331 } 317 }
332 318
333 rtc::scoped_refptr<MediaStreamInterface> 319 rtc::scoped_refptr<MediaStreamInterface>
334 PeerConnectionFactory::CreateLocalMediaStream(const std::string& label) { 320 PeerConnectionFactory::CreateLocalMediaStream(const std::string& label) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 361
376 rtc::Thread* PeerConnectionFactory::worker_thread() { 362 rtc::Thread* PeerConnectionFactory::worker_thread() {
377 RTC_DCHECK(signaling_thread_->IsCurrent()); 363 RTC_DCHECK(signaling_thread_->IsCurrent());
378 return worker_thread_; 364 return worker_thread_;
379 } 365 }
380 366
381 rtc::Thread* PeerConnectionFactory::network_thread() { 367 rtc::Thread* PeerConnectionFactory::network_thread() {
382 return network_thread_; 368 return network_thread_;
383 } 369 }
384 370
385 std::unique_ptr<cricket::MediaEngineInterface> 371 std::unique_ptr<Call> PeerConnectionFactory::CreateCall_w(
386 PeerConnectionFactory::CreateMediaEngine_w() { 372 RtcEventLog* event_log) {
387 RTC_DCHECK(worker_thread_ == rtc::Thread::Current()); 373 const int kMinBandwidthBps = 30000;
388 return std::unique_ptr<cricket::MediaEngineInterface>( 374 const int kStartBandwidthBps = 300000;
389 cricket::WebRtcMediaEngineFactory::Create( 375 const int kMaxBandwidthBps = 2000000;
390 default_adm_.get(), audio_encoder_factory_, 376
391 audio_decoder_factory_, 377 webrtc::Call::Config call_config(event_log);
392 video_encoder_factory_.get(), video_decoder_factory_.get(), 378 if (!channel_manager_->media_engine() || !call_factory_) {
393 external_audio_mixer_)); 379 return nullptr;
380 }
381 call_config.audio_state = channel_manager_->media_engine()->GetAudioState();
382 call_config.bitrate_config.min_bitrate_bps = kMinBandwidthBps;
383 call_config.bitrate_config.start_bitrate_bps = kStartBandwidthBps;
384 call_config.bitrate_config.max_bitrate_bps = kMaxBandwidthBps;
385
386 return std::unique_ptr<Call>(call_factory_->CreateCall(call_config));
394 } 387 }
395 388
396 } // namespace webrtc 389 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698