module-rtp-sap: Fix sending first session SDP

We don't initially have the SAP socket open, so we can't generate an SDP
(because we don't have the interface address). So in addition to the
regular flow, also trigger SDP creation after opening the SAP socket, so
we can have a valid SDP for the announcement.

The sending was broken in commit a44afd84. We delay the SAP fd openeing
for reasons explained in commit f2f204d6).
This commit is contained in:
Arun Raghavan 2025-02-15 16:36:57 -05:00
parent f8272c767f
commit dbf0442c7e

View file

@ -827,6 +827,18 @@ static int send_sap(struct impl *impl, struct session *sess, bool bye)
impl->sap_fd = fd;
}
/* For the first session, we might not yet have an SDP because the
* socket needs to be open for us to get the interface address (which
* happens above. So let's create the SDP now, if needed. */
if (!sess->has_sdp) {
res = make_sdp(impl, sess, sess->sdp, sizeof(sess->sdp));
if (res != 0) {
pw_log_error("Failed to create SDP: %s", spa_strerror(res));
return res;
}
sess->has_sdp = true;
}
spa_zero(header);
header.v = 1;
header.t = bye;
@ -998,10 +1010,13 @@ static struct session *session_new_announce(struct impl *impl, struct node *node
spa_strbuf_append(&buf, "%s%s", count++ > 0 ? ", " : "", v);
}
}
make_sdp(impl, sess, buffer, sizeof(buffer));
/* see if we can make an SDP, will fail for the first session because we
* haven't got the SAP socket open yet */
res = make_sdp(impl, sess, buffer, sizeof(buffer));
/* we had no sdp or something changed */
if (!sess->has_sdp || strcmp(buffer, sess->sdp) != 0) {
if (res == 0 && (!sess->has_sdp || strcmp(buffer, sess->sdp) != 0)) {
/* send bye on the old session */
send_sap(impl, sess, 1);
@ -1027,10 +1042,15 @@ static struct session *session_new_announce(struct impl *impl, struct node *node
sdp->session_version = sdp->t_ntp;
}
/* make an updated SDP for sending */
make_sdp(impl, sess, sess->sdp, sizeof(sess->sdp));
sess->has_sdp = true;
/* make an updated SDP for sending, this should not actually fail */
res = make_sdp(impl, sess, sess->sdp, sizeof(sess->sdp));
if (res == 0)
sess->has_sdp = true;
else
pw_log_error("Failed to create SDP: %s", spa_strerror(res));
}
send_sap(impl, sess, 0);
return sess;