FreeCalypso > hg > sipout-test-utils
diff libsip/sdp_gen.c @ 0:35c0d9f03c0a
beginning with sipout-test-voice,
a copy of sip-manual-out from themwi-system-sw
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 03 Mar 2024 23:20:19 -0800 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libsip/sdp_gen.c Sun Mar 03 23:20:19 2024 -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); +}