comparison sip-manual-out/rtp.c @ 189:1266e024de6c

sip-manual-out: implement hunt for IS_Header in Rx RTP
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 17 Mar 2023 09:54:22 -0800
parents 6aecee01cf0a
children 62ecc0aa081f
comparison
equal deleted inserted replaced
188:6aecee01cf0a 189:1266e024de6c
25 static uint32_t rtp_ssrc; 25 static uint32_t rtp_ssrc;
26 static uint32_t rtp_last_ts; 26 static uint32_t rtp_last_ts;
27 static uint16_t rtp_last_seq; 27 static uint16_t rtp_last_seq;
28 static int got_some_rtcp; 28 static int got_some_rtcp;
29 29
30 static const uint8_t hdr_pattern[20] = {0, 1, 0, 1, 0, 1, 1, 0, 1, 0,
31 0, 1, 1, 0, 1, 0, 1, 0, 0, 1};
32
33 static uint8_t is_hunt_buf[320];
34
35 static void
36 reset_is_hunt()
37 {
38 memset(is_hunt_buf, 0xFF, 320);
39 }
40
41 static void
42 is_hunt_proc(input, input_pos)
43 uint8_t *input;
44 unsigned input_pos;
45 {
46 unsigned offset, n;
47
48 memmove(is_hunt_buf, is_hunt_buf + 16, 304);
49 memcpy(is_hunt_buf + 304, input, 16);
50 for (offset = 0; offset < 16; offset++) {
51 for (n = 0; n < 20; n++)
52 if ((is_hunt_buf[offset + n*16] & 1) != hdr_pattern[n])
53 break;
54 if (n == 20)
55 break;
56 }
57 if (n == 20)
58 printf("Found IS_Header, last bit offset %u\n",
59 input_pos * 16 + offset);
60 }
61
30 void 62 void
31 obtain_rtp_endp() 63 obtain_rtp_endp()
32 { 64 {
33 int rc; 65 int rc;
34 struct rtp_alloc_simple res; 66 struct rtp_alloc_simple res;
37 if (rc < 0) 69 if (rc < 0)
38 exit(1); /* error msg already printed */ 70 exit(1); /* error msg already printed */
39 bcopy(&res.pstn_addr, &rtp_local_addr, sizeof(struct sockaddr_in)); 71 bcopy(&res.pstn_addr, &rtp_local_addr, sizeof(struct sockaddr_in));
40 rtp_udp_fd = res.pstn_rtp_fd; 72 rtp_udp_fd = res.pstn_rtp_fd;
41 rtcp_udp_fd = res.pstn_rtcp_fd; 73 rtcp_udp_fd = res.pstn_rtcp_fd;
74 reset_is_hunt();
42 } 75 }
43 76
44 void 77 void
45 rtp_rx_select() 78 rtp_rx_select()
46 { 79 {
48 struct sockaddr_in sin_from; 81 struct sockaddr_in sin_from;
49 socklen_t addrlen; 82 socklen_t addrlen;
50 int16_t seq_delta; 83 int16_t seq_delta;
51 int32_t ts_delta; 84 int32_t ts_delta;
52 int rc; 85 int rc;
86 unsigned is_chunk;
53 87
54 addrlen = sizeof(struct sockaddr_in); 88 addrlen = sizeof(struct sockaddr_in);
55 rc = recvfrom(rtp_udp_fd, &pkt, sizeof pkt, 0, 89 rc = recvfrom(rtp_udp_fd, &pkt, sizeof pkt, 0,
56 (struct sockaddr *) &sin_from, &addrlen); 90 (struct sockaddr *) &sin_from, &addrlen);
57 if (rc < 0) 91 if (rc < 0)
75 if (rtp_start_flag && pkt.ssrc != rtp_ssrc) { 109 if (rtp_start_flag && pkt.ssrc != rtp_ssrc) {
76 if (!rtp_ssrc_chg_flag) { 110 if (!rtp_ssrc_chg_flag) {
77 printf("Rx RTP stream changed SSRC\n"); 111 printf("Rx RTP stream changed SSRC\n");
78 rtp_ssrc_chg_flag = 1; 112 rtp_ssrc_chg_flag = 1;
79 } 113 }
114 reset_is_hunt();
80 } else if (rtp_start_flag) { 115 } else if (rtp_start_flag) {
81 seq_delta = ntohs(pkt.seq) - rtp_last_seq; 116 seq_delta = ntohs(pkt.seq) - rtp_last_seq;
82 ts_delta = ntohl(pkt.tstamp) - rtp_last_ts; 117 ts_delta = ntohl(pkt.tstamp) - rtp_last_ts;
83 if (seq_delta == 0) { 118 if (seq_delta == 0) {
84 if (!rtp_seq_zero_flag) { 119 if (!rtp_seq_zero_flag) {
97 if (seq_delta != 1) { 132 if (seq_delta != 1) {
98 if (!rtp_seq_brk_flag) { 133 if (!rtp_seq_brk_flag) {
99 printf("Rx RTP stream seq break\n"); 134 printf("Rx RTP stream seq break\n");
100 rtp_seq_brk_flag = 1; 135 rtp_seq_brk_flag = 1;
101 } 136 }
137 reset_is_hunt();
102 } else if (ts_delta != 160) { 138 } else if (ts_delta != 160) {
103 if (!rtp_ts_brk_flag) { 139 if (!rtp_ts_brk_flag) {
104 printf("Rx RTP stream tstamp break\n"); 140 printf("Rx RTP stream tstamp break\n");
105 rtp_ts_brk_flag = 1; 141 rtp_ts_brk_flag = 1;
106 } 142 }
143 reset_is_hunt();
107 } 144 }
108 } 145 }
109 rtp_ssrc = pkt.ssrc; 146 rtp_ssrc = pkt.ssrc;
110 rtp_last_ts = ntohl(pkt.tstamp); 147 rtp_last_ts = ntohl(pkt.tstamp);
111 rtp_last_seq = ntohs(pkt.seq); 148 rtp_last_seq = ntohs(pkt.seq);
112 if (!rtp_start_flag) { 149 if (!rtp_start_flag) {
113 printf("Rx RTP stream begins with seq=%u ts=%u\n", 150 printf("Rx RTP stream begins with seq=%u ts=%u\n",
114 rtp_last_seq, rtp_last_ts); 151 rtp_last_seq, rtp_last_ts);
115 rtp_start_flag = 1; 152 rtp_start_flag = 1;
116 } 153 }
154 for (is_chunk = 0; is_chunk < 10; is_chunk++)
155 is_hunt_proc(pkt.payload + is_chunk * 16, is_chunk);
117 } 156 }
118 157
119 void 158 void
120 rtcp_rx_select() 159 rtcp_rx_select()
121 { 160 {