diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:43:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:43:14 +0000 |
commit | 8dd16259287f58f9273002717ec4d27e97127719 (patch) | |
tree | 3863e62a53829a84037444beab3abd4ed9dfc7d0 /third_party/libwebrtc/audio/audio_send_stream.cc | |
parent | Releasing progress-linux version 126.0.1-1~progress7.99u1. (diff) | |
download | firefox-8dd16259287f58f9273002717ec4d27e97127719.tar.xz firefox-8dd16259287f58f9273002717ec4d27e97127719.zip |
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/libwebrtc/audio/audio_send_stream.cc')
-rw-r--r-- | third_party/libwebrtc/audio/audio_send_stream.cc | 118 |
1 files changed, 43 insertions, 75 deletions
diff --git a/third_party/libwebrtc/audio/audio_send_stream.cc b/third_party/libwebrtc/audio/audio_send_stream.cc index 8dc78b18fa..64bc15ab4e 100644 --- a/third_party/libwebrtc/audio/audio_send_stream.cc +++ b/third_party/libwebrtc/audio/audio_send_stream.cc @@ -157,6 +157,8 @@ AudioSendStream::AudioSendStream( event_log_(event_log), use_legacy_overhead_calculation_( field_trials_.IsEnabled("WebRTC-Audio-LegacyOverhead")), + enable_priority_bitrate_( + !field_trials_.IsDisabled("WebRTC-Audio-PriorityBitrate")), bitrate_allocator_(bitrate_allocator), rtp_transport_(rtp_transport), rtp_rtcp_module_(channel_send_->GetRtpRtcp()), @@ -171,7 +173,6 @@ AudioSendStream::AudioSendStream( RTC_DCHECK_RUN_ON(&worker_thread_checker_); ConfigureStream(config, true, nullptr); - UpdateCachedTargetAudioBitrateConstraints(); } AudioSendStream::~AudioSendStream() { @@ -324,10 +325,7 @@ void AudioSendStream::ConfigureStream( } // Set currently known overhead (used in ANA, opus only). - { - MutexLock lock(&overhead_per_packet_lock_); - UpdateOverheadForEncoder(); - } + UpdateOverheadPerPacket(); channel_send_->CallEncoder([this](AudioEncoder* encoder) { RTC_DCHECK_RUN_ON(&worker_thread_checker_); @@ -335,7 +333,7 @@ void AudioSendStream::ConfigureStream( return; } frame_length_range_ = encoder->GetFrameLengthRange(); - UpdateCachedTargetAudioBitrateConstraints(); + bitrate_range_ = encoder->GetBitrateRange(); }); if (sending_) { @@ -343,9 +341,6 @@ void AudioSendStream::ConfigureStream( } config_ = new_config; - if (!first_time) { - UpdateCachedTargetAudioBitrateConstraints(); - } webrtc::InvokeSetParametersCallback(callback, webrtc::RTCError::OK()); } @@ -489,30 +484,23 @@ webrtc::AudioSendStream::Stats AudioSendStream::GetStats( void AudioSendStream::DeliverRtcp(const uint8_t* packet, size_t length) { RTC_DCHECK_RUN_ON(&worker_thread_checker_); channel_send_->ReceivedRTCPPacket(packet, length); - - { - // Poll if overhead has changed, which it can do if ack triggers us to stop - // sending mid/rid. - MutexLock lock(&overhead_per_packet_lock_); - UpdateOverheadForEncoder(); - } - UpdateCachedTargetAudioBitrateConstraints(); + // Poll if overhead has changed, which it can do if ack triggers us to stop + // sending mid/rid. + UpdateOverheadPerPacket(); } uint32_t AudioSendStream::OnBitrateUpdated(BitrateAllocationUpdate update) { RTC_DCHECK_RUN_ON(&worker_thread_checker_); - // Pick a target bitrate between the constraints. Overrules the allocator if // it 1) allocated a bitrate of zero to disable the stream or 2) allocated a // higher than max to allow for e.g. extra FEC. - RTC_DCHECK(cached_constraints_.has_value()); - update.target_bitrate.Clamp(cached_constraints_->min, - cached_constraints_->max); - update.stable_target_bitrate.Clamp(cached_constraints_->min, - cached_constraints_->max); - + absl::optional<TargetAudioBitrateConstraints> constraints = + GetMinMaxBitrateConstraints(); + if (constraints) { + update.target_bitrate.Clamp(constraints->min, constraints->max); + update.stable_target_bitrate.Clamp(constraints->min, constraints->max); + } channel_send_->OnBitrateAllocation(update); - // The amount of audio protection is not exposed by the encoder, hence // always returning 0. return 0; @@ -521,41 +509,30 @@ uint32_t AudioSendStream::OnBitrateUpdated(BitrateAllocationUpdate update) { void AudioSendStream::SetTransportOverhead( int transport_overhead_per_packet_bytes) { RTC_DCHECK_RUN_ON(&worker_thread_checker_); - { - MutexLock lock(&overhead_per_packet_lock_); - transport_overhead_per_packet_bytes_ = transport_overhead_per_packet_bytes; - UpdateOverheadForEncoder(); - } - UpdateCachedTargetAudioBitrateConstraints(); + transport_overhead_per_packet_bytes_ = transport_overhead_per_packet_bytes; + UpdateOverheadPerPacket(); } -void AudioSendStream::UpdateOverheadForEncoder() { +void AudioSendStream::UpdateOverheadPerPacket() { RTC_DCHECK_RUN_ON(&worker_thread_checker_); - size_t overhead_per_packet_bytes = GetPerPacketOverheadBytes(); + size_t overhead_per_packet_bytes = + transport_overhead_per_packet_bytes_ + + rtp_rtcp_module_->ExpectedPerPacketOverhead(); if (overhead_per_packet_ == overhead_per_packet_bytes) { return; } overhead_per_packet_ = overhead_per_packet_bytes; - channel_send_->CallEncoder([&](AudioEncoder* encoder) { encoder->OnReceivedOverhead(overhead_per_packet_bytes); }); - if (total_packet_overhead_bytes_ != overhead_per_packet_bytes) { - total_packet_overhead_bytes_ = overhead_per_packet_bytes; - if (registered_with_allocator_) { - ConfigureBitrateObserver(); - } + if (registered_with_allocator_) { + ConfigureBitrateObserver(); } } size_t AudioSendStream::TestOnlyGetPerPacketOverheadBytes() const { - MutexLock lock(&overhead_per_packet_lock_); - return GetPerPacketOverheadBytes(); -} - -size_t AudioSendStream::GetPerPacketOverheadBytes() const { - return transport_overhead_per_packet_bytes_ + - rtp_rtcp_module_->ExpectedPerPacketOverhead(); + RTC_DCHECK_RUN_ON(&worker_thread_checker_); + return overhead_per_packet_; } RtpState AudioSendStream::GetRtpState() const { @@ -649,13 +626,9 @@ bool AudioSendStream::SetupSendCodec(const Config& new_config) { } // Set currently known overhead (used in ANA, opus only). - // If overhead changes later, it will be updated in UpdateOverheadForEncoder. - { - MutexLock lock(&overhead_per_packet_lock_); - size_t overhead = GetPerPacketOverheadBytes(); - if (overhead > 0) { - encoder->OnReceivedOverhead(overhead); - } + // If overhead changes later, it will be updated in UpdateOverheadPerPacket. + if (overhead_per_packet_ > 0) { + encoder->OnReceivedOverhead(overhead_per_packet_); } StoreEncoderProperties(encoder->SampleRateHz(), encoder->NumChannels()); @@ -717,18 +690,14 @@ void AudioSendStream::ReconfigureANA(const Config& new_config) { return; } if (new_config.audio_network_adaptor_config) { - // This lock needs to be acquired before CallEncoder, since it aquires - // another lock and we need to maintain the same order at all call sites to - // avoid deadlock. - MutexLock lock(&overhead_per_packet_lock_); - size_t overhead = GetPerPacketOverheadBytes(); channel_send_->CallEncoder([&](AudioEncoder* encoder) { + RTC_DCHECK_RUN_ON(&worker_thread_checker_); if (encoder->EnableAudioNetworkAdaptor( *new_config.audio_network_adaptor_config, event_log_)) { RTC_LOG(LS_INFO) << "Audio network adaptor enabled on SSRC " << new_config.rtp.ssrc; - if (overhead > 0) { - encoder->OnReceivedOverhead(overhead); + if (overhead_per_packet_ > 0) { + encoder->OnReceivedOverhead(overhead_per_packet_); } } else { RTC_LOG(LS_INFO) << "Failed to enable Audio network adaptor on SSRC " @@ -833,8 +802,7 @@ void AudioSendStream::ConfigureBitrateObserver() { priority_bitrate += max_overhead; } else { RTC_DCHECK(frame_length_range_); - const DataSize overhead_per_packet = - DataSize::Bytes(total_packet_overhead_bytes_); + const DataSize overhead_per_packet = DataSize::Bytes(overhead_per_packet_); DataRate min_overhead = overhead_per_packet / frame_length_range_->second; priority_bitrate += min_overhead; } @@ -843,6 +811,10 @@ void AudioSendStream::ConfigureBitrateObserver() { priority_bitrate = *allocation_settings_.priority_bitrate_raw; } + if (!enable_priority_bitrate_) { + priority_bitrate = DataRate::BitsPerSec(0); + } + bitrate_allocator_->AddObserver( this, MediaStreamAllocationConfig{ @@ -878,6 +850,12 @@ AudioSendStream::GetMinMaxBitrateConstraints() const { if (allocation_settings_.max_bitrate) constraints.max = *allocation_settings_.max_bitrate; + // Use encoder defined bitrate range if available. + if (bitrate_range_) { + constraints.min = bitrate_range_->first; + constraints.max = bitrate_range_->second; + } + RTC_DCHECK_GE(constraints.min, DataRate::Zero()); RTC_DCHECK_GE(constraints.max, DataRate::Zero()); if (constraints.max < constraints.min) { @@ -898,10 +876,9 @@ AudioSendStream::GetMinMaxBitrateConstraints() const { RTC_LOG(LS_WARNING) << "frame_length_range_ is not set"; return absl::nullopt; } - const DataSize kOverheadPerPacket = - DataSize::Bytes(total_packet_overhead_bytes_); - constraints.min += kOverheadPerPacket / frame_length_range_->second; - constraints.max += kOverheadPerPacket / frame_length_range_->first; + const DataSize overhead_per_packet = DataSize::Bytes(overhead_per_packet_); + constraints.min += overhead_per_packet / frame_length_range_->second; + constraints.max += overhead_per_packet / frame_length_range_->first; } return constraints; } @@ -911,14 +888,5 @@ void AudioSendStream::RegisterCngPayloadType(int payload_type, channel_send_->RegisterCngPayloadType(payload_type, clockrate_hz); } -void AudioSendStream::UpdateCachedTargetAudioBitrateConstraints() { - absl::optional<AudioSendStream::TargetAudioBitrateConstraints> - new_constraints = GetMinMaxBitrateConstraints(); - if (!new_constraints.has_value()) { - return; - } - cached_constraints_ = new_constraints; -} - } // namespace internal } // namespace webrtc |