Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * libjingle | 2 * libjingle |
| 3 * Copyright 2004 Google Inc. | 3 * Copyright 2004 Google Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
| (...skipping 895 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 906 std::string* error_desc) { | 906 std::string* error_desc) { |
| 907 *dtls = transport_channel_->IsDtlsActive(); | 907 *dtls = transport_channel_->IsDtlsActive(); |
| 908 if (*dtls && !cryptos.empty()) { | 908 if (*dtls && !cryptos.empty()) { |
| 909 SafeSetError("Cryptos must be empty when DTLS is active.", | 909 SafeSetError("Cryptos must be empty when DTLS is active.", |
| 910 error_desc); | 910 error_desc); |
| 911 return false; | 911 return false; |
| 912 } | 912 } |
| 913 return true; | 913 return true; |
| 914 } | 914 } |
| 915 | 915 |
| 916 bool BaseChannel::SetRecvRtpHeaderExtensions_w( | |
| 917 const MediaContentDescription* content, | |
| 918 MediaChannel* media_channel, | |
| 919 std::string* error_desc) { | |
| 920 if (content->rtp_header_extensions_set()) { | |
| 921 if (!media_channel->SetRecvRtpHeaderExtensions( | |
| 922 content->rtp_header_extensions())) { | |
| 923 std::ostringstream desc; | |
| 924 desc << "Failed to set receive rtp header extensions for " | |
| 925 << MediaTypeToString(content->type()) << " content."; | |
| 926 SafeSetError(desc.str(), error_desc); | |
| 927 return false; | |
| 928 } | |
| 929 } | |
| 930 return true; | |
| 931 } | |
| 932 | |
| 933 bool BaseChannel::SetSendRtpHeaderExtensions_w( | |
| 934 const MediaContentDescription* content, | |
| 935 MediaChannel* media_channel, | |
| 936 std::string* error_desc) { | |
| 937 if (content->rtp_header_extensions_set()) { | |
| 938 if (!media_channel->SetSendRtpHeaderExtensions( | |
| 939 content->rtp_header_extensions())) { | |
| 940 std::ostringstream desc; | |
| 941 desc << "Failed to set send rtp header extensions for " | |
| 942 << MediaTypeToString(content->type()) << " content."; | |
| 943 SafeSetError(desc.str(), error_desc); | |
| 944 return false; | |
| 945 } else { | |
| 946 MaybeCacheRtpAbsSendTimeHeaderExtension(content->rtp_header_extensions()); | |
| 947 } | |
| 948 } | |
| 949 return true; | |
| 950 } | |
| 951 | |
| 952 bool BaseChannel::SetSrtp_w(const std::vector<CryptoParams>& cryptos, | 916 bool BaseChannel::SetSrtp_w(const std::vector<CryptoParams>& cryptos, |
| 953 ContentAction action, | 917 ContentAction action, |
| 954 ContentSource src, | 918 ContentSource src, |
| 955 std::string* error_desc) { | 919 std::string* error_desc) { |
| 956 if (action == CA_UPDATE) { | 920 if (action == CA_UPDATE) { |
| 957 // no crypto params. | 921 // no crypto params. |
| 958 return true; | 922 return true; |
| 959 } | 923 } |
| 960 bool ret = false; | 924 bool ret = false; |
| 961 bool dtls = false; | 925 bool dtls = false; |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1203 desc << "Failed to add remote stream ssrc: " << it->first_ssrc(); | 1167 desc << "Failed to add remote stream ssrc: " << it->first_ssrc(); |
| 1204 SafeSetError(desc.str(), error_desc); | 1168 SafeSetError(desc.str(), error_desc); |
| 1205 ret = false; | 1169 ret = false; |
| 1206 } | 1170 } |
| 1207 } | 1171 } |
| 1208 } | 1172 } |
| 1209 remote_streams_ = streams; | 1173 remote_streams_ = streams; |
| 1210 return ret; | 1174 return ret; |
| 1211 } | 1175 } |
| 1212 | 1176 |
| 1213 bool BaseChannel::SetBaseLocalContent_w(const MediaContentDescription* content, | |
| 1214 ContentAction action, | |
| 1215 std::string* error_desc) { | |
| 1216 // Cache secure_required_ for belt and suspenders check on SendPacket | |
| 1217 secure_required_ = content->crypto_required() != CT_NONE; | |
| 1218 // Set local RTP header extensions. | |
| 1219 bool ret = SetRecvRtpHeaderExtensions_w(content, media_channel(), error_desc); | |
| 1220 // Set local SRTP parameters (what we will encrypt with). | |
| 1221 ret &= SetSrtp_w(content->cryptos(), action, CS_LOCAL, error_desc); | |
| 1222 // Set local RTCP mux parameters. | |
| 1223 ret &= SetRtcpMux_w(content->rtcp_mux(), action, CS_LOCAL, error_desc); | |
| 1224 | |
| 1225 // Call UpdateLocalStreams_w last to make sure as many settings as possible | |
| 1226 // are already set when creating streams. | |
| 1227 ret &= UpdateLocalStreams_w(content->streams(), action, error_desc); | |
| 1228 set_local_content_direction(content->direction()); | |
| 1229 return ret; | |
| 1230 } | |
| 1231 | |
| 1232 bool BaseChannel::SetBaseRemoteContent_w(const MediaContentDescription* content, | |
| 1233 ContentAction action, | |
| 1234 std::string* error_desc) { | |
| 1235 // Set remote RTP header extensions. | |
| 1236 bool ret = SetSendRtpHeaderExtensions_w(content, media_channel(), error_desc); | |
| 1237 // Set remote SRTP parameters (what the other side will encrypt with). | |
| 1238 ret &= SetSrtp_w(content->cryptos(), action, CS_REMOTE, error_desc); | |
| 1239 // Set remote RTCP mux parameters. | |
| 1240 ret &= SetRtcpMux_w(content->rtcp_mux(), action, CS_REMOTE, error_desc); | |
| 1241 if (!media_channel()->SetMaxSendBandwidth(content->bandwidth())) { | |
| 1242 std::ostringstream desc; | |
| 1243 desc << "Failed to set max send bandwidth for " | |
| 1244 << MediaTypeToString(content->type()) << " content."; | |
| 1245 SafeSetError(desc.str(), error_desc); | |
| 1246 ret = false; | |
| 1247 } | |
| 1248 | |
| 1249 // Call UpdateRemoteStreams_w last to make sure as many settings as possible | |
| 1250 // are already set when creating streams. | |
| 1251 ret &= UpdateRemoteStreams_w(content->streams(), action, error_desc); | |
| 1252 set_remote_content_direction(content->direction()); | |
| 1253 return ret; | |
| 1254 } | |
| 1255 | |
| 1256 void BaseChannel::MaybeCacheRtpAbsSendTimeHeaderExtension( | 1177 void BaseChannel::MaybeCacheRtpAbsSendTimeHeaderExtension( |
| 1257 const std::vector<RtpHeaderExtension>& extensions) { | 1178 const std::vector<RtpHeaderExtension>& extensions) { |
| 1258 const RtpHeaderExtension* send_time_extension = | 1179 const RtpHeaderExtension* send_time_extension = |
| 1259 FindHeaderExtension(extensions, kRtpAbsoluteSenderTimeHeaderExtension); | 1180 FindHeaderExtension(extensions, kRtpAbsoluteSenderTimeHeaderExtension); |
| 1260 rtp_abs_sendtime_extn_id_ = | 1181 rtp_abs_sendtime_extn_id_ = |
| 1261 send_time_extension ? send_time_extension->id : -1; | 1182 send_time_extension ? send_time_extension->id : -1; |
| 1262 } | 1183 } |
| 1263 | 1184 |
| 1264 void BaseChannel::OnMessage(rtc::Message *pmsg) { | 1185 void BaseChannel::OnMessage(rtc::Message *pmsg) { |
| 1265 switch (pmsg->message_id) { | 1186 switch (pmsg->message_id) { |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1495 LOG(LS_INFO) << "Setting local voice description"; | 1416 LOG(LS_INFO) << "Setting local voice description"; |
| 1496 | 1417 |
| 1497 const AudioContentDescription* audio = | 1418 const AudioContentDescription* audio = |
| 1498 static_cast<const AudioContentDescription*>(content); | 1419 static_cast<const AudioContentDescription*>(content); |
| 1499 ASSERT(audio != NULL); | 1420 ASSERT(audio != NULL); |
| 1500 if (!audio) { | 1421 if (!audio) { |
| 1501 SafeSetError("Can't find audio content in local description.", error_desc); | 1422 SafeSetError("Can't find audio content in local description.", error_desc); |
| 1502 return false; | 1423 return false; |
| 1503 } | 1424 } |
| 1504 | 1425 |
| 1505 bool ret = SetBaseLocalContent_w(content, action, error_desc); | 1426 // CA_UPDATE is only used by the Harmony library to update send streams. |
| 1506 // Set local audio codecs (what we want to receive). | 1427 if (action == CA_UPDATE && |
| 1507 // TODO(whyuan): Change action != CA_UPDATE to !audio->partial() when partial | 1428 !UpdateLocalStreams_w(content->streams(), action, error_desc)) { |
| 1508 // is set properly. | 1429 SafeSetError("Failed to set local audio description send streams.", |
| 1509 if (action != CA_UPDATE || audio->has_codecs()) { | 1430 error_desc); |
| 1510 if (!media_channel()->SetRecvCodecs(audio->codecs())) { | 1431 return false; |
| 1511 SafeSetError("Failed to set audio receive codecs.", error_desc); | |
| 1512 ret = false; | |
| 1513 } | |
| 1514 } | 1432 } |
| 1515 | 1433 |
| 1516 // If everything worked, see if we can start receiving. | 1434 // Cache secure_required_ for belt and suspenders check on SendPacket |
| 1517 if (ret) { | 1435 set_secure_required(content->crypto_required() != CT_NONE); |
| 1518 std::vector<AudioCodec>::const_iterator it = audio->codecs().begin(); | 1436 if (!SetSrtp_w(content->cryptos(), action, CS_LOCAL, error_desc)) { |
| 1519 for (; it != audio->codecs().end(); ++it) { | 1437 SafeSetError("Failed to set local audio description SRTP.", error_desc); |
| 1520 bundle_filter()->AddPayloadType(it->id); | 1438 return false; |
| 1521 } | 1439 } |
| 1522 ChangeState(); | 1440 |
| 1441 if (!SetRtcpMux_w(content->rtcp_mux(), action, CS_LOCAL, error_desc)) { | |
| 1442 SafeSetError("Failed to set local audio description RTCP mux.", error_desc); | |
| 1443 return false; | |
| 1444 } | |
| 1445 | |
| 1446 AudioRecvParameters recv_params; | |
| 1447 recv_params.codecs = audio->codecs(); | |
| 1448 // TODO(pthatcher): See if we really need | |
| 1449 // rtp_header_extensions_set() and remove it if we don't. | |
| 1450 if (audio->rtp_header_extensions_set()) { | |
| 1451 recv_params.extensions = audio->rtp_header_extensions(); | |
| 1523 } else { | 1452 } else { |
| 1524 LOG(LS_WARNING) << "Failed to set local voice description"; | 1453 // Just maintain the last set of header extensions. |
|
pbos-webrtc
2015/07/12 15:56:08
Should this be stateful? Shouldn't all extensions
pthatcher1
2015/07/13 22:58:28
The existing behavior is that if !rtp_header_exten
| |
| 1454 recv_params.extensions = last_recv_params_.extensions; | |
| 1525 } | 1455 } |
| 1526 return ret; | 1456 |
| 1457 if (!media_channel()->SetRecvParameters(recv_params)) { | |
| 1458 SafeSetError("Failed to set local video description recv parameters.", | |
| 1459 error_desc); | |
| 1460 return false; | |
| 1461 } | |
| 1462 | |
| 1463 // TODO(pthatcher): Move local streams into AudioSendParameters, and | |
| 1464 // only give it to the media channel once we have a remote | |
| 1465 // description too (without a remote description, we won't be able | |
| 1466 // to send them anyway). | |
| 1467 if (!UpdateLocalStreams_w(audio->streams(), action, error_desc)) { | |
| 1468 SafeSetError("Failed to set local audio description streams.", error_desc); | |
| 1469 return false; | |
| 1470 } | |
| 1471 | |
| 1472 for (const AudioCodec& codec : audio->codecs()) { | |
| 1473 bundle_filter()->AddPayloadType(codec.id); | |
| 1474 } | |
| 1475 | |
| 1476 set_local_content_direction(content->direction()); | |
| 1477 ChangeState(); | |
| 1478 return true; | |
| 1527 } | 1479 } |
| 1528 | 1480 |
| 1529 bool VoiceChannel::SetRemoteContent_w(const MediaContentDescription* content, | 1481 bool VoiceChannel::SetRemoteContent_w(const MediaContentDescription* content, |
| 1530 ContentAction action, | 1482 ContentAction action, |
| 1531 std::string* error_desc) { | 1483 std::string* error_desc) { |
| 1532 ASSERT(worker_thread() == rtc::Thread::Current()); | 1484 ASSERT(worker_thread() == rtc::Thread::Current()); |
| 1533 LOG(LS_INFO) << "Setting remote voice description"; | 1485 LOG(LS_INFO) << "Setting remote voice description"; |
| 1534 | 1486 |
| 1535 const AudioContentDescription* audio = | 1487 const AudioContentDescription* audio = |
| 1536 static_cast<const AudioContentDescription*>(content); | 1488 static_cast<const AudioContentDescription*>(content); |
| 1537 ASSERT(audio != NULL); | 1489 ASSERT(audio != NULL); |
| 1538 if (!audio) { | 1490 if (!audio) { |
| 1539 SafeSetError("Can't find audio content in remote description.", error_desc); | 1491 SafeSetError("Can't find audio content in remote description.", error_desc); |
| 1540 return false; | 1492 return false; |
| 1541 } | 1493 } |
| 1542 | 1494 |
| 1543 bool ret = true; | 1495 // CA_UPDATE is only used by the Harmony library to update send |
|
pbos-webrtc
2015/07/12 15:56:08
This why we need to maintain last set of parameter
pthatcher1
2015/07/13 22:58:27
No, this is a separate thing, not related to the h
| |
| 1544 // Set remote video codecs (what the other side wants to receive). | 1496 // codecs and receive streams. |
| 1545 if (action != CA_UPDATE || audio->has_codecs()) { | 1497 if (action == CA_UPDATE) { |
| 1546 if (!media_channel()->SetSendCodecs(audio->codecs())) { | 1498 if (audio->has_codecs() && |
| 1547 SafeSetError("Failed to set audio send codecs.", error_desc); | 1499 !media_channel()->SetSendCodecs(audio->codecs())) { |
| 1548 ret = false; | 1500 SafeSetError("Failed to set remote audio description send codecs.", |
| 1501 error_desc); | |
| 1502 return false; | |
| 1549 } | 1503 } |
| 1504 if (!UpdateRemoteStreams_w(content->streams(), action, error_desc)) { | |
| 1505 SafeSetError("Failed to set remote audio description receive streams.", | |
| 1506 error_desc); | |
| 1507 return false; | |
| 1508 } | |
| 1509 return true; | |
| 1550 } | 1510 } |
| 1551 | 1511 |
| 1552 ret &= SetBaseRemoteContent_w(content, action, error_desc); | 1512 if (!SetSrtp_w(content->cryptos(), action, CS_REMOTE, error_desc)) { |
| 1553 | 1513 LOG(LS_WARNING) << "Failed to set remote video description SRTP"; |
| 1554 if (action != CA_UPDATE) { | 1514 return false; |
| 1555 // Tweak our audio processing settings, if needed. | |
| 1556 AudioOptions audio_options; | |
| 1557 if (!media_channel()->GetOptions(&audio_options)) { | |
| 1558 LOG(LS_WARNING) << "Can not set audio options from on remote content."; | |
| 1559 } else { | |
| 1560 if (audio->conference_mode()) { | |
| 1561 audio_options.conference_mode.Set(true); | |
| 1562 } | |
| 1563 if (audio->agc_minus_10db()) { | |
| 1564 audio_options.adjust_agc_delta.Set(kAgcMinus10db); | |
| 1565 } | |
| 1566 if (!media_channel()->SetOptions(audio_options)) { | |
| 1567 // Log an error on failure, but don't abort the call. | |
| 1568 LOG(LS_ERROR) << "Failed to set voice channel options"; | |
| 1569 } | |
| 1570 } | |
| 1571 } | 1515 } |
| 1572 | 1516 |
| 1573 // If everything worked, see if we can start sending. | 1517 if (!SetRtcpMux_w(content->rtcp_mux(), action, CS_REMOTE, error_desc)) { |
| 1574 if (ret) { | 1518 LOG(LS_WARNING) << "Failed to set remote video description RTCP mux"; |
| 1575 ChangeState(); | 1519 return false; |
| 1520 } | |
| 1521 | |
| 1522 AudioSendParameters send_params; | |
| 1523 send_params.codecs = audio->codecs(); | |
| 1524 // TODO(pthatcher): See if we really need | |
| 1525 // rtp_header_extensions_set() and remove it if we don't. | |
| 1526 if (audio->rtp_header_extensions_set()) { | |
| 1527 send_params.extensions = audio->rtp_header_extensions(); | |
| 1576 } else { | 1528 } else { |
| 1577 LOG(LS_WARNING) << "Failed to set remote voice description"; | 1529 // Just maintain the last set of header extensions. |
| 1530 send_params.extensions = last_send_params_.extensions; | |
|
pbos-webrtc
2015/07/12 15:56:08
Is this tied to CA_UPDATE? Otherwise no set extens
pthatcher1
2015/07/13 22:58:27
No, this has nothing to do with CA_UPDATE. Honest
| |
| 1578 } | 1531 } |
| 1579 return ret; | 1532 send_params.max_bandwidth_bps = audio->bandwidth(); |
| 1533 send_params.options = last_send_params_.options; | |
| 1534 if (audio->conference_mode()) { | |
| 1535 send_params.options.conference_mode.Set(true); | |
| 1536 } | |
| 1537 if (audio->agc_minus_10db()) { | |
| 1538 send_params.options.adjust_agc_delta.Set(kAgcMinus10db); | |
| 1539 } | |
| 1540 if (!media_channel()->SetSendParameters(send_params)) { | |
| 1541 SafeSetError("Failed to set remote audio description send parameters.", | |
| 1542 error_desc); | |
| 1543 return false; | |
| 1544 } | |
| 1545 last_send_params_ = send_params; | |
| 1546 | |
| 1547 // TODO(pthatcher): Move remote streams into AudioRecvParameters, | |
| 1548 // and only give it to the media channel once we have a local | |
| 1549 // description too (without a local description, we won't be able to | |
| 1550 // recv them anyway). | |
| 1551 if (!UpdateRemoteStreams_w(audio->streams(), action, error_desc)) { | |
| 1552 LOG(LS_WARNING) << "Failed to set remote audio description receive streams"; | |
| 1553 return false; | |
| 1554 } | |
| 1555 | |
| 1556 set_remote_content_direction(content->direction()); | |
| 1557 ChangeState(); | |
| 1558 return true; | |
| 1580 } | 1559 } |
| 1581 | 1560 |
| 1582 bool VoiceChannel::SetRingbackTone_w(const void* buf, int len) { | 1561 bool VoiceChannel::SetRingbackTone_w(const void* buf, int len) { |
| 1583 ASSERT(worker_thread() == rtc::Thread::Current()); | 1562 ASSERT(worker_thread() == rtc::Thread::Current()); |
| 1584 return media_channel()->SetRingbackTone(static_cast<const char*>(buf), len); | 1563 return media_channel()->SetRingbackTone(static_cast<const char*>(buf), len); |
| 1585 } | 1564 } |
| 1586 | 1565 |
| 1587 bool VoiceChannel::PlayRingbackTone_w(uint32 ssrc, bool play, bool loop) { | 1566 bool VoiceChannel::PlayRingbackTone_w(uint32 ssrc, bool play, bool loop) { |
| 1588 ASSERT(worker_thread() == rtc::Thread::Current()); | 1567 ASSERT(worker_thread() == rtc::Thread::Current()); |
| 1589 if (play) { | 1568 if (play) { |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1839 LOG(LS_INFO) << "Setting local video description"; | 1818 LOG(LS_INFO) << "Setting local video description"; |
| 1840 | 1819 |
| 1841 const VideoContentDescription* video = | 1820 const VideoContentDescription* video = |
| 1842 static_cast<const VideoContentDescription*>(content); | 1821 static_cast<const VideoContentDescription*>(content); |
| 1843 ASSERT(video != NULL); | 1822 ASSERT(video != NULL); |
| 1844 if (!video) { | 1823 if (!video) { |
| 1845 SafeSetError("Can't find video content in local description.", error_desc); | 1824 SafeSetError("Can't find video content in local description.", error_desc); |
| 1846 return false; | 1825 return false; |
| 1847 } | 1826 } |
| 1848 | 1827 |
| 1849 bool ret = SetBaseLocalContent_w(content, action, error_desc); | 1828 // CA_UPDATE is only used by the Harmony library to update send streams. |
| 1850 // Set local video codecs (what we want to receive). | 1829 if (action == CA_UPDATE && |
| 1851 if (action != CA_UPDATE || video->has_codecs()) { | 1830 !UpdateLocalStreams_w(content->streams(), action, error_desc)) { |
| 1852 if (!media_channel()->SetRecvCodecs(video->codecs())) { | 1831 SafeSetError("Failed to set local audio description send streams.", |
| 1853 SafeSetError("Failed to set video receive codecs.", error_desc); | 1832 error_desc); |
| 1854 ret = false; | 1833 return false; |
| 1855 } | |
| 1856 } | 1834 } |
| 1857 | 1835 |
| 1858 if (action != CA_UPDATE) { | 1836 // Cache secure_required_ for belt and suspenders check on SendPacket |
| 1859 VideoOptions video_options; | 1837 set_secure_required(content->crypto_required() != CT_NONE); |
| 1860 media_channel()->GetOptions(&video_options); | 1838 if (!SetSrtp_w(content->cryptos(), action, CS_LOCAL, error_desc)) { |
| 1861 video_options.buffered_mode_latency.Set(video->buffered_mode_latency()); | 1839 SafeSetError("Failed to set local video description SRTP.", error_desc); |
| 1862 | 1840 return false; |
| 1863 if (!media_channel()->SetOptions(video_options)) { | |
| 1864 // Log an error on failure, but don't abort the call. | |
| 1865 LOG(LS_ERROR) << "Failed to set video channel options"; | |
| 1866 } | |
| 1867 } | 1841 } |
| 1868 | 1842 |
| 1869 // If everything worked, see if we can start receiving. | 1843 if (!SetRtcpMux_w(content->rtcp_mux(), action, CS_LOCAL, error_desc)) { |
| 1870 if (ret) { | 1844 SafeSetError("Failed to set local video description RTCP mux.", error_desc); |
| 1871 std::vector<VideoCodec>::const_iterator it = video->codecs().begin(); | 1845 return false; |
| 1872 for (; it != video->codecs().end(); ++it) { | 1846 } |
| 1873 bundle_filter()->AddPayloadType(it->id); | 1847 |
| 1874 } | 1848 VideoRecvParameters recv_params; |
| 1875 ChangeState(); | 1849 recv_params.codecs = video->codecs(); |
| 1850 // TODO(pthatcher): See if we really need | |
| 1851 // rtp_header_extensions_set() and remove it if we don't. | |
| 1852 if (video->rtp_header_extensions_set()) { | |
| 1853 recv_params.extensions = video->rtp_header_extensions(); | |
|
pbos-webrtc
2015/07/12 15:56:08
Feels like I've read this code 4x times now, can s
pthatcher1
2015/07/13 22:58:27
Maybe. The code before was structured a lot to sh
| |
| 1876 } else { | 1854 } else { |
| 1877 LOG(LS_WARNING) << "Failed to set local video description"; | 1855 // Just maintain the last set of header extensions. |
| 1856 recv_params.extensions = last_recv_params_.extensions; | |
| 1878 } | 1857 } |
| 1879 return ret; | 1858 |
| 1859 if (!media_channel()->SetRecvParameters(recv_params)) { | |
| 1860 SafeSetError("Failed to set local video description recv parameters.", | |
| 1861 error_desc); | |
| 1862 return false; | |
| 1863 } | |
| 1864 last_recv_params_ = recv_params; | |
| 1865 | |
| 1866 // TODO(pthatcher): Move local streams into VideoSendParameters, and | |
| 1867 // only give it to the media channel once we have a remote | |
| 1868 // description too (without a remote description, we won't be able | |
| 1869 // to send them anyway). | |
| 1870 if (!UpdateLocalStreams_w(video->streams(), action, error_desc)) { | |
| 1871 SafeSetError("Failed to set local video description streams.", error_desc); | |
| 1872 return false; | |
| 1873 } | |
| 1874 | |
| 1875 for (const VideoCodec& codec : video->codecs()) { | |
| 1876 bundle_filter()->AddPayloadType(codec.id); | |
| 1877 } | |
| 1878 | |
| 1879 set_local_content_direction(content->direction()); | |
| 1880 ChangeState(); | |
| 1881 return true; | |
| 1880 } | 1882 } |
| 1881 | 1883 |
| 1882 bool VideoChannel::SetRemoteContent_w(const MediaContentDescription* content, | 1884 bool VideoChannel::SetRemoteContent_w(const MediaContentDescription* content, |
| 1883 ContentAction action, | 1885 ContentAction action, |
| 1884 std::string* error_desc) { | 1886 std::string* error_desc) { |
| 1885 ASSERT(worker_thread() == rtc::Thread::Current()); | 1887 ASSERT(worker_thread() == rtc::Thread::Current()); |
| 1886 LOG(LS_INFO) << "Setting remote video description"; | 1888 LOG(LS_INFO) << "Setting remote video description"; |
| 1887 | 1889 |
| 1888 const VideoContentDescription* video = | 1890 const VideoContentDescription* video = |
| 1889 static_cast<const VideoContentDescription*>(content); | 1891 static_cast<const VideoContentDescription*>(content); |
| 1890 ASSERT(video != NULL); | 1892 ASSERT(video != NULL); |
| 1891 if (!video) { | 1893 if (!video) { |
| 1892 SafeSetError("Can't find video content in remote description.", error_desc); | 1894 SafeSetError("Can't find video content in remote description.", error_desc); |
| 1893 return false; | 1895 return false; |
| 1894 } | 1896 } |
| 1895 | 1897 |
| 1896 bool ret = true; | 1898 // CA_UPDATE is only used by the Harmony library to update send |
|
pbos-webrtc
2015/07/12 15:56:08
Can some of this go in the base class?
pthatcher1
2015/07/13 22:58:27
SetSendCodecs can't very easily (which is why it w
| |
| 1897 // Set remote video codecs (what the other side wants to receive). | 1899 // codecs and receive streams. |
| 1898 if (action != CA_UPDATE || video->has_codecs()) { | 1900 if (action == CA_UPDATE) { |
| 1899 if (!media_channel()->SetSendCodecs(video->codecs())) { | 1901 if (video->has_codecs() && |
| 1900 SafeSetError("Failed to set video send codecs.", error_desc); | 1902 !media_channel()->SetSendCodecs(video->codecs())) { |
| 1901 ret = false; | 1903 SafeSetError("Failed to set remote video description send codecs.", |
| 1904 error_desc); | |
| 1905 return false; | |
| 1902 } | 1906 } |
| 1907 if (!UpdateRemoteStreams_w(content->streams(), action, error_desc)) { | |
| 1908 SafeSetError("Failed to set remote video description receive streams.", | |
| 1909 error_desc); | |
| 1910 return false; | |
| 1911 } | |
| 1912 return true; | |
| 1903 } | 1913 } |
| 1904 | 1914 |
| 1905 ret &= SetBaseRemoteContent_w(content, action, error_desc); | 1915 if (!SetRtcpMux_w(content->rtcp_mux(), action, CS_REMOTE, error_desc)) { |
| 1906 | 1916 LOG(LS_WARNING) << "Failed to set remote video description RTCP mux"; |
| 1907 if (action != CA_UPDATE) { | 1917 return false; |
| 1908 // Tweak our video processing settings, if needed. | |
| 1909 VideoOptions video_options; | |
| 1910 media_channel()->GetOptions(&video_options); | |
| 1911 if (video->conference_mode()) { | |
| 1912 video_options.conference_mode.Set(true); | |
| 1913 } | |
| 1914 video_options.buffered_mode_latency.Set(video->buffered_mode_latency()); | |
| 1915 | |
| 1916 if (!media_channel()->SetOptions(video_options)) { | |
| 1917 // Log an error on failure, but don't abort the call. | |
| 1918 LOG(LS_ERROR) << "Failed to set video channel options"; | |
| 1919 } | |
| 1920 } | 1918 } |
| 1921 | 1919 |
| 1922 // If everything worked, see if we can start sending. | 1920 if (!SetSrtp_w(content->cryptos(), action, CS_REMOTE, error_desc)) { |
| 1923 if (ret) { | 1921 LOG(LS_WARNING) << "Failed to set remote video description SRTP"; |
| 1924 ChangeState(); | 1922 return false; |
| 1923 } | |
| 1924 | |
| 1925 VideoSendParameters send_params; | |
| 1926 send_params.codecs = video->codecs(); | |
| 1927 // TODO(pthatcher): See if we really need | |
| 1928 // rtp_header_extensions_set() and remove it if we don't. | |
| 1929 if (video->rtp_header_extensions_set()) { | |
| 1930 send_params.extensions = video->rtp_header_extensions(); | |
| 1925 } else { | 1931 } else { |
| 1926 LOG(LS_WARNING) << "Failed to set remote video description"; | 1932 // Just maintain the last set of header extensions. |
| 1933 send_params.extensions = last_send_params_.extensions; | |
| 1927 } | 1934 } |
| 1928 return ret; | 1935 send_params.max_bandwidth_bps = video->bandwidth(); |
| 1936 send_params.options = last_send_params_.options; | |
| 1937 if (video->conference_mode()) { | |
| 1938 send_params.options.conference_mode.Set(true); | |
| 1939 } | |
| 1940 if (!media_channel()->SetSendParameters(send_params)) { | |
| 1941 SafeSetError("Failed to set remote video description send parameters.", | |
| 1942 error_desc); | |
| 1943 return false; | |
| 1944 } | |
| 1945 last_send_params_ = send_params; | |
| 1946 | |
| 1947 if (video->rtp_header_extensions_set()) { | |
| 1948 MaybeCacheRtpAbsSendTimeHeaderExtension(video->rtp_header_extensions()); | |
| 1949 } | |
| 1950 | |
| 1951 // TODO(pthatcher): Move remote streams into VideoRecvParameters, | |
| 1952 // and only give it to the media channel once we have a local | |
| 1953 // description too (without a local description, we won't be able to | |
| 1954 // recv them anyway). | |
| 1955 if (!UpdateRemoteStreams_w(video->streams(), action, error_desc)) { | |
| 1956 LOG(LS_WARNING) << "Failed to set remote video description receive streams"; | |
| 1957 return false; | |
| 1958 } | |
| 1959 | |
| 1960 set_remote_content_direction(content->direction()); | |
| 1961 ChangeState(); | |
| 1962 return true; | |
| 1929 } | 1963 } |
| 1930 | 1964 |
| 1931 bool VideoChannel::ApplyViewRequest_w(const ViewRequest& request) { | 1965 bool VideoChannel::ApplyViewRequest_w(const ViewRequest& request) { |
| 1932 bool ret = true; | 1966 bool ret = true; |
| 1933 // Set the send format for each of the local streams. If the view request | 1967 // Set the send format for each of the local streams. If the view request |
| 1934 // does not contain a local stream, set its send format to 0x0, which will | 1968 // does not contain a local stream, set its send format to 0x0, which will |
| 1935 // drop all frames. | 1969 // drop all frames. |
| 1936 for (std::vector<StreamParams>::const_iterator it = local_streams().begin(); | 1970 for (std::vector<StreamParams>::const_iterator it = local_streams().begin(); |
| 1937 it != local_streams().end(); ++it) { | 1971 it != local_streams().end(); ++it) { |
| 1938 VideoFormat format(0, 0, 0, cricket::FOURCC_I420); | 1972 VideoFormat format(0, 0, 0, cricket::FOURCC_I420); |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2223 LOG(LS_INFO) << "Setting local data description"; | 2257 LOG(LS_INFO) << "Setting local data description"; |
| 2224 | 2258 |
| 2225 const DataContentDescription* data = | 2259 const DataContentDescription* data = |
| 2226 static_cast<const DataContentDescription*>(content); | 2260 static_cast<const DataContentDescription*>(content); |
| 2227 ASSERT(data != NULL); | 2261 ASSERT(data != NULL); |
| 2228 if (!data) { | 2262 if (!data) { |
| 2229 SafeSetError("Can't find data content in local description.", error_desc); | 2263 SafeSetError("Can't find data content in local description.", error_desc); |
| 2230 return false; | 2264 return false; |
| 2231 } | 2265 } |
| 2232 | 2266 |
| 2233 bool ret = false; | 2267 // CA_UPDATE is only used by the Harmony library to update send streams. |
| 2268 if (action == CA_UPDATE && | |
|
pbos-webrtc
2015/07/12 15:56:08
Same things here, did I read this 4x times? Anythi
pthatcher1
2015/07/13 22:58:27
There's nothing to be done between local and remot
| |
| 2269 !UpdateLocalStreams_w(content->streams(), action, error_desc)) { | |
| 2270 SafeSetError("Failed to set local audio description send streams.", | |
| 2271 error_desc); | |
| 2272 return false; | |
| 2273 } | |
| 2274 | |
| 2234 if (!SetDataChannelTypeFromContent(data, error_desc)) { | 2275 if (!SetDataChannelTypeFromContent(data, error_desc)) { |
| 2235 return false; | 2276 return false; |
| 2236 } | 2277 } |
| 2237 | 2278 |
| 2238 if (data_channel_type_ == DCT_SCTP) { | 2279 if (data_channel_type_ == DCT_RTP) { |
| 2239 // SCTP data channels don't need the rest of the stuff. | 2280 // Cache secure_required_ for belt and suspenders check on SendPacket |
| 2240 ret = UpdateLocalStreams_w(data->streams(), action, error_desc); | 2281 set_secure_required(content->crypto_required() != CT_NONE); |
| 2241 if (ret) { | 2282 if (!SetSrtp_w(content->cryptos(), action, CS_LOCAL, error_desc)) { |
| 2242 set_local_content_direction(content->direction()); | 2283 SafeSetError("Failed to set local data description SRTP.", error_desc); |
| 2243 // As in SetRemoteContent_w, make sure we set the local SCTP port | 2284 return false; |
| 2244 // number as specified in our DataContentDescription. | |
| 2245 if (!media_channel()->SetRecvCodecs(data->codecs())) { | |
| 2246 SafeSetError("Failed to set data receive codecs.", error_desc); | |
| 2247 ret = false; | |
| 2248 } | |
| 2249 } | 2285 } |
| 2250 } else { | 2286 |
| 2251 ret = SetBaseLocalContent_w(content, action, error_desc); | 2287 if (!SetRtcpMux_w(content->rtcp_mux(), action, CS_LOCAL, error_desc)) { |
| 2252 if (action != CA_UPDATE || data->has_codecs()) { | 2288 SafeSetError("Failed to set local data description RTCP mux.", |
| 2253 if (!media_channel()->SetRecvCodecs(data->codecs())) { | 2289 error_desc); |
| 2254 SafeSetError("Failed to set data receive codecs.", error_desc); | 2290 return false; |
| 2255 ret = false; | 2291 } |
| 2256 } | 2292 |
| 2293 for (const DataCodec& codec : data->codecs()) { | |
| 2294 bundle_filter()->AddPayloadType(codec.id); | |
| 2257 } | 2295 } |
| 2258 } | 2296 } |
| 2259 | 2297 |
| 2260 // If everything worked, see if we can start receiving. | 2298 // FYI: We send the SCTP port number (not to be confused with the |
| 2261 if (ret) { | 2299 // underlying UDP port number) as a codec parameter. So even SCTP |
| 2262 std::vector<DataCodec>::const_iterator it = data->codecs().begin(); | 2300 // data channels need codecs. |
| 2263 for (; it != data->codecs().end(); ++it) { | 2301 DataRecvParameters recv_params; |
| 2264 bundle_filter()->AddPayloadType(it->id); | 2302 recv_params.codecs = data->codecs(); |
| 2265 } | 2303 if (!media_channel()->SetRecvParameters(recv_params)) { |
| 2266 ChangeState(); | 2304 SafeSetError("Failed to set remote data description recv parameters.", |
| 2267 } else { | 2305 error_desc); |
| 2268 LOG(LS_WARNING) << "Failed to set local data description"; | 2306 return false; |
| 2269 } | 2307 } |
| 2270 return ret; | 2308 |
| 2309 // TODO(pthatcher): Move local streams into DataSendParameters, and | |
| 2310 // only give it to the media channel once we have a remote | |
| 2311 // description too (without a remote description, we won't be able | |
| 2312 // to send them anyway). | |
| 2313 if (!UpdateLocalStreams_w(data->streams(), action, error_desc)) { | |
| 2314 SafeSetError("Failed to set local data description streams.", error_desc); | |
| 2315 return false; | |
| 2316 } | |
| 2317 | |
| 2318 set_local_content_direction(content->direction()); | |
| 2319 ChangeState(); | |
| 2320 return true; | |
| 2271 } | 2321 } |
| 2272 | 2322 |
| 2273 bool DataChannel::SetRemoteContent_w(const MediaContentDescription* content, | 2323 bool DataChannel::SetRemoteContent_w(const MediaContentDescription* content, |
| 2274 ContentAction action, | 2324 ContentAction action, |
| 2275 std::string* error_desc) { | 2325 std::string* error_desc) { |
| 2276 ASSERT(worker_thread() == rtc::Thread::Current()); | 2326 ASSERT(worker_thread() == rtc::Thread::Current()); |
| 2277 | 2327 |
| 2278 const DataContentDescription* data = | 2328 const DataContentDescription* data = |
| 2279 static_cast<const DataContentDescription*>(content); | 2329 static_cast<const DataContentDescription*>(content); |
| 2280 ASSERT(data != NULL); | 2330 ASSERT(data != NULL); |
| 2281 if (!data) { | 2331 if (!data) { |
| 2282 SafeSetError("Can't find data content in remote description.", error_desc); | 2332 SafeSetError("Can't find data content in remote description.", error_desc); |
| 2283 return false; | 2333 return false; |
| 2284 } | 2334 } |
| 2285 | 2335 |
| 2286 bool ret = true; | 2336 // CA_UPDATE is only used by the Harmony library to update send |
| 2337 // codecs and receive streams. | |
| 2338 if (action == CA_UPDATE) { | |
| 2339 if (data->has_codecs() && !media_channel()->SetSendCodecs(data->codecs())) { | |
| 2340 SafeSetError("Failed to set remote data description send codecs.", | |
| 2341 error_desc); | |
| 2342 return false; | |
| 2343 } | |
| 2344 if (!UpdateRemoteStreams_w(content->streams(), action, error_desc)) { | |
| 2345 SafeSetError("Failed to set remote data description receive streams.", | |
| 2346 error_desc); | |
| 2347 return false; | |
| 2348 } | |
| 2349 return true; | |
| 2350 } | |
| 2351 | |
| 2352 // If the remote data doesn't have codecs and isn't an update, it | |
| 2353 // must be empty, so ignore it. | |
| 2354 if (!data->has_codecs()) { | |
| 2355 return true; | |
| 2356 } | |
| 2357 | |
| 2287 if (!SetDataChannelTypeFromContent(data, error_desc)) { | 2358 if (!SetDataChannelTypeFromContent(data, error_desc)) { |
| 2288 return false; | 2359 return false; |
| 2289 } | 2360 } |
| 2290 | 2361 |
| 2291 if (data_channel_type_ == DCT_SCTP) { | 2362 LOG(LS_INFO) << "Setting remote data description"; |
| 2292 LOG(LS_INFO) << "Setting SCTP remote data description"; | 2363 if (data_channel_type_ == DCT_RTP) { |
| 2293 // SCTP data channels don't need the rest of the stuff. | 2364 // Set remote SRTP parameters (what the other side will encrypt with). |
| 2294 ret = UpdateRemoteStreams_w(content->streams(), action, error_desc); | 2365 if (!SetSrtp_w(content->cryptos(), action, CS_REMOTE, error_desc)) { |
| 2295 if (ret) { | 2366 SafeSetError("Failed to set remote data description SRTP", error_desc); |
| 2296 set_remote_content_direction(content->direction()); | 2367 return false; |
| 2297 // We send the SCTP port number (not to be confused with the underlying | |
| 2298 // UDP port number) as a codec parameter. Make sure it gets there. | |
| 2299 if (!media_channel()->SetSendCodecs(data->codecs())) { | |
| 2300 SafeSetError("Failed to set data send codecs.", error_desc); | |
| 2301 ret = false; | |
| 2302 } | |
| 2303 } | |
| 2304 } else { | |
| 2305 // If the remote data doesn't have codecs and isn't an update, it | |
| 2306 // must be empty, so ignore it. | |
| 2307 if (action != CA_UPDATE && !data->has_codecs()) { | |
| 2308 return true; | |
| 2309 } | |
| 2310 LOG(LS_INFO) << "Setting remote data description"; | |
| 2311 | |
| 2312 // Set remote video codecs (what the other side wants to receive). | |
| 2313 if (action != CA_UPDATE || data->has_codecs()) { | |
| 2314 if (!media_channel()->SetSendCodecs(data->codecs())) { | |
| 2315 SafeSetError("Failed to set data send codecs.", error_desc); | |
| 2316 ret = false; | |
| 2317 } | |
| 2318 } | 2368 } |
| 2319 | 2369 |
| 2320 if (ret) { | 2370 if (!SetRtcpMux_w(content->rtcp_mux(), action, CS_REMOTE, error_desc)) { |
| 2321 ret &= SetBaseRemoteContent_w(content, action, error_desc); | 2371 SafeSetError("Failed to set remote data description RTCP-mux", |
| 2322 } | 2372 error_desc); |
| 2323 | 2373 return false; |
| 2324 if (action != CA_UPDATE) { | |
| 2325 int bandwidth_bps = data->bandwidth(); | |
| 2326 if (!media_channel()->SetMaxSendBandwidth(bandwidth_bps)) { | |
| 2327 std::ostringstream desc; | |
| 2328 desc << "Failed to set max send bandwidth for data content."; | |
| 2329 SafeSetError(desc.str(), error_desc); | |
| 2330 ret = false; | |
| 2331 } | |
| 2332 } | 2374 } |
| 2333 } | 2375 } |
| 2334 | 2376 |
| 2335 // If everything worked, see if we can start sending. | 2377 DataSendParameters send_params; |
| 2336 if (ret) { | 2378 send_params.codecs = data->codecs(); |
| 2337 ChangeState(); | 2379 send_params.max_bandwidth_bps = data->bandwidth(); |
| 2338 } else { | 2380 if (!media_channel()->SetSendParameters(send_params)) { |
| 2339 LOG(LS_WARNING) << "Failed to set remote data description"; | 2381 SafeSetError("Failed to set remote data description send parameters.", |
| 2382 error_desc); | |
| 2383 return false; | |
| 2340 } | 2384 } |
| 2341 return ret; | 2385 |
| 2386 // TODO(pthatcher): Move remote streams into DataRecvParameters, | |
| 2387 // and only give it to the media channel once we have a local | |
| 2388 // description too (without a local description, we won't be able to | |
| 2389 // recv them anyway). | |
| 2390 if (!UpdateRemoteStreams_w(data->streams(), action, error_desc)) { | |
| 2391 SafeSetError("Failed to set remote data description streams.", | |
| 2392 error_desc); | |
| 2393 return false; | |
| 2394 } | |
| 2395 | |
| 2396 set_remote_content_direction(content->direction()); | |
| 2397 ChangeState(); | |
| 2398 return true; | |
| 2342 } | 2399 } |
| 2343 | 2400 |
| 2344 void DataChannel::ChangeState() { | 2401 void DataChannel::ChangeState() { |
| 2345 // Render incoming data if we're the active call, and we have the local | 2402 // Render incoming data if we're the active call, and we have the local |
| 2346 // content. We receive data on the default channel and multiplexed streams. | 2403 // content. We receive data on the default channel and multiplexed streams. |
| 2347 bool recv = IsReadyToReceive(); | 2404 bool recv = IsReadyToReceive(); |
| 2348 if (!media_channel()->SetReceive(recv)) { | 2405 if (!media_channel()->SetReceive(recv)) { |
| 2349 LOG(LS_ERROR) << "Failed to SetReceive on data channel"; | 2406 LOG(LS_ERROR) << "Failed to SetReceive on data channel"; |
| 2350 } | 2407 } |
| 2351 | 2408 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2479 return (data_channel_type_ == DCT_RTP); | 2536 return (data_channel_type_ == DCT_RTP); |
| 2480 } | 2537 } |
| 2481 | 2538 |
| 2482 void DataChannel::OnStreamClosedRemotely(uint32 sid) { | 2539 void DataChannel::OnStreamClosedRemotely(uint32 sid) { |
| 2483 rtc::TypedMessageData<uint32>* message = | 2540 rtc::TypedMessageData<uint32>* message = |
| 2484 new rtc::TypedMessageData<uint32>(sid); | 2541 new rtc::TypedMessageData<uint32>(sid); |
| 2485 signaling_thread()->Post(this, MSG_STREAMCLOSEDREMOTELY, message); | 2542 signaling_thread()->Post(this, MSG_STREAMCLOSEDREMOTELY, message); |
| 2486 } | 2543 } |
| 2487 | 2544 |
| 2488 } // namespace cricket | 2545 } // namespace cricket |
| OLD | NEW |