Chromium Code Reviews| Index: webrtc/pc/rtptransport.cc |
| diff --git a/webrtc/pc/rtptransport.cc b/webrtc/pc/rtptransport.cc |
| index 76bc639cbcfb3685e40ef46bb605d1198225f4d3..af04628522f84147a56b3784350c45ffcc99199c 100644 |
| --- a/webrtc/pc/rtptransport.cc |
| +++ b/webrtc/pc/rtptransport.cc |
| @@ -11,18 +11,77 @@ |
| #include "webrtc/pc/rtptransport.h" |
| #include "webrtc/base/checks.h" |
| +#include "webrtc/base/copyonwritebuffer.h" |
| #include "webrtc/p2p/base/packettransportinterface.h" |
| namespace webrtc { |
| -void RtpTransport::set_rtp_packet_transport(rtc::PacketTransportInternal* rtp) { |
| - rtp_packet_transport_ = rtp; |
| +void RtpTransport::SetRtpPacketTransport( |
| + rtc::PacketTransportInternal* new_packet_transport) { |
| + if (new_packet_transport == rtp_packet_transport_) { |
| + return; |
| + } |
| + if (rtp_packet_transport_) { |
| + rtp_packet_transport_->SignalReadyToSend.disconnect(this); |
| + } |
| + if (new_packet_transport) { |
| + new_packet_transport->SignalReadyToSend.connect( |
| + this, &RtpTransport::OnReadyToSend); |
| + } |
| + rtp_packet_transport_ = new_packet_transport; |
| + |
| + // Assumes the transport is ready to send if it is writable. If we are wrong, |
| + // ready to send will be updated the next time we try to send. |
| + SetReadyToSend(false, |
| + rtp_packet_transport_ && rtp_packet_transport_->writable()); |
| +} |
| + |
| +void RtpTransport::SetRtcpPacketTransport( |
| + rtc::PacketTransportInternal* new_packet_transport) { |
| + RTC_DCHECK(!new_packet_transport || !rtcp_mux_enabled_); |
| + |
| + if (new_packet_transport == rtcp_packet_transport_) { |
| + return; |
| + } |
| + if (rtcp_packet_transport_) { |
| + rtcp_packet_transport_->SignalReadyToSend.disconnect(this); |
| + } |
| + if (new_packet_transport) { |
| + new_packet_transport->SignalReadyToSend.connect( |
| + this, &RtpTransport::OnReadyToSend); |
| + } |
| + rtcp_packet_transport_ = new_packet_transport; |
| + |
| + // Assumes the transport is ready to send if it is writable. If we are wrong, |
| + // ready to send will be updated the next time we try to send. |
| + SetReadyToSend(true, |
| + rtcp_packet_transport_ && rtcp_packet_transport_->writable()); |
| } |
| -void RtpTransport::set_rtcp_packet_transport( |
| - rtc::PacketTransportInternal* rtcp) { |
| - RTC_DCHECK(!rtcp_mux_required_); |
| - rtcp_packet_transport_ = rtcp; |
| +bool RtpTransport::IsWritable(bool send_on_rtcp) const { |
| + // TODO(zstein): Use rtcp_mux_enabled_ instead of send_on_rtcp |
|
Taylor Brandstetter
2017/04/19 05:56:33
Could this be done in this CL?
Zach Stein
2017/04/20 19:59:10
Yup, I was just looking for advice on when to set
|
| + rtc::PacketTransportInternal* transport = |
| + send_on_rtcp ? rtcp_packet_transport_ : rtp_packet_transport_; |
| + return transport && transport->writable(); |
| +} |
| + |
| +bool RtpTransport::SendPacket(bool send_on_rtcp, |
| + const rtc::CopyOnWriteBuffer* packet, |
| + const rtc::PacketOptions& options, |
| + int flags) { |
| + // TODO(zstein): Use rtcp_mux_enabled_ instead of send_on_rtcp |
| + rtc::PacketTransportInternal* transport = |
| + send_on_rtcp ? rtcp_packet_transport_ : rtp_packet_transport_; |
| + int ret = transport->SendPacket(packet->data<char>(), packet->size(), options, |
| + flags); |
| + if (ret != static_cast<int>(packet->size())) { |
| + if (transport->GetError() == ENOTCONN) { |
| + LOG(LS_WARNING) << "Got ENOTCONN from transport."; |
| + SetReadyToSend(send_on_rtcp, false); |
| + } |
| + return false; |
| + } |
| + return true; |
| } |
| PacketTransportInterface* RtpTransport::GetRtpPacketTransport() const { |
| @@ -57,4 +116,20 @@ RtpTransportAdapter* RtpTransport::GetInternal() { |
| return nullptr; |
| } |
| +void RtpTransport::OnReadyToSend(rtc::PacketTransportInternal* transport) { |
| + SetReadyToSend(transport == rtcp_packet_transport_, true); |
| +} |
| + |
| +void RtpTransport::SetReadyToSend(bool rtcp, bool ready) { |
| + if (rtcp) { |
| + rtcp_ready_to_send_ = ready; |
| + } else { |
| + rtp_ready_to_send_ = ready; |
| + } |
| + |
| + bool ready_to_send = |
| + rtp_ready_to_send_ && (rtcp_ready_to_send_ || rtcp_mux_enabled_); |
| + SignalReadyToSend(ready_to_send); |
|
Taylor Brandstetter
2017/04/19 05:56:33
nit: Would be preferable if this signal only fired
Zach Stein
2017/04/20 19:59:11
Done.
|
| +} |
| + |
| } // namespace webrtc |