From ace18ff91774c6b2daf46e05157f96b75113e16f Mon Sep 17 00:00:00 2001 From: Chris Hiszpanski Date: Tue, 4 May 2021 11:51:56 -0700 Subject: Set session id in sdp answer --- src/sdp.c | 7 +++---- src/urtc.c | 27 +++++++++++++++++++++------ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/sdp.c b/src/sdp.c index 154088c..ef73efc 100644 --- a/src/sdp.c +++ b/src/sdp.c @@ -497,9 +497,8 @@ int sdp_serialize(char *dst, size_t len, const struct sdp *src) { // write originator and session identifier n = snprintf(dst, len, - "o=liburtc/0.0.0 %s %s IN IP4 127.0.0.1\n", - src->session_id, - src->session_version + "o=- %s 0 IN IP4 127.0.0.1\n", + src->session_id ); if (n < 0) return -URTC_ERR_SDP_MALFORMED; if (n >= len) return -URTC_ERR_SDP_MALFORMED; @@ -692,7 +691,7 @@ int sdp_serialize(char *dst, size_t len, const struct sdp *src) { // write media attribute: media id // TODO fix hardcoded media id - n = snprintf(dst, len, "a=mid:0\n"); + n = snprintf(dst, len, "a=mid:video\n"); if (n < 0) return -URTC_ERR_SDP_MALFORMED; if (n >= len) return -URTC_ERR_SDP_MALFORMED; dst += n; diff --git a/src/urtc.c b/src/urtc.c index 47c32b8..7cbf790 100644 --- a/src/urtc.c +++ b/src/urtc.c @@ -37,6 +37,7 @@ #include // inet_ntoa #include // IPPROTO_UDP #include // socket +#include // gettimeofday #include #include "b64.h" // b64_encode @@ -427,15 +428,29 @@ int urtc_add_ice_candidate(struct peerconn *pc, const char *cand) { } int urtc_create_answer(struct peerconn *pc, char *answer, size_t size) { - char pwd[18]; // 24 base64 characters - char ufrag[3]; // 4 base64 characters + // write unique session id + { + struct timeval now; + if (-1 == gettimeofday(&now, NULL)) { + return -1; + } + snprintf(pc->ldesc.session_id, sizeof(pc->ldesc.session_id), + "%lu", now.tv_sec); + } - prng(pwd, sizeof(pwd)); - prng(ufrag, sizeof(ufrag)); + strcpy(pc->ldesc.mid[0], "video"); - b64_encode(pc->ldesc.pwd, pwd, sizeof(pwd)); - b64_encode(pc->ldesc.ufrag, ufrag, sizeof(ufrag)); + // write ice-pwd and ice-ufrag + { + char pwd[18]; // 24 base64 characters + char ufrag[3]; // 4 base64 characters + prng(pwd, sizeof(pwd)); + prng(ufrag, sizeof(ufrag)); + b64_encode(pc->ldesc.pwd, pwd, sizeof(pwd)); + b64_encode(pc->ldesc.ufrag, ufrag, sizeof(ufrag)); + } + pc->ldesc.ice_options.trickle = true; pc->ldesc.mode = SDP_MODE_SEND_ONLY; return sdp_serialize(answer, size, &pc->ldesc); -- cgit v1.2.3