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

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

Issue 2606123002: Remove the dependency of TransportChannel and TransportChannelImpl. (Closed)
Patch Set: Fix the format. Created 3 years, 11 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 <utility> 11 #include <utility>
12 12
13 #include "webrtc/pc/channel.h" 13 #include "webrtc/pc/channel.h"
14 14
15 #include "webrtc/api/call/audio_sink.h" 15 #include "webrtc/api/call/audio_sink.h"
16 #include "webrtc/base/bind.h" 16 #include "webrtc/base/bind.h"
17 #include "webrtc/base/byteorder.h" 17 #include "webrtc/base/byteorder.h"
18 #include "webrtc/base/checks.h" 18 #include "webrtc/base/checks.h"
19 #include "webrtc/base/common.h" 19 #include "webrtc/base/common.h"
20 #include "webrtc/base/copyonwritebuffer.h" 20 #include "webrtc/base/copyonwritebuffer.h"
21 #include "webrtc/base/dscp.h" 21 #include "webrtc/base/dscp.h"
22 #include "webrtc/base/logging.h" 22 #include "webrtc/base/logging.h"
23 #include "webrtc/base/networkroute.h" 23 #include "webrtc/base/networkroute.h"
24 #include "webrtc/base/trace_event.h" 24 #include "webrtc/base/trace_event.h"
25 #include "webrtc/media/base/mediaconstants.h" 25 #include "webrtc/media/base/mediaconstants.h"
26 #include "webrtc/media/base/rtputils.h" 26 #include "webrtc/media/base/rtputils.h"
27 #include "webrtc/p2p/base/packettransportinterface.h" 27 #include "webrtc/p2p/base/packettransportinterface.h"
28 #include "webrtc/p2p/base/transportchannel.h"
29 #include "webrtc/pc/channelmanager.h" 28 #include "webrtc/pc/channelmanager.h"
30 29
31 namespace cricket { 30 namespace cricket {
32 using rtc::Bind; 31 using rtc::Bind;
33 32
34 namespace { 33 namespace {
35 // See comment below for why we need to use a pointer to a unique_ptr. 34 // See comment below for why we need to use a pointer to a unique_ptr.
36 bool SetRawAudioSink_w(VoiceMediaChannel* channel, 35 bool SetRawAudioSink_w(VoiceMediaChannel* channel,
37 uint32_t ssrc, 36 uint32_t ssrc,
38 std::unique_ptr<webrtc::AudioSinkInterface>* sink) { 37 std::unique_ptr<webrtc::AudioSinkInterface>* sink) {
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 delete media_channel_; 190 delete media_channel_;
192 LOG(LS_INFO) << "Destroyed channel: " << content_name_; 191 LOG(LS_INFO) << "Destroyed channel: " << content_name_;
193 } 192 }
194 193
195 void BaseChannel::DisconnectTransportChannels_n() { 194 void BaseChannel::DisconnectTransportChannels_n() {
196 // Send any outstanding RTCP packets. 195 // Send any outstanding RTCP packets.
197 FlushRtcpMessages_n(); 196 FlushRtcpMessages_n();
198 197
199 // Stop signals from transport channels, but keep them alive because 198 // Stop signals from transport channels, but keep them alive because
200 // media_channel may use them from a different thread. 199 // media_channel may use them from a different thread.
201 if (rtp_transport_) { 200 if (rtp_dtls_transport_) {
202 DisconnectFromTransportChannel(rtp_transport_); 201 DisconnectFromTransport(rtp_dtls_transport_);
203 } 202 }
204 if (rtcp_transport_) { 203 if (rtcp_dtls_transport_) {
205 DisconnectFromTransportChannel(rtcp_transport_); 204 DisconnectFromTransport(rtcp_dtls_transport_);
206 } 205 }
207 206
208 // Clear pending read packets/messages. 207 // Clear pending read packets/messages.
209 network_thread_->Clear(&invoker_); 208 network_thread_->Clear(&invoker_);
210 network_thread_->Clear(this); 209 network_thread_->Clear(this);
211 } 210 }
212 211
213 bool BaseChannel::Init_w(TransportChannel* rtp_transport, 212 bool BaseChannel::Init_w(DtlsTransportInternal* rtp_dtls_transport,
214 TransportChannel* rtcp_transport) { 213 DtlsTransportInternal* rtcp_dtls_transport) {
215 if (!network_thread_->Invoke<bool>( 214 if (!network_thread_->Invoke<bool>(
216 RTC_FROM_HERE, Bind(&BaseChannel::InitNetwork_n, this, rtp_transport, 215 RTC_FROM_HERE, Bind(&BaseChannel::InitNetwork_n, this,
217 rtcp_transport))) { 216 rtp_dtls_transport, rtcp_dtls_transport))) {
218 return false; 217 return false;
219 } 218 }
220 219
221 // Both RTP and RTCP channels are set, we can call SetInterface on 220 // Both RTP and RTCP channels are set, we can call SetInterface on
222 // media channel and it can set network options. 221 // media channel and it can set network options.
223 RTC_DCHECK(worker_thread_->IsCurrent()); 222 RTC_DCHECK(worker_thread_->IsCurrent());
224 media_channel_->SetInterface(this); 223 media_channel_->SetInterface(this);
225 return true; 224 return true;
226 } 225 }
227 226
228 bool BaseChannel::InitNetwork_n(TransportChannel* rtp_transport, 227 bool BaseChannel::InitNetwork_n(DtlsTransportInternal* rtp_dtls_transport,
229 TransportChannel* rtcp_transport) { 228 DtlsTransportInternal* rtcp_dtls_transport) {
230 RTC_DCHECK(network_thread_->IsCurrent()); 229 RTC_DCHECK(network_thread_->IsCurrent());
231 // const std::string& transport_name = 230 // const std::string& transport_name =
232 // (bundle_transport_name ? *bundle_transport_name : content_name()); 231 // (bundle_transport_name ? *bundle_transport_name : content_name());
233 if (!SetTransport_n(rtp_transport, rtcp_transport)) { 232 if (!SetTransports_n(rtp_dtls_transport, rtcp_dtls_transport)) {
234 return false; 233 return false;
235 } 234 }
236 235
237 if (!SetDtlsSrtpCryptoSuites_n(rtp_transport_, false)) { 236 if (!SetDtlsSrtpCryptoSuites_n(rtp_dtls_transport_, false)) {
238 return false; 237 return false;
239 } 238 }
240 if (rtcp_transport_ && !SetDtlsSrtpCryptoSuites_n(rtcp_transport_, true)) { 239 if (rtcp_dtls_transport_ &&
240 !SetDtlsSrtpCryptoSuites_n(rtcp_dtls_transport_, true)) {
241 return false; 241 return false;
242 } 242 }
243 if (rtcp_mux_required_) { 243 if (rtcp_mux_required_) {
244 rtcp_mux_filter_.SetActive(); 244 rtcp_mux_filter_.SetActive();
245 } 245 }
246 return true; 246 return true;
247 } 247 }
248 248
249 void BaseChannel::Deinit() { 249 void BaseChannel::Deinit() {
250 RTC_DCHECK(worker_thread_->IsCurrent()); 250 RTC_DCHECK(worker_thread_->IsCurrent());
251 media_channel_->SetInterface(NULL); 251 media_channel_->SetInterface(NULL);
252 // Packets arrive on the network thread, processing packets calls virtual 252 // Packets arrive on the network thread, processing packets calls virtual
253 // functions, so need to stop this process in Deinit that is called in 253 // functions, so need to stop this process in Deinit that is called in
254 // derived classes destructor. 254 // derived classes destructor.
255 network_thread_->Invoke<void>( 255 network_thread_->Invoke<void>(
256 RTC_FROM_HERE, Bind(&BaseChannel::DisconnectTransportChannels_n, this)); 256 RTC_FROM_HERE, Bind(&BaseChannel::DisconnectTransportChannels_n, this));
257 } 257 }
258 258
259 bool BaseChannel::SetTransport(TransportChannel* rtp_transport, 259 bool BaseChannel::SetTransports(DtlsTransportInternal* rtp_dtls_transport,
260 TransportChannel* rtcp_transport) { 260 DtlsTransportInternal* rtcp_dtls_transport) {
261 return network_thread_->Invoke<bool>( 261 return network_thread_->Invoke<bool>(
262 RTC_FROM_HERE, 262 RTC_FROM_HERE, Bind(&BaseChannel::SetTransports_n, this,
263 Bind(&BaseChannel::SetTransport_n, this, rtp_transport, rtcp_transport)); 263 rtp_dtls_transport, rtcp_dtls_transport));
264 } 264 }
265 265
266 bool BaseChannel::SetTransport_n(TransportChannel* rtp_transport, 266 bool BaseChannel::SetTransports_n(DtlsTransportInternal* rtp_dtls_transport,
267 TransportChannel* rtcp_transport) { 267 DtlsTransportInternal* rtcp_dtls_transport) {
268 RTC_DCHECK(network_thread_->IsCurrent()); 268 RTC_DCHECK(network_thread_->IsCurrent());
269 if (!rtp_transport && !rtcp_transport) { 269 if (!rtp_dtls_transport && !rtcp_dtls_transport) {
270 LOG(LS_ERROR) << "Setting nullptr to RTP Transport and RTCP Transport."; 270 LOG(LS_ERROR) << "Setting nullptr to RTP Transport and RTCP Transport.";
271 return false; 271 return false;
272 } 272 }
273 273
274 if (rtcp_transport) { 274 if (rtcp_dtls_transport) {
275 RTC_DCHECK(rtp_transport->transport_name() == 275 RTC_DCHECK(rtp_dtls_transport->transport_name() ==
276 rtcp_transport->transport_name()); 276 rtcp_dtls_transport->transport_name());
277 RTC_DCHECK(NeedsRtcpTransport()); 277 RTC_DCHECK(NeedsRtcpTransport());
278 } 278 }
279 279
280 if (rtp_transport->transport_name() == transport_name_) { 280 if (rtp_dtls_transport->transport_name() == transport_name_) {
281 // Nothing to do if transport name isn't changing. 281 // Nothing to do if transport name isn't changing.
282 return true; 282 return true;
283 } 283 }
284 284
285 transport_name_ = rtp_transport->transport_name(); 285 transport_name_ = rtp_dtls_transport->transport_name();
286 286
287 // When using DTLS-SRTP, we must reset the SrtpFilter every time the transport 287 // When using DTLS-SRTP, we must reset the SrtpFilter every time the transport
288 // changes and wait until the DTLS handshake is complete to set the newly 288 // changes and wait until the DTLS handshake is complete to set the newly
289 // negotiated parameters. 289 // negotiated parameters.
290 if (ShouldSetupDtlsSrtp_n()) { 290 if (ShouldSetupDtlsSrtp_n()) {
291 // Set |writable_| to false such that UpdateWritableState_w can set up 291 // Set |writable_| to false such that UpdateWritableState_w can set up
292 // DTLS-SRTP when |writable_| becomes true again. 292 // DTLS-SRTP when |writable_| becomes true again.
293 writable_ = false; 293 writable_ = false;
294 srtp_filter_.ResetParams(); 294 srtp_filter_.ResetParams();
295 } 295 }
296 296
297 // If this BaseChannel doesn't require RTCP mux and we haven't fully 297 // If this BaseChannel doesn't require RTCP mux and we haven't fully
298 // negotiated RTCP mux, we need an RTCP transport. 298 // negotiated RTCP mux, we need an RTCP transport.
299 if (NeedsRtcpTransport()) { 299 if (NeedsRtcpTransport()) {
300 LOG(LS_INFO) << "Setting RTCP Transport for " << content_name() << " on " 300 LOG(LS_INFO) << "Setting RTCP Transport for " << content_name() << " on "
301 << transport_name() << " transport " << rtcp_transport; 301 << transport_name() << " transport " << rtcp_dtls_transport;
302 SetTransportChannel_n(true, rtcp_transport); 302 SetTransport_n(true, rtcp_dtls_transport);
303 if (!rtcp_transport_) { 303 if (!rtcp_dtls_transport_) {
304 return false; 304 return false;
305 } 305 }
306 } 306 }
307 307
308 LOG(LS_INFO) << "Setting non-RTCP Transport for " << content_name() << " on " 308 LOG(LS_INFO) << "Setting non-RTCP Transport for " << content_name() << " on "
309 << transport_name() << " transport " << rtp_transport; 309 << transport_name() << " transport " << rtp_dtls_transport;
310 SetTransportChannel_n(false, rtp_transport); 310 SetTransport_n(false, rtp_dtls_transport);
311 if (!rtp_transport_) { 311 if (!rtp_dtls_transport_) {
312 return false; 312 return false;
313 } 313 }
314 314
315 // Update aggregate writable/ready-to-send state between RTP and RTCP upon 315 // Update aggregate writable/ready-to-send state between RTP and RTCP upon
316 // setting new transport channels. 316 // setting new transport channels.
317 UpdateWritableState_n(); 317 UpdateWritableState_n();
318 // We can only update ready-to-send after updating writability. 318 // We can only update ready-to-send after updating writability.
319 // 319 //
320 // On setting a new channel, assume it's ready to send if it's writable, 320 // On setting a new channel, assume it's ready to send if it's writable,
321 // because we have no way of knowing otherwise (the channel doesn't give us 321 // because we have no way of knowing otherwise (the channel doesn't give us
322 // "was last send successful?"). 322 // "was last send successful?").
323 // 323 //
324 // This won't always be accurate (the last SendPacket call from another 324 // This won't always be accurate (the last SendPacket call from another
325 // BaseChannel could have resulted in an error), but even so, we'll just 325 // BaseChannel could have resulted in an error), but even so, we'll just
326 // encounter the error again and update "ready to send" accordingly. 326 // encounter the error again and update "ready to send" accordingly.
327 SetTransportChannelReadyToSend(false,
328 rtp_transport_ && rtp_transport_->writable());
329 SetTransportChannelReadyToSend( 327 SetTransportChannelReadyToSend(
330 true, rtcp_transport_ && rtcp_transport_->writable()); 328 false, rtp_dtls_transport_ && rtp_dtls_transport_->writable());
329 SetTransportChannelReadyToSend(
330 true, rtcp_dtls_transport_ && rtcp_dtls_transport_->writable());
331 return true; 331 return true;
332 } 332 }
333 333
334 void BaseChannel::SetTransportChannel_n(bool rtcp, 334 void BaseChannel::SetTransport_n(bool rtcp,
335 TransportChannel* new_transport) { 335 DtlsTransportInternal* new_transport) {
336 RTC_DCHECK(network_thread_->IsCurrent()); 336 RTC_DCHECK(network_thread_->IsCurrent());
337 TransportChannel*& old_transport = rtcp ? rtcp_transport_ : rtp_transport_; 337 DtlsTransportInternal*& old_transport =
338 rtcp ? rtcp_dtls_transport_ : rtp_dtls_transport_;
339
338 if (!old_transport && !new_transport) { 340 if (!old_transport && !new_transport) {
339 // Nothing to do. 341 // Nothing to do.
340 return; 342 return;
341 } 343 }
344
342 RTC_DCHECK(old_transport != new_transport); 345 RTC_DCHECK(old_transport != new_transport);
343 if (old_transport) { 346 if (old_transport) {
344 DisconnectFromTransportChannel(old_transport); 347 DisconnectFromTransport(old_transport);
345 } 348 }
346 349
347 old_transport = new_transport; 350 old_transport = new_transport;
348 351
349 if (new_transport) { 352 if (new_transport) {
350 if (rtcp) { 353 if (rtcp) {
351 RTC_CHECK(!(ShouldSetupDtlsSrtp_n() && srtp_filter_.IsActive())) 354 RTC_CHECK(!(ShouldSetupDtlsSrtp_n() && srtp_filter_.IsActive()))
352 << "Setting RTCP for DTLS/SRTP after SrtpFilter is active " 355 << "Setting RTCP for DTLS/SRTP after SrtpFilter is active "
353 << "should never happen."; 356 << "should never happen.";
354 } 357 }
355 ConnectToTransportChannel(new_transport); 358 ConnectToTransport(new_transport);
356 auto& socket_options = rtcp ? rtcp_socket_options_ : socket_options_; 359 auto& socket_options = rtcp ? rtcp_socket_options_ : socket_options_;
357 for (const auto& pair : socket_options) { 360 for (const auto& pair : socket_options) {
358 new_transport->SetOption(pair.first, pair.second); 361 new_transport->SetOption(pair.first, pair.second);
359 } 362 }
360 } 363 }
361 } 364 }
362 365
363 void BaseChannel::ConnectToTransportChannel(TransportChannel* tc) { 366 void BaseChannel::ConnectToTransport(DtlsTransportInternal* transport) {
364 RTC_DCHECK(network_thread_->IsCurrent()); 367 RTC_DCHECK(network_thread_->IsCurrent());
365 368
366 tc->SignalWritableState.connect(this, &BaseChannel::OnWritableState); 369 transport->SignalWritableState.connect(this, &BaseChannel::OnWritableState);
367 tc->SignalReadPacket.connect(this, &BaseChannel::OnPacketRead); 370 transport->SignalReadPacket.connect(this, &BaseChannel::OnPacketRead);
368 tc->SignalReadyToSend.connect(this, &BaseChannel::OnReadyToSend); 371 transport->SignalReadyToSend.connect(this, &BaseChannel::OnReadyToSend);
369 tc->SignalDtlsState.connect(this, &BaseChannel::OnDtlsState); 372 transport->SignalDtlsState.connect(this, &BaseChannel::OnDtlsState);
370 tc->SignalSelectedCandidatePairChanged.connect( 373 transport->SignalSentPacket.connect(this, &BaseChannel::SignalSentPacket_n);
374 transport->ice_transport()->SignalSelectedCandidatePairChanged.connect(
371 this, &BaseChannel::OnSelectedCandidatePairChanged); 375 this, &BaseChannel::OnSelectedCandidatePairChanged);
372 tc->SignalSentPacket.connect(this, &BaseChannel::SignalSentPacket_n);
373 } 376 }
374 377
375 void BaseChannel::DisconnectFromTransportChannel(TransportChannel* tc) { 378 void BaseChannel::DisconnectFromTransport(DtlsTransportInternal* transport) {
376 RTC_DCHECK(network_thread_->IsCurrent()); 379 RTC_DCHECK(network_thread_->IsCurrent());
377 OnSelectedCandidatePairChanged(tc, nullptr, -1, false); 380 OnSelectedCandidatePairChanged(transport->ice_transport(), nullptr, -1,
381 false);
378 382
379 tc->SignalWritableState.disconnect(this); 383 transport->SignalWritableState.disconnect(this);
380 tc->SignalReadPacket.disconnect(this); 384 transport->SignalReadPacket.disconnect(this);
381 tc->SignalReadyToSend.disconnect(this); 385 transport->SignalReadyToSend.disconnect(this);
382 tc->SignalDtlsState.disconnect(this); 386 transport->SignalDtlsState.disconnect(this);
383 tc->SignalSelectedCandidatePairChanged.disconnect(this); 387 transport->SignalSentPacket.disconnect(this);
384 tc->SignalSentPacket.disconnect(this); 388 transport->ice_transport()->SignalSelectedCandidatePairChanged.disconnect(
389 this);
385 } 390 }
386 391
387 bool BaseChannel::Enable(bool enable) { 392 bool BaseChannel::Enable(bool enable) {
388 worker_thread_->Invoke<void>( 393 worker_thread_->Invoke<void>(
389 RTC_FROM_HERE, 394 RTC_FROM_HERE,
390 Bind(enable ? &BaseChannel::EnableMedia_w : &BaseChannel::DisableMedia_w, 395 Bind(enable ? &BaseChannel::EnableMedia_w : &BaseChannel::DisableMedia_w,
391 this)); 396 this));
392 return true; 397 return true;
393 } 398 }
394 399
(...skipping 27 matching lines...) Expand all
422 427
423 bool BaseChannel::SetRemoteContent(const MediaContentDescription* content, 428 bool BaseChannel::SetRemoteContent(const MediaContentDescription* content,
424 ContentAction action, 429 ContentAction action,
425 std::string* error_desc) { 430 std::string* error_desc) {
426 TRACE_EVENT0("webrtc", "BaseChannel::SetRemoteContent"); 431 TRACE_EVENT0("webrtc", "BaseChannel::SetRemoteContent");
427 return InvokeOnWorker(RTC_FROM_HERE, Bind(&BaseChannel::SetRemoteContent_w, 432 return InvokeOnWorker(RTC_FROM_HERE, Bind(&BaseChannel::SetRemoteContent_w,
428 this, content, action, error_desc)); 433 this, content, action, error_desc));
429 } 434 }
430 435
431 void BaseChannel::StartConnectionMonitor(int cms) { 436 void BaseChannel::StartConnectionMonitor(int cms) {
432 // We pass in the BaseChannel instead of the rtp_transport_ 437 // We pass in the BaseChannel instead of the rtp_dtls_transport_
433 // because if the rtp_transport_ changes, the ConnectionMonitor 438 // because if the rtp_dtls_transport_ changes, the ConnectionMonitor
434 // would be pointing to the wrong TransportChannel. 439 // would be pointing to the wrong TransportChannel.
435 // We pass in the network thread because on that thread connection monitor 440 // We pass in the network thread because on that thread connection monitor
436 // will call BaseChannel::GetConnectionStats which must be called on the 441 // will call BaseChannel::GetConnectionStats which must be called on the
437 // network thread. 442 // network thread.
438 connection_monitor_.reset( 443 connection_monitor_.reset(
439 new ConnectionMonitor(this, network_thread(), rtc::Thread::Current())); 444 new ConnectionMonitor(this, network_thread(), rtc::Thread::Current()));
440 connection_monitor_->SignalUpdate.connect( 445 connection_monitor_->SignalUpdate.connect(
441 this, &BaseChannel::OnConnectionMonitorUpdate); 446 this, &BaseChannel::OnConnectionMonitorUpdate);
442 connection_monitor_->Start(cms); 447 connection_monitor_->Start(cms);
443 } 448 }
444 449
445 void BaseChannel::StopConnectionMonitor() { 450 void BaseChannel::StopConnectionMonitor() {
446 if (connection_monitor_) { 451 if (connection_monitor_) {
447 connection_monitor_->Stop(); 452 connection_monitor_->Stop();
448 connection_monitor_.reset(); 453 connection_monitor_.reset();
449 } 454 }
450 } 455 }
451 456
452 bool BaseChannel::GetConnectionStats(ConnectionInfos* infos) { 457 bool BaseChannel::GetConnectionStats(ConnectionInfos* infos) {
453 RTC_DCHECK(network_thread_->IsCurrent()); 458 RTC_DCHECK(network_thread_->IsCurrent());
454 return rtp_transport_->GetStats(infos); 459 return rtp_dtls_transport_->ice_transport()->GetStats(infos);
455 } 460 }
456 461
457 bool BaseChannel::NeedsRtcpTransport() { 462 bool BaseChannel::NeedsRtcpTransport() {
458 // If this BaseChannel doesn't require RTCP mux and we haven't fully 463 // If this BaseChannel doesn't require RTCP mux and we haven't fully
459 // negotiated RTCP mux, we need an RTCP transport. 464 // negotiated RTCP mux, we need an RTCP transport.
460 return !rtcp_mux_required_ && !rtcp_mux_filter_.IsFullyActive(); 465 return !rtcp_mux_required_ && !rtcp_mux_filter_.IsFullyActive();
461 } 466 }
462 467
463 bool BaseChannel::IsReadyToReceiveMedia_w() const { 468 bool BaseChannel::IsReadyToReceiveMedia_w() const {
464 // Receive data if we are enabled and have local content, 469 // Receive data if we are enabled and have local content,
(...skipping 28 matching lines...) Expand all
493 int BaseChannel::SetOption(SocketType type, rtc::Socket::Option opt, 498 int BaseChannel::SetOption(SocketType type, rtc::Socket::Option opt,
494 int value) { 499 int value) {
495 return network_thread_->Invoke<int>( 500 return network_thread_->Invoke<int>(
496 RTC_FROM_HERE, Bind(&BaseChannel::SetOption_n, this, type, opt, value)); 501 RTC_FROM_HERE, Bind(&BaseChannel::SetOption_n, this, type, opt, value));
497 } 502 }
498 503
499 int BaseChannel::SetOption_n(SocketType type, 504 int BaseChannel::SetOption_n(SocketType type,
500 rtc::Socket::Option opt, 505 rtc::Socket::Option opt,
501 int value) { 506 int value) {
502 RTC_DCHECK(network_thread_->IsCurrent()); 507 RTC_DCHECK(network_thread_->IsCurrent());
503 TransportChannel* channel = nullptr; 508 DtlsTransportInternal* transport = nullptr;
504 switch (type) { 509 switch (type) {
505 case ST_RTP: 510 case ST_RTP:
506 channel = rtp_transport_; 511 transport = rtp_dtls_transport_;
507 socket_options_.push_back( 512 socket_options_.push_back(
508 std::pair<rtc::Socket::Option, int>(opt, value)); 513 std::pair<rtc::Socket::Option, int>(opt, value));
509 break; 514 break;
510 case ST_RTCP: 515 case ST_RTCP:
511 channel = rtcp_transport_; 516 transport = rtcp_dtls_transport_;
512 rtcp_socket_options_.push_back( 517 rtcp_socket_options_.push_back(
513 std::pair<rtc::Socket::Option, int>(opt, value)); 518 std::pair<rtc::Socket::Option, int>(opt, value));
514 break; 519 break;
515 } 520 }
516 return channel ? channel->SetOption(opt, value) : -1; 521 return transport ? transport->ice_transport()->SetOption(opt, value) : -1;
517 } 522 }
518 523
519 bool BaseChannel::SetCryptoOptions(const rtc::CryptoOptions& crypto_options) { 524 bool BaseChannel::SetCryptoOptions(const rtc::CryptoOptions& crypto_options) {
520 crypto_options_ = crypto_options; 525 crypto_options_ = crypto_options;
521 return true; 526 return true;
522 } 527 }
523 528
524 void BaseChannel::OnWritableState(rtc::PacketTransportInterface* transport) { 529 void BaseChannel::OnWritableState(rtc::PacketTransportInterface* transport) {
525 RTC_DCHECK(transport == rtp_transport_ || transport == rtcp_transport_); 530 RTC_DCHECK(transport == rtp_dtls_transport_ ||
531 transport == rtcp_dtls_transport_);
526 RTC_DCHECK(network_thread_->IsCurrent()); 532 RTC_DCHECK(network_thread_->IsCurrent());
527 UpdateWritableState_n(); 533 UpdateWritableState_n();
528 } 534 }
529 535
530 void BaseChannel::OnPacketRead(rtc::PacketTransportInterface* transport, 536 void BaseChannel::OnPacketRead(rtc::PacketTransportInterface* transport,
531 const char* data, 537 const char* data,
532 size_t len, 538 size_t len,
533 const rtc::PacketTime& packet_time, 539 const rtc::PacketTime& packet_time,
534 int flags) { 540 int flags) {
535 TRACE_EVENT0("webrtc", "BaseChannel::OnPacketRead"); 541 TRACE_EVENT0("webrtc", "BaseChannel::OnPacketRead");
536 // OnPacketRead gets called from P2PSocket; now pass data to MediaEngine 542 // OnPacketRead gets called from P2PSocket; now pass data to MediaEngine
537 RTC_DCHECK(network_thread_->IsCurrent()); 543 RTC_DCHECK(network_thread_->IsCurrent());
538 544
539 // When using RTCP multiplexing we might get RTCP packets on the RTP 545 // When using RTCP multiplexing we might get RTCP packets on the RTP
540 // transport. We feed RTP traffic into the demuxer to determine if it is RTCP. 546 // transport. We feed RTP traffic into the demuxer to determine if it is RTCP.
541 bool rtcp = PacketIsRtcp(transport, data, len); 547 bool rtcp = PacketIsRtcp(transport, data, len);
542 rtc::CopyOnWriteBuffer packet(data, len); 548 rtc::CopyOnWriteBuffer packet(data, len);
543 HandlePacket(rtcp, &packet, packet_time); 549 HandlePacket(rtcp, &packet, packet_time);
544 } 550 }
545 551
546 void BaseChannel::OnReadyToSend(rtc::PacketTransportInterface* transport) { 552 void BaseChannel::OnReadyToSend(rtc::PacketTransportInterface* transport) {
547 RTC_DCHECK(transport == rtp_transport_ || transport == rtcp_transport_); 553 RTC_DCHECK(transport == rtp_dtls_transport_ ||
548 SetTransportChannelReadyToSend(transport == rtcp_transport_, true); 554 transport == rtcp_dtls_transport_);
555 SetTransportChannelReadyToSend(transport == rtcp_dtls_transport_, true);
549 } 556 }
550 557
551 void BaseChannel::OnDtlsState(TransportChannel* channel, 558 void BaseChannel::OnDtlsState(DtlsTransportInternal* transport,
552 DtlsTransportState state) { 559 DtlsTransportState state) {
553 if (!ShouldSetupDtlsSrtp_n()) { 560 if (!ShouldSetupDtlsSrtp_n()) {
554 return; 561 return;
555 } 562 }
556 563
557 // Reset the srtp filter if it's not the CONNECTED state. For the CONNECTED 564 // Reset the srtp filter if it's not the CONNECTED state. For the CONNECTED
558 // state, setting up DTLS-SRTP context is deferred to ChannelWritable_w to 565 // state, setting up DTLS-SRTP context is deferred to ChannelWritable_w to
559 // cover other scenarios like the whole channel is writable (not just this 566 // cover other scenarios like the whole transport is writable (not just this
560 // TransportChannel) or when TransportChannel is attached after DTLS is 567 // TransportChannel) or when TransportChannel is attached after DTLS is
561 // negotiated. 568 // negotiated.
562 if (state != DTLS_TRANSPORT_CONNECTED) { 569 if (state != DTLS_TRANSPORT_CONNECTED) {
563 srtp_filter_.ResetParams(); 570 srtp_filter_.ResetParams();
564 } 571 }
565 } 572 }
566 573
567 void BaseChannel::OnSelectedCandidatePairChanged( 574 void BaseChannel::OnSelectedCandidatePairChanged(
568 TransportChannel* channel, 575 IceTransportInternal* ice_transport,
569 CandidatePairInterface* selected_candidate_pair, 576 CandidatePairInterface* selected_candidate_pair,
570 int last_sent_packet_id, 577 int last_sent_packet_id,
571 bool ready_to_send) { 578 bool ready_to_send) {
572 RTC_DCHECK(channel == rtp_transport_ || channel == rtcp_transport_); 579 RTC_DCHECK(ice_transport == rtp_dtls_transport_->ice_transport() ||
580 ice_transport == rtcp_dtls_transport_->ice_transport());
573 RTC_DCHECK(network_thread_->IsCurrent()); 581 RTC_DCHECK(network_thread_->IsCurrent());
574 selected_candidate_pair_ = selected_candidate_pair; 582 selected_candidate_pair_ = selected_candidate_pair;
575 std::string transport_name = channel->transport_name(); 583 std::string transport_name = ice_transport->transport_name();
576 rtc::NetworkRoute network_route; 584 rtc::NetworkRoute network_route;
577 if (selected_candidate_pair) { 585 if (selected_candidate_pair) {
578 network_route = rtc::NetworkRoute( 586 network_route = rtc::NetworkRoute(
579 ready_to_send, selected_candidate_pair->local_candidate().network_id(), 587 ready_to_send, selected_candidate_pair->local_candidate().network_id(),
580 selected_candidate_pair->remote_candidate().network_id(), 588 selected_candidate_pair->remote_candidate().network_id(),
581 last_sent_packet_id); 589 last_sent_packet_id);
582 590
583 UpdateTransportOverhead(); 591 UpdateTransportOverhead();
584 } 592 }
585 invoker_.AsyncInvoke<void>( 593 invoker_.AsyncInvoke<void>(
586 RTC_FROM_HERE, worker_thread_, 594 RTC_FROM_HERE, worker_thread_,
587 Bind(&MediaChannel::OnNetworkRouteChanged, media_channel_, transport_name, 595 Bind(&MediaChannel::OnNetworkRouteChanged, media_channel_, transport_name,
588 network_route)); 596 network_route));
589 } 597 }
590 598
591 void BaseChannel::SetTransportChannelReadyToSend(bool rtcp, bool ready) { 599 void BaseChannel::SetTransportChannelReadyToSend(bool rtcp, bool ready) {
592 RTC_DCHECK(network_thread_->IsCurrent()); 600 RTC_DCHECK(network_thread_->IsCurrent());
593 if (rtcp) { 601 if (rtcp) {
594 rtcp_ready_to_send_ = ready; 602 rtcp_ready_to_send_ = ready;
595 } else { 603 } else {
596 rtp_ready_to_send_ = ready; 604 rtp_ready_to_send_ = ready;
597 } 605 }
598 606
599 bool ready_to_send = 607 bool ready_to_send =
600 (rtp_ready_to_send_ && 608 (rtp_ready_to_send_ &&
601 // In the case of rtcp mux |rtcp_transport_| will be null. 609 // In the case of rtcp mux |rtcp_dtls_transport_| will be null.
602 (rtcp_ready_to_send_ || !rtcp_transport_)); 610 (rtcp_ready_to_send_ || !rtcp_dtls_transport_));
603 611
604 invoker_.AsyncInvoke<void>( 612 invoker_.AsyncInvoke<void>(
605 RTC_FROM_HERE, worker_thread_, 613 RTC_FROM_HERE, worker_thread_,
606 Bind(&MediaChannel::OnReadyToSend, media_channel_, ready_to_send)); 614 Bind(&MediaChannel::OnReadyToSend, media_channel_, ready_to_send));
607 } 615 }
608 616
609 bool BaseChannel::PacketIsRtcp(const rtc::PacketTransportInterface* transport, 617 bool BaseChannel::PacketIsRtcp(const rtc::PacketTransportInterface* transport,
610 const char* data, 618 const char* data,
611 size_t len) { 619 size_t len) {
612 return (transport == rtcp_transport_ || 620 return (transport == rtcp_dtls_transport_ ||
613 rtcp_mux_filter_.DemuxRtcp(data, static_cast<int>(len))); 621 rtcp_mux_filter_.DemuxRtcp(data, static_cast<int>(len)));
614 } 622 }
615 623
616 bool BaseChannel::SendPacket(bool rtcp, 624 bool BaseChannel::SendPacket(bool rtcp,
617 rtc::CopyOnWriteBuffer* packet, 625 rtc::CopyOnWriteBuffer* packet,
618 const rtc::PacketOptions& options) { 626 const rtc::PacketOptions& options) {
619 // SendPacket gets called from MediaEngine, on a pacer or an encoder thread. 627 // SendPacket gets called from MediaEngine, on a pacer or an encoder thread.
620 // If the thread is not our network thread, we will post to our network 628 // If the thread is not our network thread, we will post to our network
621 // so that the real work happens on our network. This avoids us having to 629 // so that the real work happens on our network. This avoids us having to
622 // synchronize access to all the pieces of the send path, including 630 // synchronize access to all the pieces of the send path, including
623 // SRTP and the inner workings of the transport channels. 631 // SRTP and the inner workings of the transport channels.
624 // The only downside is that we can't return a proper failure code if 632 // The only downside is that we can't return a proper failure code if
625 // needed. Since UDP is unreliable anyway, this should be a non-issue. 633 // needed. Since UDP is unreliable anyway, this should be a non-issue.
626 if (!network_thread_->IsCurrent()) { 634 if (!network_thread_->IsCurrent()) {
627 // Avoid a copy by transferring the ownership of the packet data. 635 // Avoid a copy by transferring the ownership of the packet data.
628 int message_id = rtcp ? MSG_SEND_RTCP_PACKET : MSG_SEND_RTP_PACKET; 636 int message_id = rtcp ? MSG_SEND_RTCP_PACKET : MSG_SEND_RTP_PACKET;
629 SendPacketMessageData* data = new SendPacketMessageData; 637 SendPacketMessageData* data = new SendPacketMessageData;
630 data->packet = std::move(*packet); 638 data->packet = std::move(*packet);
631 data->options = options; 639 data->options = options;
632 network_thread_->Post(RTC_FROM_HERE, this, message_id, data); 640 network_thread_->Post(RTC_FROM_HERE, this, message_id, data);
633 return true; 641 return true;
634 } 642 }
635 TRACE_EVENT0("webrtc", "BaseChannel::SendPacket"); 643 TRACE_EVENT0("webrtc", "BaseChannel::SendPacket");
636 644
637 // Now that we are on the correct thread, ensure we have a place to send this 645 // Now that we are on the correct thread, ensure we have a place to send this
638 // packet before doing anything. (We might get RTCP packets that we don't 646 // packet before doing anything. (We might get RTCP packets that we don't
639 // intend to send.) If we've negotiated RTCP mux, send RTCP over the RTP 647 // intend to send.) If we've negotiated RTCP mux, send RTCP over the RTP
640 // transport. 648 // transport.
641 TransportChannel* channel = 649 DtlsTransportInternal* transport = (!rtcp || rtcp_mux_filter_.IsActive())
642 (!rtcp || rtcp_mux_filter_.IsActive()) ? rtp_transport_ : rtcp_transport_; 650 ? rtp_dtls_transport_
643 if (!channel || !channel->writable()) { 651 : rtcp_dtls_transport_;
652 if (!transport || !transport->writable()) {
644 return false; 653 return false;
645 } 654 }
646 655
647 // Protect ourselves against crazy data. 656 // Protect ourselves against crazy data.
648 if (!ValidPacket(rtcp, packet)) { 657 if (!ValidPacket(rtcp, packet)) {
649 LOG(LS_ERROR) << "Dropping outgoing " << content_name_ << " " 658 LOG(LS_ERROR) << "Dropping outgoing " << content_name_ << " "
650 << PacketType(rtcp) 659 << PacketType(rtcp)
651 << " packet: wrong size=" << packet->size(); 660 << " packet: wrong size=" << packet->size();
652 return false; 661 return false;
653 } 662 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 // However, there shouldn't be any RTP packets sent before SRTP is set up 733 // However, there shouldn't be any RTP packets sent before SRTP is set up
725 // (and SetSend(true) is called). 734 // (and SetSend(true) is called).
726 LOG(LS_ERROR) << "Can't send outgoing RTP packet when SRTP is inactive" 735 LOG(LS_ERROR) << "Can't send outgoing RTP packet when SRTP is inactive"
727 << " and crypto is required"; 736 << " and crypto is required";
728 RTC_NOTREACHED(); 737 RTC_NOTREACHED();
729 return false; 738 return false;
730 } 739 }
731 740
732 // Bon voyage. 741 // Bon voyage.
733 int flags = (secure() && secure_dtls()) ? PF_SRTP_BYPASS : PF_NORMAL; 742 int flags = (secure() && secure_dtls()) ? PF_SRTP_BYPASS : PF_NORMAL;
734 int ret = channel->SendPacket(packet->data<char>(), packet->size(), 743 int ret = transport->SendPacket(packet->data<char>(), packet->size(),
735 updated_options, flags); 744 updated_options, flags);
736 if (ret != static_cast<int>(packet->size())) { 745 if (ret != static_cast<int>(packet->size())) {
737 if (channel->GetError() == ENOTCONN) { 746 if (transport->GetError() == ENOTCONN) {
738 LOG(LS_WARNING) << "Got ENOTCONN from transport."; 747 LOG(LS_WARNING) << "Got ENOTCONN from transport.";
739 SetTransportChannelReadyToSend(rtcp, false); 748 SetTransportChannelReadyToSend(rtcp, false);
740 } 749 }
741 return false; 750 return false;
742 } 751 }
743 return true; 752 return true;
744 } 753 }
745 754
746 bool BaseChannel::WantsPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet) { 755 bool BaseChannel::WantsPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet) {
747 // Protect ourselves against crazy data. 756 // Protect ourselves against crazy data.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 } 811 }
803 } 812 }
804 813
805 packet->SetSize(len); 814 packet->SetSize(len);
806 } else if (srtp_required_) { 815 } else if (srtp_required_) {
807 // Our session description indicates that SRTP is required, but we got a 816 // Our session description indicates that SRTP is required, but we got a
808 // packet before our SRTP filter is active. This means either that 817 // packet before our SRTP filter is active. This means either that
809 // a) we got SRTP packets before we received the SDES keys, in which case 818 // a) we got SRTP packets before we received the SDES keys, in which case
810 // we can't decrypt it anyway, or 819 // we can't decrypt it anyway, or
811 // b) we got SRTP packets before DTLS completed on both the RTP and RTCP 820 // b) we got SRTP packets before DTLS completed on both the RTP and RTCP
812 // channels, so we haven't yet extracted keys, even if DTLS did complete 821 // transports, so we haven't yet extracted keys, even if DTLS did
813 // on the channel that the packets are being sent on. It's really good 822 // complete on the transport that the packets are being sent on. It's
814 // practice to wait for both RTP and RTCP to be good to go before sending 823 // really good practice to wait for both RTP and RTCP to be good to go
815 // media, to prevent weird failure modes, so it's fine for us to just eat 824 // before sending media, to prevent weird failure modes, so it's fine
816 // packets here. This is all sidestepped if RTCP mux is used anyway. 825 // for us to just eat packets here. This is all sidestepped if RTCP mux
826 // is used anyway.
817 LOG(LS_WARNING) << "Can't process incoming " << PacketType(rtcp) 827 LOG(LS_WARNING) << "Can't process incoming " << PacketType(rtcp)
818 << " packet when SRTP is inactive and crypto is required"; 828 << " packet when SRTP is inactive and crypto is required";
819 return; 829 return;
820 } 830 }
821 831
822 invoker_.AsyncInvoke<void>( 832 invoker_.AsyncInvoke<void>(
823 RTC_FROM_HERE, worker_thread_, 833 RTC_FROM_HERE, worker_thread_,
824 Bind(&BaseChannel::OnPacketReceived, this, rtcp, *packet, packet_time)); 834 Bind(&BaseChannel::OnPacketReceived, this, rtcp, *packet, packet_time));
825 } 835 }
826 836
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 RTC_DCHECK(worker_thread_ == rtc::Thread::Current()); 890 RTC_DCHECK(worker_thread_ == rtc::Thread::Current());
881 if (!enabled_) 891 if (!enabled_)
882 return; 892 return;
883 893
884 LOG(LS_INFO) << "Channel disabled"; 894 LOG(LS_INFO) << "Channel disabled";
885 enabled_ = false; 895 enabled_ = false;
886 UpdateMediaSendRecvState_w(); 896 UpdateMediaSendRecvState_w();
887 } 897 }
888 898
889 void BaseChannel::UpdateWritableState_n() { 899 void BaseChannel::UpdateWritableState_n() {
890 if (rtp_transport_ && rtp_transport_->writable() && 900 if (rtp_dtls_transport_ && rtp_dtls_transport_->writable() &&
891 (!rtcp_transport_ || rtcp_transport_->writable())) { 901 (!rtcp_dtls_transport_ || rtcp_dtls_transport_->writable())) {
892 ChannelWritable_n(); 902 ChannelWritable_n();
893 } else { 903 } else {
894 ChannelNotWritable_n(); 904 ChannelNotWritable_n();
895 } 905 }
896 } 906 }
897 907
898 void BaseChannel::ChannelWritable_n() { 908 void BaseChannel::ChannelWritable_n() {
899 RTC_DCHECK(network_thread_->IsCurrent()); 909 RTC_DCHECK(network_thread_->IsCurrent());
900 if (writable_) { 910 if (writable_) {
901 return; 911 return;
(...skipping 20 matching lines...) Expand all
922 invoker_.AsyncInvoke<void>( 932 invoker_.AsyncInvoke<void>(
923 RTC_FROM_HERE, signaling_thread(), 933 RTC_FROM_HERE, signaling_thread(),
924 Bind(&BaseChannel::SignalDtlsSrtpSetupFailure_s, this, rtcp)); 934 Bind(&BaseChannel::SignalDtlsSrtpSetupFailure_s, this, rtcp));
925 } 935 }
926 936
927 void BaseChannel::SignalDtlsSrtpSetupFailure_s(bool rtcp) { 937 void BaseChannel::SignalDtlsSrtpSetupFailure_s(bool rtcp) {
928 RTC_DCHECK(signaling_thread() == rtc::Thread::Current()); 938 RTC_DCHECK(signaling_thread() == rtc::Thread::Current());
929 SignalDtlsSrtpSetupFailure(this, rtcp); 939 SignalDtlsSrtpSetupFailure(this, rtcp);
930 } 940 }
931 941
932 bool BaseChannel::SetDtlsSrtpCryptoSuites_n(TransportChannel* tc, bool rtcp) { 942 bool BaseChannel::SetDtlsSrtpCryptoSuites_n(DtlsTransportInternal* transport,
943 bool rtcp) {
933 std::vector<int> crypto_suites; 944 std::vector<int> crypto_suites;
934 // We always use the default SRTP crypto suites for RTCP, but we may use 945 // We always use the default SRTP crypto suites for RTCP, but we may use
935 // different crypto suites for RTP depending on the media type. 946 // different crypto suites for RTP depending on the media type.
936 if (!rtcp) { 947 if (!rtcp) {
937 GetSrtpCryptoSuites_n(&crypto_suites); 948 GetSrtpCryptoSuites_n(&crypto_suites);
938 } else { 949 } else {
939 GetDefaultSrtpCryptoSuites(crypto_options(), &crypto_suites); 950 GetDefaultSrtpCryptoSuites(crypto_options(), &crypto_suites);
940 } 951 }
941 return tc->SetSrtpCryptoSuites(crypto_suites); 952 return transport->SetSrtpCryptoSuites(crypto_suites);
942 } 953 }
943 954
944 bool BaseChannel::ShouldSetupDtlsSrtp_n() const { 955 bool BaseChannel::ShouldSetupDtlsSrtp_n() const {
945 // Since DTLS is applied to all channels, checking RTP should be enough. 956 // Since DTLS is applied to all transports, checking RTP should be enough.
946 return rtp_transport_ && rtp_transport_->IsDtlsActive(); 957 return rtp_dtls_transport_ && rtp_dtls_transport_->IsDtlsActive();
947 } 958 }
948 959
949 // This function returns true if either DTLS-SRTP is not in use 960 // This function returns true if either DTLS-SRTP is not in use
950 // *or* DTLS-SRTP is successfully set up. 961 // *or* DTLS-SRTP is successfully set up.
951 bool BaseChannel::SetupDtlsSrtp_n(bool rtcp_channel) { 962 bool BaseChannel::SetupDtlsSrtp_n(bool rtcp) {
952 RTC_DCHECK(network_thread_->IsCurrent()); 963 RTC_DCHECK(network_thread_->IsCurrent());
953 bool ret = false; 964 bool ret = false;
954 965
955 TransportChannel* channel = rtcp_channel ? rtcp_transport_ : rtp_transport_; 966 DtlsTransportInternal* transport =
967 rtcp ? rtcp_dtls_transport_ : rtp_dtls_transport_;
956 968
957 RTC_DCHECK(channel->IsDtlsActive()); 969 RTC_DCHECK(transport->IsDtlsActive());
958 970
959 int selected_crypto_suite; 971 int selected_crypto_suite;
960 972
961 if (!channel->GetSrtpCryptoSuite(&selected_crypto_suite)) { 973 if (!transport->GetSrtpCryptoSuite(&selected_crypto_suite)) {
962 LOG(LS_ERROR) << "No DTLS-SRTP selected crypto suite"; 974 LOG(LS_ERROR) << "No DTLS-SRTP selected crypto suite";
963 return false; 975 return false;
964 } 976 }
965 977
966 LOG(LS_INFO) << "Installing keys from DTLS-SRTP on " 978 LOG(LS_INFO) << "Installing keys from DTLS-SRTP on " << content_name() << " "
967 << content_name() << " " 979 << PacketType(rtcp);
968 << PacketType(rtcp_channel);
969 980
970 int key_len; 981 int key_len;
971 int salt_len; 982 int salt_len;
972 if (!rtc::GetSrtpKeyAndSaltLengths(selected_crypto_suite, &key_len, 983 if (!rtc::GetSrtpKeyAndSaltLengths(selected_crypto_suite, &key_len,
973 &salt_len)) { 984 &salt_len)) {
974 LOG(LS_ERROR) << "Unknown DTLS-SRTP crypto suite" << selected_crypto_suite; 985 LOG(LS_ERROR) << "Unknown DTLS-SRTP crypto suite" << selected_crypto_suite;
975 return false; 986 return false;
976 } 987 }
977 988
978 // OK, we're now doing DTLS (RFC 5764) 989 // OK, we're now doing DTLS (RFC 5764)
979 std::vector<unsigned char> dtls_buffer(key_len * 2 + salt_len * 2); 990 std::vector<unsigned char> dtls_buffer(key_len * 2 + salt_len * 2);
980 991
981 // RFC 5705 exporter using the RFC 5764 parameters 992 // RFC 5705 exporter using the RFC 5764 parameters
982 if (!channel->ExportKeyingMaterial( 993 if (!transport->ExportKeyingMaterial(kDtlsSrtpExporterLabel, NULL, 0, false,
983 kDtlsSrtpExporterLabel, 994 &dtls_buffer[0], dtls_buffer.size())) {
984 NULL, 0, false,
985 &dtls_buffer[0], dtls_buffer.size())) {
986 LOG(LS_WARNING) << "DTLS-SRTP key export failed"; 995 LOG(LS_WARNING) << "DTLS-SRTP key export failed";
987 RTC_NOTREACHED(); // This should never happen 996 RTC_NOTREACHED(); // This should never happen
988 return false; 997 return false;
989 } 998 }
990 999
991 // Sync up the keys with the DTLS-SRTP interface 1000 // Sync up the keys with the DTLS-SRTP interface
992 std::vector<unsigned char> client_write_key(key_len + salt_len); 1001 std::vector<unsigned char> client_write_key(key_len + salt_len);
993 std::vector<unsigned char> server_write_key(key_len + salt_len); 1002 std::vector<unsigned char> server_write_key(key_len + salt_len);
994 size_t offset = 0; 1003 size_t offset = 0;
995 memcpy(&client_write_key[0], &dtls_buffer[offset], key_len); 1004 memcpy(&client_write_key[0], &dtls_buffer[offset], key_len);
996 offset += key_len; 1005 offset += key_len;
997 memcpy(&server_write_key[0], &dtls_buffer[offset], key_len); 1006 memcpy(&server_write_key[0], &dtls_buffer[offset], key_len);
998 offset += key_len; 1007 offset += key_len;
999 memcpy(&client_write_key[key_len], &dtls_buffer[offset], salt_len); 1008 memcpy(&client_write_key[key_len], &dtls_buffer[offset], salt_len);
1000 offset += salt_len; 1009 offset += salt_len;
1001 memcpy(&server_write_key[key_len], &dtls_buffer[offset], salt_len); 1010 memcpy(&server_write_key[key_len], &dtls_buffer[offset], salt_len);
1002 1011
1003 std::vector<unsigned char> *send_key, *recv_key; 1012 std::vector<unsigned char> *send_key, *recv_key;
1004 rtc::SSLRole role; 1013 rtc::SSLRole role;
1005 if (!channel->GetSslRole(&role)) { 1014 if (!transport->GetSslRole(&role)) {
1006 LOG(LS_WARNING) << "GetSslRole failed"; 1015 LOG(LS_WARNING) << "GetSslRole failed";
1007 return false; 1016 return false;
1008 } 1017 }
1009 1018
1010 if (role == rtc::SSL_SERVER) { 1019 if (role == rtc::SSL_SERVER) {
1011 send_key = &server_write_key; 1020 send_key = &server_write_key;
1012 recv_key = &client_write_key; 1021 recv_key = &client_write_key;
1013 } else { 1022 } else {
1014 send_key = &client_write_key; 1023 send_key = &client_write_key;
1015 recv_key = &server_write_key; 1024 recv_key = &server_write_key;
1016 } 1025 }
1017 1026
1018 if (rtcp_channel) { 1027 if (rtcp) {
1019 ret = srtp_filter_.SetRtcpParams(selected_crypto_suite, &(*send_key)[0], 1028 ret = srtp_filter_.SetRtcpParams(selected_crypto_suite, &(*send_key)[0],
1020 static_cast<int>(send_key->size()), 1029 static_cast<int>(send_key->size()),
1021 selected_crypto_suite, &(*recv_key)[0], 1030 selected_crypto_suite, &(*recv_key)[0],
1022 static_cast<int>(recv_key->size())); 1031 static_cast<int>(recv_key->size()));
1023 } else { 1032 } else {
1024 ret = srtp_filter_.SetRtpParams(selected_crypto_suite, &(*send_key)[0], 1033 ret = srtp_filter_.SetRtpParams(selected_crypto_suite, &(*send_key)[0],
1025 static_cast<int>(send_key->size()), 1034 static_cast<int>(send_key->size()),
1026 selected_crypto_suite, &(*recv_key)[0], 1035 selected_crypto_suite, &(*recv_key)[0],
1027 static_cast<int>(recv_key->size())); 1036 static_cast<int>(recv_key->size()));
1028 } 1037 }
(...skipping 14 matching lines...) Expand all
1043 1052
1044 if (!ShouldSetupDtlsSrtp_n()) { 1053 if (!ShouldSetupDtlsSrtp_n()) {
1045 return; 1054 return;
1046 } 1055 }
1047 1056
1048 if (!SetupDtlsSrtp_n(false)) { 1057 if (!SetupDtlsSrtp_n(false)) {
1049 SignalDtlsSrtpSetupFailure_n(false); 1058 SignalDtlsSrtpSetupFailure_n(false);
1050 return; 1059 return;
1051 } 1060 }
1052 1061
1053 if (rtcp_transport_) { 1062 if (rtcp_dtls_transport_) {
1054 if (!SetupDtlsSrtp_n(true)) { 1063 if (!SetupDtlsSrtp_n(true)) {
1055 SignalDtlsSrtpSetupFailure_n(true); 1064 SignalDtlsSrtpSetupFailure_n(true);
1056 return; 1065 return;
1057 } 1066 }
1058 } 1067 }
1059 } 1068 }
1060 1069
1061 void BaseChannel::ChannelNotWritable_n() { 1070 void BaseChannel::ChannelNotWritable_n() {
1062 RTC_DCHECK(network_thread_->IsCurrent()); 1071 RTC_DCHECK(network_thread_->IsCurrent());
1063 if (!writable_) 1072 if (!writable_)
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1095 return false; 1104 return false;
1096 } 1105 }
1097 1106
1098 if (!SetRtcpMux_n(content->rtcp_mux(), action, src, error_desc)) { 1107 if (!SetRtcpMux_n(content->rtcp_mux(), action, src, error_desc)) {
1099 return false; 1108 return false;
1100 } 1109 }
1101 1110
1102 return true; 1111 return true;
1103 } 1112 }
1104 1113
1105 // |dtls| will be set to true if DTLS is active for transport channel and 1114 // |dtls| will be set to true if DTLS is active for transport and crypto is
1106 // crypto is empty. 1115 // empty.
1107 bool BaseChannel::CheckSrtpConfig_n(const std::vector<CryptoParams>& cryptos, 1116 bool BaseChannel::CheckSrtpConfig_n(const std::vector<CryptoParams>& cryptos,
1108 bool* dtls, 1117 bool* dtls,
1109 std::string* error_desc) { 1118 std::string* error_desc) {
1110 *dtls = rtp_transport_->IsDtlsActive(); 1119 *dtls = rtp_dtls_transport_->IsDtlsActive();
1111 if (*dtls && !cryptos.empty()) { 1120 if (*dtls && !cryptos.empty()) {
1112 SafeSetError("Cryptos must be empty when DTLS is active.", error_desc); 1121 SafeSetError("Cryptos must be empty when DTLS is active.", error_desc);
1113 return false; 1122 return false;
1114 } 1123 }
1115 return true; 1124 return true;
1116 } 1125 }
1117 1126
1118 bool BaseChannel::SetSrtp_n(const std::vector<CryptoParams>& cryptos, 1127 bool BaseChannel::SetSrtp_n(const std::vector<CryptoParams>& cryptos,
1119 ContentAction action, 1128 ContentAction action,
1120 ContentSource src, 1129 ContentSource src,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1174 "contain 'a=rtcp-mux'.", 1183 "contain 'a=rtcp-mux'.",
1175 error_desc); 1184 error_desc);
1176 return false; 1185 return false;
1177 } 1186 }
1178 bool ret = false; 1187 bool ret = false;
1179 switch (action) { 1188 switch (action) {
1180 case CA_OFFER: 1189 case CA_OFFER:
1181 ret = rtcp_mux_filter_.SetOffer(enable, src); 1190 ret = rtcp_mux_filter_.SetOffer(enable, src);
1182 break; 1191 break;
1183 case CA_PRANSWER: 1192 case CA_PRANSWER:
1184 // This may activate RTCP muxing, but we don't yet destroy the channel 1193 // This may activate RTCP muxing, but we don't yet destroy the transport
1185 // because the final answer may deactivate it. 1194 // because the final answer may deactivate it.
1186 ret = rtcp_mux_filter_.SetProvisionalAnswer(enable, src); 1195 ret = rtcp_mux_filter_.SetProvisionalAnswer(enable, src);
1187 break; 1196 break;
1188 case CA_ANSWER: 1197 case CA_ANSWER:
1189 ret = rtcp_mux_filter_.SetAnswer(enable, src); 1198 ret = rtcp_mux_filter_.SetAnswer(enable, src);
1190 if (ret && rtcp_mux_filter_.IsActive()) { 1199 if (ret && rtcp_mux_filter_.IsActive()) {
1191 // We activated RTCP mux, close down the RTCP transport. 1200 // We activated RTCP mux, close down the RTCP transport.
1192 LOG(LS_INFO) << "Enabling rtcp-mux for " << content_name() 1201 LOG(LS_INFO) << "Enabling rtcp-mux for " << content_name()
1193 << " by destroying RTCP transport channel for " 1202 << " by destroying RTCP transport for "
1194 << transport_name(); 1203 << transport_name();
1195 if (rtcp_transport()) { 1204 if (rtcp_dtls_transport()) {
1196 SetTransportChannel_n(true, nullptr); 1205 SetTransport_n(true, nullptr);
1197 SignalRtcpMuxFullyActive(rtp_transport()->transport_name()); 1206 SignalRtcpMuxFullyActive(rtp_dtls_transport()->transport_name());
1198 } 1207 }
1199 UpdateWritableState_n(); 1208 UpdateWritableState_n();
1200 SetTransportChannelReadyToSend(true, false); 1209 SetTransportChannelReadyToSend(true, false);
1201 } 1210 }
1202 break; 1211 break;
1203 case CA_UPDATE: 1212 case CA_UPDATE:
1204 // No RTCP mux info. 1213 // No RTCP mux info.
1205 ret = true; 1214 ret = true;
1206 break; 1215 break;
1207 default: 1216 default:
1208 break; 1217 break;
1209 } 1218 }
1210 if (!ret) { 1219 if (!ret) {
1211 SafeSetError("Failed to setup RTCP mux filter.", error_desc); 1220 SafeSetError("Failed to setup RTCP mux filter.", error_desc);
1212 return false; 1221 return false;
1213 } 1222 }
1214 // |rtcp_mux_filter_| can be active if |action| is CA_PRANSWER or 1223 // |rtcp_mux_filter_| can be active if |action| is CA_PRANSWER or
1215 // CA_ANSWER, but we only want to tear down the RTCP transport channel if we 1224 // CA_ANSWER, but we only want to tear down the RTCP transport if we received
1216 // received a final answer. 1225 // a final answer.
1217 if (rtcp_mux_filter_.IsActive()) { 1226 if (rtcp_mux_filter_.IsActive()) {
1218 // If the RTP transport is already writable, then so are we. 1227 // If the RTP transport is already writable, then so are we.
1219 if (rtp_transport_->writable()) { 1228 if (rtp_dtls_transport_->writable()) {
1220 ChannelWritable_n(); 1229 ChannelWritable_n();
1221 } 1230 }
1222 } 1231 }
1223 1232
1224 return true; 1233 return true;
1225 } 1234 }
1226 1235
1227 bool BaseChannel::AddRecvStream_w(const StreamParams& sp) { 1236 bool BaseChannel::AddRecvStream_w(const StreamParams& sp) {
1228 RTC_DCHECK(worker_thread() == rtc::Thread::Current()); 1237 RTC_DCHECK(worker_thread() == rtc::Thread::Current());
1229 return media_channel()->AddRecvStream(sp); 1238 return media_channel()->AddRecvStream(sp);
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
1469 1478
1470 VoiceChannel::~VoiceChannel() { 1479 VoiceChannel::~VoiceChannel() {
1471 TRACE_EVENT0("webrtc", "VoiceChannel::~VoiceChannel"); 1480 TRACE_EVENT0("webrtc", "VoiceChannel::~VoiceChannel");
1472 StopAudioMonitor(); 1481 StopAudioMonitor();
1473 StopMediaMonitor(); 1482 StopMediaMonitor();
1474 // this can't be done in the base class, since it calls a virtual 1483 // this can't be done in the base class, since it calls a virtual
1475 DisableMedia_w(); 1484 DisableMedia_w();
1476 Deinit(); 1485 Deinit();
1477 } 1486 }
1478 1487
1479 bool VoiceChannel::Init_w(TransportChannel* rtp_transport, 1488 bool VoiceChannel::Init_w(DtlsTransportInternal* rtp_dtls_transport,
1480 TransportChannel* rtcp_transport) { 1489 DtlsTransportInternal* rtcp_dtls_transport) {
1481 return BaseChannel::Init_w(rtp_transport, rtcp_transport); 1490 return BaseChannel::Init_w(rtp_dtls_transport, rtcp_dtls_transport);
1482 } 1491 }
1483 1492
1484 bool VoiceChannel::SetAudioSend(uint32_t ssrc, 1493 bool VoiceChannel::SetAudioSend(uint32_t ssrc,
1485 bool enable, 1494 bool enable,
1486 const AudioOptions* options, 1495 const AudioOptions* options,
1487 AudioSource* source) { 1496 AudioSource* source) {
1488 return InvokeOnWorker(RTC_FROM_HERE, 1497 return InvokeOnWorker(RTC_FROM_HERE,
1489 Bind(&VoiceMediaChannel::SetAudioSend, media_channel(), 1498 Bind(&VoiceMediaChannel::SetAudioSend, media_channel(),
1490 ssrc, enable, options, source)); 1499 ssrc, enable, options, source));
1491 } 1500 }
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
1871 bool rtcp_mux_required, 1880 bool rtcp_mux_required,
1872 bool srtp_required) 1881 bool srtp_required)
1873 : BaseChannel(worker_thread, 1882 : BaseChannel(worker_thread,
1874 network_thread, 1883 network_thread,
1875 signaling_thread, 1884 signaling_thread,
1876 media_channel, 1885 media_channel,
1877 content_name, 1886 content_name,
1878 rtcp_mux_required, 1887 rtcp_mux_required,
1879 srtp_required) {} 1888 srtp_required) {}
1880 1889
1881 bool VideoChannel::Init_w(TransportChannel* rtp_transport, 1890 bool VideoChannel::Init_w(DtlsTransportInternal* rtp_dtls_transport,
1882 TransportChannel* rtcp_transport) { 1891 DtlsTransportInternal* rtcp_dtls_transport) {
1883 return BaseChannel::Init_w(rtp_transport, rtcp_transport); 1892 return BaseChannel::Init_w(rtp_dtls_transport, rtcp_dtls_transport);
1884 } 1893 }
1885 1894
1886 VideoChannel::~VideoChannel() { 1895 VideoChannel::~VideoChannel() {
1887 TRACE_EVENT0("webrtc", "VideoChannel::~VideoChannel"); 1896 TRACE_EVENT0("webrtc", "VideoChannel::~VideoChannel");
1888 StopMediaMonitor(); 1897 StopMediaMonitor();
1889 // this can't be done in the base class, since it calls a virtual 1898 // this can't be done in the base class, since it calls a virtual
1890 DisableMedia_w(); 1899 DisableMedia_w();
1891 1900
1892 Deinit(); 1901 Deinit();
1893 } 1902 }
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
2141 2150
2142 RtpDataChannel::~RtpDataChannel() { 2151 RtpDataChannel::~RtpDataChannel() {
2143 TRACE_EVENT0("webrtc", "RtpDataChannel::~RtpDataChannel"); 2152 TRACE_EVENT0("webrtc", "RtpDataChannel::~RtpDataChannel");
2144 StopMediaMonitor(); 2153 StopMediaMonitor();
2145 // this can't be done in the base class, since it calls a virtual 2154 // this can't be done in the base class, since it calls a virtual
2146 DisableMedia_w(); 2155 DisableMedia_w();
2147 2156
2148 Deinit(); 2157 Deinit();
2149 } 2158 }
2150 2159
2151 bool RtpDataChannel::Init_w(TransportChannel* rtp_transport, 2160 bool RtpDataChannel::Init_w(DtlsTransportInternal* rtp_dtls_transport,
2152 TransportChannel* rtcp_transport) { 2161 DtlsTransportInternal* rtcp_dtls_transport) {
2153 if (!BaseChannel::Init_w(rtp_transport, rtcp_transport)) { 2162 if (!BaseChannel::Init_w(rtp_dtls_transport, rtcp_dtls_transport)) {
2154 return false; 2163 return false;
2155 } 2164 }
2156 media_channel()->SignalDataReceived.connect(this, 2165 media_channel()->SignalDataReceived.connect(this,
2157 &RtpDataChannel::OnDataReceived); 2166 &RtpDataChannel::OnDataReceived);
2158 media_channel()->SignalReadyToSend.connect( 2167 media_channel()->SignalReadyToSend.connect(
2159 this, &RtpDataChannel::OnDataChannelReadyToSend); 2168 this, &RtpDataChannel::OnDataChannelReadyToSend);
2160 return true; 2169 return true;
2161 } 2170 }
2162 2171
2163 bool RtpDataChannel::SendData(const SendDataParams& params, 2172 bool RtpDataChannel::SendData(const SendDataParams& params,
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
2389 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_READYTOSENDDATA, 2398 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_READYTOSENDDATA,
2390 new DataChannelReadyToSendMessageData(writable)); 2399 new DataChannelReadyToSendMessageData(writable));
2391 } 2400 }
2392 2401
2393 void RtpDataChannel::GetSrtpCryptoSuites_n( 2402 void RtpDataChannel::GetSrtpCryptoSuites_n(
2394 std::vector<int>* crypto_suites) const { 2403 std::vector<int>* crypto_suites) const {
2395 GetSupportedDataCryptoSuites(crypto_options(), crypto_suites); 2404 GetSupportedDataCryptoSuites(crypto_options(), crypto_suites);
2396 } 2405 }
2397 2406
2398 } // namespace cricket 2407 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698