summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJesús de Vicente Peña <devicentepena@webrtc.org>2021-02-12 13:51:43 +0100
committerFelicia Lim <flim@google.com>2021-02-19 14:30:49 -0800
commit16286a25fdd865c66a837a73b65fbaa7b25bf484 (patch)
treed01c95f488f16387c23d405f88e874220a99afc4 /src
parentd633f523e36e3b6d01cc6d57386458d770d618be (diff)
downloadopus-16286a25fdd865c66a837a73b65fbaa7b25bf484.tar.gz
Sending refresh DTX packets every 400 ms independently of the encoded frame size.
Signed-off-by: Felicia Lim <flim@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/opus_encoder.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/src/opus_encoder.c b/src/opus_encoder.c
index 7b5f0abf..321bb2bb 100644
--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -112,7 +112,7 @@ struct OpusEncoder {
opus_val16 delay_buffer[MAX_ENCODER_BUFFER*2];
#ifndef DISABLE_FLOAT_API
int detected_bandwidth;
- int nb_no_activity_frames;
+ int nb_no_activity_ms_Q1;
opus_val32 peak_signal_energy;
#endif
int nonfinal_frame; /* current frame is not the final in a packet */
@@ -893,24 +893,28 @@ static opus_val32 compute_frame_energy(const opus_val16 *pcm, int frame_size, in
/* Decides if DTX should be turned on (=1) or off (=0) */
static int decide_dtx_mode(opus_int activity, /* indicates if this frame contains speech/music */
- int *nb_no_activity_frames /* number of consecutive frames with no activity */
+ int *nb_no_activity_ms_Q1, /* number of consecutive milliseconds with no activity, in Q1 */
+ int frame_size_ms_Q1 /* number of miliseconds in this update, in Q1 */
)
{
if (!activity)
{
- /* The number of consecutive DTX frames should be within the allowed bounds */
- (*nb_no_activity_frames)++;
- if (*nb_no_activity_frames > NB_SPEECH_FRAMES_BEFORE_DTX)
+ /* The number of consecutive DTX frames should be within the allowed bounds.
+ Note that the allowed bound is defined in the Silk headers and assumes 20 ms
+ frames. As this function can be called with any frame length, a conversion to
+ miliseconds is done before the comparisons. */
+ (*nb_no_activity_ms_Q1) += frame_size_ms_Q1;
+ if (*nb_no_activity_ms_Q1 > NB_SPEECH_FRAMES_BEFORE_DTX*20*2)
{
- if (*nb_no_activity_frames <= (NB_SPEECH_FRAMES_BEFORE_DTX + MAX_CONSECUTIVE_DTX))
+ if (*nb_no_activity_ms_Q1 <= (NB_SPEECH_FRAMES_BEFORE_DTX + MAX_CONSECUTIVE_DTX)*20*2)
/* Valid frame for DTX! */
return 1;
else
- (*nb_no_activity_frames) = NB_SPEECH_FRAMES_BEFORE_DTX;
+ (*nb_no_activity_ms_Q1) = NB_SPEECH_FRAMES_BEFORE_DTX*20*2;
}
} else
- (*nb_no_activity_frames) = 0;
+ (*nb_no_activity_ms_Q1) = 0;
return 0;
}
@@ -2132,7 +2136,7 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_
#ifndef DISABLE_FLOAT_API
if (st->use_dtx && (analysis_info.valid || is_silence))
{
- if (decide_dtx_mode(activity, &st->nb_no_activity_frames))
+ if (decide_dtx_mode(activity, &st->nb_no_activity_ms_Q1, 2*1000*frame_size/st->Fs))
{
st->rangeFinal = 0;
data[0] = gen_toc(st->mode, st->Fs/frame_size, curr_bandwidth, st->stream_channels);
@@ -2140,7 +2144,7 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_
return 1;
}
} else {
- st->nb_no_activity_frames = 0;
+ st->nb_no_activity_ms_Q1 = 0;
}
#endif
@@ -2733,7 +2737,7 @@ int opus_encoder_ctl(OpusEncoder *st, int request, ...)
#ifndef DISABLE_FLOAT_API
else if (st->use_dtx) {
/* DTX determined by Opus. */
- *value = st->nb_no_activity_frames >= NB_SPEECH_FRAMES_BEFORE_DTX;
+ *value = st->nb_no_activity_ms_Q1 >= NB_SPEECH_FRAMES_BEFORE_DTX*20*2;
}
#endif
else {