OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2004 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 |
(...skipping 25 matching lines...) Expand all Loading... | |
36 std::unique_ptr<webrtc::AudioSinkInterface>* sink) { | 36 std::unique_ptr<webrtc::AudioSinkInterface>* sink) { |
37 channel->SetRawAudioSink(ssrc, std::move(*sink)); | 37 channel->SetRawAudioSink(ssrc, std::move(*sink)); |
38 return true; | 38 return true; |
39 } | 39 } |
40 | 40 |
41 struct SendPacketMessageData : public rtc::MessageData { | 41 struct SendPacketMessageData : public rtc::MessageData { |
42 rtc::CopyOnWriteBuffer packet; | 42 rtc::CopyOnWriteBuffer packet; |
43 rtc::PacketOptions options; | 43 rtc::PacketOptions options; |
44 }; | 44 }; |
45 | 45 |
46 #if defined(ENABLE_EXTERNAL_AUTH) | |
47 // Returns the named header extension if found among all extensions, | |
48 // nullptr otherwise. | |
49 const webrtc::RtpExtension* FindHeaderExtension( | |
50 const std::vector<webrtc::RtpExtension>& extensions, | |
51 const std::string& uri) { | |
52 for (const auto& extension : extensions) { | |
53 if (extension.uri == uri) | |
54 return &extension; | |
55 } | |
56 return nullptr; | |
57 } | |
58 #endif | |
59 | |
60 } // namespace | 46 } // namespace |
61 | 47 |
62 enum { | 48 enum { |
63 MSG_EARLYMEDIATIMEOUT = 1, | 49 MSG_EARLYMEDIATIMEOUT = 1, |
64 MSG_SEND_RTP_PACKET, | 50 MSG_SEND_RTP_PACKET, |
65 MSG_SEND_RTCP_PACKET, | 51 MSG_SEND_RTCP_PACKET, |
66 MSG_CHANNEL_ERROR, | 52 MSG_CHANNEL_ERROR, |
67 MSG_READYTOSENDDATA, | 53 MSG_READYTOSENDDATA, |
68 MSG_DATARECEIVED, | 54 MSG_DATARECEIVED, |
69 MSG_FIRSTPACKETRECEIVED, | 55 MSG_FIRSTPACKETRECEIVED, |
(...skipping 1073 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1143 | 1129 |
1144 LOG(LS_INFO) << "Channel not writable (" << content_name_ << ")"; | 1130 LOG(LS_INFO) << "Channel not writable (" << content_name_ << ")"; |
1145 writable_ = false; | 1131 writable_ = false; |
1146 UpdateMediaSendRecvState(); | 1132 UpdateMediaSendRecvState(); |
1147 } | 1133 } |
1148 | 1134 |
1149 bool BaseChannel::SetRtpTransportParameters( | 1135 bool BaseChannel::SetRtpTransportParameters( |
1150 const MediaContentDescription* content, | 1136 const MediaContentDescription* content, |
1151 ContentAction action, | 1137 ContentAction action, |
1152 ContentSource src, | 1138 ContentSource src, |
1139 const RtpHeaderExtensions& extensions, | |
1153 std::string* error_desc) { | 1140 std::string* error_desc) { |
1154 if (action == CA_UPDATE) { | 1141 if (action == CA_UPDATE) { |
1155 // These parameters never get changed by a CA_UDPATE. | 1142 // These parameters never get changed by a CA_UDPATE. |
1156 return true; | 1143 return true; |
1157 } | 1144 } |
1158 | 1145 |
1146 RtpHeaderExtensions encrypted_extensions; | |
1147 for (const webrtc::RtpExtension& extension : extensions) { | |
1148 if (extension.encrypt) { | |
1149 LOG(LS_INFO) << "Using " << src << " encrypted extension: " | |
Taylor Brandstetter
2017/03/23 20:10:56
nit: "src" will print as "0" or "1" (I believe), w
joachim
2017/03/30 22:43:49
Done.
| |
1150 << extension.ToString(); | |
1151 encrypted_extensions.push_back(extension); | |
1152 } | |
1153 } | |
1154 | |
1159 // Cache srtp_required_ for belt and suspenders check on SendPacket | 1155 // Cache srtp_required_ for belt and suspenders check on SendPacket |
1160 return network_thread_->Invoke<bool>( | 1156 return network_thread_->Invoke<bool>( |
1161 RTC_FROM_HERE, Bind(&BaseChannel::SetRtpTransportParameters_n, this, | 1157 RTC_FROM_HERE, Bind(&BaseChannel::SetRtpTransportParameters_n, this, |
1162 content, action, src, error_desc)); | 1158 content, action, src, encrypted_extensions, |
1159 error_desc)); | |
1163 } | 1160 } |
1164 | 1161 |
1165 bool BaseChannel::SetRtpTransportParameters_n( | 1162 bool BaseChannel::SetRtpTransportParameters_n( |
1166 const MediaContentDescription* content, | 1163 const MediaContentDescription* content, |
1167 ContentAction action, | 1164 ContentAction action, |
1168 ContentSource src, | 1165 ContentSource src, |
1166 const RtpHeaderExtensions& encrypted_extensions, | |
1169 std::string* error_desc) { | 1167 std::string* error_desc) { |
1170 RTC_DCHECK(network_thread_->IsCurrent()); | 1168 RTC_DCHECK(network_thread_->IsCurrent()); |
1171 | 1169 |
1172 if (!SetSrtp_n(content->cryptos(), action, src, error_desc)) { | 1170 if (!SetSrtp_n(content->cryptos(), action, src, encrypted_extensions, |
1171 error_desc)) { | |
1173 return false; | 1172 return false; |
1174 } | 1173 } |
1175 | 1174 |
1176 if (!SetRtcpMux_n(content->rtcp_mux(), action, src, error_desc)) { | 1175 if (!SetRtcpMux_n(content->rtcp_mux(), action, src, error_desc)) { |
1177 return false; | 1176 return false; |
1178 } | 1177 } |
1179 | 1178 |
1180 return true; | 1179 return true; |
1181 } | 1180 } |
1182 | 1181 |
1183 // |dtls| will be set to true if DTLS is active for transport and crypto is | 1182 // |dtls| will be set to true if DTLS is active for transport and crypto is |
1184 // empty. | 1183 // empty. |
1185 bool BaseChannel::CheckSrtpConfig_n(const std::vector<CryptoParams>& cryptos, | 1184 bool BaseChannel::CheckSrtpConfig_n(const std::vector<CryptoParams>& cryptos, |
1186 bool* dtls, | 1185 bool* dtls, |
1187 std::string* error_desc) { | 1186 std::string* error_desc) { |
1188 *dtls = rtp_dtls_transport_ && rtp_dtls_transport_->IsDtlsActive(); | 1187 *dtls = rtp_dtls_transport_ && rtp_dtls_transport_->IsDtlsActive(); |
1189 if (*dtls && !cryptos.empty()) { | 1188 if (*dtls && !cryptos.empty()) { |
1190 SafeSetError("Cryptos must be empty when DTLS is active.", error_desc); | 1189 SafeSetError("Cryptos must be empty when DTLS is active.", error_desc); |
1191 return false; | 1190 return false; |
1192 } | 1191 } |
1193 return true; | 1192 return true; |
1194 } | 1193 } |
1195 | 1194 |
1196 bool BaseChannel::SetSrtp_n(const std::vector<CryptoParams>& cryptos, | 1195 bool BaseChannel::SetSrtp_n(const std::vector<CryptoParams>& cryptos, |
1197 ContentAction action, | 1196 ContentAction action, |
1198 ContentSource src, | 1197 ContentSource src, |
1198 const RtpHeaderExtensions& encrypted_extensions, | |
1199 std::string* error_desc) { | 1199 std::string* error_desc) { |
1200 TRACE_EVENT0("webrtc", "BaseChannel::SetSrtp_w"); | 1200 TRACE_EVENT0("webrtc", "BaseChannel::SetSrtp_w"); |
1201 if (action == CA_UPDATE) { | 1201 if (action == CA_UPDATE) { |
1202 // no crypto params. | 1202 // no crypto params. |
1203 return true; | 1203 return true; |
1204 } | 1204 } |
1205 bool ret = false; | 1205 bool ret = false; |
1206 bool dtls = false; | 1206 bool dtls = false; |
1207 ret = CheckSrtpConfig_n(cryptos, &dtls, error_desc); | 1207 ret = CheckSrtpConfig_n(cryptos, &dtls, error_desc); |
1208 if (!ret) { | 1208 if (!ret) { |
1209 return false; | 1209 return false; |
1210 } | 1210 } |
1211 srtp_filter_.SetEncryptedHeaderExtensions(src, encrypted_extensions); | |
1211 switch (action) { | 1212 switch (action) { |
1212 case CA_OFFER: | 1213 case CA_OFFER: |
1213 // If DTLS is already active on the channel, we could be renegotiating | 1214 // If DTLS is already active on the channel, we could be renegotiating |
1214 // here. We don't update the srtp filter. | 1215 // here. We don't update the srtp filter. |
1215 if (!dtls) { | 1216 if (!dtls) { |
1216 ret = srtp_filter_.SetOffer(cryptos, src); | 1217 ret = srtp_filter_.SetOffer(cryptos, src); |
1217 } | 1218 } |
1218 break; | 1219 break; |
1219 case CA_PRANSWER: | 1220 case CA_PRANSWER: |
1220 // If we're doing DTLS-SRTP, we don't want to update the filter | 1221 // If we're doing DTLS-SRTP, we don't want to update the filter |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1463 return ret; | 1464 return ret; |
1464 } | 1465 } |
1465 | 1466 |
1466 void BaseChannel::MaybeCacheRtpAbsSendTimeHeaderExtension_w( | 1467 void BaseChannel::MaybeCacheRtpAbsSendTimeHeaderExtension_w( |
1467 const std::vector<webrtc::RtpExtension>& extensions) { | 1468 const std::vector<webrtc::RtpExtension>& extensions) { |
1468 // Absolute Send Time extension id is used only with external auth, | 1469 // Absolute Send Time extension id is used only with external auth, |
1469 // so do not bother searching for it and making asyncronious call to set | 1470 // so do not bother searching for it and making asyncronious call to set |
1470 // something that is not used. | 1471 // something that is not used. |
1471 #if defined(ENABLE_EXTERNAL_AUTH) | 1472 #if defined(ENABLE_EXTERNAL_AUTH) |
1472 const webrtc::RtpExtension* send_time_extension = | 1473 const webrtc::RtpExtension* send_time_extension = |
1473 FindHeaderExtension(extensions, webrtc::RtpExtension::kAbsSendTimeUri); | 1474 webrtc::RtpExtension::FindHeaderExtensionByUri( |
1475 extensions, webrtc::RtpExtension::kAbsSendTimeUri); | |
1474 int rtp_abs_sendtime_extn_id = | 1476 int rtp_abs_sendtime_extn_id = |
1475 send_time_extension ? send_time_extension->id : -1; | 1477 send_time_extension ? send_time_extension->id : -1; |
1476 invoker_.AsyncInvoke<void>( | 1478 invoker_.AsyncInvoke<void>( |
1477 RTC_FROM_HERE, network_thread_, | 1479 RTC_FROM_HERE, network_thread_, |
1478 Bind(&BaseChannel::CacheRtpAbsSendTimeHeaderExtension_n, this, | 1480 Bind(&BaseChannel::CacheRtpAbsSendTimeHeaderExtension_n, this, |
1479 rtp_abs_sendtime_extn_id)); | 1481 rtp_abs_sendtime_extn_id)); |
1480 #endif | 1482 #endif |
1481 } | 1483 } |
1482 | 1484 |
1483 void BaseChannel::CacheRtpAbsSendTimeHeaderExtension_n( | 1485 void BaseChannel::CacheRtpAbsSendTimeHeaderExtension_n( |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1797 LOG(LS_INFO) << "Setting local voice description"; | 1799 LOG(LS_INFO) << "Setting local voice description"; |
1798 | 1800 |
1799 const AudioContentDescription* audio = | 1801 const AudioContentDescription* audio = |
1800 static_cast<const AudioContentDescription*>(content); | 1802 static_cast<const AudioContentDescription*>(content); |
1801 RTC_DCHECK(audio != NULL); | 1803 RTC_DCHECK(audio != NULL); |
1802 if (!audio) { | 1804 if (!audio) { |
1803 SafeSetError("Can't find audio content in local description.", error_desc); | 1805 SafeSetError("Can't find audio content in local description.", error_desc); |
1804 return false; | 1806 return false; |
1805 } | 1807 } |
1806 | 1808 |
1807 if (!SetRtpTransportParameters(content, action, CS_LOCAL, error_desc)) { | 1809 if (!SetRtpTransportParameters(content, action, CS_LOCAL, |
1810 audio->rtp_header_extensions(), error_desc)) { | |
1808 return false; | 1811 return false; |
1809 } | 1812 } |
1810 | 1813 |
1811 AudioRecvParameters recv_params = last_recv_params_; | 1814 AudioRecvParameters recv_params = last_recv_params_; |
1812 RtpParametersFromMediaDescription(audio, &recv_params); | 1815 RtpParametersFromMediaDescription(audio, &recv_params); |
1813 if (!media_channel()->SetRecvParameters(recv_params)) { | 1816 if (!media_channel()->SetRecvParameters(recv_params)) { |
1814 SafeSetError("Failed to set local audio description recv parameters.", | 1817 SafeSetError("Failed to set local audio description recv parameters.", |
1815 error_desc); | 1818 error_desc); |
1816 return false; | 1819 return false; |
1817 } | 1820 } |
(...skipping 24 matching lines...) Expand all Loading... | |
1842 LOG(LS_INFO) << "Setting remote voice description"; | 1845 LOG(LS_INFO) << "Setting remote voice description"; |
1843 | 1846 |
1844 const AudioContentDescription* audio = | 1847 const AudioContentDescription* audio = |
1845 static_cast<const AudioContentDescription*>(content); | 1848 static_cast<const AudioContentDescription*>(content); |
1846 RTC_DCHECK(audio != NULL); | 1849 RTC_DCHECK(audio != NULL); |
1847 if (!audio) { | 1850 if (!audio) { |
1848 SafeSetError("Can't find audio content in remote description.", error_desc); | 1851 SafeSetError("Can't find audio content in remote description.", error_desc); |
1849 return false; | 1852 return false; |
1850 } | 1853 } |
1851 | 1854 |
1852 if (!SetRtpTransportParameters(content, action, CS_REMOTE, error_desc)) { | 1855 if (!SetRtpTransportParameters(content, action, CS_REMOTE, |
1856 audio->rtp_header_extensions(), error_desc)) { | |
1853 return false; | 1857 return false; |
1854 } | 1858 } |
1855 | 1859 |
1856 AudioSendParameters send_params = last_send_params_; | 1860 AudioSendParameters send_params = last_send_params_; |
1857 RtpSendParametersFromMediaDescription(audio, &send_params); | 1861 RtpSendParametersFromMediaDescription(audio, &send_params); |
1858 if (audio->agc_minus_10db()) { | 1862 if (audio->agc_minus_10db()) { |
1859 send_params.options.adjust_agc_delta = rtc::Optional<int>(kAgcMinus10db); | 1863 send_params.options.adjust_agc_delta = rtc::Optional<int>(kAgcMinus10db); |
1860 } | 1864 } |
1861 | 1865 |
1862 bool parameters_applied = media_channel()->SetSendParameters(send_params); | 1866 bool parameters_applied = media_channel()->SetSendParameters(send_params); |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2075 LOG(LS_INFO) << "Setting local video description"; | 2079 LOG(LS_INFO) << "Setting local video description"; |
2076 | 2080 |
2077 const VideoContentDescription* video = | 2081 const VideoContentDescription* video = |
2078 static_cast<const VideoContentDescription*>(content); | 2082 static_cast<const VideoContentDescription*>(content); |
2079 RTC_DCHECK(video != NULL); | 2083 RTC_DCHECK(video != NULL); |
2080 if (!video) { | 2084 if (!video) { |
2081 SafeSetError("Can't find video content in local description.", error_desc); | 2085 SafeSetError("Can't find video content in local description.", error_desc); |
2082 return false; | 2086 return false; |
2083 } | 2087 } |
2084 | 2088 |
2085 if (!SetRtpTransportParameters(content, action, CS_LOCAL, error_desc)) { | 2089 if (!SetRtpTransportParameters(content, action, CS_LOCAL, |
2090 video->rtp_header_extensions(), error_desc)) { | |
2086 return false; | 2091 return false; |
2087 } | 2092 } |
2088 | 2093 |
2089 VideoRecvParameters recv_params = last_recv_params_; | 2094 VideoRecvParameters recv_params = last_recv_params_; |
2090 RtpParametersFromMediaDescription(video, &recv_params); | 2095 RtpParametersFromMediaDescription(video, &recv_params); |
2091 if (!media_channel()->SetRecvParameters(recv_params)) { | 2096 if (!media_channel()->SetRecvParameters(recv_params)) { |
2092 SafeSetError("Failed to set local video description recv parameters.", | 2097 SafeSetError("Failed to set local video description recv parameters.", |
2093 error_desc); | 2098 error_desc); |
2094 return false; | 2099 return false; |
2095 } | 2100 } |
(...skipping 24 matching lines...) Expand all Loading... | |
2120 LOG(LS_INFO) << "Setting remote video description"; | 2125 LOG(LS_INFO) << "Setting remote video description"; |
2121 | 2126 |
2122 const VideoContentDescription* video = | 2127 const VideoContentDescription* video = |
2123 static_cast<const VideoContentDescription*>(content); | 2128 static_cast<const VideoContentDescription*>(content); |
2124 RTC_DCHECK(video != NULL); | 2129 RTC_DCHECK(video != NULL); |
2125 if (!video) { | 2130 if (!video) { |
2126 SafeSetError("Can't find video content in remote description.", error_desc); | 2131 SafeSetError("Can't find video content in remote description.", error_desc); |
2127 return false; | 2132 return false; |
2128 } | 2133 } |
2129 | 2134 |
2130 if (!SetRtpTransportParameters(content, action, CS_REMOTE, error_desc)) { | 2135 if (!SetRtpTransportParameters(content, action, CS_REMOTE, |
2136 video->rtp_header_extensions(), error_desc)) { | |
2131 return false; | 2137 return false; |
2132 } | 2138 } |
2133 | 2139 |
2134 VideoSendParameters send_params = last_send_params_; | 2140 VideoSendParameters send_params = last_send_params_; |
2135 RtpSendParametersFromMediaDescription(video, &send_params); | 2141 RtpSendParametersFromMediaDescription(video, &send_params); |
2136 if (video->conference_mode()) { | 2142 if (video->conference_mode()) { |
2137 send_params.conference_mode = true; | 2143 send_params.conference_mode = true; |
2138 } | 2144 } |
2139 | 2145 |
2140 bool parameters_applied = media_channel()->SetSendParameters(send_params); | 2146 bool parameters_applied = media_channel()->SetSendParameters(send_params); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2275 RTC_DCHECK(data != NULL); | 2281 RTC_DCHECK(data != NULL); |
2276 if (!data) { | 2282 if (!data) { |
2277 SafeSetError("Can't find data content in local description.", error_desc); | 2283 SafeSetError("Can't find data content in local description.", error_desc); |
2278 return false; | 2284 return false; |
2279 } | 2285 } |
2280 | 2286 |
2281 if (!CheckDataChannelTypeFromContent(data, error_desc)) { | 2287 if (!CheckDataChannelTypeFromContent(data, error_desc)) { |
2282 return false; | 2288 return false; |
2283 } | 2289 } |
2284 | 2290 |
2285 if (!SetRtpTransportParameters(content, action, CS_LOCAL, error_desc)) { | 2291 if (!SetRtpTransportParameters(content, action, CS_LOCAL, |
2292 data->rtp_header_extensions(), error_desc)) { | |
2286 return false; | 2293 return false; |
2287 } | 2294 } |
2288 | 2295 |
2289 DataRecvParameters recv_params = last_recv_params_; | 2296 DataRecvParameters recv_params = last_recv_params_; |
2290 RtpParametersFromMediaDescription(data, &recv_params); | 2297 RtpParametersFromMediaDescription(data, &recv_params); |
2291 if (!media_channel()->SetRecvParameters(recv_params)) { | 2298 if (!media_channel()->SetRecvParameters(recv_params)) { |
2292 SafeSetError("Failed to set remote data description recv parameters.", | 2299 SafeSetError("Failed to set remote data description recv parameters.", |
2293 error_desc); | 2300 error_desc); |
2294 return false; | 2301 return false; |
2295 } | 2302 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2330 // must be empty, so ignore it. | 2337 // must be empty, so ignore it. |
2331 if (!data->has_codecs() && action != CA_UPDATE) { | 2338 if (!data->has_codecs() && action != CA_UPDATE) { |
2332 return true; | 2339 return true; |
2333 } | 2340 } |
2334 | 2341 |
2335 if (!CheckDataChannelTypeFromContent(data, error_desc)) { | 2342 if (!CheckDataChannelTypeFromContent(data, error_desc)) { |
2336 return false; | 2343 return false; |
2337 } | 2344 } |
2338 | 2345 |
2339 LOG(LS_INFO) << "Setting remote data description"; | 2346 LOG(LS_INFO) << "Setting remote data description"; |
2340 if (!SetRtpTransportParameters(content, action, CS_REMOTE, error_desc)) { | 2347 if (!SetRtpTransportParameters(content, action, CS_REMOTE, |
2348 data->rtp_header_extensions(), error_desc)) { | |
2341 return false; | 2349 return false; |
2342 } | 2350 } |
2343 | 2351 |
2344 DataSendParameters send_params = last_send_params_; | 2352 DataSendParameters send_params = last_send_params_; |
2345 RtpSendParametersFromMediaDescription<DataCodec>(data, &send_params); | 2353 RtpSendParametersFromMediaDescription<DataCodec>(data, &send_params); |
2346 if (!media_channel()->SetSendParameters(send_params)) { | 2354 if (!media_channel()->SetSendParameters(send_params)) { |
2347 SafeSetError("Failed to set remote data description send parameters.", | 2355 SafeSetError("Failed to set remote data description send parameters.", |
2348 error_desc); | 2356 error_desc); |
2349 return false; | 2357 return false; |
2350 } | 2358 } |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2465 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_READYTOSENDDATA, | 2473 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_READYTOSENDDATA, |
2466 new DataChannelReadyToSendMessageData(writable)); | 2474 new DataChannelReadyToSendMessageData(writable)); |
2467 } | 2475 } |
2468 | 2476 |
2469 void RtpDataChannel::GetSrtpCryptoSuites_n( | 2477 void RtpDataChannel::GetSrtpCryptoSuites_n( |
2470 std::vector<int>* crypto_suites) const { | 2478 std::vector<int>* crypto_suites) const { |
2471 GetSupportedDataCryptoSuites(crypto_options(), crypto_suites); | 2479 GetSupportedDataCryptoSuites(crypto_options(), crypto_suites); |
2472 } | 2480 } |
2473 | 2481 |
2474 } // namespace cricket | 2482 } // namespace cricket |
OLD | NEW |