FreeCalypso > hg > sipout-test-utils
annotate test-voice/rtp_tx.c @ 14:f96153d15889
sipout-test-voice: implement play from file
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 11 May 2024 22:10:38 -0800 |
parents | 059b79c9f0c3 |
children | 71f01a834820 |
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 * In this module we implement outgoing RTP stream generation. |
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> |
14
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
6 #include <sys/file.h> |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
7 #include <sys/stat.h> |
0
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <sys/socket.h> |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <sys/time.h> |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <netinet/in.h> |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <stdio.h> |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <stdint.h> |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <stdlib.h> |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include <string.h> |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 #include <strings.h> |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 #include <unistd.h> |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 #include "../include/tmgw_const.h" |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 #include "../include/rtp_defs.h" |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 #include "../libutil/osmo_bits.h" |
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 extern struct sockaddr_in rtp_local_addr, rtp_remote_addr; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 extern int rtp_udp_fd, rtcp_udp_fd, pcma_selected; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 extern struct timeval cur_event_time; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 |
13
059b79c9f0c3
sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
25 static const uint8_t dmw_alaw[8] = |
059b79c9f0c3
sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
26 {0x34, 0x21, 0x21, 0x34, 0xB4, 0xA1, 0xA1, 0xB4}; |
059b79c9f0c3
sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
27 static const uint8_t dmw_ulaw[8] = |
059b79c9f0c3
sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
28 {0x1E, 0x0B, 0x0B, 0x1E, 0x9E, 0x8B, 0x8B, 0x9E}; |
059b79c9f0c3
sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
29 |
0
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 static uint32_t rtp_ssrc; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 static uint32_t rtp_out_ts; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 static uint16_t rtp_out_seq; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 static uint8_t pcm_fill_octet; |
13
059b79c9f0c3
sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
35 static int dmw_active; |
0
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 |
14
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
37 static uint8_t *play_buffer; |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
38 static unsigned play_buf_nframes, play_buf_ptr; |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
39 static int play_loop; |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
40 |
0
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 static uint16_t tfo_fill_buf[9], tfo_req_buf[7]; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 static uint16_t *is_out_ptr; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 static unsigned is_out_count; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 static int tfo_stop_req; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 void |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 assign_rtpout_ssrc() |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 { |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 rtp_ssrc = cur_event_time.tv_sec ^ cur_event_time.tv_usec ^ getpid(); |
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 |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 void |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 init_pcm_fill_octet() |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 { |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 if (pcma_selected) |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 pcm_fill_octet = 0xD5; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 else |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 pcm_fill_octet = 0xFF; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 } |
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 void |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 prepare_tfo_fill() |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 { |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 tfo_fill_buf[0] = 0x15A; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 tfo_fill_buf[1] = 0x1A9; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 tfo_fill_buf[2] = 0x129; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 tfo_fill_buf[3] = 0x15A; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 tfo_fill_buf[4] = 0x1A9; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 tfo_fill_buf[5] = 0x129; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 tfo_fill_buf[6] = 0x15A; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 tfo_fill_buf[7] = 0x1A9; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 tfo_fill_buf[8] = 0x129; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 } |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 static void |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 insert_is_msg(payload, word) |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 uint8_t *payload; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 uint16_t word; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 { |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 ubit_t is_bits[10]; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 uint8_t *bytep; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 unsigned n; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 uint16_to_bits(word, is_bits, 10); |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 for (n = 0; n < 10; n++) { |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 bytep = payload + n * 16; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 *bytep &= 0xFE; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 *bytep |= is_bits[n]; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 } |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 } |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 |
13
059b79c9f0c3
sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
92 static void |
059b79c9f0c3
sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
93 fill_with_dmw(buf) |
059b79c9f0c3
sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
94 uint8_t *buf; |
059b79c9f0c3
sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
95 { |
059b79c9f0c3
sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
96 const uint8_t *src; |
059b79c9f0c3
sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
97 unsigned n; |
059b79c9f0c3
sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
98 |
059b79c9f0c3
sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
99 if (pcma_selected) |
059b79c9f0c3
sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
100 src = dmw_alaw; |
059b79c9f0c3
sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
101 else |
059b79c9f0c3
sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
102 src = dmw_ulaw; |
059b79c9f0c3
sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
103 for (n = 0; n < 20; n++) { |
059b79c9f0c3
sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
104 memcpy(buf, src, 8); |
059b79c9f0c3
sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
105 buf += 8; |
059b79c9f0c3
sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
106 } |
059b79c9f0c3
sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
107 } |
059b79c9f0c3
sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
108 |
14
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
109 static void |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
110 fill_with_play(outbuf) |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
111 uint8_t *outbuf; |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
112 { |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
113 memcpy(outbuf, play_buffer + play_buf_ptr * 160, 160); |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
114 play_buf_ptr++; |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
115 if (play_buf_ptr < play_buf_nframes) |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
116 return; |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
117 if (play_loop) |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
118 play_buf_ptr = 0; |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
119 else { |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
120 free(play_buffer); |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
121 play_buffer = 0; |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
122 } |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
123 } |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
124 |
0
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 void |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 generate_rtp_packet() |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 { |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 struct rtp_packet pkt; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 socklen_t addrlen; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 pkt.v_p_x_cc = 0x80; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 pkt.m_pt = pcma_selected ? PSTN_CODEC_PCMA : PSTN_CODEC_PCMU; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 pkt.seq = htons(rtp_out_seq++); |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 pkt.tstamp = htonl(rtp_out_ts); |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 rtp_out_ts += 160; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 pkt.ssrc = rtp_ssrc; |
14
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
137 if (play_buffer) |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
138 fill_with_play(pkt.payload); |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
139 else if (dmw_active) |
13
059b79c9f0c3
sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
140 fill_with_dmw(pkt.payload); |
059b79c9f0c3
sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
141 else |
059b79c9f0c3
sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
142 memset(pkt.payload, pcm_fill_octet, RTP_MAX_PAYLOAD); |
0
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 if (is_out_count) { |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 insert_is_msg(pkt.payload, *is_out_ptr++); |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 is_out_count--; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 if (!is_out_count && !tfo_stop_req) { |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 is_out_ptr = tfo_req_buf; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 is_out_count = 7; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 } |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 } |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 addrlen = sizeof(struct sockaddr_in); |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 sendto(rtp_udp_fd, &pkt, RTP_PACKET_SIZE_PSTN, 0, |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 (struct sockaddr *) &rtp_remote_addr, addrlen); |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 } |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 void |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 set_pcm_fill_octet(oct) |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 unsigned oct; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 { |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 pcm_fill_octet = oct; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 } |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 void |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 send_tfo_req(sig, codec) |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 unsigned sig, codec; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
166 { |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
167 tfo_req_buf[0] = 0x15A; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
168 tfo_req_buf[1] = 0x1A9; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
169 tfo_req_buf[2] = 0x05D; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
170 tfo_req_buf[3] = 0x14E; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
171 tfo_req_buf[4] = 0x14B; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
172 encode_tfo_ext_words(sig, codec, 0, tfo_req_buf + 5); |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
173 is_out_ptr = tfo_fill_buf; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
174 is_out_count = 9; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
175 tfo_stop_req = 0; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
176 } |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 void |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
179 stop_tfo_out() |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
180 { |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
181 tfo_stop_req = 1; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
182 } |
13
059b79c9f0c3
sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
183 |
059b79c9f0c3
sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
184 void |
059b79c9f0c3
sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
185 cmd_dmw_on() |
059b79c9f0c3
sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
186 { |
059b79c9f0c3
sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
187 dmw_active = 1; |
059b79c9f0c3
sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
188 } |
059b79c9f0c3
sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
189 |
059b79c9f0c3
sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
190 void |
059b79c9f0c3
sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
191 cmd_dmw_off() |
059b79c9f0c3
sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
192 { |
059b79c9f0c3
sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
193 dmw_active = 0; |
059b79c9f0c3
sipout-test-voice: add DMW output mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
194 } |
14
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
195 |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
196 void |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
197 play_file_cmdop(filename, loop) |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
198 char *filename; |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
199 { |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
200 int fd; |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
201 struct stat st; |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
202 |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
203 if (play_buffer) { |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
204 fprintf(stderr, "error: file play already in progress\n"); |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
205 return; |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
206 } |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
207 fd = open(filename, O_RDONLY); |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
208 if (fd < 0) { |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
209 perror(filename); |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
210 return; |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
211 } |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
212 fstat(fd, &st); |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
213 if (!S_ISREG(st.st_mode)) { |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
214 close(fd); |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
215 fprintf(stderr, "error: %s is not a regular file\n", filename); |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
216 return; |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
217 } |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
218 if (st.st_size % 160) { |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
219 close(fd); |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
220 fprintf(stderr, |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
221 "error: size of %s is not a multiple of 160 bytes\n", |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
222 filename); |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
223 return; |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
224 } |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
225 play_buffer = malloc(st.st_size); |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
226 if (!play_buffer) { |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
227 close(fd); |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
228 fprintf(stderr, "unable to malloc buffer for %s\n", filename); |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
229 return; |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
230 } |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
231 read(fd, play_buffer, st.st_size); |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
232 close(fd); |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
233 play_buf_nframes = st.st_size / 160; |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
234 play_buf_ptr = 0; |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
235 play_loop = loop; |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
236 } |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
237 |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
238 void |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
239 play_file_stop() |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
240 { |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
241 if (!play_buffer) |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
242 return; |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
243 free(play_buffer); |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
244 play_buffer = 0; |
f96153d15889
sipout-test-voice: implement play from file
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
245 } |