| 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) { |
| 531 RTC_DCHECK(channel == transport_channel_ || | 532 RTC_DCHECK(transport == transport_channel_ || |
| 532 channel == rtcp_transport_channel_); | 533 transport == rtcp_transport_channel_); |
| 533 RTC_DCHECK(network_thread_->IsCurrent()); | 534 RTC_DCHECK(network_thread_->IsCurrent()); |
| 534 UpdateWritableState_n(); | 535 UpdateWritableState_n(); |
| 535 } | 536 } |
| 536 | 537 |
| 537 void BaseChannel::OnChannelRead(TransportChannel* channel, | 538 void BaseChannel::OnPacketRead(rtc::PacketTransportInterface* transport, |
| 538 const char* data, size_t len, | 539 const char* data, |
| 539 const rtc::PacketTime& packet_time, | 540 size_t len, |
| 540 int flags) { | 541 const rtc::PacketTime& packet_time, |
| 541 TRACE_EVENT0("webrtc", "BaseChannel::OnChannelRead"); | 542 int flags) { |
| 542 // OnChannelRead gets called from P2PSocket; now pass data to MediaEngine | 543 TRACE_EVENT0("webrtc", "BaseChannel::OnPacketRead"); |
| 544 // OnPacketRead gets called from P2PSocket; now pass data to MediaEngine |
| 543 RTC_DCHECK(network_thread_->IsCurrent()); | 545 RTC_DCHECK(network_thread_->IsCurrent()); |
| 544 | 546 |
| 545 // When using RTCP multiplexing we might get RTCP packets on the RTP | 547 // 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. | 548 // transport. We feed RTP traffic into the demuxer to determine if it is RTCP. |
| 547 bool rtcp = PacketIsRtcp(channel, data, len); | 549 bool rtcp = PacketIsRtcp(transport, data, len); |
| 548 rtc::CopyOnWriteBuffer packet(data, len); | 550 rtc::CopyOnWriteBuffer packet(data, len); |
| 549 HandlePacket(rtcp, &packet, packet_time); | 551 HandlePacket(rtcp, &packet, packet_time); |
| 550 } | 552 } |
| 551 | 553 |
| 552 void BaseChannel::OnReadyToSend(TransportChannel* channel) { | 554 void BaseChannel::OnReadyToSend(rtc::PacketTransportInterface* transport) { |
| 553 RTC_DCHECK(channel == transport_channel_ || | 555 RTC_DCHECK(transport == transport_channel_ || |
| 554 channel == rtcp_transport_channel_); | 556 transport == rtcp_transport_channel_); |
| 555 SetTransportChannelReadyToSend(channel == rtcp_transport_channel_, true); | 557 SetTransportChannelReadyToSend(transport == rtcp_transport_channel_, true); |
| 556 } | 558 } |
| 557 | 559 |
| 558 void BaseChannel::OnDtlsState(TransportChannel* channel, | 560 void BaseChannel::OnDtlsState(TransportChannel* channel, |
| 559 DtlsTransportState state) { | 561 DtlsTransportState state) { |
| 560 if (!ShouldSetupDtlsSrtp_n()) { | 562 if (!ShouldSetupDtlsSrtp_n()) { |
| 561 return; | 563 return; |
| 562 } | 564 } |
| 563 | 565 |
| 564 // Reset the srtp filter if it's not the CONNECTED state. For the CONNECTED | 566 // Reset the srtp filter if it's not the CONNECTED state. For the CONNECTED |
| 565 // state, setting up DTLS-SRTP context is deferred to ChannelWritable_w to | 567 // state, setting up DTLS-SRTP context is deferred to ChannelWritable_w to |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 bool ready_to_send = | 606 bool ready_to_send = |
| 605 (rtp_ready_to_send_ && | 607 (rtp_ready_to_send_ && |
| 606 // In the case of rtcp mux |rtcp_transport_channel_| will be null. | 608 // In the case of rtcp mux |rtcp_transport_channel_| will be null. |
| 607 (rtcp_ready_to_send_ || !rtcp_transport_channel_)); | 609 (rtcp_ready_to_send_ || !rtcp_transport_channel_)); |
| 608 | 610 |
| 609 invoker_.AsyncInvoke<void>( | 611 invoker_.AsyncInvoke<void>( |
| 610 RTC_FROM_HERE, worker_thread_, | 612 RTC_FROM_HERE, worker_thread_, |
| 611 Bind(&MediaChannel::OnReadyToSend, media_channel_, ready_to_send)); | 613 Bind(&MediaChannel::OnReadyToSend, media_channel_, ready_to_send)); |
| 612 } | 614 } |
| 613 | 615 |
| 614 bool BaseChannel::PacketIsRtcp(const TransportChannel* channel, | 616 bool BaseChannel::PacketIsRtcp(const rtc::PacketTransportInterface* transport, |
| 615 const char* data, size_t len) { | 617 const char* data, |
| 616 return (channel == rtcp_transport_channel_ || | 618 size_t len) { |
| 619 return (transport == rtcp_transport_channel_ || |
| 617 rtcp_mux_filter_.DemuxRtcp(data, static_cast<int>(len))); | 620 rtcp_mux_filter_.DemuxRtcp(data, static_cast<int>(len))); |
| 618 } | 621 } |
| 619 | 622 |
| 620 bool BaseChannel::SendPacket(bool rtcp, | 623 bool BaseChannel::SendPacket(bool rtcp, |
| 621 rtc::CopyOnWriteBuffer* packet, | 624 rtc::CopyOnWriteBuffer* packet, |
| 622 const rtc::PacketOptions& options) { | 625 const rtc::PacketOptions& options) { |
| 623 // SendPacket gets called from MediaEngine, on a pacer or an encoder thread. | 626 // 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 | 627 // 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 | 628 // 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 | 629 // 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. | 1441 // destructor. |
| 1439 RTC_DCHECK(network_thread_->IsCurrent()); | 1442 RTC_DCHECK(network_thread_->IsCurrent()); |
| 1440 rtc::MessageList rtcp_messages; | 1443 rtc::MessageList rtcp_messages; |
| 1441 network_thread_->Clear(this, MSG_SEND_RTCP_PACKET, &rtcp_messages); | 1444 network_thread_->Clear(this, MSG_SEND_RTCP_PACKET, &rtcp_messages); |
| 1442 for (const auto& message : rtcp_messages) { | 1445 for (const auto& message : rtcp_messages) { |
| 1443 network_thread_->Send(RTC_FROM_HERE, this, MSG_SEND_RTCP_PACKET, | 1446 network_thread_->Send(RTC_FROM_HERE, this, MSG_SEND_RTCP_PACKET, |
| 1444 message.pdata); | 1447 message.pdata); |
| 1445 } | 1448 } |
| 1446 } | 1449 } |
| 1447 | 1450 |
| 1448 void BaseChannel::SignalSentPacket_n(TransportChannel* /* channel */, | 1451 void BaseChannel::SignalSentPacket_n( |
| 1449 const rtc::SentPacket& sent_packet) { | 1452 rtc::PacketTransportInterface* /* transport */, |
| 1453 const rtc::SentPacket& sent_packet) { |
| 1450 RTC_DCHECK(network_thread_->IsCurrent()); | 1454 RTC_DCHECK(network_thread_->IsCurrent()); |
| 1451 invoker_.AsyncInvoke<void>( | 1455 invoker_.AsyncInvoke<void>( |
| 1452 RTC_FROM_HERE, worker_thread_, | 1456 RTC_FROM_HERE, worker_thread_, |
| 1453 rtc::Bind(&BaseChannel::SignalSentPacket_w, this, sent_packet)); | 1457 rtc::Bind(&BaseChannel::SignalSentPacket_w, this, sent_packet)); |
| 1454 } | 1458 } |
| 1455 | 1459 |
| 1456 void BaseChannel::SignalSentPacket_w(const rtc::SentPacket& sent_packet) { | 1460 void BaseChannel::SignalSentPacket_w(const rtc::SentPacket& sent_packet) { |
| 1457 RTC_DCHECK(worker_thread_->IsCurrent()); | 1461 RTC_DCHECK(worker_thread_->IsCurrent()); |
| 1458 SignalSentPacket(sent_packet); | 1462 SignalSentPacket(sent_packet); |
| 1459 } | 1463 } |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1634 } | 1638 } |
| 1635 | 1639 |
| 1636 int VoiceChannel::GetOutputLevel_w() { | 1640 int VoiceChannel::GetOutputLevel_w() { |
| 1637 return media_channel()->GetOutputLevel(); | 1641 return media_channel()->GetOutputLevel(); |
| 1638 } | 1642 } |
| 1639 | 1643 |
| 1640 void VoiceChannel::GetActiveStreams_w(AudioInfo::StreamList* actives) { | 1644 void VoiceChannel::GetActiveStreams_w(AudioInfo::StreamList* actives) { |
| 1641 media_channel()->GetActiveStreams(actives); | 1645 media_channel()->GetActiveStreams(actives); |
| 1642 } | 1646 } |
| 1643 | 1647 |
| 1644 void VoiceChannel::OnChannelRead(TransportChannel* channel, | 1648 void VoiceChannel::OnPacketRead(rtc::PacketTransportInterface* transport, |
| 1645 const char* data, size_t len, | 1649 const char* data, |
| 1646 const rtc::PacketTime& packet_time, | 1650 size_t len, |
| 1651 const rtc::PacketTime& packet_time, |
| 1647 int flags) { | 1652 int flags) { |
| 1648 BaseChannel::OnChannelRead(channel, data, len, packet_time, flags); | 1653 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 | 1654 // Set a flag when we've received an RTP packet. If we're waiting for early |
| 1651 // media, this will disable the timeout. | 1655 // media, this will disable the timeout. |
| 1652 if (!received_media_ && !PacketIsRtcp(channel, data, len)) { | 1656 if (!received_media_ && !PacketIsRtcp(transport, data, len)) { |
| 1653 received_media_ = true; | 1657 received_media_ = true; |
| 1654 } | 1658 } |
| 1655 } | 1659 } |
| 1656 | 1660 |
| 1657 void BaseChannel::UpdateMediaSendRecvState() { | 1661 void BaseChannel::UpdateMediaSendRecvState() { |
| 1658 RTC_DCHECK(network_thread_->IsCurrent()); | 1662 RTC_DCHECK(network_thread_->IsCurrent()); |
| 1659 invoker_.AsyncInvoke<void>( | 1663 invoker_.AsyncInvoke<void>( |
| 1660 RTC_FROM_HERE, worker_thread_, | 1664 RTC_FROM_HERE, worker_thread_, |
| 1661 Bind(&BaseChannel::UpdateMediaSendRecvState_w, this)); | 1665 Bind(&BaseChannel::UpdateMediaSendRecvState_w, this)); |
| 1662 } | 1666 } |
| (...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2410 } | 2414 } |
| 2411 | 2415 |
| 2412 void DataChannel::OnStreamClosedRemotely(uint32_t sid) { | 2416 void DataChannel::OnStreamClosedRemotely(uint32_t sid) { |
| 2413 rtc::TypedMessageData<uint32_t>* message = | 2417 rtc::TypedMessageData<uint32_t>* message = |
| 2414 new rtc::TypedMessageData<uint32_t>(sid); | 2418 new rtc::TypedMessageData<uint32_t>(sid); |
| 2415 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_STREAMCLOSEDREMOTELY, | 2419 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_STREAMCLOSEDREMOTELY, |
| 2416 message); | 2420 message); |
| 2417 } | 2421 } |
| 2418 | 2422 |
| 2419 } // namespace cricket | 2423 } // namespace cricket |
| OLD | NEW |