Remove packet overhead lock and cached bitrate constraints.
These are no longer needed since the RTP transport runs on the worker thread now. Some tests that were too strict on ordering needed change. Bug: none Change-Id: I4265cb1a4fd3355208f19aefdbb7abeb45b6cadf Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/335700 Reviewed-by: Tomas Lundqvist <tomasl@google.com> Commit-Queue: Jakob Ivarsson <jakobi@webrtc.org> Cr-Commit-Position: refs/heads/main@{#41599}
This commit is contained in:
parent
eb76f193f3
commit
340d6c0236
@ -171,7 +171,6 @@ AudioSendStream::AudioSendStream(
|
|||||||
|
|
||||||
RTC_DCHECK_RUN_ON(&worker_thread_checker_);
|
RTC_DCHECK_RUN_ON(&worker_thread_checker_);
|
||||||
ConfigureStream(config, true, nullptr);
|
ConfigureStream(config, true, nullptr);
|
||||||
UpdateCachedTargetAudioBitrateConstraints();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioSendStream::~AudioSendStream() {
|
AudioSendStream::~AudioSendStream() {
|
||||||
@ -324,10 +323,7 @@ void AudioSendStream::ConfigureStream(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set currently known overhead (used in ANA, opus only).
|
// Set currently known overhead (used in ANA, opus only).
|
||||||
{
|
UpdateOverheadPerPacket();
|
||||||
MutexLock lock(&overhead_per_packet_lock_);
|
|
||||||
UpdateOverheadForEncoder();
|
|
||||||
}
|
|
||||||
|
|
||||||
channel_send_->CallEncoder([this](AudioEncoder* encoder) {
|
channel_send_->CallEncoder([this](AudioEncoder* encoder) {
|
||||||
RTC_DCHECK_RUN_ON(&worker_thread_checker_);
|
RTC_DCHECK_RUN_ON(&worker_thread_checker_);
|
||||||
@ -335,7 +331,6 @@ void AudioSendStream::ConfigureStream(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
frame_length_range_ = encoder->GetFrameLengthRange();
|
frame_length_range_ = encoder->GetFrameLengthRange();
|
||||||
UpdateCachedTargetAudioBitrateConstraints();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (sending_) {
|
if (sending_) {
|
||||||
@ -343,9 +338,6 @@ void AudioSendStream::ConfigureStream(
|
|||||||
}
|
}
|
||||||
|
|
||||||
config_ = new_config;
|
config_ = new_config;
|
||||||
if (!first_time) {
|
|
||||||
UpdateCachedTargetAudioBitrateConstraints();
|
|
||||||
}
|
|
||||||
|
|
||||||
webrtc::InvokeSetParametersCallback(callback, webrtc::RTCError::OK());
|
webrtc::InvokeSetParametersCallback(callback, webrtc::RTCError::OK());
|
||||||
}
|
}
|
||||||
@ -488,30 +480,23 @@ webrtc::AudioSendStream::Stats AudioSendStream::GetStats(
|
|||||||
void AudioSendStream::DeliverRtcp(const uint8_t* packet, size_t length) {
|
void AudioSendStream::DeliverRtcp(const uint8_t* packet, size_t length) {
|
||||||
RTC_DCHECK_RUN_ON(&worker_thread_checker_);
|
RTC_DCHECK_RUN_ON(&worker_thread_checker_);
|
||||||
channel_send_->ReceivedRTCPPacket(packet, length);
|
channel_send_->ReceivedRTCPPacket(packet, length);
|
||||||
|
// Poll if overhead has changed, which it can do if ack triggers us to stop
|
||||||
{
|
// sending mid/rid.
|
||||||
// Poll if overhead has changed, which it can do if ack triggers us to stop
|
UpdateOverheadPerPacket();
|
||||||
// sending mid/rid.
|
|
||||||
MutexLock lock(&overhead_per_packet_lock_);
|
|
||||||
UpdateOverheadForEncoder();
|
|
||||||
}
|
|
||||||
UpdateCachedTargetAudioBitrateConstraints();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t AudioSendStream::OnBitrateUpdated(BitrateAllocationUpdate update) {
|
uint32_t AudioSendStream::OnBitrateUpdated(BitrateAllocationUpdate update) {
|
||||||
RTC_DCHECK_RUN_ON(&worker_thread_checker_);
|
RTC_DCHECK_RUN_ON(&worker_thread_checker_);
|
||||||
|
|
||||||
// Pick a target bitrate between the constraints. Overrules the allocator if
|
// 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
|
// 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.
|
// higher than max to allow for e.g. extra FEC.
|
||||||
RTC_DCHECK(cached_constraints_.has_value());
|
absl::optional<TargetAudioBitrateConstraints> constraints =
|
||||||
update.target_bitrate.Clamp(cached_constraints_->min,
|
GetMinMaxBitrateConstraints();
|
||||||
cached_constraints_->max);
|
if (constraints) {
|
||||||
update.stable_target_bitrate.Clamp(cached_constraints_->min,
|
update.target_bitrate.Clamp(constraints->min, constraints->max);
|
||||||
cached_constraints_->max);
|
update.stable_target_bitrate.Clamp(constraints->min, constraints->max);
|
||||||
|
}
|
||||||
channel_send_->OnBitrateAllocation(update);
|
channel_send_->OnBitrateAllocation(update);
|
||||||
|
|
||||||
// The amount of audio protection is not exposed by the encoder, hence
|
// The amount of audio protection is not exposed by the encoder, hence
|
||||||
// always returning 0.
|
// always returning 0.
|
||||||
return 0;
|
return 0;
|
||||||
@ -520,41 +505,30 @@ uint32_t AudioSendStream::OnBitrateUpdated(BitrateAllocationUpdate update) {
|
|||||||
void AudioSendStream::SetTransportOverhead(
|
void AudioSendStream::SetTransportOverhead(
|
||||||
int transport_overhead_per_packet_bytes) {
|
int transport_overhead_per_packet_bytes) {
|
||||||
RTC_DCHECK_RUN_ON(&worker_thread_checker_);
|
RTC_DCHECK_RUN_ON(&worker_thread_checker_);
|
||||||
{
|
transport_overhead_per_packet_bytes_ = transport_overhead_per_packet_bytes;
|
||||||
MutexLock lock(&overhead_per_packet_lock_);
|
UpdateOverheadPerPacket();
|
||||||
transport_overhead_per_packet_bytes_ = transport_overhead_per_packet_bytes;
|
|
||||||
UpdateOverheadForEncoder();
|
|
||||||
}
|
|
||||||
UpdateCachedTargetAudioBitrateConstraints();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioSendStream::UpdateOverheadForEncoder() {
|
void AudioSendStream::UpdateOverheadPerPacket() {
|
||||||
RTC_DCHECK_RUN_ON(&worker_thread_checker_);
|
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) {
|
if (overhead_per_packet_ == overhead_per_packet_bytes) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
overhead_per_packet_ = overhead_per_packet_bytes;
|
overhead_per_packet_ = overhead_per_packet_bytes;
|
||||||
|
|
||||||
channel_send_->CallEncoder([&](AudioEncoder* encoder) {
|
channel_send_->CallEncoder([&](AudioEncoder* encoder) {
|
||||||
encoder->OnReceivedOverhead(overhead_per_packet_bytes);
|
encoder->OnReceivedOverhead(overhead_per_packet_bytes);
|
||||||
});
|
});
|
||||||
if (total_packet_overhead_bytes_ != overhead_per_packet_bytes) {
|
if (registered_with_allocator_) {
|
||||||
total_packet_overhead_bytes_ = overhead_per_packet_bytes;
|
ConfigureBitrateObserver();
|
||||||
if (registered_with_allocator_) {
|
|
||||||
ConfigureBitrateObserver();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t AudioSendStream::TestOnlyGetPerPacketOverheadBytes() const {
|
size_t AudioSendStream::TestOnlyGetPerPacketOverheadBytes() const {
|
||||||
MutexLock lock(&overhead_per_packet_lock_);
|
RTC_DCHECK_RUN_ON(&worker_thread_checker_);
|
||||||
return GetPerPacketOverheadBytes();
|
return overhead_per_packet_;
|
||||||
}
|
|
||||||
|
|
||||||
size_t AudioSendStream::GetPerPacketOverheadBytes() const {
|
|
||||||
return transport_overhead_per_packet_bytes_ +
|
|
||||||
rtp_rtcp_module_->ExpectedPerPacketOverhead();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RtpState AudioSendStream::GetRtpState() const {
|
RtpState AudioSendStream::GetRtpState() const {
|
||||||
@ -648,13 +622,9 @@ bool AudioSendStream::SetupSendCodec(const Config& new_config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set currently known overhead (used in ANA, opus only).
|
// Set currently known overhead (used in ANA, opus only).
|
||||||
// If overhead changes later, it will be updated in UpdateOverheadForEncoder.
|
// If overhead changes later, it will be updated in UpdateOverheadPerPacket.
|
||||||
{
|
if (overhead_per_packet_ > 0) {
|
||||||
MutexLock lock(&overhead_per_packet_lock_);
|
encoder->OnReceivedOverhead(overhead_per_packet_);
|
||||||
size_t overhead = GetPerPacketOverheadBytes();
|
|
||||||
if (overhead > 0) {
|
|
||||||
encoder->OnReceivedOverhead(overhead);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
StoreEncoderProperties(encoder->SampleRateHz(), encoder->NumChannels());
|
StoreEncoderProperties(encoder->SampleRateHz(), encoder->NumChannels());
|
||||||
@ -716,18 +686,14 @@ void AudioSendStream::ReconfigureANA(const Config& new_config) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (new_config.audio_network_adaptor_config) {
|
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) {
|
channel_send_->CallEncoder([&](AudioEncoder* encoder) {
|
||||||
|
RTC_DCHECK_RUN_ON(&worker_thread_checker_);
|
||||||
if (encoder->EnableAudioNetworkAdaptor(
|
if (encoder->EnableAudioNetworkAdaptor(
|
||||||
*new_config.audio_network_adaptor_config, event_log_)) {
|
*new_config.audio_network_adaptor_config, event_log_)) {
|
||||||
RTC_LOG(LS_INFO) << "Audio network adaptor enabled on SSRC "
|
RTC_LOG(LS_INFO) << "Audio network adaptor enabled on SSRC "
|
||||||
<< new_config.rtp.ssrc;
|
<< new_config.rtp.ssrc;
|
||||||
if (overhead > 0) {
|
if (overhead_per_packet_ > 0) {
|
||||||
encoder->OnReceivedOverhead(overhead);
|
encoder->OnReceivedOverhead(overhead_per_packet_);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
RTC_LOG(LS_INFO) << "Failed to enable Audio network adaptor on SSRC "
|
RTC_LOG(LS_INFO) << "Failed to enable Audio network adaptor on SSRC "
|
||||||
@ -832,8 +798,7 @@ void AudioSendStream::ConfigureBitrateObserver() {
|
|||||||
priority_bitrate += max_overhead;
|
priority_bitrate += max_overhead;
|
||||||
} else {
|
} else {
|
||||||
RTC_DCHECK(frame_length_range_);
|
RTC_DCHECK(frame_length_range_);
|
||||||
const DataSize overhead_per_packet =
|
const DataSize overhead_per_packet = DataSize::Bytes(overhead_per_packet_);
|
||||||
DataSize::Bytes(total_packet_overhead_bytes_);
|
|
||||||
DataRate min_overhead = overhead_per_packet / frame_length_range_->second;
|
DataRate min_overhead = overhead_per_packet / frame_length_range_->second;
|
||||||
priority_bitrate += min_overhead;
|
priority_bitrate += min_overhead;
|
||||||
}
|
}
|
||||||
@ -897,10 +862,9 @@ AudioSendStream::GetMinMaxBitrateConstraints() const {
|
|||||||
RTC_LOG(LS_WARNING) << "frame_length_range_ is not set";
|
RTC_LOG(LS_WARNING) << "frame_length_range_ is not set";
|
||||||
return absl::nullopt;
|
return absl::nullopt;
|
||||||
}
|
}
|
||||||
const DataSize kOverheadPerPacket =
|
const DataSize overhead_per_packet = DataSize::Bytes(overhead_per_packet_);
|
||||||
DataSize::Bytes(total_packet_overhead_bytes_);
|
constraints.min += overhead_per_packet / frame_length_range_->second;
|
||||||
constraints.min += kOverheadPerPacket / frame_length_range_->second;
|
constraints.max += overhead_per_packet / frame_length_range_->first;
|
||||||
constraints.max += kOverheadPerPacket / frame_length_range_->first;
|
|
||||||
}
|
}
|
||||||
return constraints;
|
return constraints;
|
||||||
}
|
}
|
||||||
@ -910,14 +874,5 @@ void AudioSendStream::RegisterCngPayloadType(int payload_type,
|
|||||||
channel_send_->RegisterCngPayloadType(payload_type, clockrate_hz);
|
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 internal
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
|||||||
@ -110,8 +110,7 @@ class AudioSendStream final : public webrtc::AudioSendStream,
|
|||||||
const voe::ChannelSendInterface* GetChannel() const;
|
const voe::ChannelSendInterface* GetChannel() const;
|
||||||
|
|
||||||
// Returns combined per-packet overhead.
|
// Returns combined per-packet overhead.
|
||||||
size_t TestOnlyGetPerPacketOverheadBytes() const
|
size_t TestOnlyGetPerPacketOverheadBytes() const;
|
||||||
RTC_LOCKS_EXCLUDED(overhead_per_packet_lock_);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class TimedTransport;
|
class TimedTransport;
|
||||||
@ -152,19 +151,11 @@ class AudioSendStream final : public webrtc::AudioSendStream,
|
|||||||
|
|
||||||
// Sets per-packet overhead on encoded (for ANA) based on current known values
|
// Sets per-packet overhead on encoded (for ANA) based on current known values
|
||||||
// of transport and packetization overheads.
|
// of transport and packetization overheads.
|
||||||
void UpdateOverheadForEncoder()
|
void UpdateOverheadPerPacket();
|
||||||
RTC_EXCLUSIVE_LOCKS_REQUIRED(overhead_per_packet_lock_);
|
|
||||||
|
|
||||||
// Returns combined per-packet overhead.
|
|
||||||
size_t GetPerPacketOverheadBytes() const
|
|
||||||
RTC_EXCLUSIVE_LOCKS_REQUIRED(overhead_per_packet_lock_);
|
|
||||||
|
|
||||||
void RegisterCngPayloadType(int payload_type, int clockrate_hz)
|
void RegisterCngPayloadType(int payload_type, int clockrate_hz)
|
||||||
RTC_RUN_ON(worker_thread_checker_);
|
RTC_RUN_ON(worker_thread_checker_);
|
||||||
|
|
||||||
void UpdateCachedTargetAudioBitrateConstraints()
|
|
||||||
RTC_RUN_ON(worker_thread_checker_);
|
|
||||||
|
|
||||||
Clock* clock_;
|
Clock* clock_;
|
||||||
const FieldTrialsView& field_trials_;
|
const FieldTrialsView& field_trials_;
|
||||||
|
|
||||||
@ -193,9 +184,6 @@ class AudioSendStream final : public webrtc::AudioSendStream,
|
|||||||
|
|
||||||
BitrateAllocatorInterface* const bitrate_allocator_
|
BitrateAllocatorInterface* const bitrate_allocator_
|
||||||
RTC_GUARDED_BY(worker_thread_checker_);
|
RTC_GUARDED_BY(worker_thread_checker_);
|
||||||
absl::optional<AudioSendStream::TargetAudioBitrateConstraints>
|
|
||||||
cached_constraints_ RTC_GUARDED_BY(worker_thread_checker_) =
|
|
||||||
absl::nullopt;
|
|
||||||
RtpTransportControllerSendInterface* const rtp_transport_;
|
RtpTransportControllerSendInterface* const rtp_transport_;
|
||||||
|
|
||||||
RtpRtcpInterface* const rtp_rtcp_module_;
|
RtpRtcpInterface* const rtp_rtcp_module_;
|
||||||
@ -217,17 +205,14 @@ class AudioSendStream final : public webrtc::AudioSendStream,
|
|||||||
const std::vector<RtpExtension>& extensions);
|
const std::vector<RtpExtension>& extensions);
|
||||||
static int TransportSeqNumId(const Config& config);
|
static int TransportSeqNumId(const Config& config);
|
||||||
|
|
||||||
mutable Mutex overhead_per_packet_lock_;
|
|
||||||
size_t overhead_per_packet_ RTC_GUARDED_BY(overhead_per_packet_lock_) = 0;
|
|
||||||
|
|
||||||
// Current transport overhead (ICE, TURN, etc.)
|
// Current transport overhead (ICE, TURN, etc.)
|
||||||
size_t transport_overhead_per_packet_bytes_
|
size_t transport_overhead_per_packet_bytes_
|
||||||
RTC_GUARDED_BY(overhead_per_packet_lock_) = 0;
|
RTC_GUARDED_BY(worker_thread_checker_) = 0;
|
||||||
|
// Total overhead, including transport and RTP headers.
|
||||||
|
size_t overhead_per_packet_ RTC_GUARDED_BY(worker_thread_checker_) = 0;
|
||||||
|
|
||||||
bool registered_with_allocator_ RTC_GUARDED_BY(worker_thread_checker_) =
|
bool registered_with_allocator_ RTC_GUARDED_BY(worker_thread_checker_) =
|
||||||
false;
|
false;
|
||||||
size_t total_packet_overhead_bytes_ RTC_GUARDED_BY(worker_thread_checker_) =
|
|
||||||
0;
|
|
||||||
absl::optional<std::pair<TimeDelta, TimeDelta>> frame_length_range_
|
absl::optional<std::pair<TimeDelta, TimeDelta>> frame_length_range_
|
||||||
RTC_GUARDED_BY(worker_thread_checker_);
|
RTC_GUARDED_BY(worker_thread_checker_);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -560,8 +560,7 @@ TEST(AudioSendStreamTest, AudioNetworkAdaptorReceivesOverhead) {
|
|||||||
InSequence s;
|
InSequence s;
|
||||||
EXPECT_CALL(
|
EXPECT_CALL(
|
||||||
*mock_encoder,
|
*mock_encoder,
|
||||||
OnReceivedOverhead(Eq(kOverheadPerPacket.bytes<size_t>())))
|
OnReceivedOverhead(Eq(kOverheadPerPacket.bytes<size_t>())));
|
||||||
.Times(2);
|
|
||||||
EXPECT_CALL(*mock_encoder,
|
EXPECT_CALL(*mock_encoder,
|
||||||
EnableAudioNetworkAdaptor(StrEq(kAnaConfigString), _))
|
EnableAudioNetworkAdaptor(StrEq(kAnaConfigString), _))
|
||||||
.WillOnce(Return(true));
|
.WillOnce(Return(true));
|
||||||
@ -847,7 +846,6 @@ TEST(AudioSendStreamTest, AudioOverheadChanged) {
|
|||||||
EXPECT_CALL(*helper.rtp_rtcp(), ExpectedPerPacketOverhead)
|
EXPECT_CALL(*helper.rtp_rtcp(), ExpectedPerPacketOverhead)
|
||||||
.WillRepeatedly(Return(audio_overhead_per_packet_bytes));
|
.WillRepeatedly(Return(audio_overhead_per_packet_bytes));
|
||||||
auto send_stream = helper.CreateAudioSendStream();
|
auto send_stream = helper.CreateAudioSendStream();
|
||||||
auto new_config = helper.config();
|
|
||||||
|
|
||||||
BitrateAllocationUpdate update;
|
BitrateAllocationUpdate update;
|
||||||
update.target_bitrate =
|
update.target_bitrate =
|
||||||
@ -861,6 +859,8 @@ TEST(AudioSendStreamTest, AudioOverheadChanged) {
|
|||||||
|
|
||||||
EXPECT_CALL(*helper.rtp_rtcp(), ExpectedPerPacketOverhead)
|
EXPECT_CALL(*helper.rtp_rtcp(), ExpectedPerPacketOverhead)
|
||||||
.WillRepeatedly(Return(audio_overhead_per_packet_bytes + 20));
|
.WillRepeatedly(Return(audio_overhead_per_packet_bytes + 20));
|
||||||
|
// RTP overhead can only change in response to RTCP or configuration change.
|
||||||
|
send_stream->Reconfigure(helper.config(), nullptr);
|
||||||
EXPECT_CALL(*helper.channel_send(), OnBitrateAllocation);
|
EXPECT_CALL(*helper.channel_send(), OnBitrateAllocation);
|
||||||
send_stream->OnBitrateUpdated(update);
|
send_stream->OnBitrateUpdated(update);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user