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 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 760 negotiated.IntersectFeedbackParams(theirs); | 785 negotiated.IntersectFeedbackParams(theirs); |
| 761 if (IsRtxCodec(negotiated)) { | 786 if (IsRtxCodec(negotiated)) { |
| 762 std::string offered_apt_value; | 787 std::string offered_apt_value; |
| 763 theirs.GetParam(kCodecParamAssociatedPayloadType, &offered_apt_value); | 788 theirs.GetParam(kCodecParamAssociatedPayloadType, &offered_apt_value); |
| 764 // FindMatchingCodec shouldn't return something with no apt value. | 789 // FindMatchingCodec shouldn't return something with no apt value. |
| 765 RTC_DCHECK(!offered_apt_value.empty()); | 790 RTC_DCHECK(!offered_apt_value.empty()); |
| 766 negotiated.SetParam(kCodecParamAssociatedPayloadType, | 791 negotiated.SetParam(kCodecParamAssociatedPayloadType, |
| 767 offered_apt_value); | 792 offered_apt_value); |
| 768 } | 793 } |
| 769 negotiated.id = theirs.id; | 794 negotiated.id = theirs.id; |
| 795 negotiated.name = theirs.name; | |
|
ossu
2016/06/10 13:15:19
Essentially I added this because it broke my SetAu
| |
| 770 negotiated_codecs->push_back(negotiated); | 796 negotiated_codecs->push_back(negotiated); |
| 771 } | 797 } |
| 772 } | 798 } |
| 773 // RFC3264: Although the answerer MAY list the formats in their desired | 799 // RFC3264: Although the answerer MAY list the formats in their desired |
| 774 // order of preference, it is RECOMMENDED that unless there is a | 800 // order of preference, it is RECOMMENDED that unless there is a |
| 775 // specific reason, the answerer list formats in the same relative order | 801 // specific reason, the answerer list formats in the same relative order |
| 776 // they were present in the offer. | 802 // they were present in the offer. |
| 777 std::unordered_map<int, int> payload_type_preferences; | 803 std::unordered_map<int, int> payload_type_preferences; |
| 778 int preference = static_cast<int>(offered_codecs.size() + 1); | 804 int preference = static_cast<int>(offered_codecs.size() + 1); |
| 779 for (const C& codec : offered_codecs) { | 805 for (const C& codec : offered_codecs) { |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1023 return false; | 1049 return false; |
| 1024 } | 1050 } |
| 1025 | 1051 |
| 1026 if (!AddStreamParams(answer->type(), options, current_streams, answer, | 1052 if (!AddStreamParams(answer->type(), options, current_streams, answer, |
| 1027 add_legacy_stream)) { | 1053 add_legacy_stream)) { |
| 1028 return false; // Something went seriously wrong. | 1054 return false; // Something went seriously wrong. |
| 1029 } | 1055 } |
| 1030 | 1056 |
| 1031 // Make sure the answer media content direction is per default set as | 1057 // Make sure the answer media content direction is per default set as |
| 1032 // described in RFC3264 section 6.1. | 1058 // described in RFC3264 section 6.1. |
| 1033 switch (offer->direction()) { | 1059 const bool is_data = !IsRtpProtocol(answer->protocol()); |
| 1034 case MD_INACTIVE: | 1060 const bool has_send_streams = !answer->streams().empty(); |
| 1035 answer->set_direction(MD_INACTIVE); | 1061 const bool wants_send = has_send_streams || is_data; |
| 1036 break; | 1062 const bool recv_audio = |
| 1037 case MD_SENDONLY: | 1063 answer->type() == cricket::MEDIA_TYPE_AUDIO && options.recv_audio; |
| 1038 answer->set_direction(MD_RECVONLY); | 1064 const bool recv_video = |
| 1039 break; | 1065 answer->type() == cricket::MEDIA_TYPE_VIDEO && options.recv_video; |
| 1040 case MD_RECVONLY: | 1066 const bool recv_data = |
| 1041 answer->set_direction(IsRtpProtocol(answer->protocol()) && | 1067 answer->type() == cricket::MEDIA_TYPE_DATA; |
| 1042 answer->streams().empty() | 1068 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 | 1069 |
| 1070 auto offer_rtd = | |
| 1071 RtpTransceiverDirection::FromMediaContentDirection(offer->direction()); | |
| 1072 auto wants_rtd = RtpTransceiverDirection(wants_send, wants_receive); | |
| 1073 answer->set_direction(NegotiateRtpTransceiverDirection(offer_rtd, wants_rtd) | |
| 1074 .ToMediaContentDirection()); | |
| 1057 return true; | 1075 return true; |
| 1058 } | 1076 } |
| 1059 | 1077 |
| 1060 static bool IsDtlsRtp(const std::string& protocol) { | 1078 static bool IsDtlsRtp(const std::string& protocol) { |
| 1061 // Most-likely values first. | 1079 // Most-likely values first. |
| 1062 return protocol == "UDP/TLS/RTP/SAVPF" || protocol == "TCP/TLS/RTP/SAVPF" || | 1080 return protocol == "UDP/TLS/RTP/SAVPF" || protocol == "TCP/TLS/RTP/SAVPF" || |
| 1063 protocol == "UDP/TLS/RTP/SAVP" || protocol == "TCP/TLS/RTP/SAVP"; | 1081 protocol == "UDP/TLS/RTP/SAVP" || protocol == "TCP/TLS/RTP/SAVP"; |
| 1064 } | 1082 } |
| 1065 | 1083 |
| 1066 static bool IsPlainRtp(const std::string& protocol) { | 1084 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: | 1184 case MEDIA_TYPE_DATA: |
| 1167 type_str = "data"; | 1185 type_str = "data"; |
| 1168 break; | 1186 break; |
| 1169 default: | 1187 default: |
| 1170 ASSERT(false); | 1188 ASSERT(false); |
| 1171 break; | 1189 break; |
| 1172 } | 1190 } |
| 1173 return type_str; | 1191 return type_str; |
| 1174 } | 1192 } |
| 1175 | 1193 |
| 1194 std::string MediaContentDirectionToString(MediaContentDirection direction) { | |
| 1195 std::string dir_str; | |
| 1196 switch (direction) { | |
| 1197 case MD_INACTIVE: | |
| 1198 dir_str = "inactive"; | |
| 1199 break; | |
| 1200 case MD_SENDONLY: | |
| 1201 dir_str = "sendonly"; | |
| 1202 break; | |
| 1203 case MD_RECVONLY: | |
| 1204 dir_str = "recvonly"; | |
| 1205 break; | |
| 1206 case MD_SENDRECV: | |
| 1207 dir_str = "sendrecv"; | |
| 1208 break; | |
| 1209 default: | |
| 1210 ASSERT(false); | |
| 1211 break; | |
| 1212 } | |
| 1213 | |
| 1214 return dir_str; | |
| 1215 } | |
| 1216 | |
| 1176 void MediaSessionOptions::AddSendStream(MediaType type, | 1217 void MediaSessionOptions::AddSendStream(MediaType type, |
| 1177 const std::string& id, | 1218 const std::string& id, |
| 1178 const std::string& sync_label) { | 1219 const std::string& sync_label) { |
| 1179 AddSendStreamInternal(type, id, sync_label, 1); | 1220 AddSendStreamInternal(type, id, sync_label, 1); |
| 1180 } | 1221 } |
| 1181 | 1222 |
| 1182 void MediaSessionOptions::AddSendVideoStream( | 1223 void MediaSessionOptions::AddSendVideoStream( |
| 1183 const std::string& id, | 1224 const std::string& id, |
| 1184 const std::string& sync_label, | 1225 const std::string& sync_label, |
| 1185 int num_sim_layers) { | 1226 int num_sim_layers) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1227 add_legacy_(true), | 1268 add_legacy_(true), |
| 1228 transport_desc_factory_(transport_desc_factory) { | 1269 transport_desc_factory_(transport_desc_factory) { |
| 1229 } | 1270 } |
| 1230 | 1271 |
| 1231 MediaSessionDescriptionFactory::MediaSessionDescriptionFactory( | 1272 MediaSessionDescriptionFactory::MediaSessionDescriptionFactory( |
| 1232 ChannelManager* channel_manager, | 1273 ChannelManager* channel_manager, |
| 1233 const TransportDescriptionFactory* transport_desc_factory) | 1274 const TransportDescriptionFactory* transport_desc_factory) |
| 1234 : secure_(SEC_DISABLED), | 1275 : secure_(SEC_DISABLED), |
| 1235 add_legacy_(true), | 1276 add_legacy_(true), |
| 1236 transport_desc_factory_(transport_desc_factory) { | 1277 transport_desc_factory_(transport_desc_factory) { |
| 1237 channel_manager->GetSupportedAudioCodecs(&audio_codecs_); | 1278 channel_manager->GetSupportedAudioCodecs(&audio_sendrecv_codecs_); |
| 1238 channel_manager->GetSupportedAudioRtpHeaderExtensions(&audio_rtp_extensions_); | 1279 channel_manager->GetSupportedAudioRtpHeaderExtensions(&audio_rtp_extensions_); |
| 1239 channel_manager->GetSupportedVideoCodecs(&video_codecs_); | 1280 channel_manager->GetSupportedVideoCodecs(&video_codecs_); |
| 1240 channel_manager->GetSupportedVideoRtpHeaderExtensions(&video_rtp_extensions_); | 1281 channel_manager->GetSupportedVideoRtpHeaderExtensions(&video_rtp_extensions_); |
| 1241 channel_manager->GetSupportedDataCodecs(&data_codecs_); | 1282 channel_manager->GetSupportedDataCodecs(&data_codecs_); |
| 1283 audio_send_codecs_ = audio_sendrecv_codecs_; | |
| 1284 audio_recv_codecs_ = audio_sendrecv_codecs_; | |
| 1285 } | |
| 1286 | |
| 1287 const AudioCodecs& MediaSessionDescriptionFactory::audio_codecs() const { | |
| 1288 return audio_sendrecv_codecs_; | |
| 1289 } | |
| 1290 | |
| 1291 const AudioCodecs& MediaSessionDescriptionFactory::audio_send_codecs() const { | |
| 1292 return audio_send_codecs_; | |
| 1293 } | |
| 1294 | |
| 1295 const AudioCodecs& MediaSessionDescriptionFactory::audio_recv_codecs() const { | |
| 1296 return audio_recv_codecs_; | |
| 1297 } | |
| 1298 | |
| 1299 void MediaSessionDescriptionFactory::set_audio_codecs( | |
| 1300 const AudioCodecs& send_codecs, const AudioCodecs& recv_codecs) { | |
| 1301 audio_send_codecs_ = send_codecs; | |
| 1302 audio_recv_codecs_ = recv_codecs; | |
| 1303 audio_sendrecv_codecs_.clear(); | |
| 1304 // Use NegotiateCodecs to merge our codec lists, since the operation is | |
| 1305 // essentially the same. Put send_codecs as the offered_codecs, which is the | |
| 1306 // order we'd like to follow. The reasoning is that encoding is usually more | |
| 1307 // expensive than decoding, and prioritizing a codec in the send list probably | |
| 1308 // means it's a codec we can handle efficiently. | |
| 1309 NegotiateCodecs(recv_codecs, send_codecs, &audio_sendrecv_codecs_); | |
|
ossu
2016/06/10 13:15:19
I repurposed NegotiateCodecs to merge these codecs
| |
| 1242 } | 1310 } |
| 1243 | 1311 |
| 1244 SessionDescription* MediaSessionDescriptionFactory::CreateOffer( | 1312 SessionDescription* MediaSessionDescriptionFactory::CreateOffer( |
| 1245 const MediaSessionOptions& options, | 1313 const MediaSessionOptions& options, |
| 1246 const SessionDescription* current_description) const { | 1314 const SessionDescription* current_description) const { |
| 1247 std::unique_ptr<SessionDescription> offer(new SessionDescription()); | 1315 std::unique_ptr<SessionDescription> offer(new SessionDescription()); |
| 1248 | 1316 |
| 1249 StreamParamsVec current_streams; | 1317 StreamParamsVec current_streams; |
| 1250 GetCurrentStreamParams(current_description, ¤t_streams); | 1318 GetCurrentStreamParams(current_description, ¤t_streams); |
| 1251 | 1319 |
| 1320 const bool wants_send = | |
| 1321 options.HasSendMediaStream(MEDIA_TYPE_AUDIO) || add_legacy_; | |
| 1322 const AudioCodecs& supported_audio_codecs = | |
| 1323 GetAudioCodecsForOffer({wants_send, options.recv_audio}); | |
| 1324 | |
| 1252 AudioCodecs audio_codecs; | 1325 AudioCodecs audio_codecs; |
| 1253 VideoCodecs video_codecs; | 1326 VideoCodecs video_codecs; |
| 1254 DataCodecs data_codecs; | 1327 DataCodecs data_codecs; |
| 1255 GetCodecsToOffer(current_description, &audio_codecs, &video_codecs, | 1328 GetCodecsToOffer(current_description, supported_audio_codecs, |
| 1256 &data_codecs); | 1329 video_codecs_, data_codecs_, |
| 1330 &audio_codecs, &video_codecs, &data_codecs); | |
| 1257 | 1331 |
| 1258 if (!options.vad_enabled) { | 1332 if (!options.vad_enabled) { |
| 1259 // If application doesn't want CN codecs in offer. | 1333 // If application doesn't want CN codecs in offer. |
| 1260 StripCNCodecs(&audio_codecs); | 1334 StripCNCodecs(&audio_codecs); |
| 1261 } | 1335 } |
| 1262 | 1336 |
| 1263 RtpHeaderExtensions audio_rtp_extensions; | 1337 RtpHeaderExtensions audio_rtp_extensions; |
| 1264 RtpHeaderExtensions video_rtp_extensions; | 1338 RtpHeaderExtensions video_rtp_extensions; |
| 1265 GetRtpHdrExtsToOffer(current_description, &audio_rtp_extensions, | 1339 GetRtpHdrExtsToOffer(current_description, &audio_rtp_extensions, |
| 1266 &video_rtp_extensions); | 1340 &video_rtp_extensions); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1405 if (!UpdateCryptoParamsForBundle(answer_bundle, answer.get())) { | 1479 if (!UpdateCryptoParamsForBundle(answer_bundle, answer.get())) { |
| 1406 LOG(LS_ERROR) << "CreateAnswer failed to UpdateCryptoParamsForBundle."; | 1480 LOG(LS_ERROR) << "CreateAnswer failed to UpdateCryptoParamsForBundle."; |
| 1407 return NULL; | 1481 return NULL; |
| 1408 } | 1482 } |
| 1409 } | 1483 } |
| 1410 } | 1484 } |
| 1411 | 1485 |
| 1412 return answer.release(); | 1486 return answer.release(); |
| 1413 } | 1487 } |
| 1414 | 1488 |
| 1489 const AudioCodecs& MediaSessionDescriptionFactory::GetAudioCodecsForOffer( | |
| 1490 const RtpTransceiverDirection& direction) const { | |
| 1491 // If stream is inactive - generate list as if sendrecv. | |
| 1492 if (direction.send == direction.recv) { | |
| 1493 return audio_sendrecv_codecs_; | |
| 1494 } else if (direction.send) { | |
| 1495 return audio_send_codecs_; | |
| 1496 } else { | |
| 1497 return audio_recv_codecs_; | |
| 1498 } | |
| 1499 } | |
| 1500 | |
| 1501 const AudioCodecs& MediaSessionDescriptionFactory::GetAudioCodecsForAnswer( | |
| 1502 const RtpTransceiverDirection& offer, | |
| 1503 const RtpTransceiverDirection& answer) const { | |
| 1504 // For inactive and sendrecv answers, generate lists as if we were to accept | |
| 1505 // the offer's direction. See RFC 3264 Section 6.1. | |
| 1506 if (answer.send == answer.recv) { | |
| 1507 if (offer.send == offer.recv) { | |
| 1508 return audio_sendrecv_codecs_; | |
| 1509 } else if (offer.send) { | |
| 1510 return audio_recv_codecs_; | |
| 1511 } else { | |
| 1512 return audio_send_codecs_; | |
| 1513 } | |
| 1514 } else if (answer.send) { | |
| 1515 return audio_send_codecs_; | |
| 1516 } else { | |
| 1517 return audio_recv_codecs_; | |
| 1518 } | |
| 1519 } | |
| 1520 | |
| 1415 void MediaSessionDescriptionFactory::GetCodecsToOffer( | 1521 void MediaSessionDescriptionFactory::GetCodecsToOffer( |
| 1416 const SessionDescription* current_description, | 1522 const SessionDescription* current_description, |
| 1523 const AudioCodecs& supported_audio_codecs, | |
| 1524 const VideoCodecs& supported_video_codecs, | |
| 1525 const DataCodecs& supported_data_codecs, | |
| 1417 AudioCodecs* audio_codecs, | 1526 AudioCodecs* audio_codecs, |
| 1418 VideoCodecs* video_codecs, | 1527 VideoCodecs* video_codecs, |
| 1419 DataCodecs* data_codecs) const { | 1528 DataCodecs* data_codecs) const { |
| 1420 UsedPayloadTypes used_pltypes; | 1529 UsedPayloadTypes used_pltypes; |
| 1421 audio_codecs->clear(); | 1530 audio_codecs->clear(); |
| 1422 video_codecs->clear(); | 1531 video_codecs->clear(); |
| 1423 data_codecs->clear(); | 1532 data_codecs->clear(); |
| 1424 | 1533 |
| 1425 | 1534 |
| 1426 // First - get all codecs from the current description if the media type | 1535 // First - get all codecs from the current description if the media type |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1442 } | 1551 } |
| 1443 const DataContentDescription* data = | 1552 const DataContentDescription* data = |
| 1444 GetFirstDataContentDescription(current_description); | 1553 GetFirstDataContentDescription(current_description); |
| 1445 if (data) { | 1554 if (data) { |
| 1446 *data_codecs = data->codecs(); | 1555 *data_codecs = data->codecs(); |
| 1447 used_pltypes.FindAndSetIdUsed<DataCodec>(data_codecs); | 1556 used_pltypes.FindAndSetIdUsed<DataCodec>(data_codecs); |
| 1448 } | 1557 } |
| 1449 } | 1558 } |
| 1450 | 1559 |
| 1451 // Add our codecs that are not in |current_description|. | 1560 // Add our codecs that are not in |current_description|. |
| 1452 FindCodecsToOffer<AudioCodec>(audio_codecs_, audio_codecs, &used_pltypes); | 1561 FindCodecsToOffer<AudioCodec>(supported_audio_codecs, audio_codecs, |
| 1453 FindCodecsToOffer<VideoCodec>(video_codecs_, video_codecs, &used_pltypes); | 1562 &used_pltypes); |
| 1454 FindCodecsToOffer<DataCodec>(data_codecs_, data_codecs, &used_pltypes); | 1563 FindCodecsToOffer<VideoCodec>(supported_video_codecs, video_codecs, |
| 1564 &used_pltypes); | |
| 1565 FindCodecsToOffer<DataCodec>(supported_data_codecs, data_codecs, | |
| 1566 &used_pltypes); | |
| 1455 } | 1567 } |
| 1456 | 1568 |
| 1457 void MediaSessionDescriptionFactory::GetRtpHdrExtsToOffer( | 1569 void MediaSessionDescriptionFactory::GetRtpHdrExtsToOffer( |
| 1458 const SessionDescription* current_description, | 1570 const SessionDescription* current_description, |
| 1459 RtpHeaderExtensions* audio_extensions, | 1571 RtpHeaderExtensions* audio_extensions, |
| 1460 RtpHeaderExtensions* video_extensions) const { | 1572 RtpHeaderExtensions* video_extensions) const { |
| 1461 // All header extensions allocated from the same range to avoid potential | 1573 // All header extensions allocated from the same range to avoid potential |
| 1462 // issues when using BUNDLE. | 1574 // issues when using BUNDLE. |
| 1463 UsedRtpHeaderExtensionIds used_ids; | 1575 UsedRtpHeaderExtensionIds used_ids; |
| 1464 RtpHeaderExtensions all_extensions; | 1576 RtpHeaderExtensions all_extensions; |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1570 add_legacy_, | 1682 add_legacy_, |
| 1571 current_streams, | 1683 current_streams, |
| 1572 audio.get())) { | 1684 audio.get())) { |
| 1573 return false; | 1685 return false; |
| 1574 } | 1686 } |
| 1575 audio->set_lang(lang_); | 1687 audio->set_lang(lang_); |
| 1576 | 1688 |
| 1577 bool secure_transport = (transport_desc_factory_->secure() != SEC_DISABLED); | 1689 bool secure_transport = (transport_desc_factory_->secure() != SEC_DISABLED); |
| 1578 SetMediaProtocol(secure_transport, audio.get()); | 1690 SetMediaProtocol(secure_transport, audio.get()); |
| 1579 | 1691 |
| 1580 if (!audio->streams().empty()) { | 1692 auto offer_rtd = |
| 1581 if (options.recv_audio) { | 1693 RtpTransceiverDirection(!audio->streams().empty(), options.recv_audio); |
| 1582 audio->set_direction(MD_SENDRECV); | 1694 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 | 1695 |
| 1594 desc->AddContent(content_name, NS_JINGLE_RTP, audio.release()); | 1696 desc->AddContent(content_name, NS_JINGLE_RTP, audio.release()); |
| 1595 if (!AddTransportOffer(content_name, | 1697 if (!AddTransportOffer(content_name, |
| 1596 GetTransportOptions(options, content_name), | 1698 GetTransportOptions(options, content_name), |
| 1597 current_description, desc)) { | 1699 current_description, desc)) { |
| 1598 return false; | 1700 return false; |
| 1599 } | 1701 } |
| 1600 | 1702 |
| 1601 return true; | 1703 return true; |
| 1602 } | 1704 } |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1726 return true; | 1828 return true; |
| 1727 } | 1829 } |
| 1728 | 1830 |
| 1729 bool MediaSessionDescriptionFactory::AddAudioContentForAnswer( | 1831 bool MediaSessionDescriptionFactory::AddAudioContentForAnswer( |
| 1730 const SessionDescription* offer, | 1832 const SessionDescription* offer, |
| 1731 const MediaSessionOptions& options, | 1833 const MediaSessionOptions& options, |
| 1732 const SessionDescription* current_description, | 1834 const SessionDescription* current_description, |
| 1733 StreamParamsVec* current_streams, | 1835 StreamParamsVec* current_streams, |
| 1734 SessionDescription* answer) const { | 1836 SessionDescription* answer) const { |
| 1735 const ContentInfo* audio_content = GetFirstAudioContent(offer); | 1837 const ContentInfo* audio_content = GetFirstAudioContent(offer); |
| 1838 const AudioContentDescription* offer_audio = | |
| 1839 static_cast<const AudioContentDescription*>(audio_content->description); | |
| 1736 | 1840 |
| 1737 std::unique_ptr<TransportDescription> audio_transport(CreateTransportAnswer( | 1841 std::unique_ptr<TransportDescription> audio_transport(CreateTransportAnswer( |
| 1738 audio_content->name, offer, | 1842 audio_content->name, offer, |
| 1739 GetTransportOptions(options, audio_content->name), current_description)); | 1843 GetTransportOptions(options, audio_content->name), current_description)); |
| 1740 if (!audio_transport) { | 1844 if (!audio_transport) { |
| 1741 return false; | 1845 return false; |
| 1742 } | 1846 } |
| 1743 | 1847 |
| 1744 AudioCodecs audio_codecs = audio_codecs_; | 1848 // Pick codecs based on the requested communications direction in the offer. |
| 1849 const bool wants_send = | |
| 1850 options.HasSendMediaStream(MEDIA_TYPE_AUDIO) || add_legacy_; | |
| 1851 auto wants_rtd = RtpTransceiverDirection(wants_send, options.recv_audio); | |
| 1852 auto offer_rtd = | |
| 1853 RtpTransceiverDirection::FromMediaContentDirection( | |
| 1854 offer_audio->direction()); | |
| 1855 auto answer_rtd = NegotiateRtpTransceiverDirection(offer_rtd, wants_rtd); | |
| 1856 AudioCodecs audio_codecs = GetAudioCodecsForAnswer(offer_rtd, answer_rtd); | |
| 1745 if (!options.vad_enabled) { | 1857 if (!options.vad_enabled) { |
| 1746 StripCNCodecs(&audio_codecs); | 1858 StripCNCodecs(&audio_codecs); |
| 1747 } | 1859 } |
| 1748 | 1860 |
| 1749 bool bundle_enabled = | 1861 bool bundle_enabled = |
| 1750 offer->HasGroup(GROUP_TYPE_BUNDLE) && options.bundle_enabled; | 1862 offer->HasGroup(GROUP_TYPE_BUNDLE) && options.bundle_enabled; |
| 1751 std::unique_ptr<AudioContentDescription> audio_answer( | 1863 std::unique_ptr<AudioContentDescription> audio_answer( |
| 1752 new AudioContentDescription()); | 1864 new AudioContentDescription()); |
| 1753 // Do not require or create SDES cryptos if DTLS is used. | 1865 // Do not require or create SDES cryptos if DTLS is used. |
| 1754 cricket::SecurePolicy sdes_policy = | 1866 cricket::SecurePolicy sdes_policy = |
| 1755 audio_transport->secure() ? cricket::SEC_DISABLED : secure(); | 1867 audio_transport->secure() ? cricket::SEC_DISABLED : secure(); |
| 1756 if (!CreateMediaContentAnswer( | 1868 if (!CreateMediaContentAnswer( |
| 1757 static_cast<const AudioContentDescription*>( | 1869 offer_audio, |
| 1758 audio_content->description), | |
| 1759 options, | 1870 options, |
| 1760 audio_codecs, | 1871 audio_codecs, |
| 1761 sdes_policy, | 1872 sdes_policy, |
| 1762 GetCryptos(GetFirstAudioContentDescription(current_description)), | 1873 GetCryptos(GetFirstAudioContentDescription(current_description)), |
| 1763 audio_rtp_extensions_, | 1874 audio_rtp_extensions_, |
| 1764 current_streams, | 1875 current_streams, |
| 1765 add_legacy_, | 1876 add_legacy_, |
| 1766 bundle_enabled, | 1877 bundle_enabled, |
| 1767 audio_answer.get())) { | 1878 audio_answer.get())) { |
| 1768 return false; // Fails the session setup. | 1879 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)); | 2091 GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_VIDEO)); |
| 1981 } | 2092 } |
| 1982 | 2093 |
| 1983 const DataContentDescription* GetFirstDataContentDescription( | 2094 const DataContentDescription* GetFirstDataContentDescription( |
| 1984 const SessionDescription* sdesc) { | 2095 const SessionDescription* sdesc) { |
| 1985 return static_cast<const DataContentDescription*>( | 2096 return static_cast<const DataContentDescription*>( |
| 1986 GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_DATA)); | 2097 GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_DATA)); |
| 1987 } | 2098 } |
| 1988 | 2099 |
| 1989 } // namespace cricket | 2100 } // namespace cricket |
| OLD | NEW |