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