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 1267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1278 "SetSendCodec() failed to set audio packet size"); | 1278 "SetSendCodec() failed to set audio packet size"); |
1279 return -1; | 1279 return -1; |
1280 } | 1280 } |
1281 | 1281 |
1282 return 0; | 1282 return 0; |
1283 } | 1283 } |
1284 | 1284 |
1285 void Channel::SetBitRate(int bitrate_bps) { | 1285 void Channel::SetBitRate(int bitrate_bps) { |
1286 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), | 1286 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
1287 "Channel::SetBitRate(bitrate_bps=%d)", bitrate_bps); | 1287 "Channel::SetBitRate(bitrate_bps=%d)", bitrate_bps); |
1288 audio_coding_->SetBitRate(bitrate_bps); | 1288 audio_coding_->ModifyEncoder([&](std::unique_ptr<AudioEncoder>* encoder) { |
1289 if (!*encoder) { | |
1290 // There is no existing encoder. | |
1291 return; | |
1292 } | |
1293 (*encoder)->OnReceivedTargetAudioBitrate(bitrate_bps); | |
1294 }); | |
kwiberg-webrtc
2016/10/06 09:46:13
You can probably just do
if (*encoder) {
(*
minyue-webrtc
2016/10/11 09:00:22
Done.
| |
1289 retransmission_rate_limiter_->SetMaxRate(bitrate_bps); | 1295 retransmission_rate_limiter_->SetMaxRate(bitrate_bps); |
1290 } | 1296 } |
1291 | 1297 |
1292 void Channel::OnIncomingFractionLoss(int fraction_lost) { | 1298 void Channel::OnIncomingFractionLoss(int fraction_lost) { |
1293 network_predictor_->UpdatePacketLossRate(fraction_lost); | 1299 network_predictor_->UpdatePacketLossRate(fraction_lost); |
1294 uint8_t average_fraction_loss = network_predictor_->GetLossRate(); | 1300 uint8_t average_fraction_loss = network_predictor_->GetLossRate(); |
1295 | 1301 audio_coding_->ModifyEncoder([&](std::unique_ptr<AudioEncoder>* encoder) { |
1296 // Normalizes rate to 0 - 100. | 1302 if (!*encoder) { |
1297 if (audio_coding_->SetPacketLossRate(100 * average_fraction_loss / 255) != | 1303 // There is no existing encoder. |
1298 0) { | 1304 return; |
1299 assert(false); // This should not happen. | 1305 } |
1300 } | 1306 (*encoder)->OnReceivedUplinkPacketLossFraction(average_fraction_loss / |
1307 255.0f); | |
1308 }); | |
1301 } | 1309 } |
1302 | 1310 |
1303 int32_t Channel::SetVADStatus(bool enableVAD, | 1311 int32_t Channel::SetVADStatus(bool enableVAD, |
1304 ACMVADMode mode, | 1312 ACMVADMode mode, |
1305 bool disableDTX) { | 1313 bool disableDTX) { |
1306 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), | 1314 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
1307 "Channel::SetVADStatus(mode=%d)", mode); | 1315 "Channel::SetVADStatus(mode=%d)", mode); |
1308 RTC_DCHECK(!(disableDTX && enableVAD)); // disableDTX mode is deprecated. | 1316 RTC_DCHECK(!(disableDTX && enableVAD)); // disableDTX mode is deprecated. |
1309 if (!codec_manager_.SetVAD(enableVAD, mode) || | 1317 if (!codec_manager_.SetVAD(enableVAD, mode) || |
1310 !codec_manager_.MakeEncoder(&rent_a_codec_, audio_coding_.get())) { | 1318 !codec_manager_.MakeEncoder(&rent_a_codec_, audio_coding_.get())) { |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1487 int success = -1; | 1495 int success = -1; |
1488 audio_coding_->QueryEncoder([&](AudioEncoder const* encoder) { | 1496 audio_coding_->QueryEncoder([&](AudioEncoder const* encoder) { |
1489 if (encoder) { | 1497 if (encoder) { |
1490 *enabled = encoder->GetDtx(); | 1498 *enabled = encoder->GetDtx(); |
1491 success = 0; | 1499 success = 0; |
1492 } | 1500 } |
1493 }); | 1501 }); |
1494 return success; | 1502 return success; |
1495 } | 1503 } |
1496 | 1504 |
1505 bool Channel::EnableAudioNetworkAdaptor(const std::string& config_string) { | |
1506 bool success = false; | |
1507 audio_coding_->ModifyEncoder([&](std::unique_ptr<AudioEncoder>* encoder) { | |
1508 if (!*encoder) { | |
1509 // There is no existing encoder. | |
1510 return; | |
1511 } | |
1512 success = (*encoder)->EnableAudioNetworkAdaptor(config_string, | |
1513 Clock::GetRealTimeClock()); | |
1514 }); | |
1515 return success; | |
1516 } | |
1517 | |
1518 void Channel::DisableAudioNetworkAdaptor() { | |
1519 audio_coding_->ModifyEncoder([&](std::unique_ptr<AudioEncoder>* encoder) { | |
1520 if (!*encoder) { | |
1521 // There is no existing encoder. | |
1522 return; | |
1523 } | |
1524 (*encoder)->DisableAudioNetworkAdaptor(); | |
1525 }); | |
1526 } | |
1527 | |
1528 void Channel::SetReceiverFrameLengthRange(int min_frame_length_ms, | |
1529 int max_frame_length_ms) { | |
1530 audio_coding_->ModifyEncoder([&](std::unique_ptr<AudioEncoder>* encoder) { | |
1531 if (!*encoder) { | |
1532 // There is no existing encoder. | |
1533 return; | |
1534 } | |
1535 (*encoder)->SetReceiverFrameLengthRange(min_frame_length_ms, | |
1536 max_frame_length_ms); | |
1537 }); | |
1538 } | |
1539 | |
1497 int32_t Channel::RegisterExternalTransport(Transport* transport) { | 1540 int32_t Channel::RegisterExternalTransport(Transport* transport) { |
1498 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), | 1541 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
1499 "Channel::RegisterExternalTransport()"); | 1542 "Channel::RegisterExternalTransport()"); |
1500 | 1543 |
1501 rtc::CritScope cs(&_callbackCritSect); | 1544 rtc::CritScope cs(&_callbackCritSect); |
1502 if (_externalTransport) { | 1545 if (_externalTransport) { |
1503 _engineStatisticsPtr->SetLastError( | 1546 _engineStatisticsPtr->SetLastError( |
1504 VE_INVALID_OPERATION, kTraceError, | 1547 VE_INVALID_OPERATION, kTraceError, |
1505 "RegisterExternalTransport() external transport already enabled"); | 1548 "RegisterExternalTransport() external transport already enabled"); |
1506 return -1; | 1549 return -1; |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1647 } | 1690 } |
1648 | 1691 |
1649 int64_t nack_window_ms = rtt; | 1692 int64_t nack_window_ms = rtt; |
1650 if (nack_window_ms < kMinRetransmissionWindowMs) { | 1693 if (nack_window_ms < kMinRetransmissionWindowMs) { |
1651 nack_window_ms = kMinRetransmissionWindowMs; | 1694 nack_window_ms = kMinRetransmissionWindowMs; |
1652 } else if (nack_window_ms > kMaxRetransmissionWindowMs) { | 1695 } else if (nack_window_ms > kMaxRetransmissionWindowMs) { |
1653 nack_window_ms = kMaxRetransmissionWindowMs; | 1696 nack_window_ms = kMaxRetransmissionWindowMs; |
1654 } | 1697 } |
1655 retransmission_rate_limiter_->SetWindowSize(nack_window_ms); | 1698 retransmission_rate_limiter_->SetWindowSize(nack_window_ms); |
1656 | 1699 |
1700 // Invoke audio encoders OnReceivedRtt(). | |
1701 audio_coding_->ModifyEncoder([&](std::unique_ptr<AudioEncoder>* encoder) { | |
1702 if (!*encoder) { | |
1703 // There is no existing encoder. | |
1704 return; | |
1705 } | |
1706 (*encoder)->OnReceivedRtt(rtt); | |
1707 }); | |
1708 | |
1657 uint32_t ntp_secs = 0; | 1709 uint32_t ntp_secs = 0; |
1658 uint32_t ntp_frac = 0; | 1710 uint32_t ntp_frac = 0; |
1659 uint32_t rtp_timestamp = 0; | 1711 uint32_t rtp_timestamp = 0; |
1660 if (0 != | 1712 if (0 != |
1661 _rtpRtcpModule->RemoteNTP(&ntp_secs, &ntp_frac, NULL, NULL, | 1713 _rtpRtcpModule->RemoteNTP(&ntp_secs, &ntp_frac, NULL, NULL, |
1662 &rtp_timestamp)) { | 1714 &rtp_timestamp)) { |
1663 // Waiting for RTCP. | 1715 // Waiting for RTCP. |
1664 return 0; | 1716 return 0; |
1665 } | 1717 } |
1666 | 1718 |
(...skipping 1538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3205 int64_t min_rtt = 0; | 3257 int64_t min_rtt = 0; |
3206 if (_rtpRtcpModule->RTT(remoteSSRC, &rtt, &avg_rtt, &min_rtt, &max_rtt) != | 3258 if (_rtpRtcpModule->RTT(remoteSSRC, &rtt, &avg_rtt, &min_rtt, &max_rtt) != |
3207 0) { | 3259 0) { |
3208 return 0; | 3260 return 0; |
3209 } | 3261 } |
3210 return rtt; | 3262 return rtt; |
3211 } | 3263 } |
3212 | 3264 |
3213 } // namespace voe | 3265 } // namespace voe |
3214 } // namespace webrtc | 3266 } // namespace webrtc |
OLD | NEW |