| OLD | NEW |
| 1 /* Copyright (c) 2011 Xiph.Org Foundation | 1 /* Copyright (c) 2011 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 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 #include <stdio.h> | 32 #include <stdio.h> |
| 33 #include <stdlib.h> | 33 #include <stdlib.h> |
| 34 #include <limits.h> | 34 #include <limits.h> |
| 35 #include <stdint.h> | 35 #include <stdint.h> |
| 36 #include <math.h> | 36 #include <math.h> |
| 37 #include <string.h> | 37 #include <string.h> |
| 38 #include <time.h> | 38 #include <time.h> |
| 39 #if (!defined WIN32 && !defined _WIN32) || defined(__MINGW32__) | 39 #if (!defined WIN32 && !defined _WIN32) || defined(__MINGW32__) |
| 40 #include <unistd.h> | 40 #include <unistd.h> |
| 41 #else |
| 42 #include <process.h> |
| 43 #define getpid _getpid |
| 41 #endif | 44 #endif |
| 42 #include "opus.h" | 45 #include "opus.h" |
| 43 #include "test_opus_common.h" | 46 #include "test_opus_common.h" |
| 44 | 47 |
| 45 #define MAX_PACKET (1500) | 48 #define MAX_PACKET (1500) |
| 46 #define MAX_FRAME_SAMP (5760) | 49 #define MAX_FRAME_SAMP (5760) |
| 47 extern int jackpot; | |
| 48 | 50 |
| 49 int test_decoder_code0(int no_fuzz) | 51 int test_decoder_code0(int no_fuzz) |
| 50 { | 52 { |
| 51 static const opus_int32 fsv[5]={48000,24000,16000,12000,8000}; | 53 static const opus_int32 fsv[5]={48000,24000,16000,12000,8000}; |
| 52 int err,skip,plen; | 54 int err,skip,plen; |
| 53 int out_samples,fec; | 55 int out_samples,fec; |
| 54 int t; | 56 int t; |
| 55 opus_int32 i; | 57 opus_int32 i; |
| 56 OpusDecoder *dec[5*2]; | 58 OpusDecoder *dec[5*2]; |
| 57 opus_int32 decsize; | 59 opus_int32 decsize; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 | 97 |
| 96 decsize=opus_decoder_get_size(1); | 98 decsize=opus_decoder_get_size(1); |
| 97 decbak=(OpusDecoder *)malloc(decsize); | 99 decbak=(OpusDecoder *)malloc(decsize); |
| 98 if(decbak==NULL)test_failed(); | 100 if(decbak==NULL)test_failed(); |
| 99 | 101 |
| 100 for(t=0;t<5*2;t++) | 102 for(t=0;t<5*2;t++) |
| 101 { | 103 { |
| 102 int factor=48000/fsv[t>>1]; | 104 int factor=48000/fsv[t>>1]; |
| 103 for(fec=0;fec<2;fec++) | 105 for(fec=0;fec<2;fec++) |
| 104 { | 106 { |
| 107 int dur; |
| 105 /*Test PLC on a fresh decoder*/ | 108 /*Test PLC on a fresh decoder*/ |
| 106 out_samples = opus_decode(dec[t], 0, 0, outbuf, MAX_FRAME_SAMP, fec); | 109 out_samples = opus_decode(dec[t], 0, 0, outbuf, 120/factor, fec); |
| 107 if(out_samples!=120/factor)test_failed(); | 110 if(out_samples!=120/factor)test_failed(); |
| 111 if(opus_decoder_ctl(dec[t], OPUS_GET_LAST_PACKET_DURATION(&dur))!=OPUS_
OK)test_failed(); |
| 112 if(dur!=120/factor)test_failed(); |
| 108 | 113 |
| 109 /*Test null pointer input*/ | 114 /*Test null pointer input*/ |
| 110 out_samples = opus_decode(dec[t], 0, -1, outbuf, MAX_FRAME_SAMP, fec); | 115 out_samples = opus_decode(dec[t], 0, -1, outbuf, 120/factor, fec); |
| 111 if(out_samples!=120/factor)test_failed(); | 116 if(out_samples!=120/factor)test_failed(); |
| 112 out_samples = opus_decode(dec[t], 0, 1, outbuf, MAX_FRAME_SAMP, fec); | 117 out_samples = opus_decode(dec[t], 0, 1, outbuf, 120/factor, fec); |
| 113 if(out_samples!=120/factor)test_failed(); | 118 if(out_samples!=120/factor)test_failed(); |
| 114 out_samples = opus_decode(dec[t], 0, 10, outbuf, MAX_FRAME_SAMP, fec); | 119 out_samples = opus_decode(dec[t], 0, 10, outbuf, 120/factor, fec); |
| 115 if(out_samples!=120/factor)test_failed(); | 120 if(out_samples!=120/factor)test_failed(); |
| 116 out_samples = opus_decode(dec[t], 0, fast_rand(), outbuf, MAX_FRAME_SAM
P, fec); | 121 out_samples = opus_decode(dec[t], 0, fast_rand(), outbuf, 120/factor, f
ec); |
| 117 if(out_samples!=120/factor)test_failed(); | 122 if(out_samples!=120/factor)test_failed(); |
| 123 if(opus_decoder_ctl(dec[t], OPUS_GET_LAST_PACKET_DURATION(&dur))!=OPUS_
OK)test_failed(); |
| 124 if(dur!=120/factor)test_failed(); |
| 118 | 125 |
| 119 /*Zero lengths*/ | 126 /*Zero lengths*/ |
| 120 out_samples = opus_decode(dec[t], packet, 0, outbuf, MAX_FRAME_SAMP, fe
c); | 127 out_samples = opus_decode(dec[t], packet, 0, outbuf, 120/factor, fec); |
| 121 if(out_samples!=120/factor)test_failed(); | 128 if(out_samples!=120/factor)test_failed(); |
| 122 | 129 |
| 123 /*Zero buffer*/ | 130 /*Zero buffer*/ |
| 124 outbuf[0]=32749; | 131 outbuf[0]=32749; |
| 125 out_samples = opus_decode(dec[t], packet, 0, outbuf, 0, fec); | 132 out_samples = opus_decode(dec[t], packet, 0, outbuf, 0, fec); |
| 126 if(out_samples>0)test_failed(); | 133 if(out_samples>0)test_failed(); |
| 127 out_samples = opus_decode(dec[t], packet, 0, 0, 0, fec); | 134 out_samples = opus_decode(dec[t], packet, 0, 0, 0, fec); |
| 128 if(out_samples>0)test_failed(); | 135 if(out_samples>0)test_failed(); |
| 129 if(outbuf[0]!=32749)test_failed(); | 136 if(outbuf[0]!=32749)test_failed(); |
| 130 | 137 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 142 | 149 |
| 143 /*Reset the decoder*/ | 150 /*Reset the decoder*/ |
| 144 if(opus_decoder_ctl(dec[t], OPUS_RESET_STATE)!=OPUS_OK)test_failed(); | 151 if(opus_decoder_ctl(dec[t], OPUS_RESET_STATE)!=OPUS_OK)test_failed(); |
| 145 } | 152 } |
| 146 } | 153 } |
| 147 fprintf(stdout," dec[all] initial frame PLC OK.\n"); | 154 fprintf(stdout," dec[all] initial frame PLC OK.\n"); |
| 148 | 155 |
| 149 /*Count code 0 tests*/ | 156 /*Count code 0 tests*/ |
| 150 for(i=0;i<64;i++) | 157 for(i=0;i<64;i++) |
| 151 { | 158 { |
| 159 int dur; |
| 152 int j,expected[5*2]; | 160 int j,expected[5*2]; |
| 153 packet[0]=i<<2; | 161 packet[0]=i<<2; |
| 154 packet[1]=255; | 162 packet[1]=255; |
| 155 packet[2]=255; | 163 packet[2]=255; |
| 156 err=opus_packet_get_nb_channels(packet); | 164 err=opus_packet_get_nb_channels(packet); |
| 157 if(err!=(i&1)+1)test_failed(); | 165 if(err!=(i&1)+1)test_failed(); |
| 158 | 166 |
| 159 for(t=0;t<5*2;t++){ | 167 for(t=0;t<5*2;t++){ |
| 160 expected[t]=opus_decoder_get_nb_samples(dec[t],packet,1); | 168 expected[t]=opus_decoder_get_nb_samples(dec[t],packet,1); |
| 161 if(expected[t]>2880)test_failed(); | 169 if(expected[t]>2880)test_failed(); |
| 162 } | 170 } |
| 163 | 171 |
| 164 for(j=0;j<256;j++) | 172 for(j=0;j<256;j++) |
| 165 { | 173 { |
| 166 packet[1]=j; | 174 packet[1]=j; |
| 167 for(t=0;t<5*2;t++) | 175 for(t=0;t<5*2;t++) |
| 168 { | 176 { |
| 169 out_samples = opus_decode(dec[t], packet, 3, outbuf, MAX_FRAME_SAMP,
0); | 177 out_samples = opus_decode(dec[t], packet, 3, outbuf, MAX_FRAME_SAMP,
0); |
| 170 if(out_samples!=expected[t])test_failed(); | 178 if(out_samples!=expected[t])test_failed(); |
| 179 if(opus_decoder_ctl(dec[t], OPUS_GET_LAST_PACKET_DURATION(&dur))!=OP
US_OK)test_failed(); |
| 180 if(dur!=out_samples)test_failed(); |
| 171 opus_decoder_ctl(dec[t], OPUS_GET_FINAL_RANGE(&dec_final_range1)); | 181 opus_decoder_ctl(dec[t], OPUS_GET_FINAL_RANGE(&dec_final_range1)); |
| 172 if(t==0)dec_final_range2=dec_final_range1; | 182 if(t==0)dec_final_range2=dec_final_range1; |
| 173 else if(dec_final_range1!=dec_final_range2)test_failed(); | 183 else if(dec_final_range1!=dec_final_range2)test_failed(); |
| 174 } | 184 } |
| 175 } | 185 } |
| 176 | 186 |
| 177 for(t=0;t<5*2;t++){ | 187 for(t=0;t<5*2;t++){ |
| 178 int factor=48000/fsv[t>>1]; | 188 int factor=48000/fsv[t>>1]; |
| 179 /* The PLC is run for 6 frames in order to get better PLC coverage. */ | 189 /* The PLC is run for 6 frames in order to get better PLC coverage. */ |
| 180 for(j=0;j<6;j++) | 190 for(j=0;j<6;j++) |
| 181 { | 191 { |
| 182 out_samples = opus_decode(dec[t], 0, 0, outbuf, MAX_FRAME_SAMP, 0); | 192 out_samples = opus_decode(dec[t], 0, 0, outbuf, expected[t], 0); |
| 183 if(out_samples!=expected[t])test_failed(); | 193 if(out_samples!=expected[t])test_failed(); |
| 194 if(opus_decoder_ctl(dec[t], OPUS_GET_LAST_PACKET_DURATION(&dur))!=OP
US_OK)test_failed(); |
| 195 if(dur!=out_samples)test_failed(); |
| 184 } | 196 } |
| 185 /* Run the PLC once at 2.5ms, as a simulation of someone trying to | 197 /* Run the PLC once at 2.5ms, as a simulation of someone trying to |
| 186 do small drift corrections. */ | 198 do small drift corrections. */ |
| 187 if(expected[t]!=120/factor) | 199 if(expected[t]!=120/factor) |
| 188 { | 200 { |
| 189 out_samples = opus_decode(dec[t], 0, 0, outbuf, 120/factor, 0); | 201 out_samples = opus_decode(dec[t], 0, 0, outbuf, 120/factor, 0); |
| 190 if(out_samples!=120/factor)test_failed(); | 202 if(out_samples!=120/factor)test_failed(); |
| 203 if(opus_decoder_ctl(dec[t], OPUS_GET_LAST_PACKET_DURATION(&dur))!=OP
US_OK)test_failed(); |
| 204 if(dur!=out_samples)test_failed(); |
| 191 } | 205 } |
| 192 out_samples = opus_decode(dec[t], packet, 2, outbuf, expected[t]-1, 0); | 206 out_samples = opus_decode(dec[t], packet, 2, outbuf, expected[t]-1, 0); |
| 193 if(out_samples>0)test_failed(); | 207 if(out_samples>0)test_failed(); |
| 194 } | 208 } |
| 195 } | 209 } |
| 196 fprintf(stdout," dec[all] all 2-byte prefix for length 3 and PLC, all modes
(64) OK.\n"); | 210 fprintf(stdout," dec[all] all 2-byte prefix for length 3 and PLC, all modes
(64) OK.\n"); |
| 197 | 211 |
| 198 if(no_fuzz) | 212 if(no_fuzz) |
| 199 { | 213 { |
| 200 fprintf(stdout," Skipping many tests which fuzz the decoder as requested.
\n"); | 214 fprintf(stdout," Skipping many tests which fuzz the decoder as requested.
\n"); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 | 296 |
| 283 debruijn2(64,modes); | 297 debruijn2(64,modes); |
| 284 plen=(fast_rand()%18+3)*8+skip+3; | 298 plen=(fast_rand()%18+3)*8+skip+3; |
| 285 for(i=0;i<4096;i++) | 299 for(i=0;i<4096;i++) |
| 286 { | 300 { |
| 287 int j,expected[5*2]; | 301 int j,expected[5*2]; |
| 288 packet[0]=modes[i]<<2; | 302 packet[0]=modes[i]<<2; |
| 289 for(t=0;t<5*2;t++)expected[t]=opus_decoder_get_nb_samples(dec[t],packet,pl
en); | 303 for(t=0;t<5*2;t++)expected[t]=opus_decoder_get_nb_samples(dec[t],packet,pl
en); |
| 290 for(j=0;j<plen;j++)packet[j+1]=(fast_rand()|fast_rand())&255; | 304 for(j=0;j<plen;j++)packet[j+1]=(fast_rand()|fast_rand())&255; |
| 291 memcpy(decbak,dec[0],decsize); | 305 memcpy(decbak,dec[0],decsize); |
| 292 if(opus_decode(decbak, packet, plen+1, outbuf, MAX_FRAME_SAMP, 1)!=expecte
d[0])test_failed(); | 306 if(opus_decode(decbak, packet, plen+1, outbuf, expected[0], 1)!=expected[0
])test_failed(); |
| 293 memcpy(decbak,dec[0],decsize); | 307 memcpy(decbak,dec[0],decsize); |
| 294 if(opus_decode(decbak, 0, 0, outbuf, MAX_FRAME_SAMP, 1)<20)test_failed(); | 308 if(opus_decode(decbak, 0, 0, outbuf, MAX_FRAME_SAMP, 1)<20)test_failed(); |
| 295 memcpy(decbak,dec[0],decsize); | 309 memcpy(decbak,dec[0],decsize); |
| 296 if(opus_decode(decbak, 0, 0, outbuf, MAX_FRAME_SAMP, 0)<20)test_failed(); | 310 if(opus_decode(decbak, 0, 0, outbuf, MAX_FRAME_SAMP, 0)<20)test_failed(); |
| 297 for(t=0;t<5*2;t++) | 311 for(t=0;t<5*2;t++) |
| 298 { | 312 { |
| 313 int dur; |
| 299 out_samples = opus_decode(dec[t], packet, plen+1, outbuf, MAX_FRAME_SAM
P, 0); | 314 out_samples = opus_decode(dec[t], packet, plen+1, outbuf, MAX_FRAME_SAM
P, 0); |
| 300 if(out_samples!=expected[t])test_failed(); | 315 if(out_samples!=expected[t])test_failed(); |
| 301 if(t==0)dec_final_range2=dec_final_range1; | 316 if(t==0)dec_final_range2=dec_final_range1; |
| 302 else if(dec_final_range1!=dec_final_range2)test_failed(); | 317 else if(dec_final_range1!=dec_final_range2)test_failed(); |
| 318 if(opus_decoder_ctl(dec[t], OPUS_GET_LAST_PACKET_DURATION(&dur))!=OPUS_
OK)test_failed(); |
| 319 if(dur!=out_samples)test_failed(); |
| 303 } | 320 } |
| 304 } | 321 } |
| 305 fprintf(stdout," dec[all] random packets, all mode pairs (4096), %d bytes/fr
ame OK.\n",plen+1); | 322 fprintf(stdout," dec[all] random packets, all mode pairs (4096), %d bytes/fr
ame OK.\n",plen+1); |
| 306 | 323 |
| 307 plen=(fast_rand()%18+3)*8+skip+3; | 324 plen=(fast_rand()%18+3)*8+skip+3; |
| 308 t=rand()&3; | 325 t=rand()&3; |
| 309 for(i=0;i<4096;i++) | 326 for(i=0;i<4096;i++) |
| 310 { | 327 { |
| 311 int count,j,expected; | 328 int count,j,expected; |
| 312 packet[0]=modes[i]<<2; | 329 packet[0]=modes[i]<<2; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 fprintf(stderr,"Testing %s decoder. Random seed: %u (%.4X)\n", oversion, isee
d, fast_rand() % 65535); | 397 fprintf(stderr,"Testing %s decoder. Random seed: %u (%.4X)\n", oversion, isee
d, fast_rand() % 65535); |
| 381 if(env_used)fprintf(stderr," Random seed set from the environment (SEED=%s).
\n", env_seed); | 398 if(env_used)fprintf(stderr," Random seed set from the environment (SEED=%s).
\n", env_seed); |
| 382 | 399 |
| 383 /*Setting TEST_OPUS_NOFUZZ tells the tool not to send garbage data | 400 /*Setting TEST_OPUS_NOFUZZ tells the tool not to send garbage data |
| 384 into the decoders. This is helpful because garbage data | 401 into the decoders. This is helpful because garbage data |
| 385 may cause the decoders to clip, which angers CLANG IOC.*/ | 402 may cause the decoders to clip, which angers CLANG IOC.*/ |
| 386 test_decoder_code0(getenv("TEST_OPUS_NOFUZZ")!=NULL); | 403 test_decoder_code0(getenv("TEST_OPUS_NOFUZZ")!=NULL); |
| 387 | 404 |
| 388 return 0; | 405 return 0; |
| 389 } | 406 } |
| OLD | NEW |