Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 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 1335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1346 if (!ValidateRtpParameters(parameters)) { | 1346 if (!ValidateRtpParameters(parameters)) { |
| 1347 return false; | 1347 return false; |
| 1348 } | 1348 } |
| 1349 auto send_rate = ComputeSendBitrate(max_send_bitrate_bps_, | 1349 auto send_rate = ComputeSendBitrate(max_send_bitrate_bps_, |
| 1350 parameters.encodings[0].max_bitrate_bps, | 1350 parameters.encodings[0].max_bitrate_bps, |
| 1351 send_codec_spec_.codec_inst); | 1351 send_codec_spec_.codec_inst); |
| 1352 if (!send_rate) { | 1352 if (!send_rate) { |
| 1353 return false; | 1353 return false; |
| 1354 } | 1354 } |
| 1355 | 1355 |
| 1356 const rtc::Optional<int> old_rtp_max_bitrate = | |
| 1357 rtp_parameters_.encodings[0].max_bitrate_bps; | |
| 1358 | |
| 1356 rtp_parameters_ = parameters; | 1359 rtp_parameters_ = parameters; |
| 1357 | 1360 |
| 1358 // parameters.encodings[0].encodings[0].max_bitrate_bps could have changed. | 1361 if (parameters_.encodings[0].max_bitrate_bps != old_rtp_max_bitrate) { |
| 1359 if (config_.send_codec_spec.codec_inst.rate != *send_rate) { | |
| 1360 // Recreate AudioSendStream with new bit rate. | 1362 // Recreate AudioSendStream with new bit rate. |
| 1361 config_.send_codec_spec.codec_inst.rate = *send_rate; | 1363 config_.send_codec_spec.codec_inst.rate = *send_rate; |
| 1362 RecreateAudioSendStream(); | 1364 RecreateAudioSendStream(); |
| 1363 } else { | 1365 } else { |
| 1364 // parameters.encodings[0].active could have changed. | 1366 // parameters.encodings[0].active could have changed. |
| 1365 UpdateSendState(); | 1367 UpdateSendState(); |
| 1366 } | 1368 } |
| 1367 return true; | 1369 return true; |
| 1368 } | 1370 } |
| 1369 | 1371 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1381 | 1383 |
| 1382 void RecreateAudioSendStream() { | 1384 void RecreateAudioSendStream() { |
| 1383 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 1385 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 1384 if (stream_) { | 1386 if (stream_) { |
| 1385 call_->DestroyAudioSendStream(stream_); | 1387 call_->DestroyAudioSendStream(stream_); |
| 1386 stream_ = nullptr; | 1388 stream_ = nullptr; |
| 1387 } | 1389 } |
| 1388 RTC_DCHECK(!stream_); | 1390 RTC_DCHECK(!stream_); |
| 1389 if (webrtc::field_trial::IsEnabled("WebRTC-Audio-SendSideBwe")) { | 1391 if (webrtc::field_trial::IsEnabled("WebRTC-Audio-SendSideBwe")) { |
| 1390 config_.min_bitrate_bps = kOpusMinBitrateBps; | 1392 config_.min_bitrate_bps = kOpusMinBitrateBps; |
| 1391 config_.max_bitrate_bps = kOpusBitrateFbBps; | 1393 |
| 1394 // This means that when RtpParameters is reset, we may change the | |
| 1395 // encoder's bit rate immediately (through call_->CreateAudioSendStream), | |
| 1396 // meanwhile change the cap to the output of BWE. | |
| 1397 // TODO(minyue): remove dependency on RtpParameters when the signaling to | |
|
minyue-webrtc
2017/03/27 13:29:01
I did not change the TODO here since we may need t
stefan-webrtc
2017/03/27 14:04:42
I still think it makes sense to have this wired up
| |
| 1398 // BWE is done through a dedicated API. | |
| 1399 config_.max_bitrate_bps = | |
| 1400 rtp_parameters_.encodings[0].max_bitrate_bps | |
| 1401 ? *rtp_parameters_.encodings[0].max_bitrate_bps | |
| 1402 : kOpusBitrateFbBps; | |
| 1403 | |
| 1392 // TODO(mflodman): Keep testing this and set proper values. | 1404 // TODO(mflodman): Keep testing this and set proper values. |
| 1393 // Note: This is an early experiment currently only supported by Opus. | 1405 // Note: This is an early experiment currently only supported by Opus. |
| 1394 if (send_side_bwe_with_overhead_) { | 1406 if (send_side_bwe_with_overhead_) { |
| 1395 auto packet_sizes_ms = WebRtcVoiceCodecs::GetPacketSizesMs( | 1407 auto packet_sizes_ms = WebRtcVoiceCodecs::GetPacketSizesMs( |
| 1396 config_.send_codec_spec.codec_inst); | 1408 config_.send_codec_spec.codec_inst); |
| 1397 if (!packet_sizes_ms.empty()) { | 1409 if (!packet_sizes_ms.empty()) { |
| 1398 int max_packet_size_ms = | 1410 int max_packet_size_ms = |
| 1399 *std::max_element(packet_sizes_ms.begin(), packet_sizes_ms.end()); | 1411 *std::max_element(packet_sizes_ms.begin(), packet_sizes_ms.end()); |
| 1400 int min_packet_size_ms = | |
| 1401 *std::min_element(packet_sizes_ms.begin(), packet_sizes_ms.end()); | |
| 1402 | 1412 |
| 1403 // Audio network adaptor will just use 20ms and 60ms frame lengths. | 1413 // Audio network adaptor will just use 20ms and 60ms frame lengths. |
| 1404 // The adaptor will only be active for the Opus encoder. | 1414 // The adaptor will only be active for the Opus encoder. |
| 1405 if (config_.audio_network_adaptor_config && | 1415 if (config_.audio_network_adaptor_config && |
| 1406 IsCodec(config_.send_codec_spec.codec_inst, kOpusCodecName)) { | 1416 IsCodec(config_.send_codec_spec.codec_inst, kOpusCodecName)) { |
| 1407 #if WEBRTC_OPUS_SUPPORT_120MS_PTIME | 1417 #if WEBRTC_OPUS_SUPPORT_120MS_PTIME |
| 1408 max_packet_size_ms = 120; | 1418 max_packet_size_ms = 120; |
| 1409 #else | 1419 #else |
| 1410 max_packet_size_ms = 60; | 1420 max_packet_size_ms = 60; |
| 1411 #endif | 1421 #endif |
| 1412 min_packet_size_ms = 20; | |
| 1413 } | 1422 } |
| 1414 | 1423 |
| 1415 // OverheadPerPacket = Ipv4(20B) + UDP(8B) + SRTP(10B) + RTP(12) | 1424 // OverheadPerPacket = Ipv4(20B) + UDP(8B) + SRTP(10B) + RTP(12) |
| 1416 constexpr int kOverheadPerPacket = 20 + 8 + 10 + 12; | 1425 constexpr int kOverheadPerPacket = 20 + 8 + 10 + 12; |
| 1417 | 1426 |
| 1418 int min_overhead_bps = | 1427 int min_overhead_bps = |
| 1419 kOverheadPerPacket * 8 * 1000 / max_packet_size_ms; | 1428 kOverheadPerPacket * 8 * 1000 / max_packet_size_ms; |
| 1420 | 1429 |
| 1421 int max_overhead_bps = | 1430 // We assume that |config_.max_bitrate_bps| before the next line is |
| 1422 kOverheadPerPacket * 8 * 1000 / min_packet_size_ms; | 1431 // a hard limit on the payload bitrate, so we add min_overhead_bps to |
| 1432 // it to ensure that, when overhead is deducted, the payload rate | |
| 1433 // never goes beyond the limit. | |
| 1434 // Note: this also means that if a higher overhead is forced, we | |
| 1435 // cannot reach the limit. We need to investigate this. | |
| 1436 config_.max_bitrate_bps += min_overhead_bps; | |
| 1423 | 1437 |
| 1424 config_.min_bitrate_bps = kOpusMinBitrateBps + min_overhead_bps; | 1438 // In contrast to max_bitrate_bps, we let min_bitrate_bps be always |
|
stefan-webrtc
2017/03/27 14:04:42
always be reachable
| |
| 1425 config_.max_bitrate_bps = kOpusBitrateFbBps + max_overhead_bps; | 1439 // reachable. |
| 1440 config_.min_bitrate_bps += min_overhead_bps; | |
| 1426 } | 1441 } |
| 1427 } | 1442 } |
| 1428 } | 1443 } |
| 1429 stream_ = call_->CreateAudioSendStream(config_); | 1444 stream_ = call_->CreateAudioSendStream(config_); |
| 1430 RTC_CHECK(stream_); | 1445 RTC_CHECK(stream_); |
| 1431 UpdateSendState(); | 1446 UpdateSendState(); |
| 1432 } | 1447 } |
| 1433 | 1448 |
| 1434 rtc::ThreadChecker worker_thread_checker_; | 1449 rtc::ThreadChecker worker_thread_checker_; |
| 1435 rtc::RaceChecker audio_capture_race_checker_; | 1450 rtc::RaceChecker audio_capture_race_checker_; |
| (...skipping 1218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2654 ssrc); | 2669 ssrc); |
| 2655 if (it != unsignaled_recv_ssrcs_.end()) { | 2670 if (it != unsignaled_recv_ssrcs_.end()) { |
| 2656 unsignaled_recv_ssrcs_.erase(it); | 2671 unsignaled_recv_ssrcs_.erase(it); |
| 2657 return true; | 2672 return true; |
| 2658 } | 2673 } |
| 2659 return false; | 2674 return false; |
| 2660 } | 2675 } |
| 2661 } // namespace cricket | 2676 } // namespace cricket |
| 2662 | 2677 |
| 2663 #endif // HAVE_WEBRTC_VOICE | 2678 #endif // HAVE_WEBRTC_VOICE |
| OLD | NEW |