Skip to content

Commit

Permalink
rtp_relay: proper detection of last available session
Browse files Browse the repository at this point in the history
(cherry picked from commit 9e18d40)
  • Loading branch information
razvancrainea committed Sep 3, 2021
1 parent d3b93d6 commit f87c3ff
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions modules/rtp_relay/rtp_relay_ctx.c
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f87c3ff

Please sign in to comment.