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