| @@ -13,6 +13,10 @@ · 12 unmodified lines |
| 13 | 13 | #include <strings.h> |
| 14 | 14 | #endif |
| 15 | 15 | |
| 16 | +#define MODE_LOAD 0 |
| 17 | +#define MODE_ITERATE 1 |
| 18 | +#define MODE_STREAM 2 |
| 19 | + |
| 16 | 20 | static int16_t read16le(const void *p) |
| 17 | 21 | { |
| 18 | 22 | const uint8_t *src = (const uint8_t *)p; |
| @@ -59,7 +63,6 @@ static unsigned char *preload(FILE *file, int *data_size) · 40 unmodified lines |
| 59 | 63 | return data; |
| 60 | 64 | } |
| 61 | 65 | |
| 62 | | −#ifdef MP4_MODE |
| 63 | 66 | typedef struct |
| 64 | 67 | { |
| 65 | 68 | mp3dec_t *mp3d; |
| @@ -91,23 +94,36 @@ static int frames_iterate_cb(void *user_data, const uint8_t *frame, int frame_si · 25 unmodified lines |
| 91 | 94 | } |
| 92 | 95 | return 0; |
| 93 | 96 | } |
| 94 | | −#endif |
| 95 | 97 | |
| 96 | | −static void decode_file(const char *input_file_name, const unsigned char *buf_ref, int ref_size, FILE *file_out, const int wave_out) |
| 98 | +static void decode_file(const char *input_file_name, const unsigned char *buf_ref, int ref_size, FILE *file_out, const int wave_out, const int mode) |
| 97 | 99 | { |
| 98 | 100 | mp3dec_t mp3d; |
| 99 | | − int i, data_bytes, total_samples = 0, maxdiff = 0; |
| 101 | + int i, res = -1, data_bytes, total_samples = 0, maxdiff = 0; |
| 100 | 102 | double MSE = 0.0, psnr; |
| 101 | 103 | |
| 102 | 104 | mp3dec_file_info_t info; |
| 103 | | −#ifdef MP4_MODE |
| 104 | | − frames_iterate_data d = { &mp3d, &info, 0 }; |
| 105 | | − mp3dec_init(&mp3d); |
| 106 | | − memset(&info, 0, sizeof(info)); |
| 107 | | − if (mp3dec_iterate(input_file_name, frames_iterate_cb, &d)) |
| 108 | | −#else |
| 109 | | − if (mp3dec_load(&mp3d, input_file_name, &info, 0, 0)) |
| 110 | | −#endif |
| 105 | + if (MODE_LOAD == mode) |
| 106 | + { |
| 107 | + res = mp3dec_load(&mp3d, input_file_name, &info, 0, 0); |
| 108 | + } else if (MODE_ITERATE == mode) |
| 109 | + { |
| 110 | + frames_iterate_data d = { &mp3d, &info, 0 }; |
| 111 | + mp3dec_init(&mp3d); |
| 112 | + memset(&info, 0, sizeof(info)); |
| 113 | + res = mp3dec_iterate(input_file_name, frames_iterate_cb, &d); |
| 114 | + } else if (MODE_STREAM == mode) |
| 115 | + { |
| 116 | + mp3dec_ex_t dec; |
| 117 | + res = mp3dec_ex_open(&dec, input_file_name, MP3D_SEEK_TO_SAMPLE); |
| 118 | + info.samples = dec.samples; |
| 119 | + info.buffer = malloc(dec.samples*sizeof(int16_t)); |
| 120 | + mp3dec_ex_read(&dec, info.buffer, dec.samples); |
| 121 | + } else |
| 122 | + { |
| 123 | + printf("error: unknown mode"); |
| 124 | + exit(1); |
| 125 | + } |
| 126 | + if (res) |
| 111 | 127 | { |
| 112 | 128 | if (ref_size) |
| 113 | 129 | { |
| @@ -190,9 +206,21 @@ int main2(int argc, char *argv[]) · 76 unmodified lines |
| 190 | 206 | int main(int argc, char *argv[]) |
| 191 | 207 | #endif |
| 192 | 208 | { |
| 193 | | − int wave_out = 0, ref_size; |
| 194 | | − char *ref_file_name = (argc > 2) ? argv[2] : NULL; |
| 195 | | − char *output_file_name = (argc > 3) ? argv[3] : NULL; |
| 209 | + int wave_out = 0, mode = 0, i, ref_size; |
| 210 | + for(i = 1; i < argc; i++) |
| 211 | + { |
| 212 | + if (argv[i][0] != '-') |
| 213 | + break; |
| 214 | + switch (argv[i][1]) |
| 215 | + { |
| 216 | + case 'm': i++; if (i < argc) mode = atoi(argv[i]); break; |
| 217 | + default: |
| 218 | + printf("error: unrecognized option\n"); |
| 219 | + return 1; |
| 220 | + } |
| 221 | + } |
| 222 | + char *ref_file_name = (argc > (i + 1)) ? argv[i + 1] : NULL; |
| 223 | + char *output_file_name = (argc > (i + 2)) ? argv[i + 2] : NULL; |
| 196 | 224 | FILE *file_out = NULL; |
| 197 | 225 | if (output_file_name) |
| 198 | 226 | { |
| @@ -211,13 +239,13 @@ int main(int argc, char *argv[]) · 12 unmodified lines |
| 211 | 239 | __AFL_INIT(); |
| 212 | 240 | while (__AFL_LOOP(1000)) { |
| 213 | 241 | #endif |
| 214 | | − char *input_file_name = (argc > 1) ? argv[1] : NULL; |
| 242 | + char *input_file_name = (argc > i) ? argv[i] : NULL; |
| 215 | 243 | if (!input_file_name) |
| 216 | 244 | { |
| 217 | 245 | printf("error: no file names given\n"); |
| 218 | 246 | return 1; |
| 219 | 247 | } |
| 220 | | − decode_file(input_file_name, buf_ref, ref_size, file_out, wave_out); |
| 248 | + decode_file(input_file_name, buf_ref, ref_size, file_out, wave_out, mode); |
| 221 | 249 | #ifdef __AFL_HAVE_MANUAL_CONTROL |
| 222 | 250 | } |
| 223 | 251 | #endif |