annotate sip-manual-out/sdp_in.c @ 275:def9f6e4f49e default tip

doc/Use-outside-USA: Fake-NANP-numbers article is here
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 27 Nov 2023 21:49:19 -0800
parents 10a4b0b0a239
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
156
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
191
6ac96217c442 sip-manual-out: add SDP response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents: 163
diff changeset
2 * In this module we handle SDP responses to our INVITE.
156
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/socket.h>
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <netinet/in.h>
191
6ac96217c442 sip-manual-out: add SDP response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents: 163
diff changeset
8 #include <arpa/inet.h>
156
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdio.h>
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdlib.h>
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <string.h>
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <strings.h>
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include "../libsip/parse.h"
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include "../libsip/sdp.h"
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 extern char *get_single_header();
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 extern char *extract_to_tag();
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
191
6ac96217c442 sip-manual-out: add SDP response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents: 163
diff changeset
19 struct sockaddr_in rtp_remote_addr;
214
10a4b0b0a239 sip-manual-out: parse SDP for all responses, not just 200
Mychaela Falconia <falcon@freecalypso.org>
parents: 211
diff changeset
20 int got_sdp_answer, pcma_selected, rtp_out_enable;
156
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 static
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 check_sdp_present(msg)
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 struct sip_pkt_rx *msg;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 {
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 char *hval;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 if (!msg->msg_body_len)
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 return 0;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 hval = get_single_header(msg, "Content-Type", "c", (int *) 0);
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 if (!hval)
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 return 0;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 if (!strcasecmp(hval, "application/sdp"))
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 return 1;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 else
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 return 0;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 }
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38
191
6ac96217c442 sip-manual-out: add SDP response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents: 163
diff changeset
39 void
6ac96217c442 sip-manual-out: add SDP response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents: 163
diff changeset
40 extract_resp_sdp(msg)
156
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 struct sip_pkt_rx *msg;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 {
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 struct sdp_parse sdp_parse;
191
6ac96217c442 sip-manual-out: add SDP response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents: 163
diff changeset
44 int rc;
156
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45
214
10a4b0b0a239 sip-manual-out: parse SDP for all responses, not just 200
Mychaela Falconia <falcon@freecalypso.org>
parents: 211
diff changeset
46 if (!check_sdp_present(msg))
191
6ac96217c442 sip-manual-out: add SDP response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents: 163
diff changeset
47 return;
156
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 rc = parse_incoming_sdp(msg->msg_body, msg->msg_body_len, &sdp_parse);
191
6ac96217c442 sip-manual-out: add SDP response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents: 163
diff changeset
49 if (rc < 0) {
6ac96217c442 sip-manual-out: add SDP response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents: 163
diff changeset
50 printf("SDP parse error: %d\n", rc);
6ac96217c442 sip-manual-out: add SDP response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents: 163
diff changeset
51 return;
6ac96217c442 sip-manual-out: add SDP response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents: 163
diff changeset
52 }
156
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 switch (sdp_parse.codec_mask) {
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 case SDP_CODEC_MASK_PCMU:
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 case SDP_CODEC_MASK_BOTH:
191
6ac96217c442 sip-manual-out: add SDP response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents: 163
diff changeset
56 pcma_selected = 0;
156
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 break;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 case SDP_CODEC_MASK_PCMA:
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 case SDP_CODEC_MASK_BOTH | SDP_CODEC_MASK_PCMA_PREF:
191
6ac96217c442 sip-manual-out: add SDP response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents: 163
diff changeset
60 pcma_selected = 1;
156
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 break;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 default:
191
6ac96217c442 sip-manual-out: add SDP response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents: 163
diff changeset
63 printf("SDP error: no supported codec\n");
156
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 return;
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 }
191
6ac96217c442 sip-manual-out: add SDP response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents: 163
diff changeset
66 printf("SDP response: IP %s port %u codec %s\n",
6ac96217c442 sip-manual-out: add SDP response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents: 163
diff changeset
67 inet_ntoa(sdp_parse.ip_addr), sdp_parse.audio_port,
6ac96217c442 sip-manual-out: add SDP response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents: 163
diff changeset
68 pcma_selected ? "PCMA" : "PCMU");
6ac96217c442 sip-manual-out: add SDP response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents: 163
diff changeset
69 rtp_remote_addr.sin_family = AF_INET;
6ac96217c442 sip-manual-out: add SDP response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents: 163
diff changeset
70 rtp_remote_addr.sin_addr = sdp_parse.ip_addr;
6ac96217c442 sip-manual-out: add SDP response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents: 163
diff changeset
71 rtp_remote_addr.sin_port = htons(sdp_parse.audio_port);
214
10a4b0b0a239 sip-manual-out: parse SDP for all responses, not just 200
Mychaela Falconia <falcon@freecalypso.org>
parents: 211
diff changeset
72 got_sdp_answer = 1;
10a4b0b0a239 sip-manual-out: parse SDP for all responses, not just 200
Mychaela Falconia <falcon@freecalypso.org>
parents: 211
diff changeset
73 }
10a4b0b0a239 sip-manual-out: parse SDP for all responses, not just 200
Mychaela Falconia <falcon@freecalypso.org>
parents: 211
diff changeset
74
10a4b0b0a239 sip-manual-out: parse SDP for all responses, not just 200
Mychaela Falconia <falcon@freecalypso.org>
parents: 211
diff changeset
75 void
10a4b0b0a239 sip-manual-out: parse SDP for all responses, not just 200
Mychaela Falconia <falcon@freecalypso.org>
parents: 211
diff changeset
76 invite_200_rtpout()
10a4b0b0a239 sip-manual-out: parse SDP for all responses, not just 200
Mychaela Falconia <falcon@freecalypso.org>
parents: 211
diff changeset
77 {
10a4b0b0a239 sip-manual-out: parse SDP for all responses, not just 200
Mychaela Falconia <falcon@freecalypso.org>
parents: 211
diff changeset
78 if (!got_sdp_answer) {
10a4b0b0a239 sip-manual-out: parse SDP for all responses, not just 200
Mychaela Falconia <falcon@freecalypso.org>
parents: 211
diff changeset
79 printf("INVITE response has no SDP!\n");
10a4b0b0a239 sip-manual-out: parse SDP for all responses, not just 200
Mychaela Falconia <falcon@freecalypso.org>
parents: 211
diff changeset
80 return;
10a4b0b0a239 sip-manual-out: parse SDP for all responses, not just 200
Mychaela Falconia <falcon@freecalypso.org>
parents: 211
diff changeset
81 }
192
f8a33603288f sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents: 191
diff changeset
82 rtp_out_enable = 1;
f8a33603288f sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents: 191
diff changeset
83 assign_rtpout_ssrc();
211
fbfa72b114e8 sip-manual-out: prep for making PCM fill octet changeable
Mychaela Falconia <falcon@freecalypso.org>
parents: 201
diff changeset
84 init_pcm_fill_octet();
201
d3c99b41fb04 sip-manual-out TFO: rework for continuous output of TFO_REQ
Mychaela Falconia <falcon@freecalypso.org>
parents: 192
diff changeset
85 prepare_tfo_fill();
156
0bacca1f2f7b sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 }