MT#55283 add logic to discard old packets

If DTX audio has already been produced for a particular timestamp and a
late packet matching that timestamp is encountered, we should just
discard the packet instead of immediately doing a timestamp reset. This
prevents unwanted TS resets. Only do a timestamp reset if this happens
multiple times in a row, as we don't want to have to discard too much
audio.

Change-Id: I46c8c20b08787f7e45145bd88463bb6878f36f15
(cherry picked from commit a2fc205505)
(cherry picked from commit fdc847ca7d)
mr13.3.1
Richard Fuchs 6 months ago
parent be5887eb72
commit c7c3a70eaf

@ -132,6 +132,7 @@ struct dtx_buffer {
unsigned long head_ts;
uint32_t ssrc;
time_t start;
unsigned int discard_old_count;
};
struct dtx_packet {
struct transcode_packet *packet;
@ -3724,6 +3725,7 @@ static void __dtx_send_later(struct codec_timer *ct) {
unsigned long ts;
int p_left = 0;
long tv_diff = -1, ts_diff = 0;
bool discarded_old = false;
mutex_lock(&dtxb->lock);
@ -3748,8 +3750,16 @@ static void __dtx_send_later(struct codec_timer *ct) {
if (!dtxb->head_ts)
; // first packet
else if (ts_diff < 0)
else if (ts_diff_us < -100000 || dtxb->discard_old_count > 3)
ilogs(dtx, LOG_DEBUG, "DTX timestamp reset (from %lu to %lu)", dtxb->head_ts, ts);
else if (ts_diff < 0 || (ts_diff == 0 && discarded_old)) {
ilogs(dtx, LOG_DEBUG, "Discarding old packet (TS %lu < %lu, %" PRId64 " ms old)",
ts, dtxb->head_ts, -ts_diff);
t_queue_pop_head(&dtxb->packets);
dtx_packet_free(dtxp);
discarded_old = true;
continue; // try again
}
else if (ts_diff_us > MAX(20 * rtpe_config.dtx_delay, 200000))
ilogs(dtx, LOG_DEBUG, "DTX timestamp reset (from %lu to %lu = %lli ms)",
dtxb->head_ts, ts, ts_diff_us);
@ -3910,6 +3920,11 @@ static void __dtx_send_later(struct codec_timer *ct) {
int ptime = dtxb->ptime;
time_t dtxb_start = dtxb->start;
if (discarded_old)
dtxb->discard_old_count++;
else
dtxb->discard_old_count = 0;
mutex_unlock(&dtxb->lock);
rwlock_lock_r(&call->master_lock);

Loading…
Cancel
Save