Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(831)

Side by Side Diff: third_party/opus/src/tests/test_opus_encode.c

Issue 2962373002: [Opus] Update to v1.2.1 (Closed)
Patch Set: Include minor updates including fix for win_clang Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* Copyright (c) 2011-2013 Xiph.Org Foundation 1 /* Copyright (c) 2011-2013 Xiph.Org Foundation
2 Written by Gregory Maxwell */ 2 Written by Gregory Maxwell */
3 /* 3 /*
4 Redistribution and use in source and binary forms, with or without 4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions 5 modification, are permitted provided that the following conditions
6 are met: 6 are met:
7 7
8 - Redistributions of source code must retain the above copyright 8 - Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer. 9 notice, this list of conditions and the following disclaimer.
10 10
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 #endif 44 #endif
45 #include "opus_multistream.h" 45 #include "opus_multistream.h"
46 #include "opus.h" 46 #include "opus.h"
47 #include "../src/opus_private.h" 47 #include "../src/opus_private.h"
48 #include "test_opus_common.h" 48 #include "test_opus_common.h"
49 49
50 #define MAX_PACKET (1500) 50 #define MAX_PACKET (1500)
51 #define SAMPLES (48000*30) 51 #define SAMPLES (48000*30)
52 #define SSAMPLES (SAMPLES/3) 52 #define SSAMPLES (SAMPLES/3)
53 #define MAX_FRAME_SAMP (5760) 53 #define MAX_FRAME_SAMP (5760)
54
55 #define PI (3.141592653589793238462643f) 54 #define PI (3.141592653589793238462643f)
55 #define RAND_SAMPLE(a) (a[fast_rand() % sizeof(a)/sizeof(a[0])])
56 56
57 void generate_music(short *buf, opus_int32 len) 57 void generate_music(short *buf, opus_int32 len)
58 { 58 {
59 opus_int32 a1,b1,a2,b2; 59 opus_int32 a1,b1,a2,b2;
60 opus_int32 c1,c2,d1,d2; 60 opus_int32 c1,c2,d1,d2;
61 opus_int32 i,j; 61 opus_int32 i,j;
62 a1=b1=a2=b2=0; 62 a1=b1=a2=b2=0;
63 c1=c2=d1=d2=0; 63 c1=c2=d1=d2=0;
64 j=0; 64 j=0;
65 /*60ms silence*/ 65 /*60ms silence*/
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 int_to_char(len, int_field); 105 int_to_char(len, int_field);
106 fwrite(int_field, 1, 4, fout); 106 fwrite(int_field, 1, 4, fout);
107 int_to_char(rng, int_field); 107 int_to_char(rng, int_field);
108 fwrite(int_field, 1, 4, fout); 108 fwrite(int_field, 1, 4, fout);
109 fwrite(p, 1, len, fout); 109 fwrite(p, 1, len, fout);
110 fclose(fout); 110 fclose(fout);
111 save_ctr++; 111 save_ctr++;
112 } 112 }
113 #endif 113 #endif
114 114
115 int get_frame_size_enum(int frame_size, int sampling_rate)
116 {
117 int frame_size_enum;
118
119 if(frame_size==sampling_rate/400)
120 frame_size_enum = OPUS_FRAMESIZE_2_5_MS;
121 else if(frame_size==sampling_rate/200)
122 frame_size_enum = OPUS_FRAMESIZE_5_MS;
123 else if(frame_size==sampling_rate/100)
124 frame_size_enum = OPUS_FRAMESIZE_10_MS;
125 else if(frame_size==sampling_rate/50)
126 frame_size_enum = OPUS_FRAMESIZE_20_MS;
127 else if(frame_size==sampling_rate/25)
128 frame_size_enum = OPUS_FRAMESIZE_40_MS;
129 else if(frame_size==3*sampling_rate/50)
130 frame_size_enum = OPUS_FRAMESIZE_60_MS;
131 else if(frame_size==4*sampling_rate/50)
132 frame_size_enum = OPUS_FRAMESIZE_80_MS;
133 else if(frame_size==5*sampling_rate/50)
134 frame_size_enum = OPUS_FRAMESIZE_100_MS;
135 else if(frame_size==6*sampling_rate/50)
136 frame_size_enum = OPUS_FRAMESIZE_120_MS;
137 else
138 test_failed();
139
140 return frame_size_enum;
141 }
142
143 void test_encode(OpusEncoder *enc, int channels, int frame_size, OpusDecoder *de c, const char* debug_info)
144 {
145 int samp_count = 0;
146 opus_int16 *inbuf;
147 unsigned char packet[MAX_PACKET+257];
148 int len;
149 opus_int16 *outbuf;
150 int out_samples;
151
152 /* Generate input data */
153 inbuf = (opus_int16*)malloc(sizeof(*inbuf)*SSAMPLES);
154 generate_music(inbuf, SSAMPLES/2);
155
156 /* Allocate memory for output data */
157 outbuf = (opus_int16*)malloc(sizeof(*outbuf)*MAX_FRAME_SAMP*3);
158
159 /* Encode data, then decode for sanity check */
160 do {
161 len = opus_encode(enc, &inbuf[samp_count*channels], frame_size, packet, MA X_PACKET);
162 if(len<0 || len>MAX_PACKET) {
163 fprintf(stderr,"%s\n",debug_info);
164 fprintf(stderr,"opus_encode() returned %d\n",len);
165 test_failed();
166 }
167
168 out_samples = opus_decode(dec, packet, len, outbuf, MAX_FRAME_SAMP, 0);
169 if(out_samples!=frame_size) {
170 fprintf(stderr,"%s\n",debug_info);
171 fprintf(stderr,"opus_decode() returned %d\n",out_samples);
172 test_failed();
173 }
174
175 samp_count += frame_size;
176 } while (samp_count < ((SSAMPLES/2)-MAX_FRAME_SAMP));
177
178 /* Clean up */
179 free(inbuf);
180 free(outbuf);
181 }
182
183 void fuzz_encoder_settings(const int num_encoders, const int num_setting_changes )
184 {
185 OpusEncoder *enc;
186 OpusDecoder *dec;
187 int i,j,err;
188
189 /* Parameters to fuzz. Some values are duplicated to increase their probabili ty of being tested. */
190 int sampling_rates[5] = {8000, 12000, 16000, 24000, 48000};
191 int channels[2] = {1, 2};
192 int applications[3] = {OPUS_APPLICATION_AUDIO, OPUS_APPLICATION_VOIP, OPUS_AP PLICATION_RESTRICTED_LOWDELAY};
193 int bitrates[11] = {6000, 12000, 16000, 24000, 32000, 48000, 64000, 96000, 51 0000, OPUS_AUTO, OPUS_BITRATE_MAX};
194 int force_channels[4] = {OPUS_AUTO, OPUS_AUTO, 1, 2};
195 int use_vbr[3] = {0, 1, 1};
196 int vbr_constraints[3] = {0, 1, 1};
197 int complexities[11] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
198 int max_bandwidths[6] = {OPUS_BANDWIDTH_NARROWBAND, OPUS_BANDWIDTH_MEDIUMBAND ,
199 OPUS_BANDWIDTH_WIDEBAND, OPUS_BANDWIDTH_SUPERWIDEBAN D,
200 OPUS_BANDWIDTH_FULLBAND, OPUS_BANDWIDTH_FULLBAND};
201 int signals[4] = {OPUS_AUTO, OPUS_AUTO, OPUS_SIGNAL_VOICE, OPUS_SIGNAL_MUSIC} ;
202 int inband_fecs[3] = {0, 0, 1};
203 int packet_loss_perc[4] = {0, 1, 2, 5};
204 int lsb_depths[2] = {8, 24};
205 int prediction_disabled[3] = {0, 0, 1};
206 int use_dtx[2] = {0, 1};
207 int frame_sizes_ms_x2[9] = {5, 10, 20, 40, 80, 120, 160, 200, 240}; /* x2 to avoid 2.5 ms */
208 char debug_info[512];
209
210 for (i=0; i<num_encoders; i++) {
211 int sampling_rate = RAND_SAMPLE(sampling_rates);
212 int num_channels = RAND_SAMPLE(channels);
213 int application = RAND_SAMPLE(applications);
214
215 dec = opus_decoder_create(sampling_rate, num_channels, &err);
216 if(err!=OPUS_OK || dec==NULL)test_failed();
217
218 enc = opus_encoder_create(sampling_rate, num_channels, application, &err);
219 if(err!=OPUS_OK || enc==NULL)test_failed();
220
221 for (j=0; j<num_setting_changes; j++) {
222 int bitrate = RAND_SAMPLE(bitrates);
223 int force_channel = RAND_SAMPLE(force_channels);
224 int vbr = RAND_SAMPLE(use_vbr);
225 int vbr_constraint = RAND_SAMPLE(vbr_constraints);
226 int complexity = RAND_SAMPLE(complexities);
227 int max_bw = RAND_SAMPLE(max_bandwidths);
228 int sig = RAND_SAMPLE(signals);
229 int inband_fec = RAND_SAMPLE(inband_fecs);
230 int pkt_loss = RAND_SAMPLE(packet_loss_perc);
231 int lsb_depth = RAND_SAMPLE(lsb_depths);
232 int pred_disabled = RAND_SAMPLE(prediction_disabled);
233 int dtx = RAND_SAMPLE(use_dtx);
234 int frame_size_ms_x2 = RAND_SAMPLE(frame_sizes_ms_x2);
235 int frame_size = frame_size_ms_x2*sampling_rate/2000;
236 int frame_size_enum = get_frame_size_enum(frame_size, sampling_rate);
237 force_channel = IMIN(force_channel, num_channels);
238
239 sprintf(debug_info,
240 "fuzz_encoder_settings: %d kHz, %d ch, application: %d, "
241 "%d bps, force ch: %d, vbr: %d, vbr constraint: %d, complexity: %d, "
242 "max bw: %d, signal: %d, inband fec: %d, pkt loss: %d%%, lsb de pth: %d, "
243 "pred disabled: %d, dtx: %d, (%d/2) ms\n",
244 sampling_rate/1000, num_channels, application, bitrate,
245 force_channel, vbr, vbr_constraint, complexity, max_bw, sig, in band_fec,
246 pkt_loss, lsb_depth, pred_disabled, dtx, frame_size_ms_x2);
247
248 if(opus_encoder_ctl(enc, OPUS_SET_BITRATE(bitrate)) != OPUS_OK) test_fa iled();
249 if(opus_encoder_ctl(enc, OPUS_SET_FORCE_CHANNELS(force_channel)) != OPU S_OK) test_failed();
250 if(opus_encoder_ctl(enc, OPUS_SET_VBR(vbr)) != OPUS_OK) test_failed();
251 if(opus_encoder_ctl(enc, OPUS_SET_VBR_CONSTRAINT(vbr_constraint)) != OP US_OK) test_failed();
252 if(opus_encoder_ctl(enc, OPUS_SET_COMPLEXITY(complexity)) != OPUS_OK) t est_failed();
253 if(opus_encoder_ctl(enc, OPUS_SET_MAX_BANDWIDTH(max_bw)) != OPUS_OK) te st_failed();
254 if(opus_encoder_ctl(enc, OPUS_SET_SIGNAL(sig)) != OPUS_OK) test_failed( );
255 if(opus_encoder_ctl(enc, OPUS_SET_INBAND_FEC(inband_fec)) != OPUS_OK) t est_failed();
256 if(opus_encoder_ctl(enc, OPUS_SET_PACKET_LOSS_PERC(pkt_loss)) != OPUS_O K) test_failed();
257 if(opus_encoder_ctl(enc, OPUS_SET_LSB_DEPTH(lsb_depth)) != OPUS_OK) tes t_failed();
258 if(opus_encoder_ctl(enc, OPUS_SET_PREDICTION_DISABLED(pred_disabled)) ! = OPUS_OK) test_failed();
259 if(opus_encoder_ctl(enc, OPUS_SET_DTX(dtx)) != OPUS_OK) test_failed();
260 if(opus_encoder_ctl(enc, OPUS_SET_EXPERT_FRAME_DURATION(frame_size_enum )) != OPUS_OK) test_failed();
261
262 test_encode(enc, num_channels, frame_size, dec, debug_info);
263 }
264
265 opus_encoder_destroy(enc);
266 opus_decoder_destroy(dec);
267 }
268 }
269
115 int run_test1(int no_fuzz) 270 int run_test1(int no_fuzz)
116 { 271 {
117 static const int fsizes[6]={960*3,960*2,120,240,480,960}; 272 static const int fsizes[6]={960*3,960*2,120,240,480,960};
118 static const char *mstrings[3] = {" LP","Hybrid"," MDCT"}; 273 static const char *mstrings[3] = {" LP","Hybrid"," MDCT"};
119 unsigned char mapping[256] = {0,1,255}; 274 unsigned char mapping[256] = {0,1,255};
120 unsigned char db62[36]; 275 unsigned char db62[36];
121 opus_int32 i; 276 opus_int32 i,j;
122 int rc,j,err; 277 int rc,err;
123 OpusEncoder *enc; 278 OpusEncoder *enc;
124 OpusMSEncoder *MSenc; 279 OpusMSEncoder *MSenc;
125 OpusDecoder *dec; 280 OpusDecoder *dec;
126 OpusMSDecoder *MSdec; 281 OpusMSDecoder *MSdec;
127 OpusMSDecoder *MSdec_err; 282 OpusMSDecoder *MSdec_err;
128 OpusDecoder *dec_err[10]; 283 OpusDecoder *dec_err[10];
129 short *inbuf; 284 short *inbuf;
130 short *outbuf; 285 short *outbuf;
131 short *out2buf; 286 short *out2buf;
132 opus_int32 bitrate_bps; 287 opus_int32 bitrate_bps;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 377
223 generate_music(inbuf,SAMPLES); 378 generate_music(inbuf,SAMPLES);
224 379
225 /* FILE *foo; 380 /* FILE *foo;
226 foo = fopen("foo.sw", "wb+"); 381 foo = fopen("foo.sw", "wb+");
227 fwrite(inbuf, 1, SAMPLES*2*2, foo); 382 fwrite(inbuf, 1, SAMPLES*2*2, foo);
228 fclose(foo);*/ 383 fclose(foo);*/
229 384
230 if(opus_encoder_ctl(enc, OPUS_SET_BANDWIDTH(OPUS_AUTO))!=OPUS_OK)test_failed( ); 385 if(opus_encoder_ctl(enc, OPUS_SET_BANDWIDTH(OPUS_AUTO))!=OPUS_OK)test_failed( );
231 if(opus_encoder_ctl(enc, OPUS_SET_FORCE_MODE(-2))!=OPUS_BAD_ARG)test_failed() ; 386 if(opus_encoder_ctl(enc, OPUS_SET_FORCE_MODE(-2))!=OPUS_BAD_ARG)test_failed() ;
387 if(opus_encode(enc, inbuf, 500, packet, MAX_PACKET)!=OPUS_BAD_ARG)test_failed ();
232 388
233 for(rc=0;rc<3;rc++) 389 for(rc=0;rc<3;rc++)
234 { 390 {
235 if(opus_encoder_ctl(enc, OPUS_SET_VBR(rc<2))!=OPUS_OK)test_failed(); 391 if(opus_encoder_ctl(enc, OPUS_SET_VBR(rc<2))!=OPUS_OK)test_failed();
236 if(opus_encoder_ctl(enc, OPUS_SET_VBR_CONSTRAINT(rc==1))!=OPUS_OK)test_fai led(); 392 if(opus_encoder_ctl(enc, OPUS_SET_VBR_CONSTRAINT(rc==1))!=OPUS_OK)test_fai led();
237 if(opus_encoder_ctl(enc, OPUS_SET_VBR_CONSTRAINT(rc==1))!=OPUS_OK)test_fai led(); 393 if(opus_encoder_ctl(enc, OPUS_SET_VBR_CONSTRAINT(rc==1))!=OPUS_OK)test_fai led();
238 if(opus_encoder_ctl(enc, OPUS_SET_INBAND_FEC(rc==0))!=OPUS_OK)test_failed( ); 394 if(opus_encoder_ctl(enc, OPUS_SET_INBAND_FEC(rc==0))!=OPUS_OK)test_failed( );
239 for(j=0;j<13;j++) 395 for(j=0;j<13;j++)
240 { 396 {
241 int rate; 397 int rate;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 int modes[16]={0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2}; 484 int modes[16]={0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2};
329 int rates[16]={4000,12000,32000,8000,16000,32000,48000,88000,4000,12000 ,32000,8000,16000,32000,48000,88000}; 485 int rates[16]={4000,12000,32000,8000,16000,32000,48000,88000,4000,12000 ,32000,8000,16000,32000,48000,88000};
330 int frame[16]={160*1,160,80,160,160,80,40,20,160*1,160,80,160,160,80,40 ,20}; 486 int frame[16]={160*1,160,80,160,160,80,40,20,160*1,160,80,160,160,80,40 ,20};
331 if(opus_multistream_encoder_ctl(MSenc, OPUS_SET_INBAND_FEC(rc==0&&j==1) )!=OPUS_OK)test_failed(); 487 if(opus_multistream_encoder_ctl(MSenc, OPUS_SET_INBAND_FEC(rc==0&&j==1) )!=OPUS_OK)test_failed();
332 if(opus_multistream_encoder_ctl(MSenc, OPUS_SET_FORCE_MODE(MODE_SILK_ON LY+modes[j]))!=OPUS_OK)test_failed(); 488 if(opus_multistream_encoder_ctl(MSenc, OPUS_SET_FORCE_MODE(MODE_SILK_ON LY+modes[j]))!=OPUS_OK)test_failed();
333 rate=rates[j]+fast_rand()%rates[j]; 489 rate=rates[j]+fast_rand()%rates[j];
334 if(opus_multistream_encoder_ctl(MSenc, OPUS_SET_DTX(fast_rand()&1))!=OP US_OK)test_failed(); 490 if(opus_multistream_encoder_ctl(MSenc, OPUS_SET_DTX(fast_rand()&1))!=OP US_OK)test_failed();
335 if(opus_multistream_encoder_ctl(MSenc, OPUS_SET_BITRATE(rate))!=OPUS_OK )test_failed(); 491 if(opus_multistream_encoder_ctl(MSenc, OPUS_SET_BITRATE(rate))!=OPUS_OK )test_failed();
336 count=i=0; 492 count=i=0;
337 do { 493 do {
338 int pred,len,out_samples,frame_size,loss; 494 int len,out_samples,frame_size,loss;
495 opus_int32 pred;
339 if(opus_multistream_encoder_ctl(MSenc, OPUS_GET_PREDICTION_DISABLED( &pred))!=OPUS_OK)test_failed(); 496 if(opus_multistream_encoder_ctl(MSenc, OPUS_GET_PREDICTION_DISABLED( &pred))!=OPUS_OK)test_failed();
340 if(opus_multistream_encoder_ctl(MSenc, OPUS_SET_PREDICTION_DISABLED( (int)(fast_rand()&15)<(pred?11:4)))!=OPUS_OK)test_failed(); 497 if(opus_multistream_encoder_ctl(MSenc, OPUS_SET_PREDICTION_DISABLED( (int)(fast_rand()&15)<(pred?11:4)))!=OPUS_OK)test_failed();
341 frame_size=frame[j]; 498 frame_size=frame[j];
342 if(opus_multistream_encoder_ctl(MSenc, OPUS_SET_COMPLEXITY((count>>2 )%11))!=OPUS_OK)test_failed(); 499 if(opus_multistream_encoder_ctl(MSenc, OPUS_SET_COMPLEXITY((count>>2 )%11))!=OPUS_OK)test_failed();
343 if(opus_multistream_encoder_ctl(MSenc, OPUS_SET_PACKET_LOSS_PERC((fa st_rand()&15)&(fast_rand()%15)))!=OPUS_OK)test_failed(); 500 if(opus_multistream_encoder_ctl(MSenc, OPUS_SET_PACKET_LOSS_PERC((fa st_rand()&15)&(fast_rand()%15)))!=OPUS_OK)test_failed();
344 if((fast_rand()&255)==0) 501 if((fast_rand()&255)==0)
345 { 502 {
346 if(opus_multistream_encoder_ctl(MSenc, OPUS_RESET_STATE)!=OPUS_OK )test_failed(); 503 if(opus_multistream_encoder_ctl(MSenc, OPUS_RESET_STATE)!=OPUS_OK )test_failed();
347 if(opus_multistream_decoder_ctl(MSdec, OPUS_RESET_STATE)!=OPUS_OK )test_failed(); 504 if(opus_multistream_decoder_ctl(MSdec, OPUS_RESET_STATE)!=OPUS_OK )test_failed();
348 if((fast_rand()&3)!=0) 505 if((fast_rand()&3)!=0)
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 opus_decoder_ctl(dec, OPUS_GET_FINAL_RANGE(&dec_final_range)); 575 opus_decoder_ctl(dec, OPUS_GET_FINAL_RANGE(&dec_final_range));
419 576
420 /* compare final range encoder rng values of encoder and decoder */ 577 /* compare final range encoder rng values of encoder and decoder */
421 if(dec_final_range!=enc_final_range)test_failed(); 578 if(dec_final_range!=enc_final_range)test_failed();
422 579
423 /* We fuzz the packet, but take care not to only corrupt the payload 580 /* We fuzz the packet, but take care not to only corrupt the payload
424 Corrupted headers are tested elsewhere and we need to actually run 581 Corrupted headers are tested elsewhere and we need to actually run
425 the decoders in order to compare them. */ 582 the decoders in order to compare them. */
426 if(opus_packet_parse(packet,len,&toc,frames,size,&payload_offset)<=0)test_ failed(); 583 if(opus_packet_parse(packet,len,&toc,frames,size,&payload_offset)<=0)test_ failed();
427 if((fast_rand()&1023)==0)len=0; 584 if((fast_rand()&1023)==0)len=0;
428 for(j=(frames[0]-packet);j<len;j++)for(jj=0;jj<8;jj++)packet[j]^=((!no_fuz z)&&((fast_rand()&1023)==0))<<jj; 585 for(j=(opus_int32)(frames[0]-packet);j<len;j++)for(jj=0;jj<8;jj++)packet[j ]^=((!no_fuzz)&&((fast_rand()&1023)==0))<<jj;
429 out_samples = opus_decode(dec_err[0], len>0?packet:NULL, len, out2buf, MAX _FRAME_SAMP, 0); 586 out_samples = opus_decode(dec_err[0], len>0?packet:NULL, len, out2buf, MAX _FRAME_SAMP, 0);
430 if(out_samples<0||out_samples>MAX_FRAME_SAMP)test_failed(); 587 if(out_samples<0||out_samples>MAX_FRAME_SAMP)test_failed();
431 if((len>0&&out_samples!=frame_size))test_failed(); /*FIXME use lastframe*/ 588 if((len>0&&out_samples!=frame_size))test_failed(); /*FIXME use lastframe*/
432 589
433 opus_decoder_ctl(dec_err[0], OPUS_GET_FINAL_RANGE(&dec_final_range)); 590 opus_decoder_ctl(dec_err[0], OPUS_GET_FINAL_RANGE(&dec_final_range));
434 591
435 /*randomly select one of the decoders to compare with*/ 592 /*randomly select one of the decoders to compare with*/
436 dec2=fast_rand()%9+1; 593 dec2=fast_rand()%9+1;
437 out_samples = opus_decode(dec_err[dec2], len>0?packet:NULL, len, out2buf, MAX_FRAME_SAMP, 0); 594 out_samples = opus_decode(dec_err[dec2], len>0?packet:NULL, len, out2buf, MAX_FRAME_SAMP, 0);
438 if(out_samples<0||out_samples>MAX_FRAME_SAMP)test_failed(); /*FIXME, use f actor, lastframe for loss*/ 595 if(out_samples<0||out_samples>MAX_FRAME_SAMP)test_failed(); /*FIXME, use f actor, lastframe for loss*/
(...skipping 24 matching lines...) Expand all
463 if(opus_multistream_decoder_ctl(MSdec, OPUS_RESET_STATE)!=OPUS_OK)test_failed (); 620 if(opus_multistream_decoder_ctl(MSdec, OPUS_RESET_STATE)!=OPUS_OK)test_failed ();
464 opus_multistream_decoder_destroy(MSdec); 621 opus_multistream_decoder_destroy(MSdec);
465 opus_multistream_decoder_destroy(MSdec_err); 622 opus_multistream_decoder_destroy(MSdec_err);
466 for(i=0;i<10;i++)opus_decoder_destroy(dec_err[i]); 623 for(i=0;i<10;i++)opus_decoder_destroy(dec_err[i]);
467 free(inbuf); 624 free(inbuf);
468 free(outbuf); 625 free(outbuf);
469 free(out2buf); 626 free(out2buf);
470 return 0; 627 return 0;
471 } 628 }
472 629
630 void print_usage(char* _argv[])
631 {
632 fprintf(stderr,"Usage: %s [<seed>] [-fuzz <num_encoders> <num_settings_per_en coder>]\n",_argv[0]);
633 }
634
473 int main(int _argc, char **_argv) 635 int main(int _argc, char **_argv)
474 { 636 {
637 int args=1;
638 char * strtol_str=NULL;
475 const char * oversion; 639 const char * oversion;
476 const char * env_seed; 640 const char * env_seed;
477 int env_used; 641 int env_used;
478 642 int num_encoders_to_fuzz=5;
479 if(_argc>2) 643 int num_setting_changes=40;
480 {
481 fprintf(stderr,"Usage: %s [<seed>]\n",_argv[0]);
482 return 1;
483 }
484 644
485 env_used=0; 645 env_used=0;
486 env_seed=getenv("SEED"); 646 env_seed=getenv("SEED");
487 if(_argc>1)iseed=atoi(_argv[1]); 647 if(_argc>1)
488 else if(env_seed) 648 iseed=strtol(_argv[1], &strtol_str, 10); /* the first input argument migh t be the seed */
489 { 649 if(strtol_str!=NULL && strtol_str[0]=='\0') /* iseed is a valid number */
650 args++;
651 else if(env_seed) {
490 iseed=atoi(env_seed); 652 iseed=atoi(env_seed);
491 env_used=1; 653 env_used=1;
492 } 654 }
493 else iseed=(opus_uint32)time(NULL)^((getpid()&65535)<<16); 655 else iseed=(opus_uint32)time(NULL)^(((opus_uint32)getpid()&65535)<<16);
494 Rw=Rz=iseed; 656 Rw=Rz=iseed;
495 657
658 while(args<_argc)
659 {
660 if(strcmp(_argv[args], "-fuzz")==0 && _argc==(args+3)) {
661 num_encoders_to_fuzz=strtol(_argv[args+1], &strtol_str, 10);
662 if(strtol_str[0]!='\0' || num_encoders_to_fuzz<=0) {
663 print_usage(_argv);
664 return EXIT_FAILURE;
665 }
666 num_setting_changes=strtol(_argv[args+2], &strtol_str, 10);
667 if(strtol_str[0]!='\0' || num_setting_changes<=0) {
668 print_usage(_argv);
669 return EXIT_FAILURE;
670 }
671 args+=3;
672 }
673 else {
674 print_usage(_argv);
675 return EXIT_FAILURE;
676 }
677 }
678
496 oversion=opus_get_version_string(); 679 oversion=opus_get_version_string();
497 if(!oversion)test_failed(); 680 if(!oversion)test_failed();
498 fprintf(stderr,"Testing %s encoder. Random seed: %u (%.4X)\n", oversion, isee d, fast_rand() % 65535); 681 fprintf(stderr,"Testing %s encoder. Random seed: %u (%.4X)\n", oversion, isee d, fast_rand() % 65535);
499 if(env_used)fprintf(stderr," Random seed set from the environment (SEED=%s). \n", env_seed); 682 if(env_used)fprintf(stderr," Random seed set from the environment (SEED=%s). \n", env_seed);
500 683
684 regression_test();
685
501 /*Setting TEST_OPUS_NOFUZZ tells the tool not to send garbage data 686 /*Setting TEST_OPUS_NOFUZZ tells the tool not to send garbage data
502 into the decoders. This is helpful because garbage data 687 into the decoders. This is helpful because garbage data
503 may cause the decoders to clip, which angers CLANG IOC.*/ 688 may cause the decoders to clip, which angers CLANG IOC.*/
504 run_test1(getenv("TEST_OPUS_NOFUZZ")!=NULL); 689 run_test1(getenv("TEST_OPUS_NOFUZZ")!=NULL);
505 690
691 /* Fuzz encoder settings online */
692 if(getenv("TEST_OPUS_NOFUZZ")==NULL) {
693 fprintf(stderr,"Running fuzz_encoder_settings with %d encoder(s) and %d se tting change(s) each.\n",
694 num_encoders_to_fuzz, num_setting_changes);
695 fuzz_encoder_settings(num_encoders_to_fuzz, num_setting_changes);
696 }
697
506 fprintf(stderr,"Tests completed successfully.\n"); 698 fprintf(stderr,"Tests completed successfully.\n");
507 699
508 return 0; 700 return 0;
509 } 701 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698