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