Chromium Code Reviews| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 func(&crypto_suites); | 43 func(&crypto_suites); |
| 44 for (const auto crypto : crypto_suites) { | 44 for (const auto crypto : crypto_suites) { |
| 45 names->push_back(rtc::SrtpCryptoSuiteToName(crypto)); | 45 names->push_back(rtc::SrtpCryptoSuiteToName(crypto)); |
| 46 } | 46 } |
| 47 #endif | 47 #endif |
| 48 } | 48 } |
| 49 } // namespace | 49 } // namespace |
| 50 | 50 |
| 51 namespace cricket { | 51 namespace cricket { |
| 52 | 52 |
| 53 | |
| 54 // RTP Profile names | 53 // RTP Profile names |
| 55 // http://www.iana.org/assignments/rtp-parameters/rtp-parameters.xml | 54 // http://www.iana.org/assignments/rtp-parameters/rtp-parameters.xml |
| 56 // RFC4585 | 55 // RFC4585 |
| 57 const char kMediaProtocolAvpf[] = "RTP/AVPF"; | 56 const char kMediaProtocolAvpf[] = "RTP/AVPF"; |
| 58 // RFC5124 | 57 // RFC5124 |
| 59 const char kMediaProtocolDtlsSavpf[] = "UDP/TLS/RTP/SAVPF"; | 58 const char kMediaProtocolDtlsSavpf[] = "UDP/TLS/RTP/SAVPF"; |
| 60 | 59 |
| 61 // We always generate offers with "UDP/TLS/RTP/SAVPF" when using DTLS-SRTP, | 60 // We always generate offers with "UDP/TLS/RTP/SAVPF" when using DTLS-SRTP, |
| 62 // but we tolerate "RTP/SAVPF" in offers we receive, for compatibility. | 61 // but we tolerate "RTP/SAVPF" in offers we receive, for compatibility. |
| 63 const char kMediaProtocolSavpf[] = "RTP/SAVPF"; | 62 const char kMediaProtocolSavpf[] = "RTP/SAVPF"; |
| 64 | 63 |
| 65 const char kMediaProtocolRtpPrefix[] = "RTP/"; | 64 const char kMediaProtocolRtpPrefix[] = "RTP/"; |
| 66 | 65 |
| 67 const char kMediaProtocolSctp[] = "SCTP"; | 66 const char kMediaProtocolSctp[] = "SCTP"; |
| 68 const char kMediaProtocolDtlsSctp[] = "DTLS/SCTP"; | 67 const char kMediaProtocolDtlsSctp[] = "DTLS/SCTP"; |
| 69 const char kMediaProtocolUdpDtlsSctp[] = "UDP/DTLS/SCTP"; | 68 const char kMediaProtocolUdpDtlsSctp[] = "UDP/DTLS/SCTP"; |
| 70 const char kMediaProtocolTcpDtlsSctp[] = "TCP/DTLS/SCTP"; | 69 const char kMediaProtocolTcpDtlsSctp[] = "TCP/DTLS/SCTP"; |
| 71 | 70 |
| 71 RtpTransceiverDirection RtpTransceiverDirection::FromMediaContentDirection( | |
| 72 MediaContentDirection md) { | |
| 73 const bool send = (md == MD_SENDRECV || md == MD_SENDONLY); | |
| 74 const bool recv = (md == MD_SENDRECV || md == MD_RECVONLY); | |
| 75 return RtpTransceiverDirection(send, recv); | |
| 76 } | |
| 77 | |
| 78 MediaContentDirection RtpTransceiverDirection::ToMediaContentDirection() const { | |
| 79 if (send && recv) { | |
| 80 return MD_SENDRECV; | |
| 81 } else if (send) { | |
| 82 return MD_SENDONLY; | |
| 83 } else if (recv) { | |
| 84 return MD_RECVONLY; | |
| 85 } | |
| 86 | |
| 87 return MD_INACTIVE; | |
| 88 } | |
| 89 | |
| 90 RtpTransceiverDirection | |
| 91 NegotiateRtpTransceiverDirection(RtpTransceiverDirection offer, | |
| 92 RtpTransceiverDirection wants) { | |
| 93 return RtpTransceiverDirection(offer.recv && wants.send, | |
| 94 offer.send && wants.recv); | |
| 95 } | |
| 96 | |
| 72 static bool IsMediaContentOfType(const ContentInfo* content, | 97 static bool IsMediaContentOfType(const ContentInfo* content, |
| 73 MediaType media_type) { | 98 MediaType media_type) { |
| 74 if (!IsMediaContent(content)) { | 99 if (!IsMediaContent(content)) { |
| 75 return false; | 100 return false; |
| 76 } | 101 } |
| 77 | 102 |
| 78 const MediaContentDescription* mdesc = | 103 const MediaContentDescription* mdesc = |
| 79 static_cast<const MediaContentDescription*>(content->description); | 104 static_cast<const MediaContentDescription*>(content->description); |
| 80 return mdesc && mdesc->type() == media_type; | 105 return mdesc && mdesc->type() == media_type; |
| 81 } | 106 } |
| (...skipping 941 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1023 return false; | 1048 return false; |
| 1024 } | 1049 } |
| 1025 | 1050 |
| 1026 if (!AddStreamParams(answer->type(), options, current_streams, answer, | 1051 if (!AddStreamParams(answer->type(), options, current_streams, answer, |
| 1027 add_legacy_stream)) { | 1052 add_legacy_stream)) { |
| 1028 return false; // Something went seriously wrong. | 1053 return false; // Something went seriously wrong. |
| 1029 } | 1054 } |
| 1030 | 1055 |
| 1031 // Make sure the answer media content direction is per default set as | 1056 // Make sure the answer media content direction is per default set as |
| 1032 // described in RFC3264 section 6.1. | 1057 // described in RFC3264 section 6.1. |
| 1033 switch (offer->direction()) { | 1058 const bool is_data = !IsRtpProtocol(answer->protocol()); |
| 1034 case MD_INACTIVE: | 1059 const bool has_send_streams = !answer->streams().empty(); |
| 1035 answer->set_direction(MD_INACTIVE); | 1060 const bool wants_send = has_send_streams || is_data; |
| 1036 break; | 1061 const bool recv_audio = |
| 1037 case MD_SENDONLY: | 1062 answer->type() == cricket::MEDIA_TYPE_AUDIO && options.recv_audio; |
| 1038 answer->set_direction(MD_RECVONLY); | 1063 const bool recv_video = |
| 1039 break; | 1064 answer->type() == cricket::MEDIA_TYPE_VIDEO && options.recv_video; |
| 1040 case MD_RECVONLY: | 1065 const bool recv_data = |
| 1041 answer->set_direction(IsRtpProtocol(answer->protocol()) && | 1066 answer->type() == cricket::MEDIA_TYPE_DATA; |
| 1042 answer->streams().empty() | 1067 const bool wants_receive = recv_audio || recv_video || recv_data; |
| 1043 ? MD_INACTIVE | |
| 1044 : MD_SENDONLY); | |
| 1045 break; | |
| 1046 case MD_SENDRECV: | |
| 1047 answer->set_direction(IsRtpProtocol(answer->protocol()) && | |
| 1048 answer->streams().empty() | |
| 1049 ? MD_RECVONLY | |
| 1050 : MD_SENDRECV); | |
| 1051 break; | |
| 1052 default: | |
| 1053 RTC_DCHECK(false && "MediaContentDescription has unexpected direction."); | |
| 1054 break; | |
| 1055 } | |
| 1056 | 1068 |
| 1069 auto offer_rtd = | |
| 1070 RtpTransceiverDirection::FromMediaContentDirection(offer->direction()); | |
| 1071 auto wants_rtd = RtpTransceiverDirection(wants_send, wants_receive); | |
| 1072 answer->set_direction(NegotiateRtpTransceiverDirection(offer_rtd, wants_rtd) | |
| 1073 .ToMediaContentDirection()); | |
| 1057 return true; | 1074 return true; |
| 1058 } | 1075 } |
| 1059 | 1076 |
| 1060 static bool IsDtlsRtp(const std::string& protocol) { | 1077 static bool IsDtlsRtp(const std::string& protocol) { |
| 1061 // Most-likely values first. | 1078 // Most-likely values first. |
| 1062 return protocol == "UDP/TLS/RTP/SAVPF" || protocol == "TCP/TLS/RTP/SAVPF" || | 1079 return protocol == "UDP/TLS/RTP/SAVPF" || protocol == "TCP/TLS/RTP/SAVPF" || |
| 1063 protocol == "UDP/TLS/RTP/SAVP" || protocol == "TCP/TLS/RTP/SAVP"; | 1080 protocol == "UDP/TLS/RTP/SAVP" || protocol == "TCP/TLS/RTP/SAVP"; |
| 1064 } | 1081 } |
| 1065 | 1082 |
| 1066 static bool IsPlainRtp(const std::string& protocol) { | 1083 static bool IsPlainRtp(const std::string& protocol) { |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1166 case MEDIA_TYPE_DATA: | 1183 case MEDIA_TYPE_DATA: |
| 1167 type_str = "data"; | 1184 type_str = "data"; |
| 1168 break; | 1185 break; |
| 1169 default: | 1186 default: |
| 1170 ASSERT(false); | 1187 ASSERT(false); |
| 1171 break; | 1188 break; |
| 1172 } | 1189 } |
| 1173 return type_str; | 1190 return type_str; |
| 1174 } | 1191 } |
| 1175 | 1192 |
| 1193 std::string MediaContentDirectionToString(MediaContentDirection direction) { | |
| 1194 std::string dir_str; | |
| 1195 switch (direction) { | |
| 1196 case MD_INACTIVE: | |
| 1197 dir_str = "inactive"; | |
| 1198 break; | |
| 1199 case MD_SENDONLY: | |
| 1200 dir_str = "sendonly"; | |
| 1201 break; | |
| 1202 case MD_RECVONLY: | |
| 1203 dir_str = "recvonly"; | |
| 1204 break; | |
| 1205 case MD_SENDRECV: | |
| 1206 dir_str = "sendrecv"; | |
| 1207 break; | |
| 1208 default: | |
| 1209 ASSERT(false); | |
| 1210 break; | |
| 1211 } | |
| 1212 | |
| 1213 return dir_str; | |
| 1214 } | |
| 1215 | |
| 1176 void MediaSessionOptions::AddSendStream(MediaType type, | 1216 void MediaSessionOptions::AddSendStream(MediaType type, |
| 1177 const std::string& id, | 1217 const std::string& id, |
| 1178 const std::string& sync_label) { | 1218 const std::string& sync_label) { |
| 1179 AddSendStreamInternal(type, id, sync_label, 1); | 1219 AddSendStreamInternal(type, id, sync_label, 1); |
| 1180 } | 1220 } |
| 1181 | 1221 |
| 1182 void MediaSessionOptions::AddSendVideoStream( | 1222 void MediaSessionOptions::AddSendVideoStream( |
| 1183 const std::string& id, | 1223 const std::string& id, |
| 1184 const std::string& sync_label, | 1224 const std::string& sync_label, |
| 1185 int num_sim_layers) { | 1225 int num_sim_layers) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1227 add_legacy_(true), | 1267 add_legacy_(true), |
| 1228 transport_desc_factory_(transport_desc_factory) { | 1268 transport_desc_factory_(transport_desc_factory) { |
| 1229 } | 1269 } |
| 1230 | 1270 |
| 1231 MediaSessionDescriptionFactory::MediaSessionDescriptionFactory( | 1271 MediaSessionDescriptionFactory::MediaSessionDescriptionFactory( |
| 1232 ChannelManager* channel_manager, | 1272 ChannelManager* channel_manager, |
| 1233 const TransportDescriptionFactory* transport_desc_factory) | 1273 const TransportDescriptionFactory* transport_desc_factory) |
| 1234 : secure_(SEC_DISABLED), | 1274 : secure_(SEC_DISABLED), |
| 1235 add_legacy_(true), | 1275 add_legacy_(true), |
| 1236 transport_desc_factory_(transport_desc_factory) { | 1276 transport_desc_factory_(transport_desc_factory) { |
| 1237 channel_manager->GetSupportedAudioCodecs(&audio_codecs_); | 1277 channel_manager->GetSupportedAudioCodecs(&audio_sendrecv_codecs_); |
| 1238 channel_manager->GetSupportedAudioRtpHeaderExtensions(&audio_rtp_extensions_); | 1278 channel_manager->GetSupportedAudioRtpHeaderExtensions(&audio_rtp_extensions_); |
| 1239 channel_manager->GetSupportedVideoCodecs(&video_codecs_); | 1279 channel_manager->GetSupportedVideoCodecs(&video_codecs_); |
| 1240 channel_manager->GetSupportedVideoRtpHeaderExtensions(&video_rtp_extensions_); | 1280 channel_manager->GetSupportedVideoRtpHeaderExtensions(&video_rtp_extensions_); |
| 1241 channel_manager->GetSupportedDataCodecs(&data_codecs_); | 1281 channel_manager->GetSupportedDataCodecs(&data_codecs_); |
| 1282 audio_send_codecs_ = audio_sendrecv_codecs_; | |
| 1283 audio_recv_codecs_ = audio_sendrecv_codecs_; | |
| 1284 } | |
| 1285 | |
| 1286 const AudioCodecs& MediaSessionDescriptionFactory::audio_codecs() const { | |
| 1287 return audio_sendrecv_codecs_; | |
| 1288 } | |
| 1289 | |
| 1290 const AudioCodecs& MediaSessionDescriptionFactory::audio_send_codecs() const { | |
| 1291 return audio_send_codecs_; | |
| 1292 } | |
| 1293 | |
| 1294 const AudioCodecs& MediaSessionDescriptionFactory::audio_recv_codecs() const { | |
| 1295 return audio_recv_codecs_; | |
| 1296 } | |
| 1297 | |
| 1298 void MediaSessionDescriptionFactory::set_audio_codecs( | |
| 1299 const AudioCodecs& send_codecs, const AudioCodecs& recv_codecs) { | |
| 1300 audio_send_codecs_ = send_codecs; | |
| 1301 audio_recv_codecs_ = recv_codecs; | |
| 1302 audio_sendrecv_codecs_.clear(); | |
| 1303 | |
| 1304 // Intersect the two lists of codecs, preserving the order of the send codecs. | |
| 1305 // If there's any difference in priorities, chances are encoding is more | |
| 1306 // expensive than decoding, and high-priority send codecs are likely handled | |
| 1307 // better (e.g. through hardware encoder support) than low-priority ones. | |
| 1308 // TODO(ossu): This is O(n^2). However, each list should generally be small | |
| 1309 // enough for this to not be a problem. They are also nicely local in memory | |
| 1310 // like this. | |
| 1311 for (const auto& sc : audio_send_codecs_) { | |
| 1312 for (const auto& rc : audio_recv_codecs_) { | |
| 1313 const size_t send_channels = (sc.channels == 0) ? 1 : sc.channels; | |
| 1314 const size_t recv_channels = (rc.channels == 0) ? 1 : rc.channels; | |
| 1315 if (sc.clockrate == rc.clockrate && | |
| 1316 sc.bitrate == rc.bitrate && | |
| 1317 send_channels == recv_channels && | |
| 1318 (_stricmp(sc.name.c_str(), rc.name.c_str()) == 0) && | |
| 1319 sc.params == rc.params && | |
| 1320 sc.feedback_params == rc.feedback_params) { | |
|
Taylor Brandstetter
2016/06/03 17:13:20
Can this comparison be replaced by a comparison me
ossu
2016/06/10 09:10:04
There are currently two ways to compare AudioCodec
Taylor Brandstetter
2016/06/10 17:39:13
Understood. My only worry is that an additional at
ossu
2016/06/13 12:47:19
Ah, yes. Well, I guess it's a moot point now that
| |
| 1321 AudioCodec out_codec = sc; | |
| 1322 out_codec.channels = send_channels; | |
| 1323 audio_sendrecv_codecs_.push_back(out_codec); | |
| 1324 break; | |
| 1325 } | |
| 1326 } | |
| 1327 } | |
| 1242 } | 1328 } |
| 1243 | 1329 |
| 1244 SessionDescription* MediaSessionDescriptionFactory::CreateOffer( | 1330 SessionDescription* MediaSessionDescriptionFactory::CreateOffer( |
| 1245 const MediaSessionOptions& options, | 1331 const MediaSessionOptions& options, |
| 1246 const SessionDescription* current_description) const { | 1332 const SessionDescription* current_description) const { |
| 1247 std::unique_ptr<SessionDescription> offer(new SessionDescription()); | 1333 std::unique_ptr<SessionDescription> offer(new SessionDescription()); |
| 1248 | 1334 |
| 1249 StreamParamsVec current_streams; | 1335 StreamParamsVec current_streams; |
| 1250 GetCurrentStreamParams(current_description, ¤t_streams); | 1336 GetCurrentStreamParams(current_description, ¤t_streams); |
| 1251 | 1337 |
| 1338 const bool wants_send = | |
| 1339 options.HasSendMediaStream(MEDIA_TYPE_AUDIO) || add_legacy_; | |
| 1340 const AudioCodecs& supported_audio_codecs = | |
| 1341 GetAudioCodecsForDirection({wants_send, options.recv_audio}); | |
| 1342 | |
| 1252 AudioCodecs audio_codecs; | 1343 AudioCodecs audio_codecs; |
| 1253 VideoCodecs video_codecs; | 1344 VideoCodecs video_codecs; |
| 1254 DataCodecs data_codecs; | 1345 DataCodecs data_codecs; |
| 1255 GetCodecsToOffer(current_description, &audio_codecs, &video_codecs, | 1346 GetCodecsToOffer(current_description, supported_audio_codecs, |
| 1256 &data_codecs); | 1347 video_codecs_, data_codecs_, |
| 1348 &audio_codecs, &video_codecs, &data_codecs); | |
| 1257 | 1349 |
| 1258 if (!options.vad_enabled) { | 1350 if (!options.vad_enabled) { |
| 1259 // If application doesn't want CN codecs in offer. | 1351 // If application doesn't want CN codecs in offer. |
| 1260 StripCNCodecs(&audio_codecs); | 1352 StripCNCodecs(&audio_codecs); |
| 1261 } | 1353 } |
| 1262 | 1354 |
| 1263 RtpHeaderExtensions audio_rtp_extensions; | 1355 RtpHeaderExtensions audio_rtp_extensions; |
| 1264 RtpHeaderExtensions video_rtp_extensions; | 1356 RtpHeaderExtensions video_rtp_extensions; |
| 1265 GetRtpHdrExtsToOffer(current_description, &audio_rtp_extensions, | 1357 GetRtpHdrExtsToOffer(current_description, &audio_rtp_extensions, |
| 1266 &video_rtp_extensions); | 1358 &video_rtp_extensions); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1405 if (!UpdateCryptoParamsForBundle(answer_bundle, answer.get())) { | 1497 if (!UpdateCryptoParamsForBundle(answer_bundle, answer.get())) { |
| 1406 LOG(LS_ERROR) << "CreateAnswer failed to UpdateCryptoParamsForBundle."; | 1498 LOG(LS_ERROR) << "CreateAnswer failed to UpdateCryptoParamsForBundle."; |
| 1407 return NULL; | 1499 return NULL; |
| 1408 } | 1500 } |
| 1409 } | 1501 } |
| 1410 } | 1502 } |
| 1411 | 1503 |
| 1412 return answer.release(); | 1504 return answer.release(); |
| 1413 } | 1505 } |
| 1414 | 1506 |
| 1507 const AudioCodecs& MediaSessionDescriptionFactory::GetAudioCodecsForDirection( | |
| 1508 const RtpTransceiverDirection& direction) const { | |
| 1509 // If stream is inactive - generate list as if sendrecv. | |
| 1510 // See RFC 3264 Section 6.1. | |
| 1511 if (direction.send == direction.recv) { | |
| 1512 return audio_sendrecv_codecs_; | |
|
Taylor Brandstetter
2016/06/03 17:13:20
The rule in rfc 3264 for "inactive" is a bit more
ossu
2016/06/10 09:10:04
Ah, that's correct! I missed that when reading the
| |
| 1513 } else if (direction.send) { | |
| 1514 return audio_send_codecs_; | |
| 1515 } else { | |
| 1516 return audio_recv_codecs_; | |
| 1517 } | |
| 1518 } | |
| 1519 | |
| 1415 void MediaSessionDescriptionFactory::GetCodecsToOffer( | 1520 void MediaSessionDescriptionFactory::GetCodecsToOffer( |
| 1416 const SessionDescription* current_description, | 1521 const SessionDescription* current_description, |
| 1522 const AudioCodecs& supported_audio_codecs, | |
| 1523 const VideoCodecs& supported_video_codecs, | |
| 1524 const DataCodecs& supported_data_codecs, | |
| 1417 AudioCodecs* audio_codecs, | 1525 AudioCodecs* audio_codecs, |
| 1418 VideoCodecs* video_codecs, | 1526 VideoCodecs* video_codecs, |
| 1419 DataCodecs* data_codecs) const { | 1527 DataCodecs* data_codecs) const { |
| 1420 UsedPayloadTypes used_pltypes; | 1528 UsedPayloadTypes used_pltypes; |
| 1421 audio_codecs->clear(); | 1529 audio_codecs->clear(); |
| 1422 video_codecs->clear(); | 1530 video_codecs->clear(); |
| 1423 data_codecs->clear(); | 1531 data_codecs->clear(); |
| 1424 | 1532 |
| 1425 | 1533 |
| 1426 // First - get all codecs from the current description if the media type | 1534 // First - get all codecs from the current description if the media type |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1442 } | 1550 } |
| 1443 const DataContentDescription* data = | 1551 const DataContentDescription* data = |
| 1444 GetFirstDataContentDescription(current_description); | 1552 GetFirstDataContentDescription(current_description); |
| 1445 if (data) { | 1553 if (data) { |
| 1446 *data_codecs = data->codecs(); | 1554 *data_codecs = data->codecs(); |
| 1447 used_pltypes.FindAndSetIdUsed<DataCodec>(data_codecs); | 1555 used_pltypes.FindAndSetIdUsed<DataCodec>(data_codecs); |
| 1448 } | 1556 } |
| 1449 } | 1557 } |
| 1450 | 1558 |
| 1451 // Add our codecs that are not in |current_description|. | 1559 // Add our codecs that are not in |current_description|. |
| 1452 FindCodecsToOffer<AudioCodec>(audio_codecs_, audio_codecs, &used_pltypes); | 1560 FindCodecsToOffer<AudioCodec>(supported_audio_codecs, audio_codecs, |
| 1453 FindCodecsToOffer<VideoCodec>(video_codecs_, video_codecs, &used_pltypes); | 1561 &used_pltypes); |
| 1454 FindCodecsToOffer<DataCodec>(data_codecs_, data_codecs, &used_pltypes); | 1562 FindCodecsToOffer<VideoCodec>(supported_video_codecs, video_codecs, |
| 1563 &used_pltypes); | |
| 1564 FindCodecsToOffer<DataCodec>(supported_data_codecs, data_codecs, | |
| 1565 &used_pltypes); | |
| 1455 } | 1566 } |
| 1456 | 1567 |
| 1457 void MediaSessionDescriptionFactory::GetRtpHdrExtsToOffer( | 1568 void MediaSessionDescriptionFactory::GetRtpHdrExtsToOffer( |
| 1458 const SessionDescription* current_description, | 1569 const SessionDescription* current_description, |
| 1459 RtpHeaderExtensions* audio_extensions, | 1570 RtpHeaderExtensions* audio_extensions, |
| 1460 RtpHeaderExtensions* video_extensions) const { | 1571 RtpHeaderExtensions* video_extensions) const { |
| 1461 // All header extensions allocated from the same range to avoid potential | 1572 // All header extensions allocated from the same range to avoid potential |
| 1462 // issues when using BUNDLE. | 1573 // issues when using BUNDLE. |
| 1463 UsedRtpHeaderExtensionIds used_ids; | 1574 UsedRtpHeaderExtensionIds used_ids; |
| 1464 RtpHeaderExtensions all_extensions; | 1575 RtpHeaderExtensions all_extensions; |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1570 add_legacy_, | 1681 add_legacy_, |
| 1571 current_streams, | 1682 current_streams, |
| 1572 audio.get())) { | 1683 audio.get())) { |
| 1573 return false; | 1684 return false; |
| 1574 } | 1685 } |
| 1575 audio->set_lang(lang_); | 1686 audio->set_lang(lang_); |
| 1576 | 1687 |
| 1577 bool secure_transport = (transport_desc_factory_->secure() != SEC_DISABLED); | 1688 bool secure_transport = (transport_desc_factory_->secure() != SEC_DISABLED); |
| 1578 SetMediaProtocol(secure_transport, audio.get()); | 1689 SetMediaProtocol(secure_transport, audio.get()); |
| 1579 | 1690 |
| 1580 if (!audio->streams().empty()) { | 1691 auto offer_rtd = |
| 1581 if (options.recv_audio) { | 1692 RtpTransceiverDirection(!audio->streams().empty(), options.recv_audio); |
| 1582 audio->set_direction(MD_SENDRECV); | 1693 audio->set_direction(offer_rtd.ToMediaContentDirection()); |
| 1583 } else { | |
| 1584 audio->set_direction(MD_SENDONLY); | |
| 1585 } | |
| 1586 } else { | |
| 1587 if (options.recv_audio) { | |
| 1588 audio->set_direction(MD_RECVONLY); | |
| 1589 } else { | |
| 1590 audio->set_direction(MD_INACTIVE); | |
| 1591 } | |
| 1592 } | |
| 1593 | 1694 |
| 1594 desc->AddContent(content_name, NS_JINGLE_RTP, audio.release()); | 1695 desc->AddContent(content_name, NS_JINGLE_RTP, audio.release()); |
| 1595 if (!AddTransportOffer(content_name, | 1696 if (!AddTransportOffer(content_name, |
| 1596 GetTransportOptions(options, content_name), | 1697 GetTransportOptions(options, content_name), |
| 1597 current_description, desc)) { | 1698 current_description, desc)) { |
| 1598 return false; | 1699 return false; |
| 1599 } | 1700 } |
| 1600 | 1701 |
| 1601 return true; | 1702 return true; |
| 1602 } | 1703 } |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1726 return true; | 1827 return true; |
| 1727 } | 1828 } |
| 1728 | 1829 |
| 1729 bool MediaSessionDescriptionFactory::AddAudioContentForAnswer( | 1830 bool MediaSessionDescriptionFactory::AddAudioContentForAnswer( |
| 1730 const SessionDescription* offer, | 1831 const SessionDescription* offer, |
| 1731 const MediaSessionOptions& options, | 1832 const MediaSessionOptions& options, |
| 1732 const SessionDescription* current_description, | 1833 const SessionDescription* current_description, |
| 1733 StreamParamsVec* current_streams, | 1834 StreamParamsVec* current_streams, |
| 1734 SessionDescription* answer) const { | 1835 SessionDescription* answer) const { |
| 1735 const ContentInfo* audio_content = GetFirstAudioContent(offer); | 1836 const ContentInfo* audio_content = GetFirstAudioContent(offer); |
| 1837 const AudioContentDescription* offer_audio = | |
| 1838 static_cast<const AudioContentDescription*>(audio_content->description); | |
| 1736 | 1839 |
| 1737 std::unique_ptr<TransportDescription> audio_transport(CreateTransportAnswer( | 1840 std::unique_ptr<TransportDescription> audio_transport(CreateTransportAnswer( |
| 1738 audio_content->name, offer, | 1841 audio_content->name, offer, |
| 1739 GetTransportOptions(options, audio_content->name), current_description)); | 1842 GetTransportOptions(options, audio_content->name), current_description)); |
| 1740 if (!audio_transport) { | 1843 if (!audio_transport) { |
| 1741 return false; | 1844 return false; |
| 1742 } | 1845 } |
| 1743 | 1846 |
| 1744 AudioCodecs audio_codecs = audio_codecs_; | 1847 // Pick codecs based on the requested communications direction in the offer. |
| 1848 const bool wants_send = | |
| 1849 options.HasSendMediaStream(MEDIA_TYPE_AUDIO) || add_legacy_; | |
| 1850 auto wants_rtd = RtpTransceiverDirection(wants_send, options.recv_audio); | |
| 1851 auto offer_rtd = | |
| 1852 RtpTransceiverDirection::FromMediaContentDirection( | |
| 1853 offer_audio->direction()); | |
| 1854 auto answer_rtd = NegotiateRtpTransceiverDirection(offer_rtd, wants_rtd); | |
| 1855 AudioCodecs audio_codecs = GetAudioCodecsForDirection(answer_rtd); | |
| 1745 if (!options.vad_enabled) { | 1856 if (!options.vad_enabled) { |
| 1746 StripCNCodecs(&audio_codecs); | 1857 StripCNCodecs(&audio_codecs); |
| 1747 } | 1858 } |
| 1748 | 1859 |
| 1749 bool bundle_enabled = | 1860 bool bundle_enabled = |
| 1750 offer->HasGroup(GROUP_TYPE_BUNDLE) && options.bundle_enabled; | 1861 offer->HasGroup(GROUP_TYPE_BUNDLE) && options.bundle_enabled; |
| 1751 std::unique_ptr<AudioContentDescription> audio_answer( | 1862 std::unique_ptr<AudioContentDescription> audio_answer( |
| 1752 new AudioContentDescription()); | 1863 new AudioContentDescription()); |
| 1753 // Do not require or create SDES cryptos if DTLS is used. | 1864 // Do not require or create SDES cryptos if DTLS is used. |
| 1754 cricket::SecurePolicy sdes_policy = | 1865 cricket::SecurePolicy sdes_policy = |
| 1755 audio_transport->secure() ? cricket::SEC_DISABLED : secure(); | 1866 audio_transport->secure() ? cricket::SEC_DISABLED : secure(); |
| 1756 if (!CreateMediaContentAnswer( | 1867 if (!CreateMediaContentAnswer( |
| 1757 static_cast<const AudioContentDescription*>( | 1868 offer_audio, |
| 1758 audio_content->description), | |
| 1759 options, | 1869 options, |
| 1760 audio_codecs, | 1870 audio_codecs, |
| 1761 sdes_policy, | 1871 sdes_policy, |
| 1762 GetCryptos(GetFirstAudioContentDescription(current_description)), | 1872 GetCryptos(GetFirstAudioContentDescription(current_description)), |
| 1763 audio_rtp_extensions_, | 1873 audio_rtp_extensions_, |
| 1764 current_streams, | 1874 current_streams, |
| 1765 add_legacy_, | 1875 add_legacy_, |
| 1766 bundle_enabled, | 1876 bundle_enabled, |
| 1767 audio_answer.get())) { | 1877 audio_answer.get())) { |
| 1768 return false; // Fails the session setup. | 1878 return false; // Fails the session setup. |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1980 GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_VIDEO)); | 2090 GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_VIDEO)); |
| 1981 } | 2091 } |
| 1982 | 2092 |
| 1983 const DataContentDescription* GetFirstDataContentDescription( | 2093 const DataContentDescription* GetFirstDataContentDescription( |
| 1984 const SessionDescription* sdesc) { | 2094 const SessionDescription* sdesc) { |
| 1985 return static_cast<const DataContentDescription*>( | 2095 return static_cast<const DataContentDescription*>( |
| 1986 GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_DATA)); | 2096 GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_DATA)); |
| 1987 } | 2097 } |
| 1988 | 2098 |
| 1989 } // namespace cricket | 2099 } // namespace cricket |
| OLD | NEW |