Newer
Older

Gregory Maxwell
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* Copyright (c) 2011 Xiph.Org Foundation
Written by Gregory Maxwell */
/*
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* This tests the API presented by the libopus system.
It does not attempt to extensively exercise the codec internals.
The strategy here is to simply the API interface invariants:
That sane options are accepted, insane options are rejected,
and that nothing blows up. In particular we don't actually test
that settings are heeded by the codec (though we do check that
get after set returns a sane value when it should). Other
tests check the actual codec behavior.
In cases where its reasonable to do so we test exhaustively,
but its not reasonable to do so in all cases.
Although these tests are simple they found several library bugs
when they were initially developed. */
/* These tests are more sensitive if compiled with -DVALGRIND and
run inside valgrind. Malloc failure testing requires glibc. */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include "arch.h"

Gregory Maxwell
committed
#include "opus_multistream.h"

Gregory Maxwell
committed
#include "test_opus_common.h"
#ifdef VALGRIND
#include <valgrind/memcheck.h>
#define VG_UNDEF(x,y) VALGRIND_MAKE_MEM_UNDEFINED((x),(y))
#define VG_CHECK(x,y) VALGRIND_CHECK_MEM_IS_DEFINED((x),(y))
#else
#define VG_UNDEF(x,y)
#define VG_CHECK(x,y)
#endif
#if defined(HAVE___MALLOC_HOOK)

Gregory Maxwell
committed
#define MALLOC_FAIL
#include "os_support.h"
#include <malloc.h>
static const opus_int32 opus_apps[3] = {OPUS_APPLICATION_VOIP,
OPUS_APPLICATION_AUDIO,OPUS_APPLICATION_RESTRICTED_LOWDELAY};

Gregory Maxwell
committed
void *malloc_hook(__attribute__((unused)) size_t size,
__attribute__((unused)) const void *caller)
{
return 0;
}
#endif
static const opus_int32 opus_rates[5] = {48000,24000,16000,12000,8000};

