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