FreeCalypso > hg > themwi-system-sw
annotate sip-manual-out/sdp_in.c @ 199:e6c7ced3c031
mgw: accept zero-length RTP payload as BFI
Mainline OsmoBTS now has an option (rtp continuous-streaming)
that causes it to emit an RTP packet every 20 ms without gaps,
sending a BFI marker in the form of zero-length RTP payload
when it has nothing else to send. These codec-independent
BFI markers don't indicate TAF, but this provision is a good
start. Accept this BFI packet format in themwi-mgw.
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 29 Mar 2023 20:23:43 -0800 |
parents | f8a33603288f |
children | d3c99b41fb04 |
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; |
192
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
191
diff
changeset
|
20 int 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 |
191
6ac96217c442
sip-manual-out: add SDP response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents:
163
diff
changeset
|
46 if (!check_sdp_present(msg)) { |
6ac96217c442
sip-manual-out: add SDP response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents:
163
diff
changeset
|
47 printf("INVITE response has no SDP!\n"); |
6ac96217c442
sip-manual-out: add SDP response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents:
163
diff
changeset
|
48 return; |
6ac96217c442
sip-manual-out: add SDP response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents:
163
diff
changeset
|
49 } |
156
0bacca1f2f7b
sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 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
|
51 if (rc < 0) { |
6ac96217c442
sip-manual-out: add SDP response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents:
163
diff
changeset
|
52 printf("SDP parse error: %d\n", rc); |
6ac96217c442
sip-manual-out: add SDP response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents:
163
diff
changeset
|
53 return; |
6ac96217c442
sip-manual-out: add SDP response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents:
163
diff
changeset
|
54 } |
156
0bacca1f2f7b
sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 switch (sdp_parse.codec_mask) { |
0bacca1f2f7b
sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 case SDP_CODEC_MASK_PCMU: |
0bacca1f2f7b
sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 case SDP_CODEC_MASK_BOTH: |
191
6ac96217c442
sip-manual-out: add SDP response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents:
163
diff
changeset
|
58 pcma_selected = 0; |
156
0bacca1f2f7b
sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 break; |
0bacca1f2f7b
sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 case SDP_CODEC_MASK_PCMA: |
0bacca1f2f7b
sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 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
|
62 pcma_selected = 1; |
156
0bacca1f2f7b
sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 break; |
0bacca1f2f7b
sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 default: |
191
6ac96217c442
sip-manual-out: add SDP response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents:
163
diff
changeset
|
65 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
|
66 return; |
0bacca1f2f7b
sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 } |
191
6ac96217c442
sip-manual-out: add SDP response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents:
163
diff
changeset
|
68 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
|
69 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
|
70 pcma_selected ? "PCMA" : "PCMU"); |
6ac96217c442
sip-manual-out: add SDP response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents:
163
diff
changeset
|
71 rtp_remote_addr.sin_family = AF_INET; |
6ac96217c442
sip-manual-out: add SDP response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents:
163
diff
changeset
|
72 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
|
73 rtp_remote_addr.sin_port = htons(sdp_parse.audio_port); |
192
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
191
diff
changeset
|
74 rtp_out_enable = 1; |
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
191
diff
changeset
|
75 assign_rtpout_ssrc(); |
156
0bacca1f2f7b
sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 } |