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