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

Side by Side Diff: webrtc/pc/rtptransport.cc

Issue 2812243005: Move ready to send logic from BaseChannel to RtpTransport. (Closed)
Patch Set: Move Connect, Disconnect, and more ready to send logic to RtpTransport. Update tests. Introduce rtc… 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2017 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2017 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 "webrtc/pc/rtptransport.h" 11 #include "webrtc/pc/rtptransport.h"
12 12
13 #include "webrtc/base/checks.h" 13 #include "webrtc/base/checks.h"
14 #include "webrtc/base/copyonwritebuffer.h"
14 #include "webrtc/p2p/base/packettransportinterface.h" 15 #include "webrtc/p2p/base/packettransportinterface.h"
15 16
16 namespace webrtc { 17 namespace webrtc {
17 18
18 void RtpTransport::set_rtp_packet_transport(rtc::PacketTransportInternal* rtp) { 19 void RtpTransport::SetRtpPacketTransport(
19 rtp_packet_transport_ = rtp; 20 rtc::PacketTransportInternal* new_packet_transport) {
21 if (new_packet_transport == rtp_packet_transport_) {
22 return;
23 }
24 if (rtp_packet_transport_) {
25 rtp_packet_transport_->SignalReadyToSend.disconnect(this);
26 }
27 if (new_packet_transport) {
28 new_packet_transport->SignalReadyToSend.connect(
29 this, &RtpTransport::OnReadyToSend);
30 }
31 rtp_packet_transport_ = new_packet_transport;
32
33 // Assumes the transport is ready to send if it is writable. If we are wrong,
34 // ready to send will be updated the next time we try to send.
35 SetReadyToSend(false,
36 rtp_packet_transport_ && rtp_packet_transport_->writable());
20 } 37 }
21 38
22 void RtpTransport::set_rtcp_packet_transport( 39 void RtpTransport::SetRtcpPacketTransport(
23 rtc::PacketTransportInternal* rtcp) { 40 rtc::PacketTransportInternal* new_packet_transport) {
24 RTC_DCHECK(!rtcp_mux_required_); 41 RTC_DCHECK(!new_packet_transport || !rtcp_mux_enabled_);
25 rtcp_packet_transport_ = rtcp; 42
43 if (new_packet_transport == rtcp_packet_transport_) {
44 return;
45 }
46 if (rtcp_packet_transport_) {
47 rtcp_packet_transport_->SignalReadyToSend.disconnect(this);
48 }
49 if (new_packet_transport) {
50 new_packet_transport->SignalReadyToSend.connect(
51 this, &RtpTransport::OnReadyToSend);
52 }
53 rtcp_packet_transport_ = new_packet_transport;
54
55 // Assumes the transport is ready to send if it is writable. If we are wrong,
56 // ready to send will be updated the next time we try to send.
57 SetReadyToSend(true,
58 rtcp_packet_transport_ && rtcp_packet_transport_->writable());
59 }
60
61 bool RtpTransport::IsWritable(bool send_on_rtcp) const {
62 // 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
63 rtc::PacketTransportInternal* transport =
64 send_on_rtcp ? rtcp_packet_transport_ : rtp_packet_transport_;
65 return transport && transport->writable();
66 }
67
68 bool RtpTransport::SendPacket(bool send_on_rtcp,
69 const rtc::CopyOnWriteBuffer* packet,
70 const rtc::PacketOptions& options,
71 int flags) {
72 // TODO(zstein): Use rtcp_mux_enabled_ instead of send_on_rtcp
73 rtc::PacketTransportInternal* transport =
74 send_on_rtcp ? rtcp_packet_transport_ : rtp_packet_transport_;
75 int ret = transport->SendPacket(packet->data<char>(), packet->size(), options,
76 flags);
77 if (ret != static_cast<int>(packet->size())) {
78 if (transport->GetError() == ENOTCONN) {
79 LOG(LS_WARNING) << "Got ENOTCONN from transport.";
80 SetReadyToSend(send_on_rtcp, false);
81 }
82 return false;
83 }
84 return true;
26 } 85 }
27 86
28 PacketTransportInterface* RtpTransport::GetRtpPacketTransport() const { 87 PacketTransportInterface* RtpTransport::GetRtpPacketTransport() const {
29 return rtp_packet_transport_; 88 return rtp_packet_transport_;
30 } 89 }
31 90
32 PacketTransportInterface* RtpTransport::GetRtcpPacketTransport() const { 91 PacketTransportInterface* RtpTransport::GetRtcpPacketTransport() const {
33 return rtcp_packet_transport_; 92 return rtcp_packet_transport_;
34 } 93 }
35 94
(...skipping 14 matching lines...) Expand all
50 } 109 }
51 110
52 RtcpParameters RtpTransport::GetRtcpParameters() const { 111 RtcpParameters RtpTransport::GetRtcpParameters() const {
53 return rtcp_parameters_; 112 return rtcp_parameters_;
54 } 113 }
55 114
56 RtpTransportAdapter* RtpTransport::GetInternal() { 115 RtpTransportAdapter* RtpTransport::GetInternal() {
57 return nullptr; 116 return nullptr;
58 } 117 }
59 118
119 void RtpTransport::OnReadyToSend(rtc::PacketTransportInternal* transport) {
120 SetReadyToSend(transport == rtcp_packet_transport_, true);
121 }
122
123 void RtpTransport::SetReadyToSend(bool rtcp, bool ready) {
124 if (rtcp) {
125 rtcp_ready_to_send_ = ready;
126 } else {
127 rtp_ready_to_send_ = ready;
128 }
129
130 bool ready_to_send =
131 rtp_ready_to_send_ && (rtcp_ready_to_send_ || rtcp_mux_enabled_);
132 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.
133 }
134
60 } // namespace webrtc 135 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698