The current IFO API is fine if you have a full DVD image to play with, but not if you want to poke .ifo files directly as a generic IFO lib.
To that end, add a new ifoOpenPath() func which allows opening of files directly via a path. Internally, we abstract away the file I/O so that it is easy to work with any input source. This should be API & ABI compatible. Signed-off-by: Mike Frysinger <[email protected]> --- src/dvdread/ifo_print.h | 1 + src/dvdread/ifo_read.h | 8 + src/dvdread/ifo_types.h | 3 +- src/ifo_print.c | 7 +- src/ifo_read.c | 385 +++++++++++++++++++++++++++++------------------- 5 files changed, 253 insertions(+), 151 deletions(-) diff --git a/src/dvdread/ifo_print.h b/src/dvdread/ifo_print.h index c3068cb..476cd77 100644 --- a/src/dvdread/ifo_print.h +++ b/src/dvdread/ifo_print.h @@ -23,6 +23,7 @@ #include "ifo_types.h" void ifo_print(dvd_reader_t *dvd, int title); +void ifo_print_handle(ifo_handle_t *ifohandle); void dvdread_print_time(dvd_time_t *dtime); #endif /* LIBDVDREAD_IFO_PRINT_H */ diff --git a/src/dvdread/ifo_read.h b/src/dvdread/ifo_read.h index 97f4179..cabf9cd 100644 --- a/src/dvdread/ifo_read.h +++ b/src/dvdread/ifo_read.h @@ -39,6 +39,14 @@ extern "C" { ifo_handle_t *ifoOpen(dvd_reader_t *, int ); /** + * handle = ifoOpenPath(file); + * + * Opens an IFO file and reads in all the data for it. + * Returns a handle to a completely parsed structure. + */ +ifo_handle_t *ifoOpenPath(const char *); + +/** * handle = ifoOpenVMGI(dvd); * * Opens an IFO and reads in _only_ the vmgi_mat data. This call can be used diff --git a/src/dvdread/ifo_types.h b/src/dvdread/ifo_types.h index 7db7d34..0b3a5b8 100644 --- a/src/dvdread/ifo_types.h +++ b/src/dvdread/ifo_types.h @@ -723,8 +723,9 @@ typedef struct { * VIDEO_TS.[IFO,BUP] file, and the VTSI, or Video Title Set Information, which * is read in from the VTS_XX_0.[IFO,BUP] files. */ +struct fops_state; typedef struct { - dvd_file_t *file; + struct fops_state *state; /* VMGI */ vmgi_mat_t *vmgi_mat; diff --git a/src/ifo_print.c b/src/ifo_print.c index 976f68b..a239371 100644 --- a/src/ifo_print.c +++ b/src/ifo_print.c @@ -1085,7 +1085,12 @@ void ifo_print(dvd_reader_t *dvd, int title) { return; } + ifo_print_handle(ifohandle); + ifoClose(ifohandle); +} + +void ifo_print_handle(ifo_handle_t *ifohandle) { if(ifohandle->vmgi_mat) { printf("VMG top level\n-------------\n"); @@ -1200,6 +1205,4 @@ void ifo_print(dvd_reader_t *dvd, int title) { printf( "-----------------\n"); ifoPrint_VOBU_ADMAP(ifohandle->vts_vobu_admap); } - - ifoClose(ifohandle); } diff --git a/src/ifo_read.c b/src/ifo_read.c index 0bb35d3..5367af6 100644 --- a/src/ifo_read.c +++ b/src/ifo_read.c @@ -22,10 +22,12 @@ #include "config.h" +#include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <inttypes.h> #include <string.h> +#include <unistd.h> #include "bswap.h" #include "dvdread/ifo_types.h" @@ -91,14 +93,96 @@ static void ifoFree_PGC(pgc_t *pgc); static void ifoFree_PGC_COMMAND_TBL(pgc_command_tbl_t *cmd_tbl); static void ifoFree_PGCIT_internal(pgcit_t *pgcit); -static inline int DVDFileSeekForce_( dvd_file_t *dvd_file, uint32_t offset, int force_size ) { - return (DVDFileSeekForce(dvd_file, (int)offset, force_size) == (int)offset); +/* Logic for file input independence */ +struct fops_state; + +typedef enum { + FOPS_LIBDVD, FOPS_RAW_FD, FOPS_MEMORY, +} fops_type_t; + +typedef struct { + fops_type_t type; + int (*seek)(struct fops_state *, off_t); + int (*seek_force)(struct fops_state *, off_t, int); + int (*read)(struct fops_state *, void *, size_t); +} fops_t; + +typedef struct fops_state { + const fops_t *fops; + union { + dvd_file_t *dvd; + int fd; + void *data; + }; +} fops_state_t; + +#define _fops_fop(ptr, fop, ...) (ptr)->state->fops->fop((ptr)->state, __VA_ARGS__) +#define fops_seek(ptr, ...) _fops_fop((ptr), seek, __VA_ARGS__) +#define fops_seek_force(ptr, ...) _fops_fop((ptr), seek_force, __VA_ARGS__) +#define fops_read(ptr, ...) _fops_fop((ptr), read, __VA_ARGS__) + +static int fdseek(struct fops_state *state, off_t offset) { + return lseek(state->fd, offset, SEEK_SET) == offset; +} +static int fdseekforce(struct fops_state *state, off_t offset, int force_size) { + return fdseek(state, offset); +} +static int fdread(struct fops_state *state, void *data, size_t byte_size) { + return read(state->fd, data, byte_size); +} +static const fops_t fd_fops = { + .type = FOPS_RAW_FD, + .seek = fdseek, + .seek_force = fdseekforce, + .read = fdread, +}; + +static int DVDFileSeek_(struct fops_state *state, off_t offset) { + return (DVDFileSeek(state->dvd, (int)offset) == (int)offset); +} +static int DVDFileSeekForce_(struct fops_state *state, off_t offset, int force_size) { + return (DVDFileSeekForce(state->dvd, (int)offset, force_size) == (int)offset); +} +static int DVDReadBytes_(struct fops_state *state, void *data, size_t byte_size) { + return DVDReadBytes(state->dvd, data, byte_size); +} +static const fops_t libdvd_fops = { + .type = FOPS_LIBDVD, + .seek = DVDFileSeek_, + .seek_force = DVDFileSeekForce_, + .read = DVDReadBytes_, +}; + +static void *fops_state_init(fops_type_t type) { + fops_state_t *state = malloc(sizeof(*state)); + if (!state) + return state; + switch (type) { + case FOPS_LIBDVD: state->fops = &libdvd_fops; break; + case FOPS_RAW_FD: state->fops = &fd_fops; break; + case FOPS_MEMORY: + default: + free(state); + state = NULL; + } + return state; } -static inline int DVDFileSeek_( dvd_file_t *dvd_file, uint32_t offset ) { - return (DVDFileSeek(dvd_file, (int)offset) == (int)offset); +static void fops_close(fops_state_t *state) { + if (!state) + return; + switch (state->fops->type) { + case FOPS_LIBDVD: DVDCloseFile(state->dvd); break; + case FOPS_RAW_FD: close(state->fd); break; + case FOPS_MEMORY: + default: + free(state); + state = NULL; + } + free(state); } +/* Internal state read functions */ static void read_video_attr(video_attr_t *va) { getbits_state_t state; uint8_t buf[sizeof(video_attr_t)]; @@ -287,49 +371,33 @@ static void free_ptl_mait(ptl_mait_t* ptl_mait, int num_entries) { free(ptl_mait); } -ifo_handle_t *ifoOpen(dvd_reader_t *dvd, int title) { - ifo_handle_t *ifofile; - int bup_file_opened = 0; - char ifo_filename[13]; - - ifofile = (ifo_handle_t *)malloc(sizeof(ifo_handle_t)); +static ifo_handle_t *ifo_handle_alloc(fops_type_t type) { + ifo_handle_t *ifofile = calloc(1, sizeof(*ifofile)); if(!ifofile) return NULL; + ifofile->state = fops_state_init(type); + return ifofile; +} - memset(ifofile, 0, sizeof(ifo_handle_t)); - - ifofile->file = DVDOpenFile(dvd, title, DVD_READ_INFO_FILE); - if(!ifofile->file) { /* Failed to open IFO, try to open BUP */ - ifofile->file = DVDOpenFile(dvd, title, DVD_READ_INFO_BACKUP_FILE); - bup_file_opened = 1; - } - - if (title) - snprintf(ifo_filename, 12, "VTS_%02d_0.%s", title, bup_file_opened ? "BUP" : "IFO"); - else - snprintf(ifo_filename, 12, "VIDEO_TS.%s", bup_file_opened ? "BUP" : "IFO"); - - ifo_filename[12] = '\0'; - - if(!ifofile->file) { - fprintf(stderr, "libdvdread: Can't open file %s.\n", ifo_filename); - free(ifofile); - return NULL; - } +static void ifo_handle_free(ifo_handle_t *ifofile) { + free(ifofile->state); + free(ifofile); +} +static ifo_handle_t *ifoOpenInternal(ifo_handle_t *ifofile) { /* First check if this is a VMGI file. */ if(ifoRead_VMG(ifofile)) { /* These are both mandatory. */ if(!ifoRead_FP_PGC(ifofile) || !ifoRead_TT_SRPT(ifofile)) - goto ifoOpen_try_bup; + return NULL; ifoRead_PGCI_UT(ifofile); ifoRead_PTL_MAIT(ifofile); /* This is also mandatory. */ if(!ifoRead_VTS_ATRT(ifofile)) - goto ifoOpen_try_bup; + return NULL; ifoRead_TXTDT_MGI(ifofile); ifoRead_C_ADT(ifofile); @@ -341,7 +409,7 @@ ifo_handle_t *ifoOpen(dvd_reader_t *dvd, int title) { if(ifoRead_VTS(ifofile)) { if(!ifoRead_VTS_PTT_SRPT(ifofile) || !ifoRead_PGCIT(ifofile)) - goto ifoOpen_try_bup; + return NULL; ifoRead_PGCI_UT(ifofile); ifoRead_VTS_TMAPT(ifofile); @@ -349,73 +417,104 @@ ifo_handle_t *ifoOpen(dvd_reader_t *dvd, int title) { ifoRead_VOBU_ADMAP(ifofile); if(!ifoRead_TITLE_C_ADT(ifofile) || !ifoRead_TITLE_VOBU_ADMAP(ifofile)) - goto ifoOpen_try_bup; + return NULL; return ifofile; } -ifoOpen_try_bup: - if (bup_file_opened) - goto ifoOpen_fail; + return NULL; +} + +ifo_handle_t *ifoOpenPath(const char *filename) { + ifo_handle_t *ifofile; + int fd; + +#ifndef O_CLOEXEC +# define O_CLOEXEC 0 +#endif +#ifndef O_BINARY +# define O_BINARY 0 +#endif + fd = open(filename, O_RDONLY|O_CLOEXEC|O_BINARY); + if (fd < 0) + return NULL; + + ifofile = ifo_handle_alloc(FOPS_RAW_FD); + ifofile->state->fd = fd; + + if (ifoOpenInternal(ifofile)) + return ifofile; - /* Try BUP instead */ ifoClose(ifofile); + return NULL; +} + +static dvd_file_t *DVDOpenFile_(dvd_reader_t *dvd, int title, int *bup_file_opened) { + dvd_file_t *file; + + file = DVDOpenFile(dvd, title, DVD_READ_INFO_FILE); + if (bup_file_opened) + *bup_file_opened = 0; + + if (!file) { /* Failed to open IFO, try to open BUP */ + file = DVDOpenFile(dvd, title, DVD_READ_INFO_BACKUP_FILE); + if (bup_file_opened) + *bup_file_opened = 1; + } + + return file; +} + +ifo_handle_t *ifoOpen(dvd_reader_t *dvd, int title) { + ifo_handle_t *ifofile; + int bup_file_opened = 0; + char ifo_filename[13]; - ifofile = (ifo_handle_t *)malloc(sizeof(ifo_handle_t)); + ifofile = ifo_handle_alloc(FOPS_LIBDVD); if(!ifofile) return NULL; - - memset(ifofile, 0, sizeof(ifo_handle_t)); - ifofile->file = DVDOpenFile(dvd, title, DVD_READ_INFO_BACKUP_FILE); + ifofile->state->dvd = DVDOpenFile_(dvd, title, &bup_file_opened); if (title) - snprintf(ifo_filename, 12, "VTS_%02d_0.BUP", title); + snprintf(ifo_filename, 12, "VTS_%02d_0.%s", title, bup_file_opened ? "BUP" : "IFO"); else - strncpy(ifo_filename, "VIDEO_TS.BUP", 12); + snprintf(ifo_filename, 12, "VIDEO_TS.%s", bup_file_opened ? "BUP" : "IFO"); + + ifo_filename[12] = '\0'; - if (!ifofile->file) { + if(!ifofile->state->dvd) { fprintf(stderr, "libdvdread: Can't open file %s.\n", ifo_filename); - free(ifofile); + ifo_handle_free(ifofile); return NULL; } - bup_file_opened = 1; - /* First check if this is a VMGI file. */ - if(ifoRead_VMG(ifofile)) { + if (ifoOpenInternal(ifofile)) + return ifofile; - /* These are both mandatory. */ - if(!ifoRead_FP_PGC(ifofile) || !ifoRead_TT_SRPT(ifofile)) - goto ifoOpen_fail; + if (bup_file_opened) + goto ifoOpen_fail; - ifoRead_PGCI_UT(ifofile); - ifoRead_PTL_MAIT(ifofile); + /* Try BUP instead */ + ifoClose(ifofile); - /* This is also mandatory. */ - if(!ifoRead_VTS_ATRT(ifofile)) - goto ifoOpen_fail; + ifofile = ifo_handle_alloc(FOPS_LIBDVD); + if(!ifofile) + return NULL; - ifoRead_TXTDT_MGI(ifofile); - ifoRead_C_ADT(ifofile); - ifoRead_VOBU_ADMAP(ifofile); + if (title) + snprintf(ifo_filename, 12, "VTS_%02d_0.BUP", title); + else + strncpy(ifo_filename, "VIDEO_TS.BUP", 12); - return ifofile; + if (!ifofile->state->dvd) { + fprintf(stderr, "libdvdread: Can't open file %s.\n", ifo_filename); + ifo_handle_free(ifofile); + return NULL; } + bup_file_opened = 1; - if(ifoRead_VTS(ifofile)) { - - if(!ifoRead_VTS_PTT_SRPT(ifofile) || !ifoRead_PGCIT(ifofile)) - goto ifoOpen_fail; - - ifoRead_PGCI_UT(ifofile); - ifoRead_VTS_TMAPT(ifofile); - ifoRead_C_ADT(ifofile); - ifoRead_VOBU_ADMAP(ifofile); - - if(!ifoRead_TITLE_C_ADT(ifofile) || !ifoRead_TITLE_VOBU_ADMAP(ifofile)) - goto ifoOpen_fail; - + if (ifoOpenInternal(ifofile)) return ifofile; - } ifoOpen_fail: fprintf(stderr, "libdvdread: Invalid IFO for title %d (%s).\n", title, ifo_filename); @@ -427,16 +526,12 @@ ifoOpen_fail: ifo_handle_t *ifoOpenVMGI(dvd_reader_t *dvd) { ifo_handle_t *ifofile; - ifofile = (ifo_handle_t *)malloc(sizeof(ifo_handle_t)); + ifofile = ifo_handle_alloc(FOPS_LIBDVD); if(!ifofile) return NULL; - memset(ifofile, 0, sizeof(ifo_handle_t)); - - ifofile->file = DVDOpenFile(dvd, 0, DVD_READ_INFO_FILE); - if(!ifofile->file) /* Should really catch any error and try to fallback */ - ifofile->file = DVDOpenFile(dvd, 0, DVD_READ_INFO_BACKUP_FILE); - if(!ifofile->file) { + ifofile->state->dvd = DVDOpenFile_(dvd, 0, NULL); + if(!ifofile->state->dvd) { fprintf(stderr, "libdvdread: Can't open file VIDEO_TS.IFO.\n"); free(ifofile); return NULL; @@ -454,22 +549,17 @@ ifo_handle_t *ifoOpenVMGI(dvd_reader_t *dvd) { ifo_handle_t *ifoOpenVTSI(dvd_reader_t *dvd, int title) { ifo_handle_t *ifofile; - ifofile = (ifo_handle_t *)malloc(sizeof(ifo_handle_t)); - if(!ifofile) - return NULL; - - memset(ifofile, 0, sizeof(ifo_handle_t)); - if(title <= 0 || title > 99) { fprintf(stderr, "libdvdread: ifoOpenVTSI invalid title (%d).\n", title); - free(ifofile); return NULL; } - ifofile->file = DVDOpenFile(dvd, title, DVD_READ_INFO_FILE); - if(!ifofile->file) /* Should really catch any error and try to fallback */ - ifofile->file = DVDOpenFile(dvd, title, DVD_READ_INFO_BACKUP_FILE); - if(!ifofile->file) { + ifofile = ifo_handle_alloc(FOPS_LIBDVD); + if(!ifofile) + return NULL; + + ifofile->state->dvd = DVDOpenFile_(dvd, 0, NULL); + if(!ifofile->state->dvd) { fprintf(stderr, "libdvdread: Can't open file VTS_%02d_0.IFO.\n", title); free(ifofile); return NULL; @@ -509,8 +599,7 @@ void ifoClose(ifo_handle_t *ifofile) { if(ifofile->vtsi_mat) free(ifofile->vtsi_mat); - DVDCloseFile(ifofile->file); - ifofile->file = 0; + fops_close(ifofile->state); free(ifofile); ifofile = 0; } @@ -525,13 +614,13 @@ static int ifoRead_VMG(ifo_handle_t *ifofile) { ifofile->vmgi_mat = vmgi_mat; - if(!DVDFileSeek_(ifofile->file, 0)) { + if(!fops_seek(ifofile, 0)) { free(ifofile->vmgi_mat); ifofile->vmgi_mat = 0; return 0; } - if(!DVDReadBytes(ifofile->file, vmgi_mat, sizeof(vmgi_mat_t))) { + if(!fops_read(ifofile, vmgi_mat, sizeof(vmgi_mat_t))) { free(ifofile->vmgi_mat); ifofile->vmgi_mat = 0; return 0; @@ -617,13 +706,13 @@ static int ifoRead_VTS(ifo_handle_t *ifofile) { ifofile->vtsi_mat = vtsi_mat; - if(!DVDFileSeek_(ifofile->file, 0)) { + if(!fops_seek(ifofile, 0)) { free(ifofile->vtsi_mat); ifofile->vtsi_mat = NULL; return 0; } - if(!(DVDReadBytes(ifofile->file, vtsi_mat, sizeof(vtsi_mat_t)))) { + if(!fops_read(ifofile, vtsi_mat, sizeof(vtsi_mat_t))) { free(ifofile->vtsi_mat); ifofile->vtsi_mat = NULL; return 0; @@ -728,10 +817,10 @@ static int ifoRead_PGC_COMMAND_TBL(ifo_handle_t *ifofile, memset(cmd_tbl, 0, sizeof(pgc_command_tbl_t)); - if(!DVDFileSeek_(ifofile->file, offset)) + if(!fops_seek(ifofile, offset)) return 0; - if(!(DVDReadBytes(ifofile->file, cmd_tbl, PGC_COMMAND_TBL_SIZE))) + if(!fops_read(ifofile, cmd_tbl, PGC_COMMAND_TBL_SIZE)) return 0; B2N_16(cmd_tbl->nr_of_pre); @@ -746,7 +835,7 @@ static int ifoRead_PGC_COMMAND_TBL(ifo_handle_t *ifofile, if(!cmd_tbl->pre_cmds) return 0; - if(!(DVDReadBytes(ifofile->file, cmd_tbl->pre_cmds, pre_cmds_size))) { + if(!fops_read(ifofile, cmd_tbl->pre_cmds, pre_cmds_size)) { free(cmd_tbl->pre_cmds); return 0; } @@ -760,7 +849,7 @@ static int ifoRead_PGC_COMMAND_TBL(ifo_handle_t *ifofile, free(cmd_tbl->pre_cmds); return 0; } - if(!(DVDReadBytes(ifofile->file, cmd_tbl->post_cmds, post_cmds_size))) { + if(!fops_read(ifofile, cmd_tbl->post_cmds, post_cmds_size)) { if(cmd_tbl->pre_cmds) free(cmd_tbl->pre_cmds); free(cmd_tbl->post_cmds); @@ -778,7 +867,7 @@ static int ifoRead_PGC_COMMAND_TBL(ifo_handle_t *ifofile, free(cmd_tbl->post_cmds); return 0; } - if(!(DVDReadBytes(ifofile->file, cmd_tbl->cell_cmds, cell_cmds_size))) { + if(!fops_read(ifofile, cmd_tbl->cell_cmds, cell_cmds_size)) { if(cmd_tbl->pre_cmds) free(cmd_tbl->pre_cmds); if(cmd_tbl->post_cmds) @@ -812,10 +901,10 @@ static int ifoRead_PGC_PROGRAM_MAP(ifo_handle_t *ifofile, unsigned int nr, unsigned int offset) { unsigned int size = nr * sizeof(pgc_program_map_t); - if(!DVDFileSeek_(ifofile->file, offset)) + if(!fops_seek(ifofile, offset)) return 0; - if(!(DVDReadBytes(ifofile->file, program_map, size))) + if(!fops_read(ifofile, program_map, size)) return 0; return 1; @@ -827,10 +916,10 @@ static int ifoRead_CELL_PLAYBACK_TBL(ifo_handle_t *ifofile, unsigned int i; unsigned int size = nr * sizeof(cell_playback_t); - if(!DVDFileSeek_(ifofile->file, offset)) + if(!fops_seek(ifofile, offset)) return 0; - if(!(DVDReadBytes(ifofile->file, cell_playback, size))) + if(!fops_read(ifofile, cell_playback, size)) return 0; for(i = 0; i < nr; i++) { @@ -852,10 +941,10 @@ static int ifoRead_CELL_POSITION_TBL(ifo_handle_t *ifofile, unsigned int i; unsigned int size = nr * sizeof(cell_position_t); - if(!DVDFileSeek_(ifofile->file, offset)) + if(!fops_seek(ifofile, offset)) return 0; - if(!(DVDReadBytes(ifofile->file, cell_position, size))) + if(!fops_read(ifofile, cell_position, size)) return 0; for(i = 0; i < nr; i++) { @@ -869,10 +958,10 @@ static int ifoRead_CELL_POSITION_TBL(ifo_handle_t *ifofile, static int ifoRead_PGC(ifo_handle_t *ifofile, pgc_t *pgc, unsigned int offset) { unsigned int i; - if(!DVDFileSeek_(ifofile->file, offset)) + if(!fops_seek(ifofile, offset)) return 0; - if(!(DVDReadBytes(ifofile->file, pgc, PGC_SIZE))) + if(!fops_read(ifofile, pgc, PGC_SIZE)) return 0; read_user_ops(&pgc->prohibited_ops); @@ -1049,7 +1138,7 @@ int ifoRead_TT_SRPT(ifo_handle_t *ifofile) { if(ifofile->vmgi_mat->tt_srpt == 0) /* mandatory */ return 0; - if(!DVDFileSeek_(ifofile->file, ifofile->vmgi_mat->tt_srpt * DVD_BLOCK_LEN)) + if(!fops_seek(ifofile, ifofile->vmgi_mat->tt_srpt * DVD_BLOCK_LEN)) return 0; tt_srpt = (tt_srpt_t *)malloc(sizeof(tt_srpt_t)); @@ -1058,7 +1147,7 @@ int ifoRead_TT_SRPT(ifo_handle_t *ifofile) { ifofile->tt_srpt = tt_srpt; - if(!(DVDReadBytes(ifofile->file, tt_srpt, TT_SRPT_SIZE))) { + if(!fops_read(ifofile, tt_srpt, TT_SRPT_SIZE)) { fprintf(stderr, "libdvdread: Unable to read read TT_SRPT.\n"); free(tt_srpt); return 0; @@ -1075,7 +1164,7 @@ int ifoRead_TT_SRPT(ifo_handle_t *ifofile) { ifofile->tt_srpt = 0; return 0; } - if(!(DVDReadBytes(ifofile->file, tt_srpt->title, info_length))) { + if(!fops_read(ifofile, tt_srpt->title, info_length)) { fprintf(stderr, "libdvdread: Unable to read read TT_SRPT.\n"); ifoFree_TT_SRPT(ifofile); return 0; @@ -1151,7 +1240,7 @@ int ifoRead_VTS_PTT_SRPT(ifo_handle_t *ifofile) { if(ifofile->vtsi_mat->vts_ptt_srpt == 0) /* mandatory */ return 0; - if(!DVDFileSeek_(ifofile->file, + if(!fops_seek(ifofile, ifofile->vtsi_mat->vts_ptt_srpt * DVD_BLOCK_LEN)) return 0; @@ -1162,7 +1251,7 @@ int ifoRead_VTS_PTT_SRPT(ifo_handle_t *ifofile) { vts_ptt_srpt->title = NULL; ifofile->vts_ptt_srpt = vts_ptt_srpt; - if(!(DVDReadBytes(ifofile->file, vts_ptt_srpt, VTS_PTT_SRPT_SIZE))) { + if(!fops_read(ifofile, vts_ptt_srpt, VTS_PTT_SRPT_SIZE)) { fprintf(stderr, "libdvdread: Unable to read PTT search table.\n"); goto fail; } @@ -1179,7 +1268,7 @@ int ifoRead_VTS_PTT_SRPT(ifo_handle_t *ifofile) { if(!data) goto fail; - if(!(DVDReadBytes(ifofile->file, data, info_length))) { + if(!fops_read(ifofile, data, info_length)) { fprintf(stderr, "libdvdread: Unable to read PTT search table.\n"); goto fail; } @@ -1301,7 +1390,7 @@ int ifoRead_PTL_MAIT(ifo_handle_t *ifofile) { if(ifofile->vmgi_mat->ptl_mait == NULL) return 1; - if(!DVDFileSeek_(ifofile->file, ifofile->vmgi_mat->ptl_mait * DVD_BLOCK_LEN)) + if(!fops_seek(ifofile, ifofile->vmgi_mat->ptl_mait * DVD_BLOCK_LEN)) return 0; ptl_mait = (ptl_mait_t *)malloc(sizeof(ptl_mait_t)); @@ -1310,7 +1399,7 @@ int ifoRead_PTL_MAIT(ifo_handle_t *ifofile) { ifofile->ptl_mait = ptl_mait; - if(!(DVDReadBytes(ifofile->file, ptl_mait, PTL_MAIT_SIZE))) { + if(!fops_read(ifofile, ptl_mait, PTL_MAIT_SIZE)) { free(ptl_mait); ifofile->ptl_mait = NULL; return 0; @@ -1339,7 +1428,7 @@ int ifoRead_PTL_MAIT(ifo_handle_t *ifofile) { } for(i = 0; i < ptl_mait->nr_of_countries; i++) { - if(!(DVDReadBytes(ifofile->file, &ptl_mait->countries[i], PTL_MAIT_COUNTRY_SIZE))) { + if(!fops_read(ifofile, &ptl_mait->countries[i], PTL_MAIT_COUNTRY_SIZE)) { fprintf(stderr, "libdvdread: Unable to read PTL_MAIT.\n"); free(ptl_mait->countries); free(ptl_mait); @@ -1363,7 +1452,7 @@ int ifoRead_PTL_MAIT(ifo_handle_t *ifofile) { for(i = 0; i < ptl_mait->nr_of_countries; i++) { uint16_t *pf_temp; - if(!DVDFileSeek_(ifofile->file, + if(!fops_seek(ifofile, ifofile->vmgi_mat->ptl_mait * DVD_BLOCK_LEN + ptl_mait->countries[i].pf_ptl_mai_start_byte)) { fprintf(stderr, "libdvdread: Unable to seek PTL_MAIT table at index %d.\n",i); @@ -1380,7 +1469,7 @@ int ifoRead_PTL_MAIT(ifo_handle_t *ifofile) { return 0; } memset(pf_temp, 0, info_length); - if(!(DVDReadBytes(ifofile->file, pf_temp, info_length))) { + if(!fops_read(ifofile, pf_temp, info_length)) { fprintf(stderr, "libdvdread: Unable to read PTL_MAIT table at index %d.\n",i); free(pf_temp); free_ptl_mait(ptl_mait, i); @@ -1448,7 +1537,7 @@ int ifoRead_VTS_TMAPT(ifo_handle_t *ifofile) { offset = ifofile->vtsi_mat->vts_tmapt * DVD_BLOCK_LEN; - if(!DVDFileSeek_(ifofile->file, offset)) + if(!fops_seek(ifofile, offset)) return 0; vts_tmapt = (vts_tmapt_t *)malloc(sizeof(vts_tmapt_t)); @@ -1457,7 +1546,7 @@ int ifoRead_VTS_TMAPT(ifo_handle_t *ifofile) { ifofile->vts_tmapt = vts_tmapt; - if(!(DVDReadBytes(ifofile->file, vts_tmapt, VTS_TMAPT_SIZE))) { + if(!fops_read(ifofile, vts_tmapt, VTS_TMAPT_SIZE)) { fprintf(stderr, "libdvdread: Unable to read VTS_TMAPT.\n"); free(vts_tmapt); ifofile->vts_tmapt = NULL; @@ -1480,7 +1569,7 @@ int ifoRead_VTS_TMAPT(ifo_handle_t *ifofile) { vts_tmapt->tmap_offset = vts_tmap_srp; - if(!(DVDReadBytes(ifofile->file, vts_tmap_srp, info_length))) { + if(!fops_read(ifofile, vts_tmap_srp, info_length)) { fprintf(stderr, "libdvdread: Unable to read VTS_TMAPT.\n"); free(vts_tmap_srp); free(vts_tmapt); @@ -1506,12 +1595,12 @@ int ifoRead_VTS_TMAPT(ifo_handle_t *ifofile) { memset(vts_tmapt->tmap, 0, info_length); /* So ifoFree_VTS_TMAPT works. */ for(i = 0; i < vts_tmapt->nr_of_tmaps; i++) { - if(!DVDFileSeek_(ifofile->file, offset + vts_tmap_srp[i])) { + if(!fops_seek(ifofile, offset + vts_tmap_srp[i])) { ifoFree_VTS_TMAPT(ifofile); return 0; } - if(!(DVDReadBytes(ifofile->file, &vts_tmapt->tmap[i], VTS_TMAP_SIZE))) { + if(!fops_read(ifofile, &vts_tmapt->tmap[i], VTS_TMAP_SIZE)) { fprintf(stderr, "libdvdread: Unable to read VTS_TMAP.\n"); ifoFree_VTS_TMAPT(ifofile); return 0; @@ -1533,7 +1622,7 @@ int ifoRead_VTS_TMAPT(ifo_handle_t *ifofile) { return 0; } - if(!(DVDReadBytes(ifofile->file, vts_tmapt->tmap[i].map_ent, info_length))) { + if(!fops_read(ifofile, vts_tmapt->tmap[i].map_ent, info_length)) { fprintf(stderr, "libdvdread: Unable to read VTS_TMAP_ENT.\n"); ifoFree_VTS_TMAPT(ifofile); return 0; @@ -1624,10 +1713,10 @@ static int ifoRead_C_ADT_internal(ifo_handle_t *ifofile, c_adt_t *c_adt, unsigned int sector) { int i, info_length; - if(!DVDFileSeek_(ifofile->file, sector * DVD_BLOCK_LEN)) + if(!fops_seek(ifofile, sector * DVD_BLOCK_LEN)) return 0; - if(!(DVDReadBytes(ifofile->file, c_adt, C_ADT_SIZE))) + if(!fops_read(ifofile, c_adt, C_ADT_SIZE)) return 0; B2N_16(c_adt->nr_of_vobs); @@ -1654,7 +1743,7 @@ static int ifoRead_C_ADT_internal(ifo_handle_t *ifofile, return 0; if(info_length && - !(DVDReadBytes(ifofile->file, c_adt->cell_adr_table, info_length))) { + !fops_read(ifofile, c_adt->cell_adr_table, info_length)) { free(c_adt->cell_adr_table); return 0; } @@ -1760,10 +1849,10 @@ static int ifoRead_VOBU_ADMAP_internal(ifo_handle_t *ifofile, unsigned int i; int info_length; - if(!DVDFileSeekForce_(ifofile->file, sector * DVD_BLOCK_LEN, sector)) + if(!fops_seek_force(ifofile, sector * DVD_BLOCK_LEN, sector)) return 0; - if(!(DVDReadBytes(ifofile->file, vobu_admap, VOBU_ADMAP_SIZE))) + if(!fops_read(ifofile, vobu_admap, VOBU_ADMAP_SIZE)) return 0; B2N_32(vobu_admap->last_byte); @@ -1779,7 +1868,7 @@ static int ifoRead_VOBU_ADMAP_internal(ifo_handle_t *ifofile, return 0; } if(info_length && - !(DVDReadBytes(ifofile->file, + !(fops_read(ifofile, vobu_admap->vobu_start_sectors, info_length))) { free(vobu_admap->vobu_start_sectors); return 0; @@ -1845,10 +1934,10 @@ static int ifoRead_PGCIT_internal(ifo_handle_t *ifofile, pgcit_t *pgcit, int i, info_length; uint8_t *data, *ptr; - if(!DVDFileSeek_(ifofile->file, offset)) + if(!fops_seek(ifofile, offset)) return 0; - if(!(DVDReadBytes(ifofile->file, pgcit, PGCIT_SIZE))) + if(!fops_read(ifofile, pgcit, PGCIT_SIZE)) return 0; B2N_16(pgcit->nr_of_pgci_srp); @@ -1865,7 +1954,7 @@ static int ifoRead_PGCIT_internal(ifo_handle_t *ifofile, pgcit_t *pgcit, if(!data) return 0; - if(info_length && !(DVDReadBytes(ifofile->file, data, info_length))) { + if(info_length && !fops_read(ifofile, data, info_length)) { free(data); return 0; } @@ -1966,13 +2055,13 @@ int ifoRead_PGCI_UT(ifo_handle_t *ifofile) { if(!ifofile->pgci_ut) return 0; - if(!DVDFileSeek_(ifofile->file, sector * DVD_BLOCK_LEN)) { + if(!fops_seek(ifofile, sector * DVD_BLOCK_LEN)) { free(ifofile->pgci_ut); ifofile->pgci_ut = 0; return 0; } - if(!(DVDReadBytes(ifofile->file, ifofile->pgci_ut, PGCI_UT_SIZE))) { + if(!fops_read(ifofile, ifofile->pgci_ut, PGCI_UT_SIZE)) { free(ifofile->pgci_ut); ifofile->pgci_ut = 0; return 0; @@ -1995,7 +2084,7 @@ int ifoRead_PGCI_UT(ifo_handle_t *ifofile) { ifofile->pgci_ut = 0; return 0; } - if(!(DVDReadBytes(ifofile->file, data, info_length))) { + if(!fops_read(ifofile, data, info_length)) { free(data); free(pgci_ut); ifofile->pgci_ut = 0; @@ -2088,10 +2177,10 @@ static int ifoRead_VTS_ATTRIBUTES(ifo_handle_t *ifofile, unsigned int offset) { unsigned int i; - if(!DVDFileSeek_(ifofile->file, offset)) + if(!fops_seek(ifofile, offset)) return 0; - if(!(DVDReadBytes(ifofile->file, vts_attributes, sizeof(vts_attributes_t)))) + if(!fops_read(ifofile, vts_attributes, sizeof(vts_attributes_t))) return 0; read_video_attr(&vts_attributes->vtsm_vobs_attr); @@ -2151,7 +2240,7 @@ int ifoRead_VTS_ATRT(ifo_handle_t *ifofile) { return 0; sector = ifofile->vmgi_mat->vts_atrt; - if(!DVDFileSeek_(ifofile->file, sector * DVD_BLOCK_LEN)) + if(!fops_seek(ifofile, sector * DVD_BLOCK_LEN)) return 0; vts_atrt = (vts_atrt_t *)malloc(sizeof(vts_atrt_t)); @@ -2160,7 +2249,7 @@ int ifoRead_VTS_ATRT(ifo_handle_t *ifofile) { ifofile->vts_atrt = vts_atrt; - if(!(DVDReadBytes(ifofile->file, vts_atrt, VTS_ATRT_SIZE))) { + if(!fops_read(ifofile, vts_atrt, VTS_ATRT_SIZE)) { free(vts_atrt); ifofile->vts_atrt = 0; return 0; @@ -2185,7 +2274,7 @@ int ifoRead_VTS_ATRT(ifo_handle_t *ifofile) { vts_atrt->vts_atrt_offsets = data; - if(!(DVDReadBytes(ifofile->file, data, info_length))) { + if(!fops_read(ifofile, data, info_length)) { free(data); free(vts_atrt); ifofile->vts_atrt = 0; @@ -2250,7 +2339,7 @@ int ifoRead_TXTDT_MGI(ifo_handle_t *ifofile) { if(ifofile->vmgi_mat->txtdt_mgi == 0) return 1; - if(!DVDFileSeek_(ifofile->file, + if(!fops_seek(ifofile, ifofile->vmgi_mat->txtdt_mgi * DVD_BLOCK_LEN)) return 0; @@ -2260,7 +2349,7 @@ int ifoRead_TXTDT_MGI(ifo_handle_t *ifofile) { } ifofile->txtdt_mgi = txtdt_mgi; - if(!(DVDReadBytes(ifofile->file, txtdt_mgi, TXTDT_MGI_SIZE))) { + if(!fops_read(ifofile, txtdt_mgi, TXTDT_MGI_SIZE)) { fprintf(stderr, "libdvdread: Unable to read TXTDT_MGI.\n"); free(txtdt_mgi); ifofile->txtdt_mgi = 0; -- 1.8.0.2 _______________________________________________ DVDnav-discuss mailing list [email protected] https://lists.mplayerhq.hu/mailman/listinfo/dvdnav-discuss
