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