Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1336)

Side by Side Diff: webrtc/media/engine/webrtcvoiceengine.cc

Issue 2775483004: Set max bitrate for audio send stream based on RtpParameters. (Closed)
Patch Set: fixing Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 (rtp_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
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 config_.max_bitrate_bps =
1398 rtp_parameters_.encodings[0].max_bitrate_bps
1399 ? *rtp_parameters_.encodings[0].max_bitrate_bps
1400 : kOpusBitrateFbBps;
1401
1392 // TODO(mflodman): Keep testing this and set proper values. 1402 // TODO(mflodman): Keep testing this and set proper values.
1393 // Note: This is an early experiment currently only supported by Opus. 1403 // Note: This is an early experiment currently only supported by Opus.
1394 if (send_side_bwe_with_overhead_) { 1404 if (send_side_bwe_with_overhead_) {
1395 auto packet_sizes_ms = WebRtcVoiceCodecs::GetPacketSizesMs( 1405 auto packet_sizes_ms = WebRtcVoiceCodecs::GetPacketSizesMs(
1396 config_.send_codec_spec.codec_inst); 1406 config_.send_codec_spec.codec_inst);
1397 if (!packet_sizes_ms.empty()) { 1407 if (!packet_sizes_ms.empty()) {
1398 int max_packet_size_ms = 1408 int max_packet_size_ms =
1399 *std::max_element(packet_sizes_ms.begin(), packet_sizes_ms.end()); 1409 *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 1410
1403 // Audio network adaptor will just use 20ms and 60ms frame lengths. 1411 // Audio network adaptor will just use 20ms and 60ms frame lengths.
1404 // The adaptor will only be active for the Opus encoder. 1412 // The adaptor will only be active for the Opus encoder.
1405 if (config_.audio_network_adaptor_config && 1413 if (config_.audio_network_adaptor_config &&
1406 IsCodec(config_.send_codec_spec.codec_inst, kOpusCodecName)) { 1414 IsCodec(config_.send_codec_spec.codec_inst, kOpusCodecName)) {
1407 #if WEBRTC_OPUS_SUPPORT_120MS_PTIME 1415 #if WEBRTC_OPUS_SUPPORT_120MS_PTIME
1408 max_packet_size_ms = 120; 1416 max_packet_size_ms = 120;
1409 #else 1417 #else
1410 max_packet_size_ms = 60; 1418 max_packet_size_ms = 60;
1411 #endif 1419 #endif
1412 min_packet_size_ms = 20;
1413 } 1420 }
1414 1421
1415 // OverheadPerPacket = Ipv4(20B) + UDP(8B) + SRTP(10B) + RTP(12) 1422 // OverheadPerPacket = Ipv4(20B) + UDP(8B) + SRTP(10B) + RTP(12)
1416 constexpr int kOverheadPerPacket = 20 + 8 + 10 + 12; 1423 constexpr int kOverheadPerPacket = 20 + 8 + 10 + 12;
1417 1424
1418 int min_overhead_bps = 1425 int min_overhead_bps =
1419 kOverheadPerPacket * 8 * 1000 / max_packet_size_ms; 1426 kOverheadPerPacket * 8 * 1000 / max_packet_size_ms;
1420 1427
1421 int max_overhead_bps = 1428 // We assume that |config_.max_bitrate_bps| before the next line is
1422 kOverheadPerPacket * 8 * 1000 / min_packet_size_ms; 1429 // a hard limit on the payload bitrate, so we add min_overhead_bps to
1430 // it to ensure that, when overhead is deducted, the payload rate
1431 // never goes beyond the limit.
1432 // Note: this also means that if a higher overhead is forced, we
1433 // cannot reach the limit.
1434 // TODO(minyue): Reconsider this when the signaling to BWE is done
1435 // through a dedicated API.
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 always be
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
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
OLDNEW
« no previous file with comments | « no previous file | webrtc/media/engine/webrtcvoiceengine_unittest.cc » ('j') | webrtc/media/engine/webrtcvoiceengine_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698