changeset 54:9f045dcff60e

libsip: SDP generation implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 08 Sep 2022 12:02:22 -0800
parents 2423f3aac4ce
children f1d59210f7b2
files libsip/Makefile libsip/sdp_gen.c
diffstat 2 files changed, 82 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libsip/Makefile	Thu Sep 08 10:45:50 2022 -0800
+++ b/libsip/Makefile	Thu Sep 08 12:02:22 2022 -0800
@@ -1,6 +1,6 @@
 CC=	gcc
 CFLAGS=	-O2
-OBJS=	get_header.o grok_from.o out_msg.o primary_parse.o req_supp.o \
+OBJS=	get_header.o grok_from.o out_msg.o primary_parse.o req_supp.o sdp_gen.o\
 	sdp_parse.o uas_basic.o uri_utils.o
 LIB=	libsip.a
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libsip/sdp_gen.c	Thu Sep 08 12:02:22 2022 -0800
@@ -0,0 +1,81 @@
+/*
+ * Here we implement generation of outgoing SDP descriptions.
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include "sdp.h"
+#include "out_msg.h"
+
+format_sdp_in_buffer(gen, buf, lenptr)
+	struct sdp_gen *gen;
+	char *buf;
+	unsigned *lenptr;
+{
+	char *dp, *codec_list;
+
+	dp = buf;
+	strcpy(dp, "v=0\r\n");
+	dp += 5;
+	sprintf(dp, "o=- %u %u IN IP4 %s\r\n", gen->session_id, gen->version,
+		inet_ntoa(gen->owner_ip));
+	dp = index(dp, '\0');
+	strcpy(dp, "s=-\r\n");
+	dp += 5;
+	sprintf(dp, "c=IN IP4 %s\r\n", inet_ntoa(gen->conn_ip));
+	dp = index(dp, '\0');
+	strcpy(dp, "t=0 0\r\n");
+	dp += 7;
+	switch (gen->codec_mask) {
+	case SDP_CODEC_MASK_PCMU:
+		codec_list = "0";
+		break;
+	case SDP_CODEC_MASK_PCMA:
+		codec_list = "8";
+		break;
+	case SDP_CODEC_MASK_BOTH:
+		codec_list = "0 8";
+		break;
+	case SDP_CODEC_MASK_BOTH | SDP_CODEC_MASK_PCMA_PREF:
+		codec_list = "8 0";
+		break;
+	default:
+		return(-2);
+	}
+	sprintf(dp, "m=audio %u RTP/AVP %s\r\n", gen->conn_port, codec_list);
+	dp = index(dp, '\0');
+	if (gen->codec_mask & SDP_CODEC_MASK_PCMU) {
+		strcpy(dp, "a=rtpmap:0 PCMU/8000\r\n");
+		dp += 22;
+	}
+	if (gen->codec_mask & SDP_CODEC_MASK_PCMA) {
+		strcpy(dp, "a=rtpmap:8 PCMA/8000\r\n");
+		dp += 22;
+	}
+	strcpy(dp, "a=sendrecv\r\n");
+	dp += 12;
+	strcpy(dp, "a=ptime:20\r\n");
+	dp += 12;
+	*lenptr = (dp - buf);
+	return(0);
+}
+
+out_msg_finish_sdp(msg, gen)
+	struct sip_msg_out *msg;
+	struct sdp_gen *gen;
+{
+	char sdp_buf[256];
+	unsigned sdp_len;
+	int rc;
+
+	rc = format_sdp_in_buffer(gen, sdp_buf, &sdp_len);
+	if (rc < 0)
+		return rc;
+	return out_msg_finish_body(msg, sdp_buf, sdp_len);
+}