Chris@69: /* Copyright (c) 2011-2013 Xiph.Org Foundation Chris@69: Written by Gregory Maxwell */ Chris@69: /* Chris@69: Redistribution and use in source and binary forms, with or without Chris@69: modification, are permitted provided that the following conditions Chris@69: are met: Chris@69: Chris@69: - Redistributions of source code must retain the above copyright Chris@69: notice, this list of conditions and the following disclaimer. Chris@69: Chris@69: - Redistributions in binary form must reproduce the above copyright Chris@69: notice, this list of conditions and the following disclaimer in the Chris@69: documentation and/or other materials provided with the distribution. Chris@69: Chris@69: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS Chris@69: ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT Chris@69: LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR Chris@69: A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER Chris@69: OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, Chris@69: EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, Chris@69: PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR Chris@69: PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF Chris@69: LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING Chris@69: NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS Chris@69: SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Chris@69: */ Chris@69: Chris@69: #ifdef HAVE_CONFIG_H Chris@69: #include "config.h" Chris@69: #endif Chris@69: Chris@69: #include Chris@69: #include Chris@69: #include Chris@69: #include Chris@69: #include Chris@69: #include Chris@69: #include Chris@69: #if (!defined WIN32 && !defined _WIN32) || defined(__MINGW32__) Chris@69: #include Chris@69: #else Chris@69: #include Chris@69: #define getpid _getpid Chris@69: #endif Chris@69: #include "opus_multistream.h" Chris@69: #include "opus.h" Chris@69: #include "../src/opus_private.h" Chris@69: #include "test_opus_common.h" Chris@69: Chris@69: #define MAX_PACKET (1500) Chris@69: #define SAMPLES (48000*30) Chris@69: #define SSAMPLES (SAMPLES/3) Chris@69: #define MAX_FRAME_SAMP (5760) Chris@69: #define PI (3.141592653589793238462643f) Chris@69: #define RAND_SAMPLE(a) (a[fast_rand() % sizeof(a)/sizeof(a[0])]) Chris@69: Chris@69: void generate_music(short *buf, opus_int32 len) Chris@69: { Chris@69: opus_int32 a1,b1,a2,b2; Chris@69: opus_int32 c1,c2,d1,d2; Chris@69: opus_int32 i,j; Chris@69: a1=b1=a2=b2=0; Chris@69: c1=c2=d1=d2=0; Chris@69: j=0; Chris@69: /*60ms silence*/ Chris@69: for(i=0;i<2880;i++)buf[i*2]=buf[i*2+1]=0; Chris@69: for(i=2880;i>12)^((j>>10|j>>12)&26&j>>7)))&128)+128)<<15; Chris@69: r=fast_rand();v1+=r&65535;v1-=r>>16; Chris@69: r=fast_rand();v2+=r&65535;v2-=r>>16; Chris@69: b1=v1-a1+((b1*61+32)>>6);a1=v1; Chris@69: b2=v2-a2+((b2*61+32)>>6);a2=v2; Chris@69: c1=(30*(c1+b1+d1)+32)>>6;d1=b1; Chris@69: c2=(30*(c2+b2+d2)+32)>>6;d2=b2; Chris@69: v1=(c1+128)>>8; Chris@69: v2=(c2+128)>>8; Chris@69: buf[i*2]=v1>32767?32767:(v1<-32768?-32768:v1); Chris@69: buf[i*2+1]=v2>32767?32767:(v2<-32768?-32768:v2); Chris@69: if(i%6==0)j++; Chris@69: } Chris@69: } Chris@69: Chris@69: #if 0 Chris@69: static int save_ctr = 0; Chris@69: static void int_to_char(opus_uint32 i, unsigned char ch[4]) Chris@69: { Chris@69: ch[0] = i>>24; Chris@69: ch[1] = (i>>16)&0xFF; Chris@69: ch[2] = (i>>8)&0xFF; Chris@69: ch[3] = i&0xFF; Chris@69: } Chris@69: Chris@69: static OPUS_INLINE void save_packet(unsigned char* p, int len, opus_uint32 rng) Chris@69: { Chris@69: FILE *fout; Chris@69: unsigned char int_field[4]; Chris@69: char name[256]; Chris@69: snprintf(name,255,"test_opus_encode.%llu.%d.bit",(unsigned long long)iseed,save_ctr); Chris@69: fprintf(stdout,"writing %d byte packet to %s\n",len,name); Chris@69: fout=fopen(name, "wb+"); Chris@69: if(fout==NULL)test_failed(); Chris@69: int_to_char(len, int_field); Chris@69: fwrite(int_field, 1, 4, fout); Chris@69: int_to_char(rng, int_field); Chris@69: fwrite(int_field, 1, 4, fout); Chris@69: fwrite(p, 1, len, fout); Chris@69: fclose(fout); Chris@69: save_ctr++; Chris@69: } Chris@69: #endif Chris@69: Chris@69: int get_frame_size_enum(int frame_size, int sampling_rate) Chris@69: { Chris@69: int frame_size_enum; Chris@69: Chris@69: if(frame_size==sampling_rate/400) Chris@69: frame_size_enum = OPUS_FRAMESIZE_2_5_MS; Chris@69: else if(frame_size==sampling_rate/200) Chris@69: frame_size_enum = OPUS_FRAMESIZE_5_MS; Chris@69: else if(frame_size==sampling_rate/100) Chris@69: frame_size_enum = OPUS_FRAMESIZE_10_MS; Chris@69: else if(frame_size==sampling_rate/50) Chris@69: frame_size_enum = OPUS_FRAMESIZE_20_MS; Chris@69: else if(frame_size==sampling_rate/25) Chris@69: frame_size_enum = OPUS_FRAMESIZE_40_MS; Chris@69: else if(frame_size==3*sampling_rate/50) Chris@69: frame_size_enum = OPUS_FRAMESIZE_60_MS; Chris@69: else if(frame_size==4*sampling_rate/50) Chris@69: frame_size_enum = OPUS_FRAMESIZE_80_MS; Chris@69: else if(frame_size==5*sampling_rate/50) Chris@69: frame_size_enum = OPUS_FRAMESIZE_100_MS; Chris@69: else if(frame_size==6*sampling_rate/50) Chris@69: frame_size_enum = OPUS_FRAMESIZE_120_MS; Chris@69: else Chris@69: test_failed(); Chris@69: Chris@69: return frame_size_enum; Chris@69: } Chris@69: Chris@69: void test_encode(OpusEncoder *enc, int channels, int frame_size, OpusDecoder *dec, const char* debug_info) Chris@69: { Chris@69: int samp_count = 0; Chris@69: opus_int16 *inbuf; Chris@69: unsigned char packet[MAX_PACKET+257]; Chris@69: int len; Chris@69: opus_int16 *outbuf; Chris@69: int out_samples; Chris@69: Chris@69: /* Generate input data */ Chris@69: inbuf = (opus_int16*)malloc(sizeof(*inbuf)*SSAMPLES); Chris@69: generate_music(inbuf, SSAMPLES/2); Chris@69: Chris@69: /* Allocate memory for output data */ Chris@69: outbuf = (opus_int16*)malloc(sizeof(*outbuf)*MAX_FRAME_SAMP*3); Chris@69: Chris@69: /* Encode data, then decode for sanity check */ Chris@69: do { Chris@69: len = opus_encode(enc, &inbuf[samp_count*channels], frame_size, packet, MAX_PACKET); Chris@69: if(len<0 || len>MAX_PACKET) { Chris@69: fprintf(stderr,"%s\n",debug_info); Chris@69: fprintf(stderr,"opus_encode() returned %d\n",len); Chris@69: test_failed(); Chris@69: } Chris@69: Chris@69: out_samples = opus_decode(dec, packet, len, outbuf, MAX_FRAME_SAMP, 0); Chris@69: if(out_samples!=frame_size) { Chris@69: fprintf(stderr,"%s\n",debug_info); Chris@69: fprintf(stderr,"opus_decode() returned %d\n",out_samples); Chris@69: test_failed(); Chris@69: } Chris@69: Chris@69: samp_count += frame_size; Chris@69: } while (samp_count < ((SSAMPLES/2)-MAX_FRAME_SAMP)); Chris@69: Chris@69: /* Clean up */ Chris@69: free(inbuf); Chris@69: free(outbuf); Chris@69: } Chris@69: Chris@69: void fuzz_encoder_settings(const int num_encoders, const int num_setting_changes) Chris@69: { Chris@69: OpusEncoder *enc; Chris@69: OpusDecoder *dec; Chris@69: int i,j,err; Chris@69: Chris@69: /* Parameters to fuzz. Some values are duplicated to increase their probability of being tested. */ Chris@69: int sampling_rates[5] = {8000, 12000, 16000, 24000, 48000}; Chris@69: int channels[2] = {1, 2}; Chris@69: int applications[3] = {OPUS_APPLICATION_AUDIO, OPUS_APPLICATION_VOIP, OPUS_APPLICATION_RESTRICTED_LOWDELAY}; Chris@69: int bitrates[11] = {6000, 12000, 16000, 24000, 32000, 48000, 64000, 96000, 510000, OPUS_AUTO, OPUS_BITRATE_MAX}; Chris@69: int force_channels[4] = {OPUS_AUTO, OPUS_AUTO, 1, 2}; Chris@69: int use_vbr[3] = {0, 1, 1}; Chris@69: int vbr_constraints[3] = {0, 1, 1}; Chris@69: int complexities[11] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; Chris@69: int max_bandwidths[6] = {OPUS_BANDWIDTH_NARROWBAND, OPUS_BANDWIDTH_MEDIUMBAND, Chris@69: OPUS_BANDWIDTH_WIDEBAND, OPUS_BANDWIDTH_SUPERWIDEBAND, Chris@69: OPUS_BANDWIDTH_FULLBAND, OPUS_BANDWIDTH_FULLBAND}; Chris@69: int signals[4] = {OPUS_AUTO, OPUS_AUTO, OPUS_SIGNAL_VOICE, OPUS_SIGNAL_MUSIC}; Chris@69: int inband_fecs[3] = {0, 0, 1}; Chris@69: int packet_loss_perc[4] = {0, 1, 2, 5}; Chris@69: int lsb_depths[2] = {8, 24}; Chris@69: int prediction_disabled[3] = {0, 0, 1}; Chris@69: int use_dtx[2] = {0, 1}; Chris@69: int frame_sizes_ms_x2[9] = {5, 10, 20, 40, 80, 120, 160, 200, 240}; /* x2 to avoid 2.5 ms */ Chris@69: char debug_info[512]; Chris@69: Chris@69: for (i=0; i=64000?2:1)))!=OPUS_OK)test_failed(); Chris@69: if(opus_encoder_ctl(enc, OPUS_SET_COMPLEXITY((count>>2)%11))!=OPUS_OK)test_failed(); Chris@69: if(opus_encoder_ctl(enc, OPUS_SET_PACKET_LOSS_PERC((fast_rand()&15)&(fast_rand()%15)))!=OPUS_OK)test_failed(); Chris@69: bw=modes[j]==0?OPUS_BANDWIDTH_NARROWBAND+(fast_rand()%3): Chris@69: modes[j]==1?OPUS_BANDWIDTH_SUPERWIDEBAND+(fast_rand()&1): Chris@69: OPUS_BANDWIDTH_NARROWBAND+(fast_rand()%5); Chris@69: if(modes[j]==2&&bw==OPUS_BANDWIDTH_MEDIUMBAND)bw+=3; Chris@69: if(opus_encoder_ctl(enc, OPUS_SET_BANDWIDTH(bw))!=OPUS_OK)test_failed(); Chris@69: len = opus_encode(enc, &inbuf[i<<1], frame_size, packet, MAX_PACKET); Chris@69: if(len<0 || len>MAX_PACKET)test_failed(); Chris@69: if(opus_encoder_ctl(enc, OPUS_GET_FINAL_RANGE(&enc_final_range))!=OPUS_OK)test_failed(); Chris@69: if((fast_rand()&3)==0) Chris@69: { Chris@69: if(opus_packet_pad(packet,len,len+1)!=OPUS_OK)test_failed(); Chris@69: len++; Chris@69: } Chris@69: if((fast_rand()&7)==0) Chris@69: { Chris@69: if(opus_packet_pad(packet,len,len+256)!=OPUS_OK)test_failed(); Chris@69: len+=256; Chris@69: } Chris@69: if((fast_rand()&3)==0) Chris@69: { Chris@69: len=opus_packet_unpad(packet,len); Chris@69: if(len<1)test_failed(); Chris@69: } Chris@69: out_samples = opus_decode(dec, packet, len, &outbuf[i<<1], MAX_FRAME_SAMP, 0); Chris@69: if(out_samples!=frame_size)test_failed(); Chris@69: if(opus_decoder_ctl(dec, OPUS_GET_FINAL_RANGE(&dec_final_range))!=OPUS_OK)test_failed(); Chris@69: if(enc_final_range!=dec_final_range)test_failed(); Chris@69: /*LBRR decode*/ Chris@69: out_samples = opus_decode(dec_err[0], packet, len, out2buf, frame_size, (fast_rand()&3)!=0); Chris@69: if(out_samples!=frame_size)test_failed(); Chris@69: out_samples = opus_decode(dec_err[1], packet, (fast_rand()&3)==0?0:len, out2buf, MAX_FRAME_SAMP, (fast_rand()&7)!=0); Chris@69: if(out_samples<120)test_failed(); Chris@69: i+=frame_size; Chris@69: count++; Chris@69: }while(i<(SSAMPLES-MAX_FRAME_SAMP)); Chris@69: fprintf(stdout," Mode %s FB encode %s, %6d bps OK.\n",mstrings[modes[j]],rc==0?" VBR":rc==1?"CVBR":" CBR",rate); Chris@69: } Chris@69: } Chris@69: Chris@69: if(opus_encoder_ctl(enc, OPUS_SET_FORCE_MODE(OPUS_AUTO))!=OPUS_OK)test_failed(); Chris@69: if(opus_encoder_ctl(enc, OPUS_SET_FORCE_CHANNELS(OPUS_AUTO))!=OPUS_OK)test_failed(); Chris@69: if(opus_encoder_ctl(enc, OPUS_SET_INBAND_FEC(0))!=OPUS_OK)test_failed(); Chris@69: if(opus_encoder_ctl(enc, OPUS_SET_DTX(0))!=OPUS_OK)test_failed(); Chris@69: Chris@69: for(rc=0;rc<3;rc++) Chris@69: { Chris@69: if(opus_multistream_encoder_ctl(MSenc, OPUS_SET_VBR(rc<2))!=OPUS_OK)test_failed(); Chris@69: if(opus_multistream_encoder_ctl(MSenc, OPUS_SET_VBR_CONSTRAINT(rc==1))!=OPUS_OK)test_failed(); Chris@69: if(opus_multistream_encoder_ctl(MSenc, OPUS_SET_VBR_CONSTRAINT(rc==1))!=OPUS_OK)test_failed(); Chris@69: if(opus_multistream_encoder_ctl(MSenc, OPUS_SET_INBAND_FEC(rc==0))!=OPUS_OK)test_failed(); Chris@69: for(j=0;j<16;j++) Chris@69: { Chris@69: int rate; Chris@69: int modes[16]={0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2}; Chris@69: int rates[16]={4000,12000,32000,8000,16000,32000,48000,88000,4000,12000,32000,8000,16000,32000,48000,88000}; Chris@69: int frame[16]={160*1,160,80,160,160,80,40,20,160*1,160,80,160,160,80,40,20}; Chris@69: if(opus_multistream_encoder_ctl(MSenc, OPUS_SET_INBAND_FEC(rc==0&&j==1))!=OPUS_OK)test_failed(); Chris@69: if(opus_multistream_encoder_ctl(MSenc, OPUS_SET_FORCE_MODE(MODE_SILK_ONLY+modes[j]))!=OPUS_OK)test_failed(); Chris@69: rate=rates[j]+fast_rand()%rates[j]; Chris@69: if(opus_multistream_encoder_ctl(MSenc, OPUS_SET_DTX(fast_rand()&1))!=OPUS_OK)test_failed(); Chris@69: if(opus_multistream_encoder_ctl(MSenc, OPUS_SET_BITRATE(rate))!=OPUS_OK)test_failed(); Chris@69: count=i=0; Chris@69: do { Chris@69: int len,out_samples,frame_size,loss; Chris@69: opus_int32 pred; Chris@69: if(opus_multistream_encoder_ctl(MSenc, OPUS_GET_PREDICTION_DISABLED(&pred))!=OPUS_OK)test_failed(); Chris@69: if(opus_multistream_encoder_ctl(MSenc, OPUS_SET_PREDICTION_DISABLED((int)(fast_rand()&15)<(pred?11:4)))!=OPUS_OK)test_failed(); Chris@69: frame_size=frame[j]; Chris@69: if(opus_multistream_encoder_ctl(MSenc, OPUS_SET_COMPLEXITY((count>>2)%11))!=OPUS_OK)test_failed(); Chris@69: if(opus_multistream_encoder_ctl(MSenc, OPUS_SET_PACKET_LOSS_PERC((fast_rand()&15)&(fast_rand()%15)))!=OPUS_OK)test_failed(); Chris@69: if((fast_rand()&255)==0) Chris@69: { Chris@69: if(opus_multistream_encoder_ctl(MSenc, OPUS_RESET_STATE)!=OPUS_OK)test_failed(); Chris@69: if(opus_multistream_decoder_ctl(MSdec, OPUS_RESET_STATE)!=OPUS_OK)test_failed(); Chris@69: if((fast_rand()&3)!=0) Chris@69: { Chris@69: if(opus_multistream_decoder_ctl(MSdec_err, OPUS_RESET_STATE)!=OPUS_OK)test_failed(); Chris@69: } Chris@69: } Chris@69: if((fast_rand()&255)==0) Chris@69: { Chris@69: if(opus_multistream_decoder_ctl(MSdec_err, OPUS_RESET_STATE)!=OPUS_OK)test_failed(); Chris@69: } Chris@69: len = opus_multistream_encode(MSenc, &inbuf[i<<1], frame_size, packet, MAX_PACKET); Chris@69: if(len<0 || len>MAX_PACKET)test_failed(); Chris@69: if(opus_multistream_encoder_ctl(MSenc, OPUS_GET_FINAL_RANGE(&enc_final_range))!=OPUS_OK)test_failed(); Chris@69: if((fast_rand()&3)==0) Chris@69: { Chris@69: if(opus_multistream_packet_pad(packet,len,len+1,2)!=OPUS_OK)test_failed(); Chris@69: len++; Chris@69: } Chris@69: if((fast_rand()&7)==0) Chris@69: { Chris@69: if(opus_multistream_packet_pad(packet,len,len+256,2)!=OPUS_OK)test_failed(); Chris@69: len+=256; Chris@69: } Chris@69: if((fast_rand()&3)==0) Chris@69: { Chris@69: len=opus_multistream_packet_unpad(packet,len,2); Chris@69: if(len<1)test_failed(); Chris@69: } Chris@69: out_samples = opus_multistream_decode(MSdec, packet, len, out2buf, MAX_FRAME_SAMP, 0); Chris@69: if(out_samples!=frame_size*6)test_failed(); Chris@69: if(opus_multistream_decoder_ctl(MSdec, OPUS_GET_FINAL_RANGE(&dec_final_range))!=OPUS_OK)test_failed(); Chris@69: if(enc_final_range!=dec_final_range)test_failed(); Chris@69: /*LBRR decode*/ Chris@69: loss=(fast_rand()&63)==0; Chris@69: out_samples = opus_multistream_decode(MSdec_err, packet, loss?0:len, out2buf, frame_size*6, (fast_rand()&3)!=0); Chris@69: if(out_samples!=(frame_size*6))test_failed(); Chris@69: i+=frame_size; Chris@69: count++; Chris@69: }while(i<(SSAMPLES/12-MAX_FRAME_SAMP)); Chris@69: fprintf(stdout," Mode %s NB dual-mono MS encode %s, %6d bps OK.\n",mstrings[modes[j]],rc==0?" VBR":rc==1?"CVBR":" CBR",rate); Chris@69: } Chris@69: } Chris@69: Chris@69: bitrate_bps=512000; Chris@69: fsize=fast_rand()%31; Chris@69: fswitch=100; Chris@69: Chris@69: debruijn2(6,db62); Chris@69: count=i=0; Chris@69: do { Chris@69: unsigned char toc; Chris@69: const unsigned char *frames[48]; Chris@69: short size[48]; Chris@69: int payload_offset; Chris@69: opus_uint32 dec_final_range2; Chris@69: int jj,dec2; Chris@69: int len,out_samples; Chris@69: int frame_size=fsizes[db62[fsize]]; Chris@69: opus_int32 offset=i%(SAMPLES-MAX_FRAME_SAMP); Chris@69: Chris@69: opus_encoder_ctl(enc, OPUS_SET_BITRATE(bitrate_bps)); Chris@69: Chris@69: len = opus_encode(enc, &inbuf[offset<<1], frame_size, packet, MAX_PACKET); Chris@69: if(len<0 || len>MAX_PACKET)test_failed(); Chris@69: count++; Chris@69: Chris@69: opus_encoder_ctl(enc, OPUS_GET_FINAL_RANGE(&enc_final_range)); Chris@69: Chris@69: out_samples = opus_decode(dec, packet, len, &outbuf[offset<<1], MAX_FRAME_SAMP, 0); Chris@69: if(out_samples!=frame_size)test_failed(); Chris@69: Chris@69: opus_decoder_ctl(dec, OPUS_GET_FINAL_RANGE(&dec_final_range)); Chris@69: Chris@69: /* compare final range encoder rng values of encoder and decoder */ Chris@69: if(dec_final_range!=enc_final_range)test_failed(); Chris@69: Chris@69: /* We fuzz the packet, but take care not to only corrupt the payload Chris@69: Corrupted headers are tested elsewhere and we need to actually run Chris@69: the decoders in order to compare them. */ Chris@69: if(opus_packet_parse(packet,len,&toc,frames,size,&payload_offset)<=0)test_failed(); Chris@69: if((fast_rand()&1023)==0)len=0; Chris@69: for(j=(opus_int32)(frames[0]-packet);j0?packet:NULL, len, out2buf, MAX_FRAME_SAMP, 0); Chris@69: if(out_samples<0||out_samples>MAX_FRAME_SAMP)test_failed(); Chris@69: if((len>0&&out_samples!=frame_size))test_failed(); /*FIXME use lastframe*/ Chris@69: Chris@69: opus_decoder_ctl(dec_err[0], OPUS_GET_FINAL_RANGE(&dec_final_range)); Chris@69: Chris@69: /*randomly select one of the decoders to compare with*/ Chris@69: dec2=fast_rand()%9+1; Chris@69: out_samples = opus_decode(dec_err[dec2], len>0?packet:NULL, len, out2buf, MAX_FRAME_SAMP, 0); Chris@69: if(out_samples<0||out_samples>MAX_FRAME_SAMP)test_failed(); /*FIXME, use factor, lastframe for loss*/ Chris@69: Chris@69: opus_decoder_ctl(dec_err[dec2], OPUS_GET_FINAL_RANGE(&dec_final_range2)); Chris@69: if(len>0&&dec_final_range!=dec_final_range2)test_failed(); Chris@69: Chris@69: fswitch--; Chris@69: if(fswitch<1) Chris@69: { Chris@69: int new_size; Chris@69: fsize=(fsize+1)%36; Chris@69: new_size=fsizes[db62[fsize]]; Chris@69: if(new_size==960||new_size==480)fswitch=2880/new_size*(fast_rand()%19+1); Chris@69: else fswitch=(fast_rand()%(2880/new_size))+1; Chris@69: } Chris@69: bitrate_bps=((fast_rand()%508000+4000)+bitrate_bps)>>1; Chris@69: i+=frame_size; Chris@69: }while(i] [-fuzz ]\n",_argv[0]); Chris@69: } Chris@69: Chris@69: int main(int _argc, char **_argv) Chris@69: { Chris@69: int args=1; Chris@69: char * strtol_str=NULL; Chris@69: const char * oversion; Chris@69: const char * env_seed; Chris@69: int env_used; Chris@69: int num_encoders_to_fuzz=5; Chris@69: int num_setting_changes=40; Chris@69: Chris@69: env_used=0; Chris@69: env_seed=getenv("SEED"); Chris@69: if(_argc>1) Chris@69: iseed=strtol(_argv[1], &strtol_str, 10); /* the first input argument might be the seed */ Chris@69: if(strtol_str!=NULL && strtol_str[0]=='\0') /* iseed is a valid number */ Chris@69: args++; Chris@69: else if(env_seed) { Chris@69: iseed=atoi(env_seed); Chris@69: env_used=1; Chris@69: } Chris@69: else iseed=(opus_uint32)time(NULL)^(((opus_uint32)getpid()&65535)<<16); Chris@69: Rw=Rz=iseed; Chris@69: Chris@69: while(args<_argc) Chris@69: { Chris@69: if(strcmp(_argv[args], "-fuzz")==0 && _argc==(args+3)) { Chris@69: num_encoders_to_fuzz=strtol(_argv[args+1], &strtol_str, 10); Chris@69: if(strtol_str[0]!='\0' || num_encoders_to_fuzz<=0) { Chris@69: print_usage(_argv); Chris@69: return EXIT_FAILURE; Chris@69: } Chris@69: num_setting_changes=strtol(_argv[args+2], &strtol_str, 10); Chris@69: if(strtol_str[0]!='\0' || num_setting_changes<=0) { Chris@69: print_usage(_argv); Chris@69: return EXIT_FAILURE; Chris@69: } Chris@69: args+=3; Chris@69: } Chris@69: else { Chris@69: print_usage(_argv); Chris@69: return EXIT_FAILURE; Chris@69: } Chris@69: } Chris@69: Chris@69: oversion=opus_get_version_string(); Chris@69: if(!oversion)test_failed(); Chris@69: fprintf(stderr,"Testing %s encoder. Random seed: %u (%.4X)\n", oversion, iseed, fast_rand() % 65535); Chris@69: if(env_used)fprintf(stderr," Random seed set from the environment (SEED=%s).\n", env_seed); Chris@69: Chris@69: regression_test(); Chris@69: Chris@69: /*Setting TEST_OPUS_NOFUZZ tells the tool not to send garbage data Chris@69: into the decoders. This is helpful because garbage data Chris@69: may cause the decoders to clip, which angers CLANG IOC.*/ Chris@69: run_test1(getenv("TEST_OPUS_NOFUZZ")!=NULL); Chris@69: Chris@69: /* Fuzz encoder settings online */ Chris@69: if(getenv("TEST_OPUS_NOFUZZ")==NULL) { Chris@69: fprintf(stderr,"Running fuzz_encoder_settings with %d encoder(s) and %d setting change(s) each.\n", Chris@69: num_encoders_to_fuzz, num_setting_changes); Chris@69: fuzz_encoder_settings(num_encoders_to_fuzz, num_setting_changes); Chris@69: } Chris@69: Chris@69: fprintf(stderr,"Tests completed successfully.\n"); Chris@69: Chris@69: return 0; Chris@69: }