⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ifo_read.c

📁 君正早期ucos系统(只有早期的才不没有打包成库),MPLAYER,文件系统,图片解码,浏览,电子书,录音,想学ucos,识货的人就下吧 russblock fmradio explore set
💻 C
📖 第 1 页 / 共 5 页
字号:
/* -*- c-basic-offset: 2; indent-tabs-mode: nil -*- *//* * Copyright (C) 2000, 2001, 2002, 2003 *               Bj鰎n Englund <d4bjorn@dtek.chalmers.se>,  *               H錵an Hjort <d95hjort@dtek.chalmers.se> * * Modified for use with MPlayer, changes contained in libdvdread_changes.diff. * detailed changelog at http://svn.mplayerhq.hu/mplayer/trunk/ * $Id: ifo_read.c,v 1.2 2008/03/03 08:11:34 dsqiu Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */#include "config.h"#include <mplaylib.h>#include <mplaylib.h>#if defined(HAVE_INTTYPES_H)#include <inttypes.h>#elif defined(HAVE_STDINT_H)#include <stdint.h>#endif#include <mplaylib.h>#include <errno.h>#include "bswap.h"#include "ifo_types.h"#include "ifo_read.h"#include "dvd_reader.h"#include "dvdread_internal.h"#ifndef DVD_BLOCK_LEN#define DVD_BLOCK_LEN 2048#endif#ifndef NDEBUG#define CHECK_ZERO0(arg)                                                \  if(arg != 0) {                                                        \    fprintf(stderr, "*** Zero check failed in %s:%i\n    for %s = 0x%x\n", \            __FILE__, __LINE__, # arg, arg);                            \  }#define CHECK_ZERO(arg)                                                 \  if(memcmp(my_friendly_zeros, &arg, sizeof(arg))) {                    \    unsigned int i_CZ;                                                  \    fprintf(stderr, "*** Zero check failed in %s:%i\n    for %s = 0x",  \            __FILE__, __LINE__, # arg );                                \    for(i_CZ = 0; i_CZ < sizeof(arg); i_CZ++)                           \      fprintf(stderr, "%02x", *((uint8_t *)&arg + i_CZ));               \    fprintf(stderr, "\n");                                              \  }static const uint8_t my_friendly_zeros[2048];#else#define CHECK_ZERO0(arg) (void)(arg)#define CHECK_ZERO(arg) (void)(arg)#endif/* Prototypes for internal functions */static int ifoRead_VMG(ifo_handle_t *ifofile);static int ifoRead_VTS(ifo_handle_t *ifofile);static int ifoRead_PGC(ifo_handle_t *ifofile, pgc_t *pgc, unsigned int offset);static int ifoRead_PGC_COMMAND_TBL(ifo_handle_t *ifofile,                                    pgc_command_tbl_t *cmd_tbl,                                    unsigned int offset);static int ifoRead_PGC_PROGRAM_MAP(ifo_handle_t *ifofile,                                    pgc_program_map_t *program_map,                                    unsigned int nr, unsigned int offset);static int ifoRead_CELL_PLAYBACK_TBL(ifo_handle_t *ifofile,                                      cell_playback_t *cell_playback,                                      unsigned int nr, unsigned int offset);static int ifoRead_CELL_POSITION_TBL(ifo_handle_t *ifofile,                                      cell_position_t *cell_position,                                      unsigned int nr, unsigned int offset);static int ifoRead_VTS_ATTRIBUTES(ifo_handle_t *ifofile,                                   vts_attributes_t *vts_attributes,                                   unsigned int offset);static int ifoRead_C_ADT_internal(ifo_handle_t *ifofile, c_adt_t *c_adt,                                   unsigned int sector);static int ifoRead_VOBU_ADMAP_internal(ifo_handle_t *ifofile,                                        vobu_admap_t *vobu_admap,                                        unsigned int sector);static int ifoRead_PGCIT_internal(ifo_handle_t *ifofile, pgcit_t *pgcit,                                   unsigned int offset);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 ifo_handle_t *ifoOpen_File(ifo_handle_t *ifofile, int title,                                   char *suffix);static ifo_handle_t *ifoOpenVMGI_File(ifo_handle_t *ifofile, char *suffix);static ifo_handle_t *ifoOpenVTSI_File(ifo_handle_t *ifofile, int title,                                      char *suffix);static inline int DVDFileSeek_( dvd_file_t *dvd_file, uint32_t offset ) {  return (DVDFileSeek(dvd_file, (int)offset) == (int)offset);}ifo_handle_t *ifoOpen(dvd_reader_t *dvd, int title) {  ifo_handle_t *ifofile;  ifofile = malloc(sizeof(ifo_handle_t));  if(!ifofile)    return NULL;  memset(ifofile, 0, sizeof(ifo_handle_t));  ifofile->file = DVDOpenFile(dvd, title, DVD_READ_INFO_FILE);  if(!ifoOpen_File(ifofile, title, "IFO")) {    if(title) {      if(dvdread_verbose(dvd) >= 1) {        fprintf(stderr, "libdvdread: Can't open file VTS_%02d_0.%s.\n",                 title, "IFO");      }    } else {      if(dvdread_verbose(dvd) >= 1) {        fprintf(stderr, "libdvdread: Can't open file VIDEO_TS.%s.\n", "IFO");      }    }    /* lower functions free the pointer, reallocate */    ifofile = (ifo_handle_t *)malloc(sizeof(ifo_handle_t));    if(!ifofile)      return NULL;    memset(ifofile, 0, sizeof(ifo_handle_t));    ifofile->file = DVDOpenFile(dvd, title, DVD_READ_INFO_BACKUP_FILE);    if(!ifoOpen_File(ifofile, title, "BUP")) {      if(title) {        if(dvdread_verbose(dvd) >= 1) {          fprintf(stderr, "libdvdread: Can't open file VTS_%02d_0.%s.\n",                   title, "BUP");        }      } else {        if(dvdread_verbose(dvd) >= 1) {          fprintf(stderr, "libdvdread: Can't open file VIDEO_TS.%s.\n", "BUP");        }      }      return NULL;    }  }  return ifofile;}static ifo_handle_t *ifoOpen_File(ifo_handle_t *ifofile, int title,                                   char *suffix) {  if(!ifofile->file) {    free(ifofile);    return NULL;  }  /* 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)) {      if(dvdread_verbose(device_of_file(ifofile->file)) >= 0) {        fprintf(stderr, "libdvdread: Invalid main menu IFO (VIDEO_TS.%s).\n",                suffix);      }      ifoClose(ifofile);      return NULL;    }    ifoRead_PGCI_UT(ifofile);    ifoRead_PTL_MAIT(ifofile);    /* This is also mandatory. */    if(!ifoRead_VTS_ATRT(ifofile)) {      if(dvdread_verbose(device_of_file(ifofile->file)) >= 0) {        fprintf(stderr, "libdvdread: Invalid main menu IFO (VIDEO_TS.%s).\n",                suffix);      }      ifoClose(ifofile);      return NULL;    }    ifoRead_TXTDT_MGI(ifofile);    ifoRead_C_ADT(ifofile);    ifoRead_VOBU_ADMAP(ifofile);    return ifofile;  }  if(ifoRead_VTS(ifofile)) {    if(!ifoRead_VTS_PTT_SRPT(ifofile) || !ifoRead_PGCIT(ifofile)) {      if(dvdread_verbose(device_of_file(ifofile->file)) >= 0) {        fprintf(stderr, "libdvdread: Invalid title IFO (VTS_%02d_0.%s).\n",                title, suffix);      }      ifoClose(ifofile);      return NULL;    }    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)) {      if(dvdread_verbose(device_of_file(ifofile->file)) >= 0) {        fprintf(stderr, "libdvdread: Invalid title IFO (VTS_%02d_0.%s).\n",                title, suffix);      }      ifoClose(ifofile);      return NULL;    }    return ifofile;  }  if(title) {    if(dvdread_verbose(device_of_file(ifofile->file)) >= 0) {      fprintf(stderr, "libdvdread: Invalid IFO for title %d (VTS_%02d_0.%s).\n",              title, title, suffix);    }  } else {    if(dvdread_verbose(device_of_file(ifofile->file)) >= 0) {      fprintf(stderr, "libdvdread: Invalid IFO for VMGM (VIDEO_TS.%s).\n",               suffix);    }  }  ifoClose(ifofile);  return NULL;}ifo_handle_t *ifoOpenVMGI(dvd_reader_t *dvd) {  ifo_handle_t *ifofile;  ifofile = malloc(sizeof(ifo_handle_t));  if(!ifofile)    return NULL;  memset(ifofile, 0, sizeof(ifo_handle_t));  ifofile->file = DVDOpenFile(dvd, 0, DVD_READ_INFO_FILE);  if(!ifoOpenVMGI_File(ifofile, "IFO")) {    if(dvdread_verbose(dvd) >= 1) {      fprintf(stderr, "libdvdread: Can't open file VIDEO_TS.IFO: %s\n",              strerror(errno));    }    /* lower functions free the pointer, reallocate */    ifofile = (ifo_handle_t *)malloc(sizeof(ifo_handle_t));    if(!ifofile)      return NULL;    memset(ifofile, 0, sizeof(ifo_handle_t));    ifofile->file = DVDOpenFile(dvd, 0, DVD_READ_INFO_BACKUP_FILE);    if(!ifoOpenVMGI_File(ifofile, "BUP"))      if(dvdread_verbose(dvd) >= 1) {        fprintf(stderr, "libdvdread: Can't open file VIDEO_TS.BUP: %s\n",                strerror(errno));      }      return NULL;  }  return ifofile;}static ifo_handle_t *ifoOpenVMGI_File(ifo_handle_t *ifofile, char *suffix) {  if(!ifofile->file) {    free(ifofile);    return NULL;  }  if(ifoRead_VMG(ifofile))    return ifofile;  if(dvdread_verbose(device_of_file(ifofile->file)) >= 0) {    fprintf(stderr, "libdvdread: Invalid main menu IFO (VIDEO_TS.%s).\n",             suffix);  }  ifoClose(ifofile);  return NULL;}ifo_handle_t *ifoOpenVTSI(dvd_reader_t *dvd, int title) {  ifo_handle_t *ifofile;    ifofile = malloc(sizeof(ifo_handle_t));  if(!ifofile)    return NULL;  memset(ifofile, 0, sizeof(ifo_handle_t));    if(title <= 0 || title > 99) {    if(dvdread_verbose(dvd) >= 0) {      fprintf(stderr, "libdvdread: ifoOpenVTSI invalid title (%d).\n", title);    }    free(ifofile);    errno = EINVAL;    return NULL;  }      ifofile->file = DVDOpenFile(dvd, title, DVD_READ_INFO_FILE);  if(!ifoOpenVTSI_File(ifofile, title, "IFO")) {    if(dvdread_verbose(dvd) >= 1) {      fprintf(stderr, "libdvdread: Can't open file VTS_%02d_0.%s.\n", title, "IFO");    }    /* lower functions free the pointer, reallocate */    ifofile = (ifo_handle_t *)malloc(sizeof(ifo_handle_t));    if(!ifofile)      return NULL;    memset(ifofile, 0, sizeof(ifo_handle_t));    ifofile->file = DVDOpenFile(dvd, title, DVD_READ_INFO_BACKUP_FILE);    if(!ifoOpenVTSI_File(ifofile, title, "BUP"))      if(dvdread_verbose(dvd) >= 1) {        fprintf(stderr, "libdvdread: Can't open file VTS_%02d_0.%s.\n", title, "BUP");      }      return NULL;  }  return ifofile;}static ifo_handle_t *ifoOpenVTSI_File(ifo_handle_t* ifofile, int title, char *suffix) {  if(!ifofile->file) {    free(ifofile);    return NULL;  }  ifoRead_VTS(ifofile);  if(ifofile->vtsi_mat)    return ifofile;  if(dvdread_verbose(device_of_file(ifofile->file)) >= 0) {    fprintf(stderr, "libdvdread: Invalid IFO for title %d (VTS_%02d_0.%s).\n",            title, title, suffix);  }  ifoClose(ifofile);  return NULL;}void ifoClose(ifo_handle_t *ifofile) {  if(!ifofile)    return;    ifoFree_VOBU_ADMAP(ifofile);  ifoFree_TITLE_VOBU_ADMAP(ifofile);  ifoFree_C_ADT(ifofile);  ifoFree_TITLE_C_ADT(ifofile);  ifoFree_TXTDT_MGI(ifofile);  ifoFree_VTS_ATRT(ifofile);  ifoFree_PTL_MAIT(ifofile);  ifoFree_PGCI_UT(ifofile);  ifoFree_TT_SRPT(ifofile);  ifoFree_FP_PGC(ifofile);  ifoFree_PGCIT(ifofile);  ifoFree_VTS_PTT_SRPT(ifofile);  ifoFree_VTS_TMAPT(ifofile);  if(ifofile->vmgi_mat)    free(ifofile->vmgi_mat);  if(ifofile->vtsi_mat)    free(ifofile->vtsi_mat);  DVDCloseFile(ifofile->file);  ifofile->file = 0;  free(ifofile);  ifofile = 0;}static int ifoRead_VMG(ifo_handle_t *ifofile) {  vmgi_mat_t *vmgi_mat;  vmgi_mat = malloc(sizeof(vmgi_mat_t));  if(!vmgi_mat)    return 0;  ifofile->vmgi_mat = vmgi_mat;  if(!DVDFileSeek_(ifofile->file, 0)) {    free(ifofile->vmgi_mat);    ifofile->vmgi_mat = 0;    return 0;  }  if(!DVDReadBytes(ifofile->file, vmgi_mat, sizeof(vmgi_mat_t))) {    free(ifofile->vmgi_mat);    ifofile->vmgi_mat = 0;    return 0;  }  if(strncmp("DVDVIDEO-VMG", vmgi_mat->vmg_identifier, 12) != 0) {    free(ifofile->vmgi_mat);    ifofile->vmgi_mat = 0;    return 0;  }    B2N_32(vmgi_mat->vmg_last_sector);  B2N_32(vmgi_mat->vmgi_last_sector);  B2N_32(vmgi_mat->vmg_category);  B2N_16(vmgi_mat->vmg_nr_of_volumes);  B2N_16(vmgi_mat->vmg_this_volume_nr);  B2N_16(vmgi_mat->vmg_nr_of_title_sets);  B2N_64(vmgi_mat->vmg_pos_code);  B2N_32(vmgi_mat->vmgi_last_byte);  B2N_32(vmgi_mat->first_play_pgc);  B2N_32(vmgi_mat->vmgm_vobs);  B2N_32(vmgi_mat->tt_srpt);  B2N_32(vmgi_mat->vmgm_pgci_ut);  B2N_32(vmgi_mat->ptl_mait);  B2N_32(vmgi_mat->vts_atrt);  B2N_32(vmgi_mat->txtdt_mgi);  B2N_32(vmgi_mat->vmgm_c_adt);  B2N_32(vmgi_mat->vmgm_vobu_admap);  B2N_16(vmgi_mat->vmgm_audio_attr.lang_code);  B2N_16(vmgi_mat->vmgm_subp_attr.lang_code);  CHECK_ZERO(vmgi_mat->zero_1);  CHECK_ZERO(vmgi_mat->zero_2);  CHECK_ZERO(vmgi_mat->zero_3);  CHECK_ZERO(vmgi_mat->zero_4);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -