Avoid flagging Opus DTX frames as speech.

Background: After 20 consecutive DTX frames, Opus encodes the background
noise in a normal frame and then goes back to outputting DTX frames.

Currently all Opus frames are flagged as containing speech.

This CL is has two effects on outgoing Opus packets:
1. DTX frames are flagged as non-speech.
2. A non-DTX frame that follows 20 consecutive DTX frames is flagged as
   non-speech.

Bug: webrtc:8088
Change-Id: Ic36cf8c9d0a34f55ed4e57858362ad91e3897dda
Reviewed-on: https://webrtc-review.googlesource.com/23760
Commit-Queue: Gustaf Ullberg <gustaf@webrtc.org>
Reviewed-by: Henrik Lundin <henrik.lundin@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20794}
This commit is contained in:
Gustaf Ullberg
2017-11-20 14:55:41 +01:00
committed by Commit Bot
parent e5b5f4638d
commit 36de62e830
4 changed files with 78 additions and 2 deletions

View File

@ -380,7 +380,8 @@ AudioEncoderOpusImpl::AudioEncoderOpusImpl(
inst_(nullptr),
packet_loss_fraction_smoother_(new PacketLossFractionSmoother()),
audio_network_adaptor_creator_(audio_network_adaptor_creator),
bitrate_smoother_(std::move(bitrate_smoother)) {
bitrate_smoother_(std::move(bitrate_smoother)),
consecutive_dtx_frames_(0) {
RTC_DCHECK(0 <= payload_type && payload_type <= 127);
// Sanity check of the redundant payload type field that we want to get rid
@ -603,14 +604,23 @@ AudioEncoder::EncodedInfo AudioEncoderOpusImpl::EncodeImpl(
});
input_buffer_.clear();
bool dtx_frame = (info.encoded_bytes <= 2);
// Will use new packet size for next encoding.
config_.frame_size_ms = next_frame_length_ms_;
info.encoded_timestamp = first_timestamp_in_buffer_;
info.payload_type = payload_type_;
info.send_even_if_empty = true; // Allows Opus to send empty packets.
info.speech = (info.encoded_bytes > 0);
// After 20 DTX frames (MAX_CONSECUTIVE_DTX) Opus will send a frame
// coding the background noise. Avoid flagging this frame as speech
// (even though there is a probability of the frame being speech).
info.speech = !dtx_frame && (consecutive_dtx_frames_ != 20);
info.encoder_type = CodecType::kOpus;
// Increase or reset DTX counter.
consecutive_dtx_frames_ = (dtx_frame) ? (consecutive_dtx_frames_ + 1) : (0);
return info;
}