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,178 @@
|
|
|
1
|
+
#ifndef __CHAINLINK_TONEGEN_PORT_H__
|
|
2
|
+
#define __CHAINLINK_TONEGEN_PORT_H__
|
|
3
|
+
|
|
4
|
+
#include <pjmedia/port.h>
|
|
5
|
+
#include <pjmedia/tonegen.h>
|
|
6
|
+
|
|
7
|
+
PJ_BEGIN_DECL
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Create an instance of tone generator with the specified parameters.
|
|
11
|
+
* When the tone generator is first created, it will be loaded with the
|
|
12
|
+
* default digit map.
|
|
13
|
+
*
|
|
14
|
+
* @param pool Pool to allocate memory for the port structure.
|
|
15
|
+
* @param clock_rate Sampling rate.
|
|
16
|
+
* @param channel_count Number of channels. Currently only mono and stereo
|
|
17
|
+
* are supported.
|
|
18
|
+
* @param samples_per_frame Number of samples per frame.
|
|
19
|
+
* @param bits_per_sample Number of bits per sample. This version of PJMEDIA
|
|
20
|
+
* only supports 16bit per sample.
|
|
21
|
+
* @param options Option flags. Application may specify
|
|
22
|
+
* PJMEDIA_TONEGEN_LOOP to play the tone in a loop.
|
|
23
|
+
* @param p_port Pointer to receive the port instance.
|
|
24
|
+
*
|
|
25
|
+
* @return PJ_SUCCESS on success, or the appropriate
|
|
26
|
+
* error code.
|
|
27
|
+
*/
|
|
28
|
+
PJ_DECL(pj_status_t) chainlink_tonegen_create(pj_pool_t *pool,
|
|
29
|
+
unsigned clock_rate,
|
|
30
|
+
unsigned channel_count,
|
|
31
|
+
unsigned samples_per_frame,
|
|
32
|
+
unsigned bits_per_sample,
|
|
33
|
+
unsigned options,
|
|
34
|
+
pjmedia_port **p_port);
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Create an instance of tone generator with the specified parameters.
|
|
39
|
+
* When the tone generator is first created, it will be loaded with the
|
|
40
|
+
* default digit map.
|
|
41
|
+
*
|
|
42
|
+
* @param pool Pool to allocate memory for the port structure.
|
|
43
|
+
* @param name Optional name for the tone generator.
|
|
44
|
+
* @param clock_rate Sampling rate.
|
|
45
|
+
* @param channel_count Number of channels. Currently only mono and stereo
|
|
46
|
+
* are supported.
|
|
47
|
+
* @param samples_per_frame Number of samples per frame.
|
|
48
|
+
* @param bits_per_sample Number of bits per sample. This version of PJMEDIA
|
|
49
|
+
* only supports 16bit per sample.
|
|
50
|
+
* @param options Option flags. Application may specify
|
|
51
|
+
* PJMEDIA_TONEGEN_LOOP to play the tone in a loop.
|
|
52
|
+
* @param p_port Pointer to receive the port instance.
|
|
53
|
+
*
|
|
54
|
+
* @return PJ_SUCCESS on success, or the appropriate
|
|
55
|
+
* error code.
|
|
56
|
+
*/
|
|
57
|
+
PJ_DECL(pj_status_t) chainlink_tonegen_create2(pj_pool_t *pool,
|
|
58
|
+
const pj_str_t *name,
|
|
59
|
+
unsigned clock_rate,
|
|
60
|
+
unsigned channel_count,
|
|
61
|
+
unsigned samples_per_frame,
|
|
62
|
+
unsigned bits_per_sample,
|
|
63
|
+
unsigned options,
|
|
64
|
+
pjmedia_port **p_port);
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Check if the tone generator is still busy producing some tones.
|
|
69
|
+
*
|
|
70
|
+
* @param tonegen The tone generator instance.
|
|
71
|
+
*
|
|
72
|
+
* @return Non-zero if busy.
|
|
73
|
+
*/
|
|
74
|
+
PJ_DECL(pj_bool_t) chainlink_tonegen_is_busy(pjmedia_port *tonegen);
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Instruct the tone generator to stop current processing.
|
|
79
|
+
*
|
|
80
|
+
* @param tonegen The tone generator instance.
|
|
81
|
+
*
|
|
82
|
+
* @return PJ_SUCCESS on success.
|
|
83
|
+
*/
|
|
84
|
+
PJ_DECL(pj_status_t) chainlink_tonegen_stop(pjmedia_port *tonegen);
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Rewind the playback. This will start the playback to the first
|
|
89
|
+
* tone in the playback list.
|
|
90
|
+
*
|
|
91
|
+
* @param tonegen The tone generator instance.
|
|
92
|
+
*
|
|
93
|
+
* @return PJ_SUCCESS on success.
|
|
94
|
+
*/
|
|
95
|
+
PJ_DECL(pj_status_t) chainlink_tonegen_rewind(pjmedia_port *tonegen);
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Instruct the tone generator to play single or dual frequency tones
|
|
100
|
+
* with the specified duration. The new tones will be appended to currently
|
|
101
|
+
* playing tones, unless #pjmedia_tonegen_stop() is called before calling
|
|
102
|
+
* this function. The playback will begin as soon as the first get_frame()
|
|
103
|
+
* is called to the generator.
|
|
104
|
+
*
|
|
105
|
+
* @param tonegen The tone generator instance.
|
|
106
|
+
* @param count The number of tones in the array.
|
|
107
|
+
* @param tones Array of tones to be played.
|
|
108
|
+
* @param options Option flags. Application may specify
|
|
109
|
+
* PJMEDIA_TONEGEN_LOOP to play the tone in a loop.
|
|
110
|
+
*
|
|
111
|
+
* @return PJ_SUCCESS on success, or PJ_ETOOMANY if
|
|
112
|
+
* there are too many digits in the queue.
|
|
113
|
+
*/
|
|
114
|
+
PJ_DECL(pj_status_t) chainlink_tonegen_play(pjmedia_port *tonegen,
|
|
115
|
+
unsigned count,
|
|
116
|
+
const pjmedia_tone_desc tones[],
|
|
117
|
+
unsigned options);
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Instruct the tone generator to play multiple MF digits with each of
|
|
121
|
+
* the digits having individual ON/OFF duration. Each of the digit in the
|
|
122
|
+
* digit array must have the corresponding descriptor in the digit map.
|
|
123
|
+
* The new tones will be appended to currently playing tones, unless
|
|
124
|
+
* #pjmedia_tonegen_stop() is called before calling this function.
|
|
125
|
+
* The playback will begin as soon as the first get_frame() is called
|
|
126
|
+
* to the generator.
|
|
127
|
+
*
|
|
128
|
+
* @param tonegen The tone generator instance.
|
|
129
|
+
* @param count Number of digits in the array.
|
|
130
|
+
* @param digits Array of MF digits.
|
|
131
|
+
* @param options Option flags. Application may specify
|
|
132
|
+
* PJMEDIA_TONEGEN_LOOP to play the tone in a loop.
|
|
133
|
+
*
|
|
134
|
+
* @return PJ_SUCCESS on success, or PJ_ETOOMANY if
|
|
135
|
+
* there are too many digits in the queue, or
|
|
136
|
+
* PJMEDIA_RTP_EINDTMF if invalid digit is
|
|
137
|
+
* specified.
|
|
138
|
+
*/
|
|
139
|
+
PJ_DECL(pj_status_t) chainlink_tonegen_play_digits(pjmedia_port *tonegen,
|
|
140
|
+
unsigned count,
|
|
141
|
+
const pjmedia_tone_digit digits[],
|
|
142
|
+
unsigned options);
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Get the digit-map currently used by this tone generator.
|
|
147
|
+
*
|
|
148
|
+
* @param tonegen The tone generator instance.
|
|
149
|
+
* @param m On output, it will be filled with the pointer to
|
|
150
|
+
* the digitmap currently used by the tone generator.
|
|
151
|
+
*
|
|
152
|
+
* @return PJ_SUCCESS on success.
|
|
153
|
+
*/
|
|
154
|
+
PJ_DECL(pj_status_t) chainlink_tonegen_get_digit_map(pjmedia_port *tonegen,
|
|
155
|
+
const pjmedia_tone_digit_map **m);
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Set digit map to be used by the tone generator.
|
|
160
|
+
*
|
|
161
|
+
* @param tonegen The tone generator instance.
|
|
162
|
+
* @param m Digitmap to be used by the tone generator.
|
|
163
|
+
*
|
|
164
|
+
* @return PJ_SUCCESS on success.
|
|
165
|
+
*/
|
|
166
|
+
PJ_DECL(pj_status_t) chainlink_tonegen_set_digit_map(pjmedia_port *tonegen,
|
|
167
|
+
pjmedia_tone_digit_map *m);
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
PJ_END_DECL
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* @}
|
|
174
|
+
*/
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
#endif /* __CHAINLINK_TONEGEN_PORT_H__ */
|
|
178
|
+
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
#ifndef __CHAINLINK_WAV_PORT_H__
|
|
2
|
+
#define __CHAINLINK_WAV_PORT_H__
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @file wav_port.h
|
|
6
|
+
* @brief WAV file player and writer.
|
|
7
|
+
*/
|
|
8
|
+
#include <pjmedia/port.h>
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
PJ_BEGIN_DECL
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @defgroup CHAINLINK_FILE_PLAY WAV File Player
|
|
17
|
+
* @ingroup CHAINLINK_PORT
|
|
18
|
+
* @brief Audio playback from WAV file
|
|
19
|
+
* @{
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* WAV file player options.
|
|
24
|
+
*/
|
|
25
|
+
enum chainlink_file_player_option
|
|
26
|
+
{
|
|
27
|
+
/**
|
|
28
|
+
* Tell the file player to return NULL frame when the whole
|
|
29
|
+
* file has been played.
|
|
30
|
+
*/
|
|
31
|
+
CHAINLINK_FILE_NO_LOOP = 1
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Create a media port to play streams from a WAV file. WAV player port
|
|
37
|
+
* supports for reading WAV file with uncompressed 16 bit PCM format or
|
|
38
|
+
* compressed G.711 A-law/U-law format.
|
|
39
|
+
*
|
|
40
|
+
* @param pool Pool to create memory buffers for this port.
|
|
41
|
+
* @param filename File name to open.
|
|
42
|
+
* @param ptime The duration (in miliseconds) of each frame read
|
|
43
|
+
* from this port. If the value is zero, the default
|
|
44
|
+
* duration (20ms) will be used.
|
|
45
|
+
* @param flags Port creation flags.
|
|
46
|
+
* @param buff_size Buffer size to be allocated. If the value is zero or
|
|
47
|
+
* negative, the port will use default buffer size (which
|
|
48
|
+
* is about 4KB).
|
|
49
|
+
* @param p_port Pointer to receive the file port instance.
|
|
50
|
+
*
|
|
51
|
+
* @return PJ_SUCCESS on success.
|
|
52
|
+
*/
|
|
53
|
+
PJ_DECL(pj_status_t) chainlink_wav_player_port_create( pj_pool_t *pool,
|
|
54
|
+
const char *filename,
|
|
55
|
+
unsigned ptime,
|
|
56
|
+
unsigned flags,
|
|
57
|
+
pj_ssize_t buff_size,
|
|
58
|
+
pjmedia_port **p_port );
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Get the data length, in bytes.
|
|
63
|
+
*
|
|
64
|
+
* @param port The file player port.
|
|
65
|
+
*
|
|
66
|
+
* @return The length of the data, in bytes. Upon error it will
|
|
67
|
+
* return negative value.
|
|
68
|
+
*/
|
|
69
|
+
PJ_DECL(pj_ssize_t) chainlink_wav_player_get_len(pjmedia_port *port);
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Set the file play position of WAV player.
|
|
74
|
+
*
|
|
75
|
+
* @param port The file player port.
|
|
76
|
+
* @param offset Playback position in bytes, relative to the start of
|
|
77
|
+
* the payload.
|
|
78
|
+
*
|
|
79
|
+
* @return PJ_SUCCESS on success.
|
|
80
|
+
*/
|
|
81
|
+
PJ_DECL(pj_status_t) chainlink_wav_player_port_set_pos( pjmedia_port *port,
|
|
82
|
+
pj_uint32_t offset );
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Get the file play position of WAV player.
|
|
87
|
+
*
|
|
88
|
+
* @param port The file player port.
|
|
89
|
+
*
|
|
90
|
+
* @return PJ_SUCCESS on success.
|
|
91
|
+
*/
|
|
92
|
+
PJ_DECL(pj_ssize_t) chainlink_wav_player_port_get_pos( pjmedia_port *port );
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Register a callback to be called when the file reading has reached the
|
|
97
|
+
* end of file. If the file is set to play repeatedly, then the callback
|
|
98
|
+
* will be called multiple times. Note that only one callback can be
|
|
99
|
+
* registered for each file port.
|
|
100
|
+
*
|
|
101
|
+
* @param port The file player port.
|
|
102
|
+
* @param user_data User data to be specified in the callback
|
|
103
|
+
* @param cb Callback to be called. If the callback returns non-
|
|
104
|
+
* PJ_SUCCESS, the playback will stop. Note that if
|
|
105
|
+
* application destroys the file port in the callback,
|
|
106
|
+
* it must return non-PJ_SUCCESS here.
|
|
107
|
+
*
|
|
108
|
+
* @return PJ_SUCCESS on success.
|
|
109
|
+
*/
|
|
110
|
+
PJ_DECL(pj_status_t)
|
|
111
|
+
chainlink_wav_player_set_eof_cb( pjmedia_port *port,
|
|
112
|
+
void *user_data,
|
|
113
|
+
pj_status_t (*cb)(pjmedia_port *port,
|
|
114
|
+
void *usr_data));
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* @}
|
|
118
|
+
*/
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* @defgroup CHAINLINK_FILE_REC File Writer (Recorder)
|
|
123
|
+
* @ingroup CHAINLINK_PORT
|
|
124
|
+
* @brief Audio capture/recording to WAV file
|
|
125
|
+
* @{
|
|
126
|
+
*/
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* WAV file writer options.
|
|
131
|
+
*/
|
|
132
|
+
enum chainlink_file_writer_option
|
|
133
|
+
{
|
|
134
|
+
/**
|
|
135
|
+
* Tell the file writer to save the audio in PCM format.
|
|
136
|
+
*/
|
|
137
|
+
CHAINLINK_FILE_WRITE_PCM = 0,
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Tell the file writer to save the audio in G711 Alaw format.
|
|
141
|
+
*/
|
|
142
|
+
CHAINLINK_FILE_WRITE_ALAW = 1,
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Tell the file writer to save the audio in G711 Alaw format.
|
|
146
|
+
*/
|
|
147
|
+
CHAINLINK_FILE_WRITE_ULAW = 2,
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Create a media port to record streams to a WAV file. Note that the port
|
|
153
|
+
* must be closed properly (with #pjmedia_port_destroy()) so that the WAV
|
|
154
|
+
* header can be filled with correct values (such as the file length).
|
|
155
|
+
* WAV writer port supports for writing audio in uncompressed 16 bit PCM format
|
|
156
|
+
* or compressed G.711 U-law/A-law format, this needs to be specified in
|
|
157
|
+
* \a flags param.
|
|
158
|
+
*
|
|
159
|
+
* @param pool Pool to create memory buffers for this port.
|
|
160
|
+
* @param filename File name.
|
|
161
|
+
* @param clock_rate The sampling rate.
|
|
162
|
+
* @param channel_count Number of channels.
|
|
163
|
+
* @param samples_per_frame Number of samples per frame.
|
|
164
|
+
* @param bits_per_sample Number of bits per sample (eg 16).
|
|
165
|
+
* @param flags Port creation flags, see
|
|
166
|
+
* #pjmedia_file_writer_option.
|
|
167
|
+
* @param buff_size Buffer size to be allocated. If the value is
|
|
168
|
+
* zero or negative, the port will use default buffer
|
|
169
|
+
* size (which is about 4KB).
|
|
170
|
+
* @param p_port Pointer to receive the file port instance.
|
|
171
|
+
*
|
|
172
|
+
* @return PJ_SUCCESS on success.
|
|
173
|
+
*/
|
|
174
|
+
PJ_DECL(pj_status_t) chainlink_wav_writer_port_create(pj_pool_t *pool,
|
|
175
|
+
const char *filename,
|
|
176
|
+
unsigned clock_rate,
|
|
177
|
+
unsigned channel_count,
|
|
178
|
+
unsigned samples_per_frame,
|
|
179
|
+
unsigned bits_per_sample,
|
|
180
|
+
unsigned flags,
|
|
181
|
+
pj_ssize_t buff_size,
|
|
182
|
+
pjmedia_port **p_port );
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Get current writing position. Note that this does not necessarily match
|
|
187
|
+
* the size written to the file, since the WAV writer employs some internal
|
|
188
|
+
* buffering. Also the value reported here only indicates the payload size
|
|
189
|
+
* (it does not include the size of the WAV header),
|
|
190
|
+
*
|
|
191
|
+
* @param port The file writer port.
|
|
192
|
+
*
|
|
193
|
+
* @return Positive value to indicate the position (in bytes),
|
|
194
|
+
* or negative value containing the error code.
|
|
195
|
+
*/
|
|
196
|
+
PJ_DECL(pj_ssize_t) chainlink_wav_writer_port_get_pos( pjmedia_port *port );
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Register the callback to be called when the file writing has reached
|
|
201
|
+
* certain size. Application can use this callback, for example, to limit
|
|
202
|
+
* the size of the output file.
|
|
203
|
+
*
|
|
204
|
+
* @param port The file writer port.
|
|
205
|
+
* @param pos The file position on which the callback will be called.
|
|
206
|
+
* @param user_data User data to be specified in the callback, and will be
|
|
207
|
+
* given on the callback.
|
|
208
|
+
* @param cb Callback to be called. If the callback returns non-
|
|
209
|
+
* PJ_SUCCESS, the writing will stop. Note that if
|
|
210
|
+
* application destroys the port in the callback, it must
|
|
211
|
+
* return non-PJ_SUCCESS here.
|
|
212
|
+
*
|
|
213
|
+
* @return PJ_SUCCESS on success.
|
|
214
|
+
*/
|
|
215
|
+
PJ_DECL(pj_status_t)
|
|
216
|
+
chainlink_wav_writer_port_set_cb( pjmedia_port *port,
|
|
217
|
+
pj_size_t pos,
|
|
218
|
+
void *user_data,
|
|
219
|
+
pj_status_t (*cb)(pjmedia_port *port,
|
|
220
|
+
void *usr_data));
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* @}
|
|
225
|
+
*/
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
PJ_END_DECL
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
#endif /* __CHAINLINK_WAV_PORT_H__ */
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#ifndef __CHAINLINK_WIRE_PORT_H__
|
|
2
|
+
#define __CHAINLINK_WIRE_PORT_H__
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @file chainlink_wire_port.h
|
|
6
|
+
*/
|
|
7
|
+
#include <pjmedia/port.h>
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @defgroup CHAINLINK_WIRE_PORT
|
|
13
|
+
* @ingroup PJMEDIA_PORT
|
|
14
|
+
* @{
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
PJ_BEGIN_DECL
|
|
19
|
+
|
|
20
|
+
#define CHAINLINK_WIRE_PORT_SIGNATURE PJMEDIA_SIGNATURE('L', 'w', 'i', 'r')
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Create wire port (a port that just forward calls to get_frame and put_frame to its adjacent ports
|
|
24
|
+
*
|
|
25
|
+
* @param pool Pool to allocate memory.
|
|
26
|
+
* @param sampling_rate Sampling rate of the port.
|
|
27
|
+
* @param channel_count Number of channels.
|
|
28
|
+
* @param samples_per_frame Number of samples per frame.
|
|
29
|
+
* @param bits_per_sample Number of bits per sample.
|
|
30
|
+
* @param p_port Pointer to receive the port instance.
|
|
31
|
+
*
|
|
32
|
+
* @return PJ_SUCCESS on success.
|
|
33
|
+
*/
|
|
34
|
+
PJ_DECL(pj_status_t) chainlink_wire_port_create( pj_pool_t *pool,
|
|
35
|
+
unsigned sampling_rate,
|
|
36
|
+
unsigned channel_count,
|
|
37
|
+
unsigned samples_per_frame,
|
|
38
|
+
unsigned bits_per_sample,
|
|
39
|
+
pjmedia_port **p_port);
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
PJ_END_DECL
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @}
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
#endif /* __CHAINLINK_WIRE_PORT_H__ */
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/* $Id: dtmfdeg.h 0000 2000-05-02 13:02:00Z takeshi $ */
|
|
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
|
+
#ifndef __PJMEDIA_DTMFDET_H__
|
|
21
|
+
#define __PJMEDIA_DTMFDET_H__
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @file dtmfdet.h
|
|
25
|
+
* @brief DTMF Detection port.
|
|
26
|
+
*/
|
|
27
|
+
#include <pjmedia/port.h>
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @defgroup PJMEDIA_DTMFDET_PORT DTMF Detection
|
|
33
|
+
* @ingroup PJMEDIA_PORT
|
|
34
|
+
* @brief DTMF Detection port
|
|
35
|
+
* @{
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
PJ_BEGIN_DECL
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Create DTMF Detection port
|
|
44
|
+
*
|
|
45
|
+
* @param pool Pool to allocate memory.
|
|
46
|
+
* @param sampling_rate Sampling rate of the port.
|
|
47
|
+
* @param channel_count Number of channels.
|
|
48
|
+
* @param samples_per_frame Number of samples per frame.
|
|
49
|
+
* @param bits_per_sample Number of bits per sample.
|
|
50
|
+
* @param p_port Pointer to receive the port instance.
|
|
51
|
+
*
|
|
52
|
+
* @return PJ_SUCCESS on success.
|
|
53
|
+
*/
|
|
54
|
+
PJ_DECL(pj_status_t) pjmedia_dtmfdet_create( pj_pool_t *pool,
|
|
55
|
+
unsigned clock_rate,
|
|
56
|
+
unsigned channel_count,
|
|
57
|
+
unsigned samples_per_frame,
|
|
58
|
+
unsigned bits_per_sample,
|
|
59
|
+
void (*cb)(pjmedia_port*,
|
|
60
|
+
void *user_data,
|
|
61
|
+
char digit),
|
|
62
|
+
void *user_data,
|
|
63
|
+
pjmedia_port **p_port);
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
PJ_END_DECL
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @}
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
#endif /* __PJMEDIA_DTMFDET_H__ */
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
#include "chainlink.h"
|
|
2
|
+
#include "chainlink_dtmfdet.h"
|
|
3
|
+
|
|
4
|
+
#include <pjmedia/errno.h>
|
|
5
|
+
#include <pjmedia/port.h>
|
|
6
|
+
#include <pj/assert.h>
|
|
7
|
+
#include <pj/pool.h>
|
|
8
|
+
#include <pj/string.h>
|
|
9
|
+
|
|
10
|
+
#define INT16_MAX 0x7fff
|
|
11
|
+
#define INT16_MIN (-INT16_MAX - 1)
|
|
12
|
+
#include <spandsp.h>
|
|
13
|
+
#include <spandsp/expose.h>
|
|
14
|
+
|
|
15
|
+
#define SIGNATURE PJMEDIA_SIGNATURE('L', 'd', 't', 'd')
|
|
16
|
+
#define THIS_FILE "chainlink_dtmfdet.c"
|
|
17
|
+
|
|
18
|
+
#if 0
|
|
19
|
+
# define TRACE_(expr) PJ_LOG(4,expr)
|
|
20
|
+
#else
|
|
21
|
+
# define TRACE_(expr)
|
|
22
|
+
#endif
|
|
23
|
+
|
|
24
|
+
static pj_status_t dtmfdet_get_frame(pjmedia_port *this_port,
|
|
25
|
+
pjmedia_frame *frame);
|
|
26
|
+
static pj_status_t dtmfdet_put_frame(pjmedia_port *this_port,
|
|
27
|
+
pjmedia_frame *frame);
|
|
28
|
+
static pj_status_t dtmfdet_on_destroy(pjmedia_port *this_port);
|
|
29
|
+
|
|
30
|
+
struct dtmfdet
|
|
31
|
+
{
|
|
32
|
+
struct chainlink link;
|
|
33
|
+
dtmf_rx_state_t state;
|
|
34
|
+
void (*dtmf_cb)(pjmedia_port*, void*, char);
|
|
35
|
+
void *dtmf_cb_user_data;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
static void dtmfdet_digit_callback(void *user_data, int code, int level, int delay)
|
|
39
|
+
{
|
|
40
|
+
struct dtmfdet *dport = (struct dtmfdet*) user_data;
|
|
41
|
+
if(!code) return;
|
|
42
|
+
|
|
43
|
+
TRACE_((THIS_FILE, "dtmfdet digit detected: %c", code));
|
|
44
|
+
|
|
45
|
+
if(!dport->dtmf_cb) return;
|
|
46
|
+
|
|
47
|
+
dport->dtmf_cb((pjmedia_port*)dport,
|
|
48
|
+
dport->dtmf_cb_user_data,
|
|
49
|
+
code);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
PJ_DEF(pj_status_t) chainlink_dtmfdet_create( pj_pool_t *pool,
|
|
53
|
+
unsigned clock_rate,
|
|
54
|
+
unsigned channel_count,
|
|
55
|
+
unsigned samples_per_frame,
|
|
56
|
+
unsigned bits_per_sample,
|
|
57
|
+
void (*cb)(pjmedia_port*,
|
|
58
|
+
void *user_data,
|
|
59
|
+
char digit),
|
|
60
|
+
void *user_data,
|
|
61
|
+
pjmedia_port **p_port)
|
|
62
|
+
{
|
|
63
|
+
struct dtmfdet *dd;
|
|
64
|
+
const pj_str_t name = pj_str("dtmfdet");
|
|
65
|
+
|
|
66
|
+
PJ_ASSERT_RETURN(pool && clock_rate && channel_count &&
|
|
67
|
+
samples_per_frame && bits_per_sample == 16 &&
|
|
68
|
+
p_port != NULL, PJ_EINVAL);
|
|
69
|
+
|
|
70
|
+
PJ_ASSERT_RETURN(pool && p_port, PJ_EINVAL);
|
|
71
|
+
|
|
72
|
+
dd = PJ_POOL_ZALLOC_T(pool, struct dtmfdet);
|
|
73
|
+
PJ_ASSERT_RETURN(pool != NULL, PJ_ENOMEM);
|
|
74
|
+
|
|
75
|
+
pjmedia_port_info_init(&dd->link.port.info, &name, SIGNATURE, clock_rate,
|
|
76
|
+
channel_count, bits_per_sample, samples_per_frame);
|
|
77
|
+
|
|
78
|
+
dd->link.port.get_frame = &dtmfdet_get_frame;
|
|
79
|
+
dd->link.port.put_frame = &dtmfdet_put_frame;
|
|
80
|
+
dd->link.port.on_destroy = &dtmfdet_on_destroy;
|
|
81
|
+
|
|
82
|
+
dd->dtmf_cb = cb;
|
|
83
|
+
dd->dtmf_cb_user_data = user_data;
|
|
84
|
+
|
|
85
|
+
dtmf_rx_init(&dd->state, NULL, NULL);
|
|
86
|
+
dtmf_rx_set_realtime_callback(&dd->state,
|
|
87
|
+
&dtmfdet_digit_callback,
|
|
88
|
+
(void*)dd);
|
|
89
|
+
|
|
90
|
+
TRACE_((THIS_FILE, "dtmfdet created: %u/%u/%u/%u", clock_rate,
|
|
91
|
+
channel_count, samples_per_frame, bits_per_sample));
|
|
92
|
+
|
|
93
|
+
*p_port = &dd->link.port;
|
|
94
|
+
return PJ_SUCCESS;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
static pj_status_t dtmfdet_get_frame(pjmedia_port *this_port,
|
|
98
|
+
pjmedia_frame *frame) {
|
|
99
|
+
PJ_ASSERT_RETURN(this_port && frame, PJ_EINVAL);
|
|
100
|
+
|
|
101
|
+
struct dtmfdet *dport = (struct dtmfdet*)this_port;
|
|
102
|
+
return dport->link.next->get_frame(dport->link.next, frame);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
static pj_status_t dtmfdet_put_frame(pjmedia_port *this_port,
|
|
106
|
+
pjmedia_frame *frame)
|
|
107
|
+
{
|
|
108
|
+
if(frame->type != PJMEDIA_FRAME_TYPE_AUDIO) return PJ_SUCCESS;
|
|
109
|
+
|
|
110
|
+
struct dtmfdet *dport = (struct dtmfdet*) this_port;
|
|
111
|
+
dtmf_rx(&dport->state, (const pj_int16_t*)frame->buf,
|
|
112
|
+
PJMEDIA_PIA_SPF(&dport->link.port.info));
|
|
113
|
+
|
|
114
|
+
return dport->link.next->put_frame(dport->link.next, frame);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/*
|
|
118
|
+
* Destroy port.
|
|
119
|
+
*/
|
|
120
|
+
static pj_status_t dtmfdet_on_destroy(pjmedia_port *this_port)
|
|
121
|
+
{
|
|
122
|
+
return PJ_SUCCESS;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
|