add basic demux test

This commit is contained in:
lieff 2019-12-14 02:03:30 +03:00
parent f7674be354
commit d277356d99
5 changed files with 41 additions and 27 deletions

View File

@ -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;

View File

@ -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, &timestamp, &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)

View File

@ -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

Binary file not shown.

Binary file not shown.