sip-lab 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -0
- package/a.js +280 -0
- package/binding.gyp +101 -0
- package/devjournal +435 -0
- package/index.js +68 -0
- package/install.sh +32 -0
- package/package.json +30 -0
- package/samples/late_negotiation.js +278 -0
- package/samples/simple.js +280 -0
- package/samples/sip_cancel.js +111 -0
- package/src/Makefile +42 -0
- package/src/README +3 -0
- package/src/addon.cpp +1418 -0
- package/src/event_templates.cpp +55 -0
- package/src/event_templates.hpp +27 -0
- package/src/idmanager.cpp +76 -0
- package/src/idmanager.hpp +26 -0
- package/src/log.cpp +18 -0
- package/src/log.hpp +15 -0
- package/src/packetdumper.cpp +234 -0
- package/src/packetdumper.hpp +67 -0
- package/src/pjmedia/Makefile +37 -0
- package/src/pjmedia/devjournal +26 -0
- package/src/pjmedia/include/chainlink/README +3 -0
- package/src/pjmedia/include/chainlink/chainlink.h +11 -0
- package/src/pjmedia/include/chainlink/chainlink_dtmfdet.h +56 -0
- package/src/pjmedia/include/chainlink/chainlink_tonegen.h +178 -0
- package/src/pjmedia/include/chainlink/chainlink_wav_port.h +231 -0
- package/src/pjmedia/include/chainlink/chainlink_wire_port.h +50 -0
- package/src/pjmedia/include/pjmedia/README +3 -0
- package/src/pjmedia/include/pjmedia/dtmfdet.h +74 -0
- package/src/pjmedia/src/chainlink/chainlink_dtmfdet.c +125 -0
- package/src/pjmedia/src/chainlink/chainlink_tonegen.c +901 -0
- package/src/pjmedia/src/chainlink/chainlink_wav_player.c +688 -0
- package/src/pjmedia/src/chainlink/chainlink_wav_writer.c +442 -0
- package/src/pjmedia/src/chainlink/chainlink_wire_port.c +93 -0
- package/src/pjmedia/src/pjmedia/dtmfdet.c +129 -0
- package/src/pjmedia/src/pjmedia/simpleua_dtmfdet.c +753 -0
- package/src/pjmedia/src/pjmedia/tonegen_dtmfdet.c +263 -0
- package/src/sip.cpp +4891 -0
- package/src/sip.hpp +64 -0
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
/* $Id: tonegen_dtmfdet.c 2408 2009-05-02 18:29:00Z mayamatakeshi $ */
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
|
|
4
|
+
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
|
|
5
|
+
*
|
|
6
|
+
* This program is free software; you can redistribute it and/or modify
|
|
7
|
+
* it under the terms of the GNU General Public License as published by
|
|
8
|
+
* the Free Software Foundation; either version 2 of the License, or
|
|
9
|
+
* (at your option) any later version.
|
|
10
|
+
*
|
|
11
|
+
* This program is distributed in the hope that it will be useful,
|
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
* GNU General Public License for more details.
|
|
15
|
+
*
|
|
16
|
+
* You should have received a copy of the GNU General Public License
|
|
17
|
+
* along with this program; if not, write to the Free Software
|
|
18
|
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* \page page_pjmedia_samples_tonegen_dtmfdet_c Samples:
|
|
23
|
+
*
|
|
24
|
+
* This is a simple program that connects tonegen with dtmfdest so that DTMF tones generated by tonegen will be detected by dtmfdest
|
|
25
|
+
* This file is pjsip-apps/src/samples/tonegen_dtmfdet.c
|
|
26
|
+
*
|
|
27
|
+
* \includelineno tonegen_dtmfdet.c
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
#include <pjmedia.h>
|
|
32
|
+
#include <pjlib.h>
|
|
33
|
+
#include <pjlib-util.h>
|
|
34
|
+
#include <pjlib.h>
|
|
35
|
+
|
|
36
|
+
#include "util.h"
|
|
37
|
+
|
|
38
|
+
#include <ctype.h>
|
|
39
|
+
|
|
40
|
+
#define SAMPLES_PER_FRAME 160
|
|
41
|
+
#define ON_DURATION 200
|
|
42
|
+
#define OFF_DURATION 50
|
|
43
|
+
|
|
44
|
+
#define THIS_FILE "tonegen_dtmfdet.c"
|
|
45
|
+
|
|
46
|
+
pjmedia_port *tonegen_port;
|
|
47
|
+
pjmedia_port *dtmfdet_port;
|
|
48
|
+
pjmedia_master_port *master_port;
|
|
49
|
+
|
|
50
|
+
char g_digits[] = "0123456789abcd*#";
|
|
51
|
+
|
|
52
|
+
char *g_pending_digits;
|
|
53
|
+
|
|
54
|
+
static void dtmf_callback(pjmedia_port *port, void *user_data, char digit)
|
|
55
|
+
{
|
|
56
|
+
digit = tolower(digit);
|
|
57
|
+
printf("Digit arrived %c\n", digit);
|
|
58
|
+
if(digit != g_pending_digits[0]) {
|
|
59
|
+
printf("Unexpected digit %c while waiting for %c\n",
|
|
60
|
+
digit,
|
|
61
|
+
g_pending_digits[0]);
|
|
62
|
+
return 1;
|
|
63
|
+
}
|
|
64
|
+
g_pending_digits++;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
pj_status_t add_dtmf(pjmedia_port *tonegen, char digit){
|
|
68
|
+
pjmedia_tone_digit tone;
|
|
69
|
+
|
|
70
|
+
tone.digit = digit;
|
|
71
|
+
tone.on_msec = ON_DURATION;
|
|
72
|
+
tone.off_msec = OFF_DURATION;
|
|
73
|
+
tone.volume = 0;
|
|
74
|
+
|
|
75
|
+
return pjmedia_tonegen_play_digits(tonegen, 1, &tone, 0);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
pj_status_t set_dtmf_map(pj_pool_t *pool, pjmedia_port *tonegen) {
|
|
79
|
+
/* From http://en.wikipedia.org/wiki/DTMF */
|
|
80
|
+
pjmedia_tone_digit_map *map;
|
|
81
|
+
map = (pjmedia_tone_digit_map*)pj_pool_alloc(pool, sizeof(pjmedia_tone_digit_map));
|
|
82
|
+
|
|
83
|
+
map->count = 16;
|
|
84
|
+
|
|
85
|
+
map->digits[0].digit = '0';
|
|
86
|
+
map->digits[0].freq1 = 941;
|
|
87
|
+
map->digits[0].freq2 = 1336;
|
|
88
|
+
|
|
89
|
+
map->digits[1].digit = '1';
|
|
90
|
+
map->digits[1].freq1 = 697;
|
|
91
|
+
map->digits[1].freq2 = 1209;
|
|
92
|
+
|
|
93
|
+
map->digits[2].digit = '2';
|
|
94
|
+
map->digits[2].freq1 = 697;
|
|
95
|
+
map->digits[2].freq2 = 1336;
|
|
96
|
+
|
|
97
|
+
map->digits[3].digit = '3';
|
|
98
|
+
map->digits[3].freq1 = 697;
|
|
99
|
+
map->digits[3].freq2 = 1477;
|
|
100
|
+
|
|
101
|
+
map->digits[4].digit = '4';
|
|
102
|
+
map->digits[4].freq1 = 770;
|
|
103
|
+
map->digits[4].freq2 = 1209;
|
|
104
|
+
|
|
105
|
+
map->digits[5].digit = '5';
|
|
106
|
+
map->digits[5].freq1 = 770;
|
|
107
|
+
map->digits[5].freq2 = 1336;
|
|
108
|
+
|
|
109
|
+
map->digits[6].digit = '6';
|
|
110
|
+
map->digits[6].freq1 = 770;
|
|
111
|
+
map->digits[6].freq2 = 1477;
|
|
112
|
+
|
|
113
|
+
map->digits[7].digit = '7';
|
|
114
|
+
map->digits[7].freq1 = 852;
|
|
115
|
+
map->digits[7].freq2 = 1209;
|
|
116
|
+
|
|
117
|
+
map->digits[8].digit = '8';
|
|
118
|
+
map->digits[8].freq1 = 852;
|
|
119
|
+
map->digits[8].freq2 = 1336;
|
|
120
|
+
|
|
121
|
+
map->digits[9].digit = '9';
|
|
122
|
+
map->digits[9].freq1 = 852;
|
|
123
|
+
map->digits[9].freq2 = 1477;
|
|
124
|
+
|
|
125
|
+
map->digits[10].digit = 'a';
|
|
126
|
+
map->digits[10].freq1 = 697;
|
|
127
|
+
map->digits[10].freq2= 1633;
|
|
128
|
+
|
|
129
|
+
map->digits[11].digit = 'b';
|
|
130
|
+
map->digits[11].freq1 = 770;
|
|
131
|
+
map->digits[11].freq2 = 1633;
|
|
132
|
+
|
|
133
|
+
map->digits[12].digit = 'c';
|
|
134
|
+
map->digits[12].freq1 = 852;
|
|
135
|
+
map->digits[12].freq2 = 1633;
|
|
136
|
+
|
|
137
|
+
map->digits[13].digit = 'd';
|
|
138
|
+
map->digits[13].freq1 = 941;
|
|
139
|
+
map->digits[13].freq2 = 1633;
|
|
140
|
+
|
|
141
|
+
map->digits[14].digit = '*';
|
|
142
|
+
map->digits[14].freq1 = 941;
|
|
143
|
+
map->digits[14].freq2 = 1209;
|
|
144
|
+
|
|
145
|
+
map->digits[15].digit = '#';
|
|
146
|
+
map->digits[15].freq1 = 941;
|
|
147
|
+
map->digits[15].freq2 = 1477;
|
|
148
|
+
|
|
149
|
+
return pjmedia_tonegen_set_digit_map(tonegen,map);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/*
|
|
153
|
+
* main()
|
|
154
|
+
*/
|
|
155
|
+
int main()
|
|
156
|
+
{
|
|
157
|
+
pj_caching_pool cp;
|
|
158
|
+
pjmedia_endpt *med_endpt;
|
|
159
|
+
pj_pool_t *pool;
|
|
160
|
+
unsigned i;
|
|
161
|
+
pj_status_t status;
|
|
162
|
+
char *pc = g_digits;
|
|
163
|
+
|
|
164
|
+
/* Must init PJLIB first: */
|
|
165
|
+
status = pj_init();
|
|
166
|
+
PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1);
|
|
167
|
+
|
|
168
|
+
/* Must create a pool factory before we can allocate any memory. */
|
|
169
|
+
pj_caching_pool_init(&cp, &pj_pool_factory_default_policy, 0);
|
|
170
|
+
|
|
171
|
+
/*
|
|
172
|
+
* Initialize media endpoint.
|
|
173
|
+
* This will implicitly initialize PJMEDIA too.
|
|
174
|
+
*/
|
|
175
|
+
status = pjmedia_endpt_create(&cp.factory, NULL, 1, &med_endpt);
|
|
176
|
+
PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1);
|
|
177
|
+
|
|
178
|
+
/* Create memory pool for our file player */
|
|
179
|
+
pool = pj_pool_create( &cp.factory, /* pool factory */
|
|
180
|
+
"app", /* pool name. */
|
|
181
|
+
4000, /* init size */
|
|
182
|
+
4000, /* increment size */
|
|
183
|
+
NULL /* callback on error */
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
status = pjmedia_tonegen_create(pool, 8000, 1, SAMPLES_PER_FRAME, 16, 0, &tonegen_port);
|
|
187
|
+
if (status != PJ_SUCCESS){
|
|
188
|
+
app_perror(THIS_FILE, "Unable to create tonegen",status);
|
|
189
|
+
return 1;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
status = set_dtmf_map(pool, tonegen_port);
|
|
193
|
+
if (status != PJ_SUCCESS){
|
|
194
|
+
app_perror(THIS_FILE, "Failed to set digit map", status);
|
|
195
|
+
return 1;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
while(*pc){
|
|
200
|
+
char c = *pc++;
|
|
201
|
+
status = add_dtmf(tonegen_port, c);
|
|
202
|
+
printf("Adding digit %c\n",c);
|
|
203
|
+
if(status != PJ_SUCCESS){
|
|
204
|
+
app_perror(THIS_FILE, "Failed to add dtmf", status);
|
|
205
|
+
return 1;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
g_pending_digits = g_digits;
|
|
209
|
+
|
|
210
|
+
status = pjmedia_dtmfdet_create(pool,
|
|
211
|
+
8000,
|
|
212
|
+
1,
|
|
213
|
+
SAMPLES_PER_FRAME,
|
|
214
|
+
16,
|
|
215
|
+
dtmf_callback,
|
|
216
|
+
0,
|
|
217
|
+
&dtmfdet_port);
|
|
218
|
+
if (status != PJ_SUCCESS){
|
|
219
|
+
app_perror(THIS_FILE, "Unable to create dtmfdet", status);
|
|
220
|
+
return 1;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
status = pjmedia_master_port_create(pool,
|
|
224
|
+
tonegen_port,
|
|
225
|
+
dtmfdet_port,
|
|
226
|
+
0,
|
|
227
|
+
&master_port);
|
|
228
|
+
if (status != PJ_SUCCESS) {
|
|
229
|
+
app_perror(THIS_FILE, "Unable to create master port", status);
|
|
230
|
+
return 1;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
status = pjmedia_master_port_start(master_port);
|
|
234
|
+
if (status != PJ_SUCCESS) {
|
|
235
|
+
app_perror(THIS_FILE, "Unable to start master port", status);
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
while(*g_pending_digits){
|
|
240
|
+
sleep(1);
|
|
241
|
+
}
|
|
242
|
+
printf("All expected digits received\n");
|
|
243
|
+
|
|
244
|
+
pjmedia_master_port_stop(master_port);
|
|
245
|
+
|
|
246
|
+
pjmedia_master_port_destroy(master_port, 1);
|
|
247
|
+
|
|
248
|
+
/* Release application pool */
|
|
249
|
+
pj_pool_release( pool );
|
|
250
|
+
|
|
251
|
+
/* Destroy media endpoint. */
|
|
252
|
+
pjmedia_endpt_destroy( med_endpt );
|
|
253
|
+
|
|
254
|
+
/* Destroy pool factory */
|
|
255
|
+
pj_caching_pool_destroy( &cp );
|
|
256
|
+
|
|
257
|
+
/* Shutdown PJLIB */
|
|
258
|
+
pj_shutdown();
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
/* Done. */
|
|
262
|
+
return 0;
|
|
263
|
+
}
|