summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChris Hiszpanski <chris@liburtc.org>2021-05-04 11:51:56 -0700
committerChris Hiszpanski <chris@liburtc.org>2021-05-04 11:51:56 -0700
commitace18ff91774c6b2daf46e05157f96b75113e16f (patch)
tree21ab12e004f9cd20fb415016ab8d7a62636b4506 /src
parent1c80e4fad04638b4e6f141f49d27a0caf915d624 (diff)
Set session id in sdp answer
Diffstat (limited to 'src')
-rw-r--r--src/sdp.c7
-rw-r--r--src/urtc.c27
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 <arpa/inet.h> // inet_ntoa
#include <netinet/in.h> // IPPROTO_UDP
#include <sys/socket.h> // socket
+#include <sys/time.h> // gettimeofday
#include <sys/types.h>
#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);