@babblevoice/projectrtp 2.4.17 → 2.5.22
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 +3 -70
- package/package.json +6 -4
- package/src/globals.h +5 -0
- package/src/projectrtpbuffer.cpp +30 -6
- package/src/projectrtpbuffer.h +14 -3
- package/src/projectrtpchannel.cpp +110 -56
- package/src/projectrtpchannel.h +6 -0
- package/src/projectrtpchannelmux.cpp +23 -15
- package/src/projectrtpchannelmux.h +4 -2
- package/src/projectrtpcodecx.cpp +72 -96
- package/src/projectrtpcodecx.h +18 -5
- package/src/projectrtppacket.cpp +16 -41
- package/src/projectrtppacket.h +0 -2
- package/src/projectrtprawsound.cpp +56 -75
- package/src/projectrtprawsound.h +3 -2
- package/src/projectrtpsoundfile.cpp +4 -1
- package/src/projectrtptonegen.cpp +26 -43
- package/test/interface/pcap.js +2 -2
- package/test/interface/pcaps/440hzinbackgroundg722.pcap +0 -0
- package/test/interface/projectrtpchannel.js +10 -10
- package/test/interface/projectrtpdtmf.js +88 -4
- package/test/interface/projectrtpmix.js +1 -2
- package/test/interface/transcode.js +821 -0
package/src/projectrtppacket.cpp
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
|
|
2
|
-
#ifdef TESTSUITE
|
|
3
2
|
#include <iostream>
|
|
3
|
+
#include <cstdlib>
|
|
4
4
|
#include <iomanip>
|
|
5
|
-
#endif
|
|
6
5
|
|
|
7
6
|
#include "projectrtppacket.h"
|
|
8
7
|
#include "globals.h"
|
|
@@ -43,7 +42,7 @@ void rtppacket::copy( rtppacket *src )
|
|
|
43
42
|
src->pk + 12 + ( src->getpacketcsrccount() * 4 ),
|
|
44
43
|
src->getpayloadlength() );
|
|
45
44
|
|
|
46
|
-
this->length = src->
|
|
45
|
+
this->length = src->length;
|
|
47
46
|
}
|
|
48
47
|
|
|
49
48
|
/*!md
|
|
@@ -139,28 +138,11 @@ uint8_t rtppacket::getpayloadtype( void )
|
|
|
139
138
|
/*!md
|
|
140
139
|
## setpayloadtype
|
|
141
140
|
As it says. We also set the length of the packet to a default amount for that CODEC.
|
|
141
|
+
If setting a dynamic payloadtype - don't mess with the length as we won't know it
|
|
142
|
+
and it must already be set.
|
|
142
143
|
*/
|
|
143
|
-
void rtppacket::setpayloadtype( uint8_t pt )
|
|
144
|
-
{
|
|
144
|
+
void rtppacket::setpayloadtype( uint8_t pt ) {
|
|
145
145
|
this->pk[ 1 ] = ( this->pk[ 1 ] & 0x80 ) | ( pt & 0x7f );
|
|
146
|
-
|
|
147
|
-
switch( pt )
|
|
148
|
-
{
|
|
149
|
-
case ILBC20PAYLOADBYTES:
|
|
150
|
-
{
|
|
151
|
-
this->length = 12 + ILBC20PAYLOADBYTES;
|
|
152
|
-
break;
|
|
153
|
-
}
|
|
154
|
-
case ILBC30PAYLOADBYTES:
|
|
155
|
-
{
|
|
156
|
-
this->length = 12 + ILBC30PAYLOADBYTES;
|
|
157
|
-
break;
|
|
158
|
-
}
|
|
159
|
-
default:
|
|
160
|
-
{
|
|
161
|
-
this->length = 12 + G711PAYLOADBYTES;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
146
|
}
|
|
165
147
|
|
|
166
148
|
/*!md
|
|
@@ -243,8 +225,7 @@ uint32_t rtppacket::getcsrc( uint8_t index )
|
|
|
243
225
|
## getpayload
|
|
244
226
|
Returns a pointer to the start of the payload.
|
|
245
227
|
*/
|
|
246
|
-
uint8_t *rtppacket::getpayload( void )
|
|
247
|
-
{
|
|
228
|
+
uint8_t *rtppacket::getpayload( void ) {
|
|
248
229
|
uint8_t *ptr = this->pk;
|
|
249
230
|
ptr += 12;
|
|
250
231
|
ptr += ( this->getpacketcsrccount() * 4 );
|
|
@@ -256,11 +237,9 @@ uint8_t *rtppacket::getpayload( void )
|
|
|
256
237
|
## getpayloadlength
|
|
257
238
|
As it says.
|
|
258
239
|
*/
|
|
259
|
-
uint16_t rtppacket::getpayloadlength( void )
|
|
260
|
-
{
|
|
240
|
+
uint16_t rtppacket::getpayloadlength( void ) {
|
|
261
241
|
|
|
262
|
-
if( this->length < ( 12 - ( (size_t)this->getpacketcsrccount() * 4 ) ) )
|
|
263
|
-
{
|
|
242
|
+
if( this->length < ( 12 - ( (size_t) this->getpacketcsrccount() * 4 ) ) ) {
|
|
264
243
|
fprintf( stderr, "RTP Packet has a nonsense size\n" );
|
|
265
244
|
return 0;
|
|
266
245
|
}
|
|
@@ -271,30 +250,26 @@ uint16_t rtppacket::getpayloadlength( void )
|
|
|
271
250
|
## setpayloadlength
|
|
272
251
|
As it says.
|
|
273
252
|
*/
|
|
274
|
-
void rtppacket::setpayloadlength( size_t length )
|
|
275
|
-
{
|
|
253
|
+
void rtppacket::setpayloadlength( size_t length ) {
|
|
276
254
|
this->length = 12 + ( this->getpacketcsrccount() * 4 ) + length;
|
|
277
255
|
}
|
|
278
256
|
|
|
279
|
-
|
|
280
|
-
/* show the contents to cout */
|
|
257
|
+
/* dump the contents to cout */
|
|
281
258
|
void rtppacket::dump() {
|
|
282
259
|
std::cout << "=================BEGIN=================" << std::endl;
|
|
283
|
-
std::cout << "length: " << this->length << std::endl;
|
|
284
|
-
std::cout << "payload length: " << this->getpayloadlength() << std::endl;
|
|
260
|
+
std::cout << "length: " << std::dec << this->length << std::endl;
|
|
261
|
+
std::cout << "payload length: " << std::dec << this->getpayloadlength() << std::endl;
|
|
285
262
|
std::cout << "marker: " << +this->getpacketmarker() << std::endl;
|
|
286
263
|
std::cout << "pt: " << +this->getpayloadtype() << std::endl;
|
|
287
|
-
std::cout << "sn: " << this->getsequencenumber() << std::endl;
|
|
288
|
-
std::cout << "ts: " << this->gettimestamp() << std::endl;
|
|
289
|
-
std::cout << "ssrc: " << this->getssrc() << std::endl;
|
|
264
|
+
std::cout << "sn: " << std::dec << this->getsequencenumber() << std::endl;
|
|
265
|
+
std::cout << "ts: " << std::dec << this->gettimestamp() << std::endl;
|
|
266
|
+
std::cout << "ssrc: " << std::dec << this->getssrc() << std::endl;
|
|
290
267
|
|
|
291
268
|
auto v = this->getpayload();
|
|
292
269
|
for( auto i = 0; i < this->getpayloadlength(); i ++ ) {
|
|
293
270
|
std::cout << std::showbase << std::setfill( '0' ) << std::setw( 2 ) << std::hex << std::right << +(*(v+i)) << ' ';
|
|
294
|
-
if( 0 == i % 16 ) std::cout << std::endl;
|
|
271
|
+
if( 0 != i && 0 == i % 16 ) std::cout << std::endl;
|
|
295
272
|
}
|
|
296
273
|
std::cout << std::dec;
|
|
297
|
-
|
|
298
274
|
std::cout << std::endl << "=================END===================" << std::endl;
|
|
299
275
|
}
|
|
300
|
-
#endif
|
package/src/projectrtppacket.h
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
#include <iostream> // cerr
|
|
3
|
+
#include <cstdlib>
|
|
4
|
+
#include <iomanip>
|
|
3
5
|
|
|
4
6
|
#include "projectrtprawsound.h"
|
|
5
7
|
#include "projectrtpcodecx.h"
|
|
@@ -145,24 +147,17 @@ rawsound::~rawsound()
|
|
|
145
147
|
## zero
|
|
146
148
|
Reset buffer with zero
|
|
147
149
|
*/
|
|
148
|
-
void rawsound::zero( void )
|
|
149
|
-
|
|
150
|
-
if( nullptr != this->data )
|
|
151
|
-
{
|
|
152
|
-
size_t zeroamount = this->samples * this->bytespersample;
|
|
153
|
-
if( L1616KPAYLOADTYPE == format )
|
|
154
|
-
{
|
|
155
|
-
zeroamount = zeroamount * 2;
|
|
156
|
-
}
|
|
150
|
+
void rawsound::zero( void ) {
|
|
151
|
+
if( nullptr == this->data ) return;
|
|
157
152
|
|
|
158
|
-
|
|
159
|
-
{
|
|
160
|
-
std::cerr << "Trying to zero memory but capped by allocated amount" << std::endl;
|
|
161
|
-
zeroamount = this->allocatedlength;
|
|
162
|
-
}
|
|
153
|
+
size_t zeroamount = this->samples * this->bytespersample;
|
|
163
154
|
|
|
164
|
-
|
|
155
|
+
if( 0 != this->allocatedlength && zeroamount > this->allocatedlength ) {
|
|
156
|
+
std::cerr << "Trying to zero memory but capped by allocated amount" << std::endl;
|
|
157
|
+
zeroamount = this->allocatedlength;
|
|
165
158
|
}
|
|
159
|
+
|
|
160
|
+
memset( this->data, 0, zeroamount );
|
|
166
161
|
}
|
|
167
162
|
|
|
168
163
|
/*
|
|
@@ -170,49 +165,31 @@ void rawsound::zero( void )
|
|
|
170
165
|
* Target (this) MUST have memory available.
|
|
171
166
|
* format must be set appropriatly before the call
|
|
172
167
|
*/
|
|
173
|
-
void rawsound::copy( uint8_t *src, size_t len )
|
|
174
|
-
|
|
175
|
-
if( nullptr != this->data )
|
|
176
|
-
{
|
|
177
|
-
memcpy( this->data,
|
|
178
|
-
src,
|
|
179
|
-
len );
|
|
168
|
+
void rawsound::copy( uint8_t *src, size_t len ) {
|
|
169
|
+
if( nullptr == this->data ) return;
|
|
180
170
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
case L1616KPAYLOADTYPE:
|
|
185
|
-
{
|
|
186
|
-
this->samples = len / 2;
|
|
187
|
-
break;
|
|
188
|
-
}
|
|
189
|
-
default:
|
|
190
|
-
{
|
|
191
|
-
this->samples = len;
|
|
192
|
-
break;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}
|
|
171
|
+
memcpy( this->data,
|
|
172
|
+
src,
|
|
173
|
+
len );
|
|
196
174
|
}
|
|
197
175
|
|
|
198
176
|
/*
|
|
199
177
|
## copy (from other)
|
|
200
178
|
* Target (this) MUST have data allocated.
|
|
201
179
|
*/
|
|
202
|
-
void rawsound::copy( rawsound &other )
|
|
203
|
-
{
|
|
204
|
-
if( nullptr != this->data && this->samples >= other.samples )
|
|
205
|
-
{
|
|
206
|
-
this->bytespersample = other.bytespersample;
|
|
207
|
-
this->samplerate = other.samplerate;
|
|
208
|
-
this->format = other.format;
|
|
209
|
-
this->samples = other.samples;
|
|
180
|
+
void rawsound::copy( rawsound &other ) {
|
|
210
181
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
182
|
+
if( nullptr == this->data || this->samples < other.samples ) return;
|
|
183
|
+
|
|
184
|
+
this->bytespersample = other.bytespersample;
|
|
185
|
+
this->samplerate = other.samplerate;
|
|
186
|
+
this->format = other.format;
|
|
187
|
+
this->samples = other.samples;
|
|
188
|
+
|
|
189
|
+
memcpy( this->data,
|
|
190
|
+
other.data,
|
|
191
|
+
other.samples * other.bytespersample );
|
|
214
192
|
|
|
215
|
-
}
|
|
216
193
|
}
|
|
217
194
|
|
|
218
195
|
/*
|
|
@@ -235,21 +212,14 @@ void rawsound::subtract( void )
|
|
|
235
212
|
## malloc
|
|
236
213
|
Allocate our own memory.
|
|
237
214
|
*/
|
|
238
|
-
void rawsound::malloc( size_t samplecount, size_t bytespersample, int format )
|
|
239
|
-
{
|
|
215
|
+
void rawsound::malloc( size_t samplecount, size_t bytespersample, int format ) {
|
|
240
216
|
this->samples = samplecount;
|
|
241
217
|
this->bytespersample = bytespersample;
|
|
242
218
|
this->format = format;
|
|
243
219
|
size_t requiredsize = samplecount * bytespersample;
|
|
244
|
-
if( L1616KPAYLOADTYPE == format )
|
|
245
|
-
{
|
|
246
|
-
requiredsize = requiredsize * 2;
|
|
247
|
-
}
|
|
248
220
|
|
|
249
|
-
if( this->allocatedlength > 0 )
|
|
250
|
-
|
|
251
|
-
if( this->allocatedlength >= requiredsize )
|
|
252
|
-
{
|
|
221
|
+
if( this->allocatedlength > 0 ) {
|
|
222
|
+
if( this->allocatedlength >= requiredsize ) {
|
|
253
223
|
return;
|
|
254
224
|
}
|
|
255
225
|
|
|
@@ -263,46 +233,39 @@ void rawsound::malloc( size_t samplecount, size_t bytespersample, int format )
|
|
|
263
233
|
## operator +=
|
|
264
234
|
Used for mixing audio
|
|
265
235
|
*/
|
|
266
|
-
rawsound& rawsound::operator+=( codecx& rhs )
|
|
267
|
-
{
|
|
236
|
+
rawsound& rawsound::operator+=( codecx& rhs ) {
|
|
268
237
|
size_t length;
|
|
269
238
|
|
|
270
239
|
int16_t *in;
|
|
271
240
|
int16_t *out = ( int16_t * ) this->data;
|
|
272
241
|
|
|
273
|
-
switch( this->format )
|
|
274
|
-
|
|
275
|
-
case L168KPAYLOADTYPE:
|
|
276
|
-
{
|
|
242
|
+
switch( this->format ) {
|
|
243
|
+
case L168KPAYLOADTYPE: {
|
|
277
244
|
rhs.requirenarrowband();
|
|
278
|
-
|
|
245
|
+
if( rhs.l168kref.isdirty() ) return *this;
|
|
279
246
|
length = rhs.l168kref.size();
|
|
280
247
|
in = ( int16_t * ) rhs.l168kref.c_str();
|
|
281
248
|
break;
|
|
282
249
|
}
|
|
283
|
-
case L1616KPAYLOADTYPE:
|
|
284
|
-
{
|
|
250
|
+
case L1616KPAYLOADTYPE: {
|
|
285
251
|
rhs.requirewideband();
|
|
286
|
-
|
|
252
|
+
if( rhs.l1616kref.isdirty() ) return *this;
|
|
287
253
|
length = rhs.l1616kref.size();
|
|
288
254
|
in = ( int16_t * ) rhs.l1616kref.c_str();
|
|
289
255
|
break;
|
|
290
256
|
}
|
|
291
|
-
default:
|
|
292
|
-
{
|
|
257
|
+
default: {
|
|
293
258
|
std::cerr << "Attemping to perform an addition on a none linear format" << std::endl;
|
|
294
259
|
return *this;
|
|
295
260
|
}
|
|
296
261
|
}
|
|
297
262
|
|
|
298
|
-
if( length > this->samples )
|
|
299
|
-
{
|
|
263
|
+
if( length > this->samples ) {
|
|
300
264
|
std::cerr << "We have been asked to add samples but we don't have enough space" << std::endl;
|
|
301
265
|
length = this->samples;
|
|
302
266
|
}
|
|
303
267
|
|
|
304
|
-
for( size_t i = 0; i < length; i++ )
|
|
305
|
-
{
|
|
268
|
+
for( size_t i = 0; i < length; i++ ) {
|
|
306
269
|
*out++ += *in++;
|
|
307
270
|
}
|
|
308
271
|
|
|
@@ -354,3 +317,21 @@ rawsound& rawsound::operator-=( codecx& rhs )
|
|
|
354
317
|
|
|
355
318
|
return *this;
|
|
356
319
|
}
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
void rawsound::dump() {
|
|
323
|
+
|
|
324
|
+
std::cout << "=================BEGIN=================" << std::endl;
|
|
325
|
+
std::cout << "samples: " << std::dec << this->samples << std::endl;
|
|
326
|
+
std::cout << "bytespersample: " << std::dec << this->bytespersample << std::endl;
|
|
327
|
+
std::cout << "format: " << std::dec << this->format << std::endl;
|
|
328
|
+
|
|
329
|
+
auto v = this->data;
|
|
330
|
+
size_t len = this->samples * this->bytespersample;
|
|
331
|
+
for( size_t i = 0; i < len; i ++ ) {
|
|
332
|
+
std::cout << std::showbase << std::setfill( '0' ) << std::setw( 2 ) << std::hex << std::right << +(*(v+i)) << ' ';
|
|
333
|
+
if( 0 != i && 0 == i % 16 ) std::cout << std::endl;
|
|
334
|
+
}
|
|
335
|
+
std::cout << std::dec;
|
|
336
|
+
std::cout << std::endl << "=================END===================" << std::endl;
|
|
337
|
+
}
|
package/src/projectrtprawsound.h
CHANGED
|
@@ -6,8 +6,7 @@
|
|
|
6
6
|
#include "projectrtppacket.h"
|
|
7
7
|
|
|
8
8
|
class codecx;
|
|
9
|
-
class rawsound
|
|
10
|
-
{
|
|
9
|
+
class rawsound {
|
|
11
10
|
public:
|
|
12
11
|
rawsound();
|
|
13
12
|
rawsound( uint8_t *ptr, std::size_t samples, int format, uint16_t samplerate );
|
|
@@ -39,6 +38,8 @@ public:
|
|
|
39
38
|
rawsound& operator+=( codecx& rhs );
|
|
40
39
|
rawsound& operator-=( codecx& rhs );
|
|
41
40
|
|
|
41
|
+
void dump();
|
|
42
|
+
|
|
42
43
|
private:
|
|
43
44
|
void frompt( int payloadtype );
|
|
44
45
|
|
|
@@ -605,7 +605,10 @@ static napi_value wavinfo( napi_env env, napi_callback_info info ) {
|
|
|
605
605
|
return NULL;
|
|
606
606
|
}
|
|
607
607
|
|
|
608
|
-
read( fd, &hd, sizeof( wavheader ) )
|
|
608
|
+
if( sizeof( wavheader ) != read( fd, &hd, sizeof( wavheader ) ) ) {
|
|
609
|
+
napi_throw_type_error( env, "0", "Bad wav header" );
|
|
610
|
+
goto done;
|
|
611
|
+
}
|
|
609
612
|
|
|
610
613
|
if( 'R' != hd.riff_header[ 0 ] ||
|
|
611
614
|
'I' != hd.riff_header[ 1 ] ||
|
|
@@ -51,13 +51,11 @@ static void gentone( int16_t *outbuffer, int sizeofblock, double startfrequency,
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
|
|
54
|
-
static void gen( std::string tone, std::string filename )
|
|
55
|
-
{
|
|
54
|
+
static void gen( std::string tone, std::string filename ) {
|
|
56
55
|
vectorofstrings freqscadence;
|
|
57
56
|
boost::split( freqscadence, tone, boost::is_any_of( ":" ) );
|
|
58
57
|
|
|
59
|
-
if( 2 != freqscadence.size() )
|
|
60
|
-
{
|
|
58
|
+
if( 2 != freqscadence.size() ) {
|
|
61
59
|
std::cerr << "You must supply a cadence, eg. 400:1000" << std::endl;
|
|
62
60
|
return;
|
|
63
61
|
}
|
|
@@ -76,8 +74,7 @@ static void gen( std::string tone, std::string filename )
|
|
|
76
74
|
vectorofstrings cadenceparts;
|
|
77
75
|
int cadencepos = 0;
|
|
78
76
|
int cadencetotal = 0;
|
|
79
|
-
for( it = frequencies.begin(); it != frequencies.end(); it++ )
|
|
80
|
-
{
|
|
77
|
+
for( it = frequencies.begin(); it != frequencies.end(); it++ ) {
|
|
81
78
|
cadencetotal += std::atoi( cadences[ cadencepos ].c_str() );
|
|
82
79
|
cadencepos = ( cadencepos + 1 ) % cadences.size();
|
|
83
80
|
}
|
|
@@ -94,8 +91,7 @@ static void gen( std::string tone, std::string filename )
|
|
|
94
91
|
/* 3. Generate tones */
|
|
95
92
|
int pos = 0;
|
|
96
93
|
cadencepos = 0;
|
|
97
|
-
for( it = frequencies.begin(); it != frequencies.end(); it++ )
|
|
98
|
-
{
|
|
94
|
+
for( it = frequencies.begin(); it != frequencies.end(); it++ ) {
|
|
99
95
|
/* Current cadence. */
|
|
100
96
|
int cadence = std::atoi( cadences[ cadencepos ].c_str() );
|
|
101
97
|
cadencepos = ( cadencepos + 1 ) % cadences.size();
|
|
@@ -109,14 +105,12 @@ static void gen( std::string tone, std::string filename )
|
|
|
109
105
|
boost::split( freqamp, *it, boost::is_any_of( "*" ) );
|
|
110
106
|
double startamp = 1;
|
|
111
107
|
double endamp = 1;
|
|
112
|
-
if( freqamp.size() > 1 )
|
|
113
|
-
{
|
|
108
|
+
if( freqamp.size() > 1 ) {
|
|
114
109
|
vectorofstrings ampfromto;
|
|
115
110
|
boost::split( ampfromto, freqamp[ 1 ], boost::is_any_of( "~" ) );
|
|
116
111
|
startamp = std::atof( ampfromto[ 0 ].c_str() );
|
|
117
112
|
endamp = startamp;
|
|
118
|
-
if( ampfromto.size() > 1 )
|
|
119
|
-
{
|
|
113
|
+
if( ampfromto.size() > 1 ) {
|
|
120
114
|
endamp = std::atof( ampfromto[ 1 ].c_str() );
|
|
121
115
|
}
|
|
122
116
|
}
|
|
@@ -127,27 +121,20 @@ static void gen( std::string tone, std::string filename )
|
|
|
127
121
|
double endfreq = -1;
|
|
128
122
|
|
|
129
123
|
std::size_t found = freqamp[ 0 ].find_first_of( "+x~" );
|
|
130
|
-
if( std::string::npos == found )
|
|
131
|
-
{
|
|
124
|
+
if( std::string::npos == found ) {
|
|
132
125
|
startfreq = std::atof( freqparts[ 0 ].c_str() );
|
|
133
126
|
gentone( outbuffer, sizeofblock, startfreq, startfreq, startamp, endamp, outwavheader.sample_rate );
|
|
134
127
|
goto continueloop;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
{
|
|
140
|
-
case '+':
|
|
141
|
-
{
|
|
142
|
-
for( auto freqit = freqparts.begin(); freqit != freqparts.end(); freqit++ )
|
|
143
|
-
{
|
|
128
|
+
} else {
|
|
129
|
+
switch( freqamp[ 0 ][ found ] ) {
|
|
130
|
+
case '+': {
|
|
131
|
+
for( auto freqit = freqparts.begin(); freqit != freqparts.end(); freqit++ ) {
|
|
144
132
|
startfreq = std::atof( freqit->c_str() );
|
|
145
133
|
gentone( outbuffer, sizeofblock, startfreq, startfreq, startamp, endamp, outwavheader.sample_rate );
|
|
146
134
|
}
|
|
147
135
|
break;
|
|
148
136
|
}
|
|
149
|
-
case '~':
|
|
150
|
-
{
|
|
137
|
+
case '~': {
|
|
151
138
|
startfreq = std::atof( freqparts[ 0 ].c_str() );
|
|
152
139
|
endfreq = std::atof( freqparts[ 1 ].c_str() );
|
|
153
140
|
gentone( outbuffer, sizeofblock, startfreq, endfreq, startamp, endamp, outwavheader.sample_rate );
|
|
@@ -164,39 +151,35 @@ continueloop:
|
|
|
164
151
|
/* Write */
|
|
165
152
|
int file = open( filename.c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR );
|
|
166
153
|
off_t position = lseek( file, 0, SEEK_END );
|
|
167
|
-
if( 0 == position )
|
|
168
|
-
|
|
169
|
-
write( file,
|
|
170
|
-
|
|
171
|
-
}
|
|
172
|
-
else
|
|
173
|
-
{
|
|
154
|
+
if( 0 == position ) {
|
|
155
|
+
if( -1 == write( file, &outwavheader, sizeof( wavheader ) ) ) std::cerr << "Error writing to tone file" << std::endl;
|
|
156
|
+
if( -1 == write( file, readbuffer, outwavheader.chunksize ) ) std::cerr << "Error writing to tone file" << std::endl;
|
|
157
|
+
} else {
|
|
174
158
|
wavheader currentheader;
|
|
175
159
|
lseek( file, 0, SEEK_SET );
|
|
176
|
-
read( file, ¤theader, sizeof( wavheader ) )
|
|
160
|
+
if( sizeof( wavheader ) != read( file, ¤theader, sizeof( wavheader ) ) ) {
|
|
161
|
+
std::cerr << "Error reading existing tone file" << std::endl;
|
|
162
|
+
goto cleanuupgen;
|
|
163
|
+
}
|
|
177
164
|
lseek( file, 0, SEEK_END );
|
|
178
165
|
|
|
179
166
|
if( currentheader.audio_format == outwavheader.audio_format &&
|
|
180
|
-
currentheader.sample_rate == outwavheader.sample_rate )
|
|
181
|
-
{
|
|
167
|
+
currentheader.sample_rate == outwavheader.sample_rate ) {
|
|
182
168
|
/* Ok, good enough! */
|
|
183
169
|
currentheader.chunksize += outwavheader.chunksize;
|
|
184
170
|
currentheader.subchunksize += outwavheader.subchunksize;
|
|
185
171
|
|
|
186
172
|
lseek( file, 0, SEEK_SET );
|
|
187
|
-
write( file, ¤theader, sizeof( wavheader ) );
|
|
173
|
+
if( -1 == write( file, ¤theader, sizeof( wavheader ) ) ) std::cerr << "Error writing to tone file" << std::endl;
|
|
188
174
|
lseek( file, 0, SEEK_END );
|
|
189
|
-
write( file, readbuffer, outwavheader.chunksize );
|
|
190
|
-
}
|
|
191
|
-
else
|
|
192
|
-
{
|
|
175
|
+
if( -1 == write( file, readbuffer, outwavheader.chunksize ) ) std::cerr << "Error writing to tone file" << std::endl;
|
|
176
|
+
} else {
|
|
193
177
|
std::cerr << "File format to append should be the same" << std::endl;
|
|
194
178
|
}
|
|
195
179
|
}
|
|
196
180
|
|
|
197
|
-
|
|
198
|
-
if( nullptr != readbuffer )
|
|
199
|
-
{
|
|
181
|
+
cleanuupgen:
|
|
182
|
+
if( nullptr != readbuffer ) {
|
|
200
183
|
delete[] readbuffer;
|
|
201
184
|
}
|
|
202
185
|
|
package/test/interface/pcap.js
CHANGED
|
@@ -132,9 +132,9 @@ module.exports.readpcap = async ( file, maxnumberofpackets = 5000 ) => {
|
|
|
132
132
|
etherpacket.ipv4.udp = {}
|
|
133
133
|
etherpacket.ipv4.udp.srcport = parseInt( toHex( etherpacket.ipv4.data[ 20 ] ) + toHex( etherpacket.ipv4.data[ 21 ] ), 16 )
|
|
134
134
|
etherpacket.ipv4.udp.dstport = parseInt( toHex( etherpacket.ipv4.data[ 22 ] ) + toHex( etherpacket.ipv4.data[ 23 ] ), 16 )
|
|
135
|
-
etherpacket.ipv4.udp.length = parseInt( toHex( etherpacket.ipv4.data[ 24 ] ) + toHex( etherpacket.ipv4.data[ 25 ] ), 16 )
|
|
135
|
+
etherpacket.ipv4.udp.length = parseInt( toHex( etherpacket.ipv4.data[ 24 ] ) + toHex( etherpacket.ipv4.data[ 25 ] ), 16 ) - /* udp header */ 8
|
|
136
136
|
etherpacket.ipv4.udp.checksum = parseInt( toHex( etherpacket.ipv4.data[ 26 ] ) + toHex( etherpacket.ipv4.data[ 27 ] ), 16 )
|
|
137
|
-
etherpacket.ipv4.udp.data = etherpacket.ipv4.data.subarray( 28, 28 + etherpacket.ipv4.
|
|
137
|
+
etherpacket.ipv4.udp.data = etherpacket.ipv4.data.subarray( 28, 28 + etherpacket.ipv4.udp.length )
|
|
138
138
|
break
|
|
139
139
|
case 6:
|
|
140
140
|
/* TCP */
|
|
Binary file
|
|
@@ -381,8 +381,7 @@ describe( "rtpchannel", function() {
|
|
|
381
381
|
lastts = ts
|
|
382
382
|
|
|
383
383
|
receviedpkcount++
|
|
384
|
-
|
|
385
|
-
if( 185 == receviedpkcount ) channel.close()
|
|
384
|
+
|
|
386
385
|
} )
|
|
387
386
|
|
|
388
387
|
this.timeout( 15000 )
|
|
@@ -390,8 +389,7 @@ describe( "rtpchannel", function() {
|
|
|
390
389
|
|
|
391
390
|
server.bind()
|
|
392
391
|
|
|
393
|
-
|
|
394
|
-
const finished = new Promise( ( r ) => done = r )
|
|
392
|
+
|
|
395
393
|
let closedstats = {}
|
|
396
394
|
server.on( "listening", async function() {
|
|
397
395
|
|
|
@@ -402,7 +400,6 @@ describe( "rtpchannel", function() {
|
|
|
402
400
|
if( "close" === d.action ) {
|
|
403
401
|
closedstats = d
|
|
404
402
|
server.close()
|
|
405
|
-
done()
|
|
406
403
|
}
|
|
407
404
|
} )
|
|
408
405
|
|
|
@@ -410,7 +407,7 @@ describe( "rtpchannel", function() {
|
|
|
410
407
|
|
|
411
408
|
/* send a packet every 20mS x 50 */
|
|
412
409
|
let i
|
|
413
|
-
for( i = 0;
|
|
410
|
+
for( i = 0; 120 > i; i++ ) {
|
|
414
411
|
sendpk( i, i, channel.local.port, server )
|
|
415
412
|
}
|
|
416
413
|
|
|
@@ -425,7 +422,10 @@ describe( "rtpchannel", function() {
|
|
|
425
422
|
}
|
|
426
423
|
} )
|
|
427
424
|
|
|
428
|
-
await
|
|
425
|
+
await new Promise( resolve => setTimeout( resolve, 6500 ) )
|
|
426
|
+
// @ts-ignore
|
|
427
|
+
channel.close()
|
|
428
|
+
await new Promise( resolve => setTimeout( resolve, 50 ) )
|
|
429
429
|
|
|
430
430
|
/*
|
|
431
431
|
We should receive
|
|
@@ -435,10 +435,10 @@ describe( "rtpchannel", function() {
|
|
|
435
435
|
*/
|
|
436
436
|
expect( receviedpkcount ).to.equal( closedstats.stats.out.count )
|
|
437
437
|
expect( closedstats.stats.in.count ).to.equal( 300 )
|
|
438
|
-
expect( closedstats.stats.out.count ).to.be.
|
|
438
|
+
expect( closedstats.stats.out.count ).to.be.above( 250 )
|
|
439
439
|
expect( totalsndiff ).to.equal( 0 ) // received should be reordered
|
|
440
|
-
expect( totaltsdiff ).to.be.within(
|
|
441
|
-
expect( lastsn - firstsn ).to.be.within(
|
|
440
|
+
expect( totaltsdiff ).to.be.within( 5000, 18400 ) // Allow some loss in test
|
|
441
|
+
expect( lastsn - firstsn ).to.be.within( 250, 300 )
|
|
442
442
|
} )
|
|
443
443
|
|
|
444
444
|
it( "create channel echo whilst wrapping the sn", function( done ) {
|