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