| 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 <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/transportchannel.h" | 28 #include "webrtc/p2p/base/transportchannel.h" |
| 28 #include "webrtc/pc/channelmanager.h" | 29 #include "webrtc/pc/channelmanager.h" |
| 29 | 30 |
| 30 namespace cricket { | 31 namespace cricket { |
| 31 using rtc::Bind; | 32 using rtc::Bind; |
| 32 | 33 |
| 33 namespace { | 34 namespace { |
| 34 // See comment below for why we need to use a pointer to a unique_ptr. | 35 // See comment below for why we need to use a pointer to a unique_ptr. |
| 35 bool SetRawAudioSink_w(VoiceMediaChannel* channel, | 36 bool SetRawAudioSink_w(VoiceMediaChannel* channel, |
| 36 uint32_t ssrc, | 37 uint32_t ssrc, |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 for (const auto& pair : socket_options) { | 371 for (const auto& pair : socket_options) { |
| 371 new_channel->SetOption(pair.first, pair.second); | 372 new_channel->SetOption(pair.first, pair.second); |
| 372 } | 373 } |
| 373 } | 374 } |
| 374 } | 375 } |
| 375 | 376 |
| 376 void BaseChannel::ConnectToTransportChannel(TransportChannel* tc) { | 377 void BaseChannel::ConnectToTransportChannel(TransportChannel* tc) { |
| 377 RTC_DCHECK(network_thread_->IsCurrent()); | 378 RTC_DCHECK(network_thread_->IsCurrent()); |
| 378 | 379 |
| 379 tc->SignalWritableState.connect(this, &BaseChannel::OnWritableState); | 380 tc->SignalWritableState.connect(this, &BaseChannel::OnWritableState); |
| 380 tc->SignalReadPacket.connect(this, &BaseChannel::OnChannelRead); | 381 tc->SignalReadPacket.connect(this, &BaseChannel::OnPacketRead); |
| 381 tc->SignalReadyToSend.connect(this, &BaseChannel::OnReadyToSend); | 382 tc->SignalReadyToSend.connect(this, &BaseChannel::OnReadyToSend); |
| 382 tc->SignalDtlsState.connect(this, &BaseChannel::OnDtlsState); | 383 tc->SignalDtlsState.connect(this, &BaseChannel::OnDtlsState); |
| 383 tc->SignalSelectedCandidatePairChanged.connect( | 384 tc->SignalSelectedCandidatePairChanged.connect( |
| 384 this, &BaseChannel::OnSelectedCandidatePairChanged); | 385 this, &BaseChannel::OnSelectedCandidatePairChanged); |
| 385 tc->SignalSentPacket.connect(this, &BaseChannel::SignalSentPacket_n); | 386 tc->SignalSentPacket.connect(this, &BaseChannel::SignalSentPacket_n); |
| 386 } | 387 } |
| 387 | 388 |
| 388 void BaseChannel::DisconnectFromTransportChannel(TransportChannel* tc) { | 389 void BaseChannel::DisconnectFromTransportChannel(TransportChannel* tc) { |
| 389 RTC_DCHECK(network_thread_->IsCurrent()); | 390 RTC_DCHECK(network_thread_->IsCurrent()); |
| 390 | 391 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 break; | 521 break; |
| 521 } | 522 } |
| 522 return channel ? channel->SetOption(opt, value) : -1; | 523 return channel ? channel->SetOption(opt, value) : -1; |
| 523 } | 524 } |
| 524 | 525 |
| 525 bool BaseChannel::SetCryptoOptions(const rtc::CryptoOptions& crypto_options) { | 526 bool BaseChannel::SetCryptoOptions(const rtc::CryptoOptions& crypto_options) { |
| 526 crypto_options_ = crypto_options; | 527 crypto_options_ = crypto_options; |
| 527 return true; | 528 return true; |
| 528 } | 529 } |
| 529 | 530 |
| 530 void BaseChannel::OnWritableState(TransportChannel* channel) { | 531 void BaseChannel::OnWritableState(rtc::PacketTransportInterface* transport) { |
| 532 TransportChannel* channel = static_cast<TransportChannel*>(transport); |
| 531 RTC_DCHECK(channel == transport_channel_ || | 533 RTC_DCHECK(channel == transport_channel_ || |
| 532 channel == rtcp_transport_channel_); | 534 channel == rtcp_transport_channel_); |
| 533 RTC_DCHECK(network_thread_->IsCurrent()); | 535 RTC_DCHECK(network_thread_->IsCurrent()); |
| 534 UpdateWritableState_n(); | 536 UpdateWritableState_n(); |
| 535 } | 537 } |
| 536 | 538 |
| 537 void BaseChannel::OnChannelRead(TransportChannel* channel, | 539 void BaseChannel::OnPacketRead(rtc::PacketTransportInterface* transport, |
| 538 const char* data, size_t len, | 540 const char* data, |
| 539 const rtc::PacketTime& packet_time, | 541 size_t len, |
| 540 int flags) { | 542 const rtc::PacketTime& packet_time, |
| 541 TRACE_EVENT0("webrtc", "BaseChannel::OnChannelRead"); | 543 int flags) { |
| 542 // OnChannelRead gets called from P2PSocket; now pass data to MediaEngine | 544 TRACE_EVENT0("webrtc", "BaseChannel::OnPacketRead"); |
| 545 // OnPacketRead gets called from P2PSocket; now pass data to MediaEngine |
| 543 RTC_DCHECK(network_thread_->IsCurrent()); | 546 RTC_DCHECK(network_thread_->IsCurrent()); |
| 544 | 547 |
| 545 // When using RTCP multiplexing we might get RTCP packets on the RTP | 548 // When using RTCP multiplexing we might get RTCP packets on the RTP |
| 546 // transport. We feed RTP traffic into the demuxer to determine if it is RTCP. | 549 // transport. We feed RTP traffic into the demuxer to determine if it is RTCP. |
| 547 bool rtcp = PacketIsRtcp(channel, data, len); | 550 bool rtcp = PacketIsRtcp(transport, data, len); |
| 548 rtc::CopyOnWriteBuffer packet(data, len); | 551 rtc::CopyOnWriteBuffer packet(data, len); |
| 549 HandlePacket(rtcp, &packet, packet_time); | 552 HandlePacket(rtcp, &packet, packet_time); |
| 550 } | 553 } |
| 551 | 554 |
| 552 void BaseChannel::OnReadyToSend(TransportChannel* channel) { | 555 void BaseChannel::OnReadyToSend(rtc::PacketTransportInterface* transport) { |
| 556 TransportChannel* channel = static_cast<TransportChannel*>(transport); |
| 553 RTC_DCHECK(channel == transport_channel_ || | 557 RTC_DCHECK(channel == transport_channel_ || |
| 554 channel == rtcp_transport_channel_); | 558 channel == rtcp_transport_channel_); |
| 555 SetTransportChannelReadyToSend(channel == rtcp_transport_channel_, true); | 559 SetTransportChannelReadyToSend(channel == rtcp_transport_channel_, true); |
| 556 } | 560 } |
| 557 | 561 |
| 558 void BaseChannel::OnDtlsState(TransportChannel* channel, | 562 void BaseChannel::OnDtlsState(TransportChannel* channel, |
| 559 DtlsTransportState state) { | 563 DtlsTransportState state) { |
| 560 if (!ShouldSetupDtlsSrtp_n()) { | 564 if (!ShouldSetupDtlsSrtp_n()) { |
| 561 return; | 565 return; |
| 562 } | 566 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 bool ready_to_send = | 608 bool ready_to_send = |
| 605 (rtp_ready_to_send_ && | 609 (rtp_ready_to_send_ && |
| 606 // In the case of rtcp mux |rtcp_transport_channel_| will be null. | 610 // In the case of rtcp mux |rtcp_transport_channel_| will be null. |
| 607 (rtcp_ready_to_send_ || !rtcp_transport_channel_)); | 611 (rtcp_ready_to_send_ || !rtcp_transport_channel_)); |
| 608 | 612 |
| 609 invoker_.AsyncInvoke<void>( | 613 invoker_.AsyncInvoke<void>( |
| 610 RTC_FROM_HERE, worker_thread_, | 614 RTC_FROM_HERE, worker_thread_, |
| 611 Bind(&MediaChannel::OnReadyToSend, media_channel_, ready_to_send)); | 615 Bind(&MediaChannel::OnReadyToSend, media_channel_, ready_to_send)); |
| 612 } | 616 } |
| 613 | 617 |
| 614 bool BaseChannel::PacketIsRtcp(const TransportChannel* channel, | 618 bool BaseChannel::PacketIsRtcp(const rtc::PacketTransportInterface* transport, |
| 615 const char* data, size_t len) { | 619 const char* data, |
| 616 return (channel == rtcp_transport_channel_ || | 620 size_t len) { |
| 621 return (static_cast<const TransportChannel*>(transport) == |
| 622 rtcp_transport_channel_ || |
| 617 rtcp_mux_filter_.DemuxRtcp(data, static_cast<int>(len))); | 623 rtcp_mux_filter_.DemuxRtcp(data, static_cast<int>(len))); |
| 618 } | 624 } |
| 619 | 625 |
| 620 bool BaseChannel::SendPacket(bool rtcp, | 626 bool BaseChannel::SendPacket(bool rtcp, |
| 621 rtc::CopyOnWriteBuffer* packet, | 627 rtc::CopyOnWriteBuffer* packet, |
| 622 const rtc::PacketOptions& options) { | 628 const rtc::PacketOptions& options) { |
| 623 // SendPacket gets called from MediaEngine, on a pacer or an encoder thread. | 629 // SendPacket gets called from MediaEngine, on a pacer or an encoder thread. |
| 624 // If the thread is not our network thread, we will post to our network | 630 // If the thread is not our network thread, we will post to our network |
| 625 // so that the real work happens on our network. This avoids us having to | 631 // so that the real work happens on our network. This avoids us having to |
| 626 // synchronize access to all the pieces of the send path, including | 632 // synchronize access to all the pieces of the send path, including |
| (...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1438 // destructor. | 1444 // destructor. |
| 1439 RTC_DCHECK(network_thread_->IsCurrent()); | 1445 RTC_DCHECK(network_thread_->IsCurrent()); |
| 1440 rtc::MessageList rtcp_messages; | 1446 rtc::MessageList rtcp_messages; |
| 1441 network_thread_->Clear(this, MSG_SEND_RTCP_PACKET, &rtcp_messages); | 1447 network_thread_->Clear(this, MSG_SEND_RTCP_PACKET, &rtcp_messages); |
| 1442 for (const auto& message : rtcp_messages) { | 1448 for (const auto& message : rtcp_messages) { |
| 1443 network_thread_->Send(RTC_FROM_HERE, this, MSG_SEND_RTCP_PACKET, | 1449 network_thread_->Send(RTC_FROM_HERE, this, MSG_SEND_RTCP_PACKET, |
| 1444 message.pdata); | 1450 message.pdata); |
| 1445 } | 1451 } |
| 1446 } | 1452 } |
| 1447 | 1453 |
| 1448 void BaseChannel::SignalSentPacket_n(TransportChannel* /* channel */, | 1454 void BaseChannel::SignalSentPacket_n( |
| 1449 const rtc::SentPacket& sent_packet) { | 1455 rtc::PacketTransportInterface* /* transport */, |
| 1456 const rtc::SentPacket& sent_packet) { |
| 1450 RTC_DCHECK(network_thread_->IsCurrent()); | 1457 RTC_DCHECK(network_thread_->IsCurrent()); |
| 1451 invoker_.AsyncInvoke<void>( | 1458 invoker_.AsyncInvoke<void>( |
| 1452 RTC_FROM_HERE, worker_thread_, | 1459 RTC_FROM_HERE, worker_thread_, |
| 1453 rtc::Bind(&BaseChannel::SignalSentPacket_w, this, sent_packet)); | 1460 rtc::Bind(&BaseChannel::SignalSentPacket_w, this, sent_packet)); |
| 1454 } | 1461 } |
| 1455 | 1462 |
| 1456 void BaseChannel::SignalSentPacket_w(const rtc::SentPacket& sent_packet) { | 1463 void BaseChannel::SignalSentPacket_w(const rtc::SentPacket& sent_packet) { |
| 1457 RTC_DCHECK(worker_thread_->IsCurrent()); | 1464 RTC_DCHECK(worker_thread_->IsCurrent()); |
| 1458 SignalSentPacket(sent_packet); | 1465 SignalSentPacket(sent_packet); |
| 1459 } | 1466 } |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1634 } | 1641 } |
| 1635 | 1642 |
| 1636 int VoiceChannel::GetOutputLevel_w() { | 1643 int VoiceChannel::GetOutputLevel_w() { |
| 1637 return media_channel()->GetOutputLevel(); | 1644 return media_channel()->GetOutputLevel(); |
| 1638 } | 1645 } |
| 1639 | 1646 |
| 1640 void VoiceChannel::GetActiveStreams_w(AudioInfo::StreamList* actives) { | 1647 void VoiceChannel::GetActiveStreams_w(AudioInfo::StreamList* actives) { |
| 1641 media_channel()->GetActiveStreams(actives); | 1648 media_channel()->GetActiveStreams(actives); |
| 1642 } | 1649 } |
| 1643 | 1650 |
| 1644 void VoiceChannel::OnChannelRead(TransportChannel* channel, | 1651 void VoiceChannel::OnPacketRead(rtc::PacketTransportInterface* transport, |
| 1645 const char* data, size_t len, | 1652 const char* data, |
| 1646 const rtc::PacketTime& packet_time, | 1653 size_t len, |
| 1654 const rtc::PacketTime& packet_time, |
| 1647 int flags) { | 1655 int flags) { |
| 1648 BaseChannel::OnChannelRead(channel, data, len, packet_time, flags); | 1656 BaseChannel::OnPacketRead(transport, data, len, packet_time, flags); |
| 1649 | |
| 1650 // Set a flag when we've received an RTP packet. If we're waiting for early | 1657 // Set a flag when we've received an RTP packet. If we're waiting for early |
| 1651 // media, this will disable the timeout. | 1658 // media, this will disable the timeout. |
| 1652 if (!received_media_ && !PacketIsRtcp(channel, data, len)) { | 1659 if (!received_media_ && !PacketIsRtcp(transport, data, len)) { |
| 1653 received_media_ = true; | 1660 received_media_ = true; |
| 1654 } | 1661 } |
| 1655 } | 1662 } |
| 1656 | 1663 |
| 1657 void BaseChannel::UpdateMediaSendRecvState() { | 1664 void BaseChannel::UpdateMediaSendRecvState() { |
| 1658 RTC_DCHECK(network_thread_->IsCurrent()); | 1665 RTC_DCHECK(network_thread_->IsCurrent()); |
| 1659 invoker_.AsyncInvoke<void>( | 1666 invoker_.AsyncInvoke<void>( |
| 1660 RTC_FROM_HERE, worker_thread_, | 1667 RTC_FROM_HERE, worker_thread_, |
| 1661 Bind(&BaseChannel::UpdateMediaSendRecvState_w, this)); | 1668 Bind(&BaseChannel::UpdateMediaSendRecvState_w, this)); |
| 1662 } | 1669 } |
| (...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2410 } | 2417 } |
| 2411 | 2418 |
| 2412 void DataChannel::OnStreamClosedRemotely(uint32_t sid) { | 2419 void DataChannel::OnStreamClosedRemotely(uint32_t sid) { |
| 2413 rtc::TypedMessageData<uint32_t>* message = | 2420 rtc::TypedMessageData<uint32_t>* message = |
| 2414 new rtc::TypedMessageData<uint32_t>(sid); | 2421 new rtc::TypedMessageData<uint32_t>(sid); |
| 2415 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_STREAMCLOSEDREMOTELY, | 2422 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_STREAMCLOSEDREMOTELY, |
| 2416 message); | 2423 message); |
| 2417 } | 2424 } |
| 2418 | 2425 |
| 2419 } // namespace cricket | 2426 } // namespace cricket |
| OLD | NEW |