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

Unified Diff: webrtc/pc/rtptransport.cc

Issue 2812243005: Move ready to send logic from BaseChannel to RtpTransport. (Closed)
Patch Set: Remove dcheck that does not currently hold. Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/pc/rtptransport.h ('k') | webrtc/pc/rtptransport_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/pc/rtptransport.cc
diff --git a/webrtc/pc/rtptransport.cc b/webrtc/pc/rtptransport.cc
index 76bc639cbcfb3685e40ef46bb605d1198225f4d3..2ee27e02fb673725ec3c66ab9260d723d6083dda 100644
--- a/webrtc/pc/rtptransport.cc
+++ b/webrtc/pc/rtptransport.cc
@@ -11,18 +11,80 @@
#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::SetRtcpMuxEnabled(bool enable) {
+ rtcp_mux_enabled_ = enable;
+ MaybeSignalReadyToSend();
}
-void RtpTransport::set_rtcp_packet_transport(
- rtc::PacketTransportInternal* rtcp) {
- RTC_DCHECK(!rtcp_mux_required_);
- rtcp_packet_transport_ = rtcp;
+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) {
+ 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());
+}
+
+bool RtpTransport::IsWritable(bool rtcp) const {
+ rtc::PacketTransportInternal* transport = rtcp && !rtcp_mux_enabled_
+ ? rtcp_packet_transport_
+ : rtp_packet_transport_;
+ return transport && transport->writable();
+}
+
+bool RtpTransport::SendPacket(bool rtcp,
+ const rtc::CopyOnWriteBuffer* packet,
+ const rtc::PacketOptions& options,
+ int flags) {
+ rtc::PacketTransportInternal* transport = rtcp && !rtcp_mux_enabled_
+ ? 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(rtcp, false);
+ }
+ return false;
+ }
+ return true;
}
PacketTransportInterface* RtpTransport::GetRtpPacketTransport() const {
@@ -57,4 +119,27 @@ 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;
+ }
+
+ MaybeSignalReadyToSend();
+}
+
+void RtpTransport::MaybeSignalReadyToSend() {
+ bool ready_to_send =
+ rtp_ready_to_send_ && (rtcp_ready_to_send_ || rtcp_mux_enabled_);
+ if (ready_to_send != ready_to_send_) {
+ ready_to_send_ = ready_to_send;
+ SignalReadyToSend(ready_to_send);
+ }
+}
+
} // namespace webrtc
« no previous file with comments | « webrtc/pc/rtptransport.h ('k') | webrtc/pc/rtptransport_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698