From f87c3ff362d9b4f4d6c105794a0063f65abdb584 Mon Sep 17 00:00:00 2001 From: Razvan Crainea Date: Fri, 3 Sep 2021 14:14:21 +0300 Subject: [PATCH] rtp_relay: proper detection of last available session (cherry picked from commit 9e18d404ff2a1eb416a57d2bf6e5d0d4e6caa10e) --- modules/rtp_relay/rtp_relay_ctx.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/modules/rtp_relay/rtp_relay_ctx.c b/modules/rtp_relay/rtp_relay_ctx.c index add112cdea1..88641eae6b2 100644 --- a/modules/rtp_relay/rtp_relay_ctx.c +++ b/modules/rtp_relay/rtp_relay_ctx.c @@ -814,13 +814,31 @@ static int rtp_relay_dlg_callbacks(struct dlg_cell *dlg, struct rtp_relay_ctx *c return -1; } +static int rtp_relay_sess_last(struct rtp_relay_ctx *ctx, + struct rtp_relay_sess *sess) +{ + struct list_head *it; + struct rtp_relay_sess *s; + int n = 0; + + list_for_each(it, &ctx->sessions) { + s = list_entry(it, struct rtp_relay_sess, list); + if (s->index == RTP_RELAY_ALL_BRANCHES) + continue; + if (sess && sess->index == s->index) + continue; + n++; + } + return n == 0; +} + static int rtp_relay_sess_success(struct rtp_relay_ctx *ctx, struct rtp_relay_sess *sess, struct cell *t) { struct dlg_cell *dlg; rtp_sess_set_success(sess); - if (list_is_singular(&ctx->sessions)) + if (rtp_relay_sess_last(ctx, sess)) rtp_relay_sess_merge(ctx, sess); if (!rtp_relay_ctx_established(ctx)) { dlg = rtp_relay_dlg.get_dlg(); @@ -848,7 +866,7 @@ static void rtp_relay_sess_failed(struct rtp_relay_ctx *ctx, rtp_sess_reset_pending(sess); list_del(&sess->list); - if (list_is_singular(&ctx->sessions)) { + if (rtp_relay_sess_last(ctx, NULL)) { last = list_last_entry(&ctx->sessions, struct rtp_relay_sess, list); if (rtp_sess_success(last)) rtp_relay_sess_merge(ctx, last);