Gregory Maxwell
committed
opus_int32 test_dec_api(void)
{
opus_uint32 dec_final_range;
OpusDecoder *dec;
OpusDecoder *dec2;
opus_int32 i,j,cfgs;
unsigned char packet[1276];
#ifndef DISABLE_FLOAT_API
float fbuf[960*2];
#endif
short sbuf[960*2];
int c,err;
int *nullptr;
nullptr=0;
cfgs=0;
/*First test invalid configurations which should fail*/
fprintf(stdout,"\n Decoder basic API tests\n");
fprintf(stdout," ---------------------------------------------------\n");

Gregory Maxwell
committed
for(c=0;c<4;c++)
{
i=opus_decoder_get_size(c);
if(((c==1||c==2)&&(i<=2048||i>1<<16))||((c!=1&&c!=2)&&i!=0))test_failed();

Gregory Maxwell
committed
fprintf(stdout," opus_decoder_get_size(%d)=%d ...............%s OK.\n",c,i,i>0?"":"....");

Gregory Maxwell
committed
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
cfgs++;
}
/*Test with unsupported sample rates*/
for(c=0;c<4;c++)
{
for(i=-7;i<=96000;i++)
{
int fs;
if((i==8000||i==12000||i==16000||i==24000||i==48000)&&(c==1||c==2))continue;
switch(i)
{
case(-5):fs=-8000;break;
case(-6):fs=INT32_MAX;break;
case(-7):fs=INT32_MIN;break;
default:fs=i;
}
err = OPUS_OK;
VG_UNDEF(&err,sizeof(err));
dec = opus_decoder_create(fs, c, &err);
if(err!=OPUS_BAD_ARG || dec!=NULL)test_failed();
cfgs++;
dec=malloc(opus_decoder_get_size(2));
if(dec==NULL)test_failed();
err = opus_decoder_init(dec,fs,c);
if(err!=OPUS_BAD_ARG)test_failed();
cfgs++;
free(dec);
}
}
VG_UNDEF(&err,sizeof(err));
dec = opus_decoder_create(48000, 2, &err);
if(err!=OPUS_OK || dec==NULL)test_failed();
VG_CHECK(dec,opus_decoder_get_size(2));
cfgs++;

Gregory Maxwell
committed
fprintf(stdout," opus_decoder_create() ........................ OK.\n");
fprintf(stdout," opus_decoder_init() .......................... OK.\n");

Gregory Maxwell
committed
VG_UNDEF(&dec_final_range,sizeof(dec_final_range));
err=opus_decoder_ctl(dec, OPUS_GET_FINAL_RANGE(&dec_final_range));
if(err!=OPUS_OK)test_failed();
VG_CHECK(&dec_final_range,sizeof(dec_final_range));

Gregory Maxwell
committed
fprintf(stdout," OPUS_GET_FINAL_RANGE ......................... OK.\n");

Gregory Maxwell
committed
cfgs++;
err=opus_decoder_ctl(dec,OPUS_UNIMPLEMENTED);
if(err!=OPUS_UNIMPLEMENTED)test_failed();

Gregory Maxwell
committed
fprintf(stdout," OPUS_UNIMPLEMENTED ........................... OK.\n");

Gregory Maxwell
committed
cfgs++;
VG_UNDEF(&i,sizeof(i));
err=opus_decoder_ctl(dec, OPUS_GET_BANDWIDTH(&i));
if(err != OPUS_OK || i!=0)test_failed();

Gregory Maxwell
committed
fprintf(stdout," OPUS_GET_BANDWIDTH ........................... OK.\n");

Gregory Maxwell
committed
cfgs++;
/*GET_PITCH has different execution paths depending on the previously decoded frame.*/
err=opus_decoder_ctl(dec, OPUS_GET_PITCH(nullptr));
if(err!=OPUS_BAD_ARG)test_failed();
cfgs++;
VG_UNDEF(&i,sizeof(i));
err=opus_decoder_ctl(dec, OPUS_GET_PITCH(&i));
if(err != OPUS_OK || i>0 || i<-1)test_failed();
cfgs++;
VG_UNDEF(packet,sizeof(packet));
packet[0]=63<<2;packet[1]=packet[2]=0;
if(opus_decode(dec, packet, 3, sbuf, 960, 0)!=960)test_failed();
cfgs++;
VG_UNDEF(&i,sizeof(i));
err=opus_decoder_ctl(dec, OPUS_GET_PITCH(&i));
if(err != OPUS_OK || i>0 || i<-1)test_failed();
cfgs++;
packet[0]=1;
if(opus_decode(dec, packet, 1, sbuf, 960, 0)!=960)test_failed();
cfgs++;
VG_UNDEF(&i,sizeof(i));
err=opus_decoder_ctl(dec, OPUS_GET_PITCH(&i));
if(err != OPUS_OK || i>0 || i<-1)test_failed();
cfgs++;

Gregory Maxwell
committed
fprintf(stdout," OPUS_GET_PITCH ............................... OK.\n");

Gregory Maxwell
committed
/*Reset the decoder*/
dec2=malloc(opus_decoder_get_size(2));
memcpy(dec2,dec,opus_decoder_get_size(2));
if(opus_decoder_ctl(dec, OPUS_RESET_STATE)!=OPUS_OK)test_failed();
if(memcmp(dec2,dec,opus_decoder_get_size(2))==0)test_failed();
free(dec2);

Gregory Maxwell
committed
fprintf(stdout," OPUS_RESET_STATE ............................. OK.\n");

Gregory Maxwell
committed
cfgs++;
VG_UNDEF(packet,sizeof(packet));
packet[0]=0;
if(opus_decoder_get_nb_samples(dec,packet,1)!=480)test_failed();
cfgs++;
packet[0]=(63<<2)|3;
packet[1]=63;
if(opus_decoder_get_nb_samples(dec,packet,2)!=OPUS_INVALID_PACKET)test_failed();

Gregory Maxwell
committed
fprintf(stdout," opus_decoder_get_nb_samples() ................ OK.\n");

Gregory Maxwell
committed
cfgs++;
if(OPUS_BAD_ARG!=opus_packet_get_nb_frames(packet,0))test_failed();
for(i=0;i<256;i++) {
int l1res[4]={1,2,2,OPUS_INVALID_PACKET};
packet[0]=i;
if(l1res[packet[0]&3]!=opus_packet_get_nb_frames(packet,1))test_failed();
cfgs++;
for(j=0;j<256;j++) {
packet[1]=j;
if(((packet[0]&3)!=3?l1res[packet[0]&3]:packet[1]&63)!=opus_packet_get_nb_frames(packet,2))test_failed();
cfgs++;
}
}

Gregory Maxwell
committed
fprintf(stdout," opus_packet_get_nb_frames() .................. OK.\n");

Gregory Maxwell
committed
for(i=0;i<256;i++) {
int bw;
packet[0]=i;
bw=packet[0]>>4;
bw=OPUS_BANDWIDTH_NARROWBAND+(((((bw&7)*9)&(63-(bw&8)))+2+12*((bw&8)!=0))>>4);
if(bw!=opus_packet_get_bandwidth(packet))test_failed();
cfgs++;
}

Gregory Maxwell
committed
fprintf(stdout," opus_packet_get_bandwidth() .................. OK.\n");

Gregory Maxwell
committed
for(i=0;i<256;i++) {
int fp3s,rate;
packet[0]=i;
fp3s=packet[0]>>3;
fp3s=((((3-(fp3s&3))*13&119)+9)>>2)*((fp3s>13)*(3-((fp3s&3)==3))+1)*25;
for(rate=0;rate<5;rate++) {
if((opus_rates[rate]*3/fp3s)!=opus_packet_get_samples_per_frame(packet,opus_rates[rate]))test_failed();
cfgs++;
}
}

Gregory Maxwell
committed
fprintf(stdout," opus_packet_get_samples_per_frame() .......... OK.\n");

Gregory Maxwell
committed
packet[0]=(63<<2)+3;
packet[1]=49;
for(j=2;j<51;j++)packet[j]=0;
VG_UNDEF(sbuf,sizeof(sbuf));
if(opus_decode(dec, packet, 51, sbuf, 960, 0)!=OPUS_INVALID_PACKET)test_failed();
cfgs++;
packet[0]=(63<<2);
packet[1]=packet[2]=0;
if(opus_decode(dec, packet, -1, sbuf, 960, 0)!=OPUS_BAD_ARG)test_failed();
cfgs++;
if(opus_decode(dec, packet, 3, sbuf, 60, 0)!=OPUS_BUFFER_TOO_SMALL)test_failed();
cfgs++;
if(opus_decode(dec, packet, 3, sbuf, 480, 0)!=OPUS_BUFFER_TOO_SMALL)test_failed();
cfgs++;
if(opus_decode(dec, packet, 3, sbuf, 960, 0)!=960)test_failed();
cfgs++;

Gregory Maxwell
committed
fprintf(stdout," opus_decode() ................................ OK.\n");

Gregory Maxwell
committed
#ifndef DISABLE_FLOAT_API
VG_UNDEF(fbuf,sizeof(fbuf));
if(opus_decode_float(dec, packet, 3, fbuf, 960, 0)!=960)test_failed();
cfgs++;

Gregory Maxwell
committed
fprintf(stdout," opus_decode_float() .......................... OK.\n");

Gregory Maxwell
committed
#endif
#if 0
/*These tests are disabled because the library crashes with null states*/
if(opus_decoder_ctl(0,OPUS_RESET_STATE) !=OPUS_INVALID_STATE)test_failed();
if(opus_decoder_init(0,48000,1) !=OPUS_INVALID_STATE)test_failed();
if(opus_decode(0,packet,1,outbuf,2880,0) !=OPUS_INVALID_STATE)test_failed();
if(opus_decode_float(0,packet,1,0,2880,0) !=OPUS_INVALID_STATE)test_failed();
if(opus_decoder_get_nb_samples(0,packet,1) !=OPUS_INVALID_STATE)test_failed();
if(opus_packet_get_nb_frames(NULL,1) !=OPUS_BAD_ARG)test_failed();
if(opus_packet_get_bandwidth(NULL) !=OPUS_BAD_ARG)test_failed();
if(opus_packet_get_samples_per_frame(NULL,48000)!=OPUS_BAD_ARG)test_failed();
#endif
opus_decoder_destroy(dec);
cfgs++;
fprintf(stdout," All decoder interface tests passed\n");
fprintf(stdout," (%6d API invocations)\n",cfgs);
return cfgs;
}

