comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:35c0d9f03c0a
1 /*
2 * Here we implement generation of outgoing SDP descriptions.
3 */
4
5 #include <sys/types.h>
6 #include <sys/socket.h>
7 #include <netinet/in.h>
8 #include <arpa/inet.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <strings.h>
13 #include "sdp.h"
14 #include "out_msg.h"
15
16 format_sdp_in_buffer(gen, buf, lenptr)
17 struct sdp_gen *gen;
18 char *buf;
19 unsigned *lenptr;
20 {
21 char *dp, *codec_list;
22
23 dp = buf;
24 strcpy(dp, "v=0\r\n");
25 dp += 5;
26 sprintf(dp, "o=- %u %u IN IP4 %s\r\n", gen->session_id, gen->version,
27 inet_ntoa(gen->owner_ip));
28 dp = index(dp, '\0');
29 strcpy(dp, "s=-\r\n");
30 dp += 5;
31 sprintf(dp, "c=IN IP4 %s\r\n", inet_ntoa(gen->conn_ip));
32 dp = index(dp, '\0');
33 strcpy(dp, "t=0 0\r\n");
34 dp += 7;
35 switch (gen->codec_mask) {
36 case SDP_CODEC_MASK_PCMU:
37 codec_list = "0";
38 break;
39 case SDP_CODEC_MASK_PCMA:
40 codec_list = "8";
41 break;
42 case SDP_CODEC_MASK_BOTH:
43 codec_list = "0 8";
44 break;
45 case SDP_CODEC_MASK_BOTH | SDP_CODEC_MASK_PCMA_PREF:
46 codec_list = "8 0";
47 break;
48 default:
49 return(-2);
50 }
51 sprintf(dp, "m=audio %u RTP/AVP %s\r\n", gen->conn_port, codec_list);
52 dp = index(dp, '\0');
53 if (gen->codec_mask & SDP_CODEC_MASK_PCMU) {
54 strcpy(dp, "a=rtpmap:0 PCMU/8000\r\n");
55 dp += 22;
56 }
57 if (gen->codec_mask & SDP_CODEC_MASK_PCMA) {
58 strcpy(dp, "a=rtpmap:8 PCMA/8000\r\n");
59 dp += 22;
60 }
61 strcpy(dp, "a=sendrecv\r\n");
62 dp += 12;
63 strcpy(dp, "a=ptime:20\r\n");
64 dp += 12;
65 *lenptr = (dp - buf);
66 return(0);
67 }
68
69 out_msg_finish_sdp(msg, gen)
70 struct sip_msg_out *msg;
71 struct sdp_gen *gen;
72 {
73 char sdp_buf[256];
74 unsigned sdp_len;
75 int rc;
76
77 rc = format_sdp_in_buffer(gen, sdp_buf, &sdp_len);
78 if (rc < 0)
79 return rc;
80 return out_msg_finish_body(msg, sdp_buf, sdp_len);
81 }