OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 894 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
905 // RTCP is enabled by default. | 905 // RTCP is enabled by default. |
906 _rtpRtcpModule->SetRTCPStatus(RtcpMode::kCompound); | 906 _rtpRtcpModule->SetRTCPStatus(RtcpMode::kCompound); |
907 // --- Register all permanent callbacks | 907 // --- Register all permanent callbacks |
908 if (audio_coding_->RegisterTransportCallback(this) == -1) { | 908 if (audio_coding_->RegisterTransportCallback(this) == -1) { |
909 _engineStatisticsPtr->SetLastError( | 909 _engineStatisticsPtr->SetLastError( |
910 VE_CANNOT_INIT_CHANNEL, kTraceError, | 910 VE_CANNOT_INIT_CHANNEL, kTraceError, |
911 "Channel::Init() callbacks not registered"); | 911 "Channel::Init() callbacks not registered"); |
912 return -1; | 912 return -1; |
913 } | 913 } |
914 | 914 |
| 915 // TODO(solenberg): Remove? |
915 // Register a default set of send codecs. | 916 // Register a default set of send codecs. |
916 const int nSupportedCodecs = AudioCodingModule::NumberOfCodecs(); | 917 const int nSupportedCodecs = AudioCodingModule::NumberOfCodecs(); |
917 for (int idx = 0; idx < nSupportedCodecs; idx++) { | 918 for (int idx = 0; idx < nSupportedCodecs; idx++) { |
918 CodecInst codec; | 919 CodecInst codec; |
919 RTC_CHECK_EQ(0, audio_coding_->Codec(idx, &codec)); | 920 RTC_CHECK_EQ(0, audio_coding_->Codec(idx, &codec)); |
920 | 921 |
921 // Ensure that PCMU is used as default send codec. | 922 // Ensure that PCMU is used as default send codec. |
922 if (STR_CASE_CMP(codec.plname, "PCMU") == 0 && codec.channels == 1) { | 923 if (STR_CASE_CMP(codec.plname, "PCMU") == 0 && codec.channels == 1) { |
923 SetSendCodec(codec); | 924 SetSendCodec(codec); |
924 } | 925 } |
(...skipping 16 matching lines...) Expand all Loading... |
941 "Channel::Init() failed to register CN (%d/%d) " | 942 "Channel::Init() failed to register CN (%d/%d) " |
942 "correctly - 1", | 943 "correctly - 1", |
943 codec.pltype, codec.plfreq); | 944 codec.pltype, codec.plfreq); |
944 } | 945 } |
945 } | 946 } |
946 } | 947 } |
947 | 948 |
948 return 0; | 949 return 0; |
949 } | 950 } |
950 | 951 |
951 void Channel::RegisterLegacyReceiveCodecs() { | |
952 const int nSupportedCodecs = AudioCodingModule::NumberOfCodecs(); | |
953 for (int idx = 0; idx < nSupportedCodecs; idx++) { | |
954 CodecInst codec; | |
955 RTC_CHECK_EQ(0, audio_coding_->Codec(idx, &codec)); | |
956 | |
957 // Open up the RTP/RTCP receiver for all supported codecs | |
958 if (rtp_receiver_->RegisterReceivePayload(codec) == -1) { | |
959 WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId), | |
960 "Channel::Init() unable to register %s " | |
961 "(%d/%d/%" PRIuS "/%d) to RTP/RTCP receiver", | |
962 codec.plname, codec.pltype, codec.plfreq, codec.channels, | |
963 codec.rate); | |
964 } else { | |
965 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), | |
966 "Channel::Init() %s (%d/%d/%" PRIuS | |
967 "/%d) has been " | |
968 "added to the RTP/RTCP receiver", | |
969 codec.plname, codec.pltype, codec.plfreq, codec.channels, | |
970 codec.rate); | |
971 } | |
972 | |
973 // Register default PT for 'telephone-event' | |
974 if (STR_CASE_CMP(codec.plname, "telephone-event") == 0) { | |
975 if (!audio_coding_->RegisterReceiveCodec(codec.pltype, | |
976 CodecInstToSdp(codec))) { | |
977 WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId), | |
978 "Channel::Init() failed to register inband " | |
979 "'telephone-event' (%d/%d) correctly", | |
980 codec.pltype, codec.plfreq); | |
981 } | |
982 } | |
983 | |
984 if (STR_CASE_CMP(codec.plname, "CN") == 0) { | |
985 if (!audio_coding_->RegisterReceiveCodec(codec.pltype, | |
986 CodecInstToSdp(codec))) { | |
987 WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId), | |
988 "Channel::Init() failed to register CN (%d/%d) " | |
989 "correctly - 1", | |
990 codec.pltype, codec.plfreq); | |
991 } | |
992 } | |
993 } | |
994 } | |
995 | |
996 void Channel::Terminate() { | 952 void Channel::Terminate() { |
997 RTC_DCHECK(construction_thread_.CalledOnValidThread()); | 953 RTC_DCHECK(construction_thread_.CalledOnValidThread()); |
998 // Must be called on the same thread as Init(). | 954 // Must be called on the same thread as Init(). |
999 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_instanceId, _channelId), | 955 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_instanceId, _channelId), |
1000 "Channel::Terminate"); | 956 "Channel::Terminate"); |
1001 | 957 |
1002 rtp_receive_statistics_->RegisterRtcpStatisticsCallback(NULL); | 958 rtp_receive_statistics_->RegisterRtcpStatisticsCallback(NULL); |
1003 | 959 |
1004 StopSend(); | 960 StopSend(); |
1005 StopPlayout(); | 961 StopPlayout(); |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1332 void Channel::OnUplinkPacketLossRate(float packet_loss_rate) { | 1288 void Channel::OnUplinkPacketLossRate(float packet_loss_rate) { |
1333 if (use_twcc_plr_for_ana_) | 1289 if (use_twcc_plr_for_ana_) |
1334 return; | 1290 return; |
1335 audio_coding_->ModifyEncoder([&](std::unique_ptr<AudioEncoder>* encoder) { | 1291 audio_coding_->ModifyEncoder([&](std::unique_ptr<AudioEncoder>* encoder) { |
1336 if (*encoder) { | 1292 if (*encoder) { |
1337 (*encoder)->OnReceivedUplinkPacketLossFraction(packet_loss_rate); | 1293 (*encoder)->OnReceivedUplinkPacketLossFraction(packet_loss_rate); |
1338 } | 1294 } |
1339 }); | 1295 }); |
1340 } | 1296 } |
1341 | 1297 |
1342 int32_t Channel::SetVADStatus(bool enableVAD, | |
1343 ACMVADMode mode, | |
1344 bool disableDTX) { | |
1345 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), | |
1346 "Channel::SetVADStatus(mode=%d)", mode); | |
1347 RTC_DCHECK(!(disableDTX && enableVAD)); // disableDTX mode is deprecated. | |
1348 if (!codec_manager_.SetVAD(enableVAD, mode) || | |
1349 !codec_manager_.MakeEncoder(&rent_a_codec_, audio_coding_.get())) { | |
1350 _engineStatisticsPtr->SetLastError(VE_AUDIO_CODING_MODULE_ERROR, | |
1351 kTraceError, | |
1352 "SetVADStatus() failed to set VAD"); | |
1353 return -1; | |
1354 } | |
1355 return 0; | |
1356 } | |
1357 | |
1358 int32_t Channel::GetVADStatus(bool& enabledVAD, | |
1359 ACMVADMode& mode, | |
1360 bool& disabledDTX) { | |
1361 const auto* params = codec_manager_.GetStackParams(); | |
1362 enabledVAD = params->use_cng; | |
1363 mode = params->vad_mode; | |
1364 disabledDTX = !params->use_cng; | |
1365 return 0; | |
1366 } | |
1367 | |
1368 void Channel::SetReceiveCodecs(const std::map<int, SdpAudioFormat>& codecs) { | 1298 void Channel::SetReceiveCodecs(const std::map<int, SdpAudioFormat>& codecs) { |
1369 rtp_payload_registry_->SetAudioReceivePayloads(codecs); | 1299 rtp_payload_registry_->SetAudioReceivePayloads(codecs); |
1370 audio_coding_->SetReceiveCodecs(codecs); | 1300 audio_coding_->SetReceiveCodecs(codecs); |
1371 } | 1301 } |
1372 | 1302 |
1373 int32_t Channel::SetRecPayloadType(const CodecInst& codec) { | |
1374 return SetRecPayloadType(codec.pltype, CodecInstToSdp(codec)); | |
1375 } | |
1376 | |
1377 int32_t Channel::SetRecPayloadType(int payload_type, | |
1378 const SdpAudioFormat& format) { | |
1379 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), | |
1380 "Channel::SetRecPayloadType()"); | |
1381 | |
1382 if (channel_state_.Get().playing) { | |
1383 _engineStatisticsPtr->SetLastError( | |
1384 VE_ALREADY_PLAYING, kTraceError, | |
1385 "SetRecPayloadType() unable to set PT while playing"); | |
1386 return -1; | |
1387 } | |
1388 | |
1389 const CodecInst codec = SdpToCodecInst(payload_type, format); | |
1390 | |
1391 if (payload_type == -1) { | |
1392 // De-register the selected codec (RTP/RTCP module and ACM) | |
1393 | |
1394 int8_t pltype(-1); | |
1395 CodecInst rxCodec = codec; | |
1396 | |
1397 // Get payload type for the given codec | |
1398 rtp_payload_registry_->ReceivePayloadType(rxCodec, &pltype); | |
1399 rxCodec.pltype = pltype; | |
1400 | |
1401 if (rtp_receiver_->DeRegisterReceivePayload(pltype) != 0) { | |
1402 _engineStatisticsPtr->SetLastError( | |
1403 VE_RTP_RTCP_MODULE_ERROR, kTraceError, | |
1404 "SetRecPayloadType() RTP/RTCP-module deregistration " | |
1405 "failed"); | |
1406 return -1; | |
1407 } | |
1408 if (audio_coding_->UnregisterReceiveCodec(rxCodec.pltype) != 0) { | |
1409 _engineStatisticsPtr->SetLastError( | |
1410 VE_AUDIO_CODING_MODULE_ERROR, kTraceError, | |
1411 "SetRecPayloadType() ACM deregistration failed - 1"); | |
1412 return -1; | |
1413 } | |
1414 return 0; | |
1415 } | |
1416 | |
1417 if (rtp_receiver_->RegisterReceivePayload(codec) != 0) { | |
1418 // First attempt to register failed => de-register and try again | |
1419 // TODO(kwiberg): Retrying is probably not necessary, since | |
1420 // AcmReceiver::AddCodec also retries. | |
1421 rtp_receiver_->DeRegisterReceivePayload(codec.pltype); | |
1422 if (rtp_receiver_->RegisterReceivePayload(codec) != 0) { | |
1423 _engineStatisticsPtr->SetLastError( | |
1424 VE_RTP_RTCP_MODULE_ERROR, kTraceError, | |
1425 "SetRecPayloadType() RTP/RTCP-module registration failed"); | |
1426 return -1; | |
1427 } | |
1428 } | |
1429 if (!audio_coding_->RegisterReceiveCodec(payload_type, format)) { | |
1430 audio_coding_->UnregisterReceiveCodec(payload_type); | |
1431 if (!audio_coding_->RegisterReceiveCodec(payload_type, format)) { | |
1432 _engineStatisticsPtr->SetLastError( | |
1433 VE_AUDIO_CODING_MODULE_ERROR, kTraceError, | |
1434 "SetRecPayloadType() ACM registration failed - 1"); | |
1435 return -1; | |
1436 } | |
1437 } | |
1438 return 0; | |
1439 } | |
1440 | |
1441 int32_t Channel::GetRecPayloadType(CodecInst& codec) { | |
1442 int8_t payloadType(-1); | |
1443 if (rtp_payload_registry_->ReceivePayloadType(codec, &payloadType) != 0) { | |
1444 _engineStatisticsPtr->SetLastError( | |
1445 VE_RTP_RTCP_MODULE_ERROR, kTraceWarning, | |
1446 "GetRecPayloadType() failed to retrieve RX payload type"); | |
1447 return -1; | |
1448 } | |
1449 codec.pltype = payloadType; | |
1450 return 0; | |
1451 } | |
1452 | |
1453 int32_t Channel::SetSendCNPayloadType(int type, PayloadFrequencies frequency) { | |
1454 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), | |
1455 "Channel::SetSendCNPayloadType()"); | |
1456 | |
1457 CodecInst codec; | |
1458 int32_t samplingFreqHz(-1); | |
1459 const size_t kMono = 1; | |
1460 if (frequency == kFreq32000Hz) | |
1461 samplingFreqHz = 32000; | |
1462 else if (frequency == kFreq16000Hz) | |
1463 samplingFreqHz = 16000; | |
1464 | |
1465 if (audio_coding_->Codec("CN", &codec, samplingFreqHz, kMono) == -1) { | |
1466 _engineStatisticsPtr->SetLastError( | |
1467 VE_AUDIO_CODING_MODULE_ERROR, kTraceError, | |
1468 "SetSendCNPayloadType() failed to retrieve default CN codec " | |
1469 "settings"); | |
1470 return -1; | |
1471 } | |
1472 | |
1473 // Modify the payload type (must be set to dynamic range) | |
1474 codec.pltype = type; | |
1475 | |
1476 if (!codec_manager_.RegisterEncoder(codec) || | |
1477 !codec_manager_.MakeEncoder(&rent_a_codec_, audio_coding_.get())) { | |
1478 _engineStatisticsPtr->SetLastError( | |
1479 VE_AUDIO_CODING_MODULE_ERROR, kTraceError, | |
1480 "SetSendCNPayloadType() failed to register CN to ACM"); | |
1481 return -1; | |
1482 } | |
1483 | |
1484 if (_rtpRtcpModule->RegisterSendPayload(codec) != 0) { | |
1485 _rtpRtcpModule->DeRegisterSendPayload(codec.pltype); | |
1486 if (_rtpRtcpModule->RegisterSendPayload(codec) != 0) { | |
1487 _engineStatisticsPtr->SetLastError( | |
1488 VE_RTP_RTCP_MODULE_ERROR, kTraceError, | |
1489 "SetSendCNPayloadType() failed to register CN to RTP/RTCP " | |
1490 "module"); | |
1491 return -1; | |
1492 } | |
1493 } | |
1494 return 0; | |
1495 } | |
1496 | |
1497 int Channel::SetOpusMaxPlaybackRate(int frequency_hz) { | |
1498 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), | |
1499 "Channel::SetOpusMaxPlaybackRate()"); | |
1500 | |
1501 if (audio_coding_->SetOpusMaxPlaybackRate(frequency_hz) != 0) { | |
1502 _engineStatisticsPtr->SetLastError( | |
1503 VE_AUDIO_CODING_MODULE_ERROR, kTraceError, | |
1504 "SetOpusMaxPlaybackRate() failed to set maximum playback rate"); | |
1505 return -1; | |
1506 } | |
1507 return 0; | |
1508 } | |
1509 | |
1510 int Channel::SetOpusDtx(bool enable_dtx) { | |
1511 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), | |
1512 "Channel::SetOpusDtx(%d)", enable_dtx); | |
1513 int ret = enable_dtx ? audio_coding_->EnableOpusDtx() | |
1514 : audio_coding_->DisableOpusDtx(); | |
1515 if (ret != 0) { | |
1516 _engineStatisticsPtr->SetLastError(VE_AUDIO_CODING_MODULE_ERROR, | |
1517 kTraceError, "SetOpusDtx() failed"); | |
1518 return -1; | |
1519 } | |
1520 return 0; | |
1521 } | |
1522 | |
1523 int Channel::GetOpusDtx(bool* enabled) { | |
1524 int success = -1; | |
1525 audio_coding_->QueryEncoder([&](AudioEncoder const* encoder) { | |
1526 if (encoder) { | |
1527 *enabled = encoder->GetDtx(); | |
1528 success = 0; | |
1529 } | |
1530 }); | |
1531 return success; | |
1532 } | |
1533 | |
1534 bool Channel::EnableAudioNetworkAdaptor(const std::string& config_string) { | 1303 bool Channel::EnableAudioNetworkAdaptor(const std::string& config_string) { |
1535 bool success = false; | 1304 bool success = false; |
1536 audio_coding_->ModifyEncoder([&](std::unique_ptr<AudioEncoder>* encoder) { | 1305 audio_coding_->ModifyEncoder([&](std::unique_ptr<AudioEncoder>* encoder) { |
1537 if (*encoder) { | 1306 if (*encoder) { |
1538 success = (*encoder)->EnableAudioNetworkAdaptor(config_string, | 1307 success = (*encoder)->EnableAudioNetworkAdaptor(config_string, |
1539 event_log_proxy_.get()); | 1308 event_log_proxy_.get()); |
1540 } | 1309 } |
1541 }); | 1310 }); |
1542 return success; | 1311 return success; |
1543 } | 1312 } |
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2064 stats.packetsReceived = packetsReceived; | 1833 stats.packetsReceived = packetsReceived; |
2065 | 1834 |
2066 // --- Timestamps | 1835 // --- Timestamps |
2067 { | 1836 { |
2068 rtc::CritScope lock(&ts_stats_lock_); | 1837 rtc::CritScope lock(&ts_stats_lock_); |
2069 stats.capture_start_ntp_time_ms_ = capture_start_ntp_time_ms_; | 1838 stats.capture_start_ntp_time_ms_ = capture_start_ntp_time_ms_; |
2070 } | 1839 } |
2071 return 0; | 1840 return 0; |
2072 } | 1841 } |
2073 | 1842 |
2074 int Channel::SetCodecFECStatus(bool enable) { | |
2075 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), | |
2076 "Channel::SetCodecFECStatus()"); | |
2077 | |
2078 if (!codec_manager_.SetCodecFEC(enable) || | |
2079 !codec_manager_.MakeEncoder(&rent_a_codec_, audio_coding_.get())) { | |
2080 _engineStatisticsPtr->SetLastError( | |
2081 VE_AUDIO_CODING_MODULE_ERROR, kTraceError, | |
2082 "SetCodecFECStatus() failed to set FEC state"); | |
2083 return -1; | |
2084 } | |
2085 return 0; | |
2086 } | |
2087 | |
2088 bool Channel::GetCodecFECStatus() { | |
2089 return codec_manager_.GetStackParams()->use_codec_fec; | |
2090 } | |
2091 | |
2092 void Channel::SetNACKStatus(bool enable, int maxNumberOfPackets) { | 1843 void Channel::SetNACKStatus(bool enable, int maxNumberOfPackets) { |
2093 // None of these functions can fail. | 1844 // None of these functions can fail. |
2094 // If pacing is enabled we always store packets. | 1845 // If pacing is enabled we always store packets. |
2095 if (!pacing_enabled_) | 1846 if (!pacing_enabled_) |
2096 _rtpRtcpModule->SetStorePacketsStatus(enable, maxNumberOfPackets); | 1847 _rtpRtcpModule->SetStorePacketsStatus(enable, maxNumberOfPackets); |
2097 rtp_receive_statistics_->SetMaxReorderingThreshold(maxNumberOfPackets); | 1848 rtp_receive_statistics_->SetMaxReorderingThreshold(maxNumberOfPackets); |
2098 if (enable) | 1849 if (enable) |
2099 audio_coding_->EnableNack(maxNumberOfPackets); | 1850 audio_coding_->EnableNack(maxNumberOfPackets); |
2100 else | 1851 else |
2101 audio_coding_->DisableNack(); | 1852 audio_coding_->DisableNack(); |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2430 int64_t min_rtt = 0; | 2181 int64_t min_rtt = 0; |
2431 if (_rtpRtcpModule->RTT(remoteSSRC, &rtt, &avg_rtt, &min_rtt, &max_rtt) != | 2182 if (_rtpRtcpModule->RTT(remoteSSRC, &rtt, &avg_rtt, &min_rtt, &max_rtt) != |
2432 0) { | 2183 0) { |
2433 return 0; | 2184 return 0; |
2434 } | 2185 } |
2435 return rtt; | 2186 return rtt; |
2436 } | 2187 } |
2437 | 2188 |
2438 } // namespace voe | 2189 } // namespace voe |
2439 } // namespace webrtc | 2190 } // namespace webrtc |
OLD | NEW |