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