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