From d277356d995f209bae61e6026dd4982a9e08031d Mon Sep 17 00:00:00 2001 From: lieff Date: Sat, 14 Dec 2019 02:03:30 +0300 Subject: [PATCH] add basic demux test --- minimp4.h | 4 ++-- minimp4_test.c | 17 ++++++++++++-- scripts/test.sh | 47 +++++++++++++++++++------------------ vectors/foreman.264 | Bin 391267 -> 390973 bytes vectors/foreman_slices.264 | Bin 421462 -> 421168 bytes 5 files changed, 41 insertions(+), 27 deletions(-) diff --git a/minimp4.h b/minimp4.h index 1fc01d2..0c009fc 100644 --- a/minimp4.h +++ b/minimp4.h @@ -331,7 +331,7 @@ typedef struct } mp4_h26x_writer_t; int mp4_h26x_write_init(mp4_h26x_writer_t *h, MP4E_mux_t *mux, int width, int height, int is_hevc); -int mp4_h26x_write_close(mp4_h26x_writer_t *h); +void mp4_h26x_write_close(mp4_h26x_writer_t *h); int mp4_h26x_write_nal(mp4_h26x_writer_t *h, const unsigned char *nal, int length, unsigned timeStamp90kHz_next); /************************************************************************/ @@ -2198,7 +2198,7 @@ int mp4_h26x_write_init(mp4_h26x_writer_t *h, MP4E_mux_t *mux, int width, int he return MP4E_STATUS_OK; } -int mp4_h26x_write_close(mp4_h26x_writer_t *h) +void mp4_h26x_write_close(mp4_h26x_writer_t *h) { #if MINIMP4_TRANSCODE_SPS_ID h264_sps_id_patcher_t *p = &h->sps_patcher; diff --git a/minimp4_test.c b/minimp4_test.c index b7c4b01..f9629a1 100644 --- a/minimp4_test.c +++ b/minimp4_test.c @@ -107,15 +107,28 @@ int demux(uint8_t *input_buf, ssize_t input_size, FILE *fout) unsigned frame_bytes, timestamp, duration; MP4D_file_offset_t ofs = MP4D_frame_offset(&mp4, ntrack, i, &frame_bytes, ×tamp, &duration); uint8_t *mem = input_buf + ofs; - mem[0] = 0; mem[1] = 0; mem[2] = 0; mem[3] = 1; sum_duration += duration; - fwrite(mem + USE_SHORT_SYNC, 1, frame_bytes - USE_SHORT_SYNC, fout); + while (frame_bytes) + { + uint32_t size = ((uint32_t)mem[0] << 24) | ((uint32_t)mem[1] << 16) | ((uint32_t)mem[2] << 8) | mem[3]; + size += 4; + mem[0] = 0; mem[1] = 0; mem[2] = 0; mem[3] = 1; + fwrite(mem + USE_SHORT_SYNC, 1, size - USE_SHORT_SYNC, fout); + if (frame_bytes < size) + { + printf("error: demux sample failed\n"); + exit(1); + } + frame_bytes -= size; + mem += size; + } } } MP4D_close(&mp4); if (input_buf) free(input_buf); + return 0; } int main(int argc, char **argv) diff --git a/scripts/test.sh b/scripts/test.sh index 2f0d9c6..5fe9695 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -4,7 +4,11 @@ CUR_DIR=$(cd $(dirname ${CUR_DIR}); pwd)/$(basename ${CUR_DIR})/ pushd $CUR_DIR/.. -./minimp4_x86 vectors/foreman.264 out.mp4 +test_executable() { + +EXEC=$1 + +$EXEC vectors/foreman.264 out.mp4 if ! cmp ./out.mp4 vectors/out_ref.mp4 >/dev/null 2>&1 then echo test failed @@ -12,7 +16,7 @@ then fi rm out.mp4 -./minimp4_x86 -s vectors/foreman.264 out.mp4 +$EXEC -s vectors/foreman.264 out.mp4 if ! cmp ./out.mp4 vectors/out_sequential_ref.mp4 >/dev/null 2>&1 then echo sequential test failed @@ -20,7 +24,7 @@ then fi rm out.mp4 -./minimp4_x86 -f vectors/foreman.264 out.mp4 +$EXEC -f vectors/foreman.264 out.mp4 if ! cmp ./out.mp4 vectors/out_fragmentation_ref.mp4 >/dev/null 2>&1 then echo fragmentation test failed @@ -28,7 +32,7 @@ then fi rm out.mp4 -./minimp4_x86 vectors/foreman_slices.264 out.mp4 +$EXEC vectors/foreman_slices.264 out.mp4 if ! cmp ./out.mp4 vectors/out_slices_ref.mp4 >/dev/null 2>&1 then echo slices test failed @@ -36,36 +40,33 @@ then fi rm out.mp4 -qemu-arm ./minimp4_arm_gcc vectors/foreman.264 out.mp4 -if ! cmp ./out.mp4 vectors/out_ref.mp4 >/dev/null 2>&1 +$EXEC -d vectors/out_ref.mp4 out.h264 +if ! cmp ./out.h264 vectors/foreman.264 >/dev/null 2>&1 then - echo test failed + echo demux test failed exit 1 fi -rm out.mp4 +rm out.h264 -qemu-arm ./minimp4_arm_gcc -s vectors/foreman.264 out.mp4 -if ! cmp ./out.mp4 vectors/out_sequential_ref.mp4 >/dev/null 2>&1 +$EXEC -d vectors/out_sequential_ref.mp4 out.h264 +if ! cmp ./out.h264 vectors/foreman.264 >/dev/null 2>&1 then - echo sequential test failed + echo demux sequential test failed exit 1 fi -rm out.mp4 +rm out.h264 -qemu-arm ./minimp4_arm_gcc -f vectors/foreman.264 out.mp4 -if ! cmp ./out.mp4 vectors/out_fragmentation_ref.mp4 >/dev/null 2>&1 +$EXEC -d vectors/out_slices_ref.mp4 out.h264 +if ! cmp ./out.h264 vectors/foreman_slices.264 >/dev/null 2>&1 then - echo fragmentation test failed + echo demux slices test failed exit 1 fi -rm out.mp4 +rm out.h264 -qemu-arm ./minimp4_arm_gcc vectors/foreman_slices.264 out.mp4 -if ! cmp ./out.mp4 vectors/out_slices_ref.mp4 >/dev/null 2>&1 -then - echo slices test failed - exit 1 -fi -rm out.mp4 +} + +test_executable ./minimp4_x86 +test_executable "qemu-arm ./minimp4_arm_gcc" echo test passed diff --git a/vectors/foreman.264 b/vectors/foreman.264 index c17064caaf130c5a3b5ac8d36dfb4fc79eb9d0c1..28927b20deaa6d40bff2c22efa70423ba1d3ad53 100644 GIT binary patch delta 95 zcmV-l0HFWl@E5)A7qG)&mt|Z86SM1KJWjJbu#Z}|;0giHV7J6;0cUErK-K}PKeiSE zX=1m2cmh6vx6$|lD|5FIYy*0Tx1jU`uxGbrTm+$Hw;RC(u4}j6ECpC$w@Z!%7;0$J BD$M`@ delta 142 zcmdn{PW6X2$^4m8= ev*f3Mq|^?uEYAihKCjIh2DDpdyG}2wU={!Zs5X!Q diff --git a/vectors/foreman_slices.264 b/vectors/foreman_slices.264 index 6d6cb73f129cb259ff4e6233885998a6192fe915..88e8896db9248c3eba0ba671178a3dccd36fb41c 100644 GIT binary patch delta 91 zcmV-h0Hpuc+!?Ui8L;_hvkqv&SF`26fnm3MAp!4Zw||HMYjL;#`2lW3w}L(b&1Sb` xr2-j-w~{LZ=6Sb`r33h%x0*!+*LAmsy97UMx7sHK4RN>pm<4lYw}k%%(r#qEEp`9^ delta 133 zcmdmROY+(s$qhf#C$fld{+)gxd?JhN=EM6d6M_8gc8ZK|(|`iojXM~V3qc|?elq5` zfJAugn2rLa#J68w!X(}X68WUXe6JEDa%lX V4Q$Ta>8yo7?K0a_|FNFV0|4Z)H(&q&