ref: 8e89e558ae25b75b0ec3c3bdb250c8d0eeadb2eb
parent: 190310fcb959cc600932e4c56b9c86f061760d86
author: lieff <lieff@users.noreply.github.com>
date: Sun Feb 2 21:04:32 EST 2020
start test mp3dec_ex_* API
--- a/minimp3_test.c
+++ b/minimp3_test.c
@@ -13,6 +13,10 @@
#include <strings.h>
#endif
+#define MODE_LOAD 0
+#define MODE_ITERATE 1
+#define MODE_STREAM 2
+
static int16_t read16le(const void *p)
{
const uint8_t *src = (const uint8_t *)p;
@@ -59,7 +63,6 @@
return data;
}
-#ifdef MP4_MODE
typedef struct
{
mp3dec_t *mp3d;
@@ -91,24 +94,37 @@
}
return 0;
}
-#endif
-static void decode_file(const char *input_file_name, const unsigned char *buf_ref, int ref_size, FILE *file_out, const int wave_out)
+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)
{
mp3dec_t mp3d;
- int i, data_bytes, total_samples = 0, maxdiff = 0;
+ int i, res = -1, data_bytes, total_samples = 0, maxdiff = 0;
double MSE = 0.0, psnr;
mp3dec_file_info_t info;
-#ifdef MP4_MODE
- frames_iterate_data d = { &mp3d, &info, 0 };
- mp3dec_init(&mp3d);
- memset(&info, 0, sizeof(info));
- if (mp3dec_iterate(input_file_name, frames_iterate_cb, &d))
-#else
- if (mp3dec_load(&mp3d, input_file_name, &info, 0, 0))
-#endif
+ if (MODE_LOAD == mode)
{
+ res = mp3dec_load(&mp3d, input_file_name, &info, 0, 0);
+ } else if (MODE_ITERATE == mode)
+ {
+ frames_iterate_data d = { &mp3d, &info, 0 };
+ mp3dec_init(&mp3d);
+ memset(&info, 0, sizeof(info));
+ res = mp3dec_iterate(input_file_name, frames_iterate_cb, &d);
+ } else if (MODE_STREAM == mode)
+ {
+ mp3dec_ex_t dec;
+ res = mp3dec_ex_open(&dec, input_file_name, MP3D_SEEK_TO_SAMPLE);
+ info.samples = dec.samples;
+ info.buffer = malloc(dec.samples*sizeof(int16_t));
+ mp3dec_ex_read(&dec, info.buffer, dec.samples);
+ } else
+ {
+ printf("error: unknown mode");
+ exit(1);
+ }
+ if (res)
+ {
if (ref_size)
{
printf("error: file not found or read error");
@@ -190,9 +206,21 @@
int main(int argc, char *argv[])
#endif
{
- int wave_out = 0, ref_size;
- char *ref_file_name = (argc > 2) ? argv[2] : NULL;
- char *output_file_name = (argc > 3) ? argv[3] : NULL;
+ int wave_out = 0, mode = 0, i, ref_size;
+ for(i = 1; i < argc; i++)
+ {
+ if (argv[i][0] != '-')
+ break;
+ switch (argv[i][1])
+ {
+ case 'm': i++; if (i < argc) mode = atoi(argv[i]); break;
+ default:
+ printf("error: unrecognized option\n");
+ return 1;
+ }
+ }
+ char *ref_file_name = (argc > (i + 1)) ? argv[i + 1] : NULL;
+ char *output_file_name = (argc > (i + 2)) ? argv[i + 2] : NULL;
FILE *file_out = NULL;
if (output_file_name)
{
@@ -211,13 +239,13 @@
__AFL_INIT();
while (__AFL_LOOP(1000)) {
#endif
- char *input_file_name = (argc > 1) ? argv[1] : NULL;
+ char *input_file_name = (argc > i) ? argv[i] : NULL;
if (!input_file_name)
{
printf("error: no file names given\n");
return 1;
}
- decode_file(input_file_name, buf_ref, ref_size, file_out, wave_out);
+ decode_file(input_file_name, buf_ref, ref_size, file_out, wave_out, mode);
#ifdef __AFL_HAVE_MANUAL_CONTROL
}
#endif
--- a/scripts/build.sh
+++ b/scripts/build.sh
@@ -11,7 +11,11 @@
echo testing mp4 mode...
gcc $CFLAGS -DMP4_MODE -o minimp3 minimp3_test.c -lm
-scripts/test_mp4_mode.sh
+scripts/test_mode.sh 1
+
+echo testing stream mode...
+gcc $CFLAGS -DMP4_MODE -o minimp3 minimp3_test.c -lm
+scripts/test_mode.sh 2
echo testing coverage x86 w sse...
gcc -coverage -O0 -m32 -std=c89 -msse2 -DMINIMP3_TEST -DMINIMP3_NO_WAV -o minimp3 minimp3_test.c -lm
--- /dev/null
+++ b/scripts/test_mode.sh
@@ -1,0 +1,21 @@
+_FILENAME=${0##*/}
+CUR_DIR=${0/${_FILENAME}}
+CUR_DIR=$(cd $(dirname ${CUR_DIR}); pwd)/$(basename ${CUR_DIR})/
+
+pushd $CUR_DIR/..
+
+APP=./minimp3
+MODE=$1
+
+set +e
+for i in vectors/l3-compl.bit vectors/l3-he_32khz.bit vectors/l3-he_44khz.bit vectors/l3-he_48khz.bit \
+vectors/l3-hecommon.bit vectors/l3-he_mode.bit vectors/l3-si.bit vectors/l3-si_block.bit vectors/l3-si_huff.bit \
+vectors/l3-sin1k0db.bit vectors/l3-test45.bit vectors/l3-test46.bit vectors/M2L3_bitrate_16_all.bit \
+vectors/M2L3_bitrate_22_all.bit vectors/M2L3_bitrate_24_all.bit vectors/M2L3_compl24.bit vectors/M2L3_noise.bit; do
+$APP -m $MODE $i ${i%.*}.pcm
+retval=$?
+echo $i exited with code=$retval
+if [ ! $retval -eq 0 ]; then
+ exit 1
+fi
+done
--- a/scripts/test_mp4_mode.sh
+++ /dev/null
@@ -1,20 +1,0 @@
-_FILENAME=${0##*/}
-CUR_DIR=${0/${_FILENAME}}
-CUR_DIR=$(cd $(dirname ${CUR_DIR}); pwd)/$(basename ${CUR_DIR})/
-
-pushd $CUR_DIR/..
-
-APP=./minimp3
-
-set +e
-for i in vectors/l3-compl.bit vectors/l3-he_32khz.bit vectors/l3-he_44khz.bit vectors/l3-he_48khz.bit \
-vectors/l3-hecommon.bit vectors/l3-he_mode.bit vectors/l3-si.bit vectors/l3-si_block.bit vectors/l3-si_huff.bit \
-vectors/l3-sin1k0db.bit vectors/l3-test45.bit vectors/l3-test46.bit vectors/M2L3_bitrate_16_all.bit \
-vectors/M2L3_bitrate_22_all.bit vectors/M2L3_bitrate_24_all.bit vectors/M2L3_compl24.bit vectors/M2L3_noise.bit; do
-$APP $i ${i%.*}.pcm
-retval=$?
-echo $i exited with code=$retval
-if [ ! $retval -eq 0 ]; then
- exit 1
-fi
-done