OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2017 The WebRTC project authors. All Rights Reserved. | |
3 * | |
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 | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 #include "webrtc/ortc/rtptransportadapter.h" | |
12 | |
13 #include <algorithm> // For std::find. | |
14 #include <set> | |
15 #include <sstream> | |
16 #include <utility> // For std::move. | |
17 | |
18 #include "webrtc/api/proxy.h" | |
19 #include "webrtc/base/logging.h" | |
20 | |
21 namespace webrtc { | |
22 | |
23 BEGIN_OWNED_PROXY_MAP(RtpTransport) | |
24 PROXY_SIGNALING_THREAD_DESTRUCTOR() | |
25 PROXY_CONSTMETHOD0(PacketTransportInterface*, GetRtpPacketTransport) | |
26 PROXY_CONSTMETHOD0(PacketTransportInterface*, GetRtcpPacketTransport) | |
27 PROXY_METHOD1(RTCError, SetRtcpParameters, const RtcpParameters&) | |
28 PROXY_CONSTMETHOD0(RtcpParameters, GetRtcpParameters) | |
29 protected: | |
30 RtpTransportAdapter* GetInternal() override { | |
31 return internal(); | |
32 } | |
33 END_PROXY_MAP() | |
34 | |
35 BEGIN_OWNED_PROXY_MAP(SrtpTransport) | |
36 PROXY_SIGNALING_THREAD_DESTRUCTOR() | |
37 PROXY_CONSTMETHOD0(PacketTransportInterface*, GetRtpPacketTransport) | |
38 PROXY_CONSTMETHOD0(PacketTransportInterface*, GetRtcpPacketTransport) | |
39 PROXY_METHOD1(RTCError, SetRtcpParameters, const RtcpParameters&) | |
40 PROXY_CONSTMETHOD0(RtcpParameters, GetRtcpParameters) | |
41 PROXY_METHOD1(RTCError, SetSrtpSendKey, const cricket::CryptoParams&) | |
42 PROXY_METHOD1(RTCError, SetSrtpReceiveKey, const cricket::CryptoParams&) | |
43 protected: | |
44 RtpTransportAdapter* GetInternal() override { | |
45 return internal(); | |
46 } | |
47 END_PROXY_MAP() | |
48 | |
49 // static | |
50 RTCErrorOr<std::unique_ptr<RtpTransportInterface>> | |
51 RtpTransportAdapter::CreateProxied( | |
52 const RtcpParameters& rtcp_parameters, | |
53 PacketTransportInterface* rtp, | |
54 PacketTransportInterface* rtcp, | |
55 RtpTransportControllerAdapter* rtp_transport_controller) { | |
56 if (!rtp) { | |
57 LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, | |
58 "Must provide an RTP packet transport."); | |
59 } | |
60 if (!rtcp_parameters.mux && !rtcp) { | |
61 LOG_AND_RETURN_ERROR( | |
62 RTCErrorType::INVALID_PARAMETER, | |
63 "Must provide an RTCP packet transport when RTCP muxing is not used."); | |
64 } | |
65 if (rtcp_parameters.mux && rtcp) { | |
66 LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, | |
67 "Creating an RtpTransport with RTCP muxing enabled, " | |
68 "with a separate RTCP packet transport?"); | |
69 } | |
70 if (!rtp_transport_controller) { | |
71 // Since OrtcFactory::CreateRtpTransport creates an RtpTransportController | |
72 // automatically when one isn't passed in, this should never be reached. | |
73 RTC_NOTREACHED(); | |
74 LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, | |
75 "Must provide an RTP transport controller."); | |
76 } | |
77 return RtpTransportProxyWithInternal<RtpTransportAdapter>::Create( | |
78 rtp_transport_controller->signaling_thread(), | |
79 rtp_transport_controller->worker_thread(), | |
80 new RtpTransportAdapter(rtcp_parameters, rtp, rtcp, | |
81 rtp_transport_controller, | |
82 /*is_srtp_transport*/ false)); | |
83 } | |
84 | |
85 RTCErrorOr<std::unique_ptr<SrtpTransportInterface>> | |
86 RtpTransportAdapter::CreateSrtpProxied( | |
87 const RtcpParameters& rtcp_parameters, | |
88 PacketTransportInterface* rtp, | |
89 PacketTransportInterface* rtcp, | |
90 RtpTransportControllerAdapter* rtp_transport_controller) { | |
91 if (!rtp) { | |
92 LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, | |
93 "Must provide an RTP packet transport."); | |
94 } | |
95 if (!rtcp_parameters.mux && !rtcp) { | |
96 LOG_AND_RETURN_ERROR( | |
97 RTCErrorType::INVALID_PARAMETER, | |
98 "Must provide an RTCP packet transport when RTCP muxing is not used."); | |
99 } | |
100 if (rtcp_parameters.mux && rtcp) { | |
101 LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, | |
102 "Creating an RtpTransport with RTCP muxing enabled, " | |
103 "with a separate RTCP packet transport?"); | |
104 } | |
105 if (!rtp_transport_controller) { | |
106 // Since OrtcFactory::CreateRtpTransport creates an RtpTransportController | |
107 // automatically when one isn't passed in, this should never be reached. | |
108 RTC_NOTREACHED(); | |
109 LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, | |
110 "Must provide an RTP transport controller."); | |
111 } | |
112 return SrtpTransportProxyWithInternal<RtpTransportAdapter>::Create( | |
113 rtp_transport_controller->signaling_thread(), | |
114 rtp_transport_controller->worker_thread(), | |
115 new RtpTransportAdapter(rtcp_parameters, rtp, rtcp, | |
116 rtp_transport_controller, | |
117 /*is_srtp_transport*/ true)); | |
118 } | |
119 | |
120 void RtpTransportAdapter::TakeOwnershipOfRtpTransportController( | |
121 std::unique_ptr<RtpTransportControllerInterface> controller) { | |
122 RTC_DCHECK_EQ(rtp_transport_controller_, controller->GetInternal()); | |
123 RTC_DCHECK(owned_rtp_transport_controller_.get() == nullptr); | |
124 owned_rtp_transport_controller_ = std::move(controller); | |
125 } | |
126 | |
127 RtpTransportAdapter::RtpTransportAdapter( | |
128 const RtcpParameters& rtcp_parameters, | |
129 PacketTransportInterface* rtp, | |
130 PacketTransportInterface* rtcp, | |
131 RtpTransportControllerAdapter* rtp_transport_controller, | |
132 bool is_srtp_transport) | |
133 : rtp_packet_transport_(rtp), | |
134 rtcp_packet_transport_(rtcp), | |
135 rtp_transport_controller_(rtp_transport_controller), | |
136 rtcp_parameters_(rtcp_parameters), | |
137 is_srtp_transport_(is_srtp_transport), | |
138 have_send_key_(false), | |
139 have_receive_key_(false) { | |
140 RTC_DCHECK(rtp_transport_controller); | |
141 // CNAME should have been filled by OrtcFactory if empty. | |
142 RTC_DCHECK(!rtcp_parameters_.cname.empty()); | |
143 } | |
144 | |
145 RtpTransportAdapter::~RtpTransportAdapter() { | |
146 SignalDestroyed(this); | |
147 } | |
148 | |
149 PacketTransportInterface* RtpTransportAdapter::GetRtpPacketTransport() const { | |
150 return rtp_packet_transport_; | |
151 } | |
152 | |
153 PacketTransportInterface* RtpTransportAdapter::GetRtcpPacketTransport() const { | |
154 return rtcp_packet_transport_; | |
155 } | |
156 | |
157 RTCError RtpTransportAdapter::SetRtcpParameters( | |
158 const RtcpParameters& parameters) { | |
159 if (!parameters.mux && rtcp_parameters_.mux) { | |
160 LOG_AND_RETURN_ERROR(webrtc::RTCErrorType::INVALID_STATE, | |
161 "Can't disable RTCP muxing after enabling."); | |
162 } | |
163 if (!parameters.cname.empty() && parameters.cname != rtcp_parameters_.cname) { | |
164 LOG_AND_RETURN_ERROR(webrtc::RTCErrorType::UNSUPPORTED_OPERATION, | |
165 "Changing the RTCP CNAME is currently unsupported."); | |
166 } | |
167 // If the CNAME is empty, use the existing one. | |
168 RtcpParameters copy = parameters; | |
169 if (copy.cname.empty()) { | |
170 copy.cname = rtcp_parameters_.cname; | |
171 } | |
172 RTCError err = rtp_transport_controller_->SetRtcpParameters(copy, this); | |
173 if (!err.ok()) { | |
174 return err; | |
175 } | |
176 rtcp_parameters_ = copy; | |
177 if (rtcp_parameters_.mux) { | |
178 rtcp_packet_transport_ = nullptr; | |
179 } | |
180 return RTCError::OK(); | |
181 } | |
182 | |
183 RTCError RtpTransportAdapter::SetSrtpSendKey( | |
184 const cricket::CryptoParams& params) { | |
185 if (have_send_key_) { | |
186 LOG_AND_RETURN_ERROR(webrtc::RTCErrorType::UNSUPPORTED_OPERATION, | |
187 "Re-set the SRTP send key is currently unsupported."); | |
Taylor Brandstetter
2017/02/24 18:57:58
nit: "Re-setting", or maybe "Setting the SRTP send
Zhi Huang
2017/02/27 05:16:00
Done.
| |
188 } | |
189 RTCError err = rtp_transport_controller_->SetSrtpSendKey(params, this); | |
190 if (!err.ok()) { | |
191 return err; | |
192 } | |
193 have_send_key_ = true; | |
194 return RTCError::OK(); | |
195 } | |
196 | |
197 RTCError RtpTransportAdapter::SetSrtpReceiveKey( | |
198 const cricket::CryptoParams& params) { | |
199 if (have_receive_key_) { | |
200 LOG_AND_RETURN_ERROR( | |
201 webrtc::RTCErrorType::UNSUPPORTED_OPERATION, | |
202 "Re-set the SRTP receive key is currently unsupported."); | |
203 } | |
204 RTCError err = rtp_transport_controller_->SetSrtpReceiveKey(params, this); | |
205 if (!err.ok()) { | |
206 return err; | |
207 } | |
208 have_receive_key_ = true; | |
209 return RTCError::OK(); | |
210 } | |
211 | |
212 bool RtpTransportAdapter::TransportReadyToSendAndReceive() { | |
213 return !is_srtp_transport_ || | |
214 (is_srtp_transport_ && have_send_key_ && have_receive_key_); | |
215 } | |
216 | |
217 } // namespace webrtc | |
OLD | NEW |