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

Side by Side Diff: webrtc/api/quicdatatransport.cc

Issue 2166873002: Modified PeerConnection and WebRtcSession for end-to-end QuicDataChannel usage. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Change the comments and minor fix. Created 4 years, 4 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
« no previous file with comments | « webrtc/api/quicdatatransport.h ('k') | webrtc/api/quicdatatransport_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 DestroyTransportChannel(quic_transport_channel_);
36 LOG(LS_INFO) << "Destroyed the QUIC data transport.";
37 }
38
39 bool QuicDataTransport::SetTransport(const std::string& transport_name) {
40 if (transport_name_ == transport_name) {
41 // Nothing to do if transport name isn't changing
42 return true;
43 }
44
45 cricket::QuicTransportChannel* transport_channel =
46 CreateTransportChannel(transport_name);
47 if (!SetTransportChannel(transport_channel)) {
48 DestroyTransportChannel(transport_channel);
49 return false;
50 }
51
52 transport_name_ = transport_name;
53 return true;
54 }
31 55
32 bool QuicDataTransport::SetTransportChannel( 56 bool QuicDataTransport::SetTransportChannel(
33 cricket::QuicTransportChannel* channel) { 57 cricket::QuicTransportChannel* channel) {
34 if (!channel) { 58 if (!channel) {
35 LOG(LS_ERROR) << "|channel| is NULL. Cannot set transport channel."; 59 LOG(LS_ERROR) << "|channel| is NULL. Cannot set transport channel.";
36 return false; 60 return false;
37 } 61 }
38 if (quic_transport_channel_) { 62 if (quic_transport_channel_) {
39 if (channel == quic_transport_channel_) { 63 if (channel == quic_transport_channel_) {
40 LOG(LS_WARNING) << "Ignoring duplicate transport channel."; 64 LOG(LS_WARNING) << "Ignoring duplicate transport channel.";
41 return true; 65 return true;
42 } 66 }
43 LOG(LS_ERROR) << "|channel| does not match existing transport channel."; 67 LOG(LS_ERROR) << "|channel| does not match existing transport channel.";
44 return false; 68 return false;
45 } 69 }
46 70
47 LOG(LS_INFO) << "Setting QuicTransportChannel for QuicDataTransport"; 71 LOG(LS_INFO) << "Setting QuicTransportChannel for QuicDataTransport";
48 quic_transport_channel_ = channel; 72 quic_transport_channel_ = channel;
49 quic_transport_channel_->SignalIncomingStream.connect( 73 quic_transport_channel_->SignalIncomingStream.connect(
50 this, &QuicDataTransport::OnIncomingStream); 74 this, &QuicDataTransport::OnIncomingStream);
51
52 bool success = true; 75 bool success = true;
53 for (const auto& kv : data_channel_by_id_) { 76 for (const auto& kv : data_channel_by_id_) {
54 rtc::scoped_refptr<QuicDataChannel> data_channel = kv.second; 77 rtc::scoped_refptr<QuicDataChannel> data_channel = kv.second;
55 if (!data_channel->SetTransportChannel(quic_transport_channel_)) { 78 if (!data_channel->SetTransportChannel(quic_transport_channel_)) {
56 LOG(LS_ERROR) 79 LOG(LS_ERROR)
57 << "Cannot set QUIC transport channel for QUIC data channel " 80 << "Cannot set QUIC transport channel for QUIC data channel "
58 << kv.first; 81 << kv.first;
59 success = false; 82 success = false;
60 } 83 }
61 } 84 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 return; 163 return;
141 } 164 }
142 QuicDataChannel* data_channel = data_channel_kv->second; 165 QuicDataChannel* data_channel = data_channel_kv->second;
143 QuicDataChannel::Message message; 166 QuicDataChannel::Message message;
144 message.id = message_id; 167 message.id = message_id;
145 message.buffer = rtc::CopyOnWriteBuffer(data, len); 168 message.buffer = rtc::CopyOnWriteBuffer(data, len);
146 message.stream = stream; 169 message.stream = stream;
147 data_channel->OnIncomingMessage(std::move(message)); 170 data_channel->OnIncomingMessage(std::move(message));
148 } 171 }
149 172
173 cricket::QuicTransportChannel* QuicDataTransport::CreateTransportChannel(
174 const std::string& transport_name) {
175 DCHECK(transport_controller_->quic());
176
177 cricket::TransportChannel* transport_channel =
178 network_thread_->Invoke<cricket::TransportChannel*>(
179 RTC_FROM_HERE,
180 rtc::Bind(&cricket::TransportController::CreateTransportChannel_n,
181 transport_controller_, transport_name,
182 cricket::ICE_CANDIDATE_COMPONENT_DEFAULT));
183 return static_cast<cricket::QuicTransportChannel*>(transport_channel);
184 }
185
186 void QuicDataTransport::DestroyTransportChannel(
187 cricket::TransportChannel* transport_channel) {
188 if (transport_channel) {
189 network_thread_->Invoke<void>(
190 RTC_FROM_HERE,
191 rtc::Bind(&cricket::TransportController::DestroyTransportChannel_n,
192 transport_controller_, transport_channel->transport_name(),
193 cricket::ICE_CANDIDATE_COMPONENT_DEFAULT));
194 }
195 }
196
150 } // namespace webrtc 197 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/api/quicdatatransport.h ('k') | webrtc/api/quicdatatransport_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698