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