Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2016 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/api/quicdatatransport.h" | 11 #include "webrtc/api/quicdatatransport.h" |
| 12 | 12 |
| 13 #include "webrtc/base/bind.h" | |
| 13 #include "webrtc/base/logging.h" | 14 #include "webrtc/base/logging.h" |
| 14 #include "webrtc/p2p/quic/quictransportchannel.h" | 15 #include "webrtc/p2p/quic/quictransportchannel.h" |
| 15 #include "webrtc/p2p/quic/reliablequicstream.h" | 16 #include "webrtc/p2p/quic/reliablequicstream.h" |
| 16 | 17 |
| 17 namespace webrtc { | 18 namespace webrtc { |
| 18 | 19 |
| 19 QuicDataTransport::QuicDataTransport(rtc::Thread* signaling_thread, | 20 QuicDataTransport::QuicDataTransport( |
| 20 rtc::Thread* worker_thread, | 21 rtc::Thread* signaling_thread, |
| 21 rtc::Thread* network_thread) | 22 rtc::Thread* worker_thread, |
| 23 rtc::Thread* network_thread, | |
| 24 cricket::TransportController* transport_controller) | |
| 22 : signaling_thread_(signaling_thread), | 25 : signaling_thread_(signaling_thread), |
| 23 worker_thread_(worker_thread), | 26 worker_thread_(worker_thread), |
| 24 network_thread_(network_thread) { | 27 network_thread_(network_thread), |
| 28 transport_controller_(transport_controller) { | |
| 25 RTC_DCHECK(signaling_thread_); | 29 RTC_DCHECK(signaling_thread_); |
| 26 RTC_DCHECK(worker_thread_); | 30 RTC_DCHECK(worker_thread_); |
| 27 RTC_DCHECK(network_thread_); | 31 RTC_DCHECK(network_thread_); |
| 28 } | 32 } |
| 29 | 33 |
| 30 QuicDataTransport::~QuicDataTransport() {} | 34 QuicDataTransport::~QuicDataTransport() { |
| 35 network_thread_->Invoke<void>( | |
| 36 RTC_FROM_HERE, | |
| 37 rtc::Bind(&QuicDataTransport::DestroyTransportChannels_n, this)); | |
| 38 LOG(LS_INFO) << "Destroyed the QUIC data transport."; | |
| 39 } | |
| 40 | |
| 41 void QuicDataTransport::DestroyTransportChannels_n() { | |
|
Taylor Brandstetter
2016/07/21 23:39:57
nit: I think the location of the method in the .cc
Zhi Huang
2016/07/25 23:40:36
Done.
| |
| 42 if (quic_transport_channel_) { | |
| 43 transport_controller_->DestroyTransportChannel_n( | |
| 44 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTP); | |
|
pthatcher1
2016/07/22 17:57:57
Can you add a new component constant, perhaps ICE_
Zhi Huang
2016/07/25 23:40:36
We already have "const int ICE_CANDIDATE_COMPONENT
| |
| 45 } | |
| 46 } | |
| 31 | 47 |
| 32 bool QuicDataTransport::SetTransportChannel( | 48 bool QuicDataTransport::SetTransportChannel( |
| 33 cricket::QuicTransportChannel* channel) { | 49 cricket::QuicTransportChannel* channel) { |
| 34 if (!channel) { | 50 if (!channel) { |
| 35 LOG(LS_ERROR) << "|channel| is NULL. Cannot set transport channel."; | 51 LOG(LS_ERROR) << "|channel| is NULL. Cannot set transport channel."; |
| 36 return false; | 52 return false; |
| 37 } | 53 } |
| 38 if (quic_transport_channel_) { | 54 |
| 39 if (channel == quic_transport_channel_) { | 55 if (channel == quic_transport_channel_) { |
| 40 LOG(LS_WARNING) << "Ignoring duplicate transport channel."; | 56 LOG(LS_WARNING) << "Ignoring duplicate transport channel."; |
| 41 return true; | 57 return true; |
| 42 } | |
| 43 LOG(LS_ERROR) << "|channel| does not match existing transport channel."; | |
| 44 return false; | |
| 45 } | 58 } |
| 46 | 59 |
| 47 LOG(LS_INFO) << "Setting QuicTransportChannel for QuicDataTransport"; | 60 LOG(LS_INFO) << "Setting QuicTransportChannel for QuicDataTransport"; |
| 61 | |
| 62 if (quic_transport_channel_) { | |
| 63 quic_transport_channel_->SignalIncomingStream.disconnect(this); | |
| 64 transport_controller_->DestroyTransportChannel_n( | |
| 65 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTP); | |
|
pthatcher1
2016/07/22 17:57:57
Can you put this in a common method, perhaps Destr
Zhi Huang
2016/07/25 23:40:36
Since we are not supporting switching the transpor
| |
| 66 } | |
| 48 quic_transport_channel_ = channel; | 67 quic_transport_channel_ = channel; |
| 49 quic_transport_channel_->SignalIncomingStream.connect( | 68 quic_transport_channel_->SignalIncomingStream.connect( |
| 50 this, &QuicDataTransport::OnIncomingStream); | 69 this, &QuicDataTransport::OnIncomingStream); |
| 51 | 70 |
| 52 bool success = true; | 71 bool success = true; |
| 53 for (const auto& kv : data_channel_by_id_) { | 72 for (const auto& kv : data_channel_by_id_) { |
| 54 rtc::scoped_refptr<QuicDataChannel> data_channel = kv.second; | 73 rtc::scoped_refptr<QuicDataChannel> data_channel = kv.second; |
| 55 if (!data_channel->SetTransportChannel(quic_transport_channel_)) { | 74 if (!data_channel->SetTransportChannel(quic_transport_channel_)) { |
| 56 LOG(LS_ERROR) | 75 LOG(LS_ERROR) |
| 57 << "Cannot set QUIC transport channel for QUIC data channel " | 76 << "Cannot set QUIC transport channel for QUIC data channel " |
| 58 << kv.first; | 77 << kv.first; |
| 59 success = false; | 78 success = false; |
| 60 } | 79 } |
| 61 } | 80 } |
| 62 return success; | 81 return success; |
| 63 } | 82 } |
| 64 | 83 |
| 84 bool QuicDataTransport::SetTransport(const std::string& transport_name) { | |
| 85 return network_thread_->Invoke<bool>( | |
| 86 RTC_FROM_HERE, | |
| 87 rtc::Bind(&QuicDataTransport::SetTransport_n, this, transport_name)); | |
| 88 } | |
| 89 | |
| 90 bool QuicDataTransport::SetTransport_n(const std::string& transport_name) { | |
|
Taylor Brandstetter
2016/07/21 23:39:57
I think there needs to be a way to un-set the tran
pthatcher1
2016/07/22 10:46:03
I don't think we need to unset the transport. Jus
Taylor Brandstetter
2016/07/22 19:04:56
That's what unsetting the transport would do. Are
Zhi Huang
2016/07/25 23:40:36
I think what Peter suggested is that we can direct
| |
| 91 RTC_DCHECK(network_thread_->IsCurrent()); | |
| 92 | |
| 93 if (transport_name_ == transport_name) { | |
| 94 // Nothing to do if transport name isn't changing | |
| 95 return true; | |
| 96 } | |
| 97 | |
| 98 SetTransportChannel(static_cast<cricket::QuicTransportChannel*>( | |
| 99 transport_controller_->CreateTransportChannel_n( | |
| 100 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP))); | |
|
pthatcher1
2016/07/22 17:57:57
Can you put this in a CreateQuicTransportChannel m
Zhi Huang
2016/07/25 23:40:36
Done.
| |
| 101 | |
| 102 if (!quic_transport_channel_) { | |
| 103 return false; | |
| 104 } | |
| 105 | |
| 106 transport_name_ = transport_name; | |
| 107 return true; | |
| 108 } | |
| 109 | |
| 65 rtc::scoped_refptr<DataChannelInterface> QuicDataTransport::CreateDataChannel( | 110 rtc::scoped_refptr<DataChannelInterface> QuicDataTransport::CreateDataChannel( |
| 66 const std::string& label, | 111 const std::string& label, |
| 67 const DataChannelInit* config) { | 112 const DataChannelInit* config) { |
| 68 if (config == nullptr) { | 113 if (config == nullptr) { |
| 69 return nullptr; | 114 return nullptr; |
| 70 } | 115 } |
| 71 if (data_channel_by_id_.find(config->id) != data_channel_by_id_.end()) { | 116 if (data_channel_by_id_.find(config->id) != data_channel_by_id_.end()) { |
| 72 LOG(LS_ERROR) << "QUIC data channel already exists with id " << config->id; | 117 LOG(LS_ERROR) << "QUIC data channel already exists with id " << config->id; |
| 73 return nullptr; | 118 return nullptr; |
| 74 } | 119 } |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 } | 186 } |
| 142 QuicDataChannel* data_channel = data_channel_kv->second; | 187 QuicDataChannel* data_channel = data_channel_kv->second; |
| 143 QuicDataChannel::Message message; | 188 QuicDataChannel::Message message; |
| 144 message.id = message_id; | 189 message.id = message_id; |
| 145 message.buffer = rtc::CopyOnWriteBuffer(data, len); | 190 message.buffer = rtc::CopyOnWriteBuffer(data, len); |
| 146 message.stream = stream; | 191 message.stream = stream; |
| 147 data_channel->OnIncomingMessage(std::move(message)); | 192 data_channel->OnIncomingMessage(std::move(message)); |
| 148 } | 193 } |
| 149 | 194 |
| 150 } // namespace webrtc | 195 } // namespace webrtc |
| OLD | NEW |