OLD | NEW |
---|---|
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 RTCErrorOr<std::unique_ptr<RtpTransportInterface>>( | |
84 std::move(params_result)); | |
Taylor Brandstetter
2017/08/07 19:59:36
nit: I think you should be able to just return "st
sprang_webrtc
2017/08/08 08:15:13
Right, thanks!
| |
85 } | |
86 | |
77 return RtpTransportProxyWithInternal<RtpTransportAdapter>::Create( | 87 return RtpTransportProxyWithInternal<RtpTransportAdapter>::Create( |
78 rtp_transport_controller->signaling_thread(), | 88 rtp_transport_controller->signaling_thread(), |
79 rtp_transport_controller->worker_thread(), | 89 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 } | 90 } |
84 | 91 |
85 RTCErrorOr<std::unique_ptr<SrtpTransportInterface>> | 92 RTCErrorOr<std::unique_ptr<SrtpTransportInterface>> |
86 RtpTransportAdapter::CreateSrtpProxied( | 93 RtpTransportAdapter::CreateSrtpProxied( |
87 const RtcpParameters& rtcp_parameters, | 94 const RtpTransportParameters& parameters, |
88 PacketTransportInterface* rtp, | 95 PacketTransportInterface* rtp, |
89 PacketTransportInterface* rtcp, | 96 PacketTransportInterface* rtcp, |
90 RtpTransportControllerAdapter* rtp_transport_controller) { | 97 RtpTransportControllerAdapter* rtp_transport_controller) { |
91 if (!rtp) { | 98 if (!rtp) { |
92 LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, | 99 LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, |
93 "Must provide an RTP packet transport."); | 100 "Must provide an RTP packet transport."); |
94 } | 101 } |
95 if (!rtcp_parameters.mux && !rtcp) { | 102 if (!parameters.rtcp.mux && !rtcp) { |
96 LOG_AND_RETURN_ERROR( | 103 LOG_AND_RETURN_ERROR( |
97 RTCErrorType::INVALID_PARAMETER, | 104 RTCErrorType::INVALID_PARAMETER, |
98 "Must provide an RTCP packet transport when RTCP muxing is not used."); | 105 "Must provide an RTCP packet transport when RTCP muxing is not used."); |
99 } | 106 } |
100 if (rtcp_parameters.mux && rtcp) { | 107 if (parameters.rtcp.mux && rtcp) { |
101 LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, | 108 LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, |
102 "Creating an RtpTransport with RTCP muxing enabled, " | 109 "Creating an RtpTransport with RTCP muxing enabled, " |
103 "with a separate RTCP packet transport?"); | 110 "with a separate RTCP packet transport?"); |
104 } | 111 } |
105 if (!rtp_transport_controller) { | 112 if (!rtp_transport_controller) { |
106 // Since OrtcFactory::CreateRtpTransport creates an RtpTransportController | 113 // Since OrtcFactory::CreateRtpTransport creates an RtpTransportController |
107 // automatically when one isn't passed in, this should never be reached. | 114 // automatically when one isn't passed in, this should never be reached. |
108 RTC_NOTREACHED(); | 115 RTC_NOTREACHED(); |
109 LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, | 116 LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, |
110 "Must provide an RTP transport controller."); | 117 "Must provide an RTP transport controller."); |
111 } | 118 } |
119 std::unique_ptr<RtpTransportAdapter> transport_adapter( | |
120 new RtpTransportAdapter(parameters.rtcp, rtp, rtcp, | |
121 rtp_transport_controller, | |
122 true /*is_srtp_transport*/)); | |
123 RTCError params_result = transport_adapter->SetParameters(parameters); | |
124 if (!params_result.ok()) { | |
125 return RTCErrorOr<std::unique_ptr<SrtpTransportInterface>>( | |
126 std::move(params_result)); | |
127 } | |
128 | |
112 return SrtpTransportProxyWithInternal<RtpTransportAdapter>::Create( | 129 return SrtpTransportProxyWithInternal<RtpTransportAdapter>::Create( |
113 rtp_transport_controller->signaling_thread(), | 130 rtp_transport_controller->signaling_thread(), |
114 rtp_transport_controller->worker_thread(), | 131 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 } | 132 } |
119 | 133 |
120 void RtpTransportAdapter::TakeOwnershipOfRtpTransportController( | 134 void RtpTransportAdapter::TakeOwnershipOfRtpTransportController( |
121 std::unique_ptr<RtpTransportControllerInterface> controller) { | 135 std::unique_ptr<RtpTransportControllerInterface> controller) { |
122 RTC_DCHECK_EQ(rtp_transport_controller_, controller->GetInternal()); | 136 RTC_DCHECK_EQ(rtp_transport_controller_, controller->GetInternal()); |
123 RTC_DCHECK(owned_rtp_transport_controller_.get() == nullptr); | 137 RTC_DCHECK(owned_rtp_transport_controller_.get() == nullptr); |
124 owned_rtp_transport_controller_ = std::move(controller); | 138 owned_rtp_transport_controller_ = std::move(controller); |
125 } | 139 } |
126 | 140 |
127 RtpTransportAdapter::RtpTransportAdapter( | 141 RtpTransportAdapter::RtpTransportAdapter( |
128 const RtcpParameters& rtcp_parameters, | 142 const RtcpParameters& rtcp_params, |
129 PacketTransportInterface* rtp, | 143 PacketTransportInterface* rtp, |
130 PacketTransportInterface* rtcp, | 144 PacketTransportInterface* rtcp, |
131 RtpTransportControllerAdapter* rtp_transport_controller, | 145 RtpTransportControllerAdapter* rtp_transport_controller, |
132 bool is_srtp_transport) | 146 bool is_srtp_transport) |
133 : rtp_packet_transport_(rtp), | 147 : rtp_packet_transport_(rtp), |
134 rtcp_packet_transport_(rtcp), | 148 rtcp_packet_transport_(rtcp), |
135 rtp_transport_controller_(rtp_transport_controller), | 149 rtp_transport_controller_(rtp_transport_controller), |
136 rtcp_parameters_(rtcp_parameters), | |
137 is_srtp_transport_(is_srtp_transport) { | 150 is_srtp_transport_(is_srtp_transport) { |
151 parameters_.rtcp = rtcp_params; | |
152 // CNAME should have been filled by OrtcFactory if empty. | |
153 RTC_DCHECK(!parameters_.rtcp.cname.empty()); | |
138 RTC_DCHECK(rtp_transport_controller); | 154 RTC_DCHECK(rtp_transport_controller); |
139 // CNAME should have been filled by OrtcFactory if empty. | |
140 RTC_DCHECK(!rtcp_parameters_.cname.empty()); | |
141 } | 155 } |
142 | 156 |
143 RtpTransportAdapter::~RtpTransportAdapter() { | 157 RtpTransportAdapter::~RtpTransportAdapter() { |
144 SignalDestroyed(this); | 158 SignalDestroyed(this); |
145 } | 159 } |
146 | 160 |
147 PacketTransportInterface* RtpTransportAdapter::GetRtpPacketTransport() const { | 161 PacketTransportInterface* RtpTransportAdapter::GetRtpPacketTransport() const { |
148 return rtp_packet_transport_; | 162 return rtp_packet_transport_; |
149 } | 163 } |
150 | 164 |
151 PacketTransportInterface* RtpTransportAdapter::GetRtcpPacketTransport() const { | 165 PacketTransportInterface* RtpTransportAdapter::GetRtcpPacketTransport() const { |
152 return rtcp_packet_transport_; | 166 return rtcp_packet_transport_; |
153 } | 167 } |
154 | 168 |
155 RTCError RtpTransportAdapter::SetRtcpParameters( | 169 RTCError RtpTransportAdapter::SetParameters( |
156 const RtcpParameters& parameters) { | 170 const RtpTransportParameters& parameters) { |
157 if (!parameters.mux && rtcp_parameters_.mux) { | 171 if (!parameters.rtcp.mux && parameters_.rtcp.mux) { |
158 LOG_AND_RETURN_ERROR(webrtc::RTCErrorType::INVALID_STATE, | 172 LOG_AND_RETURN_ERROR(webrtc::RTCErrorType::INVALID_STATE, |
159 "Can't disable RTCP muxing after enabling."); | 173 "Can't disable RTCP muxing after enabling."); |
160 } | 174 } |
161 if (!parameters.cname.empty() && parameters.cname != rtcp_parameters_.cname) { | 175 if (!parameters.rtcp.cname.empty() && |
176 parameters.rtcp.cname != parameters_.rtcp.cname) { | |
162 LOG_AND_RETURN_ERROR(webrtc::RTCErrorType::UNSUPPORTED_OPERATION, | 177 LOG_AND_RETURN_ERROR(webrtc::RTCErrorType::UNSUPPORTED_OPERATION, |
163 "Changing the RTCP CNAME is currently unsupported."); | 178 "Changing the RTCP CNAME is currently unsupported."); |
164 } | 179 } |
165 // If the CNAME is empty, use the existing one. | 180 // If the CNAME is empty, use the existing one. |
166 RtcpParameters copy = parameters; | 181 RtpTransportParameters copy = parameters; |
167 if (copy.cname.empty()) { | 182 if (copy.rtcp.cname.empty()) { |
168 copy.cname = rtcp_parameters_.cname; | 183 copy.rtcp.cname = parameters_.rtcp.cname; |
169 } | 184 } |
170 RTCError err = rtp_transport_controller_->SetRtcpParameters(copy, this); | 185 RTCError err = |
186 rtp_transport_controller_->SetRtpTransportParameters(copy, this); | |
171 if (!err.ok()) { | 187 if (!err.ok()) { |
172 return err; | 188 return err; |
173 } | 189 } |
174 rtcp_parameters_ = copy; | 190 parameters_ = copy; |
175 if (rtcp_parameters_.mux) { | 191 if (parameters_.rtcp.mux) { |
176 rtcp_packet_transport_ = nullptr; | 192 rtcp_packet_transport_ = nullptr; |
177 } | 193 } |
178 return RTCError::OK(); | 194 return RTCError::OK(); |
179 } | 195 } |
180 | 196 |
181 RTCError RtpTransportAdapter::SetSrtpSendKey( | 197 RTCError RtpTransportAdapter::SetSrtpSendKey( |
182 const cricket::CryptoParams& params) { | 198 const cricket::CryptoParams& params) { |
183 if (send_key_) { | 199 if (send_key_) { |
184 LOG_AND_RETURN_ERROR( | 200 LOG_AND_RETURN_ERROR( |
185 webrtc::RTCErrorType::UNSUPPORTED_OPERATION, | 201 webrtc::RTCErrorType::UNSUPPORTED_OPERATION, |
(...skipping 18 matching lines...) Expand all Loading... | |
204 if (send_key_ && send_key_->cipher_suite != params.cipher_suite) { | 220 if (send_key_ && send_key_->cipher_suite != params.cipher_suite) { |
205 LOG_AND_RETURN_ERROR( | 221 LOG_AND_RETURN_ERROR( |
206 webrtc::RTCErrorType::UNSUPPORTED_OPERATION, | 222 webrtc::RTCErrorType::UNSUPPORTED_OPERATION, |
207 "The send key and receive key must have the same cipher suite."); | 223 "The send key and receive key must have the same cipher suite."); |
208 } | 224 } |
209 receive_key_ = rtc::Optional<cricket::CryptoParams>(params); | 225 receive_key_ = rtc::Optional<cricket::CryptoParams>(params); |
210 return RTCError::OK(); | 226 return RTCError::OK(); |
211 } | 227 } |
212 | 228 |
213 } // namespace webrtc | 229 } // namespace webrtc |
OLD | NEW |