From 8933c04be5a111b8b92a87d7e9503ce458de0924 Mon Sep 17 00:00:00 2001 From: Donat Zenichev Date: Mon, 23 Sep 2024 16:27:18 +0200 Subject: [PATCH] MT#60476 sdp_create: properly detect usable ps for session Look for the first usable (non-rejected, non-empty) media and ps, thereby to determine session-level attributes, if any. For that to work, it has to have `->selected_sfd` of the packet stream. Change-Id: Id4324864571bc78936aa16e235e3866e40860420 --- daemon/sdp.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/daemon/sdp.c b/daemon/sdp.c index c3b0b947a..56a24c0a5 100644 --- a/daemon/sdp.c +++ b/daemon/sdp.c @@ -3860,20 +3860,29 @@ int sdp_create(str *out, struct call_monologue *monologue, sdp_ng_flags *flags) const char *err = NULL; GString *s = NULL; const struct transport_protocol *prtp; + struct call_media *media = NULL; + struct packet_stream *first_ps = NULL; err = "Need at least one media"; if (!monologue->medias->len) goto err; /* look for the first usable (non-rejected, non-empty) media and ps, - * to determine session-level attributes, if any */ - struct call_media *media = monologue->medias->pdata[0]; - err = "No media stream"; - if (!media->streams.length) - goto err; - struct packet_stream *first_ps = media->streams.head->data; - err = "No packet stream"; - if (!first_ps->selected_sfd) + * thereby to determine session-level attributes, if any */ + for (int i = 0; i < monologue->medias->len; i++) { + media = monologue->medias->pdata[i]; + if (!media) + continue; + if (!media->streams.head) + continue; + first_ps = media->streams.head->data; + if (!first_ps->selected_sfd) + continue; + break; + } + + err = "No usable packet stream"; + if (!first_ps || !first_ps->selected_sfd) goto err; /* init new sdp */