diff -r 0d39d995cb65 -r e6dd805197fa modules/mlv_rec/mlv_dump.c --- a/modules/mlv_rec/mlv_dump.c Tue Sep 18 07:54:06 2018 +0200 +++ b/modules/mlv_rec/mlv_dump.c Thu Sep 20 12:07:48 2018 +0200 @@ -1239,6 +1239,33 @@ } } +static int seek_to_next_known_block(FILE * in_file) +{ + int read_ahead_size = 128 * 1024 * 1024; + uint8_t * ahead = malloc(read_ahead_size); + assert(ahead); + + int read = fread(ahead, 1, read_ahead_size, in_file); + /* fixme: file_set_pos doesn't work */ + fseek(in_file, -read, SEEK_CUR); + for (int i = 0; i < read; i++) + { + if (memcmp(ahead + i, "VIDF", 4) == 0 || + memcmp(ahead + i, "AUDF", 4) == 0 || + memcmp(ahead + i, "NULL", 4) == 0) + { + print_msg(MSG_INFO, "Next known block: %c%c%c%c at 0x%"PRIx64"+0x%x = ", ahead[i], ahead[i+1], ahead[i+2], ahead[i+3], file_get_pos(in_file), i); + fseek(in_file, i, SEEK_CUR); + print_msg(MSG_INFO, "0x%"PRIx64"\n", file_get_pos(in_file)); + free(ahead); + return 1; + } + } + + print_msg(MSG_ERROR, "Could not find any known block from 0x"PRIx64".\n", file_get_pos(in_file)); + free(ahead); + return 0; +} int main (int argc, char *argv[]) { @@ -2129,7 +2156,13 @@ else { print_msg(MSG_ERROR, "Invalid block size at position 0x%08" PRIx64 "\n", position); - goto abort; + + /* attempt to seek to next valid block */ + if (seek_to_next_known_block(in_file)) { + goto read_headers; + } else { + goto abort; + } } } @@ -4080,6 +4113,11 @@ else { print_msg(MSG_INFO, "Unknown Block: %c%c%c%c, skipping\n", mlv_block->blockType[0], mlv_block->blockType[1], mlv_block->blockType[2], mlv_block->blockType[3]); + + /* this block might be bad; seek to next valid one */ + fseek(in_file, -mlv_block->blockSize, SEEK_CUR); + seek_to_next_known_block(in_file); + goto read_headers; } lua_handle_hdr(lua_state, mlv_block->blockType, "", 0);