comparison test-voice/sdp_in.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 * In this module we handle SDP responses to our INVITE.
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 "../libsip/parse.h"
14 #include "../libsip/sdp.h"
15
16 extern char *get_single_header();
17 extern char *extract_to_tag();
18
19 struct sockaddr_in rtp_remote_addr;
20 int got_sdp_answer, pcma_selected, rtp_out_enable;
21
22 static
23 check_sdp_present(msg)
24 struct sip_pkt_rx *msg;
25 {
26 char *hval;
27
28 if (!msg->msg_body_len)
29 return 0;
30 hval = get_single_header(msg, "Content-Type", "c", (int *) 0);
31 if (!hval)
32 return 0;
33 if (!strcasecmp(hval, "application/sdp"))
34 return 1;
35 else
36 return 0;
37 }
38
39 void
40 extract_resp_sdp(msg)
41 struct sip_pkt_rx *msg;
42 {
43 struct sdp_parse sdp_parse;
44 int rc;
45
46 if (!check_sdp_present(msg))
47 return;
48 rc = parse_incoming_sdp(msg->msg_body, msg->msg_body_len, &sdp_parse);
49 if (rc < 0) {
50 printf("SDP parse error: %d\n", rc);
51 return;
52 }
53 switch (sdp_parse.codec_mask) {
54 case SDP_CODEC_MASK_PCMU:
55 case SDP_CODEC_MASK_BOTH:
56 pcma_selected = 0;
57 break;
58 case SDP_CODEC_MASK_PCMA:
59 case SDP_CODEC_MASK_BOTH | SDP_CODEC_MASK_PCMA_PREF:
60 pcma_selected = 1;
61 break;
62 default:
63 printf("SDP error: no supported codec\n");
64 return;
65 }
66 printf("SDP response: IP %s port %u codec %s\n",
67 inet_ntoa(sdp_parse.ip_addr), sdp_parse.audio_port,
68 pcma_selected ? "PCMA" : "PCMU");
69 rtp_remote_addr.sin_family = AF_INET;
70 rtp_remote_addr.sin_addr = sdp_parse.ip_addr;
71 rtp_remote_addr.sin_port = htons(sdp_parse.audio_port);
72 got_sdp_answer = 1;
73 }
74
75 void
76 invite_200_rtpout()
77 {
78 if (!got_sdp_answer) {
79 printf("INVITE response has no SDP!\n");
80 return;
81 }
82 rtp_out_enable = 1;
83 assign_rtpout_ssrc();
84 init_pcm_fill_octet();
85 prepare_tfo_fill();
86 }