Gregory Maxwell
committed
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
opus_int32 test_msdec_api(void)
{
opus_uint32 dec_final_range;
OpusMSDecoder *dec;
opus_int32 i,j,cfgs;
unsigned char packet[1276];
unsigned char mapping[256] = {0,1};
#ifndef DISABLE_FLOAT_API
float fbuf[960*2];
#endif
short sbuf[960*2];
int a,b,c,err;
int *nullptr;
nullptr=0;
cfgs=0;
/*First test invalid configurations which should fail*/
fprintf(stdout,"\n Multistream decoder basic API tests\n");
fprintf(stdout," ---------------------------------------------------\n");
for(a=-1;a<4;a++)
{
for(b=-1;b<4;b++)
{
i=opus_multistream_decoder_get_size(a,b);
if(((a>0&&b<=a&&b>=0)&&(i<=2048||i>((1<<16)*a)))||((a<1||b>a||b<0)&&i!=0))test_failed();
fprintf(stdout," opus_multistream_decoder_get_size(%2d,%2d)=%d %sOK.\n",a,b,i,i>0?"":"... ");
cfgs++;
}
}
/*Test with unsupported sample rates*/
for(c=1;c<3;c++)
{
for(i=-7;i<=96000;i++)
{
int fs;
if((i==8000||i==12000||i==16000||i==24000||i==48000)&&(c==1||c==2))continue;
switch(i)
{
case(-5):fs=-8000;break;
case(-6):fs=INT32_MAX;break;
case(-7):fs=INT32_MIN;break;
default:fs=i;
}
err = OPUS_OK;
VG_UNDEF(&err,sizeof(err));
dec = opus_multistream_decoder_create(fs, c, 1, c-1, mapping, &err);
if(err!=OPUS_BAD_ARG || dec!=NULL)test_failed();
cfgs++;
dec=malloc(opus_multistream_decoder_get_size(1,1));
if(dec==NULL)test_failed();
err = opus_multistream_decoder_init(dec,fs,c,1,c-1, mapping);
if(err!=OPUS_BAD_ARG)test_failed();
cfgs++;
free(dec);
}
}
VG_UNDEF(&err,sizeof(err));
dec = opus_multistream_decoder_create(48000, 2, 1, 1, mapping, &err);
if(err!=OPUS_OK || dec==NULL)test_failed();
VG_CHECK(dec,opus_multistream_decoder_get_size(1,1));
cfgs++;
fprintf(stdout," opus_multistream_decoder_create() ............ OK.\n");
fprintf(stdout," opus_multistream_decoder_init() .............. OK.\n");
VG_UNDEF(&dec_final_range,sizeof(dec_final_range));
err=opus_multistream_decoder_ctl(dec, OPUS_GET_FINAL_RANGE(&dec_final_range));
if(err!=OPUS_OK)test_failed();
VG_CHECK(&dec_final_range,sizeof(dec_final_range));
fprintf(stdout," OPUS_GET_FINAL_RANGE ......................... OK.\n");
cfgs++;
err=opus_multistream_decoder_ctl(dec,OPUS_UNIMPLEMENTED);
if(err!=OPUS_UNIMPLEMENTED)test_failed();
fprintf(stdout," OPUS_UNIMPLEMENTED ........................... OK.\n");
cfgs++;
#if 0
/*Currently unimplemented for multistream*/
VG_UNDEF(&i,sizeof(i));
err=opus_multistream_decoder_ctl(dec, OPUS_GET_BANDWIDTH(&i));
if(err != OPUS_OK || i!=0)test_failed();
fprintf(stdout," OPUS_GET_BANDWIDTH ........................... OK.\n");
cfgs++;
/*GET_PITCH has different execution paths depending on the previously decoded frame.*/
err=opus_multistream_decoder_ctl(dec, OPUS_GET_PITCH(nullptr));
if(err!=OPUS_BAD_ARG)test_failed();
cfgs++;
VG_UNDEF(&i,sizeof(i));
err=opus_multistream_decoder_ctl(dec, OPUS_GET_PITCH(&i));
if(err != OPUS_OK || i>0 || i<-1)test_failed();
cfgs++;
VG_UNDEF(packet,sizeof(packet));
packet[0]=63<<2;packet[1]=packet[2]=0;
if(opus_multistream_decode(dec, packet, 3, sbuf, 960, 0)!=960)test_failed();
cfgs++;
VG_UNDEF(&i,sizeof(i));
err=opus_multistream_decoder_ctl(dec, OPUS_GET_PITCH(&i));
if(err != OPUS_OK || i>0 || i<-1)test_failed();
cfgs++;
packet[0]=1;
if(opus_multistream_decode(dec, packet, 1, sbuf, 960, 0)!=960)test_failed();
cfgs++;
VG_UNDEF(&i,sizeof(i));
err=opus_multistream_decoder_ctl(dec, OPUS_GET_PITCH(&i));
if(err != OPUS_OK || i>0 || i<-1)test_failed();
cfgs++;
fprintf(stdout," OPUS_GET_PITCH ............................... OK.\n");
#endif
/*Reset the decoder*/
if(opus_multistream_decoder_ctl(dec, OPUS_RESET_STATE)!=OPUS_OK)test_failed();
fprintf(stdout," OPUS_RESET_STATE ............................. OK.\n");
cfgs++;
packet[0]=(63<<2)+3;
packet[1]=49;
for(j=2;j<51;j++)packet[j]=0;
VG_UNDEF(sbuf,sizeof(sbuf));
if(opus_multistream_decode(dec, packet, 51, sbuf, 960, 0)!=OPUS_INVALID_PACKET)test_failed();
cfgs++;
packet[0]=(63<<2);
packet[1]=packet[2]=0;
if(opus_multistream_decode(dec, packet, -1, sbuf, 960, 0)!=OPUS_BAD_ARG){printf("%d\n",opus_multistream_decode(dec, packet, -1, sbuf, 960, 0));test_failed();}
cfgs++;
if(opus_multistream_decode(dec, packet, 3, sbuf, 60, 0)!=OPUS_BUFFER_TOO_SMALL)test_failed();
cfgs++;
if(opus_multistream_decode(dec, packet, 3, sbuf, 480, 0)!=OPUS_BUFFER_TOO_SMALL)test_failed();
cfgs++;
if(opus_multistream_decode(dec, packet, 3, sbuf, 960, 0)!=960)test_failed();
cfgs++;
fprintf(stdout," opus_multistream_decode() .................... OK.\n");
#ifndef DISABLE_FLOAT_API
VG_UNDEF(fbuf,sizeof(fbuf));
if(opus_multistream_decode_float(dec, packet, 3, fbuf, 960, 0)!=960)test_failed();
cfgs++;
fprintf(stdout," opus_multistream_decode_float() .............. OK.\n");
#endif
#if 0
/*These tests are disabled because the library crashes with null states*/
if(opus_multistream_decoder_ctl(0,OPUS_RESET_STATE) !=OPUS_INVALID_STATE)test_failed();
if(opus_multistream_decoder_init(0,48000,1) !=OPUS_INVALID_STATE)test_failed();
if(opus_multistream_decode(0,packet,1,outbuf,2880,0) !=OPUS_INVALID_STATE)test_failed();
if(opus_multistream_decode_float(0,packet,1,0,2880,0) !=OPUS_INVALID_STATE)test_failed();
if(opus_multistream_decoder_get_nb_samples(0,packet,1) !=OPUS_INVALID_STATE)test_failed();
#endif
opus_multistream_decoder_destroy(dec);
cfgs++;
fprintf(stdout," All multistream decoder interface tests passed\n");
fprintf(stdout," (%6d API invocations)\n",cfgs);
return cfgs;
}

