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 1216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1227 add_legacy_(true), | 1227 add_legacy_(true), |
1228 transport_desc_factory_(transport_desc_factory) { | 1228 transport_desc_factory_(transport_desc_factory) { |
1229 } | 1229 } |
1230 | 1230 |
1231 MediaSessionDescriptionFactory::MediaSessionDescriptionFactory( | 1231 MediaSessionDescriptionFactory::MediaSessionDescriptionFactory( |
1232 ChannelManager* channel_manager, | 1232 ChannelManager* channel_manager, |
1233 const TransportDescriptionFactory* transport_desc_factory) | 1233 const TransportDescriptionFactory* transport_desc_factory) |
1234 : secure_(SEC_DISABLED), | 1234 : secure_(SEC_DISABLED), |
1235 add_legacy_(true), | 1235 add_legacy_(true), |
1236 transport_desc_factory_(transport_desc_factory) { | 1236 transport_desc_factory_(transport_desc_factory) { |
1237 channel_manager->GetSupportedAudioCodecs(&audio_codecs_); | 1237 channel_manager->GetSupportedAudioCodecs(&audio_sendrecv_codecs_); |
1238 channel_manager->GetSupportedAudioRtpHeaderExtensions(&audio_rtp_extensions_); | 1238 channel_manager->GetSupportedAudioRtpHeaderExtensions(&audio_rtp_extensions_); |
1239 channel_manager->GetSupportedVideoCodecs(&video_codecs_); | 1239 channel_manager->GetSupportedVideoCodecs(&video_codecs_); |
1240 channel_manager->GetSupportedVideoRtpHeaderExtensions(&video_rtp_extensions_); | 1240 channel_manager->GetSupportedVideoRtpHeaderExtensions(&video_rtp_extensions_); |
1241 channel_manager->GetSupportedDataCodecs(&data_codecs_); | 1241 channel_manager->GetSupportedDataCodecs(&data_codecs_); |
1242 audio_send_codecs_ = audio_sendrecv_codecs_; | |
1243 audio_recv_codecs_ = audio_sendrecv_codecs_; | |
1244 } | |
1245 | |
1246 const AudioCodecs& MediaSessionDescriptionFactory::audio_codecs() const { | |
1247 return audio_sendrecv_codecs_; | |
1248 } | |
1249 | |
1250 void MediaSessionDescriptionFactory::set_audio_codecs( | |
1251 const AudioCodecs& send_and_recv_codecs) { | |
1252 audio_send_codecs_ = send_and_recv_codecs; | |
1253 audio_recv_codecs_ = send_and_recv_codecs; | |
1254 audio_sendrecv_codecs_ = send_and_recv_codecs; | |
1255 } | |
1256 | |
1257 void MediaSessionDescriptionFactory::set_audio_codecs( | |
1258 const AudioCodecs& send_codecs, const AudioCodecs& recv_codecs) { | |
1259 audio_send_codecs_ = send_codecs; | |
1260 audio_recv_codecs_ = recv_codecs; | |
1261 audio_sendrecv_codecs_.clear(); | |
1262 | |
1263 // Intersect the two lists of codecs, preserving the order of the send codecs. | |
1264 // If there's any difference in priorities, chances are encoding is more | |
1265 // expensive than decoding, and high-priority send codecs are likely handled | |
1266 // better (e.g. through hardware encoder support) than low-priority ones. | |
1267 // TODO(ossu): Deal with channels == 0 also meaning channels = 1. | |
1268 // TODO(ossu): This is O(n^2). Normalizing and putting in a set could handle | |
1269 // both issues. | |
1270 for (const auto& sc : audio_send_codecs_) { | |
ossu
2016/05/09 10:57:06
This clearly needs testing and should probably be
| |
1271 for (const auto& rc : audio_recv_codecs_) { | |
1272 if (sc.clockrate == rc.clockrate && | |
1273 sc.bitrate == rc.bitrate && | |
1274 sc.channels == rc.channels && | |
1275 sc.name == rc.name && | |
1276 sc.params == rc.params && | |
1277 sc.feedback_params == rc.feedback_params) { | |
1278 audio_sendrecv_codecs_.push_back(sc); | |
1279 break; | |
1280 } | |
1281 } | |
1282 } | |
1242 } | 1283 } |
1243 | 1284 |
1244 SessionDescription* MediaSessionDescriptionFactory::CreateOffer( | 1285 SessionDescription* MediaSessionDescriptionFactory::CreateOffer( |
1245 const MediaSessionOptions& options, | 1286 const MediaSessionOptions& options, |
1246 const SessionDescription* current_description) const { | 1287 const SessionDescription* current_description) const { |
1247 std::unique_ptr<SessionDescription> offer(new SessionDescription()); | 1288 std::unique_ptr<SessionDescription> offer(new SessionDescription()); |
1248 | 1289 |
1249 StreamParamsVec current_streams; | 1290 StreamParamsVec current_streams; |
1250 GetCurrentStreamParams(current_description, ¤t_streams); | 1291 GetCurrentStreamParams(current_description, ¤t_streams); |
1251 | 1292 |
1293 const AudioCodecs *supported_audio_codecs = nullptr; | |
kwiberg-webrtc
2016/05/17 12:22:36
You set this in all branches below, so the default
ossu
2016/05/23 14:18:04
Acknowledged.
| |
1294 if (options.HasSendMediaStream(MEDIA_TYPE_AUDIO)) { | |
1295 if (options.recv_audio) { | |
1296 // sendrecv | |
1297 supported_audio_codecs = &audio_sendrecv_codecs_; | |
1298 } else { | |
1299 // sendonly | |
1300 supported_audio_codecs = &audio_send_codecs_; | |
1301 } | |
1302 } else if (options.recv_audio) { | |
1303 // recvonly | |
1304 supported_audio_codecs = &audio_recv_codecs_; | |
1305 } else { | |
1306 // Stream is inactive - generate list as if sendrecv. | |
1307 // See RFC 3264 Section 6.1. | |
1308 supported_audio_codecs = &audio_sendrecv_codecs_; | |
1309 } | |
1310 | |
1252 AudioCodecs audio_codecs; | 1311 AudioCodecs audio_codecs; |
1253 VideoCodecs video_codecs; | 1312 VideoCodecs video_codecs; |
1254 DataCodecs data_codecs; | 1313 DataCodecs data_codecs; |
1255 GetCodecsToOffer(current_description, &audio_codecs, &video_codecs, | 1314 GetCodecsToOffer(current_description, *supported_audio_codecs, |
1256 &data_codecs); | 1315 video_codecs_, data_codecs_, |
1316 &audio_codecs, &video_codecs, &data_codecs); | |
1257 | 1317 |
1258 if (!options.vad_enabled) { | 1318 if (!options.vad_enabled) { |
1259 // If application doesn't want CN codecs in offer. | 1319 // If application doesn't want CN codecs in offer. |
1260 StripCNCodecs(&audio_codecs); | 1320 StripCNCodecs(&audio_codecs); |
1261 } | 1321 } |
1262 | 1322 |
1263 RtpHeaderExtensions audio_rtp_extensions; | 1323 RtpHeaderExtensions audio_rtp_extensions; |
1264 RtpHeaderExtensions video_rtp_extensions; | 1324 RtpHeaderExtensions video_rtp_extensions; |
1265 GetRtpHdrExtsToOffer(current_description, &audio_rtp_extensions, | 1325 GetRtpHdrExtsToOffer(current_description, &audio_rtp_extensions, |
1266 &video_rtp_extensions); | 1326 &video_rtp_extensions); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1407 return NULL; | 1467 return NULL; |
1408 } | 1468 } |
1409 } | 1469 } |
1410 } | 1470 } |
1411 | 1471 |
1412 return answer.release(); | 1472 return answer.release(); |
1413 } | 1473 } |
1414 | 1474 |
1415 void MediaSessionDescriptionFactory::GetCodecsToOffer( | 1475 void MediaSessionDescriptionFactory::GetCodecsToOffer( |
1416 const SessionDescription* current_description, | 1476 const SessionDescription* current_description, |
1477 const AudioCodecs& supported_audio_codecs, | |
1478 const VideoCodecs& supported_video_codecs, | |
1479 const DataCodecs& supported_data_codecs, | |
1417 AudioCodecs* audio_codecs, | 1480 AudioCodecs* audio_codecs, |
1418 VideoCodecs* video_codecs, | 1481 VideoCodecs* video_codecs, |
1419 DataCodecs* data_codecs) const { | 1482 DataCodecs* data_codecs) const { |
1420 UsedPayloadTypes used_pltypes; | 1483 UsedPayloadTypes used_pltypes; |
1421 audio_codecs->clear(); | 1484 audio_codecs->clear(); |
1422 video_codecs->clear(); | 1485 video_codecs->clear(); |
1423 data_codecs->clear(); | 1486 data_codecs->clear(); |
1424 | 1487 |
1425 | 1488 |
1426 // First - get all codecs from the current description if the media type | 1489 // First - get all codecs from the current description if the media type |
(...skipping 15 matching lines...) Expand all Loading... | |
1442 } | 1505 } |
1443 const DataContentDescription* data = | 1506 const DataContentDescription* data = |
1444 GetFirstDataContentDescription(current_description); | 1507 GetFirstDataContentDescription(current_description); |
1445 if (data) { | 1508 if (data) { |
1446 *data_codecs = data->codecs(); | 1509 *data_codecs = data->codecs(); |
1447 used_pltypes.FindAndSetIdUsed<DataCodec>(data_codecs); | 1510 used_pltypes.FindAndSetIdUsed<DataCodec>(data_codecs); |
1448 } | 1511 } |
1449 } | 1512 } |
1450 | 1513 |
1451 // Add our codecs that are not in |current_description|. | 1514 // Add our codecs that are not in |current_description|. |
1452 FindCodecsToOffer<AudioCodec>(audio_codecs_, audio_codecs, &used_pltypes); | 1515 FindCodecsToOffer<AudioCodec>(supported_audio_codecs, audio_codecs, |
1453 FindCodecsToOffer<VideoCodec>(video_codecs_, video_codecs, &used_pltypes); | 1516 &used_pltypes); |
1454 FindCodecsToOffer<DataCodec>(data_codecs_, data_codecs, &used_pltypes); | 1517 FindCodecsToOffer<VideoCodec>(supported_video_codecs, video_codecs, |
1518 &used_pltypes); | |
1519 FindCodecsToOffer<DataCodec>(supported_data_codecs, data_codecs, | |
1520 &used_pltypes); | |
1455 } | 1521 } |
1456 | 1522 |
1457 void MediaSessionDescriptionFactory::GetRtpHdrExtsToOffer( | 1523 void MediaSessionDescriptionFactory::GetRtpHdrExtsToOffer( |
1458 const SessionDescription* current_description, | 1524 const SessionDescription* current_description, |
1459 RtpHeaderExtensions* audio_extensions, | 1525 RtpHeaderExtensions* audio_extensions, |
1460 RtpHeaderExtensions* video_extensions) const { | 1526 RtpHeaderExtensions* video_extensions) const { |
1461 // All header extensions allocated from the same range to avoid potential | 1527 // All header extensions allocated from the same range to avoid potential |
1462 // issues when using BUNDLE. | 1528 // issues when using BUNDLE. |
1463 UsedRtpHeaderExtensionIds used_ids; | 1529 UsedRtpHeaderExtensionIds used_ids; |
1464 RtpHeaderExtensions all_extensions; | 1530 RtpHeaderExtensions all_extensions; |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1726 return true; | 1792 return true; |
1727 } | 1793 } |
1728 | 1794 |
1729 bool MediaSessionDescriptionFactory::AddAudioContentForAnswer( | 1795 bool MediaSessionDescriptionFactory::AddAudioContentForAnswer( |
1730 const SessionDescription* offer, | 1796 const SessionDescription* offer, |
1731 const MediaSessionOptions& options, | 1797 const MediaSessionOptions& options, |
1732 const SessionDescription* current_description, | 1798 const SessionDescription* current_description, |
1733 StreamParamsVec* current_streams, | 1799 StreamParamsVec* current_streams, |
1734 SessionDescription* answer) const { | 1800 SessionDescription* answer) const { |
1735 const ContentInfo* audio_content = GetFirstAudioContent(offer); | 1801 const ContentInfo* audio_content = GetFirstAudioContent(offer); |
1802 const AudioContentDescription* audio_content_description = | |
1803 static_cast<const AudioContentDescription*>(audio_content->description); | |
1736 | 1804 |
1737 std::unique_ptr<TransportDescription> audio_transport(CreateTransportAnswer( | 1805 std::unique_ptr<TransportDescription> audio_transport(CreateTransportAnswer( |
1738 audio_content->name, offer, | 1806 audio_content->name, offer, |
1739 GetTransportOptions(options, audio_content->name), current_description)); | 1807 GetTransportOptions(options, audio_content->name), current_description)); |
1740 if (!audio_transport) { | 1808 if (!audio_transport) { |
1741 return false; | 1809 return false; |
1742 } | 1810 } |
1743 | 1811 |
1744 AudioCodecs audio_codecs = audio_codecs_; | 1812 // Pick codecs based on the requested communications direction in the offer. |
1813 // According to RFC 3264 Section 6.1, inactive is to be treated as sendrecv | |
1814 // when constructing the list of supported formats. | |
1815 AudioCodecs audio_codecs; | |
1816 switch (audio_content_description->direction()) { | |
1817 case MD_INACTIVE: | |
1818 audio_codecs = audio_sendrecv_codecs_; | |
1819 break; | |
1820 case MD_SENDRECV: | |
1821 if (options.HasSendMediaStream(MEDIA_TYPE_AUDIO)) | |
1822 audio_codecs = audio_sendrecv_codecs_; | |
1823 else | |
1824 audio_codecs = audio_recv_codecs_; | |
1825 break; | |
1826 case MD_RECVONLY: | |
1827 if (options.HasSendMediaStream(MEDIA_TYPE_AUDIO)) | |
1828 audio_codecs = audio_send_codecs_; | |
1829 else | |
1830 audio_codecs = audio_sendrecv_codecs_; // inactive | |
1831 break; | |
1832 case MD_SENDONLY: | |
1833 audio_codecs = audio_recv_codecs_; | |
1834 break; | |
1835 } | |
1836 | |
1745 if (!options.vad_enabled) { | 1837 if (!options.vad_enabled) { |
1746 StripCNCodecs(&audio_codecs); | 1838 StripCNCodecs(&audio_codecs); |
1747 } | 1839 } |
1748 | 1840 |
1749 bool bundle_enabled = | 1841 bool bundle_enabled = |
1750 offer->HasGroup(GROUP_TYPE_BUNDLE) && options.bundle_enabled; | 1842 offer->HasGroup(GROUP_TYPE_BUNDLE) && options.bundle_enabled; |
1751 std::unique_ptr<AudioContentDescription> audio_answer( | 1843 std::unique_ptr<AudioContentDescription> audio_answer( |
1752 new AudioContentDescription()); | 1844 new AudioContentDescription()); |
1753 // Do not require or create SDES cryptos if DTLS is used. | 1845 // Do not require or create SDES cryptos if DTLS is used. |
1754 cricket::SecurePolicy sdes_policy = | 1846 cricket::SecurePolicy sdes_policy = |
1755 audio_transport->secure() ? cricket::SEC_DISABLED : secure(); | 1847 audio_transport->secure() ? cricket::SEC_DISABLED : secure(); |
1756 if (!CreateMediaContentAnswer( | 1848 if (!CreateMediaContentAnswer( |
1757 static_cast<const AudioContentDescription*>( | 1849 audio_content_description, |
1758 audio_content->description), | |
1759 options, | 1850 options, |
1760 audio_codecs, | 1851 audio_codecs, |
1761 sdes_policy, | 1852 sdes_policy, |
1762 GetCryptos(GetFirstAudioContentDescription(current_description)), | 1853 GetCryptos(GetFirstAudioContentDescription(current_description)), |
1763 audio_rtp_extensions_, | 1854 audio_rtp_extensions_, |
1764 current_streams, | 1855 current_streams, |
1765 add_legacy_, | 1856 add_legacy_, |
1766 bundle_enabled, | 1857 bundle_enabled, |
1767 audio_answer.get())) { | 1858 audio_answer.get())) { |
1768 return false; // Fails the session setup. | 1859 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)); | 2071 GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_VIDEO)); |
1981 } | 2072 } |
1982 | 2073 |
1983 const DataContentDescription* GetFirstDataContentDescription( | 2074 const DataContentDescription* GetFirstDataContentDescription( |
1984 const SessionDescription* sdesc) { | 2075 const SessionDescription* sdesc) { |
1985 return static_cast<const DataContentDescription*>( | 2076 return static_cast<const DataContentDescription*>( |
1986 GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_DATA)); | 2077 GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_DATA)); |
1987 } | 2078 } |
1988 | 2079 |
1989 } // namespace cricket | 2080 } // namespace cricket |
OLD | NEW |