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

Side by Side Diff: webrtc/ortc/rtptransportadapter.cc

Issue 2981513002: Wire up RTP keep-alive in ortc api. (Closed)
Patch Set: deps, again Created 3 years, 4 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/ortc/rtptransportadapter.h ('k') | webrtc/ortc/rtptransportcontrolleradapter.h » ('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/ortc/rtptransportadapter.h" 11 #include "webrtc/ortc/rtptransportadapter.h"
12 12
13 #include <algorithm> // For std::find. 13 #include <algorithm> // For std::find.
14 #include <set> 14 #include <set>
15 #include <sstream> 15 #include <sstream>
16 #include <utility> // For std::move. 16 #include <utility> // For std::move.
17 17
18 #include "webrtc/api/proxy.h" 18 #include "webrtc/api/proxy.h"
19 #include "webrtc/rtc_base/logging.h" 19 #include "webrtc/rtc_base/logging.h"
20 20
21 namespace webrtc { 21 namespace webrtc {
22 22
23 BEGIN_OWNED_PROXY_MAP(RtpTransport) 23 BEGIN_OWNED_PROXY_MAP(RtpTransport)
24 PROXY_SIGNALING_THREAD_DESTRUCTOR() 24 PROXY_SIGNALING_THREAD_DESTRUCTOR()
25 PROXY_CONSTMETHOD0(PacketTransportInterface*, GetRtpPacketTransport) 25 PROXY_CONSTMETHOD0(PacketTransportInterface*, GetRtpPacketTransport)
26 PROXY_CONSTMETHOD0(PacketTransportInterface*, GetRtcpPacketTransport) 26 PROXY_CONSTMETHOD0(PacketTransportInterface*, GetRtcpPacketTransport)
27 PROXY_METHOD1(RTCError, SetRtcpParameters, const RtcpParameters&) 27 PROXY_METHOD1(RTCError, SetParameters, const RtpTransportParameters&)
28 PROXY_CONSTMETHOD0(RtcpParameters, GetRtcpParameters) 28 PROXY_CONSTMETHOD0(RtpTransportParameters, GetParameters)
29 protected: 29 protected:
30 RtpTransportAdapter* GetInternal() override { 30 RtpTransportAdapter* GetInternal() override {
31 return internal(); 31 return internal();
32 } 32 }
33 END_PROXY_MAP() 33 END_PROXY_MAP()
34 34
35 BEGIN_OWNED_PROXY_MAP(SrtpTransport) 35 BEGIN_OWNED_PROXY_MAP(SrtpTransport)
36 PROXY_SIGNALING_THREAD_DESTRUCTOR() 36 PROXY_SIGNALING_THREAD_DESTRUCTOR()
37 PROXY_CONSTMETHOD0(PacketTransportInterface*, GetRtpPacketTransport) 37 PROXY_CONSTMETHOD0(PacketTransportInterface*, GetRtpPacketTransport)
38 PROXY_CONSTMETHOD0(PacketTransportInterface*, GetRtcpPacketTransport) 38 PROXY_CONSTMETHOD0(PacketTransportInterface*, GetRtcpPacketTransport)
39 PROXY_METHOD1(RTCError, SetRtcpParameters, const RtcpParameters&) 39 PROXY_METHOD1(RTCError, SetParameters, const RtpTransportParameters&)
40 PROXY_CONSTMETHOD0(RtcpParameters, GetRtcpParameters) 40 PROXY_CONSTMETHOD0(RtpTransportParameters, GetParameters)
41 PROXY_METHOD1(RTCError, SetSrtpSendKey, const cricket::CryptoParams&) 41 PROXY_METHOD1(RTCError, SetSrtpSendKey, const cricket::CryptoParams&)
42 PROXY_METHOD1(RTCError, SetSrtpReceiveKey, const cricket::CryptoParams&) 42 PROXY_METHOD1(RTCError, SetSrtpReceiveKey, const cricket::CryptoParams&)
43 protected: 43 protected:
44 RtpTransportAdapter* GetInternal() override { 44 RtpTransportAdapter* GetInternal() override {
45 return internal(); 45 return internal();
46 } 46 }
47 END_PROXY_MAP() 47 END_PROXY_MAP()
48 48
49 // static 49 // static
50 RTCErrorOr<std::unique_ptr<RtpTransportInterface>> 50 RTCErrorOr<std::unique_ptr<RtpTransportInterface>>
51 RtpTransportAdapter::CreateProxied( 51 RtpTransportAdapter::CreateProxied(
52 const RtcpParameters& rtcp_parameters, 52 const RtpTransportParameters& parameters,
53 PacketTransportInterface* rtp, 53 PacketTransportInterface* rtp,
54 PacketTransportInterface* rtcp, 54 PacketTransportInterface* rtcp,
55 RtpTransportControllerAdapter* rtp_transport_controller) { 55 RtpTransportControllerAdapter* rtp_transport_controller) {
56 if (!rtp) { 56 if (!rtp) {
57 LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, 57 LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
58 "Must provide an RTP packet transport."); 58 "Must provide an RTP packet transport.");
59 } 59 }
60 if (!rtcp_parameters.mux && !rtcp) { 60 if (!parameters.rtcp.mux && !rtcp) {
61 LOG_AND_RETURN_ERROR( 61 LOG_AND_RETURN_ERROR(
62 RTCErrorType::INVALID_PARAMETER, 62 RTCErrorType::INVALID_PARAMETER,
63 "Must provide an RTCP packet transport when RTCP muxing is not used."); 63 "Must provide an RTCP packet transport when RTCP muxing is not used.");
64 } 64 }
65 if (rtcp_parameters.mux && rtcp) { 65 if (parameters.rtcp.mux && rtcp) {
66 LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, 66 LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
67 "Creating an RtpTransport with RTCP muxing enabled, " 67 "Creating an RtpTransport with RTCP muxing enabled, "
68 "with a separate RTCP packet transport?"); 68 "with a separate RTCP packet transport?");
69 } 69 }
70 if (!rtp_transport_controller) { 70 if (!rtp_transport_controller) {
71 // Since OrtcFactory::CreateRtpTransport creates an RtpTransportController 71 // Since OrtcFactory::CreateRtpTransport creates an RtpTransportController
72 // automatically when one isn't passed in, this should never be reached. 72 // automatically when one isn't passed in, this should never be reached.
73 RTC_NOTREACHED(); 73 RTC_NOTREACHED();
74 LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, 74 LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
75 "Must provide an RTP transport controller."); 75 "Must provide an RTP transport controller.");
76 } 76 }
77 std::unique_ptr<RtpTransportAdapter> transport_adapter(
78 new RtpTransportAdapter(parameters.rtcp, rtp, rtcp,
79 rtp_transport_controller,
80 false /*is_srtp_transport*/));
81 RTCError params_result = transport_adapter->SetParameters(parameters);
82 if (!params_result.ok()) {
83 return std::move(params_result);
84 }
85
77 return RtpTransportProxyWithInternal<RtpTransportAdapter>::Create( 86 return RtpTransportProxyWithInternal<RtpTransportAdapter>::Create(
78 rtp_transport_controller->signaling_thread(), 87 rtp_transport_controller->signaling_thread(),
79 rtp_transport_controller->worker_thread(), 88 rtp_transport_controller->worker_thread(), std::move(transport_adapter));
80 std::unique_ptr<RtpTransportAdapter>(new RtpTransportAdapter(
81 rtcp_parameters, rtp, rtcp, rtp_transport_controller,
82 /*is_srtp_transport*/ false)));
83 } 89 }
84 90
85 RTCErrorOr<std::unique_ptr<SrtpTransportInterface>> 91 RTCErrorOr<std::unique_ptr<SrtpTransportInterface>>
86 RtpTransportAdapter::CreateSrtpProxied( 92 RtpTransportAdapter::CreateSrtpProxied(
87 const RtcpParameters& rtcp_parameters, 93 const RtpTransportParameters& parameters,
88 PacketTransportInterface* rtp, 94 PacketTransportInterface* rtp,
89 PacketTransportInterface* rtcp, 95 PacketTransportInterface* rtcp,
90 RtpTransportControllerAdapter* rtp_transport_controller) { 96 RtpTransportControllerAdapter* rtp_transport_controller) {
91 if (!rtp) { 97 if (!rtp) {
92 LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, 98 LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
93 "Must provide an RTP packet transport."); 99 "Must provide an RTP packet transport.");
94 } 100 }
95 if (!rtcp_parameters.mux && !rtcp) { 101 if (!parameters.rtcp.mux && !rtcp) {
96 LOG_AND_RETURN_ERROR( 102 LOG_AND_RETURN_ERROR(
97 RTCErrorType::INVALID_PARAMETER, 103 RTCErrorType::INVALID_PARAMETER,
98 "Must provide an RTCP packet transport when RTCP muxing is not used."); 104 "Must provide an RTCP packet transport when RTCP muxing is not used.");
99 } 105 }
100 if (rtcp_parameters.mux && rtcp) { 106 if (parameters.rtcp.mux && rtcp) {
101 LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, 107 LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
102 "Creating an RtpTransport with RTCP muxing enabled, " 108 "Creating an RtpTransport with RTCP muxing enabled, "
103 "with a separate RTCP packet transport?"); 109 "with a separate RTCP packet transport?");
104 } 110 }
105 if (!rtp_transport_controller) { 111 if (!rtp_transport_controller) {
106 // Since OrtcFactory::CreateRtpTransport creates an RtpTransportController 112 // Since OrtcFactory::CreateRtpTransport creates an RtpTransportController
107 // automatically when one isn't passed in, this should never be reached. 113 // automatically when one isn't passed in, this should never be reached.
108 RTC_NOTREACHED(); 114 RTC_NOTREACHED();
109 LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, 115 LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
110 "Must provide an RTP transport controller."); 116 "Must provide an RTP transport controller.");
111 } 117 }
118 std::unique_ptr<RtpTransportAdapter> transport_adapter(
119 new RtpTransportAdapter(parameters.rtcp, rtp, rtcp,
120 rtp_transport_controller,
121 true /*is_srtp_transport*/));
122 RTCError params_result = transport_adapter->SetParameters(parameters);
123 if (!params_result.ok()) {
124 return std::move(params_result);
125 }
126
112 return SrtpTransportProxyWithInternal<RtpTransportAdapter>::Create( 127 return SrtpTransportProxyWithInternal<RtpTransportAdapter>::Create(
113 rtp_transport_controller->signaling_thread(), 128 rtp_transport_controller->signaling_thread(),
114 rtp_transport_controller->worker_thread(), 129 rtp_transport_controller->worker_thread(), std::move(transport_adapter));
115 std::unique_ptr<RtpTransportAdapter>(new RtpTransportAdapter(
116 rtcp_parameters, rtp, rtcp, rtp_transport_controller,
117 /*is_srtp_transport*/ true)));
118 } 130 }
119 131
120 void RtpTransportAdapter::TakeOwnershipOfRtpTransportController( 132 void RtpTransportAdapter::TakeOwnershipOfRtpTransportController(
121 std::unique_ptr<RtpTransportControllerInterface> controller) { 133 std::unique_ptr<RtpTransportControllerInterface> controller) {
122 RTC_DCHECK_EQ(rtp_transport_controller_, controller->GetInternal()); 134 RTC_DCHECK_EQ(rtp_transport_controller_, controller->GetInternal());
123 RTC_DCHECK(owned_rtp_transport_controller_.get() == nullptr); 135 RTC_DCHECK(owned_rtp_transport_controller_.get() == nullptr);
124 owned_rtp_transport_controller_ = std::move(controller); 136 owned_rtp_transport_controller_ = std::move(controller);
125 } 137 }
126 138
127 RtpTransportAdapter::RtpTransportAdapter( 139 RtpTransportAdapter::RtpTransportAdapter(
128 const RtcpParameters& rtcp_parameters, 140 const RtcpParameters& rtcp_params,
129 PacketTransportInterface* rtp, 141 PacketTransportInterface* rtp,
130 PacketTransportInterface* rtcp, 142 PacketTransportInterface* rtcp,
131 RtpTransportControllerAdapter* rtp_transport_controller, 143 RtpTransportControllerAdapter* rtp_transport_controller,
132 bool is_srtp_transport) 144 bool is_srtp_transport)
133 : rtp_packet_transport_(rtp), 145 : rtp_packet_transport_(rtp),
134 rtcp_packet_transport_(rtcp), 146 rtcp_packet_transport_(rtcp),
135 rtp_transport_controller_(rtp_transport_controller), 147 rtp_transport_controller_(rtp_transport_controller),
136 rtcp_parameters_(rtcp_parameters),
137 is_srtp_transport_(is_srtp_transport) { 148 is_srtp_transport_(is_srtp_transport) {
149 parameters_.rtcp = rtcp_params;
150 // CNAME should have been filled by OrtcFactory if empty.
151 RTC_DCHECK(!parameters_.rtcp.cname.empty());
138 RTC_DCHECK(rtp_transport_controller); 152 RTC_DCHECK(rtp_transport_controller);
139 // CNAME should have been filled by OrtcFactory if empty.
140 RTC_DCHECK(!rtcp_parameters_.cname.empty());
141 } 153 }
142 154
143 RtpTransportAdapter::~RtpTransportAdapter() { 155 RtpTransportAdapter::~RtpTransportAdapter() {
144 SignalDestroyed(this); 156 SignalDestroyed(this);
145 } 157 }
146 158
147 PacketTransportInterface* RtpTransportAdapter::GetRtpPacketTransport() const { 159 PacketTransportInterface* RtpTransportAdapter::GetRtpPacketTransport() const {
148 return rtp_packet_transport_; 160 return rtp_packet_transport_;
149 } 161 }
150 162
151 PacketTransportInterface* RtpTransportAdapter::GetRtcpPacketTransport() const { 163 PacketTransportInterface* RtpTransportAdapter::GetRtcpPacketTransport() const {
152 return rtcp_packet_transport_; 164 return rtcp_packet_transport_;
153 } 165 }
154 166
155 RTCError RtpTransportAdapter::SetRtcpParameters( 167 RTCError RtpTransportAdapter::SetParameters(
156 const RtcpParameters& parameters) { 168 const RtpTransportParameters& parameters) {
157 if (!parameters.mux && rtcp_parameters_.mux) { 169 if (!parameters.rtcp.mux && parameters_.rtcp.mux) {
158 LOG_AND_RETURN_ERROR(webrtc::RTCErrorType::INVALID_STATE, 170 LOG_AND_RETURN_ERROR(webrtc::RTCErrorType::INVALID_STATE,
159 "Can't disable RTCP muxing after enabling."); 171 "Can't disable RTCP muxing after enabling.");
160 } 172 }
161 if (!parameters.cname.empty() && parameters.cname != rtcp_parameters_.cname) { 173 if (!parameters.rtcp.cname.empty() &&
174 parameters.rtcp.cname != parameters_.rtcp.cname) {
162 LOG_AND_RETURN_ERROR(webrtc::RTCErrorType::UNSUPPORTED_OPERATION, 175 LOG_AND_RETURN_ERROR(webrtc::RTCErrorType::UNSUPPORTED_OPERATION,
163 "Changing the RTCP CNAME is currently unsupported."); 176 "Changing the RTCP CNAME is currently unsupported.");
164 } 177 }
165 // If the CNAME is empty, use the existing one. 178 // If the CNAME is empty, use the existing one.
166 RtcpParameters copy = parameters; 179 RtpTransportParameters copy = parameters;
167 if (copy.cname.empty()) { 180 if (copy.rtcp.cname.empty()) {
168 copy.cname = rtcp_parameters_.cname; 181 copy.rtcp.cname = parameters_.rtcp.cname;
169 } 182 }
170 RTCError err = rtp_transport_controller_->SetRtcpParameters(copy, this); 183 RTCError err =
184 rtp_transport_controller_->SetRtpTransportParameters(copy, this);
171 if (!err.ok()) { 185 if (!err.ok()) {
172 return err; 186 return err;
173 } 187 }
174 rtcp_parameters_ = copy; 188 parameters_ = copy;
175 if (rtcp_parameters_.mux) { 189 if (parameters_.rtcp.mux) {
176 rtcp_packet_transport_ = nullptr; 190 rtcp_packet_transport_ = nullptr;
177 } 191 }
178 return RTCError::OK(); 192 return RTCError::OK();
179 } 193 }
180 194
181 RTCError RtpTransportAdapter::SetSrtpSendKey( 195 RTCError RtpTransportAdapter::SetSrtpSendKey(
182 const cricket::CryptoParams& params) { 196 const cricket::CryptoParams& params) {
183 if (send_key_) { 197 if (send_key_) {
184 LOG_AND_RETURN_ERROR( 198 LOG_AND_RETURN_ERROR(
185 webrtc::RTCErrorType::UNSUPPORTED_OPERATION, 199 webrtc::RTCErrorType::UNSUPPORTED_OPERATION,
(...skipping 18 matching lines...) Expand all
204 if (send_key_ && send_key_->cipher_suite != params.cipher_suite) { 218 if (send_key_ && send_key_->cipher_suite != params.cipher_suite) {
205 LOG_AND_RETURN_ERROR( 219 LOG_AND_RETURN_ERROR(
206 webrtc::RTCErrorType::UNSUPPORTED_OPERATION, 220 webrtc::RTCErrorType::UNSUPPORTED_OPERATION,
207 "The send key and receive key must have the same cipher suite."); 221 "The send key and receive key must have the same cipher suite.");
208 } 222 }
209 receive_key_ = rtc::Optional<cricket::CryptoParams>(params); 223 receive_key_ = rtc::Optional<cricket::CryptoParams>(params);
210 return RTCError::OK(); 224 return RTCError::OK();
211 } 225 }
212 226
213 } // namespace webrtc 227 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/ortc/rtptransportadapter.h ('k') | webrtc/ortc/rtptransportcontrolleradapter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698