Gregory Maxwell
committed
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
#ifdef VALGRIND
#define UNDEFINE_FOR_PARSE toc=-1; \
frames[0]=(unsigned char *)0; \
frames[1]=(unsigned char *)0; \
payload_offset=-1; \
VG_UNDEF(&toc,sizeof(toc)); \
VG_UNDEF(frames,sizeof(frames));\
VG_UNDEF(&payload_offset,sizeof(payload_offset));
#else
#define UNDEFINE_FOR_PARSE toc=-1; \
frames[0]=(unsigned char *)0; \
frames[1]=(unsigned char *)0; \
payload_offset=-1;
#endif
/* This test exercises the heck out of the libopus parser.
It is much larger than the parser itself in part because
it tries to hit a lot of corner cases that could never
fail with the libopus code, but might be problematic for
other implementations. */
opus_int32 test_parse(void)
{
opus_int32 i,j,jj,sz;
unsigned char packet[1276];
opus_int32 cfgs,cfgs_total;
unsigned char toc;
const unsigned char *frames[48];
short size[48];
int payload_offset, ret;
fprintf(stdout,"\n Packet header parsing tests\n");
fprintf(stdout," ---------------------------------------------------\n");

Gregory Maxwell
committed
memset(packet,0,sizeof(char)*1276);
packet[0]=63<<2;
if(opus_packet_parse(packet,1,&toc,frames,0,&payload_offset)!=OPUS_BAD_ARG)test_failed();
cfgs_total=cfgs=1;
/*code 0*/
for(i=0;i<64;i++)
{
UNDEFINE_FOR_PARSE
ret=opus_packet_parse(packet,4,&toc,frames,size,&payload_offset);
cfgs++;
if(ret!=1)test_failed();
if(size[0]!=3)test_failed();
if(frames[0]!=packet+1)test_failed();
}

Gregory Maxwell
committed
fprintf(stdout," code 0 (%2d cases) ............................ OK.\n",cfgs);

Gregory Maxwell
committed
cfgs_total+=cfgs;cfgs=0;
/*code 1, two frames of the same size*/
for(i=0;i<64;i++)
{
packet[0]=(i<<2)+1;
for(jj=0;jj<=1275*2+3;jj++)
{
UNDEFINE_FOR_PARSE
ret=opus_packet_parse(packet,jj,&toc,frames,size,&payload_offset);
cfgs++;
if((jj&1)==1 && jj<=2551)
{
/* Must pass if payload length even (packet length odd) and
size<=2551, must fail otherwise. */
if(ret!=2)test_failed();
if(size[0]!=size[1] || size[0]!=((jj-1)>>1))test_failed();
if(frames[0]!=packet+1)test_failed();
if(frames[1]!=frames[0]+size[0])test_failed();
if((toc>>2)!=i)test_failed();
} else if(ret!=OPUS_INVALID_PACKET)test_failed();
}
}

Gregory Maxwell
committed
fprintf(stdout," code 1 (%6d cases) ........................ OK.\n",cfgs);

Gregory Maxwell
committed
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
cfgs_total+=cfgs;cfgs=0;
for(i=0;i<64;i++)
{
/*code 2, length code overflow*/
packet[0]=(i<<2)+2;
UNDEFINE_FOR_PARSE
ret=opus_packet_parse(packet,1,&toc,frames,size,&payload_offset);
cfgs++;
if(ret!=OPUS_INVALID_PACKET)test_failed();
packet[1]=252;
UNDEFINE_FOR_PARSE
ret=opus_packet_parse(packet,2,&toc,frames,size,&payload_offset);
cfgs++;
if(ret!=OPUS_INVALID_PACKET)test_failed();
for(j=0;j<1275;j++)
{
if(j<252)packet[1]=j;
else{packet[1]=252+(j&3);packet[2]=(j-252)>>2;}
/*Code 2, one too short*/
UNDEFINE_FOR_PARSE
ret=opus_packet_parse(packet,j+(j<252?2:3)-1,&toc,frames,size,&payload_offset);
cfgs++;
if(ret!=OPUS_INVALID_PACKET)test_failed();
/*Code 2, one too long*/
UNDEFINE_FOR_PARSE
ret=opus_packet_parse(packet,j+(j<252?2:3)+1276,&toc,frames,size,&payload_offset);
cfgs++;
if(ret!=OPUS_INVALID_PACKET)test_failed();
/*Code 2, second zero*/
UNDEFINE_FOR_PARSE
ret=opus_packet_parse(packet,j+(j<252?2:3),&toc,frames,size,&payload_offset);
cfgs++;
if(ret!=2)test_failed();
if(size[0]!=j||size[1]!=0)test_failed();
if(frames[1]!=frames[0]+size[0])test_failed();
if((toc>>2)!=i)test_failed();
/*Code 2, normal*/
UNDEFINE_FOR_PARSE
ret=opus_packet_parse(packet,(j<<1)+4,&toc,frames,size,&payload_offset);
cfgs++;
if(ret!=2)test_failed();
if(size[0]!=j||size[1]!=(j<<1)+3-j-(j<252?1:2))test_failed();
if(frames[1]!=frames[0]+size[0])test_failed();
if((toc>>2)!=i)test_failed();
}
}

Gregory Maxwell
committed
fprintf(stdout," code 2 (%6d cases) ........................ OK.\n",cfgs);

Gregory Maxwell
committed
cfgs_total+=cfgs;cfgs=0;
for(i=0;i<64;i++)
{
packet[0]=(i<<2)+3;
/*code 3, length code overflow*/
UNDEFINE_FOR_PARSE
ret=opus_packet_parse(packet,1,&toc,frames,size,&payload_offset);
cfgs++;
if(ret!=OPUS_INVALID_PACKET)test_failed();
}

Gregory Maxwell
committed
fprintf(stdout," code 3 m-truncation (%2d cases) ............... OK.\n",cfgs);

Gregory Maxwell
committed
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
cfgs_total+=cfgs;cfgs=0;
for(i=0;i<64;i++)
{
/*code 3, m is zero or 49-63*/
packet[0]=(i<<2)+3;
for(jj=49;jj<=64;jj++)
{
packet[1]=0+(jj&63); /*CBR, no padding*/
UNDEFINE_FOR_PARSE
ret=opus_packet_parse(packet,1275,&toc,frames,size,&payload_offset);
cfgs++;
if(ret!=OPUS_INVALID_PACKET)test_failed();
packet[1]=128+(jj&63); /*VBR, no padding*/
UNDEFINE_FOR_PARSE
ret=opus_packet_parse(packet,1275,&toc,frames,size,&payload_offset);
cfgs++;
if(ret!=OPUS_INVALID_PACKET)test_failed();
packet[1]=64+(jj&63); /*CBR, padding*/
UNDEFINE_FOR_PARSE
ret=opus_packet_parse(packet,1275,&toc,frames,size,&payload_offset);
cfgs++;
if(ret!=OPUS_INVALID_PACKET)test_failed();
packet[1]=128+64+(jj&63); /*VBR, padding*/
UNDEFINE_FOR_PARSE
ret=opus_packet_parse(packet,1275,&toc,frames,size,&payload_offset);
cfgs++;
if(ret!=OPUS_INVALID_PACKET)test_failed();
}
}

Gregory Maxwell
committed
fprintf(stdout," code 3 m=0,49-64 (%2d cases) ................ OK.\n",cfgs);

Gregory Maxwell
committed
cfgs_total+=cfgs;cfgs=0;
for(i=0;i<64;i++)
{
packet[0]=(i<<2)+3;
/*code 3, m is one, cbr*/
packet[1]=1;
for(j=0;j<1276;j++)
{
UNDEFINE_FOR_PARSE
ret=opus_packet_parse(packet,j+2,&toc,frames,size,&payload_offset);
cfgs++;
if(ret!=1)test_failed();
if(size[0]!=j)test_failed();
if((toc>>2)!=i)test_failed();
}
UNDEFINE_FOR_PARSE
ret=opus_packet_parse(packet,1276+2,&toc,frames,size,&payload_offset);
cfgs++;
if(ret!=OPUS_INVALID_PACKET)test_failed();
}

Gregory Maxwell
committed
fprintf(stdout," code 3 m=1 CBR (%2d cases) ................. OK.\n",cfgs);

Gregory Maxwell
committed
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
cfgs_total+=cfgs;cfgs=0;
for(i=0;i<64;i++)
{
int frame_samp;
/*code 3, m>1 CBR*/
packet[0]=(i<<2)+3;
frame_samp=opus_packet_get_samples_per_frame(packet,48000);
for(j=2;j<49;j++)
{
packet[1]=j;
for(sz=2;sz<((j+2)*1275);sz++)
{
UNDEFINE_FOR_PARSE
ret=opus_packet_parse(packet,sz,&toc,frames,size,&payload_offset);
cfgs++;
/*Must be <=120ms, must be evenly divisible, can't have frames>1275 bytes*/
if(frame_samp*j<=5760 && (sz-2)%j==0 && (sz-2)/j<1276)
{
if(ret!=j)test_failed();
for(jj=1;jj<ret;jj++)if(frames[jj]!=frames[jj-1]+size[jj-1])test_failed();
if((toc>>2)!=i)test_failed();
} else if(ret!=OPUS_INVALID_PACKET)test_failed();
}
}
/*Super jumbo packets*/
packet[1]=5760/frame_samp;
UNDEFINE_FOR_PARSE
ret=opus_packet_parse(packet,1275*packet[1]+2,&toc,frames,size,&payload_offset);
cfgs++;
if(ret!=packet[1])test_failed();
for(jj=0;jj<ret;jj++)if(size[jj]!=1275)test_failed();
}

Gregory Maxwell
committed
fprintf(stdout," code 3 m=1-48 CBR (%2d cases) .......... OK.\n",cfgs);

Gregory Maxwell
committed
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
cfgs_total+=cfgs;cfgs=0;
for(i=0;i<64;i++)
{
int frame_samp;
/*Code 3 VBR, m one*/
packet[0]=(i<<2)+3;
packet[1]=128+1;
frame_samp=opus_packet_get_samples_per_frame(packet,48000);
for(jj=0;jj<1276;jj++)
{
UNDEFINE_FOR_PARSE
ret=opus_packet_parse(packet,2+jj,&toc,frames,size,&payload_offset);
cfgs++;
if(ret!=1)test_failed();
if(size[0]!=jj)test_failed();
if((toc>>2)!=i)test_failed();
}
UNDEFINE_FOR_PARSE
ret=opus_packet_parse(packet,2+1276,&toc,frames,size,&payload_offset);
cfgs++;
if(ret!=OPUS_INVALID_PACKET)test_failed();
for(j=2;j<49;j++)
{
packet[1]=128+j;
/*Length code overflow*/
UNDEFINE_FOR_PARSE
ret=opus_packet_parse(packet,2+j-2,&toc,frames,size,&payload_offset);
cfgs++;
if(ret!=OPUS_INVALID_PACKET)test_failed();
packet[2]=252;
packet[3]=0;
for(jj=4;jj<2+j;jj++)packet[jj]=0;
UNDEFINE_FOR_PARSE
ret=opus_packet_parse(packet,2+j,&toc,frames,size,&payload_offset);
cfgs++;
if(ret!=OPUS_INVALID_PACKET)test_failed();
/*One byte too short*/
for(jj=2;jj<2+j;jj++)packet[jj]=0;
UNDEFINE_FOR_PARSE
ret=opus_packet_parse(packet,2+j-2,&toc,frames,size,&payload_offset);
cfgs++;
if(ret!=OPUS_INVALID_PACKET)test_failed();
/*One byte too short thanks to length coding*/
packet[2]=252;
packet[3]=0;
for(jj=4;jj<2+j;jj++)packet[jj]=0;
UNDEFINE_FOR_PARSE
ret=opus_packet_parse(packet,2+j+252-1,&toc,frames,size,&payload_offset);
cfgs++;
if(ret!=OPUS_INVALID_PACKET)test_failed();
/*Most expensive way of coding zeros*/
for(jj=2;jj<2+j;jj++)packet[jj]=0;
UNDEFINE_FOR_PARSE
ret=opus_packet_parse(packet,2+j-1,&toc,frames,size,&payload_offset);
cfgs++;
if(frame_samp*j<=5760){
if(ret!=j)test_failed();
for(jj=0;jj<j;jj++)if(size[jj]!=0)test_failed();
if((toc>>2)!=i)test_failed();
} else if(ret!=OPUS_INVALID_PACKET)test_failed();
/*Quasi-CBR use of mode 3*/
for(sz=0;sz<8;sz++)
{
const int tsz[8]={50,201,403,700,1472,5110,20400,61298};
int pos=0;
int as=(tsz[sz]+i-j-2)/j;
for(jj=0;jj<j-1;jj++)
{
if(as<252){packet[2+pos]=as;pos++;}
else{packet[2+pos]=252+(as&3);packet[3+pos]=(as-252)>>2;pos+=2;}
}
UNDEFINE_FOR_PARSE
ret=opus_packet_parse(packet,tsz[sz]+i,&toc,frames,size,&payload_offset);
cfgs++;
if(frame_samp*j<=5760 && as<1276 && (tsz[sz]+i-2-pos-as*(j-1))<1276){
if(ret!=j)test_failed();
for(jj=0;jj<j-1;jj++)if(size[jj]!=as)test_failed();
if(size[j-1]!=(tsz[sz]+i-2-pos-as*(j-1)))test_failed();
if((toc>>2)!=i)test_failed();
} else if(ret!=OPUS_INVALID_PACKET)test_failed();
}
}
}

Gregory Maxwell
committed
fprintf(stdout," code 3 m=1-48 VBR (%2d cases) ............. OK.\n",cfgs);

Gregory Maxwell
committed
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
cfgs_total+=cfgs;cfgs=0;
for(i=0;i<64;i++)
{
packet[0]=(i<<2)+3;
/*Padding*/
packet[1]=128+1+64;
/*Overflow the length coding*/
for(jj=2;jj<127;jj++)packet[jj]=255;
UNDEFINE_FOR_PARSE
ret=opus_packet_parse(packet,127,&toc,frames,size,&payload_offset);
cfgs++;
if(ret!=OPUS_INVALID_PACKET)test_failed();
for(sz=0;sz<4;sz++)
{
const int tsz[4]={0,72,512,1275};
for(jj=sz;jj<65025;jj+=11)
{
int pos;
for(pos=0;pos<jj/254;pos++)packet[2+pos]=255;
packet[2+pos]=jj%254;
pos++;
if(sz==0&&i==63)
{
/*Code more padding than there is room in the packet*/
UNDEFINE_FOR_PARSE
ret=opus_packet_parse(packet,2+jj+pos-1,&toc,frames,size,&payload_offset);
cfgs++;
if(ret!=OPUS_INVALID_PACKET)test_failed();
}
UNDEFINE_FOR_PARSE
ret=opus_packet_parse(packet,2+jj+tsz[sz]+i+pos,&toc,frames,size,&payload_offset);
cfgs++;
if(tsz[sz]+i<1276)
{
if(ret!=1)test_failed();
if(size[0]!=tsz[sz]+i)test_failed();
if((toc>>2)!=i)test_failed();
} else if (ret!=OPUS_INVALID_PACKET)test_failed();
}
}
}

Gregory Maxwell
committed
fprintf(stdout," code 3 padding (%2d cases) ............... OK.\n",cfgs);

Gregory Maxwell
committed
cfgs_total+=cfgs;cfgs=0;

Gregory Maxwell
committed
fprintf(stdout," opus_packet_parse ............................ OK.\n");

Gregory Maxwell
committed
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
fprintf(stdout," All packet parsing tests passed\n");
fprintf(stdout," (%d API invocations)\n",cfgs_total);
return cfgs_total;
}
/* This is a helper macro for the encoder tests.
The encoder api tests all have a pattern of set-must-fail, set-must-fail,
set-must-pass, get-and-compare, set-must-pass, get-and-compare. */
#define CHECK_SETGET(setcall,getcall,badv,badv2,goodv,goodv2,sok,gok) \
i=(badv);\
if(opus_encoder_ctl(enc,setcall)==OPUS_OK)test_failed();\
i=(badv2);\
if(opus_encoder_ctl(enc,setcall)==OPUS_OK)test_failed();\
j=i=(goodv);\
if(opus_encoder_ctl(enc,setcall)!=OPUS_OK)test_failed();\
i=-12345;\
VG_UNDEF(&i,sizeof(i)); \
err=opus_encoder_ctl(enc,getcall);\
if(err!=OPUS_OK || i!=j)test_failed();\
j=i=(goodv2);\
if(opus_encoder_ctl(enc,setcall)!=OPUS_OK)test_failed();\
fprintf(stdout,sok);\
i=-12345;\
VG_UNDEF(&i,sizeof(i)); \
err=opus_encoder_ctl(enc,getcall);\
if(err!=OPUS_OK || i!=j)test_failed();\
fprintf(stdout,gok);\
cfgs+=6;
opus_int32 test_enc_api(void)
{
opus_uint32 enc_final_range;
OpusEncoder *enc;
opus_int32 i,j;
unsigned char packet[1276];
#ifndef DISABLE_FLOAT_API
float fbuf[960*2];
#endif
short sbuf[960*2];
int c,err,cfgs;
cfgs=0;
/*First test invalid configurations which should fail*/
fprintf(stdout,"\n Encoder basic API tests\n");
fprintf(stdout," ---------------------------------------------------\n");

Gregory Maxwell
committed
for(c=0;c<4;c++)
{
i=opus_encoder_get_size(c);
if(((c==1||c==2)&&(i<=2048||i>1<<17))||((c!=1&&c!=2)&&i!=0))test_failed();

Gregory Maxwell
committed
fprintf(stdout," opus_encoder_get_size(%d)=%d ...............%s OK.\n",c,i,i>0?"":"....");

Gregory Maxwell
committed
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
cfgs++;
}
/*Test with unsupported sample rates, channel counts*/
for(c=0;c<4;c++)
{
for(i=-7;i<=96000;i++)
{
int fs;
if((i==8000||i==12000||i==16000||i==24000||i==48000)&&(c==1||c==2))continue;
switch(i)
{
case(-5):fs=-8000;break;
case(-6):fs=INT32_MAX;break;
case(-7):fs=INT32_MIN;break;
default:fs=i;
}
err = OPUS_OK;
VG_UNDEF(&err,sizeof(err));
enc = opus_encoder_create(fs, c, OPUS_APPLICATION_VOIP, &err);
if(err!=OPUS_BAD_ARG || enc!=NULL)test_failed();
cfgs++;
opus_encoder_destroy(enc);
enc=malloc(opus_encoder_get_size(2));
if(enc==NULL)test_failed();
err = opus_encoder_init(enc, fs, c, OPUS_APPLICATION_VOIP);
if(err!=OPUS_BAD_ARG)test_failed();
cfgs++;
free(enc);
}
}
enc = opus_encoder_create(48000, 2, OPUS_AUTO, NULL);
if(enc!=NULL)test_failed();
cfgs++;
VG_UNDEF(&err,sizeof(err));
enc = opus_encoder_create(48000, 2, OPUS_AUTO, &err);
if(err!=OPUS_BAD_ARG || enc!=NULL)test_failed();
cfgs++;
VG_UNDEF(&err,sizeof(err));
enc = opus_encoder_create(48000, 2, OPUS_APPLICATION_VOIP, NULL);
if(enc==NULL)test_failed();
opus_encoder_destroy(enc);
cfgs++;
VG_UNDEF(&err,sizeof(err));
enc = opus_encoder_create(48000, 2, OPUS_APPLICATION_RESTRICTED_LOWDELAY, &err);
if(err!=OPUS_OK || enc==NULL)test_failed();
cfgs++;
err=opus_encoder_ctl(enc,OPUS_GET_LOOKAHEAD(&i));
if(err!=OPUS_OK || i<0 || i>32766)test_failed();
opus_encoder_destroy(enc);
cfgs++;
VG_UNDEF(&err,sizeof(err));
enc = opus_encoder_create(48000, 2, OPUS_APPLICATION_AUDIO, &err);
if(err!=OPUS_OK || enc==NULL)test_failed();
cfgs++;
err=opus_encoder_ctl(enc,OPUS_GET_LOOKAHEAD(&i));
if(err!=OPUS_OK || i<0 || i>32766)test_failed();
opus_encoder_destroy(enc);
cfgs++;
VG_UNDEF(&err,sizeof(err));
enc = opus_encoder_create(48000, 2, OPUS_APPLICATION_VOIP, &err);
if(err!=OPUS_OK || enc==NULL)test_failed();
cfgs++;

Gregory Maxwell
committed
fprintf(stdout," opus_encoder_create() ........................ OK.\n");
fprintf(stdout," opus_encoder_init() .......................... OK.\n");

Gregory Maxwell
committed
i=-12345;
VG_UNDEF(&i,sizeof(i));
err=opus_encoder_ctl(enc,OPUS_GET_LOOKAHEAD(&i));
if(err!=OPUS_OK || i<0 || i>32766)test_failed();
cfgs++;

Gregory Maxwell
committed
fprintf(stdout," OPUS_GET_LOOKAHEAD ........................... OK.\n");

Gregory Maxwell
committed
if(opus_encoder_ctl(enc,OPUS_UNIMPLEMENTED)!=OPUS_UNIMPLEMENTED)test_failed();

Gregory Maxwell
committed
fprintf(stdout," OPUS_UNIMPLEMENTED ........................... OK.\n");

Gregory Maxwell
committed
cfgs++;
CHECK_SETGET(OPUS_SET_APPLICATION(i),OPUS_GET_APPLICATION(&i),-1,OPUS_AUTO,
OPUS_APPLICATION_AUDIO,OPUS_APPLICATION_RESTRICTED_LOWDELAY,

Gregory Maxwell
committed
" OPUS_SET_APPLICATION ......................... OK.\n",
" OPUS_GET_APPLICATION ......................... OK.\n")

Gregory Maxwell
committed
if(opus_encoder_ctl(enc,OPUS_SET_BITRATE(1073741832))!=OPUS_OK)test_failed();
cfgs++;
VG_UNDEF(&i,sizeof(i));
if(opus_encoder_ctl(enc,OPUS_GET_BITRATE(&i))!=OPUS_OK)test_failed();
if(i>700000||i<256000)test_failed();
cfgs++;
CHECK_SETGET(OPUS_SET_BITRATE(i),OPUS_GET_BITRATE(&i),-12345,0,
500,256000,

Gregory Maxwell
committed
" OPUS_SET_BITRATE ............................. OK.\n",
" OPUS_GET_BITRATE ............................. OK.\n")

Gregory Maxwell
committed
CHECK_SETGET(OPUS_SET_FORCE_CHANNELS(i),OPUS_GET_FORCE_CHANNELS(&i),-1,3,
1,OPUS_AUTO,

Gregory Maxwell
committed
" OPUS_SET_FORCE_CHANNELS ...................... OK.\n",
" OPUS_GET_FORCE_CHANNELS ...................... OK.\n")

Gregory Maxwell
committed
i=-2;
if(opus_encoder_ctl(enc,OPUS_SET_BANDWIDTH(i))==OPUS_OK)test_failed();
cfgs++;
i=OPUS_BANDWIDTH_FULLBAND+1;
if(opus_encoder_ctl(enc,OPUS_SET_BANDWIDTH(i))==OPUS_OK)test_failed();
cfgs++;
i=OPUS_BANDWIDTH_NARROWBAND;
if(opus_encoder_ctl(enc,OPUS_SET_BANDWIDTH(i))!=OPUS_OK)test_failed();
cfgs++;
i=OPUS_BANDWIDTH_FULLBAND;
if(opus_encoder_ctl(enc,OPUS_SET_BANDWIDTH(i))!=OPUS_OK)test_failed();
cfgs++;
i=OPUS_BANDWIDTH_WIDEBAND;
if(opus_encoder_ctl(enc,OPUS_SET_BANDWIDTH(i))!=OPUS_OK)test_failed();
cfgs++;
i=OPUS_BANDWIDTH_MEDIUMBAND;
if(opus_encoder_ctl(enc,OPUS_SET_BANDWIDTH(i))!=OPUS_OK)test_failed();
cfgs++;

Gregory Maxwell
committed
fprintf(stdout," OPUS_SET_BANDWIDTH ........................... OK.\n");

Gregory Maxwell
committed
/*We don't test if the bandwidth has actually changed.
because the change may be delayed until the encoder is advanced.*/
i=-12345;
VG_UNDEF(&i,sizeof(i));
err=opus_encoder_ctl(enc,OPUS_GET_BANDWIDTH(&i));
if(err!=OPUS_OK || (i!=OPUS_BANDWIDTH_NARROWBAND&&
i!=OPUS_BANDWIDTH_MEDIUMBAND&&i!=OPUS_BANDWIDTH_WIDEBAND&&
i!=OPUS_BANDWIDTH_FULLBAND&&i!=OPUS_AUTO))test_failed();
cfgs++;
if(opus_encoder_ctl(enc,OPUS_SET_BANDWIDTH(OPUS_AUTO))!=OPUS_OK)test_failed();
cfgs++;

Gregory Maxwell
committed
fprintf(stdout," OPUS_GET_BANDWIDTH ........................... OK.\n");

Gregory Maxwell
committed
i=-2;
if(opus_encoder_ctl(enc,OPUS_SET_MAX_BANDWIDTH(i))==OPUS_OK)test_failed();
cfgs++;
i=OPUS_BANDWIDTH_FULLBAND+1;
if(opus_encoder_ctl(enc,OPUS_SET_MAX_BANDWIDTH(i))==OPUS_OK)test_failed();
cfgs++;
i=OPUS_BANDWIDTH_NARROWBAND;
if(opus_encoder_ctl(enc,OPUS_SET_MAX_BANDWIDTH(i))!=OPUS_OK)test_failed();
cfgs++;
i=OPUS_BANDWIDTH_FULLBAND;
if(opus_encoder_ctl(enc,OPUS_SET_MAX_BANDWIDTH(i))!=OPUS_OK)test_failed();
cfgs++;
i=OPUS_BANDWIDTH_WIDEBAND;
if(opus_encoder_ctl(enc,OPUS_SET_MAX_BANDWIDTH(i))!=OPUS_OK)test_failed();
cfgs++;
i=OPUS_BANDWIDTH_MEDIUMBAND;
if(opus_encoder_ctl(enc,OPUS_SET_MAX_BANDWIDTH(i))!=OPUS_OK)test_failed();
cfgs++;

Gregory Maxwell
committed
fprintf(stdout," OPUS_SET_MAX_BANDWIDTH ....................... OK.\n");
/*We don't test if the bandwidth has actually changed.
because the change may be delayed until the encoder is advanced.*/
i=-12345;
VG_UNDEF(&i,sizeof(i));