Mercurial > libdvdread4.hg
comparison ifo_read.c @ 26:0d82d0f30c98 src
cosmetics: Convert all tabs to spaces.
author | diego |
---|---|
date | Tue, 23 Sep 2008 09:14:45 +0000 |
parents | 447c5319a522 |
children | 98951f8ec89c |
comparison
equal
deleted
inserted
replaced
25:17258a7b3239 | 26:0d82d0f30c98 |
---|---|
64 static int ifoRead_VMG(ifo_handle_t *ifofile); | 64 static int ifoRead_VMG(ifo_handle_t *ifofile); |
65 static int ifoRead_VTS(ifo_handle_t *ifofile); | 65 static int ifoRead_VTS(ifo_handle_t *ifofile); |
66 static int ifoRead_PGC(ifo_handle_t *ifofile, pgc_t *pgc, unsigned int offset); | 66 static int ifoRead_PGC(ifo_handle_t *ifofile, pgc_t *pgc, unsigned int offset); |
67 static int ifoRead_PGC_COMMAND_TBL(ifo_handle_t *ifofile, | 67 static int ifoRead_PGC_COMMAND_TBL(ifo_handle_t *ifofile, |
68 pgc_command_tbl_t *cmd_tbl, | 68 pgc_command_tbl_t *cmd_tbl, |
69 unsigned int offset); | 69 unsigned int offset); |
70 static int ifoRead_PGC_PROGRAM_MAP(ifo_handle_t *ifofile, | 70 static int ifoRead_PGC_PROGRAM_MAP(ifo_handle_t *ifofile, |
71 pgc_program_map_t *program_map, | 71 pgc_program_map_t *program_map, |
72 unsigned int nr, unsigned int offset); | 72 unsigned int nr, unsigned int offset); |
73 static int ifoRead_CELL_PLAYBACK_TBL(ifo_handle_t *ifofile, | 73 static int ifoRead_CELL_PLAYBACK_TBL(ifo_handle_t *ifofile, |
74 cell_playback_t *cell_playback, | 74 cell_playback_t *cell_playback, |
81 unsigned int offset); | 81 unsigned int offset); |
82 static int ifoRead_C_ADT_internal(ifo_handle_t *ifofile, c_adt_t *c_adt, | 82 static int ifoRead_C_ADT_internal(ifo_handle_t *ifofile, c_adt_t *c_adt, |
83 unsigned int sector); | 83 unsigned int sector); |
84 static int ifoRead_VOBU_ADMAP_internal(ifo_handle_t *ifofile, | 84 static int ifoRead_VOBU_ADMAP_internal(ifo_handle_t *ifofile, |
85 vobu_admap_t *vobu_admap, | 85 vobu_admap_t *vobu_admap, |
86 unsigned int sector); | 86 unsigned int sector); |
87 static int ifoRead_PGCIT_internal(ifo_handle_t *ifofile, pgcit_t *pgcit, | 87 static int ifoRead_PGCIT_internal(ifo_handle_t *ifofile, pgcit_t *pgcit, |
88 unsigned int offset); | 88 unsigned int offset); |
89 | 89 |
90 static void ifoFree_PGC(pgc_t *pgc); | 90 static void ifoFree_PGC(pgc_t *pgc); |
91 static void ifoFree_PGC_COMMAND_TBL(pgc_command_tbl_t *cmd_tbl); | 91 static void ifoFree_PGC_COMMAND_TBL(pgc_command_tbl_t *cmd_tbl); |
361 return ifofile; | 361 return ifofile; |
362 } | 362 } |
363 | 363 |
364 if(title) { | 364 if(title) { |
365 fprintf(stderr, "libdvdread: Invalid IFO for title %d (VTS_%02d_0.IFO).\n", | 365 fprintf(stderr, "libdvdread: Invalid IFO for title %d (VTS_%02d_0.IFO).\n", |
366 title, title); | 366 title, title); |
367 } else { | 367 } else { |
368 fprintf(stderr, "libdvdread: Invalid IFO for VMGM (VIDEO_TS.IFO).\n"); | 368 fprintf(stderr, "libdvdread: Invalid IFO for VMGM (VIDEO_TS.IFO).\n"); |
369 } | 369 } |
370 ifoClose(ifofile); | 370 ifoClose(ifofile); |
371 return NULL; | 371 return NULL; |
671 } | 671 } |
672 | 672 |
673 | 673 |
674 static int ifoRead_PGC_COMMAND_TBL(ifo_handle_t *ifofile, | 674 static int ifoRead_PGC_COMMAND_TBL(ifo_handle_t *ifofile, |
675 pgc_command_tbl_t *cmd_tbl, | 675 pgc_command_tbl_t *cmd_tbl, |
676 unsigned int offset) { | 676 unsigned int offset) { |
677 | 677 |
678 memset(cmd_tbl, 0, sizeof(pgc_command_tbl_t)); | 678 memset(cmd_tbl, 0, sizeof(pgc_command_tbl_t)); |
679 | 679 |
680 if(!DVDFileSeek_(ifofile->file, offset)) | 680 if(!DVDFileSeek_(ifofile->file, offset)) |
681 return 0; | 681 return 0; |
704 if(cmd_tbl->nr_of_post != 0) { | 704 if(cmd_tbl->nr_of_post != 0) { |
705 unsigned int post_cmds_size = cmd_tbl->nr_of_post * COMMAND_DATA_SIZE; | 705 unsigned int post_cmds_size = cmd_tbl->nr_of_post * COMMAND_DATA_SIZE; |
706 cmd_tbl->post_cmds = (vm_cmd_t *)malloc(post_cmds_size); | 706 cmd_tbl->post_cmds = (vm_cmd_t *)malloc(post_cmds_size); |
707 if(!cmd_tbl->post_cmds) { | 707 if(!cmd_tbl->post_cmds) { |
708 if(cmd_tbl->pre_cmds) | 708 if(cmd_tbl->pre_cmds) |
709 free(cmd_tbl->pre_cmds); | 709 free(cmd_tbl->pre_cmds); |
710 return 0; | 710 return 0; |
711 } | 711 } |
712 if(!(DVDReadBytes(ifofile->file, cmd_tbl->post_cmds, post_cmds_size))) { | 712 if(!(DVDReadBytes(ifofile->file, cmd_tbl->post_cmds, post_cmds_size))) { |
713 if(cmd_tbl->pre_cmds) | 713 if(cmd_tbl->pre_cmds) |
714 free(cmd_tbl->pre_cmds); | 714 free(cmd_tbl->pre_cmds); |
715 free(cmd_tbl->post_cmds); | 715 free(cmd_tbl->post_cmds); |
716 return 0; | 716 return 0; |
717 } | 717 } |
718 } | 718 } |
719 | 719 |
720 if(cmd_tbl->nr_of_cell != 0) { | 720 if(cmd_tbl->nr_of_cell != 0) { |
721 unsigned int cell_cmds_size = cmd_tbl->nr_of_cell * COMMAND_DATA_SIZE; | 721 unsigned int cell_cmds_size = cmd_tbl->nr_of_cell * COMMAND_DATA_SIZE; |
722 cmd_tbl->cell_cmds = (vm_cmd_t *)malloc(cell_cmds_size); | 722 cmd_tbl->cell_cmds = (vm_cmd_t *)malloc(cell_cmds_size); |
723 if(!cmd_tbl->cell_cmds) { | 723 if(!cmd_tbl->cell_cmds) { |
724 if(cmd_tbl->pre_cmds) | 724 if(cmd_tbl->pre_cmds) |
725 free(cmd_tbl->pre_cmds); | 725 free(cmd_tbl->pre_cmds); |
726 if(cmd_tbl->post_cmds) | 726 if(cmd_tbl->post_cmds) |
727 free(cmd_tbl->post_cmds); | 727 free(cmd_tbl->post_cmds); |
728 return 0; | 728 return 0; |
729 } | 729 } |
730 if(!(DVDReadBytes(ifofile->file, cmd_tbl->cell_cmds, cell_cmds_size))) { | 730 if(!(DVDReadBytes(ifofile->file, cmd_tbl->cell_cmds, cell_cmds_size))) { |
731 if(cmd_tbl->pre_cmds) | 731 if(cmd_tbl->pre_cmds) |
732 free(cmd_tbl->pre_cmds); | 732 free(cmd_tbl->pre_cmds); |
733 if(cmd_tbl->post_cmds) | 733 if(cmd_tbl->post_cmds) |
734 free(cmd_tbl->post_cmds); | 734 free(cmd_tbl->post_cmds); |
735 free(cmd_tbl->cell_cmds); | 735 free(cmd_tbl->cell_cmds); |
736 return 0; | 736 return 0; |
737 } | 737 } |
738 } | 738 } |
739 | 739 |
756 } | 756 } |
757 } | 757 } |
758 | 758 |
759 static int ifoRead_PGC_PROGRAM_MAP(ifo_handle_t *ifofile, | 759 static int ifoRead_PGC_PROGRAM_MAP(ifo_handle_t *ifofile, |
760 pgc_program_map_t *program_map, | 760 pgc_program_map_t *program_map, |
761 unsigned int nr, unsigned int offset) { | 761 unsigned int nr, unsigned int offset) { |
762 unsigned int size = nr * sizeof(pgc_program_map_t); | 762 unsigned int size = nr * sizeof(pgc_program_map_t); |
763 | 763 |
764 if(!DVDFileSeek_(ifofile->file, offset)) | 764 if(!DVDFileSeek_(ifofile->file, offset)) |
765 return 0; | 765 return 0; |
766 | 766 |
897 if(pgc->cell_playback_offset != 0 && pgc->nr_of_cells>0) { | 897 if(pgc->cell_playback_offset != 0 && pgc->nr_of_cells>0) { |
898 pgc->cell_playback = malloc(pgc->nr_of_cells * sizeof(cell_playback_t)); | 898 pgc->cell_playback = malloc(pgc->nr_of_cells * sizeof(cell_playback_t)); |
899 if(!pgc->cell_playback) { | 899 if(!pgc->cell_playback) { |
900 ifoFree_PGC_COMMAND_TBL(pgc->command_tbl); | 900 ifoFree_PGC_COMMAND_TBL(pgc->command_tbl); |
901 if(pgc->program_map) | 901 if(pgc->program_map) |
902 free(pgc->program_map); | 902 free(pgc->program_map); |
903 return 0; | 903 return 0; |
904 } | 904 } |
905 if(!ifoRead_CELL_PLAYBACK_TBL(ifofile, pgc->cell_playback, | 905 if(!ifoRead_CELL_PLAYBACK_TBL(ifofile, pgc->cell_playback, |
906 pgc->nr_of_cells, | 906 pgc->nr_of_cells, |
907 offset + pgc->cell_playback_offset)) { | 907 offset + pgc->cell_playback_offset)) { |
908 ifoFree_PGC_COMMAND_TBL(pgc->command_tbl); | 908 ifoFree_PGC_COMMAND_TBL(pgc->command_tbl); |
909 if(pgc->program_map) | 909 if(pgc->program_map) |
910 free(pgc->program_map); | 910 free(pgc->program_map); |
911 free(pgc->cell_playback); | 911 free(pgc->cell_playback); |
912 return 0; | 912 return 0; |
913 } | 913 } |
914 } else { | 914 } else { |
915 pgc->cell_playback = NULL; | 915 pgc->cell_playback = NULL; |
920 if(!pgc->cell_position) { | 920 if(!pgc->cell_position) { |
921 ifoFree_PGC(pgc); | 921 ifoFree_PGC(pgc); |
922 return 0; | 922 return 0; |
923 } | 923 } |
924 if(!ifoRead_CELL_POSITION_TBL(ifofile, pgc->cell_position, | 924 if(!ifoRead_CELL_POSITION_TBL(ifofile, pgc->cell_position, |
925 pgc->nr_of_cells, | 925 pgc->nr_of_cells, |
926 offset + pgc->cell_position_offset)) { | 926 offset + pgc->cell_position_offset)) { |
927 ifoFree_PGC(pgc); | 927 ifoFree_PGC(pgc); |
928 return 0; | 928 return 0; |
929 } | 929 } |
930 } else { | 930 } else { |
1099 | 1099 |
1100 if(ifofile->vtsi_mat->vts_ptt_srpt == 0) /* mandatory */ | 1100 if(ifofile->vtsi_mat->vts_ptt_srpt == 0) /* mandatory */ |
1101 return 0; | 1101 return 0; |
1102 | 1102 |
1103 if(!DVDFileSeek_(ifofile->file, | 1103 if(!DVDFileSeek_(ifofile->file, |
1104 ifofile->vtsi_mat->vts_ptt_srpt * DVD_BLOCK_LEN)) | 1104 ifofile->vtsi_mat->vts_ptt_srpt * DVD_BLOCK_LEN)) |
1105 return 0; | 1105 return 0; |
1106 | 1106 |
1107 vts_ptt_srpt = (vts_ptt_srpt_t *)malloc(sizeof(vts_ptt_srpt_t)); | 1107 vts_ptt_srpt = (vts_ptt_srpt_t *)malloc(sizeof(vts_ptt_srpt_t)); |
1108 if(!vts_ptt_srpt) | 1108 if(!vts_ptt_srpt) |
1109 return 0; | 1109 return 0; |
1262 CHECK_VALUE(ptl_mait->nr_of_countries != 0); | 1262 CHECK_VALUE(ptl_mait->nr_of_countries != 0); |
1263 CHECK_VALUE(ptl_mait->nr_of_countries < 100); /* ?? */ | 1263 CHECK_VALUE(ptl_mait->nr_of_countries < 100); /* ?? */ |
1264 CHECK_VALUE(ptl_mait->nr_of_vtss != 0); | 1264 CHECK_VALUE(ptl_mait->nr_of_vtss != 0); |
1265 CHECK_VALUE(ptl_mait->nr_of_vtss < 100); /* ?? */ | 1265 CHECK_VALUE(ptl_mait->nr_of_vtss < 100); /* ?? */ |
1266 CHECK_VALUE(ptl_mait->nr_of_countries * PTL_MAIT_COUNTRY_SIZE | 1266 CHECK_VALUE(ptl_mait->nr_of_countries * PTL_MAIT_COUNTRY_SIZE |
1267 <= ptl_mait->last_byte + 1 - PTL_MAIT_SIZE); | 1267 <= ptl_mait->last_byte + 1 - PTL_MAIT_SIZE); |
1268 | 1268 |
1269 info_length = ptl_mait->nr_of_countries * sizeof(ptl_mait_country_t); | 1269 info_length = ptl_mait->nr_of_countries * sizeof(ptl_mait_country_t); |
1270 ptl_mait->countries = (ptl_mait_country_t *)malloc(info_length); | 1270 ptl_mait->countries = (ptl_mait_country_t *)malloc(info_length); |
1271 if(!ptl_mait->countries) { | 1271 if(!ptl_mait->countries) { |
1272 free(ptl_mait); | 1272 free(ptl_mait); |
1291 | 1291 |
1292 for(i = 0; i < ptl_mait->nr_of_countries; i++) { | 1292 for(i = 0; i < ptl_mait->nr_of_countries; i++) { |
1293 CHECK_ZERO(ptl_mait->countries[i].zero_1); | 1293 CHECK_ZERO(ptl_mait->countries[i].zero_1); |
1294 CHECK_ZERO(ptl_mait->countries[i].zero_2); | 1294 CHECK_ZERO(ptl_mait->countries[i].zero_2); |
1295 CHECK_VALUE(ptl_mait->countries[i].pf_ptl_mai_start_byte | 1295 CHECK_VALUE(ptl_mait->countries[i].pf_ptl_mai_start_byte |
1296 + 8*2 * (ptl_mait->nr_of_vtss + 1) <= ptl_mait->last_byte + 1); | 1296 + 8*2 * (ptl_mait->nr_of_vtss + 1) <= ptl_mait->last_byte + 1); |
1297 } | 1297 } |
1298 | 1298 |
1299 for(i = 0; i < ptl_mait->nr_of_countries; i++) { | 1299 for(i = 0; i < ptl_mait->nr_of_countries; i++) { |
1300 uint16_t *pf_temp; | 1300 uint16_t *pf_temp; |
1301 | 1301 |
1302 if(!DVDFileSeek_(ifofile->file, | 1302 if(!DVDFileSeek_(ifofile->file, |
1303 ifofile->vmgi_mat->ptl_mait * DVD_BLOCK_LEN | 1303 ifofile->vmgi_mat->ptl_mait * DVD_BLOCK_LEN |
1304 + ptl_mait->countries[i].pf_ptl_mai_start_byte)) { | 1304 + ptl_mait->countries[i].pf_ptl_mai_start_byte)) { |
1305 fprintf(stderr, "libdvdread: Unable to seak PTL_MAIT table.\n"); | 1305 fprintf(stderr, "libdvdread: Unable to seak PTL_MAIT table.\n"); |
1306 free(ptl_mait->countries); | 1306 free(ptl_mait->countries); |
1307 free(ptl_mait); | 1307 free(ptl_mait); |
1308 return 0; | 1308 return 0; |
1329 return 0; | 1329 return 0; |
1330 } | 1330 } |
1331 { /* Transpose the array so we can use C indexing. */ | 1331 { /* Transpose the array so we can use C indexing. */ |
1332 int level, vts; | 1332 int level, vts; |
1333 for(level = 0; level < 8; level++) { | 1333 for(level = 0; level < 8; level++) { |
1334 for(vts = 0; vts <= ptl_mait->nr_of_vtss; vts++) { | 1334 for(vts = 0; vts <= ptl_mait->nr_of_vtss; vts++) { |
1335 ptl_mait->countries[i].pf_ptl_mai[vts][level] = | 1335 ptl_mait->countries[i].pf_ptl_mai[vts][level] = |
1336 pf_temp[(7-level)*(ptl_mait->nr_of_vtss+1) + vts]; | 1336 pf_temp[(7-level)*(ptl_mait->nr_of_vtss+1) + vts]; |
1337 } | 1337 } |
1338 } | 1338 } |
1339 free(pf_temp); | 1339 free(pf_temp); |
1340 } | 1340 } |
1341 } | 1341 } |
1342 return 1; | 1342 return 1; |
1484 return; | 1484 return; |
1485 | 1485 |
1486 if(ifofile->vts_tmapt) { | 1486 if(ifofile->vts_tmapt) { |
1487 for(i = 0; i < ifofile->vts_tmapt->nr_of_tmaps; i++) | 1487 for(i = 0; i < ifofile->vts_tmapt->nr_of_tmaps; i++) |
1488 if(ifofile->vts_tmapt->tmap[i].map_ent) | 1488 if(ifofile->vts_tmapt->tmap[i].map_ent) |
1489 free(ifofile->vts_tmapt->tmap[i].map_ent); | 1489 free(ifofile->vts_tmapt->tmap[i].map_ent); |
1490 free(ifofile->vts_tmapt->tmap); | 1490 free(ifofile->vts_tmapt->tmap); |
1491 free(ifofile->vts_tmapt->tmap_offset); | 1491 free(ifofile->vts_tmapt->tmap_offset); |
1492 free(ifofile->vts_tmapt); | 1492 free(ifofile->vts_tmapt); |
1493 ifofile->vts_tmapt = NULL; | 1493 ifofile->vts_tmapt = NULL; |
1494 } | 1494 } |
1598 CHECK_ZERO(c_adt->cell_adr_table[i].zero_1); | 1598 CHECK_ZERO(c_adt->cell_adr_table[i].zero_1); |
1599 CHECK_VALUE(c_adt->cell_adr_table[i].vob_id > 0); | 1599 CHECK_VALUE(c_adt->cell_adr_table[i].vob_id > 0); |
1600 CHECK_VALUE(c_adt->cell_adr_table[i].vob_id <= c_adt->nr_of_vobs); | 1600 CHECK_VALUE(c_adt->cell_adr_table[i].vob_id <= c_adt->nr_of_vobs); |
1601 CHECK_VALUE(c_adt->cell_adr_table[i].cell_id > 0); | 1601 CHECK_VALUE(c_adt->cell_adr_table[i].cell_id > 0); |
1602 CHECK_VALUE(c_adt->cell_adr_table[i].start_sector < | 1602 CHECK_VALUE(c_adt->cell_adr_table[i].start_sector < |
1603 c_adt->cell_adr_table[i].last_sector); | 1603 c_adt->cell_adr_table[i].last_sector); |
1604 } | 1604 } |
1605 | 1605 |
1606 return 1; | 1606 return 1; |
1607 } | 1607 } |
1608 | 1608 |
1685 return 1; | 1685 return 1; |
1686 } | 1686 } |
1687 | 1687 |
1688 static int ifoRead_VOBU_ADMAP_internal(ifo_handle_t *ifofile, | 1688 static int ifoRead_VOBU_ADMAP_internal(ifo_handle_t *ifofile, |
1689 vobu_admap_t *vobu_admap, | 1689 vobu_admap_t *vobu_admap, |
1690 unsigned int sector) { | 1690 unsigned int sector) { |
1691 unsigned int i; | 1691 unsigned int i; |
1692 int info_length; | 1692 int info_length; |
1693 | 1693 |
1694 if(!DVDFileSeekForce_(ifofile->file, sector * DVD_BLOCK_LEN, sector)) | 1694 if(!DVDFileSeekForce_(ifofile->file, sector * DVD_BLOCK_LEN, sector)) |
1695 return 0; | 1695 return 0; |
1709 if(!vobu_admap->vobu_start_sectors) { | 1709 if(!vobu_admap->vobu_start_sectors) { |
1710 return 0; | 1710 return 0; |
1711 } | 1711 } |
1712 if(info_length && | 1712 if(info_length && |
1713 !(DVDReadBytes(ifofile->file, | 1713 !(DVDReadBytes(ifofile->file, |
1714 vobu_admap->vobu_start_sectors, info_length))) { | 1714 vobu_admap->vobu_start_sectors, info_length))) { |
1715 free(vobu_admap->vobu_start_sectors); | 1715 free(vobu_admap->vobu_start_sectors); |
1716 return 0; | 1716 return 0; |
1717 } | 1717 } |
1718 | 1718 |
1719 for(i = 0; i < info_length/sizeof(uint32_t); i++) | 1719 for(i = 0; i < info_length/sizeof(uint32_t); i++) |
1984 free(pgci_ut); | 1984 free(pgci_ut); |
1985 ifofile->pgci_ut = 0; | 1985 ifofile->pgci_ut = 0; |
1986 return 0; | 1986 return 0; |
1987 } | 1987 } |
1988 /* | 1988 /* |
1989 * FIXME: Iterate and verify that all menus that should exists accordingly | 1989 * FIXME: Iterate and verify that all menus that should exists accordingly |
1990 * to pgci_ut->lu[i].exists really do? | 1990 * to pgci_ut->lu[i].exists really do? |
1991 */ | 1991 */ |
1992 } | 1992 } |
1993 | 1993 |
1994 return 1; | 1994 return 1; |
1995 } | 1995 } |
1996 | 1996 |
2178 /* Return successfully if there is nothing to read. */ | 2178 /* Return successfully if there is nothing to read. */ |
2179 if(ifofile->vmgi_mat->txtdt_mgi == 0) | 2179 if(ifofile->vmgi_mat->txtdt_mgi == 0) |
2180 return 1; | 2180 return 1; |
2181 | 2181 |
2182 if(!DVDFileSeek_(ifofile->file, | 2182 if(!DVDFileSeek_(ifofile->file, |
2183 ifofile->vmgi_mat->txtdt_mgi * DVD_BLOCK_LEN)) | 2183 ifofile->vmgi_mat->txtdt_mgi * DVD_BLOCK_LEN)) |
2184 return 0; | 2184 return 0; |
2185 | 2185 |
2186 txtdt_mgi = (txtdt_mgi_t *)malloc(sizeof(txtdt_mgi_t)); | 2186 txtdt_mgi = (txtdt_mgi_t *)malloc(sizeof(txtdt_mgi_t)); |
2187 if(!txtdt_mgi) { | 2187 if(!txtdt_mgi) { |
2188 return 0; | 2188 return 0; |