OLD | NEW |
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/channelmanager.h" | 11 #include "webrtc/pc/channelmanager.h" |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
14 | 14 |
15 #include "webrtc/api/mediacontroller.h" | 15 #include "webrtc/api/mediacontroller.h" |
16 #include "webrtc/base/bind.h" | 16 #include "webrtc/base/bind.h" |
17 #include "webrtc/base/common.h" | 17 #include "webrtc/base/common.h" |
18 #include "webrtc/base/logging.h" | 18 #include "webrtc/base/logging.h" |
19 #include "webrtc/base/stringencode.h" | 19 #include "webrtc/base/stringencode.h" |
20 #include "webrtc/base/stringutils.h" | 20 #include "webrtc/base/stringutils.h" |
21 #include "webrtc/base/trace_event.h" | 21 #include "webrtc/base/trace_event.h" |
22 #include "webrtc/media/base/device.h" | 22 #include "webrtc/media/base/device.h" |
23 #include "webrtc/media/base/hybriddataengine.h" | |
24 #include "webrtc/media/base/rtpdataengine.h" | 23 #include "webrtc/media/base/rtpdataengine.h" |
25 #ifdef HAVE_SCTP | |
26 #include "webrtc/media/sctp/sctpdataengine.h" | |
27 #endif | |
28 #include "webrtc/pc/srtpfilter.h" | 24 #include "webrtc/pc/srtpfilter.h" |
29 | 25 |
30 namespace cricket { | 26 namespace cricket { |
31 | 27 |
32 | 28 |
33 using rtc::Bind; | 29 using rtc::Bind; |
34 | 30 |
35 static DataEngineInterface* ConstructDataEngine() { | 31 static DataEngineInterface* ConstructDataEngine() { |
36 #ifdef HAVE_SCTP | |
37 return new HybridDataEngine(new RtpDataEngine(), new SctpDataEngine()); | |
38 #else | |
39 return new RtpDataEngine(); | 32 return new RtpDataEngine(); |
40 #endif | |
41 } | 33 } |
42 | 34 |
43 ChannelManager::ChannelManager(MediaEngineInterface* me, | 35 ChannelManager::ChannelManager(MediaEngineInterface* me, |
44 DataEngineInterface* dme, | 36 DataEngineInterface* dme, |
45 rtc::Thread* thread) { | 37 rtc::Thread* thread) { |
46 Construct(me, dme, thread, thread); | 38 Construct(me, dme, thread, thread); |
47 } | 39 } |
48 | 40 |
49 ChannelManager::ChannelManager(MediaEngineInterface* me, | 41 ChannelManager::ChannelManager(MediaEngineInterface* me, |
50 rtc::Thread* worker_thread, | 42 rtc::Thread* worker_thread, |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 VideoChannels::iterator it = std::find(video_channels_.begin(), | 329 VideoChannels::iterator it = std::find(video_channels_.begin(), |
338 video_channels_.end(), video_channel); | 330 video_channels_.end(), video_channel); |
339 ASSERT(it != video_channels_.end()); | 331 ASSERT(it != video_channels_.end()); |
340 if (it == video_channels_.end()) | 332 if (it == video_channels_.end()) |
341 return; | 333 return; |
342 | 334 |
343 video_channels_.erase(it); | 335 video_channels_.erase(it); |
344 delete video_channel; | 336 delete video_channel; |
345 } | 337 } |
346 | 338 |
347 DataChannel* ChannelManager::CreateDataChannel( | 339 RtpDataChannel* ChannelManager::CreateRtpDataChannel( |
348 webrtc::MediaControllerInterface* media_controller, | 340 webrtc::MediaControllerInterface* media_controller, |
349 TransportController* transport_controller, | 341 TransportController* transport_controller, |
350 const std::string& content_name, | 342 const std::string& content_name, |
351 const std::string* bundle_transport_name, | 343 const std::string* bundle_transport_name, |
352 bool rtcp, | 344 bool rtcp, |
353 bool srtp_required, | 345 bool srtp_required) { |
354 DataChannelType channel_type) { | 346 return worker_thread_->Invoke<RtpDataChannel*>( |
355 return worker_thread_->Invoke<DataChannel*>( | 347 RTC_FROM_HERE, Bind(&ChannelManager::CreateRtpDataChannel_w, this, |
356 RTC_FROM_HERE, | 348 media_controller, transport_controller, content_name, |
357 Bind(&ChannelManager::CreateDataChannel_w, this, media_controller, | 349 bundle_transport_name, rtcp, srtp_required)); |
358 transport_controller, content_name, bundle_transport_name, rtcp, | |
359 srtp_required, channel_type)); | |
360 } | 350 } |
361 | 351 |
362 DataChannel* ChannelManager::CreateDataChannel_w( | 352 RtpDataChannel* ChannelManager::CreateRtpDataChannel_w( |
363 webrtc::MediaControllerInterface* media_controller, | 353 webrtc::MediaControllerInterface* media_controller, |
364 TransportController* transport_controller, | 354 TransportController* transport_controller, |
365 const std::string& content_name, | 355 const std::string& content_name, |
366 const std::string* bundle_transport_name, | 356 const std::string* bundle_transport_name, |
367 bool rtcp, | 357 bool rtcp, |
368 bool srtp_required, | 358 bool srtp_required) { |
369 DataChannelType data_channel_type) { | |
370 // This is ok to alloc from a thread other than the worker thread. | 359 // This is ok to alloc from a thread other than the worker thread. |
371 ASSERT(initialized_); | 360 ASSERT(initialized_); |
372 MediaConfig config; | 361 MediaConfig config; |
373 if (media_controller) { | 362 if (media_controller) { |
374 config = media_controller->config(); | 363 config = media_controller->config(); |
375 } | 364 } |
376 DataMediaChannel* media_channel = | 365 DataMediaChannel* media_channel = data_media_engine_->CreateChannel(config); |
377 data_media_engine_->CreateChannel(data_channel_type, config); | |
378 if (!media_channel) { | 366 if (!media_channel) { |
379 LOG(LS_WARNING) << "Failed to create data channel of type " | 367 LOG(LS_WARNING) << "Failed to create RTP data channel."; |
380 << data_channel_type; | 368 return nullptr; |
381 return NULL; | |
382 } | 369 } |
383 | 370 |
384 // Only RTP data channels need SRTP. | 371 RtpDataChannel* data_channel = new RtpDataChannel( |
385 srtp_required = srtp_required && data_channel_type == DCT_RTP; | 372 worker_thread_, network_thread_, media_channel, transport_controller, |
386 DataChannel* data_channel = | 373 content_name, rtcp, srtp_required); |
387 new DataChannel(worker_thread_, network_thread_, media_channel, | |
388 transport_controller, content_name, rtcp, srtp_required); | |
389 data_channel->SetCryptoOptions(crypto_options_); | 374 data_channel->SetCryptoOptions(crypto_options_); |
390 if (!data_channel->Init_w(bundle_transport_name)) { | 375 if (!data_channel->Init_w(bundle_transport_name)) { |
391 LOG(LS_WARNING) << "Failed to init data channel."; | 376 LOG(LS_WARNING) << "Failed to init data channel."; |
392 delete data_channel; | 377 delete data_channel; |
393 return NULL; | 378 return nullptr; |
394 } | 379 } |
395 data_channels_.push_back(data_channel); | 380 data_channels_.push_back(data_channel); |
396 return data_channel; | 381 return data_channel; |
397 } | 382 } |
398 | 383 |
399 void ChannelManager::DestroyDataChannel(DataChannel* data_channel) { | 384 void ChannelManager::DestroyRtpDataChannel(RtpDataChannel* data_channel) { |
400 TRACE_EVENT0("webrtc", "ChannelManager::DestroyDataChannel"); | 385 TRACE_EVENT0("webrtc", "ChannelManager::DestroyRtpDataChannel"); |
401 if (data_channel) { | 386 if (data_channel) { |
402 worker_thread_->Invoke<void>( | 387 worker_thread_->Invoke<void>( |
403 RTC_FROM_HERE, | 388 RTC_FROM_HERE, |
404 Bind(&ChannelManager::DestroyDataChannel_w, this, data_channel)); | 389 Bind(&ChannelManager::DestroyRtpDataChannel_w, this, data_channel)); |
405 } | 390 } |
406 } | 391 } |
407 | 392 |
408 void ChannelManager::DestroyDataChannel_w(DataChannel* data_channel) { | 393 void ChannelManager::DestroyRtpDataChannel_w(RtpDataChannel* data_channel) { |
409 TRACE_EVENT0("webrtc", "ChannelManager::DestroyDataChannel_w"); | 394 TRACE_EVENT0("webrtc", "ChannelManager::DestroyRtpDataChannel_w"); |
410 // Destroy data channel. | 395 // Destroy data channel. |
411 ASSERT(initialized_); | 396 ASSERT(initialized_); |
412 DataChannels::iterator it = std::find(data_channels_.begin(), | 397 RtpDataChannels::iterator it = |
413 data_channels_.end(), data_channel); | 398 std::find(data_channels_.begin(), data_channels_.end(), data_channel); |
414 ASSERT(it != data_channels_.end()); | 399 ASSERT(it != data_channels_.end()); |
415 if (it == data_channels_.end()) | 400 if (it == data_channels_.end()) |
416 return; | 401 return; |
417 | 402 |
418 data_channels_.erase(it); | 403 data_channels_.erase(it); |
419 delete data_channel; | 404 delete data_channel; |
420 } | 405 } |
421 | 406 |
422 bool ChannelManager::StartAecDump(rtc::PlatformFile file, | 407 bool ChannelManager::StartAecDump(rtc::PlatformFile file, |
423 int64_t max_size_bytes) { | 408 int64_t max_size_bytes) { |
424 return worker_thread_->Invoke<bool>( | 409 return worker_thread_->Invoke<bool>( |
425 RTC_FROM_HERE, Bind(&MediaEngineInterface::StartAecDump, | 410 RTC_FROM_HERE, Bind(&MediaEngineInterface::StartAecDump, |
426 media_engine_.get(), file, max_size_bytes)); | 411 media_engine_.get(), file, max_size_bytes)); |
427 } | 412 } |
428 | 413 |
429 void ChannelManager::StopAecDump() { | 414 void ChannelManager::StopAecDump() { |
430 worker_thread_->Invoke<void>( | 415 worker_thread_->Invoke<void>( |
431 RTC_FROM_HERE, | 416 RTC_FROM_HERE, |
432 Bind(&MediaEngineInterface::StopAecDump, media_engine_.get())); | 417 Bind(&MediaEngineInterface::StopAecDump, media_engine_.get())); |
433 } | 418 } |
434 | 419 |
435 } // namespace cricket | 420 } // namespace cricket |
OLD | NEW |