| 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/packettransport.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 483 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::PacketTransport* pt) { |
| 532 TransportChannel* channel = static_cast<TransportChannel*>(pt); |
| 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::OnChannelRead(rtc::PacketTransport* pt, |
| 538 const char* data, size_t len, | 540 const char* data, |
| 541 size_t len, |
| 539 const rtc::PacketTime& packet_time, | 542 const rtc::PacketTime& packet_time, |
| 540 int flags) { | 543 int flags) { |
| 544 TransportChannel* channel = static_cast<TransportChannel*>(pt); |
| 541 TRACE_EVENT0("webrtc", "BaseChannel::OnChannelRead"); | 545 TRACE_EVENT0("webrtc", "BaseChannel::OnChannelRead"); |
| 542 // OnChannelRead gets called from P2PSocket; now pass data to MediaEngine | 546 // OnChannelRead gets called from P2PSocket; now pass data to MediaEngine |
| 543 RTC_DCHECK(network_thread_->IsCurrent()); | 547 RTC_DCHECK(network_thread_->IsCurrent()); |
| 544 | 548 |
| 545 // When using RTCP multiplexing we might get RTCP packets on the RTP | 549 // 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. | 550 // transport. We feed RTP traffic into the demuxer to determine if it is RTCP. |
| 547 bool rtcp = PacketIsRtcp(channel, data, len); | 551 bool rtcp = PacketIsRtcp(channel, data, len); |
| 548 rtc::CopyOnWriteBuffer packet(data, len); | 552 rtc::CopyOnWriteBuffer packet(data, len); |
| 549 HandlePacket(rtcp, &packet, packet_time); | 553 HandlePacket(rtcp, &packet, packet_time); |
| 550 } | 554 } |
| 551 | 555 |
| 552 void BaseChannel::OnReadyToSend(TransportChannel* channel) { | 556 void BaseChannel::OnReadyToSend(rtc::PacketTransport* pt) { |
| 557 TransportChannel* channel = static_cast<TransportChannel*>(pt); |
| 553 RTC_DCHECK(channel == transport_channel_ || | 558 RTC_DCHECK(channel == transport_channel_ || |
| 554 channel == rtcp_transport_channel_); | 559 channel == rtcp_transport_channel_); |
| 555 SetTransportChannelReadyToSend(channel == rtcp_transport_channel_, true); | 560 SetTransportChannelReadyToSend(channel == rtcp_transport_channel_, true); |
| 556 } | 561 } |
| 557 | 562 |
| 558 void BaseChannel::OnDtlsState(TransportChannel* channel, | 563 void BaseChannel::OnDtlsState(TransportChannel* channel, |
| 559 DtlsTransportState state) { | 564 DtlsTransportState state) { |
| 560 if (!ShouldSetupDtlsSrtp_n()) { | 565 if (!ShouldSetupDtlsSrtp_n()) { |
| 561 return; | 566 return; |
| 562 } | 567 } |
| (...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1438 // destructor. | 1443 // destructor. |
| 1439 RTC_DCHECK(network_thread_->IsCurrent()); | 1444 RTC_DCHECK(network_thread_->IsCurrent()); |
| 1440 rtc::MessageList rtcp_messages; | 1445 rtc::MessageList rtcp_messages; |
| 1441 network_thread_->Clear(this, MSG_SEND_RTCP_PACKET, &rtcp_messages); | 1446 network_thread_->Clear(this, MSG_SEND_RTCP_PACKET, &rtcp_messages); |
| 1442 for (const auto& message : rtcp_messages) { | 1447 for (const auto& message : rtcp_messages) { |
| 1443 network_thread_->Send(RTC_FROM_HERE, this, MSG_SEND_RTCP_PACKET, | 1448 network_thread_->Send(RTC_FROM_HERE, this, MSG_SEND_RTCP_PACKET, |
| 1444 message.pdata); | 1449 message.pdata); |
| 1445 } | 1450 } |
| 1446 } | 1451 } |
| 1447 | 1452 |
| 1448 void BaseChannel::SignalSentPacket_n(TransportChannel* /* channel */, | 1453 void BaseChannel::SignalSentPacket_n(rtc::PacketTransport* /* pt */, |
| 1449 const rtc::SentPacket& sent_packet) { | 1454 const rtc::SentPacket& sent_packet) { |
| 1450 RTC_DCHECK(network_thread_->IsCurrent()); | 1455 RTC_DCHECK(network_thread_->IsCurrent()); |
| 1451 invoker_.AsyncInvoke<void>( | 1456 invoker_.AsyncInvoke<void>( |
| 1452 RTC_FROM_HERE, worker_thread_, | 1457 RTC_FROM_HERE, worker_thread_, |
| 1453 rtc::Bind(&BaseChannel::SignalSentPacket_w, this, sent_packet)); | 1458 rtc::Bind(&BaseChannel::SignalSentPacket_w, this, sent_packet)); |
| 1454 } | 1459 } |
| 1455 | 1460 |
| 1456 void BaseChannel::SignalSentPacket_w(const rtc::SentPacket& sent_packet) { | 1461 void BaseChannel::SignalSentPacket_w(const rtc::SentPacket& sent_packet) { |
| 1457 RTC_DCHECK(worker_thread_->IsCurrent()); | 1462 RTC_DCHECK(worker_thread_->IsCurrent()); |
| 1458 SignalSentPacket(sent_packet); | 1463 SignalSentPacket(sent_packet); |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1634 } | 1639 } |
| 1635 | 1640 |
| 1636 int VoiceChannel::GetOutputLevel_w() { | 1641 int VoiceChannel::GetOutputLevel_w() { |
| 1637 return media_channel()->GetOutputLevel(); | 1642 return media_channel()->GetOutputLevel(); |
| 1638 } | 1643 } |
| 1639 | 1644 |
| 1640 void VoiceChannel::GetActiveStreams_w(AudioInfo::StreamList* actives) { | 1645 void VoiceChannel::GetActiveStreams_w(AudioInfo::StreamList* actives) { |
| 1641 media_channel()->GetActiveStreams(actives); | 1646 media_channel()->GetActiveStreams(actives); |
| 1642 } | 1647 } |
| 1643 | 1648 |
| 1644 void VoiceChannel::OnChannelRead(TransportChannel* channel, | 1649 void VoiceChannel::OnChannelRead(rtc::PacketTransport* pt, |
| 1645 const char* data, size_t len, | 1650 const char* data, |
| 1651 size_t len, |
| 1646 const rtc::PacketTime& packet_time, | 1652 const rtc::PacketTime& packet_time, |
| 1647 int flags) { | 1653 int flags) { |
| 1648 BaseChannel::OnChannelRead(channel, data, len, packet_time, flags); | 1654 BaseChannel::OnChannelRead(pt, data, len, packet_time, flags); |
| 1649 | 1655 TransportChannel* channel = static_cast<TransportChannel*>(pt); |
| 1650 // Set a flag when we've received an RTP packet. If we're waiting for early | 1656 // Set a flag when we've received an RTP packet. If we're waiting for early |
| 1651 // media, this will disable the timeout. | 1657 // media, this will disable the timeout. |
| 1652 if (!received_media_ && !PacketIsRtcp(channel, data, len)) { | 1658 if (!received_media_ && !PacketIsRtcp(channel, data, len)) { |
| 1653 received_media_ = true; | 1659 received_media_ = true; |
| 1654 } | 1660 } |
| 1655 } | 1661 } |
| 1656 | 1662 |
| 1657 void BaseChannel::UpdateMediaSendRecvState() { | 1663 void BaseChannel::UpdateMediaSendRecvState() { |
| 1658 RTC_DCHECK(network_thread_->IsCurrent()); | 1664 RTC_DCHECK(network_thread_->IsCurrent()); |
| 1659 invoker_.AsyncInvoke<void>( | 1665 invoker_.AsyncInvoke<void>( |
| (...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2410 } | 2416 } |
| 2411 | 2417 |
| 2412 void DataChannel::OnStreamClosedRemotely(uint32_t sid) { | 2418 void DataChannel::OnStreamClosedRemotely(uint32_t sid) { |
| 2413 rtc::TypedMessageData<uint32_t>* message = | 2419 rtc::TypedMessageData<uint32_t>* message = |
| 2414 new rtc::TypedMessageData<uint32_t>(sid); | 2420 new rtc::TypedMessageData<uint32_t>(sid); |
| 2415 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_STREAMCLOSEDREMOTELY, | 2421 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_STREAMCLOSEDREMOTELY, |
| 2416 message); | 2422 message); |
| 2417 } | 2423 } |
| 2418 | 2424 |
| 2419 } // namespace cricket | 2425 } // namespace cricket |
| OLD | NEW |