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

Side by Side 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, 7 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
« no previous file with comments | « webrtc/pc/rtptransport.h ('k') | webrtc/pc/rtptransport_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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::SetRtcpMuxEnabled(bool enable) {
19 rtp_packet_transport_ = rtp; 20 rtcp_mux_enabled_ = enable;
21 MaybeSignalReadyToSend();
20 } 22 }
21 23
22 void RtpTransport::set_rtcp_packet_transport( 24 void RtpTransport::SetRtpPacketTransport(
23 rtc::PacketTransportInternal* rtcp) { 25 rtc::PacketTransportInternal* new_packet_transport) {
24 RTC_DCHECK(!rtcp_mux_required_); 26 if (new_packet_transport == rtp_packet_transport_) {
25 rtcp_packet_transport_ = rtcp; 27 return;
28 }
29 if (rtp_packet_transport_) {
30 rtp_packet_transport_->SignalReadyToSend.disconnect(this);
31 }
32 if (new_packet_transport) {
33 new_packet_transport->SignalReadyToSend.connect(
34 this, &RtpTransport::OnReadyToSend);
35 }
36 rtp_packet_transport_ = new_packet_transport;
37
38 // Assumes the transport is ready to send if it is writable. If we are wrong,
39 // ready to send will be updated the next time we try to send.
40 SetReadyToSend(false,
41 rtp_packet_transport_ && rtp_packet_transport_->writable());
42 }
43
44 void RtpTransport::SetRtcpPacketTransport(
45 rtc::PacketTransportInternal* new_packet_transport) {
46 if (new_packet_transport == rtcp_packet_transport_) {
47 return;
48 }
49 if (rtcp_packet_transport_) {
50 rtcp_packet_transport_->SignalReadyToSend.disconnect(this);
51 }
52 if (new_packet_transport) {
53 new_packet_transport->SignalReadyToSend.connect(
54 this, &RtpTransport::OnReadyToSend);
55 }
56 rtcp_packet_transport_ = new_packet_transport;
57
58 // Assumes the transport is ready to send if it is writable. If we are wrong,
59 // ready to send will be updated the next time we try to send.
60 SetReadyToSend(true,
61 rtcp_packet_transport_ && rtcp_packet_transport_->writable());
62 }
63
64 bool RtpTransport::IsWritable(bool rtcp) const {
65 rtc::PacketTransportInternal* transport = rtcp && !rtcp_mux_enabled_
66 ? rtcp_packet_transport_
67 : rtp_packet_transport_;
68 return transport && transport->writable();
69 }
70
71 bool RtpTransport::SendPacket(bool rtcp,
72 const rtc::CopyOnWriteBuffer* packet,
73 const rtc::PacketOptions& options,
74 int flags) {
75 rtc::PacketTransportInternal* transport = rtcp && !rtcp_mux_enabled_
76 ? rtcp_packet_transport_
77 : rtp_packet_transport_;
78 int ret = transport->SendPacket(packet->data<char>(), packet->size(), options,
79 flags);
80 if (ret != static_cast<int>(packet->size())) {
81 if (transport->GetError() == ENOTCONN) {
82 LOG(LS_WARNING) << "Got ENOTCONN from transport.";
83 SetReadyToSend(rtcp, false);
84 }
85 return false;
86 }
87 return true;
26 } 88 }
27 89
28 PacketTransportInterface* RtpTransport::GetRtpPacketTransport() const { 90 PacketTransportInterface* RtpTransport::GetRtpPacketTransport() const {
29 return rtp_packet_transport_; 91 return rtp_packet_transport_;
30 } 92 }
31 93
32 PacketTransportInterface* RtpTransport::GetRtcpPacketTransport() const { 94 PacketTransportInterface* RtpTransport::GetRtcpPacketTransport() const {
33 return rtcp_packet_transport_; 95 return rtcp_packet_transport_;
34 } 96 }
35 97
(...skipping 14 matching lines...) Expand all
50 } 112 }
51 113
52 RtcpParameters RtpTransport::GetRtcpParameters() const { 114 RtcpParameters RtpTransport::GetRtcpParameters() const {
53 return rtcp_parameters_; 115 return rtcp_parameters_;
54 } 116 }
55 117
56 RtpTransportAdapter* RtpTransport::GetInternal() { 118 RtpTransportAdapter* RtpTransport::GetInternal() {
57 return nullptr; 119 return nullptr;
58 } 120 }
59 121
122 void RtpTransport::OnReadyToSend(rtc::PacketTransportInternal* transport) {
123 SetReadyToSend(transport == rtcp_packet_transport_, true);
124 }
125
126 void RtpTransport::SetReadyToSend(bool rtcp, bool ready) {
127 if (rtcp) {
128 rtcp_ready_to_send_ = ready;
129 } else {
130 rtp_ready_to_send_ = ready;
131 }
132
133 MaybeSignalReadyToSend();
134 }
135
136 void RtpTransport::MaybeSignalReadyToSend() {
137 bool ready_to_send =
138 rtp_ready_to_send_ && (rtcp_ready_to_send_ || rtcp_mux_enabled_);
139 if (ready_to_send != ready_to_send_) {
140 ready_to_send_ = ready_to_send;
141 SignalReadyToSend(ready_to_send);
142 }
143 }
144
60 } // namespace webrtc 145 } // namespace webrtc
OLDNEW
« 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