Avoids unnecessary calls to audio encoder.
As of this CL: https://webrtc-review.googlesource.com/c/src/+/173704 ...we now call AudioEncoder::OnReceivedOverhead() too often, since we don't check if overhead has actually changed. This CL rectifies that. Bug: webrtc:10809 Change-Id: I0b86e0296a7860dde3e62e817f9b941fa82afe4a Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/175009 Reviewed-by: Per Åhgren <peah@webrtc.org> Commit-Queue: Erik Språng <sprang@webrtc.org> Cr-Commit-Position: refs/heads/master@{#31279}
This commit is contained in:
@ -544,10 +544,12 @@ void AudioSendStream::SetTransportOverhead(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AudioSendStream::UpdateOverheadForEncoder() {
|
void AudioSendStream::UpdateOverheadForEncoder() {
|
||||||
const size_t overhead_per_packet_bytes = GetPerPacketOverheadBytes();
|
size_t overhead_per_packet_bytes = GetPerPacketOverheadBytes();
|
||||||
if (overhead_per_packet_bytes == 0) {
|
if (overhead_per_packet_ == overhead_per_packet_bytes) {
|
||||||
return; // Overhead is not known yet, do not tell the encoder.
|
return;
|
||||||
}
|
}
|
||||||
|
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);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -195,6 +195,7 @@ class AudioSendStream final : public webrtc::AudioSendStream,
|
|||||||
static int TransportSeqNumId(const Config& config);
|
static int TransportSeqNumId(const Config& config);
|
||||||
|
|
||||||
rtc::CriticalSection overhead_per_packet_lock_;
|
rtc::CriticalSection 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_
|
||||||
|
|||||||
@ -794,7 +794,7 @@ TEST(AudioSendStreamTest, OnTransportOverheadChanged) {
|
|||||||
auto new_config = helper.config();
|
auto new_config = helper.config();
|
||||||
|
|
||||||
// CallEncoder will be called on overhead change.
|
// CallEncoder will be called on overhead change.
|
||||||
EXPECT_CALL(*helper.channel_send(), CallEncoder(::testing::_)).Times(1);
|
EXPECT_CALL(*helper.channel_send(), CallEncoder);
|
||||||
|
|
||||||
const size_t transport_overhead_per_packet_bytes = 333;
|
const size_t transport_overhead_per_packet_bytes = 333;
|
||||||
send_stream->SetTransportOverhead(transport_overhead_per_packet_bytes);
|
send_stream->SetTransportOverhead(transport_overhead_per_packet_bytes);
|
||||||
@ -804,6 +804,27 @@ TEST(AudioSendStreamTest, OnTransportOverheadChanged) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(AudioSendStreamTest, DoesntCallEncoderWhenOverheadUnchanged) {
|
||||||
|
for (bool use_null_audio_processing : {false, true}) {
|
||||||
|
ConfigHelper helper(false, true, use_null_audio_processing);
|
||||||
|
auto send_stream = helper.CreateAudioSendStream();
|
||||||
|
auto new_config = helper.config();
|
||||||
|
|
||||||
|
// CallEncoder will be called on overhead change.
|
||||||
|
EXPECT_CALL(*helper.channel_send(), CallEncoder);
|
||||||
|
const size_t transport_overhead_per_packet_bytes = 333;
|
||||||
|
send_stream->SetTransportOverhead(transport_overhead_per_packet_bytes);
|
||||||
|
|
||||||
|
// Set the same overhead again, CallEncoder should not be called again.
|
||||||
|
EXPECT_CALL(*helper.channel_send(), CallEncoder).Times(0);
|
||||||
|
send_stream->SetTransportOverhead(transport_overhead_per_packet_bytes);
|
||||||
|
|
||||||
|
// New overhead, call CallEncoder again
|
||||||
|
EXPECT_CALL(*helper.channel_send(), CallEncoder);
|
||||||
|
send_stream->SetTransportOverhead(transport_overhead_per_packet_bytes + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TEST(AudioSendStreamTest, AudioOverheadChanged) {
|
TEST(AudioSendStreamTest, AudioOverheadChanged) {
|
||||||
for (bool use_null_audio_processing : {false, true}) {
|
for (bool use_null_audio_processing : {false, true}) {
|
||||||
ConfigHelper helper(false, true, use_null_audio_processing);
|
ConfigHelper helper(false, true, use_null_audio_processing);
|
||||||
|
|||||||
Reference in New Issue
Block a user