Unverified Commit 16286a25 authored by Jesús de Vicente Peña's avatar Jesús de Vicente Peña Committed by Felicia Lim
Browse files

Sending refresh DTX packets every 400 ms independently of the encoded frame size.


Signed-off-by: Felicia Lim's avatarFelicia Lim <flim@google.com>
parent d633f523
Pipeline #2424 passed with stages
in 5 minutes and 41 seconds
...@@ -112,7 +112,7 @@ struct OpusEncoder { ...@@ -112,7 +112,7 @@ struct OpusEncoder {
opus_val16 delay_buffer[MAX_ENCODER_BUFFER*2]; opus_val16 delay_buffer[MAX_ENCODER_BUFFER*2];
#ifndef DISABLE_FLOAT_API #ifndef DISABLE_FLOAT_API
int detected_bandwidth; int detected_bandwidth;
int nb_no_activity_frames; int nb_no_activity_ms_Q1;
opus_val32 peak_signal_energy; opus_val32 peak_signal_energy;
#endif #endif
int nonfinal_frame; /* current frame is not the final in a packet */ 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 ...@@ -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) */ /* 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 */ 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) if (!activity)
{ {
/* The number of consecutive DTX frames should be within the allowed bounds */ /* The number of consecutive DTX frames should be within the allowed bounds.
(*nb_no_activity_frames)++; Note that the allowed bound is defined in the Silk headers and assumes 20 ms
if (*nb_no_activity_frames > NB_SPEECH_FRAMES_BEFORE_DTX) 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! */ /* Valid frame for DTX! */
return 1; return 1;
else else
(*nb_no_activity_frames) = NB_SPEECH_FRAMES_BEFORE_DTX; (*nb_no_activity_ms_Q1) = NB_SPEECH_FRAMES_BEFORE_DTX*20*2;
} }
} else } else
(*nb_no_activity_frames) = 0; (*nb_no_activity_ms_Q1) = 0;
return 0; return 0;
} }
...@@ -2132,7 +2136,7 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_ ...@@ -2132,7 +2136,7 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_
#ifndef DISABLE_FLOAT_API #ifndef DISABLE_FLOAT_API
if (st->use_dtx && (analysis_info.valid || is_silence)) 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; st->rangeFinal = 0;
data[0] = gen_toc(st->mode, st->Fs/frame_size, curr_bandwidth, st->stream_channels); 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_ ...@@ -2140,7 +2144,7 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_
return 1; return 1;
} }
} else { } else {
st->nb_no_activity_frames = 0; st->nb_no_activity_ms_Q1 = 0;
} }
#endif #endif
...@@ -2733,7 +2737,7 @@ int opus_encoder_ctl(OpusEncoder *st, int request, ...) ...@@ -2733,7 +2737,7 @@ int opus_encoder_ctl(OpusEncoder *st, int request, ...)
#ifndef DISABLE_FLOAT_API #ifndef DISABLE_FLOAT_API
else if (st->use_dtx) { else if (st->use_dtx) {
/* DTX determined by Opus. */ /* 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 #endif
else { else {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment