annotate libmpdvdkit2/ifo_read.c @ 10184:b6c63ab184a4

Changed a few remaining -dvd and -vcd options to dvd:// and vcd://.
author diego
date Sun, 25 May 2003 19:15:01 +0000
parents 596919e4f601
children 25df9508f9a8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7029
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1 /*
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
2 * Copyright (C) 2000, 2001, 2002 Björn Englund <d4bjorn@dtek.chalmers.se>,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
3 * Håkan Hjort <d95hjort@dtek.chalmers.se>
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
4 *
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
5 * This program is free software; you can redistribute it and/or modify
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
7 * the Free Software Foundation; either version 2 of the License, or
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
8 * (at your option) any later version.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
9 *
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
13 * GNU General Public License for more details.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
14 *
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
16 * along with this program; if not, write to the Free Software
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
18 */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
19
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
20 #include <stdio.h>
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
21 #include <stdlib.h>
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
22 #include <unistd.h>
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
23 #include <inttypes.h>
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
24 #include <string.h>
7033
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
25 //#include <assert.h>
7029
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
26
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
27 #include "dvd_reader.h"
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
28
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
29 #include "config.h" // Needed for WORDS_BIGENDIAN
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
30 #include "bswap.h"
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
31 #include "ifo_types.h"
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
32 #include "ifo_read.h"
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
33
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
34 #ifndef DVD_BLOCK_LEN
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
35 #define DVD_BLOCK_LEN 2048
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
36 #endif
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
37
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
38 #ifndef NDEBUG
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
39 #define CHECK_ZERO(arg) \
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
40 if(memcmp(my_friendly_zeros, &arg, sizeof(arg))) { \
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
41 unsigned int i_CZ; \
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
42 fprintf(stderr, "*** Zero check failed in %s:%i\n for %s = 0x", \
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
43 __FILE__, __LINE__, # arg ); \
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
44 for(i_CZ = 0; i_CZ < sizeof(arg); i_CZ++) \
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
45 fprintf(stderr, "%02x", *((uint8_t *)&arg + i_CZ)); \
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
46 fprintf(stderr, "\n"); \
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
47 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
48 static const uint8_t my_friendly_zeros[2048];
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
49 #else
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
50 #define CHECK_ZERO(arg) (void)(arg)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
51 #endif
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
52
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
53
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
54 /* Prototypes for internal functions */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
55 static int ifoRead_VMG(ifo_handle_t *ifofile);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
56 static int ifoRead_VTS(ifo_handle_t *ifofile);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
57 static int ifoRead_PGC(ifo_handle_t *ifofile, pgc_t *pgc, unsigned int offset);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
58 static int ifoRead_PGC_COMMAND_TBL(ifo_handle_t *ifofile,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
59 pgc_command_tbl_t *cmd_tbl,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
60 unsigned int offset);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
61 static int ifoRead_PGC_PROGRAM_MAP(ifo_handle_t *ifofile,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
62 pgc_program_map_t *program_map,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
63 unsigned int nr, unsigned int offset);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
64 static int ifoRead_CELL_PLAYBACK_TBL(ifo_handle_t *ifofile,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
65 cell_playback_t *cell_playback,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
66 unsigned int nr, unsigned int offset);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
67 static int ifoRead_CELL_POSITION_TBL(ifo_handle_t *ifofile,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
68 cell_position_t *cell_position,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
69 unsigned int nr, unsigned int offset);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
70 static int ifoRead_VTS_ATTRIBUTES(ifo_handle_t *ifofile,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
71 vts_attributes_t *vts_attributes,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
72 unsigned int offset);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
73 static int ifoRead_C_ADT_internal(ifo_handle_t *ifofile, c_adt_t *c_adt,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
74 unsigned int sector);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
75 static int ifoRead_VOBU_ADMAP_internal(ifo_handle_t *ifofile,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
76 vobu_admap_t *vobu_admap,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
77 unsigned int sector);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
78 static int ifoRead_PGCIT_internal(ifo_handle_t *ifofile, pgcit_t *pgcit,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
79 unsigned int offset);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
80
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
81 static void ifoFree_PGC(pgc_t *pgc);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
82 static void ifoFree_PGC_COMMAND_TBL(pgc_command_tbl_t *cmd_tbl);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
83 static void ifoFree_PGCIT_internal(pgcit_t *pgcit);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
84
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
85
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
86 static int DVDFileSeek_( dvd_file_t *dvd_file, uint32_t offset ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
87 return (DVDFileSeek(dvd_file, (int)offset) == (int)offset);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
88 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
89
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
90
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
91 ifo_handle_t *ifoOpen(dvd_reader_t *dvd, int title) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
92 ifo_handle_t *ifofile;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
93
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
94 ifofile = (ifo_handle_t *)malloc(sizeof(ifo_handle_t));
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
95 if(!ifofile)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
96 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
97
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
98 memset(ifofile, 0, sizeof(ifo_handle_t));
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
99
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
100 ifofile->file = DVDOpenFile(dvd, title, DVD_READ_INFO_FILE);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
101 if(!ifofile->file) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
102 if(title) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
103 fprintf(stderr, "libdvdread: Can't open file VTS_%02d_0.IFO.\n", title);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
104 } else {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
105 fprintf(stderr, "libdvdread: Can't open file VIDEO_TS.IFO.\n");
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
106 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
107 free(ifofile);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
108 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
109 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
110
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
111 /* First check if this is a VMGI file. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
112 if(ifoRead_VMG(ifofile)) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
113
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
114 /* These are both mandatory. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
115 if(!ifoRead_FP_PGC(ifofile) || !ifoRead_TT_SRPT(ifofile)) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
116 fprintf(stderr, "libdvdread: Invalid main menu IFO (VIDEO_TS.IFO).\n");
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
117 ifoClose(ifofile);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
118 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
119 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
120
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
121 ifoRead_PGCI_UT(ifofile);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
122 ifoRead_PTL_MAIT(ifofile);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
123
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
124 /* This is also mandatory. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
125 if(!ifoRead_VTS_ATRT(ifofile)) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
126 fprintf(stderr, "libdvdread: Invalid main menu IFO (VIDEO_TS.IFO).\n");
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
127 ifoClose(ifofile);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
128 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
129 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
130
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
131 ifoRead_TXTDT_MGI(ifofile);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
132 ifoRead_C_ADT(ifofile);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
133 ifoRead_VOBU_ADMAP(ifofile);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
134
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
135 return ifofile;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
136 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
137
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
138 if(ifoRead_VTS(ifofile)) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
139
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
140 if(!ifoRead_VTS_PTT_SRPT(ifofile) || !ifoRead_PGCIT(ifofile)) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
141 fprintf(stderr, "libdvdread: Invalid title IFO (VTS_%02d_0.IFO).\n",
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
142 title);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
143 ifoClose(ifofile);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
144 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
145 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
146
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
147
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
148 ifoRead_PGCI_UT(ifofile);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
149 ifoRead_C_ADT(ifofile);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
150 ifoRead_VOBU_ADMAP(ifofile);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
151
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
152 if(!ifoRead_TITLE_C_ADT(ifofile) || !ifoRead_TITLE_VOBU_ADMAP(ifofile)) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
153 fprintf(stderr, "libdvdread: Invalid title IFO (VTS_%02d_0.IFO).\n",
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
154 title);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
155 ifoClose(ifofile);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
156 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
157 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
158
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
159 return ifofile;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
160 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
161
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
162 if(title) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
163 fprintf(stderr, "libdvdread: Invalid IFO for title %d (VTS_%02d_0.IFO).\n",
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
164 title, title);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
165 } else {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
166 fprintf(stderr, "libdvdread: Invalid IFO for VMGM (VIDEO_TS.IFO).\n");
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
167 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
168 ifoClose(ifofile);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
169 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
170 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
171
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
172
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
173 ifo_handle_t *ifoOpenVMGI(dvd_reader_t *dvd) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
174 ifo_handle_t *ifofile;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
175
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
176 ifofile = (ifo_handle_t *)malloc(sizeof(ifo_handle_t));
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
177 if(!ifofile)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
178 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
179
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
180 memset(ifofile, 0, sizeof(ifo_handle_t));
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
181
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
182 ifofile->file = DVDOpenFile(dvd, 0, DVD_READ_INFO_FILE);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
183 if(!ifofile->file) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
184 fprintf(stderr, "libdvdread: Can't open file VIDEO_TS.IFO.\n");
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
185 free(ifofile);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
186 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
187 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
188
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
189 if(ifoRead_VMG(ifofile))
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
190 return ifofile;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
191
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
192 fprintf(stderr, "libdvdread: Invalid main menu IFO (VIDEO_TS.IFO).\n");
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
193 ifoClose(ifofile);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
194 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
195 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
196
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
197
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
198 ifo_handle_t *ifoOpenVTSI(dvd_reader_t *dvd, int title) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
199 ifo_handle_t *ifofile;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
200
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
201 ifofile = (ifo_handle_t *)malloc(sizeof(ifo_handle_t));
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
202 if(!ifofile)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
203 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
204
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
205 memset(ifofile, 0, sizeof(ifo_handle_t));
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
206
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
207 if(title <= 0 || title > 99) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
208 fprintf(stderr, "libdvdread: ifoOpenVTSI invalid title (%d).\n", title);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
209 free(ifofile);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
210 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
211 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
212
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
213 ifofile->file = DVDOpenFile(dvd, title, DVD_READ_INFO_FILE);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
214 if(!ifofile->file) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
215 fprintf(stderr, "libdvdread: Can't open file VTS_%02d_0.IFO.\n", title);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
216 free(ifofile);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
217 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
218 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
219
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
220 ifoRead_VTS(ifofile);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
221 if(ifofile->vtsi_mat)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
222 return ifofile;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
223
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
224 fprintf(stderr, "libdvdread: Invalid IFO for title %d (VTS_%02d_0.IFO).\n",
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
225 title, title);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
226 ifoClose(ifofile);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
227 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
228 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
229
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
230
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
231 void ifoClose(ifo_handle_t *ifofile) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
232 if(!ifofile)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
233 return;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
234
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
235 ifoFree_VOBU_ADMAP(ifofile);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
236 ifoFree_TITLE_VOBU_ADMAP(ifofile);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
237 ifoFree_C_ADT(ifofile);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
238 ifoFree_TITLE_C_ADT(ifofile);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
239 ifoFree_TXTDT_MGI(ifofile);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
240 ifoFree_VTS_ATRT(ifofile);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
241 ifoFree_PTL_MAIT(ifofile);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
242 ifoFree_PGCI_UT(ifofile);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
243 ifoFree_TT_SRPT(ifofile);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
244 ifoFree_FP_PGC(ifofile);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
245 ifoFree_PGCIT(ifofile);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
246 ifoFree_VTS_PTT_SRPT(ifofile);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
247
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
248 if(ifofile->vmgi_mat)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
249 free(ifofile->vmgi_mat);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
250
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
251 if(ifofile->vtsi_mat)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
252 free(ifofile->vtsi_mat);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
253
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
254 DVDCloseFile(ifofile->file);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
255 ifofile->file = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
256 free(ifofile);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
257 ifofile = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
258 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
259
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
260
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
261 static int ifoRead_VMG(ifo_handle_t *ifofile) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
262 vmgi_mat_t *vmgi_mat;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
263
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
264 vmgi_mat = (vmgi_mat_t *)malloc(sizeof(vmgi_mat_t));
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
265 if(!vmgi_mat)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
266 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
267
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
268 ifofile->vmgi_mat = vmgi_mat;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
269
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
270 if(!DVDFileSeek_(ifofile->file, 0)) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
271 free(ifofile->vmgi_mat);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
272 ifofile->vmgi_mat = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
273 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
274 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
275
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
276 if(!DVDReadBytes(ifofile->file, vmgi_mat, sizeof(vmgi_mat_t))) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
277 free(ifofile->vmgi_mat);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
278 ifofile->vmgi_mat = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
279 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
280 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
281
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
282 if(strncmp("DVDVIDEO-VMG", vmgi_mat->vmg_identifier, 12) != 0) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
283 free(ifofile->vmgi_mat);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
284 ifofile->vmgi_mat = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
285 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
286 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
287
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
288 B2N_32(vmgi_mat->vmg_last_sector);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
289 B2N_32(vmgi_mat->vmgi_last_sector);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
290 B2N_32(vmgi_mat->vmg_category);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
291 B2N_16(vmgi_mat->vmg_nr_of_volumes);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
292 B2N_16(vmgi_mat->vmg_this_volume_nr);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
293 B2N_16(vmgi_mat->vmg_nr_of_title_sets);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
294 B2N_64(vmgi_mat->vmg_pos_code);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
295 B2N_32(vmgi_mat->vmgi_last_byte);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
296 B2N_32(vmgi_mat->first_play_pgc);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
297 B2N_32(vmgi_mat->vmgm_vobs);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
298 B2N_32(vmgi_mat->tt_srpt);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
299 B2N_32(vmgi_mat->vmgm_pgci_ut);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
300 B2N_32(vmgi_mat->ptl_mait);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
301 B2N_32(vmgi_mat->vts_atrt);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
302 B2N_32(vmgi_mat->txtdt_mgi);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
303 B2N_32(vmgi_mat->vmgm_c_adt);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
304 B2N_32(vmgi_mat->vmgm_vobu_admap);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
305 B2N_16(vmgi_mat->vmgm_audio_attr.lang_code);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
306 B2N_16(vmgi_mat->vmgm_subp_attr.lang_code);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
307
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
308
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
309 CHECK_ZERO(vmgi_mat->zero_1);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
310 CHECK_ZERO(vmgi_mat->zero_2);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
311 CHECK_ZERO(vmgi_mat->zero_3);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
312 CHECK_ZERO(vmgi_mat->zero_4);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
313 CHECK_ZERO(vmgi_mat->zero_5);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
314 CHECK_ZERO(vmgi_mat->zero_6);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
315 CHECK_ZERO(vmgi_mat->zero_7);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
316 CHECK_ZERO(vmgi_mat->zero_8);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
317 CHECK_ZERO(vmgi_mat->zero_9);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
318 CHECK_ZERO(vmgi_mat->zero_10);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
319 assert(vmgi_mat->vmg_last_sector != 0);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
320 assert(vmgi_mat->vmgi_last_sector != 0);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
321 assert(vmgi_mat->vmgi_last_sector * 2 <= vmgi_mat->vmg_last_sector);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
322 assert(vmgi_mat->vmg_nr_of_volumes != 0);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
323 assert(vmgi_mat->vmg_this_volume_nr != 0);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
324 assert(vmgi_mat->vmg_this_volume_nr <= vmgi_mat->vmg_nr_of_volumes);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
325 assert(vmgi_mat->disc_side == 1 || vmgi_mat->disc_side == 2);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
326 assert(vmgi_mat->vmg_nr_of_title_sets != 0);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
327 assert(vmgi_mat->vmgi_last_byte >= 341);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
328 assert(vmgi_mat->vmgi_last_byte / DVD_BLOCK_LEN <=
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
329 vmgi_mat->vmgi_last_sector);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
330 /* It seems that first_play_pgc might be optional. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
331 assert(vmgi_mat->first_play_pgc != 0 &&
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
332 vmgi_mat->first_play_pgc < vmgi_mat->vmgi_last_byte);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
333 assert(vmgi_mat->vmgm_vobs == 0 ||
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
334 (vmgi_mat->vmgm_vobs > vmgi_mat->vmgi_last_sector &&
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
335 vmgi_mat->vmgm_vobs < vmgi_mat->vmg_last_sector));
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
336 assert(vmgi_mat->tt_srpt <= vmgi_mat->vmgi_last_sector);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
337 assert(vmgi_mat->vmgm_pgci_ut <= vmgi_mat->vmgi_last_sector);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
338 assert(vmgi_mat->ptl_mait <= vmgi_mat->vmgi_last_sector);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
339 assert(vmgi_mat->vts_atrt <= vmgi_mat->vmgi_last_sector);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
340 assert(vmgi_mat->txtdt_mgi <= vmgi_mat->vmgi_last_sector);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
341 assert(vmgi_mat->vmgm_c_adt <= vmgi_mat->vmgi_last_sector);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
342 assert(vmgi_mat->vmgm_vobu_admap <= vmgi_mat->vmgi_last_sector);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
343
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
344 assert(vmgi_mat->nr_of_vmgm_audio_streams <= 1);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
345 assert(vmgi_mat->nr_of_vmgm_subp_streams <= 1);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
346
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
347 return 1;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
348 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
349
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
350
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
351 static int ifoRead_VTS(ifo_handle_t *ifofile) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
352 vtsi_mat_t *vtsi_mat;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
353 int i;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
354
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
355 vtsi_mat = (vtsi_mat_t *)malloc(sizeof(vtsi_mat_t));
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
356 if(!vtsi_mat)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
357 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
358
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
359 ifofile->vtsi_mat = vtsi_mat;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
360
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
361 if(!DVDFileSeek_(ifofile->file, 0)) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
362 free(ifofile->vtsi_mat);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
363 ifofile->vtsi_mat = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
364 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
365 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
366
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
367 if(!(DVDReadBytes(ifofile->file, vtsi_mat, sizeof(vtsi_mat_t)))) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
368 free(ifofile->vtsi_mat);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
369 ifofile->vtsi_mat = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
370 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
371 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
372
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
373 if(strncmp("DVDVIDEO-VTS", vtsi_mat->vts_identifier, 12) != 0) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
374 free(ifofile->vtsi_mat);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
375 ifofile->vtsi_mat = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
376 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
377 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
378
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
379 B2N_32(vtsi_mat->vts_last_sector);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
380 B2N_32(vtsi_mat->vtsi_last_sector);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
381 B2N_32(vtsi_mat->vts_category);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
382 B2N_32(vtsi_mat->vtsi_last_byte);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
383 B2N_32(vtsi_mat->vtsm_vobs);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
384 B2N_32(vtsi_mat->vtstt_vobs);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
385 B2N_32(vtsi_mat->vts_ptt_srpt);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
386 B2N_32(vtsi_mat->vts_pgcit);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
387 B2N_32(vtsi_mat->vtsm_pgci_ut);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
388 B2N_32(vtsi_mat->vts_tmapt);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
389 B2N_32(vtsi_mat->vtsm_c_adt);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
390 B2N_32(vtsi_mat->vtsm_vobu_admap);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
391 B2N_32(vtsi_mat->vts_c_adt);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
392 B2N_32(vtsi_mat->vts_vobu_admap);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
393 B2N_16(vtsi_mat->vtsm_audio_attr.lang_code);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
394 B2N_16(vtsi_mat->vtsm_subp_attr.lang_code);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
395 for(i = 0; i < 8; i++)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
396 B2N_16(vtsi_mat->vts_audio_attr[i].lang_code);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
397 for(i = 0; i < 32; i++)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
398 B2N_16(vtsi_mat->vts_subp_attr[i].lang_code);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
399
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
400
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
401 CHECK_ZERO(vtsi_mat->zero_1);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
402 CHECK_ZERO(vtsi_mat->zero_2);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
403 CHECK_ZERO(vtsi_mat->zero_3);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
404 CHECK_ZERO(vtsi_mat->zero_4);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
405 CHECK_ZERO(vtsi_mat->zero_5);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
406 CHECK_ZERO(vtsi_mat->zero_6);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
407 CHECK_ZERO(vtsi_mat->zero_7);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
408 CHECK_ZERO(vtsi_mat->zero_8);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
409 CHECK_ZERO(vtsi_mat->zero_9);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
410 CHECK_ZERO(vtsi_mat->zero_10);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
411 CHECK_ZERO(vtsi_mat->zero_11);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
412 CHECK_ZERO(vtsi_mat->zero_12);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
413 CHECK_ZERO(vtsi_mat->zero_13);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
414 CHECK_ZERO(vtsi_mat->zero_14);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
415 CHECK_ZERO(vtsi_mat->zero_15);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
416 CHECK_ZERO(vtsi_mat->zero_16);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
417 CHECK_ZERO(vtsi_mat->zero_17);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
418 CHECK_ZERO(vtsi_mat->zero_18);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
419 CHECK_ZERO(vtsi_mat->zero_19);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
420 CHECK_ZERO(vtsi_mat->zero_20);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
421 assert(vtsi_mat->vtsi_last_sector*2 <= vtsi_mat->vts_last_sector);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
422 assert(vtsi_mat->vtsi_last_byte/DVD_BLOCK_LEN <= vtsi_mat->vtsi_last_sector);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
423 assert(vtsi_mat->vtsm_vobs == 0 ||
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
424 (vtsi_mat->vtsm_vobs > vtsi_mat->vtsi_last_sector &&
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
425 vtsi_mat->vtsm_vobs < vtsi_mat->vts_last_sector));
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
426 assert(vtsi_mat->vtstt_vobs == 0 ||
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
427 (vtsi_mat->vtstt_vobs > vtsi_mat->vtsi_last_sector &&
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
428 vtsi_mat->vtstt_vobs < vtsi_mat->vts_last_sector));
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
429 assert(vtsi_mat->vts_ptt_srpt <= vtsi_mat->vtsi_last_sector);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
430 assert(vtsi_mat->vts_pgcit <= vtsi_mat->vtsi_last_sector);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
431 assert(vtsi_mat->vtsm_pgci_ut <= vtsi_mat->vtsi_last_sector);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
432 assert(vtsi_mat->vts_tmapt <= vtsi_mat->vtsi_last_sector);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
433 assert(vtsi_mat->vtsm_c_adt <= vtsi_mat->vtsi_last_sector);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
434 assert(vtsi_mat->vtsm_vobu_admap <= vtsi_mat->vtsi_last_sector);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
435 assert(vtsi_mat->vts_c_adt <= vtsi_mat->vtsi_last_sector);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
436 assert(vtsi_mat->vts_vobu_admap <= vtsi_mat->vtsi_last_sector);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
437
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
438 assert(vtsi_mat->nr_of_vtsm_audio_streams <= 1);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
439 assert(vtsi_mat->nr_of_vtsm_subp_streams <= 1);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
440
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
441 assert(vtsi_mat->nr_of_vts_audio_streams <= 8);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
442 for(i = vtsi_mat->nr_of_vts_audio_streams; i < 8; i++)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
443 CHECK_ZERO(vtsi_mat->vts_audio_attr[i]);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
444
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
445 assert(vtsi_mat->nr_of_vts_subp_streams <= 32);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
446 for(i = vtsi_mat->nr_of_vts_subp_streams; i < 32; i++)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
447 CHECK_ZERO(vtsi_mat->vts_subp_attr[i]);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
448
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
449 return 1;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
450 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
451
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
452
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
453 static int ifoRead_PGC_COMMAND_TBL(ifo_handle_t *ifofile,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
454 pgc_command_tbl_t *cmd_tbl,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
455 unsigned int offset) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
456
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
457 memset(cmd_tbl, 0, sizeof(pgc_command_tbl_t));
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
458
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
459 if(!DVDFileSeek_(ifofile->file, offset))
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
460 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
461
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
462 if(!(DVDReadBytes(ifofile->file, cmd_tbl, PGC_COMMAND_TBL_SIZE)))
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
463 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
464
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
465 B2N_16(cmd_tbl->nr_of_pre);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
466 B2N_16(cmd_tbl->nr_of_post);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
467 B2N_16(cmd_tbl->nr_of_cell);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
468
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
469 assert(cmd_tbl->nr_of_pre + cmd_tbl->nr_of_post + cmd_tbl->nr_of_cell<= 255);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
470
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
471 if(cmd_tbl->nr_of_pre != 0) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
472 unsigned int pre_cmds_size = cmd_tbl->nr_of_pre * COMMAND_DATA_SIZE;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
473 cmd_tbl->pre_cmds = (vm_cmd_t *)malloc(pre_cmds_size);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
474 if(!cmd_tbl->pre_cmds)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
475 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
476
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
477 if(!(DVDReadBytes(ifofile->file, cmd_tbl->pre_cmds, pre_cmds_size))) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
478 free(cmd_tbl->pre_cmds);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
479 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
480 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
481 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
482
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
483 if(cmd_tbl->nr_of_post != 0) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
484 unsigned int post_cmds_size = cmd_tbl->nr_of_post * COMMAND_DATA_SIZE;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
485 cmd_tbl->post_cmds = (vm_cmd_t *)malloc(post_cmds_size);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
486 if(!cmd_tbl->post_cmds) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
487 if(cmd_tbl->pre_cmds)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
488 free(cmd_tbl->pre_cmds);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
489 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
490 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
491 if(!(DVDReadBytes(ifofile->file, cmd_tbl->post_cmds, post_cmds_size))) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
492 if(cmd_tbl->pre_cmds)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
493 free(cmd_tbl->pre_cmds);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
494 free(cmd_tbl->post_cmds);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
495 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
496 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
497 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
498
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
499 if(cmd_tbl->nr_of_cell != 0) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
500 unsigned int cell_cmds_size = cmd_tbl->nr_of_cell * COMMAND_DATA_SIZE;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
501 cmd_tbl->cell_cmds = (vm_cmd_t *)malloc(cell_cmds_size);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
502 if(!cmd_tbl->cell_cmds) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
503 if(cmd_tbl->pre_cmds)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
504 free(cmd_tbl->pre_cmds);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
505 if(cmd_tbl->post_cmds)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
506 free(cmd_tbl->post_cmds);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
507 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
508 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
509 if(!(DVDReadBytes(ifofile->file, cmd_tbl->cell_cmds, cell_cmds_size))) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
510 if(cmd_tbl->pre_cmds)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
511 free(cmd_tbl->pre_cmds);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
512 if(cmd_tbl->post_cmds)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
513 free(cmd_tbl->post_cmds);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
514 free(cmd_tbl->cell_cmds);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
515 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
516 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
517 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
518
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
519 /*
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
520 * Make a run over all the commands and see that we can interpret them all?
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
521 */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
522 return 1;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
523 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
524
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
525
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
526 static void ifoFree_PGC_COMMAND_TBL(pgc_command_tbl_t *cmd_tbl) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
527 if(cmd_tbl) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
528 if(cmd_tbl->nr_of_pre && cmd_tbl->pre_cmds)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
529 free(cmd_tbl->pre_cmds);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
530 if(cmd_tbl->nr_of_post && cmd_tbl->post_cmds)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
531 free(cmd_tbl->post_cmds);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
532 if(cmd_tbl->nr_of_cell && cmd_tbl->cell_cmds)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
533 free(cmd_tbl->cell_cmds);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
534 free(cmd_tbl);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
535 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
536 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
537
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
538 static int ifoRead_PGC_PROGRAM_MAP(ifo_handle_t *ifofile,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
539 pgc_program_map_t *program_map,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
540 unsigned int nr, unsigned int offset) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
541 unsigned int size = nr * sizeof(pgc_program_map_t);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
542
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
543 if(!DVDFileSeek_(ifofile->file, offset))
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
544 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
545
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
546 if(!(DVDReadBytes(ifofile->file, program_map, size)))
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
547 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
548
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
549 return 1;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
550 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
551
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
552 static int ifoRead_CELL_PLAYBACK_TBL(ifo_handle_t *ifofile,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
553 cell_playback_t *cell_playback,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
554 unsigned int nr, unsigned int offset) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
555 unsigned int i;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
556 unsigned int size = nr * sizeof(cell_playback_t);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
557
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
558 if(!DVDFileSeek_(ifofile->file, offset))
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
559 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
560
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
561 if(!(DVDReadBytes(ifofile->file, cell_playback, size)))
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
562 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
563
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
564 for(i = 0; i < nr; i++) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
565 B2N_32(cell_playback[i].first_sector);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
566 B2N_32(cell_playback[i].first_ilvu_end_sector);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
567 B2N_32(cell_playback[i].last_vobu_start_sector);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
568 B2N_32(cell_playback[i].last_sector);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
569
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
570 /* Changed < to <= because this was false in the movie 'Pi'. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
571 assert(cell_playback[i].last_vobu_start_sector <=
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
572 cell_playback[i].last_sector);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
573 assert(cell_playback[i].first_sector <=
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
574 cell_playback[i].last_vobu_start_sector);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
575 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
576
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
577 return 1;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
578 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
579
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
580
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
581 static int ifoRead_CELL_POSITION_TBL(ifo_handle_t *ifofile,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
582 cell_position_t *cell_position,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
583 unsigned int nr, unsigned int offset) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
584 unsigned int i;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
585 unsigned int size = nr * sizeof(cell_position_t);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
586
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
587 if(!DVDFileSeek_(ifofile->file, offset))
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
588 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
589
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
590 if(!(DVDReadBytes(ifofile->file, cell_position, size)))
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
591 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
592
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
593 for(i = 0; i < nr; i++) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
594 B2N_16(cell_position[i].vob_id_nr);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
595 CHECK_ZERO(cell_position[i].zero_1);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
596 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
597
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
598 return 1;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
599 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
600
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
601 static int ifoRead_PGC(ifo_handle_t *ifofile, pgc_t *pgc, unsigned int offset) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
602 unsigned int i;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
603
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
604 if(!DVDFileSeek_(ifofile->file, offset))
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
605 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
606
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
607 if(!(DVDReadBytes(ifofile->file, pgc, PGC_SIZE)))
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
608 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
609
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
610 B2N_16(pgc->next_pgc_nr);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
611 B2N_16(pgc->prev_pgc_nr);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
612 B2N_16(pgc->goup_pgc_nr);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
613 B2N_16(pgc->command_tbl_offset);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
614 B2N_16(pgc->program_map_offset);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
615 B2N_16(pgc->cell_playback_offset);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
616 B2N_16(pgc->cell_position_offset);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
617
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
618 for(i = 0; i < 8; i++)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
619 B2N_16(pgc->audio_control[i]);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
620 for(i = 0; i < 32; i++)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
621 B2N_32(pgc->subp_control[i]);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
622 for(i = 0; i < 16; i++)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
623 B2N_32(pgc->palette[i]);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
624
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
625 CHECK_ZERO(pgc->zero_1);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
626 assert(pgc->nr_of_programs <= pgc->nr_of_cells);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
627
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
628 /* verify time (look at print_time) */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
629 for(i = 0; i < 8; i++)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
630 if(!pgc->audio_control[i] & 0x8000) /* The 'is present' bit */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
631 CHECK_ZERO(pgc->audio_control[i]);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
632 for(i = 0; i < 32; i++)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
633 if(!pgc->subp_control[i] & 0x80000000) /* The 'is present' bit */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
634 CHECK_ZERO(pgc->subp_control[i]);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
635
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
636 /* Check that time is 0:0:0:0 also if nr_of_programs == 0 */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
637 if(pgc->nr_of_programs == 0) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
638 CHECK_ZERO(pgc->still_time);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
639 CHECK_ZERO(pgc->pg_playback_mode); // ??
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
640 assert(pgc->program_map_offset == 0);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
641 assert(pgc->cell_playback_offset == 0);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
642 assert(pgc->cell_position_offset == 0);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
643 } else {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
644 assert(pgc->program_map_offset != 0);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
645 assert(pgc->cell_playback_offset != 0);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
646 assert(pgc->cell_position_offset != 0);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
647 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
648
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
649 if(pgc->command_tbl_offset != 0) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
650 pgc->command_tbl = malloc(sizeof(pgc_command_tbl_t));
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
651 if(!pgc->command_tbl)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
652 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
653
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
654 if(!ifoRead_PGC_COMMAND_TBL(ifofile, pgc->command_tbl,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
655 offset + pgc->command_tbl_offset)) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
656 free(pgc->command_tbl);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
657 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
658 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
659 } else {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
660 pgc->command_tbl = NULL;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
661 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
662
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
663 if(pgc->program_map_offset != 0) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
664 pgc->program_map = malloc(pgc->nr_of_programs * sizeof(pgc_program_map_t));
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
665 if(!pgc->program_map) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
666 ifoFree_PGC_COMMAND_TBL(pgc->command_tbl);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
667 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
668 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
669 if(!ifoRead_PGC_PROGRAM_MAP(ifofile, pgc->program_map,pgc->nr_of_programs,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
670 offset + pgc->program_map_offset)) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
671 ifoFree_PGC_COMMAND_TBL(pgc->command_tbl);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
672 free(pgc->program_map);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
673 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
674 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
675 } else {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
676 pgc->program_map = NULL;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
677 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
678
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
679 if(pgc->cell_playback_offset != 0) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
680 pgc->cell_playback = malloc(pgc->nr_of_cells * sizeof(cell_playback_t));
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
681 if(!pgc->cell_playback) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
682 ifoFree_PGC_COMMAND_TBL(pgc->command_tbl);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
683 if(pgc->program_map)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
684 free(pgc->program_map);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
685 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
686 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
687 if(!ifoRead_CELL_PLAYBACK_TBL(ifofile, pgc->cell_playback,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
688 pgc->nr_of_cells,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
689 offset + pgc->cell_playback_offset)) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
690 ifoFree_PGC_COMMAND_TBL(pgc->command_tbl);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
691 if(pgc->program_map)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
692 free(pgc->program_map);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
693 free(pgc->cell_playback);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
694 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
695 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
696 } else {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
697 pgc->cell_playback = NULL;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
698 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
699
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
700 if(pgc->cell_position_offset != 0) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
701 pgc->cell_position = malloc(pgc->nr_of_cells * sizeof(cell_position_t));
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
702 if(!pgc->cell_position) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
703 ifoFree_PGC(pgc);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
704 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
705 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
706 if(!ifoRead_CELL_POSITION_TBL(ifofile, pgc->cell_position,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
707 pgc->nr_of_cells,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
708 offset + pgc->cell_position_offset)) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
709 ifoFree_PGC(pgc);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
710 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
711 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
712 } else {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
713 pgc->cell_position = NULL;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
714 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
715
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
716 return 1;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
717 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
718
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
719 int ifoRead_FP_PGC(ifo_handle_t *ifofile) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
720
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
721 if(!ifofile)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
722 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
723
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
724 if(!ifofile->vmgi_mat)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
725 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
726
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
727 /* It seems that first_play_pgc might be optional after all. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
728 if(ifofile->vmgi_mat->first_play_pgc == 0) { /* mandatory */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
729 ifofile->first_play_pgc = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
730 return 0; /* change this to a 1 if it's optional. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
731 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
732
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
733 ifofile->first_play_pgc = (pgc_t *)malloc(sizeof(pgc_t));
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
734 if(!ifofile->first_play_pgc)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
735 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
736
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
737 if(!ifoRead_PGC(ifofile, ifofile->first_play_pgc,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
738 ifofile->vmgi_mat->first_play_pgc)) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
739 free(ifofile->first_play_pgc);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
740 ifofile->first_play_pgc = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
741 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
742 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
743
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
744 return 1;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
745 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
746
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
747 static void ifoFree_PGC(pgc_t *pgc) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
748 if(pgc) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
749 ifoFree_PGC_COMMAND_TBL(pgc->command_tbl);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
750 if(pgc->program_map)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
751 free(pgc->program_map);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
752 if(pgc->cell_playback)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
753 free(pgc->cell_playback);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
754 if(pgc->cell_position)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
755 free(pgc->cell_position);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
756 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
757 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
758
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
759 void ifoFree_FP_PGC(ifo_handle_t *ifofile) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
760 if(!ifofile)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
761 return;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
762
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
763 if(ifofile->first_play_pgc) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
764 ifoFree_PGC(ifofile->first_play_pgc);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
765 free(ifofile->first_play_pgc);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
766 ifofile->first_play_pgc = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
767 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
768 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
769
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
770
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
771 int ifoRead_TT_SRPT(ifo_handle_t *ifofile) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
772 tt_srpt_t *tt_srpt;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
773 int i, info_length;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
774
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
775 if(!ifofile)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
776 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
777
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
778 if(!ifofile->vmgi_mat)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
779 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
780
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
781 if(ifofile->vmgi_mat->tt_srpt == 0) /* mandatory */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
782 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
783
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
784 if(!DVDFileSeek_(ifofile->file, ifofile->vmgi_mat->tt_srpt * DVD_BLOCK_LEN))
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
785 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
786
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
787 tt_srpt = (tt_srpt_t *)malloc(sizeof(tt_srpt_t));
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
788 if(!tt_srpt)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
789 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
790
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
791 ifofile->tt_srpt = tt_srpt;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
792
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
793 if(!(DVDReadBytes(ifofile->file, tt_srpt, TT_SRPT_SIZE))) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
794 fprintf(stderr, "libdvdread: Unable to read read TT_SRPT.\n");
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
795 free(tt_srpt);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
796 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
797 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
798
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
799 B2N_16(tt_srpt->nr_of_srpts);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
800 B2N_32(tt_srpt->last_byte);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
801
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
802 info_length = tt_srpt->last_byte + 1 - TT_SRPT_SIZE;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
803
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
804 tt_srpt->title = (title_info_t *)malloc(info_length);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
805 if(!tt_srpt->title) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
806 free(tt_srpt);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
807 ifofile->tt_srpt = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
808 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
809 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
810 if(!(DVDReadBytes(ifofile->file, tt_srpt->title, info_length))) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
811 fprintf(stderr, "libdvdread: Unable to read read TT_SRPT.\n");
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
812 ifoFree_TT_SRPT(ifofile);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
813 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
814 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
815
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
816 for(i = 0; i < tt_srpt->nr_of_srpts; i++) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
817 B2N_16(tt_srpt->title[i].nr_of_ptts);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
818 B2N_16(tt_srpt->title[i].parental_id);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
819 B2N_32(tt_srpt->title[i].title_set_sector);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
820 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
821
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
822
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
823 CHECK_ZERO(tt_srpt->zero_1);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
824 assert(tt_srpt->nr_of_srpts != 0);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
825 assert(tt_srpt->nr_of_srpts < 100); // ??
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
826 assert((int)tt_srpt->nr_of_srpts * sizeof(title_info_t) <= info_length);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
827
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
828 for(i = 0; i < tt_srpt->nr_of_srpts; i++) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
829 assert(tt_srpt->title[i].pb_ty.zero_1 == 0);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
830 assert(tt_srpt->title[i].nr_of_angles != 0);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
831 assert(tt_srpt->title[i].nr_of_angles < 10);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
832 //assert(tt_srpt->title[i].nr_of_ptts != 0);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
833 // XXX: this assertion breaks Ghostbusters:
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
834 assert(tt_srpt->title[i].nr_of_ptts < 1000); // ??
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
835 assert(tt_srpt->title[i].title_set_nr != 0);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
836 assert(tt_srpt->title[i].title_set_nr < 100); // ??
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
837 assert(tt_srpt->title[i].vts_ttn != 0);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
838 assert(tt_srpt->title[i].vts_ttn < 100); // ??
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
839 //assert(tt_srpt->title[i].title_set_sector != 0);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
840 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
841
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
842 // Make this a function
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
843 #if 0
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
844 if(memcmp((uint8_t *)tt_srpt->title +
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
845 tt_srpt->nr_of_srpts * sizeof(title_info_t),
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
846 my_friendly_zeros,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
847 info_length - tt_srpt->nr_of_srpts * sizeof(title_info_t))) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
848 fprintf(stderr, "VMG_PTT_SRPT slack is != 0, ");
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
849 hexdump((uint8_t *)tt_srpt->title +
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
850 tt_srpt->nr_of_srpts * sizeof(title_info_t),
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
851 info_length - tt_srpt->nr_of_srpts * sizeof(title_info_t));
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
852 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
853 #endif
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
854
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
855 return 1;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
856 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
857
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
858
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
859 void ifoFree_TT_SRPT(ifo_handle_t *ifofile) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
860 if(!ifofile)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
861 return;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
862
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
863 if(ifofile->tt_srpt) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
864 free(ifofile->tt_srpt->title);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
865 free(ifofile->tt_srpt);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
866 ifofile->tt_srpt = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
867 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
868 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
869
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
870
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
871 int ifoRead_VTS_PTT_SRPT(ifo_handle_t *ifofile) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
872 vts_ptt_srpt_t *vts_ptt_srpt;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
873 int info_length, i, j;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
874 uint32_t *data;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
875
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
876 if(!ifofile)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
877 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
878
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
879 if(!ifofile->vtsi_mat)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
880 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
881
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
882 if(ifofile->vtsi_mat->vts_ptt_srpt == 0) /* mandatory */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
883 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
884
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
885 if(!DVDFileSeek_(ifofile->file,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
886 ifofile->vtsi_mat->vts_ptt_srpt * DVD_BLOCK_LEN))
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
887 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
888
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
889 vts_ptt_srpt = (vts_ptt_srpt_t *)malloc(sizeof(vts_ptt_srpt_t));
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
890 if(!vts_ptt_srpt)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
891 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
892
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
893 ifofile->vts_ptt_srpt = vts_ptt_srpt;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
894
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
895 if(!(DVDReadBytes(ifofile->file, vts_ptt_srpt, VTS_PTT_SRPT_SIZE))) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
896 fprintf(stderr, "libdvdread: Unable to read PTT search table.\n");
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
897 free(vts_ptt_srpt);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
898 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
899 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
900
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
901 B2N_16(vts_ptt_srpt->nr_of_srpts);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
902 B2N_32(vts_ptt_srpt->last_byte);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
903
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
904 CHECK_ZERO(vts_ptt_srpt->zero_1);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
905 assert(vts_ptt_srpt->nr_of_srpts != 0);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
906 assert(vts_ptt_srpt->nr_of_srpts < 100); // ??
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
907
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
908 info_length = vts_ptt_srpt->last_byte + 1 - VTS_PTT_SRPT_SIZE;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
909
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
910 data = (uint32_t *)malloc(info_length);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
911 if(!data) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
912 free(vts_ptt_srpt);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
913 ifofile->vts_ptt_srpt = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
914 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
915 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
916 if(!(DVDReadBytes(ifofile->file, data, info_length))) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
917 fprintf(stderr, "libdvdread: Unable to read PTT search table.\n");
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
918 free(vts_ptt_srpt);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
919 free(data);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
920 ifofile->vts_ptt_srpt = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
921 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
922 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
923
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
924 for(i = 0; i < vts_ptt_srpt->nr_of_srpts; i++) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
925 B2N_32(data[i]);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
926 /* assert(data[i] + sizeof(ptt_info_t) <= vts_ptt_srpt->last_byte + 1);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
927 Magic Knight Rayearth Daybreak is mastered very strange and has
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
928 Titles with 0 PTTs. They all have a data[i] offsets beyond the end of
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
929 of the vts_ptt_srpt structure. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
930 assert(data[i] + sizeof(ptt_info_t) <= vts_ptt_srpt->last_byte + 1 + 4);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
931 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
932
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
933 vts_ptt_srpt->title = malloc(vts_ptt_srpt->nr_of_srpts * sizeof(ttu_t));
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
934 if(!vts_ptt_srpt->title) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
935 free(vts_ptt_srpt);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
936 free(data);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
937 ifofile->vts_ptt_srpt = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
938 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
939 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
940 for(i = 0; i < vts_ptt_srpt->nr_of_srpts; i++) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
941 int n;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
942 if(i < vts_ptt_srpt->nr_of_srpts - 1)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
943 n = (data[i+1] - data[i]);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
944 else
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
945 n = (vts_ptt_srpt->last_byte + 1 - data[i]);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
946 /* assert(n > 0 && (n % 4) == 0);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
947 Magic Knight Rayearth Daybreak is mastered very strange and has
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
948 Titles with 0 PTTs. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
949 if(n < 0) n = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
950 assert(n % 4 == 0);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
951
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
952 vts_ptt_srpt->title[i].nr_of_ptts = n / 4;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
953 vts_ptt_srpt->title[i].ptt = malloc(n * sizeof(ptt_info_t));
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
954 if(!vts_ptt_srpt->title[i].ptt) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
955 for(n = 0; n < i; n++)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
956 free(vts_ptt_srpt->title[n].ptt);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
957 free(vts_ptt_srpt);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
958 free(data);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
959 ifofile->vts_ptt_srpt = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
960 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
961 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
962 for(j = 0; j < vts_ptt_srpt->title[i].nr_of_ptts; j++) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
963 /* The assert placed here because of Magic Knight Rayearth Daybreak */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
964 assert(data[i] + sizeof(ptt_info_t) <= vts_ptt_srpt->last_byte + 1);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
965 vts_ptt_srpt->title[i].ptt[j].pgcn
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
966 = *(uint16_t*)(((char *)data) + data[i] + 4*j - VTS_PTT_SRPT_SIZE);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
967 vts_ptt_srpt->title[i].ptt[j].pgn
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
968 = *(uint16_t*)(((char *)data) + data[i] + 4*j + 2 - VTS_PTT_SRPT_SIZE);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
969 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
970 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
971 free(data);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
972
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
973 for(i = 0; i < vts_ptt_srpt->nr_of_srpts; i++) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
974 for(j = 0; j < vts_ptt_srpt->title[i].nr_of_ptts; j++) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
975 B2N_16(vts_ptt_srpt->title[i].ptt[j].pgcn);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
976 B2N_16(vts_ptt_srpt->title[i].ptt[j].pgn);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
977 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
978 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
979
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
980 for(i = 0; i < vts_ptt_srpt->nr_of_srpts; i++) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
981 assert(vts_ptt_srpt->title[i].nr_of_ptts < 1000); // ??
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
982 for(j = 0; j < vts_ptt_srpt->title[i].nr_of_ptts; j++) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
983 assert(vts_ptt_srpt->title[i].ptt[j].pgcn != 0 );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
984 assert(vts_ptt_srpt->title[i].ptt[j].pgcn < 1000); // ??
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
985 assert(vts_ptt_srpt->title[i].ptt[j].pgn != 0);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
986 assert(vts_ptt_srpt->title[i].ptt[j].pgn < 100); // ??
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
987 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
988 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
989
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
990 return 1;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
991 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
992
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
993
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
994 void ifoFree_VTS_PTT_SRPT(ifo_handle_t *ifofile) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
995 if(!ifofile)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
996 return;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
997
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
998 if(ifofile->vts_ptt_srpt) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
999 int i;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1000 for(i = 0; i < ifofile->vts_ptt_srpt->nr_of_srpts; i++)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1001 free(ifofile->vts_ptt_srpt->title[i].ptt);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1002 free(ifofile->vts_ptt_srpt->title);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1003 free(ifofile->vts_ptt_srpt);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1004 ifofile->vts_ptt_srpt = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1005 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1006 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1007
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1008
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1009 int ifoRead_PTL_MAIT(ifo_handle_t *ifofile) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1010 ptl_mait_t *ptl_mait;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1011 int info_length;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1012 unsigned int i;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1013
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1014 if(!ifofile)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1015 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1016
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1017 if(!ifofile->vmgi_mat)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1018 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1019
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1020 if(ifofile->vmgi_mat->ptl_mait == 0)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1021 return 1;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1022
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1023 if(!DVDFileSeek_(ifofile->file,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1024 ifofile->vmgi_mat->ptl_mait * DVD_BLOCK_LEN))
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1025 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1026
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1027 ptl_mait = (ptl_mait_t *)malloc(sizeof(ptl_mait_t));
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1028 if(!ptl_mait)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1029 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1030
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1031 ifofile->ptl_mait = ptl_mait;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1032
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1033 if(!(DVDReadBytes(ifofile->file, ptl_mait, PTL_MAIT_SIZE))) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1034 free(ptl_mait);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1035 ifofile->ptl_mait = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1036 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1037 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1038
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1039 B2N_16(ptl_mait->nr_of_countries);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1040 B2N_16(ptl_mait->nr_of_vtss);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1041 B2N_32(ptl_mait->last_byte);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1042
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1043 info_length = ptl_mait->last_byte + 1 - PTL_MAIT_SIZE;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1044
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1045 assert(ptl_mait->nr_of_countries != 0);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1046 assert(ptl_mait->nr_of_countries < 100); // ??
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1047 assert(ptl_mait->nr_of_vtss != 0);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1048 assert(ptl_mait->nr_of_vtss < 100); // ??
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1049 assert(ptl_mait->nr_of_countries * PTL_MAIT_COUNTRY_SIZE <= info_length);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1050
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1051 /* Change this to read and 'translate' the tables too.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1052 I.e don't read so much here */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1053 ptl_mait->countries = (ptl_mait_country_t *)malloc(info_length);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1054 if(!ptl_mait->countries) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1055 free(ptl_mait);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1056 ifofile->ptl_mait = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1057 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1058 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1059 if(!(DVDReadBytes(ifofile->file, ptl_mait->countries, info_length))) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1060 fprintf(stderr, "libdvdread: Unable to read PTL_MAIT.\n");
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1061 ifoFree_PTL_MAIT(ifofile);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1062 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1063 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1064
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1065 for(i = 0; i < ptl_mait->nr_of_countries; i++) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1066 B2N_16(ptl_mait->countries[i].country_code);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1067 B2N_16(ptl_mait->countries[i].pf_ptl_mai_start_byte);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1068 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1069
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1070 for(i = 0; i < ptl_mait->nr_of_countries; i++) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1071 CHECK_ZERO(ptl_mait->countries[i].zero_1);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1072 CHECK_ZERO(ptl_mait->countries[i].zero_2);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1073 assert(ptl_mait->countries[i].pf_ptl_mai_start_byte +
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1074 8 * (ptl_mait->nr_of_vtss + 1) * 2 <= ptl_mait->last_byte + 1);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1075 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1076
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1077 return 1;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1078 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1079
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1080
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1081 void ifoFree_PTL_MAIT(ifo_handle_t *ifofile) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1082 if(!ifofile)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1083 return;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1084
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1085 if(ifofile->ptl_mait) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1086 free(ifofile->ptl_mait->countries);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1087 free(ifofile->ptl_mait);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1088 ifofile->ptl_mait = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1089 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1090 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1091
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1092 int ifoRead_TITLE_C_ADT(ifo_handle_t *ifofile) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1093
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1094 if(!ifofile)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1095 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1096
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1097 if(!ifofile->vtsi_mat)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1098 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1099
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1100 if(ifofile->vtsi_mat->vts_c_adt == 0) /* mandatory */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1101 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1102
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1103 ifofile->vts_c_adt = (c_adt_t *)malloc(sizeof(c_adt_t));
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1104 if(!ifofile->vts_c_adt)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1105 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1106
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1107 if(!ifoRead_C_ADT_internal(ifofile, ifofile->vts_c_adt,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1108 ifofile->vtsi_mat->vts_c_adt)) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1109 free(ifofile->vts_c_adt);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1110 ifofile->vts_c_adt = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1111 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1112 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1113
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1114 return 1;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1115 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1116
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1117 int ifoRead_C_ADT(ifo_handle_t *ifofile) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1118 unsigned int sector;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1119
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1120 if(!ifofile)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1121 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1122
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1123 if(ifofile->vmgi_mat) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1124 if(ifofile->vmgi_mat->vmgm_c_adt == 0)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1125 return 1;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1126 sector = ifofile->vmgi_mat->vmgm_c_adt;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1127 } else if(ifofile->vtsi_mat) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1128 if(ifofile->vtsi_mat->vtsm_c_adt == 0)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1129 return 1;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1130 sector = ifofile->vtsi_mat->vtsm_c_adt;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1131 } else {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1132 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1133 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1134
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1135 ifofile->menu_c_adt = (c_adt_t *)malloc(sizeof(c_adt_t));
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1136 if(!ifofile->menu_c_adt)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1137 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1138
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1139 if(!ifoRead_C_ADT_internal(ifofile, ifofile->menu_c_adt, sector)) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1140 free(ifofile->menu_c_adt);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1141 ifofile->menu_c_adt = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1142 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1143 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1144
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1145 return 1;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1146 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1147
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1148 static int ifoRead_C_ADT_internal(ifo_handle_t *ifofile,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1149 c_adt_t *c_adt, unsigned int sector) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1150 int i, info_length;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1151
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1152 if(!DVDFileSeek_(ifofile->file, sector * DVD_BLOCK_LEN))
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1153 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1154
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1155 if(!(DVDReadBytes(ifofile->file, c_adt, C_ADT_SIZE)))
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1156 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1157
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1158 B2N_16(c_adt->nr_of_vobs);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1159 B2N_32(c_adt->last_byte);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1160
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1161 info_length = c_adt->last_byte + 1 - C_ADT_SIZE;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1162
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1163 CHECK_ZERO(c_adt->zero_1);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1164 /* assert(c_adt->nr_of_vobs > 0);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1165 Magic Knight Rayearth Daybreak is mastered very strange and has
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1166 Titles with a VOBS that has no cells. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1167 assert(info_length % sizeof(cell_adr_t) == 0);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1168
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1169 /* assert(info_length / sizeof(cell_adr_t) >= c_adt->nr_of_vobs);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1170 Enemy of the State region 2 (de) has Titles where nr_of_vobs field
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1171 is to high, they high ones are never referenced though. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1172 if(info_length / sizeof(cell_adr_t) < c_adt->nr_of_vobs) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1173 fprintf(stderr, "libdvdread: *C_ADT nr_of_vobs > avaiable info entries\n");
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1174 c_adt->nr_of_vobs = info_length / sizeof(cell_adr_t);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1175 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1176
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1177 c_adt->cell_adr_table = (cell_adr_t *)malloc(info_length);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1178 if(!c_adt->cell_adr_table)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1179 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1180
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1181 if(info_length &&
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1182 !(DVDReadBytes(ifofile->file, c_adt->cell_adr_table, info_length))) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1183 free(c_adt->cell_adr_table);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1184 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1185 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1186
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1187 for(i = 0; i < info_length/sizeof(cell_adr_t); i++) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1188 B2N_16(c_adt->cell_adr_table[i].vob_id);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1189 B2N_32(c_adt->cell_adr_table[i].start_sector);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1190 B2N_32(c_adt->cell_adr_table[i].last_sector);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1191
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1192 CHECK_ZERO(c_adt->cell_adr_table[i].zero_1);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1193 assert(c_adt->cell_adr_table[i].vob_id > 0);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1194 assert(c_adt->cell_adr_table[i].vob_id <= c_adt->nr_of_vobs);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1195 assert(c_adt->cell_adr_table[i].cell_id > 0);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1196 assert(c_adt->cell_adr_table[i].start_sector <
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1197 c_adt->cell_adr_table[i].last_sector);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1198 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1199
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1200 return 1;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1201 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1202
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1203
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1204 static void ifoFree_C_ADT_internal(c_adt_t *c_adt) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1205 if(c_adt) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1206 free(c_adt->cell_adr_table);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1207 free(c_adt);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1208 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1209 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1210
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1211 void ifoFree_C_ADT(ifo_handle_t *ifofile) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1212 if(!ifofile)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1213 return;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1214
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1215 ifoFree_C_ADT_internal(ifofile->menu_c_adt);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1216 ifofile->menu_c_adt = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1217 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1218
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1219 void ifoFree_TITLE_C_ADT(ifo_handle_t *ifofile) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1220 if(!ifofile)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1221 return;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1222
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1223 ifoFree_C_ADT_internal(ifofile->vts_c_adt);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1224 ifofile->vts_c_adt = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1225 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1226
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1227 int ifoRead_TITLE_VOBU_ADMAP(ifo_handle_t *ifofile) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1228 if(!ifofile)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1229 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1230
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1231 if(!ifofile->vtsi_mat)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1232 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1233
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1234 if(ifofile->vtsi_mat->vts_vobu_admap == 0) /* mandatory */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1235 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1236
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1237 ifofile->vts_vobu_admap = (vobu_admap_t *)malloc(sizeof(vobu_admap_t));
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1238 if(!ifofile->vts_vobu_admap)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1239 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1240
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1241 if(!ifoRead_VOBU_ADMAP_internal(ifofile, ifofile->vts_vobu_admap,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1242 ifofile->vtsi_mat->vts_vobu_admap)) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1243 free(ifofile->vts_vobu_admap);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1244 ifofile->vts_vobu_admap = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1245 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1246 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1247
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1248 return 1;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1249 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1250
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1251 int ifoRead_VOBU_ADMAP(ifo_handle_t *ifofile) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1252 unsigned int sector;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1253
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1254 if(!ifofile)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1255 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1256
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1257 if(ifofile->vmgi_mat) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1258 if(ifofile->vmgi_mat->vmgm_vobu_admap == 0)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1259 return 1;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1260 sector = ifofile->vmgi_mat->vmgm_vobu_admap;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1261 } else if(ifofile->vtsi_mat) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1262 if(ifofile->vtsi_mat->vtsm_vobu_admap == 0)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1263 return 1;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1264 sector = ifofile->vtsi_mat->vtsm_vobu_admap;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1265 } else {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1266 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1267 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1268
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1269 ifofile->menu_vobu_admap = (vobu_admap_t *)malloc(sizeof(vobu_admap_t));
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1270 if(!ifofile->menu_vobu_admap)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1271 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1272
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1273 if(!ifoRead_VOBU_ADMAP_internal(ifofile, ifofile->menu_vobu_admap, sector)) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1274 free(ifofile->menu_vobu_admap);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1275 ifofile->menu_vobu_admap = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1276 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1277 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1278
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1279 return 1;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1280 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1281
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1282 static int ifoRead_VOBU_ADMAP_internal(ifo_handle_t *ifofile,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1283 vobu_admap_t *vobu_admap,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1284 unsigned int sector) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1285 unsigned int i;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1286 int info_length;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1287
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1288 if(!DVDFileSeek_(ifofile->file, sector * DVD_BLOCK_LEN))
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1289 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1290
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1291 if(!(DVDReadBytes(ifofile->file, vobu_admap, VOBU_ADMAP_SIZE)))
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1292 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1293
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1294 B2N_32(vobu_admap->last_byte);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1295
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1296 info_length = vobu_admap->last_byte + 1 - VOBU_ADMAP_SIZE;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1297 /* assert(info_length > 0);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1298 Magic Knight Rayearth Daybreak is mastered very strange and has
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1299 Titles with a VOBS that has no VOBUs. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1300 assert(info_length % sizeof(uint32_t) == 0);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1301
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1302 vobu_admap->vobu_start_sectors = (uint32_t *)malloc(info_length);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1303 if(!vobu_admap->vobu_start_sectors) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1304 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1305 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1306 if(info_length &&
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1307 !(DVDReadBytes(ifofile->file,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1308 vobu_admap->vobu_start_sectors, info_length))) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1309 free(vobu_admap->vobu_start_sectors);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1310 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1311 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1312
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1313 for(i = 0; i < info_length/sizeof(uint32_t); i++)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1314 B2N_32(vobu_admap->vobu_start_sectors[i]);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1315
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1316 return 1;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1317 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1318
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1319
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1320 static void ifoFree_VOBU_ADMAP_internal(vobu_admap_t *vobu_admap) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1321 if(vobu_admap) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1322 free(vobu_admap->vobu_start_sectors);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1323 free(vobu_admap);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1324 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1325 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1326
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1327 void ifoFree_VOBU_ADMAP(ifo_handle_t *ifofile) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1328 if(!ifofile)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1329 return;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1330
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1331 ifoFree_VOBU_ADMAP_internal(ifofile->menu_vobu_admap);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1332 ifofile->menu_vobu_admap = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1333 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1334
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1335 void ifoFree_TITLE_VOBU_ADMAP(ifo_handle_t *ifofile) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1336 if(!ifofile)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1337 return;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1338
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1339 ifoFree_VOBU_ADMAP_internal(ifofile->vts_vobu_admap);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1340 ifofile->vts_vobu_admap = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1341 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1342
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1343 int ifoRead_PGCIT(ifo_handle_t *ifofile) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1344
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1345 if(!ifofile)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1346 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1347
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1348 if(!ifofile->vtsi_mat)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1349 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1350
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1351 if(ifofile->vtsi_mat->vts_pgcit == 0) /* mandatory */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1352 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1353
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1354 ifofile->vts_pgcit = (pgcit_t *)malloc(sizeof(pgcit_t));
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1355 if(!ifofile->vts_pgcit)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1356 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1357
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1358 if(!ifoRead_PGCIT_internal(ifofile, ifofile->vts_pgcit,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1359 ifofile->vtsi_mat->vts_pgcit * DVD_BLOCK_LEN)) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1360 free(ifofile->vts_pgcit);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1361 ifofile->vts_pgcit = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1362 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1363 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1364
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1365 return 1;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1366 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1367
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1368 static int ifoRead_PGCIT_internal(ifo_handle_t *ifofile, pgcit_t *pgcit,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1369 unsigned int offset) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1370 int i, info_length;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1371 uint8_t *data, *ptr;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1372
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1373 if(!DVDFileSeek_(ifofile->file, offset))
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1374 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1375
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1376 if(!(DVDReadBytes(ifofile->file, pgcit, PGCIT_SIZE)))
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1377 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1378
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1379 B2N_16(pgcit->nr_of_pgci_srp);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1380 B2N_32(pgcit->last_byte);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1381
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1382 CHECK_ZERO(pgcit->zero_1);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1383 /* assert(pgcit->nr_of_pgci_srp != 0);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1384 Magic Knight Rayearth Daybreak is mastered very strange and has
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1385 Titles with 0 PTTs. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1386 assert(pgcit->nr_of_pgci_srp < 10000); // ?? seen max of 1338
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1387
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1388 info_length = pgcit->nr_of_pgci_srp * PGCI_SRP_SIZE;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1389 data = malloc(info_length);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1390 if(!data)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1391 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1392
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1393 if(info_length && !(DVDReadBytes(ifofile->file, data, info_length))) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1394 free(data);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1395 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1396 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1397
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1398 pgcit->pgci_srp = malloc(pgcit->nr_of_pgci_srp * sizeof(pgci_srp_t));
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1399 if(!pgcit->pgci_srp) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1400 free(data);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1401 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1402 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1403 ptr = data;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1404 for(i = 0; i < pgcit->nr_of_pgci_srp; i++) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1405 memcpy(&pgcit->pgci_srp[i], ptr, PGCI_LU_SIZE);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1406 ptr += PGCI_LU_SIZE;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1407 B2N_16(pgcit->pgci_srp[i].ptl_id_mask);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1408 B2N_32(pgcit->pgci_srp[i].pgc_start_byte);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1409 assert(pgcit->pgci_srp[i].unknown1 == 0);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1410 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1411 free(data);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1412
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1413 for(i = 0; i < pgcit->nr_of_pgci_srp; i++)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1414 assert(pgcit->pgci_srp[i].pgc_start_byte + PGC_SIZE <= pgcit->last_byte+1);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1415
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1416 for(i = 0; i < pgcit->nr_of_pgci_srp; i++) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1417 pgcit->pgci_srp[i].pgc = malloc(sizeof(pgc_t));
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1418 if(!pgcit->pgci_srp[i].pgc) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1419 int j;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1420 for(j = 0; j < i; j++) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1421 ifoFree_PGC(pgcit->pgci_srp[j].pgc);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1422 free(pgcit->pgci_srp[j].pgc);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1423 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1424 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1425 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1426 if(!ifoRead_PGC(ifofile, pgcit->pgci_srp[i].pgc,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1427 offset + pgcit->pgci_srp[i].pgc_start_byte)) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1428 int j;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1429 for(j = 0; j < i; j++) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1430 ifoFree_PGC(pgcit->pgci_srp[j].pgc);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1431 free(pgcit->pgci_srp[j].pgc);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1432 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1433 free(pgcit->pgci_srp);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1434 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1435 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1436 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1437
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1438 return 1;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1439 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1440
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1441 static void ifoFree_PGCIT_internal(pgcit_t *pgcit) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1442 if(pgcit) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1443 int i;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1444 for(i = 0; i < pgcit->nr_of_pgci_srp; i++)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1445 ifoFree_PGC(pgcit->pgci_srp[i].pgc);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1446 free(pgcit->pgci_srp);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1447 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1448 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1449
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1450 void ifoFree_PGCIT(ifo_handle_t *ifofile) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1451 if(!ifofile)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1452 return;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1453
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1454 if(ifofile->vts_pgcit) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1455 ifoFree_PGCIT_internal(ifofile->vts_pgcit);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1456 free(ifofile->vts_pgcit);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1457 ifofile->vts_pgcit = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1458 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1459 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1460
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1461
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1462 int ifoRead_PGCI_UT(ifo_handle_t *ifofile) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1463 pgci_ut_t *pgci_ut;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1464 unsigned int sector;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1465 unsigned int i;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1466 int info_length;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1467 uint8_t *data, *ptr;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1468
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1469 if(!ifofile)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1470 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1471
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1472 if(ifofile->vmgi_mat) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1473 if(ifofile->vmgi_mat->vmgm_pgci_ut == 0)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1474 return 1;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1475 sector = ifofile->vmgi_mat->vmgm_pgci_ut;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1476 } else if(ifofile->vtsi_mat) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1477 if(ifofile->vtsi_mat->vtsm_pgci_ut == 0)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1478 return 1;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1479 sector = ifofile->vtsi_mat->vtsm_pgci_ut;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1480 } else {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1481 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1482 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1483
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1484 ifofile->pgci_ut = (pgci_ut_t *)malloc(sizeof(pgci_ut_t));
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1485 if(!ifofile->pgci_ut)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1486 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1487
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1488 if(!DVDFileSeek_(ifofile->file, sector * DVD_BLOCK_LEN)) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1489 free(ifofile->pgci_ut);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1490 ifofile->pgci_ut = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1491 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1492 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1493
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1494 if(!(DVDReadBytes(ifofile->file, ifofile->pgci_ut, PGCI_UT_SIZE))) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1495 free(ifofile->pgci_ut);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1496 ifofile->pgci_ut = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1497 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1498 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1499
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1500 pgci_ut = ifofile->pgci_ut;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1501
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1502 B2N_16(pgci_ut->nr_of_lus);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1503 B2N_32(pgci_ut->last_byte);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1504
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1505 CHECK_ZERO(pgci_ut->zero_1);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1506 assert(pgci_ut->nr_of_lus != 0);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1507 assert(pgci_ut->nr_of_lus < 100); // ?? 3-4 ?
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1508 assert((uint32_t)pgci_ut->nr_of_lus * PGCI_LU_SIZE < pgci_ut->last_byte);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1509
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1510 info_length = pgci_ut->nr_of_lus * PGCI_LU_SIZE;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1511 data = malloc(info_length);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1512 if(!data) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1513 free(pgci_ut);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1514 ifofile->pgci_ut = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1515 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1516 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1517 if(!(DVDReadBytes(ifofile->file, data, info_length))) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1518 free(data);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1519 free(pgci_ut);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1520 ifofile->pgci_ut = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1521 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1522 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1523
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1524 pgci_ut->lu = malloc(pgci_ut->nr_of_lus * sizeof(pgci_lu_t));
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1525 if(!pgci_ut->lu) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1526 free(data);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1527 free(pgci_ut);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1528 ifofile->pgci_ut = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1529 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1530 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1531 ptr = data;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1532 for(i = 0; i < pgci_ut->nr_of_lus; i++) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1533 memcpy(&pgci_ut->lu[i], ptr, PGCI_LU_SIZE);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1534 ptr += PGCI_LU_SIZE;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1535 B2N_16(pgci_ut->lu[i].lang_code);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1536 B2N_32(pgci_ut->lu[i].lang_start_byte);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1537 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1538 free(data);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1539
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1540 for(i = 0; i < pgci_ut->nr_of_lus; i++) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1541 CHECK_ZERO(pgci_ut->lu[i].zero_1);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1542 // Maybe this is only defined for v1.1 and later titles?
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1543 /* If the bits in 'lu[i].exists' are enumerated abcd efgh then:
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1544 VTS_x_yy.IFO VIDEO_TS.IFO
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1545 a == 0x83 "Root" 0x82 "Title"
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1546 b == 0x84 "Subpicture"
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1547 c == 0x85 "Audio"
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1548 d == 0x86 "Angle"
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1549 e == 0x87 "PTT"
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1550 */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1551 assert((pgci_ut->lu[i].exists & 0x07) == 0);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1552 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1553
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1554 for(i = 0; i < pgci_ut->nr_of_lus; i++) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1555 pgci_ut->lu[i].pgcit = malloc(sizeof(pgcit_t));
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1556 if(!pgci_ut->lu[i].pgcit) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1557 unsigned int j;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1558 for(j = 0; j < i; j++) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1559 ifoFree_PGCIT_internal(pgci_ut->lu[j].pgcit);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1560 free(pgci_ut->lu[j].pgcit);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1561 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1562 free(pgci_ut->lu);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1563 free(pgci_ut);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1564 ifofile->pgci_ut = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1565 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1566 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1567 if(!ifoRead_PGCIT_internal(ifofile, pgci_ut->lu[i].pgcit,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1568 sector * DVD_BLOCK_LEN
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1569 + pgci_ut->lu[i].lang_start_byte)) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1570 unsigned int j;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1571 for(j = 0; j < i; j++) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1572 ifoFree_PGCIT_internal(pgci_ut->lu[j].pgcit);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1573 free(pgci_ut->lu[j].pgcit);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1574 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1575 free(pgci_ut->lu[i].pgcit);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1576 free(pgci_ut->lu);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1577 free(pgci_ut);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1578 ifofile->pgci_ut = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1579 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1580 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1581 // FIXME: Iterate and verify that all menus that should exists accordingly
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1582 // to pgci_ut->lu[i].exists really do?
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1583 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1584
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1585 return 1;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1586 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1587
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1588
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1589 void ifoFree_PGCI_UT(ifo_handle_t *ifofile) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1590 unsigned int i;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1591
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1592 if(!ifofile)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1593 return;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1594
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1595 if(ifofile->pgci_ut) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1596 for(i = 0; i < ifofile->pgci_ut->nr_of_lus; i++) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1597 ifoFree_PGCIT_internal(ifofile->pgci_ut->lu[i].pgcit);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1598 free(ifofile->pgci_ut->lu[i].pgcit);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1599 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1600 free(ifofile->pgci_ut->lu);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1601 free(ifofile->pgci_ut);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1602 ifofile->pgci_ut = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1603 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1604 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1605
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1606 static int ifoRead_VTS_ATTRIBUTES(ifo_handle_t *ifofile,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1607 vts_attributes_t *vts_attributes,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1608 unsigned int offset) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1609 unsigned int i;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1610
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1611 if(!DVDFileSeek_(ifofile->file, offset))
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1612 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1613
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1614 if(!(DVDReadBytes(ifofile->file, vts_attributes, sizeof(vts_attributes_t))))
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1615 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1616
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1617 B2N_32(vts_attributes->last_byte);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1618 B2N_32(vts_attributes->vts_cat);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1619 B2N_16(vts_attributes->vtsm_audio_attr.lang_code);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1620 B2N_16(vts_attributes->vtsm_subp_attr.lang_code);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1621 for(i = 0; i < 8; i++)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1622 B2N_16(vts_attributes->vtstt_audio_attr[i].lang_code);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1623 for(i = 0; i < 32; i++)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1624 B2N_16(vts_attributes->vtstt_subp_attr[i].lang_code);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1625
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1626 CHECK_ZERO(vts_attributes->zero_1);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1627 CHECK_ZERO(vts_attributes->zero_2);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1628 CHECK_ZERO(vts_attributes->zero_3);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1629 CHECK_ZERO(vts_attributes->zero_4);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1630 CHECK_ZERO(vts_attributes->zero_5);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1631 CHECK_ZERO(vts_attributes->zero_6);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1632 CHECK_ZERO(vts_attributes->zero_7);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1633 assert(vts_attributes->nr_of_vtsm_audio_streams <= 1);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1634 assert(vts_attributes->nr_of_vtsm_subp_streams <= 1);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1635 assert(vts_attributes->nr_of_vtstt_audio_streams <= 8);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1636 for(i = vts_attributes->nr_of_vtstt_audio_streams; i < 8; i++)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1637 CHECK_ZERO(vts_attributes->vtstt_audio_attr[i]);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1638 assert(vts_attributes->nr_of_vtstt_subp_streams <= 32);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1639 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1640 unsigned int nr_coded;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1641 assert(vts_attributes->last_byte + 1 >= VTS_ATTRIBUTES_MIN_SIZE);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1642 nr_coded = (vts_attributes->last_byte + 1 - VTS_ATTRIBUTES_MIN_SIZE)/6;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1643 // This is often nr_coded = 70, how do you know how many there really are?
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1644 if(nr_coded > 32) { // We haven't read more from disk/file anyway
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1645 nr_coded = 32;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1646 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1647 assert(vts_attributes->nr_of_vtstt_subp_streams <= nr_coded);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1648 for(i = vts_attributes->nr_of_vtstt_subp_streams; i < nr_coded; i++)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1649 CHECK_ZERO(vts_attributes->vtstt_subp_attr[i]);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1650 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1651
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1652 return 1;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1653 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1654
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1655
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1656
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1657 int ifoRead_VTS_ATRT(ifo_handle_t *ifofile) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1658 vts_atrt_t *vts_atrt;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1659 unsigned int i, info_length, sector;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1660 uint32_t *data;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1661
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1662 if(!ifofile)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1663 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1664
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1665 if(!ifofile->vmgi_mat)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1666 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1667
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1668 if(ifofile->vmgi_mat->vts_atrt == 0) /* mandatory */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1669 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1670
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1671 sector = ifofile->vmgi_mat->vts_atrt;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1672 if(!DVDFileSeek_(ifofile->file, sector * DVD_BLOCK_LEN))
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1673 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1674
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1675 vts_atrt = (vts_atrt_t *)malloc(sizeof(vts_atrt_t));
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1676 if(!vts_atrt)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1677 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1678
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1679 ifofile->vts_atrt = vts_atrt;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1680
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1681 if(!(DVDReadBytes(ifofile->file, vts_atrt, VTS_ATRT_SIZE))) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1682 free(vts_atrt);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1683 ifofile->vts_atrt = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1684 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1685 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1686
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1687 B2N_16(vts_atrt->nr_of_vtss);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1688 B2N_32(vts_atrt->last_byte);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1689
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1690 CHECK_ZERO(vts_atrt->zero_1);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1691 assert(vts_atrt->nr_of_vtss != 0);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1692 assert(vts_atrt->nr_of_vtss < 100); //??
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1693 assert((uint32_t)vts_atrt->nr_of_vtss * (4 + VTS_ATTRIBUTES_MIN_SIZE) +
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1694 VTS_ATRT_SIZE < vts_atrt->last_byte + 1);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1695
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1696 info_length = vts_atrt->nr_of_vtss * sizeof(uint32_t);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1697 data = (uint32_t *)malloc(info_length);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1698 if(!data) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1699 free(vts_atrt);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1700 ifofile->vts_atrt = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1701 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1702 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1703 if(!(DVDReadBytes(ifofile->file, data, info_length))) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1704 free(data);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1705 free(vts_atrt);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1706 ifofile->vts_atrt = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1707 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1708 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1709
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1710 for(i = 0; i < vts_atrt->nr_of_vtss; i++) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1711 B2N_32(data[i]);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1712 assert(data[i] + VTS_ATTRIBUTES_MIN_SIZE < vts_atrt->last_byte + 1);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1713 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1714
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1715 info_length = vts_atrt->nr_of_vtss * sizeof(vts_attributes_t);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1716 vts_atrt->vts = (vts_attributes_t *)malloc(info_length);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1717 if(!vts_atrt->vts) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1718 free(data);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1719 free(vts_atrt);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1720 ifofile->vts_atrt = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1721 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1722 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1723 for(i = 0; i < vts_atrt->nr_of_vtss; i++) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1724 unsigned int offset = data[i];
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1725 if(!ifoRead_VTS_ATTRIBUTES(ifofile, &(vts_atrt->vts[i]),
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1726 (sector * DVD_BLOCK_LEN) + offset)) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1727 free(data);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1728 free(vts_atrt);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1729 ifofile->vts_atrt = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1730 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1731 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1732
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1733 // This assert cant be in ifoRead_VTS_ATTRIBUTES
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1734 assert(offset + vts_atrt->vts[i].last_byte <= vts_atrt->last_byte + 1);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1735 // Is this check correct?
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1736 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1737 free(data);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1738
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1739 return 1;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1740 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1741
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1742
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1743 void ifoFree_VTS_ATRT(ifo_handle_t *ifofile) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1744 if(!ifofile)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1745 return;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1746
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1747 if(ifofile->vts_atrt) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1748 free(ifofile->vts_atrt->vts);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1749 free(ifofile->vts_atrt);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1750 ifofile->vts_atrt = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1751 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1752 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1753
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1754
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1755 int ifoRead_TXTDT_MGI(ifo_handle_t *ifofile) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1756 txtdt_mgi_t *txtdt_mgi;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1757
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1758 if(!ifofile)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1759 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1760
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1761 if(!ifofile->vmgi_mat)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1762 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1763
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1764 /* Return successfully if there is nothing to read. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1765 if(ifofile->vmgi_mat->txtdt_mgi == 0)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1766 return 1;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1767
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1768 if(!DVDFileSeek_(ifofile->file,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1769 ifofile->vmgi_mat->txtdt_mgi * DVD_BLOCK_LEN))
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1770 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1771
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1772 txtdt_mgi = (txtdt_mgi_t *)malloc(sizeof(txtdt_mgi_t));
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1773 if(!txtdt_mgi) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1774 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1775 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1776 ifofile->txtdt_mgi = txtdt_mgi;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1777
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1778 if(!(DVDReadBytes(ifofile->file, txtdt_mgi, TXTDT_MGI_SIZE))) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1779 fprintf(stderr, "libdvdread: Unable to read TXTDT_MGI.\n");
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1780 free(txtdt_mgi);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1781 ifofile->txtdt_mgi = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1782 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1783 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1784
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1785 // fprintf(stderr, "-- Not done yet --\n");
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1786 return 1;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1787 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1788
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1789 void ifoFree_TXTDT_MGI(ifo_handle_t *ifofile) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1790 if(!ifofile)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1791 return;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1792
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1793 if(ifofile->txtdt_mgi) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1794 free(ifofile->txtdt_mgi);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1795 ifofile->txtdt_mgi = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1796 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1797 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1798