Mercurial > libdvdread4.hg
annotate ifo_read.c @ 92:7ab44001373e src tip
Use 0 instead of NULL in integer comparison
Both GCC 4.8.2 and Clang 3.4 warn about a format mismatch in a
comparison.
libtool: compile: gcc -DHAVE_CONFIG_H -I. -I.. -I.. -I../src -mno-ms-bitfields -O3 -Wall -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOUR
CE -MT ifo_read.lo -MD -MP -MF .deps/ifo_read.Tpo -c ifo_read.c -fPIC -DPIC -o .libs/ifo_read.o
[?]
ifo_read.c: In function 'ifoRead_PTL_MAIT':
ifo_read.c:1313:34: warning: comparison between pointer and integer [enabled by default]
if(ifofile->vmgi_mat->ptl_mait == NULL)
libtool: compile: clang -DHAVE_CONFIG_H -I. -I.. -I.. -I../src -O3 -Wall -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -MT ifo_read.
lo -MD -MP -MF .deps/ifo_read.Tpo -c ifo_read.c -fPIC -DPIC -o .libs/ifo_read.o
[?]
ifo_read.c:1313:34: warning: comparison between pointer and integer ('uint32_t' (aka 'unsigned int') and 'void *')
if(ifofile->vmgi_mat->ptl_mait == NULL)
~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~
Fix this by using the integer 0 instead of `NULL`.
Patch by Paul Menzel <paulepanter AT users DOT sourceforge DOT net>
| author | rathann |
|---|---|
| date | Wed, 04 Dec 2013 22:44:23 +0000 |
| parents | 23d412d59d62 |
| children |
| rev | line source |
|---|---|
| 3 | 1 /* |
| 2 * Copyright (C) 2000, 2001, 2002, 2003 | |
| 22 | 3 * Björn Englund <d4bjorn@dtek.chalmers.se>, |
| 4 * Håkan Hjort <d95hjort@dtek.chalmers.se> | |
| 3 | 5 * |
|
21
4aa618ae094f
Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents:
20
diff
changeset
|
6 * This file is part of libdvdread. |
|
4aa618ae094f
Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents:
20
diff
changeset
|
7 * |
|
4aa618ae094f
Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents:
20
diff
changeset
|
8 * libdvdread is free software; you can redistribute it and/or modify |
| 3 | 9 * it under the terms of the GNU General Public License as published by |
| 10 * the Free Software Foundation; either version 2 of the License, or | |
| 11 * (at your option) any later version. | |
| 12 * | |
|
21
4aa618ae094f
Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents:
20
diff
changeset
|
13 * libdvdread is distributed in the hope that it will be useful, |
| 3 | 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 * GNU General Public License for more details. | |
| 17 * | |
|
21
4aa618ae094f
Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents:
20
diff
changeset
|
18 * You should have received a copy of the GNU General Public License along |
|
4aa618ae094f
Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents:
20
diff
changeset
|
19 * with libdvdread; if not, write to the Free Software Foundation, Inc., |
|
4aa618ae094f
Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents:
20
diff
changeset
|
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 3 | 21 */ |
| 22 | |
| 23 #include "config.h" | |
| 24 | |
| 25 #include <stdio.h> | |
| 26 #include <stdlib.h> | |
| 27 #include <inttypes.h> | |
| 28 #include <string.h> | |
| 29 | |
| 30 #include "bswap.h" | |
|
33
c743d79f187b
Move installed headers into dvdread directory to make them easier to
reimar
parents:
27
diff
changeset
|
31 #include "dvdread/ifo_types.h" |
|
c743d79f187b
Move installed headers into dvdread directory to make them easier to
reimar
parents:
27
diff
changeset
|
32 #include "dvdread/ifo_read.h" |
|
c743d79f187b
Move installed headers into dvdread directory to make them easier to
reimar
parents:
27
diff
changeset
|
33 #include "dvdread/dvd_reader.h" |
| 3 | 34 #include "dvdread_internal.h" |
|
33
c743d79f187b
Move installed headers into dvdread directory to make them easier to
reimar
parents:
27
diff
changeset
|
35 #include "dvdread/bitreader.h" |
| 3 | 36 |
| 37 #ifndef DVD_BLOCK_LEN | |
| 38 #define DVD_BLOCK_LEN 2048 | |
| 39 #endif | |
| 40 | |
| 41 #ifndef NDEBUG | |
|
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
42 #define CHECK_ZERO0(arg) \ |
|
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
43 if(arg != 0) { \ |
| 3 | 44 fprintf(stderr, "*** Zero check failed in %s:%i\n for %s = 0x%x\n", \ |
|
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
45 __FILE__, __LINE__, # arg, arg); \ |
| 3 | 46 } |
|
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
47 #define CHECK_ZERO(arg) \ |
|
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
48 if(memcmp(my_friendly_zeros, &arg, sizeof(arg))) { \ |
|
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
49 unsigned int i_CZ; \ |
|
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
50 fprintf(stderr, "*** Zero check failed in %s:%i\n for %s = 0x", \ |
|
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
51 __FILE__, __LINE__, # arg ); \ |
|
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
52 for(i_CZ = 0; i_CZ < sizeof(arg); i_CZ++) \ |
|
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
53 fprintf(stderr, "%02x", *((uint8_t *)&arg + i_CZ)); \ |
|
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
54 fprintf(stderr, "\n"); \ |
| 3 | 55 } |
| 56 static const uint8_t my_friendly_zeros[2048]; | |
| 57 #else | |
| 58 #define CHECK_ZERO0(arg) (void)(arg) | |
| 59 #define CHECK_ZERO(arg) (void)(arg) | |
| 60 #endif | |
| 61 | |
| 62 | |
| 63 /* Prototypes for internal functions */ | |
| 64 static int ifoRead_VMG(ifo_handle_t *ifofile); | |
| 65 static int ifoRead_VTS(ifo_handle_t *ifofile); | |
| 66 static int ifoRead_PGC(ifo_handle_t *ifofile, pgc_t *pgc, unsigned int offset); | |
| 20 | 67 static int ifoRead_PGC_COMMAND_TBL(ifo_handle_t *ifofile, |
| 68 pgc_command_tbl_t *cmd_tbl, | |
| 26 | 69 unsigned int offset); |
| 20 | 70 static int ifoRead_PGC_PROGRAM_MAP(ifo_handle_t *ifofile, |
| 71 pgc_program_map_t *program_map, | |
| 3 | 72 unsigned int nr, unsigned int offset); |
| 20 | 73 static int ifoRead_CELL_PLAYBACK_TBL(ifo_handle_t *ifofile, |
| 74 cell_playback_t *cell_playback, | |
| 3 | 75 unsigned int nr, unsigned int offset); |
| 20 | 76 static int ifoRead_CELL_POSITION_TBL(ifo_handle_t *ifofile, |
| 77 cell_position_t *cell_position, | |
| 3 | 78 unsigned int nr, unsigned int offset); |
| 20 | 79 static int ifoRead_VTS_ATTRIBUTES(ifo_handle_t *ifofile, |
| 80 vts_attributes_t *vts_attributes, | |
| 3 | 81 unsigned int offset); |
| 20 | 82 static int ifoRead_C_ADT_internal(ifo_handle_t *ifofile, c_adt_t *c_adt, |
| 3 | 83 unsigned int sector); |
| 20 | 84 static int ifoRead_VOBU_ADMAP_internal(ifo_handle_t *ifofile, |
| 85 vobu_admap_t *vobu_admap, | |
| 26 | 86 unsigned int sector); |
| 20 | 87 static int ifoRead_PGCIT_internal(ifo_handle_t *ifofile, pgcit_t *pgcit, |
| 3 | 88 unsigned int offset); |
| 89 | |
| 75 | 90 static void ifoFree_PGC(pgc_t **pgc); |
| 3 | 91 static void ifoFree_PGC_COMMAND_TBL(pgc_command_tbl_t *cmd_tbl); |
| 75 | 92 static void ifoFree_PGCIT_internal(pgcit_t **pgcit); |
| 3 | 93 |
| 94 static inline int DVDFileSeekForce_( dvd_file_t *dvd_file, uint32_t offset, int force_size ) { | |
| 95 return (DVDFileSeekForce(dvd_file, (int)offset, force_size) == (int)offset); | |
| 96 } | |
| 97 | |
| 98 static inline int DVDFileSeek_( dvd_file_t *dvd_file, uint32_t offset ) { | |
| 99 return (DVDFileSeek(dvd_file, (int)offset) == (int)offset); | |
| 100 } | |
| 101 | |
| 102 static void read_video_attr(video_attr_t *va) { | |
| 103 getbits_state_t state; | |
| 104 uint8_t buf[sizeof(video_attr_t)]; | |
| 105 | |
| 106 memcpy(buf, va, sizeof(video_attr_t)); | |
| 107 if (!dvdread_getbits_init(&state, buf)) abort(); | |
| 108 va->mpeg_version = dvdread_getbits(&state, 2); | |
| 109 va->video_format = dvdread_getbits(&state, 2); | |
| 110 va->display_aspect_ratio = dvdread_getbits(&state, 2); | |
| 111 va->permitted_df = dvdread_getbits(&state, 2); | |
| 112 va->line21_cc_1 = dvdread_getbits(&state, 1); | |
| 113 va->line21_cc_2 = dvdread_getbits(&state, 1); | |
| 114 va->unknown1 = dvdread_getbits(&state, 1); | |
| 115 va->bit_rate = dvdread_getbits(&state, 1); | |
| 116 va->picture_size = dvdread_getbits(&state, 2); | |
| 117 va->letterboxed = dvdread_getbits(&state, 1); | |
| 118 va->film_mode = dvdread_getbits(&state, 1); | |
| 119 } | |
| 120 | |
| 121 static void read_audio_attr(audio_attr_t *aa) { | |
| 122 getbits_state_t state; | |
| 123 uint8_t buf[sizeof(audio_attr_t)]; | |
| 20 | 124 |
| 3 | 125 memcpy(buf, aa, sizeof(audio_attr_t)); |
| 126 if (!dvdread_getbits_init(&state, buf)) abort(); | |
| 127 aa->audio_format = dvdread_getbits(&state, 3); | |
| 128 aa->multichannel_extension = dvdread_getbits(&state, 1); | |
| 129 aa->lang_type = dvdread_getbits(&state, 2); | |
| 130 aa->application_mode = dvdread_getbits(&state, 2); | |
| 131 aa->quantization = dvdread_getbits(&state, 2); | |
| 132 aa->sample_frequency = dvdread_getbits(&state, 2); | |
| 133 aa->unknown1 = dvdread_getbits(&state, 1); | |
| 134 aa->channels = dvdread_getbits(&state, 3); | |
| 135 aa->lang_code = dvdread_getbits(&state, 16); | |
| 136 aa->lang_extension = dvdread_getbits(&state, 8); | |
| 137 aa->code_extension = dvdread_getbits(&state, 8); | |
| 138 aa->unknown3 = dvdread_getbits(&state, 8); | |
| 139 aa->app_info.karaoke.unknown4 = dvdread_getbits(&state, 1); | |
| 140 aa->app_info.karaoke.channel_assignment = dvdread_getbits(&state, 3); | |
| 141 aa->app_info.karaoke.version = dvdread_getbits(&state, 2); | |
| 142 aa->app_info.karaoke.mc_intro = dvdread_getbits(&state, 1); | |
| 143 aa->app_info.karaoke.mode = dvdread_getbits(&state, 1); | |
| 144 } | |
| 145 | |
| 146 static void read_multichannel_ext(multichannel_ext_t *me) { | |
| 147 getbits_state_t state; | |
| 148 uint8_t buf[sizeof(multichannel_ext_t)]; | |
| 20 | 149 |
| 3 | 150 memcpy(buf, me, sizeof(multichannel_ext_t)); |
| 151 if (!dvdread_getbits_init(&state, buf)) abort(); | |
| 152 me->zero1 = dvdread_getbits(&state, 7); | |
| 153 me->ach0_gme = dvdread_getbits(&state, 1); | |
| 154 me->zero2 = dvdread_getbits(&state, 7); | |
| 155 me->ach1_gme = dvdread_getbits(&state, 1); | |
| 156 me->zero3 = dvdread_getbits(&state, 4); | |
| 157 me->ach2_gv1e = dvdread_getbits(&state, 1); | |
| 158 me->ach2_gv2e = dvdread_getbits(&state, 1); | |
| 159 me->ach2_gm1e = dvdread_getbits(&state, 1); | |
| 160 me->ach2_gm2e = dvdread_getbits(&state, 1); | |
| 161 me->zero4 = dvdread_getbits(&state, 4); | |
| 162 me->ach3_gv1e = dvdread_getbits(&state, 1); | |
| 163 me->ach3_gv2e = dvdread_getbits(&state, 1); | |
| 164 me->ach3_gmAe = dvdread_getbits(&state, 1); | |
| 165 me->ach3_se2e = dvdread_getbits(&state, 1); | |
| 166 me->zero5 = dvdread_getbits(&state, 4); | |
| 167 me->ach4_gv1e = dvdread_getbits(&state, 1); | |
| 168 me->ach4_gv2e = dvdread_getbits(&state, 1); | |
| 169 me->ach4_gmBe = dvdread_getbits(&state, 1); | |
| 170 me->ach4_seBe = dvdread_getbits(&state, 1); | |
| 171 } | |
| 172 | |
| 173 static void read_subp_attr(subp_attr_t *sa) { | |
| 174 getbits_state_t state; | |
| 175 uint8_t buf[sizeof(subp_attr_t)]; | |
| 20 | 176 |
| 3 | 177 memcpy(buf, sa, sizeof(subp_attr_t)); |
| 178 if (!dvdread_getbits_init(&state, buf)) abort(); | |
| 179 sa->code_mode = dvdread_getbits(&state, 3); | |
| 180 sa->zero1 = dvdread_getbits(&state, 3); | |
| 181 sa->type = dvdread_getbits(&state, 2); | |
| 182 sa->zero2 = dvdread_getbits(&state, 8); | |
| 183 sa->lang_code = dvdread_getbits(&state, 16); | |
| 184 sa->lang_extension = dvdread_getbits(&state, 8); | |
| 185 sa->code_extension = dvdread_getbits(&state, 8); | |
| 186 } | |
| 187 | |
| 188 static void read_user_ops(user_ops_t *uo) { | |
| 189 getbits_state_t state; | |
| 190 uint8_t buf[sizeof(user_ops_t)]; | |
| 20 | 191 |
| 3 | 192 memcpy(buf, uo, sizeof(user_ops_t)); |
| 193 if (!dvdread_getbits_init(&state, buf)) abort(); | |
| 194 uo->zero = dvdread_getbits(&state, 7); | |
| 195 uo->video_pres_mode_change = dvdread_getbits(&state, 1); | |
| 196 uo->karaoke_audio_pres_mode_change = dvdread_getbits(&state, 1); | |
| 197 uo->angle_change = dvdread_getbits(&state, 1); | |
| 198 uo->subpic_stream_change = dvdread_getbits(&state, 1); | |
| 199 uo->audio_stream_change = dvdread_getbits(&state, 1); | |
| 200 uo->pause_on = dvdread_getbits(&state, 1); | |
| 201 uo->still_off = dvdread_getbits(&state, 1); | |
| 202 uo->button_select_or_activate = dvdread_getbits(&state, 1); | |
| 203 uo->resume = dvdread_getbits(&state, 1); | |
| 204 uo->chapter_menu_call = dvdread_getbits(&state, 1); | |
| 205 uo->angle_menu_call = dvdread_getbits(&state, 1); | |
| 206 uo->audio_menu_call = dvdread_getbits(&state, 1); | |
| 207 uo->subpic_menu_call = dvdread_getbits(&state, 1); | |
| 208 uo->root_menu_call = dvdread_getbits(&state, 1); | |
| 209 uo->title_menu_call = dvdread_getbits(&state, 1); | |
| 210 uo->backward_scan = dvdread_getbits(&state, 1); | |
| 211 uo->forward_scan = dvdread_getbits(&state, 1); | |
| 212 uo->next_pg_search = dvdread_getbits(&state, 1); | |
| 213 uo->prev_or_top_pg_search = dvdread_getbits(&state, 1); | |
| 214 uo->time_or_chapter_search = dvdread_getbits(&state, 1); | |
| 215 uo->go_up = dvdread_getbits(&state, 1); | |
| 216 uo->stop = dvdread_getbits(&state, 1); | |
| 217 uo->title_play = dvdread_getbits(&state, 1); | |
| 218 uo->chapter_search_or_play = dvdread_getbits(&state, 1); | |
| 219 uo->title_or_time_play = dvdread_getbits(&state, 1); | |
| 220 } | |
| 221 | |
| 222 static void read_pgci_srp(pgci_srp_t *ps) { | |
| 223 getbits_state_t state; | |
| 224 uint8_t buf[sizeof(pgci_srp_t)]; | |
| 20 | 225 |
| 3 | 226 memcpy(buf, ps, sizeof(pgci_srp_t)); |
| 227 if (!dvdread_getbits_init(&state, buf)) abort(); | |
| 228 ps->entry_id = dvdread_getbits(&state, 8); | |
| 229 ps->block_mode = dvdread_getbits(&state, 2); | |
| 230 ps->block_type = dvdread_getbits(&state, 2); | |
| 231 ps->unknown1 = dvdread_getbits(&state, 4); | |
| 232 ps->ptl_id_mask = dvdread_getbits(&state, 16); | |
| 233 ps->pgc_start_byte = dvdread_getbits(&state, 32); | |
| 234 } | |
| 235 | |
| 236 static void read_cell_playback(cell_playback_t *cp) { | |
| 237 getbits_state_t state; | |
| 238 uint8_t buf[sizeof(cell_playback_t)]; | |
| 20 | 239 |
| 3 | 240 memcpy(buf, cp, sizeof(cell_playback_t)); |
| 241 if (!dvdread_getbits_init(&state, buf)) abort(); | |
| 242 cp->block_mode = dvdread_getbits(&state, 2); | |
| 243 cp->block_type = dvdread_getbits(&state, 2); | |
| 244 cp->seamless_play = dvdread_getbits(&state, 1); | |
| 245 cp->interleaved = dvdread_getbits(&state, 1); | |
| 246 cp->stc_discontinuity = dvdread_getbits(&state, 1); | |
| 247 cp->seamless_angle = dvdread_getbits(&state, 1); | |
| 248 cp->playback_mode = dvdread_getbits(&state, 1); | |
| 249 cp->restricted = dvdread_getbits(&state, 1); | |
| 250 cp->unknown2 = dvdread_getbits(&state, 6); | |
| 251 cp->still_time = dvdread_getbits(&state, 8); | |
| 252 cp->cell_cmd_nr = dvdread_getbits(&state, 8); | |
| 20 | 253 |
| 3 | 254 cp->playback_time.hour = dvdread_getbits(&state, 8); |
| 255 cp->playback_time.minute = dvdread_getbits(&state, 8); | |
| 256 cp->playback_time.second = dvdread_getbits(&state, 8); | |
| 257 cp->playback_time.frame_u = dvdread_getbits(&state, 8); | |
| 20 | 258 |
| 3 | 259 cp->first_sector = dvdread_getbits(&state, 32); |
| 260 cp->first_ilvu_end_sector = dvdread_getbits(&state, 32); | |
| 261 cp->last_vobu_start_sector = dvdread_getbits(&state, 32); | |
| 262 cp->last_sector = dvdread_getbits(&state, 32); | |
| 263 } | |
| 264 | |
| 265 static void read_playback_type(playback_type_t *pt) { | |
| 266 getbits_state_t state; | |
| 267 uint8_t buf[sizeof(playback_type_t)]; | |
| 20 | 268 |
| 3 | 269 memcpy(buf, pt, sizeof(playback_type_t)); |
| 270 if (!dvdread_getbits_init(&state, buf)) abort(); | |
| 271 pt->zero_1 = dvdread_getbits(&state, 1); | |
| 272 pt->multi_or_random_pgc_title = dvdread_getbits(&state, 1); | |
| 273 pt->jlc_exists_in_cell_cmd = dvdread_getbits(&state, 1); | |
| 274 pt->jlc_exists_in_prepost_cmd = dvdread_getbits(&state, 1); | |
| 275 pt->jlc_exists_in_button_cmd = dvdread_getbits(&state, 1); | |
| 276 pt->jlc_exists_in_tt_dom = dvdread_getbits(&state, 1); | |
| 277 pt->chapter_search_or_play = dvdread_getbits(&state, 1); | |
| 278 pt->title_or_time_play = dvdread_getbits(&state, 1); | |
| 279 } | |
| 280 | |
|
12
056f5573a7dc
moved various pieces of duplicated code to free_ptl_mait(); patch by Erik Hovland org
nicodvb
parents:
3
diff
changeset
|
281 static void free_ptl_mait(ptl_mait_t* ptl_mait, int num_entries) { |
|
056f5573a7dc
moved various pieces of duplicated code to free_ptl_mait(); patch by Erik Hovland org
nicodvb
parents:
3
diff
changeset
|
282 int i; |
|
056f5573a7dc
moved various pieces of duplicated code to free_ptl_mait(); patch by Erik Hovland org
nicodvb
parents:
3
diff
changeset
|
283 for (i = 0; i < num_entries; i++) |
|
056f5573a7dc
moved various pieces of duplicated code to free_ptl_mait(); patch by Erik Hovland org
nicodvb
parents:
3
diff
changeset
|
284 free(ptl_mait->countries[i].pf_ptl_mai); |
|
056f5573a7dc
moved various pieces of duplicated code to free_ptl_mait(); patch by Erik Hovland org
nicodvb
parents:
3
diff
changeset
|
285 |
|
056f5573a7dc
moved various pieces of duplicated code to free_ptl_mait(); patch by Erik Hovland org
nicodvb
parents:
3
diff
changeset
|
286 free(ptl_mait->countries); |
|
056f5573a7dc
moved various pieces of duplicated code to free_ptl_mait(); patch by Erik Hovland org
nicodvb
parents:
3
diff
changeset
|
287 free(ptl_mait); |
|
056f5573a7dc
moved various pieces of duplicated code to free_ptl_mait(); patch by Erik Hovland org
nicodvb
parents:
3
diff
changeset
|
288 } |
|
056f5573a7dc
moved various pieces of duplicated code to free_ptl_mait(); patch by Erik Hovland org
nicodvb
parents:
3
diff
changeset
|
289 |
| 3 | 290 ifo_handle_t *ifoOpen(dvd_reader_t *dvd, int title) { |
| 291 ifo_handle_t *ifofile; | |
| 59 | 292 int bup_file_opened = 0; |
| 293 char ifo_filename[13]; | |
| 3 | 294 |
| 295 ifofile = (ifo_handle_t *)malloc(sizeof(ifo_handle_t)); | |
| 296 if(!ifofile) | |
| 297 return NULL; | |
| 298 | |
| 299 memset(ifofile, 0, sizeof(ifo_handle_t)); | |
| 300 | |
| 301 ifofile->file = DVDOpenFile(dvd, title, DVD_READ_INFO_FILE); | |
| 59 | 302 if(!ifofile->file) { /* Failed to open IFO, try to open BUP */ |
| 3 | 303 ifofile->file = DVDOpenFile(dvd, title, DVD_READ_INFO_BACKUP_FILE); |
| 59 | 304 bup_file_opened = 1; |
| 305 } | |
| 306 | |
| 307 if (title) | |
| 308 snprintf(ifo_filename, 12, "VTS_%02d_0.%s", title, bup_file_opened ? "BUP" : "IFO"); | |
| 309 else | |
| 310 snprintf(ifo_filename, 12, "VIDEO_TS.%s", bup_file_opened ? "BUP" : "IFO"); | |
| 311 | |
| 312 ifo_filename[12] = '\0'; | |
| 313 | |
| 3 | 314 if(!ifofile->file) { |
| 59 | 315 fprintf(stderr, "libdvdread: Can't open file %s.\n", ifo_filename); |
| 3 | 316 free(ifofile); |
| 317 return NULL; | |
| 318 } | |
| 319 | |
| 320 /* First check if this is a VMGI file. */ | |
| 321 if(ifoRead_VMG(ifofile)) { | |
| 322 | |
| 323 /* These are both mandatory. */ | |
| 59 | 324 if(!ifoRead_FP_PGC(ifofile) || !ifoRead_TT_SRPT(ifofile)) |
| 325 goto ifoOpen_try_bup; | |
| 3 | 326 |
| 327 ifoRead_PGCI_UT(ifofile); | |
| 328 ifoRead_PTL_MAIT(ifofile); | |
| 329 | |
| 330 /* This is also mandatory. */ | |
| 59 | 331 if(!ifoRead_VTS_ATRT(ifofile)) |
| 332 goto ifoOpen_try_bup; | |
| 3 | 333 |
| 334 ifoRead_TXTDT_MGI(ifofile); | |
| 335 ifoRead_C_ADT(ifofile); | |
| 336 ifoRead_VOBU_ADMAP(ifofile); | |
| 337 | |
| 338 return ifofile; | |
| 339 } | |
| 340 | |
| 341 if(ifoRead_VTS(ifofile)) { | |
| 342 | |
| 59 | 343 if(!ifoRead_VTS_PTT_SRPT(ifofile) || !ifoRead_PGCIT(ifofile)) |
| 344 goto ifoOpen_try_bup; | |
| 3 | 345 |
| 346 ifoRead_PGCI_UT(ifofile); | |
| 347 ifoRead_VTS_TMAPT(ifofile); | |
| 348 ifoRead_C_ADT(ifofile); | |
| 349 ifoRead_VOBU_ADMAP(ifofile); | |
| 350 | |
| 59 | 351 if(!ifoRead_TITLE_C_ADT(ifofile) || !ifoRead_TITLE_VOBU_ADMAP(ifofile)) |
| 352 goto ifoOpen_try_bup; | |
| 3 | 353 |
| 354 return ifofile; | |
| 355 } | |
| 356 | |
| 59 | 357 ifoOpen_try_bup: |
| 358 if (bup_file_opened) | |
| 359 goto ifoOpen_fail; | |
| 360 | |
| 361 /* Try BUP instead */ | |
| 362 ifoClose(ifofile); | |
| 363 | |
| 364 ifofile = (ifo_handle_t *)malloc(sizeof(ifo_handle_t)); | |
| 365 if(!ifofile) | |
| 366 return NULL; | |
| 367 | |
| 368 memset(ifofile, 0, sizeof(ifo_handle_t)); | |
| 369 ifofile->file = DVDOpenFile(dvd, title, DVD_READ_INFO_BACKUP_FILE); | |
| 370 | |
| 371 if (title) | |
| 372 snprintf(ifo_filename, 12, "VTS_%02d_0.BUP", title); | |
| 373 else | |
| 374 strncpy(ifo_filename, "VIDEO_TS.BUP", 12); | |
| 375 | |
| 376 if (!ifofile->file) { | |
| 377 fprintf(stderr, "libdvdread: Can't open file %s.\n", ifo_filename); | |
| 378 free(ifofile); | |
| 379 return NULL; | |
| 3 | 380 } |
| 59 | 381 bup_file_opened = 1; |
| 382 | |
| 383 /* First check if this is a VMGI file. */ | |
| 384 if(ifoRead_VMG(ifofile)) { | |
| 385 | |
| 386 /* These are both mandatory. */ | |
| 387 if(!ifoRead_FP_PGC(ifofile) || !ifoRead_TT_SRPT(ifofile)) | |
| 388 goto ifoOpen_fail; | |
| 389 | |
| 390 ifoRead_PGCI_UT(ifofile); | |
| 391 ifoRead_PTL_MAIT(ifofile); | |
| 392 | |
| 393 /* This is also mandatory. */ | |
| 394 if(!ifoRead_VTS_ATRT(ifofile)) | |
| 395 goto ifoOpen_fail; | |
| 396 | |
| 397 ifoRead_TXTDT_MGI(ifofile); | |
| 398 ifoRead_C_ADT(ifofile); | |
| 399 ifoRead_VOBU_ADMAP(ifofile); | |
| 400 | |
| 401 return ifofile; | |
| 402 } | |
| 403 | |
| 404 if(ifoRead_VTS(ifofile)) { | |
| 405 | |
| 406 if(!ifoRead_VTS_PTT_SRPT(ifofile) || !ifoRead_PGCIT(ifofile)) | |
| 407 goto ifoOpen_fail; | |
| 408 | |
| 409 ifoRead_PGCI_UT(ifofile); | |
| 410 ifoRead_VTS_TMAPT(ifofile); | |
| 411 ifoRead_C_ADT(ifofile); | |
| 412 ifoRead_VOBU_ADMAP(ifofile); | |
| 413 | |
| 414 if(!ifoRead_TITLE_C_ADT(ifofile) || !ifoRead_TITLE_VOBU_ADMAP(ifofile)) | |
| 415 goto ifoOpen_fail; | |
| 416 | |
| 417 return ifofile; | |
| 418 } | |
| 419 | |
| 420 ifoOpen_fail: | |
| 421 fprintf(stderr, "libdvdread: Invalid IFO for title %d (%s).\n", title, ifo_filename); | |
| 3 | 422 ifoClose(ifofile); |
| 423 return NULL; | |
| 424 } | |
| 425 | |
| 426 | |
| 427 ifo_handle_t *ifoOpenVMGI(dvd_reader_t *dvd) { | |
| 428 ifo_handle_t *ifofile; | |
| 429 | |
| 430 ifofile = (ifo_handle_t *)malloc(sizeof(ifo_handle_t)); | |
| 431 if(!ifofile) | |
| 432 return NULL; | |
| 433 | |
| 434 memset(ifofile, 0, sizeof(ifo_handle_t)); | |
| 435 | |
| 436 ifofile->file = DVDOpenFile(dvd, 0, DVD_READ_INFO_FILE); | |
| 437 if(!ifofile->file) /* Should really catch any error and try to fallback */ | |
| 438 ifofile->file = DVDOpenFile(dvd, 0, DVD_READ_INFO_BACKUP_FILE); | |
| 439 if(!ifofile->file) { | |
| 440 fprintf(stderr, "libdvdread: Can't open file VIDEO_TS.IFO.\n"); | |
| 441 free(ifofile); | |
| 442 return NULL; | |
| 443 } | |
| 444 | |
| 445 if(ifoRead_VMG(ifofile)) | |
| 446 return ifofile; | |
| 447 | |
| 448 fprintf(stderr, "libdvdread,ifoOpenVMGI(): Invalid main menu IFO (VIDEO_TS.IFO).\n"); | |
| 449 ifoClose(ifofile); | |
| 450 return NULL; | |
| 451 } | |
| 452 | |
| 453 | |
| 454 ifo_handle_t *ifoOpenVTSI(dvd_reader_t *dvd, int title) { | |
| 455 ifo_handle_t *ifofile; | |
| 20 | 456 |
| 3 | 457 ifofile = (ifo_handle_t *)malloc(sizeof(ifo_handle_t)); |
| 458 if(!ifofile) | |
| 459 return NULL; | |
| 460 | |
| 461 memset(ifofile, 0, sizeof(ifo_handle_t)); | |
| 20 | 462 |
| 3 | 463 if(title <= 0 || title > 99) { |
| 464 fprintf(stderr, "libdvdread: ifoOpenVTSI invalid title (%d).\n", title); | |
| 465 free(ifofile); | |
| 466 return NULL; | |
| 467 } | |
| 20 | 468 |
| 3 | 469 ifofile->file = DVDOpenFile(dvd, title, DVD_READ_INFO_FILE); |
| 470 if(!ifofile->file) /* Should really catch any error and try to fallback */ | |
| 471 ifofile->file = DVDOpenFile(dvd, title, DVD_READ_INFO_BACKUP_FILE); | |
| 472 if(!ifofile->file) { | |
| 473 fprintf(stderr, "libdvdread: Can't open file VTS_%02d_0.IFO.\n", title); | |
| 474 free(ifofile); | |
| 475 return NULL; | |
| 476 } | |
| 477 | |
| 478 ifoRead_VTS(ifofile); | |
| 479 if(ifofile->vtsi_mat) | |
| 480 return ifofile; | |
| 481 | |
| 482 fprintf(stderr, "libdvdread: Invalid IFO for title %d (VTS_%02d_0.IFO).\n", | |
| 483 title, title); | |
| 484 ifoClose(ifofile); | |
| 485 return NULL; | |
| 486 } | |
| 487 | |
| 488 | |
| 489 void ifoClose(ifo_handle_t *ifofile) { | |
| 490 if(!ifofile) | |
| 491 return; | |
| 20 | 492 |
| 3 | 493 ifoFree_VOBU_ADMAP(ifofile); |
| 494 ifoFree_TITLE_VOBU_ADMAP(ifofile); | |
| 495 ifoFree_C_ADT(ifofile); | |
| 496 ifoFree_TITLE_C_ADT(ifofile); | |
| 497 ifoFree_TXTDT_MGI(ifofile); | |
| 498 ifoFree_VTS_ATRT(ifofile); | |
| 499 ifoFree_PTL_MAIT(ifofile); | |
| 500 ifoFree_PGCI_UT(ifofile); | |
| 501 ifoFree_TT_SRPT(ifofile); | |
| 502 ifoFree_FP_PGC(ifofile); | |
| 503 ifoFree_PGCIT(ifofile); | |
| 504 ifoFree_VTS_PTT_SRPT(ifofile); | |
| 505 ifoFree_VTS_TMAPT(ifofile); | |
| 506 | |
| 507 if(ifofile->vmgi_mat) | |
| 508 free(ifofile->vmgi_mat); | |
| 509 | |
| 510 if(ifofile->vtsi_mat) | |
| 511 free(ifofile->vtsi_mat); | |
| 512 | |
| 513 DVDCloseFile(ifofile->file); | |
| 514 ifofile->file = 0; | |
| 515 free(ifofile); | |
| 516 ifofile = 0; | |
| 517 } | |
| 518 | |
| 519 | |
| 520 static int ifoRead_VMG(ifo_handle_t *ifofile) { | |
| 521 vmgi_mat_t *vmgi_mat; | |
| 522 | |
| 523 vmgi_mat = (vmgi_mat_t *)malloc(sizeof(vmgi_mat_t)); | |
| 524 if(!vmgi_mat) | |
| 525 return 0; | |
| 526 | |
| 527 ifofile->vmgi_mat = vmgi_mat; | |
| 528 | |
| 529 if(!DVDFileSeek_(ifofile->file, 0)) { | |
| 530 free(ifofile->vmgi_mat); | |
| 531 ifofile->vmgi_mat = 0; | |
| 532 return 0; | |
| 533 } | |
| 534 | |
| 535 if(!DVDReadBytes(ifofile->file, vmgi_mat, sizeof(vmgi_mat_t))) { | |
| 536 free(ifofile->vmgi_mat); | |
| 537 ifofile->vmgi_mat = 0; | |
| 538 return 0; | |
| 539 } | |
| 540 | |
| 541 if(strncmp("DVDVIDEO-VMG", vmgi_mat->vmg_identifier, 12) != 0) { | |
| 542 free(ifofile->vmgi_mat); | |
| 543 ifofile->vmgi_mat = 0; | |
| 544 return 0; | |
| 545 } | |
| 20 | 546 |
| 3 | 547 B2N_32(vmgi_mat->vmg_last_sector); |
| 548 B2N_32(vmgi_mat->vmgi_last_sector); | |
| 549 B2N_32(vmgi_mat->vmg_category); | |
| 550 B2N_16(vmgi_mat->vmg_nr_of_volumes); | |
| 551 B2N_16(vmgi_mat->vmg_this_volume_nr); | |
| 552 B2N_16(vmgi_mat->vmg_nr_of_title_sets); | |
| 553 B2N_64(vmgi_mat->vmg_pos_code); | |
| 554 B2N_32(vmgi_mat->vmgi_last_byte); | |
| 555 B2N_32(vmgi_mat->first_play_pgc); | |
| 556 B2N_32(vmgi_mat->vmgm_vobs); | |
| 557 B2N_32(vmgi_mat->tt_srpt); | |
| 558 B2N_32(vmgi_mat->vmgm_pgci_ut); | |
| 559 B2N_32(vmgi_mat->ptl_mait); | |
| 560 B2N_32(vmgi_mat->vts_atrt); | |
| 561 B2N_32(vmgi_mat->txtdt_mgi); | |
| 562 B2N_32(vmgi_mat->vmgm_c_adt); | |
| 563 B2N_32(vmgi_mat->vmgm_vobu_admap); | |
| 564 read_video_attr(&vmgi_mat->vmgm_video_attr); | |
| 565 read_audio_attr(&vmgi_mat->vmgm_audio_attr); | |
| 566 read_subp_attr(&vmgi_mat->vmgm_subp_attr); | |
| 567 | |
| 568 | |
| 569 CHECK_ZERO(vmgi_mat->zero_1); | |
| 570 CHECK_ZERO(vmgi_mat->zero_2); | |
|
87
1a6394166cce
Document warnings generated by DVDs made with the VDR-to-DVD device LG RC590M.
rathann
parents:
83
diff
changeset
|
571 /* DVDs created by VDR-to-DVD device LG RC590M violate the following check with |
|
1a6394166cce
Document warnings generated by DVDs made with the VDR-to-DVD device LG RC590M.
rathann
parents:
83
diff
changeset
|
572 * vmgi_mat->zero_3 = 0x00000000010000000000000000000000000000. */ |
| 3 | 573 CHECK_ZERO(vmgi_mat->zero_3); |
| 574 CHECK_ZERO(vmgi_mat->zero_4); | |
| 575 CHECK_ZERO(vmgi_mat->zero_5); | |
| 576 CHECK_ZERO(vmgi_mat->zero_6); | |
| 577 CHECK_ZERO(vmgi_mat->zero_7); | |
| 578 CHECK_ZERO(vmgi_mat->zero_8); | |
| 579 CHECK_ZERO(vmgi_mat->zero_9); | |
| 20 | 580 CHECK_ZERO(vmgi_mat->zero_10); |
| 3 | 581 CHECK_VALUE(vmgi_mat->vmg_last_sector != 0); |
| 582 CHECK_VALUE(vmgi_mat->vmgi_last_sector != 0); | |
| 583 CHECK_VALUE(vmgi_mat->vmgi_last_sector * 2 <= vmgi_mat->vmg_last_sector); | |
| 584 CHECK_VALUE(vmgi_mat->vmgi_last_sector * 2 <= vmgi_mat->vmg_last_sector); | |
| 585 CHECK_VALUE(vmgi_mat->vmg_nr_of_volumes != 0); | |
| 586 CHECK_VALUE(vmgi_mat->vmg_this_volume_nr != 0); | |
| 587 CHECK_VALUE(vmgi_mat->vmg_this_volume_nr <= vmgi_mat->vmg_nr_of_volumes); | |
| 588 CHECK_VALUE(vmgi_mat->disc_side == 1 || vmgi_mat->disc_side == 2); | |
| 589 CHECK_VALUE(vmgi_mat->vmg_nr_of_title_sets != 0); | |
| 590 CHECK_VALUE(vmgi_mat->vmgi_last_byte >= 341); | |
| 20 | 591 CHECK_VALUE(vmgi_mat->vmgi_last_byte / DVD_BLOCK_LEN <= |
|
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
592 vmgi_mat->vmgi_last_sector); |
| 3 | 593 /* It seems that first_play_pgc is optional. */ |
| 594 CHECK_VALUE(vmgi_mat->first_play_pgc < vmgi_mat->vmgi_last_byte); | |
| 20 | 595 CHECK_VALUE(vmgi_mat->vmgm_vobs == 0 || |
|
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
596 (vmgi_mat->vmgm_vobs > vmgi_mat->vmgi_last_sector && |
|
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
597 vmgi_mat->vmgm_vobs < vmgi_mat->vmg_last_sector)); |
| 3 | 598 CHECK_VALUE(vmgi_mat->tt_srpt <= vmgi_mat->vmgi_last_sector); |
| 599 CHECK_VALUE(vmgi_mat->vmgm_pgci_ut <= vmgi_mat->vmgi_last_sector); | |
| 600 CHECK_VALUE(vmgi_mat->ptl_mait <= vmgi_mat->vmgi_last_sector); | |
| 601 CHECK_VALUE(vmgi_mat->vts_atrt <= vmgi_mat->vmgi_last_sector); | |
| 602 CHECK_VALUE(vmgi_mat->txtdt_mgi <= vmgi_mat->vmgi_last_sector); | |
| 603 CHECK_VALUE(vmgi_mat->vmgm_c_adt <= vmgi_mat->vmgi_last_sector); | |
| 604 CHECK_VALUE(vmgi_mat->vmgm_vobu_admap <= vmgi_mat->vmgi_last_sector); | |
| 605 | |
| 606 CHECK_VALUE(vmgi_mat->nr_of_vmgm_audio_streams <= 1); | |
| 607 CHECK_VALUE(vmgi_mat->nr_of_vmgm_subp_streams <= 1); | |
| 608 | |
| 609 return 1; | |
| 610 } | |
| 611 | |
| 612 | |
| 613 static int ifoRead_VTS(ifo_handle_t *ifofile) { | |
| 614 vtsi_mat_t *vtsi_mat; | |
| 615 int i; | |
| 616 | |
| 617 vtsi_mat = (vtsi_mat_t *)malloc(sizeof(vtsi_mat_t)); | |
| 618 if(!vtsi_mat) | |
| 619 return 0; | |
| 20 | 620 |
| 3 | 621 ifofile->vtsi_mat = vtsi_mat; |
| 622 | |
| 623 if(!DVDFileSeek_(ifofile->file, 0)) { | |
| 624 free(ifofile->vtsi_mat); | |
| 625 ifofile->vtsi_mat = 0; | |
| 626 return 0; | |
| 627 } | |
| 628 | |
| 629 if(!(DVDReadBytes(ifofile->file, vtsi_mat, sizeof(vtsi_mat_t)))) { | |
| 630 free(ifofile->vtsi_mat); | |
| 631 ifofile->vtsi_mat = 0; | |
| 632 return 0; | |
| 633 } | |
| 634 | |
| 635 if(strncmp("DVDVIDEO-VTS", vtsi_mat->vts_identifier, 12) != 0) { | |
| 636 free(ifofile->vtsi_mat); | |
| 637 ifofile->vtsi_mat = 0; | |
| 638 return 0; | |
| 639 } | |
| 640 | |
| 641 read_video_attr(&vtsi_mat->vtsm_video_attr); | |
| 642 read_video_attr(&vtsi_mat->vts_video_attr); | |
| 643 read_audio_attr(&vtsi_mat->vtsm_audio_attr); | |
| 644 for(i=0; i<8; i++) | |
| 645 read_audio_attr(&vtsi_mat->vts_audio_attr[i]); | |
| 646 read_subp_attr(&vtsi_mat->vtsm_subp_attr); | |
| 647 for(i=0; i<32; i++) | |
| 648 read_subp_attr(&vtsi_mat->vts_subp_attr[i]); | |
| 649 B2N_32(vtsi_mat->vts_last_sector); | |
| 650 B2N_32(vtsi_mat->vtsi_last_sector); | |
| 651 B2N_32(vtsi_mat->vts_category); | |
| 652 B2N_32(vtsi_mat->vtsi_last_byte); | |
| 653 B2N_32(vtsi_mat->vtsm_vobs); | |
| 654 B2N_32(vtsi_mat->vtstt_vobs); | |
| 655 B2N_32(vtsi_mat->vts_ptt_srpt); | |
| 656 B2N_32(vtsi_mat->vts_pgcit); | |
| 657 B2N_32(vtsi_mat->vtsm_pgci_ut); | |
| 658 B2N_32(vtsi_mat->vts_tmapt); | |
| 659 B2N_32(vtsi_mat->vtsm_c_adt); | |
| 660 B2N_32(vtsi_mat->vtsm_vobu_admap); | |
| 661 B2N_32(vtsi_mat->vts_c_adt); | |
| 662 B2N_32(vtsi_mat->vts_vobu_admap); | |
| 663 | |
| 664 | |
| 665 CHECK_ZERO(vtsi_mat->zero_1); | |
| 666 CHECK_ZERO(vtsi_mat->zero_2); | |
| 667 CHECK_ZERO(vtsi_mat->zero_3); | |
| 668 CHECK_ZERO(vtsi_mat->zero_4); | |
| 669 CHECK_ZERO(vtsi_mat->zero_5); | |
| 670 CHECK_ZERO(vtsi_mat->zero_6); | |
| 671 CHECK_ZERO(vtsi_mat->zero_7); | |
| 672 CHECK_ZERO(vtsi_mat->zero_8); | |
| 673 CHECK_ZERO(vtsi_mat->zero_9); | |
| 674 CHECK_ZERO(vtsi_mat->zero_10); | |
| 675 CHECK_ZERO(vtsi_mat->zero_11); | |
| 676 CHECK_ZERO(vtsi_mat->zero_12); | |
| 677 CHECK_ZERO(vtsi_mat->zero_13); | |
| 678 CHECK_ZERO(vtsi_mat->zero_14); | |
| 679 CHECK_ZERO(vtsi_mat->zero_15); | |
| 680 CHECK_ZERO(vtsi_mat->zero_16); | |
| 681 CHECK_ZERO(vtsi_mat->zero_17); | |
| 682 CHECK_ZERO(vtsi_mat->zero_18); | |
| 683 CHECK_ZERO(vtsi_mat->zero_19); | |
| 684 CHECK_ZERO(vtsi_mat->zero_20); | |
| 685 CHECK_ZERO(vtsi_mat->zero_21); | |
| 686 CHECK_VALUE(vtsi_mat->vtsi_last_sector*2 <= vtsi_mat->vts_last_sector); | |
| 687 CHECK_VALUE(vtsi_mat->vtsi_last_byte/DVD_BLOCK_LEN <= vtsi_mat->vtsi_last_sector); | |
| 20 | 688 CHECK_VALUE(vtsi_mat->vtsm_vobs == 0 || |
|
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
689 (vtsi_mat->vtsm_vobs > vtsi_mat->vtsi_last_sector && |
|
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
690 vtsi_mat->vtsm_vobs < vtsi_mat->vts_last_sector)); |
| 20 | 691 CHECK_VALUE(vtsi_mat->vtstt_vobs == 0 || |
|
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
692 (vtsi_mat->vtstt_vobs > vtsi_mat->vtsi_last_sector && |
|
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
693 vtsi_mat->vtstt_vobs < vtsi_mat->vts_last_sector)); |
| 3 | 694 CHECK_VALUE(vtsi_mat->vts_ptt_srpt <= vtsi_mat->vtsi_last_sector); |
| 695 CHECK_VALUE(vtsi_mat->vts_pgcit <= vtsi_mat->vtsi_last_sector); | |
| 696 CHECK_VALUE(vtsi_mat->vtsm_pgci_ut <= vtsi_mat->vtsi_last_sector); | |
| 697 CHECK_VALUE(vtsi_mat->vts_tmapt <= vtsi_mat->vtsi_last_sector); | |
| 698 CHECK_VALUE(vtsi_mat->vtsm_c_adt <= vtsi_mat->vtsi_last_sector); | |
| 699 CHECK_VALUE(vtsi_mat->vtsm_vobu_admap <= vtsi_mat->vtsi_last_sector); | |
| 700 CHECK_VALUE(vtsi_mat->vts_c_adt <= vtsi_mat->vtsi_last_sector); | |
| 701 CHECK_VALUE(vtsi_mat->vts_vobu_admap <= vtsi_mat->vtsi_last_sector); | |
| 20 | 702 |
| 3 | 703 CHECK_VALUE(vtsi_mat->nr_of_vtsm_audio_streams <= 1); |
| 704 CHECK_VALUE(vtsi_mat->nr_of_vtsm_subp_streams <= 1); | |
| 705 | |
| 706 CHECK_VALUE(vtsi_mat->nr_of_vts_audio_streams <= 8); | |
| 707 for(i = vtsi_mat->nr_of_vts_audio_streams; i < 8; i++) | |
| 708 CHECK_ZERO(vtsi_mat->vts_audio_attr[i]); | |
| 709 | |
| 710 CHECK_VALUE(vtsi_mat->nr_of_vts_subp_streams <= 32); | |
| 711 for(i = vtsi_mat->nr_of_vts_subp_streams; i < 32; i++) | |
| 20 | 712 CHECK_ZERO(vtsi_mat->vts_subp_attr[i]); |
| 713 | |
| 3 | 714 for(i = 0; i < 8; i++) { |
| 715 read_multichannel_ext(&vtsi_mat->vts_mu_audio_attr[i]); | |
| 716 CHECK_ZERO0(vtsi_mat->vts_mu_audio_attr[i].zero1); | |
| 717 CHECK_ZERO0(vtsi_mat->vts_mu_audio_attr[i].zero2); | |
| 718 CHECK_ZERO0(vtsi_mat->vts_mu_audio_attr[i].zero3); | |
| 719 CHECK_ZERO0(vtsi_mat->vts_mu_audio_attr[i].zero4); | |
| 720 CHECK_ZERO0(vtsi_mat->vts_mu_audio_attr[i].zero5); | |
| 721 CHECK_ZERO(vtsi_mat->vts_mu_audio_attr[i].zero6); | |
| 722 } | |
| 20 | 723 |
| 3 | 724 return 1; |
| 725 } | |
| 726 | |
| 727 | |
| 20 | 728 static int ifoRead_PGC_COMMAND_TBL(ifo_handle_t *ifofile, |
| 729 pgc_command_tbl_t *cmd_tbl, | |
| 26 | 730 unsigned int offset) { |
| 20 | 731 |
| 3 | 732 memset(cmd_tbl, 0, sizeof(pgc_command_tbl_t)); |
| 20 | 733 |
| 3 | 734 if(!DVDFileSeek_(ifofile->file, offset)) |
| 735 return 0; | |
| 736 | |
| 737 if(!(DVDReadBytes(ifofile->file, cmd_tbl, PGC_COMMAND_TBL_SIZE))) | |
| 738 return 0; | |
| 739 | |
| 740 B2N_16(cmd_tbl->nr_of_pre); | |
| 741 B2N_16(cmd_tbl->nr_of_post); | |
| 742 B2N_16(cmd_tbl->nr_of_cell); | |
| 743 | |
| 744 CHECK_VALUE(cmd_tbl->nr_of_pre + cmd_tbl->nr_of_post + cmd_tbl->nr_of_cell<= 255); | |
| 20 | 745 |
| 3 | 746 if(cmd_tbl->nr_of_pre != 0) { |
| 747 unsigned int pre_cmds_size = cmd_tbl->nr_of_pre * COMMAND_DATA_SIZE; | |
| 748 cmd_tbl->pre_cmds = (vm_cmd_t *)malloc(pre_cmds_size); | |
| 749 if(!cmd_tbl->pre_cmds) | |
| 750 return 0; | |
| 751 | |
| 752 if(!(DVDReadBytes(ifofile->file, cmd_tbl->pre_cmds, pre_cmds_size))) { | |
| 753 free(cmd_tbl->pre_cmds); | |
| 754 return 0; | |
| 755 } | |
| 756 } | |
| 20 | 757 |
| 3 | 758 if(cmd_tbl->nr_of_post != 0) { |
| 759 unsigned int post_cmds_size = cmd_tbl->nr_of_post * COMMAND_DATA_SIZE; | |
| 760 cmd_tbl->post_cmds = (vm_cmd_t *)malloc(post_cmds_size); | |
| 761 if(!cmd_tbl->post_cmds) { | |
| 20 | 762 if(cmd_tbl->pre_cmds) |
| 26 | 763 free(cmd_tbl->pre_cmds); |
| 3 | 764 return 0; |
| 765 } | |
| 766 if(!(DVDReadBytes(ifofile->file, cmd_tbl->post_cmds, post_cmds_size))) { | |
| 20 | 767 if(cmd_tbl->pre_cmds) |
| 26 | 768 free(cmd_tbl->pre_cmds); |
| 3 | 769 free(cmd_tbl->post_cmds); |
| 770 return 0; | |
| 771 } | |
| 772 } | |
| 773 | |
| 774 if(cmd_tbl->nr_of_cell != 0) { | |
| 775 unsigned int cell_cmds_size = cmd_tbl->nr_of_cell * COMMAND_DATA_SIZE; | |
| 776 cmd_tbl->cell_cmds = (vm_cmd_t *)malloc(cell_cmds_size); | |
| 777 if(!cmd_tbl->cell_cmds) { | |
| 778 if(cmd_tbl->pre_cmds) | |
| 26 | 779 free(cmd_tbl->pre_cmds); |
| 3 | 780 if(cmd_tbl->post_cmds) |
| 26 | 781 free(cmd_tbl->post_cmds); |
| 3 | 782 return 0; |
| 783 } | |
| 784 if(!(DVDReadBytes(ifofile->file, cmd_tbl->cell_cmds, cell_cmds_size))) { | |
| 20 | 785 if(cmd_tbl->pre_cmds) |
| 26 | 786 free(cmd_tbl->pre_cmds); |
| 20 | 787 if(cmd_tbl->post_cmds) |
| 26 | 788 free(cmd_tbl->post_cmds); |
| 3 | 789 free(cmd_tbl->cell_cmds); |
| 790 return 0; | |
| 791 } | |
| 792 } | |
| 20 | 793 |
| 794 /* | |
| 3 | 795 * Make a run over all the commands and see that we can interpret them all? |
| 796 */ | |
| 797 return 1; | |
| 798 } | |
| 799 | |
| 800 | |
| 801 static void ifoFree_PGC_COMMAND_TBL(pgc_command_tbl_t *cmd_tbl) { | |
| 802 if(cmd_tbl) { | |
| 803 if(cmd_tbl->nr_of_pre && cmd_tbl->pre_cmds) | |
| 804 free(cmd_tbl->pre_cmds); | |
| 805 if(cmd_tbl->nr_of_post && cmd_tbl->post_cmds) | |
| 806 free(cmd_tbl->post_cmds); | |
| 807 if(cmd_tbl->nr_of_cell && cmd_tbl->cell_cmds) | |
| 808 free(cmd_tbl->cell_cmds); | |
| 809 free(cmd_tbl); | |
| 810 } | |
| 811 } | |
| 812 | |
| 20 | 813 static int ifoRead_PGC_PROGRAM_MAP(ifo_handle_t *ifofile, |
| 814 pgc_program_map_t *program_map, | |
| 26 | 815 unsigned int nr, unsigned int offset) { |
| 3 | 816 unsigned int size = nr * sizeof(pgc_program_map_t); |
| 817 | |
| 818 if(!DVDFileSeek_(ifofile->file, offset)) | |
| 819 return 0; | |
| 20 | 820 |
| 3 | 821 if(!(DVDReadBytes(ifofile->file, program_map, size))) |
| 822 return 0; | |
| 823 | |
| 824 return 1; | |
| 825 } | |
| 826 | |
| 20 | 827 static int ifoRead_CELL_PLAYBACK_TBL(ifo_handle_t *ifofile, |
| 3 | 828 cell_playback_t *cell_playback, |
| 829 unsigned int nr, unsigned int offset) { | |
| 830 unsigned int i; | |
| 831 unsigned int size = nr * sizeof(cell_playback_t); | |
| 832 | |
| 833 if(!DVDFileSeek_(ifofile->file, offset)) | |
| 834 return 0; | |
| 835 | |
| 836 if(!(DVDReadBytes(ifofile->file, cell_playback, size))) | |
| 837 return 0; | |
| 838 | |
| 839 for(i = 0; i < nr; i++) { | |
| 840 read_cell_playback(&cell_playback[i]); | |
| 841 /* Changed < to <= because this was false in the movie 'Pi'. */ | |
| 20 | 842 CHECK_VALUE(cell_playback[i].last_vobu_start_sector <= |
|
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
843 cell_playback[i].last_sector); |
| 20 | 844 CHECK_VALUE(cell_playback[i].first_sector <= |
|
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
845 cell_playback[i].last_vobu_start_sector); |
| 3 | 846 } |
| 847 | |
| 848 return 1; | |
| 849 } | |
| 850 | |
| 851 | |
| 20 | 852 static int ifoRead_CELL_POSITION_TBL(ifo_handle_t *ifofile, |
| 853 cell_position_t *cell_position, | |
| 3 | 854 unsigned int nr, unsigned int offset) { |
| 855 unsigned int i; | |
| 856 unsigned int size = nr * sizeof(cell_position_t); | |
| 857 | |
| 858 if(!DVDFileSeek_(ifofile->file, offset)) | |
| 859 return 0; | |
| 860 | |
| 861 if(!(DVDReadBytes(ifofile->file, cell_position, size))) | |
| 862 return 0; | |
| 863 | |
| 864 for(i = 0; i < nr; i++) { | |
| 865 B2N_16(cell_position[i].vob_id_nr); | |
| 866 CHECK_ZERO(cell_position[i].zero_1); | |
| 867 } | |
| 868 | |
| 869 return 1; | |
| 870 } | |
| 871 | |
| 872 static int ifoRead_PGC(ifo_handle_t *ifofile, pgc_t *pgc, unsigned int offset) { | |
| 873 unsigned int i; | |
| 874 | |
| 875 if(!DVDFileSeek_(ifofile->file, offset)) | |
| 876 return 0; | |
| 20 | 877 |
| 3 | 878 if(!(DVDReadBytes(ifofile->file, pgc, PGC_SIZE))) |
| 879 return 0; | |
| 880 | |
| 881 read_user_ops(&pgc->prohibited_ops); | |
| 882 B2N_16(pgc->next_pgc_nr); | |
| 883 B2N_16(pgc->prev_pgc_nr); | |
| 884 B2N_16(pgc->goup_pgc_nr); | |
| 885 B2N_16(pgc->command_tbl_offset); | |
| 886 B2N_16(pgc->program_map_offset); | |
| 887 B2N_16(pgc->cell_playback_offset); | |
| 888 B2N_16(pgc->cell_position_offset); | |
| 889 | |
| 890 for(i = 0; i < 8; i++) | |
| 891 B2N_16(pgc->audio_control[i]); | |
| 892 for(i = 0; i < 32; i++) | |
| 893 B2N_32(pgc->subp_control[i]); | |
| 894 for(i = 0; i < 16; i++) | |
| 895 B2N_32(pgc->palette[i]); | |
| 20 | 896 |
| 3 | 897 CHECK_ZERO(pgc->zero_1); |
| 898 CHECK_VALUE(pgc->nr_of_programs <= pgc->nr_of_cells); | |
| 899 | |
| 900 /* verify time (look at print_time) */ | |
| 901 for(i = 0; i < 8; i++) | |
| 43 | 902 if(!(pgc->audio_control[i] & 0x8000)) /* The 'is present' bit */ |
| 3 | 903 CHECK_ZERO(pgc->audio_control[i]); |
| 904 for(i = 0; i < 32; i++) | |
| 43 | 905 if(!(pgc->subp_control[i] & 0x80000000)) /* The 'is present' bit */ |
| 3 | 906 CHECK_ZERO(pgc->subp_control[i]); |
| 20 | 907 |
| 3 | 908 /* Check that time is 0:0:0:0 also if nr_of_programs == 0 */ |
| 909 if(pgc->nr_of_programs == 0) { | |
| 910 CHECK_ZERO(pgc->still_time); | |
| 911 CHECK_ZERO(pgc->pg_playback_mode); /* ?? */ | |
| 912 CHECK_VALUE(pgc->program_map_offset == 0); | |
| 913 CHECK_VALUE(pgc->cell_playback_offset == 0); | |
| 914 CHECK_VALUE(pgc->cell_position_offset == 0); | |
| 915 } else { | |
| 916 CHECK_VALUE(pgc->program_map_offset != 0); | |
| 917 CHECK_VALUE(pgc->cell_playback_offset != 0); | |
| 918 CHECK_VALUE(pgc->cell_position_offset != 0); | |
| 919 } | |
| 20 | 920 |
| 3 | 921 if(pgc->command_tbl_offset != 0) { |
| 922 pgc->command_tbl = malloc(sizeof(pgc_command_tbl_t)); | |
| 923 if(!pgc->command_tbl) | |
| 924 return 0; | |
| 925 | |
| 20 | 926 if(!ifoRead_PGC_COMMAND_TBL(ifofile, pgc->command_tbl, |
| 3 | 927 offset + pgc->command_tbl_offset)) { |
| 928 return 0; | |
| 929 } | |
| 930 } else { | |
| 931 pgc->command_tbl = NULL; | |
| 932 } | |
| 20 | 933 |
| 3 | 934 if(pgc->program_map_offset != 0 && pgc->nr_of_programs>0) { |
| 935 pgc->program_map = malloc(pgc->nr_of_programs * sizeof(pgc_program_map_t)); | |
| 936 if(!pgc->program_map) { | |
| 937 return 0; | |
| 938 } | |
| 939 if(!ifoRead_PGC_PROGRAM_MAP(ifofile, pgc->program_map,pgc->nr_of_programs, | |
| 940 offset + pgc->program_map_offset)) { | |
| 941 return 0; | |
| 942 } | |
| 943 } else { | |
| 944 pgc->program_map = NULL; | |
| 945 } | |
| 20 | 946 |
| 3 | 947 if(pgc->cell_playback_offset != 0 && pgc->nr_of_cells>0) { |
| 948 pgc->cell_playback = malloc(pgc->nr_of_cells * sizeof(cell_playback_t)); | |
| 949 if(!pgc->cell_playback) { | |
| 950 return 0; | |
| 951 } | |
| 20 | 952 if(!ifoRead_CELL_PLAYBACK_TBL(ifofile, pgc->cell_playback, |
| 26 | 953 pgc->nr_of_cells, |
| 3 | 954 offset + pgc->cell_playback_offset)) { |
| 955 return 0; | |
| 956 } | |
| 957 } else { | |
| 958 pgc->cell_playback = NULL; | |
| 959 } | |
| 20 | 960 |
| 3 | 961 if(pgc->cell_position_offset != 0 && pgc->nr_of_cells>0) { |
| 962 pgc->cell_position = malloc(pgc->nr_of_cells * sizeof(cell_position_t)); | |
| 963 if(!pgc->cell_position) { | |
| 964 return 0; | |
| 965 } | |
| 20 | 966 if(!ifoRead_CELL_POSITION_TBL(ifofile, pgc->cell_position, |
| 26 | 967 pgc->nr_of_cells, |
| 3 | 968 offset + pgc->cell_position_offset)) { |
| 969 return 0; | |
| 970 } | |
| 971 } else { | |
| 972 pgc->cell_position = NULL; | |
| 973 } | |
| 974 | |
| 975 return 1; | |
| 976 } | |
| 977 | |
| 978 int ifoRead_FP_PGC(ifo_handle_t *ifofile) { | |
| 979 | |
| 980 if(!ifofile) | |
| 981 return 0; | |
| 982 | |
| 983 if(!ifofile->vmgi_mat) | |
| 984 return 0; | |
| 20 | 985 |
| 3 | 986 /* It seems that first_play_pgc is optional after all. */ |
| 987 ifofile->first_play_pgc = 0; | |
| 988 if(ifofile->vmgi_mat->first_play_pgc == 0) | |
| 989 return 1; | |
| 20 | 990 |
| 75 | 991 ifofile->first_play_pgc = (pgc_t *)calloc(1, sizeof(pgc_t)); |
| 3 | 992 if(!ifofile->first_play_pgc) |
| 993 return 0; | |
| 20 | 994 |
| 75 | 995 ifofile->first_play_pgc->ref_count = 1; |
| 20 | 996 if(!ifoRead_PGC(ifofile, ifofile->first_play_pgc, |
| 3 | 997 ifofile->vmgi_mat->first_play_pgc)) { |
| 75 | 998 ifoFree_PGC(&ifofile->first_play_pgc); |
| 3 | 999 return 0; |
| 1000 } | |
| 1001 | |
| 1002 return 1; | |
| 1003 } | |
| 1004 | |
| 75 | 1005 static void ifoFree_PGC(pgc_t **pgc) { |
| 1006 if(pgc && *pgc && (--(*pgc)->ref_count) <= 0) { | |
| 1007 ifoFree_PGC_COMMAND_TBL((*pgc)->command_tbl); | |
| 1008 if((*pgc)->program_map) | |
| 1009 free((*pgc)->program_map); | |
| 1010 if((*pgc)->cell_playback) | |
| 1011 free((*pgc)->cell_playback); | |
| 1012 if((*pgc)->cell_position) | |
| 1013 free((*pgc)->cell_position); | |
| 1014 free(*pgc); | |
| 1015 } | |
| 1016 if (pgc) { | |
| 1017 *pgc = NULL; | |
| 3 | 1018 } |
| 1019 } | |
| 1020 | |
| 1021 void ifoFree_FP_PGC(ifo_handle_t *ifofile) { | |
| 1022 if(!ifofile) | |
| 1023 return; | |
| 20 | 1024 |
| 3 | 1025 if(ifofile->first_play_pgc) { |
| 75 | 1026 ifoFree_PGC(&ifofile->first_play_pgc); |
| 3 | 1027 } |
| 1028 } | |
| 1029 | |
| 1030 | |
| 1031 int ifoRead_TT_SRPT(ifo_handle_t *ifofile) { | |
| 1032 tt_srpt_t *tt_srpt; | |
| 1033 int i, info_length; | |
| 1034 | |
| 1035 if(!ifofile) | |
| 1036 return 0; | |
| 1037 | |
| 1038 if(!ifofile->vmgi_mat) | |
| 1039 return 0; | |
| 1040 | |
| 1041 if(ifofile->vmgi_mat->tt_srpt == 0) /* mandatory */ | |
| 1042 return 0; | |
| 1043 | |
| 1044 if(!DVDFileSeek_(ifofile->file, ifofile->vmgi_mat->tt_srpt * DVD_BLOCK_LEN)) | |
| 1045 return 0; | |
| 1046 | |
| 1047 tt_srpt = (tt_srpt_t *)malloc(sizeof(tt_srpt_t)); | |
| 1048 if(!tt_srpt) | |
| 1049 return 0; | |
| 1050 | |
| 1051 ifofile->tt_srpt = tt_srpt; | |
| 20 | 1052 |
| 3 | 1053 if(!(DVDReadBytes(ifofile->file, tt_srpt, TT_SRPT_SIZE))) { |
| 1054 fprintf(stderr, "libdvdread: Unable to read read TT_SRPT.\n"); | |
| 1055 free(tt_srpt); | |
| 1056 return 0; | |
| 1057 } | |
| 1058 | |
| 1059 B2N_16(tt_srpt->nr_of_srpts); | |
| 1060 B2N_32(tt_srpt->last_byte); | |
| 20 | 1061 |
| 3 | 1062 info_length = tt_srpt->last_byte + 1 - TT_SRPT_SIZE; |
| 1063 | |
| 20 | 1064 tt_srpt->title = (title_info_t *)malloc(info_length); |
| 3 | 1065 if(!tt_srpt->title) { |
| 1066 free(tt_srpt); | |
| 1067 ifofile->tt_srpt = 0; | |
| 1068 return 0; | |
| 1069 } | |
| 1070 if(!(DVDReadBytes(ifofile->file, tt_srpt->title, info_length))) { | |
| 1071 fprintf(stderr, "libdvdread: Unable to read read TT_SRPT.\n"); | |
| 1072 ifoFree_TT_SRPT(ifofile); | |
| 1073 return 0; | |
| 1074 } | |
| 1075 | |
|
76
677e09255a1c
This patch fixes a segmentation fault hit when reading the DVD 'The
rathann
parents:
75
diff
changeset
|
1076 if(tt_srpt->nr_of_srpts>info_length/sizeof(title_info_t)){ |
|
677e09255a1c
This patch fixes a segmentation fault hit when reading the DVD 'The
rathann
parents:
75
diff
changeset
|
1077 fprintf(stderr,"libdvdread: data mismatch: info_length (%ld)!= nr_of_srpts (%d). Truncating.\n", |
|
677e09255a1c
This patch fixes a segmentation fault hit when reading the DVD 'The
rathann
parents:
75
diff
changeset
|
1078 info_length/sizeof(title_info_t),tt_srpt->nr_of_srpts); |
|
677e09255a1c
This patch fixes a segmentation fault hit when reading the DVD 'The
rathann
parents:
75
diff
changeset
|
1079 tt_srpt->nr_of_srpts=info_length/sizeof(title_info_t); |
|
677e09255a1c
This patch fixes a segmentation fault hit when reading the DVD 'The
rathann
parents:
75
diff
changeset
|
1080 } |
|
677e09255a1c
This patch fixes a segmentation fault hit when reading the DVD 'The
rathann
parents:
75
diff
changeset
|
1081 |
| 3 | 1082 for(i = 0; i < tt_srpt->nr_of_srpts; i++) { |
| 1083 B2N_16(tt_srpt->title[i].nr_of_ptts); | |
| 1084 B2N_16(tt_srpt->title[i].parental_id); | |
| 1085 B2N_32(tt_srpt->title[i].title_set_sector); | |
| 1086 } | |
| 20 | 1087 |
| 3 | 1088 |
| 1089 CHECK_ZERO(tt_srpt->zero_1); | |
| 1090 CHECK_VALUE(tt_srpt->nr_of_srpts != 0); | |
| 1091 CHECK_VALUE(tt_srpt->nr_of_srpts < 100); /* ?? */ | |
| 1092 CHECK_VALUE((int)tt_srpt->nr_of_srpts * sizeof(title_info_t) <= info_length); | |
| 20 | 1093 |
| 3 | 1094 for(i = 0; i < tt_srpt->nr_of_srpts; i++) { |
| 1095 read_playback_type(&tt_srpt->title[i].pb_ty); | |
| 1096 CHECK_VALUE(tt_srpt->title[i].pb_ty.zero_1 == 0); | |
| 1097 CHECK_VALUE(tt_srpt->title[i].nr_of_angles != 0); | |
| 1098 CHECK_VALUE(tt_srpt->title[i].nr_of_angles < 10); | |
| 1099 /* CHECK_VALUE(tt_srpt->title[i].nr_of_ptts != 0); */ | |
| 1100 /* XXX: this assertion breaks Ghostbusters: */ | |
| 1101 CHECK_VALUE(tt_srpt->title[i].nr_of_ptts < 1000); /* ?? */ | |
| 1102 CHECK_VALUE(tt_srpt->title[i].title_set_nr != 0); | |
| 1103 CHECK_VALUE(tt_srpt->title[i].title_set_nr < 100); /* ?? */ | |
| 1104 CHECK_VALUE(tt_srpt->title[i].vts_ttn != 0); | |
| 1105 CHECK_VALUE(tt_srpt->title[i].vts_ttn < 100); /* ?? */ | |
| 1106 /* CHECK_VALUE(tt_srpt->title[i].title_set_sector != 0); */ | |
| 1107 } | |
| 20 | 1108 |
| 3 | 1109 /* Make this a function */ |
| 1110 #if 0 | |
| 20 | 1111 if(memcmp((uint8_t *)tt_srpt->title + |
| 1112 tt_srpt->nr_of_srpts * sizeof(title_info_t), | |
| 1113 my_friendly_zeros, | |
| 3 | 1114 info_length - tt_srpt->nr_of_srpts * sizeof(title_info_t))) { |
| 1115 fprintf(stderr, "VMG_PTT_SRPT slack is != 0, "); | |
| 20 | 1116 hexdump((uint8_t *)tt_srpt->title + |
| 1117 tt_srpt->nr_of_srpts * sizeof(title_info_t), | |
| 3 | 1118 info_length - tt_srpt->nr_of_srpts * sizeof(title_info_t)); |
| 1119 } | |
| 1120 #endif | |
| 1121 | |
| 1122 return 1; | |
| 1123 } | |
| 1124 | |
| 1125 | |
| 1126 void ifoFree_TT_SRPT(ifo_handle_t *ifofile) { | |
| 1127 if(!ifofile) | |
| 1128 return; | |
| 20 | 1129 |
| 3 | 1130 if(ifofile->tt_srpt) { |
| 1131 free(ifofile->tt_srpt->title); | |
| 1132 free(ifofile->tt_srpt); | |
| 1133 ifofile->tt_srpt = 0; | |
| 1134 } | |
| 1135 } | |
| 1136 | |
| 1137 | |
| 1138 int ifoRead_VTS_PTT_SRPT(ifo_handle_t *ifofile) { | |
| 68 | 1139 vts_ptt_srpt_t *vts_ptt_srpt = NULL; |
| 3 | 1140 int info_length, i, j; |
| 67 | 1141 uint32_t *data = NULL; |
| 3 | 1142 |
| 1143 if(!ifofile) | |
| 1144 return 0; | |
| 20 | 1145 |
| 3 | 1146 if(!ifofile->vtsi_mat) |
| 1147 return 0; | |
| 1148 | |
| 1149 if(ifofile->vtsi_mat->vts_ptt_srpt == 0) /* mandatory */ | |
| 1150 return 0; | |
| 20 | 1151 |
| 3 | 1152 if(!DVDFileSeek_(ifofile->file, |
| 26 | 1153 ifofile->vtsi_mat->vts_ptt_srpt * DVD_BLOCK_LEN)) |
| 3 | 1154 return 0; |
| 1155 | |
| 67 | 1156 vts_ptt_srpt = malloc(sizeof(vts_ptt_srpt_t)); |
| 3 | 1157 if(!vts_ptt_srpt) |
| 1158 return 0; | |
| 1159 | |
| 71 | 1160 vts_ptt_srpt->title = NULL; |
| 3 | 1161 ifofile->vts_ptt_srpt = vts_ptt_srpt; |
| 1162 | |
| 1163 if(!(DVDReadBytes(ifofile->file, vts_ptt_srpt, VTS_PTT_SRPT_SIZE))) { | |
| 1164 fprintf(stderr, "libdvdread: Unable to read PTT search table.\n"); | |
| 68 | 1165 goto fail; |
| 3 | 1166 } |
| 1167 | |
| 1168 B2N_16(vts_ptt_srpt->nr_of_srpts); | |
| 1169 B2N_32(vts_ptt_srpt->last_byte); | |
| 1170 | |
| 1171 CHECK_ZERO(vts_ptt_srpt->zero_1); | |
| 1172 CHECK_VALUE(vts_ptt_srpt->nr_of_srpts != 0); | |
| 1173 CHECK_VALUE(vts_ptt_srpt->nr_of_srpts < 100); /* ?? */ | |
| 20 | 1174 |
| 3 | 1175 info_length = vts_ptt_srpt->last_byte + 1 - VTS_PTT_SRPT_SIZE; |
| 67 | 1176 data = malloc(info_length); |
| 69 | 1177 if(!data) |
| 68 | 1178 goto fail; |
| 69 | 1179 |
| 3 | 1180 if(!(DVDReadBytes(ifofile->file, data, info_length))) { |
| 1181 fprintf(stderr, "libdvdread: Unable to read PTT search table.\n"); | |
| 68 | 1182 goto fail; |
| 3 | 1183 } |
| 1184 | |
| 70 | 1185 if(vts_ptt_srpt->nr_of_srpts > info_length / sizeof(*data)) { |
| 1186 fprintf(stderr, "libdvdread: PTT search table too small.\n"); | |
| 1187 goto fail; | |
| 1188 } | |
| 91 | 1189 |
| 1190 if(vts_ptt_srpt->nr_of_srpts == 0) { | |
| 1191 fprintf(stderr, "libdvdread: Zero entries in PTT search table.\n"); | |
| 1192 goto fail; | |
| 1193 } | |
| 1194 | |
| 3 | 1195 for(i = 0; i < vts_ptt_srpt->nr_of_srpts; i++) { |
|
83
bed968b9bd99
If the start offset points past the last_byte (outside the region read) stop
rathann
parents:
77
diff
changeset
|
1196 /* Transformers 3 has PTT start bytes that point outside the SRPT PTT */ |
|
bed968b9bd99
If the start offset points past the last_byte (outside the region read) stop
rathann
parents:
77
diff
changeset
|
1197 uint32_t start = data[i]; |
|
bed968b9bd99
If the start offset points past the last_byte (outside the region read) stop
rathann
parents:
77
diff
changeset
|
1198 B2N_32(start); |
|
bed968b9bd99
If the start offset points past the last_byte (outside the region read) stop
rathann
parents:
77
diff
changeset
|
1199 if(start + sizeof(ptt_info_t) > vts_ptt_srpt->last_byte + 1) { |
|
bed968b9bd99
If the start offset points past the last_byte (outside the region read) stop
rathann
parents:
77
diff
changeset
|
1200 /* don't mess with any bytes beyond the end of the allocation */ |
|
bed968b9bd99
If the start offset points past the last_byte (outside the region read) stop
rathann
parents:
77
diff
changeset
|
1201 vts_ptt_srpt->nr_of_srpts = i; |
|
bed968b9bd99
If the start offset points past the last_byte (outside the region read) stop
rathann
parents:
77
diff
changeset
|
1202 break; |
|
bed968b9bd99
If the start offset points past the last_byte (outside the region read) stop
rathann
parents:
77
diff
changeset
|
1203 } |
|
bed968b9bd99
If the start offset points past the last_byte (outside the region read) stop
rathann
parents:
77
diff
changeset
|
1204 data[i] = start; |
| 3 | 1205 /* assert(data[i] + sizeof(ptt_info_t) <= vts_ptt_srpt->last_byte + 1); |
| 20 | 1206 Magic Knight Rayearth Daybreak is mastered very strange and has |
| 3 | 1207 Titles with 0 PTTs. They all have a data[i] offsets beyond the end of |
| 1208 of the vts_ptt_srpt structure. */ | |
| 1209 CHECK_VALUE(data[i] + sizeof(ptt_info_t) <= vts_ptt_srpt->last_byte + 1 + 4); | |
| 1210 } | |
| 20 | 1211 |
| 3 | 1212 vts_ptt_srpt->ttu_offset = data; |
| 20 | 1213 |
| 3 | 1214 vts_ptt_srpt->title = malloc(vts_ptt_srpt->nr_of_srpts * sizeof(ttu_t)); |
| 69 | 1215 if(!vts_ptt_srpt->title) |
| 68 | 1216 goto fail; |
| 69 | 1217 |
| 3 | 1218 for(i = 0; i < vts_ptt_srpt->nr_of_srpts; i++) { |
| 1219 int n; | |
| 1220 if(i < vts_ptt_srpt->nr_of_srpts - 1) | |
| 1221 n = (data[i+1] - data[i]); | |
| 1222 else | |
| 1223 n = (vts_ptt_srpt->last_byte + 1 - data[i]); | |
| 69 | 1224 |
| 3 | 1225 /* assert(n > 0 && (n % 4) == 0); |
| 20 | 1226 Magic Knight Rayearth Daybreak is mastered very strange and has |
| 3 | 1227 Titles with 0 PTTs. */ |
| 1228 if(n < 0) n = 0; | |
| 69 | 1229 |
|
87
1a6394166cce
Document warnings generated by DVDs made with the VDR-to-DVD device LG RC590M.
rathann
parents:
83
diff
changeset
|
1230 /* DVDs created by the VDR-to-DVD device LG RC590M violate the following requirement */ |
| 3 | 1231 CHECK_VALUE(n % 4 == 0); |
| 20 | 1232 |
| 3 | 1233 vts_ptt_srpt->title[i].nr_of_ptts = n / 4; |
| 1234 vts_ptt_srpt->title[i].ptt = malloc(n * sizeof(ptt_info_t)); | |
| 1235 if(!vts_ptt_srpt->title[i].ptt) { | |
| 1236 for(n = 0; n < i; n++) | |
| 1237 free(vts_ptt_srpt->title[n].ptt); | |
| 68 | 1238 |
| 1239 goto fail; | |
| 3 | 1240 } |
| 1241 for(j = 0; j < vts_ptt_srpt->title[i].nr_of_ptts; j++) { | |
| 1242 /* The assert placed here because of Magic Knight Rayearth Daybreak */ | |
| 1243 CHECK_VALUE(data[i] + sizeof(ptt_info_t) <= vts_ptt_srpt->last_byte + 1); | |
| 20 | 1244 vts_ptt_srpt->title[i].ptt[j].pgcn |
| 3 | 1245 = *(uint16_t*)(((char *)data) + data[i] + 4*j - VTS_PTT_SRPT_SIZE); |
| 20 | 1246 vts_ptt_srpt->title[i].ptt[j].pgn |
| 3 | 1247 = *(uint16_t*)(((char *)data) + data[i] + 4*j + 2 - VTS_PTT_SRPT_SIZE); |
| 1248 } | |
| 1249 } | |
| 20 | 1250 |
| 3 | 1251 for(i = 0; i < vts_ptt_srpt->nr_of_srpts; i++) { |
| 1252 for(j = 0; j < vts_ptt_srpt->title[i].nr_of_ptts; j++) { | |
| 1253 B2N_16(vts_ptt_srpt->title[i].ptt[j].pgcn); | |
| 1254 B2N_16(vts_ptt_srpt->title[i].ptt[j].pgn); | |
| 1255 } | |
| 1256 } | |
| 20 | 1257 |
| 3 | 1258 for(i = 0; i < vts_ptt_srpt->nr_of_srpts; i++) { |
| 1259 CHECK_VALUE(vts_ptt_srpt->title[i].nr_of_ptts < 1000); /* ?? */ | |
| 1260 for(j = 0; j < vts_ptt_srpt->title[i].nr_of_ptts; j++) { | |
| 1261 CHECK_VALUE(vts_ptt_srpt->title[i].ptt[j].pgcn != 0 ); | |
| 1262 CHECK_VALUE(vts_ptt_srpt->title[i].ptt[j].pgcn < 1000); /* ?? */ | |
| 1263 CHECK_VALUE(vts_ptt_srpt->title[i].ptt[j].pgn != 0); | |
| 1264 CHECK_VALUE(vts_ptt_srpt->title[i].ptt[j].pgn < 100); /* ?? */ | |
| 75 | 1265 if (vts_ptt_srpt->title[i].ptt[j].pgcn == 0 || |
| 1266 vts_ptt_srpt->title[i].ptt[j].pgcn >= 1000 || | |
| 1267 vts_ptt_srpt->title[i].ptt[j].pgn == 0 || | |
| 1268 vts_ptt_srpt->title[i].ptt[j].pgn >= 100) { | |
| 1269 return 0; | |
| 1270 } | |
| 1271 | |
| 3 | 1272 } |
| 1273 } | |
| 1274 | |
| 1275 return 1; | |
| 68 | 1276 |
| 1277 fail: | |
| 1278 free(data); | |
| 1279 ifofile->vts_ptt_srpt = 0; | |
| 71 | 1280 free(vts_ptt_srpt->title); |
| 68 | 1281 free(vts_ptt_srpt); |
| 1282 return 0; | |
| 3 | 1283 } |
| 1284 | |
| 1285 | |
| 1286 void ifoFree_VTS_PTT_SRPT(ifo_handle_t *ifofile) { | |
| 1287 if(!ifofile) | |
| 1288 return; | |
| 20 | 1289 |
| 3 | 1290 if(ifofile->vts_ptt_srpt) { |
| 1291 int i; | |
| 1292 for(i = 0; i < ifofile->vts_ptt_srpt->nr_of_srpts; i++) | |
| 1293 free(ifofile->vts_ptt_srpt->title[i].ptt); | |
| 1294 free(ifofile->vts_ptt_srpt->ttu_offset); | |
| 1295 free(ifofile->vts_ptt_srpt->title); | |
| 1296 free(ifofile->vts_ptt_srpt); | |
| 1297 ifofile->vts_ptt_srpt = 0; | |
| 1298 } | |
| 1299 } | |
| 1300 | |
| 1301 | |
| 1302 int ifoRead_PTL_MAIT(ifo_handle_t *ifofile) { | |
| 1303 ptl_mait_t *ptl_mait; | |
| 1304 int info_length; | |
| 1305 unsigned int i, j; | |
| 1306 | |
| 1307 if(!ifofile) | |
| 1308 return 0; | |
| 20 | 1309 |
| 3 | 1310 if(!ifofile->vmgi_mat) |
| 1311 return 0; | |
| 20 | 1312 |
| 92 | 1313 if(ifofile->vmgi_mat->ptl_mait == 0) |
| 3 | 1314 return 1; |
| 1315 | |
| 1316 if(!DVDFileSeek_(ifofile->file, ifofile->vmgi_mat->ptl_mait * DVD_BLOCK_LEN)) | |
| 1317 return 0; | |
| 1318 | |
| 1319 ptl_mait = (ptl_mait_t *)malloc(sizeof(ptl_mait_t)); | |
| 1320 if(!ptl_mait) | |
| 1321 return 0; | |
| 1322 | |
| 1323 ifofile->ptl_mait = ptl_mait; | |
| 1324 | |
| 1325 if(!(DVDReadBytes(ifofile->file, ptl_mait, PTL_MAIT_SIZE))) { | |
| 1326 free(ptl_mait); | |
| 74 | 1327 ifofile->ptl_mait = NULL; |
| 3 | 1328 return 0; |
| 1329 } | |
| 1330 | |
| 1331 B2N_16(ptl_mait->nr_of_countries); | |
| 1332 B2N_16(ptl_mait->nr_of_vtss); | |
| 1333 B2N_32(ptl_mait->last_byte); | |
| 20 | 1334 |
| 3 | 1335 CHECK_VALUE(ptl_mait->nr_of_countries != 0); |
| 1336 CHECK_VALUE(ptl_mait->nr_of_countries < 100); /* ?? */ | |
| 1337 CHECK_VALUE(ptl_mait->nr_of_vtss != 0); | |
| 1338 CHECK_VALUE(ptl_mait->nr_of_vtss < 100); /* ?? */ | |
| 20 | 1339 CHECK_VALUE(ptl_mait->nr_of_countries * PTL_MAIT_COUNTRY_SIZE |
| 26 | 1340 <= ptl_mait->last_byte + 1 - PTL_MAIT_SIZE); |
| 20 | 1341 |
| 3 | 1342 info_length = ptl_mait->nr_of_countries * sizeof(ptl_mait_country_t); |
| 1343 ptl_mait->countries = (ptl_mait_country_t *)malloc(info_length); | |
| 1344 if(!ptl_mait->countries) { | |
| 1345 free(ptl_mait); | |
| 74 | 1346 ifofile->ptl_mait = NULL; |
| 3 | 1347 return 0; |
| 1348 } | |
| 63 | 1349 for(i = 0; i < ptl_mait->nr_of_countries; i++) { |
| 1350 ptl_mait->countries[i].pf_ptl_mai = NULL; | |
| 1351 } | |
| 20 | 1352 |
| 3 | 1353 for(i = 0; i < ptl_mait->nr_of_countries; i++) { |
| 1354 if(!(DVDReadBytes(ifofile->file, &ptl_mait->countries[i], PTL_MAIT_COUNTRY_SIZE))) { | |
| 1355 fprintf(stderr, "libdvdread: Unable to read PTL_MAIT.\n"); | |
| 1356 free(ptl_mait->countries); | |
| 1357 free(ptl_mait); | |
| 74 | 1358 ifofile->ptl_mait = NULL; |
| 3 | 1359 return 0; |
| 1360 } | |
| 1361 } | |
| 1362 | |
| 1363 for(i = 0; i < ptl_mait->nr_of_countries; i++) { | |
| 1364 B2N_16(ptl_mait->countries[i].country_code); | |
| 1365 B2N_16(ptl_mait->countries[i].pf_ptl_mai_start_byte); | |
| 1366 } | |
| 20 | 1367 |
| 3 | 1368 for(i = 0; i < ptl_mait->nr_of_countries; i++) { |
| 1369 CHECK_ZERO(ptl_mait->countries[i].zero_1); | |
| 20 | 1370 CHECK_ZERO(ptl_mait->countries[i].zero_2); |
| 3 | 1371 CHECK_VALUE(ptl_mait->countries[i].pf_ptl_mai_start_byte |
| 64 | 1372 + sizeof(pf_level_t) * (ptl_mait->nr_of_vtss + 1) <= ptl_mait->last_byte + 1); |
| 3 | 1373 } |
| 1374 | |
| 1375 for(i = 0; i < ptl_mait->nr_of_countries; i++) { | |
| 1376 uint16_t *pf_temp; | |
| 20 | 1377 |
| 1378 if(!DVDFileSeek_(ifofile->file, | |
| 26 | 1379 ifofile->vmgi_mat->ptl_mait * DVD_BLOCK_LEN |
| 3 | 1380 + ptl_mait->countries[i].pf_ptl_mai_start_byte)) { |
| 65 | 1381 fprintf(stderr, "libdvdread: Unable to seek PTL_MAIT table at index %d.\n",i); |
| 3 | 1382 free(ptl_mait->countries); |
| 1383 free(ptl_mait); | |
| 63 | 1384 ifofile->ptl_mait = NULL; |
| 3 | 1385 return 0; |
| 1386 } | |
| 1387 info_length = (ptl_mait->nr_of_vtss + 1) * sizeof(pf_level_t); | |
| 1388 pf_temp = (uint16_t *)malloc(info_length); | |
| 1389 if(!pf_temp) { | |
|
12
056f5573a7dc
moved various pieces of duplicated code to free_ptl_mait(); patch by Erik Hovland org
nicodvb
parents:
3
diff
changeset
|
1390 free_ptl_mait(ptl_mait, i); |
| 63 | 1391 ifofile->ptl_mait = NULL; |
| 3 | 1392 return 0; |
| 1393 } | |
| 89 | 1394 memset(pf_temp, 0, info_length); |
| 3 | 1395 if(!(DVDReadBytes(ifofile->file, pf_temp, info_length))) { |
| 65 | 1396 fprintf(stderr, "libdvdread: Unable to read PTL_MAIT table at index %d.\n",i); |
|
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
1397 free(pf_temp); |
|
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
1398 free_ptl_mait(ptl_mait, i); |
| 63 | 1399 ifofile->ptl_mait = NULL; |
|
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
1400 return 0; |
| 3 | 1401 } |
| 1402 for (j = 0; j < ((ptl_mait->nr_of_vtss + 1) * 8); j++) { | |
|
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
1403 B2N_16(pf_temp[j]); |
| 3 | 1404 } |
| 1405 ptl_mait->countries[i].pf_ptl_mai = (pf_level_t *)malloc(info_length); | |
| 1406 if(!ptl_mait->countries[i].pf_ptl_mai) { | |
| 1407 free(pf_temp); | |
|
12
056f5573a7dc
moved various pieces of duplicated code to free_ptl_mait(); patch by Erik Hovland org
nicodvb
parents:
3
diff
changeset
|
1408 free_ptl_mait(ptl_mait, i); |
| 63 | 1409 ifofile->ptl_mait = NULL; |
| 3 | 1410 return 0; |
| 1411 } | |
| 1412 { /* Transpose the array so we can use C indexing. */ | |
| 1413 int level, vts; | |
| 64 | 1414 for(level = 0; level < PTL_MAIT_NUM_LEVEL; level++) { |
| 26 | 1415 for(vts = 0; vts <= ptl_mait->nr_of_vtss; vts++) { |
| 1416 ptl_mait->countries[i].pf_ptl_mai[vts][level] = | |
| 1417 pf_temp[(7-level)*(ptl_mait->nr_of_vtss+1) + vts]; | |
| 1418 } | |
| 3 | 1419 } |
| 1420 free(pf_temp); | |
| 1421 } | |
| 1422 } | |
| 1423 return 1; | |
| 1424 } | |
| 1425 | |
| 1426 void ifoFree_PTL_MAIT(ifo_handle_t *ifofile) { | |
| 1427 unsigned int i; | |
| 20 | 1428 |
| 3 | 1429 if(!ifofile) |
| 1430 return; | |
| 20 | 1431 |
| 3 | 1432 if(ifofile->ptl_mait) { |
| 1433 for(i = 0; i < ifofile->ptl_mait->nr_of_countries; i++) { | |
|
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
1434 free(ifofile->ptl_mait->countries[i].pf_ptl_mai); |
| 3 | 1435 } |
| 1436 free(ifofile->ptl_mait->countries); | |
| 1437 free(ifofile->ptl_mait); | |
| 74 | 1438 ifofile->ptl_mait = NULL; |
| 3 | 1439 } |
| 1440 } | |
| 1441 | |
| 1442 int ifoRead_VTS_TMAPT(ifo_handle_t *ifofile) { | |
| 1443 vts_tmapt_t *vts_tmapt; | |
| 1444 uint32_t *vts_tmap_srp; | |
| 1445 unsigned int offset; | |
| 1446 int info_length; | |
| 1447 unsigned int i, j; | |
| 20 | 1448 |
| 3 | 1449 if(!ifofile) |
| 1450 return 0; | |
| 1451 | |
| 1452 if(!ifofile->vtsi_mat) | |
| 1453 return 0; | |
| 1454 | |
| 1455 if(ifofile->vtsi_mat->vts_tmapt == 0) { /* optional(?) */ | |
| 1456 ifofile->vts_tmapt = NULL; | |
| 88 | 1457 fprintf(stderr,"libdvdread: No VTS_TMAPT available - skipping.\n"); |
| 3 | 1458 return 1; |
| 1459 } | |
| 20 | 1460 |
| 3 | 1461 offset = ifofile->vtsi_mat->vts_tmapt * DVD_BLOCK_LEN; |
| 20 | 1462 |
| 1463 if(!DVDFileSeek_(ifofile->file, offset)) | |
| 3 | 1464 return 0; |
| 20 | 1465 |
| 3 | 1466 vts_tmapt = (vts_tmapt_t *)malloc(sizeof(vts_tmapt_t)); |
| 1467 if(!vts_tmapt) | |
| 1468 return 0; | |
| 20 | 1469 |
| 3 | 1470 ifofile->vts_tmapt = vts_tmapt; |
| 20 | 1471 |
| 3 | 1472 if(!(DVDReadBytes(ifofile->file, vts_tmapt, VTS_TMAPT_SIZE))) { |
| 1473 fprintf(stderr, "libdvdread: Unable to read VTS_TMAPT.\n"); | |
| 1474 free(vts_tmapt); | |
| 1475 ifofile->vts_tmapt = NULL; | |
| 1476 return 0; | |
| 1477 } | |
| 1478 | |
| 1479 B2N_16(vts_tmapt->nr_of_tmaps); | |
| 1480 B2N_32(vts_tmapt->last_byte); | |
| 20 | 1481 |
| 3 | 1482 CHECK_ZERO(vts_tmapt->zero_1); |
| 20 | 1483 |
| 3 | 1484 info_length = vts_tmapt->nr_of_tmaps * 4; |
| 20 | 1485 |
| 3 | 1486 vts_tmap_srp = (uint32_t *)malloc(info_length); |
| 1487 if(!vts_tmap_srp) { | |
| 1488 free(vts_tmapt); | |
| 1489 ifofile->vts_tmapt = NULL; | |
| 1490 return 0; | |
| 1491 } | |
| 1492 | |
| 1493 vts_tmapt->tmap_offset = vts_tmap_srp; | |
| 20 | 1494 |
| 3 | 1495 if(!(DVDReadBytes(ifofile->file, vts_tmap_srp, info_length))) { |
| 1496 fprintf(stderr, "libdvdread: Unable to read VTS_TMAPT.\n"); | |
| 1497 free(vts_tmap_srp); | |
| 1498 free(vts_tmapt); | |
| 1499 ifofile->vts_tmapt = NULL; | |
| 1500 return 0; | |
| 1501 } | |
| 1502 | |
| 1503 for (i = 0; i < vts_tmapt->nr_of_tmaps; i++) { | |
|
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
1504 B2N_32(vts_tmap_srp[i]); |
| 3 | 1505 } |
| 1506 | |
| 20 | 1507 |
| 3 | 1508 info_length = vts_tmapt->nr_of_tmaps * sizeof(vts_tmap_t); |
| 20 | 1509 |
| 3 | 1510 vts_tmapt->tmap = (vts_tmap_t *)malloc(info_length); |
| 1511 if(!vts_tmapt->tmap) { | |
| 1512 free(vts_tmap_srp); | |
| 1513 free(vts_tmapt); | |
| 1514 ifofile->vts_tmapt = NULL; | |
| 1515 return 0; | |
| 1516 } | |
| 1517 | |
| 1518 memset(vts_tmapt->tmap, 0, info_length); /* So ifoFree_VTS_TMAPT works. */ | |
| 20 | 1519 |
| 3 | 1520 for(i = 0; i < vts_tmapt->nr_of_tmaps; i++) { |
| 1521 if(!DVDFileSeek_(ifofile->file, offset + vts_tmap_srp[i])) { | |
| 1522 ifoFree_VTS_TMAPT(ifofile); | |
| 1523 return 0; | |
| 1524 } | |
| 1525 | |
| 1526 if(!(DVDReadBytes(ifofile->file, &vts_tmapt->tmap[i], VTS_TMAP_SIZE))) { | |
| 1527 fprintf(stderr, "libdvdread: Unable to read VTS_TMAP.\n"); | |
| 1528 ifoFree_VTS_TMAPT(ifofile); | |
| 1529 return 0; | |
| 1530 } | |
| 20 | 1531 |
| 3 | 1532 B2N_16(vts_tmapt->tmap[i].nr_of_entries); |
| 1533 CHECK_ZERO(vts_tmapt->tmap[i].zero_1); | |
| 20 | 1534 |
| 3 | 1535 if(vts_tmapt->tmap[i].nr_of_entries == 0) { /* Early out if zero entries */ |
| 1536 vts_tmapt->tmap[i].map_ent = NULL; | |
| 1537 continue; | |
| 1538 } | |
| 20 | 1539 |
| 3 | 1540 info_length = vts_tmapt->tmap[i].nr_of_entries * sizeof(map_ent_t); |
| 20 | 1541 |
| 3 | 1542 vts_tmapt->tmap[i].map_ent = (map_ent_t *)malloc(info_length); |
| 1543 if(!vts_tmapt->tmap[i].map_ent) { | |
| 1544 ifoFree_VTS_TMAPT(ifofile); | |
| 1545 return 0; | |
| 1546 } | |
| 1547 | |
| 1548 if(!(DVDReadBytes(ifofile->file, vts_tmapt->tmap[i].map_ent, info_length))) { | |
| 1549 fprintf(stderr, "libdvdread: Unable to read VTS_TMAP_ENT.\n"); | |
| 1550 ifoFree_VTS_TMAPT(ifofile); | |
| 1551 return 0; | |
| 1552 } | |
| 20 | 1553 |
| 3 | 1554 for(j = 0; j < vts_tmapt->tmap[i].nr_of_entries; j++) |
| 1555 B2N_32(vts_tmapt->tmap[i].map_ent[j]); | |
| 20 | 1556 } |
| 1557 | |
| 3 | 1558 return 1; |
| 1559 } | |
| 1560 | |
| 1561 void ifoFree_VTS_TMAPT(ifo_handle_t *ifofile) { | |
| 1562 unsigned int i; | |
| 20 | 1563 |
| 3 | 1564 if(!ifofile) |
| 1565 return; | |
| 20 | 1566 |
| 1567 if(ifofile->vts_tmapt) { | |
| 3 | 1568 for(i = 0; i < ifofile->vts_tmapt->nr_of_tmaps; i++) |
| 1569 if(ifofile->vts_tmapt->tmap[i].map_ent) | |
| 26 | 1570 free(ifofile->vts_tmapt->tmap[i].map_ent); |
| 3 | 1571 free(ifofile->vts_tmapt->tmap); |
| 1572 free(ifofile->vts_tmapt->tmap_offset); | |
| 1573 free(ifofile->vts_tmapt); | |
| 1574 ifofile->vts_tmapt = NULL; | |
| 1575 } | |
| 1576 } | |
| 1577 | |
| 1578 | |
| 1579 int ifoRead_TITLE_C_ADT(ifo_handle_t *ifofile) { | |
| 1580 | |
| 1581 if(!ifofile) | |
| 1582 return 0; | |
| 1583 | |
| 1584 if(!ifofile->vtsi_mat) | |
| 1585 return 0; | |
| 1586 | |
| 1587 if(ifofile->vtsi_mat->vts_c_adt == 0) /* mandatory */ | |
| 1588 return 0; | |
| 1589 | |
| 1590 ifofile->vts_c_adt = (c_adt_t *)malloc(sizeof(c_adt_t)); | |
| 1591 if(!ifofile->vts_c_adt) | |
| 1592 return 0; | |
| 1593 | |
| 20 | 1594 if(!ifoRead_C_ADT_internal(ifofile, ifofile->vts_c_adt, |
| 3 | 1595 ifofile->vtsi_mat->vts_c_adt)) { |
| 1596 free(ifofile->vts_c_adt); | |
| 1597 ifofile->vts_c_adt = 0; | |
| 1598 return 0; | |
| 1599 } | |
| 1600 | |
| 1601 return 1; | |
| 1602 } | |
| 1603 | |
| 1604 int ifoRead_C_ADT(ifo_handle_t *ifofile) { | |
| 1605 unsigned int sector; | |
| 1606 | |
| 1607 if(!ifofile) | |
| 1608 return 0; | |
| 20 | 1609 |
| 3 | 1610 if(ifofile->vmgi_mat) { |
| 1611 if(ifofile->vmgi_mat->vmgm_c_adt == 0) | |
| 1612 return 1; | |
| 1613 sector = ifofile->vmgi_mat->vmgm_c_adt; | |
| 1614 } else if(ifofile->vtsi_mat) { | |
| 1615 if(ifofile->vtsi_mat->vtsm_c_adt == 0) | |
| 1616 return 1; | |
| 1617 sector = ifofile->vtsi_mat->vtsm_c_adt; | |
| 1618 } else { | |
| 1619 return 0; | |
| 1620 } | |
| 20 | 1621 |
| 3 | 1622 ifofile->menu_c_adt = (c_adt_t *)malloc(sizeof(c_adt_t)); |
| 1623 if(!ifofile->menu_c_adt) | |
| 1624 return 0; | |
| 1625 | |
| 1626 if(!ifoRead_C_ADT_internal(ifofile, ifofile->menu_c_adt, sector)) { | |
| 1627 free(ifofile->menu_c_adt); | |
| 1628 ifofile->menu_c_adt = 0; | |
| 1629 return 0; | |
| 1630 } | |
| 1631 | |
| 1632 return 1; | |
| 1633 } | |
| 1634 | |
| 20 | 1635 static int ifoRead_C_ADT_internal(ifo_handle_t *ifofile, |
| 3 | 1636 c_adt_t *c_adt, unsigned int sector) { |
| 1637 int i, info_length; | |
| 1638 | |
| 1639 if(!DVDFileSeek_(ifofile->file, sector * DVD_BLOCK_LEN)) | |
| 1640 return 0; | |
| 1641 | |
| 1642 if(!(DVDReadBytes(ifofile->file, c_adt, C_ADT_SIZE))) | |
| 1643 return 0; | |
| 1644 | |
| 1645 B2N_16(c_adt->nr_of_vobs); | |
| 1646 B2N_32(c_adt->last_byte); | |
| 20 | 1647 |
| 3 | 1648 info_length = c_adt->last_byte + 1 - C_ADT_SIZE; |
| 20 | 1649 |
| 3 | 1650 CHECK_ZERO(c_adt->zero_1); |
| 20 | 1651 /* assert(c_adt->nr_of_vobs > 0); |
| 1652 Magic Knight Rayearth Daybreak is mastered very strange and has | |
| 3 | 1653 Titles with a VOBS that has no cells. */ |
| 1654 CHECK_VALUE(info_length % sizeof(cell_adr_t) == 0); | |
| 20 | 1655 |
| 3 | 1656 /* assert(info_length / sizeof(cell_adr_t) >= c_adt->nr_of_vobs); |
| 1657 Enemy of the State region 2 (de) has Titles where nr_of_vobs field | |
| 1658 is to high, they high ones are never referenced though. */ | |
| 1659 if(info_length / sizeof(cell_adr_t) < c_adt->nr_of_vobs) { | |
| 61 | 1660 fprintf(stderr, "libdvdread: *C_ADT nr_of_vobs > available info entries\n"); |
| 3 | 1661 c_adt->nr_of_vobs = info_length / sizeof(cell_adr_t); |
| 1662 } | |
| 20 | 1663 |
| 3 | 1664 c_adt->cell_adr_table = (cell_adr_t *)malloc(info_length); |
| 1665 if(!c_adt->cell_adr_table) | |
| 1666 return 0; | |
| 1667 | |
| 20 | 1668 if(info_length && |
| 3 | 1669 !(DVDReadBytes(ifofile->file, c_adt->cell_adr_table, info_length))) { |
| 1670 free(c_adt->cell_adr_table); | |
| 1671 return 0; | |
| 1672 } | |
| 1673 | |
| 1674 for(i = 0; i < info_length/sizeof(cell_adr_t); i++) { | |
| 1675 B2N_16(c_adt->cell_adr_table[i].vob_id); | |
| 1676 B2N_32(c_adt->cell_adr_table[i].start_sector); | |
| 1677 B2N_32(c_adt->cell_adr_table[i].last_sector); | |
| 1678 | |
| 1679 CHECK_ZERO(c_adt->cell_adr_table[i].zero_1); | |
| 1680 CHECK_VALUE(c_adt->cell_adr_table[i].vob_id > 0); | |
| 1681 CHECK_VALUE(c_adt->cell_adr_table[i].vob_id <= c_adt->nr_of_vobs); | |
| 1682 CHECK_VALUE(c_adt->cell_adr_table[i].cell_id > 0); | |
| 20 | 1683 CHECK_VALUE(c_adt->cell_adr_table[i].start_sector < |
|
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
1684 c_adt->cell_adr_table[i].last_sector); |
| 3 | 1685 } |
| 1686 | |
| 1687 return 1; | |
| 1688 } | |
| 1689 | |
| 1690 | |
| 1691 static void ifoFree_C_ADT_internal(c_adt_t *c_adt) { | |
| 1692 if(c_adt) { | |
| 1693 free(c_adt->cell_adr_table); | |
| 1694 free(c_adt); | |
| 1695 } | |
| 1696 } | |
| 1697 | |
| 1698 void ifoFree_C_ADT(ifo_handle_t *ifofile) { | |
| 1699 if(!ifofile) | |
| 1700 return; | |
| 20 | 1701 |
| 3 | 1702 ifoFree_C_ADT_internal(ifofile->menu_c_adt); |
| 1703 ifofile->menu_c_adt = 0; | |
| 1704 } | |
| 1705 | |
| 1706 void ifoFree_TITLE_C_ADT(ifo_handle_t *ifofile) { | |
| 1707 if(!ifofile) | |
| 1708 return; | |
| 20 | 1709 |
| 3 | 1710 ifoFree_C_ADT_internal(ifofile->vts_c_adt); |
| 1711 ifofile->vts_c_adt = 0; | |
| 1712 } | |
| 1713 | |
| 1714 int ifoRead_TITLE_VOBU_ADMAP(ifo_handle_t *ifofile) { | |
| 1715 if(!ifofile) | |
| 1716 return 0; | |
| 1717 | |
| 1718 if(!ifofile->vtsi_mat) | |
| 1719 return 0; | |
| 20 | 1720 |
| 3 | 1721 if(ifofile->vtsi_mat->vts_vobu_admap == 0) /* mandatory */ |
| 1722 return 0; | |
| 20 | 1723 |
| 3 | 1724 ifofile->vts_vobu_admap = (vobu_admap_t *)malloc(sizeof(vobu_admap_t)); |
| 1725 if(!ifofile->vts_vobu_admap) | |
| 1726 return 0; | |
| 1727 | |
| 1728 if(!ifoRead_VOBU_ADMAP_internal(ifofile, ifofile->vts_vobu_admap, | |
| 1729 ifofile->vtsi_mat->vts_vobu_admap)) { | |
| 1730 free(ifofile->vts_vobu_admap); | |
| 1731 ifofile->vts_vobu_admap = 0; | |
| 1732 return 0; | |
| 1733 } | |
| 1734 | |
| 1735 return 1; | |
| 1736 } | |
| 1737 | |
| 1738 int ifoRead_VOBU_ADMAP(ifo_handle_t *ifofile) { | |
| 1739 unsigned int sector; | |
| 1740 | |
| 1741 if(!ifofile) | |
| 1742 return 0; | |
| 20 | 1743 |
| 3 | 1744 if(ifofile->vmgi_mat) { |
| 1745 if(ifofile->vmgi_mat->vmgm_vobu_admap == 0) | |
| 1746 return 1; | |
| 1747 sector = ifofile->vmgi_mat->vmgm_vobu_admap; | |
| 1748 } else if(ifofile->vtsi_mat) { | |
| 1749 if(ifofile->vtsi_mat->vtsm_vobu_admap == 0) | |
| 1750 return 1; | |
| 1751 sector = ifofile->vtsi_mat->vtsm_vobu_admap; | |
| 1752 } else { | |
| 1753 return 0; | |
| 1754 } | |
| 20 | 1755 |
| 3 | 1756 ifofile->menu_vobu_admap = (vobu_admap_t *)malloc(sizeof(vobu_admap_t)); |
| 1757 if(!ifofile->menu_vobu_admap) | |
| 1758 return 0; | |
| 20 | 1759 |
| 3 | 1760 if(!ifoRead_VOBU_ADMAP_internal(ifofile, ifofile->menu_vobu_admap, sector)) { |
| 1761 free(ifofile->menu_vobu_admap); | |
| 1762 ifofile->menu_vobu_admap = 0; | |
| 1763 return 0; | |
| 1764 } | |
| 1765 | |
| 1766 return 1; | |
| 1767 } | |
| 1768 | |
| 20 | 1769 static int ifoRead_VOBU_ADMAP_internal(ifo_handle_t *ifofile, |
| 1770 vobu_admap_t *vobu_admap, | |
| 26 | 1771 unsigned int sector) { |
| 3 | 1772 unsigned int i; |
| 1773 int info_length; | |
| 1774 | |
| 1775 if(!DVDFileSeekForce_(ifofile->file, sector * DVD_BLOCK_LEN, sector)) | |
| 1776 return 0; | |
| 1777 | |
| 1778 if(!(DVDReadBytes(ifofile->file, vobu_admap, VOBU_ADMAP_SIZE))) | |
| 1779 return 0; | |
| 1780 | |
| 1781 B2N_32(vobu_admap->last_byte); | |
| 20 | 1782 |
| 3 | 1783 info_length = vobu_admap->last_byte + 1 - VOBU_ADMAP_SIZE; |
| 1784 /* assert(info_length > 0); | |
| 20 | 1785 Magic Knight Rayearth Daybreak is mastered very strange and has |
| 3 | 1786 Titles with a VOBS that has no VOBUs. */ |
| 1787 CHECK_VALUE(info_length % sizeof(uint32_t) == 0); | |
| 20 | 1788 |
| 1789 vobu_admap->vobu_start_sectors = (uint32_t *)malloc(info_length); | |
| 3 | 1790 if(!vobu_admap->vobu_start_sectors) { |
| 1791 return 0; | |
| 1792 } | |
| 20 | 1793 if(info_length && |
| 1794 !(DVDReadBytes(ifofile->file, | |
| 26 | 1795 vobu_admap->vobu_start_sectors, info_length))) { |
| 3 | 1796 free(vobu_admap->vobu_start_sectors); |
| 1797 return 0; | |
| 1798 } | |
| 1799 | |
| 1800 for(i = 0; i < info_length/sizeof(uint32_t); i++) | |
| 1801 B2N_32(vobu_admap->vobu_start_sectors[i]); | |
| 1802 | |
| 1803 return 1; | |
| 1804 } | |
| 1805 | |
| 1806 | |
| 1807 static void ifoFree_VOBU_ADMAP_internal(vobu_admap_t *vobu_admap) { | |
| 1808 if(vobu_admap) { | |
| 1809 free(vobu_admap->vobu_start_sectors); | |
| 1810 free(vobu_admap); | |
| 1811 } | |
| 1812 } | |
| 1813 | |
| 1814 void ifoFree_VOBU_ADMAP(ifo_handle_t *ifofile) { | |
| 1815 if(!ifofile) | |
| 1816 return; | |
| 20 | 1817 |
| 3 | 1818 ifoFree_VOBU_ADMAP_internal(ifofile->menu_vobu_admap); |
| 1819 ifofile->menu_vobu_admap = 0; | |
| 1820 } | |
| 1821 | |
| 1822 void ifoFree_TITLE_VOBU_ADMAP(ifo_handle_t *ifofile) { | |
| 1823 if(!ifofile) | |
| 1824 return; | |
| 20 | 1825 |
| 3 | 1826 ifoFree_VOBU_ADMAP_internal(ifofile->vts_vobu_admap); |
| 1827 ifofile->vts_vobu_admap = 0; | |
| 1828 } | |
| 1829 | |
| 1830 int ifoRead_PGCIT(ifo_handle_t *ifofile) { | |
| 1831 | |
| 1832 if(!ifofile) | |
| 1833 return 0; | |
| 20 | 1834 |
| 3 | 1835 if(!ifofile->vtsi_mat) |
| 1836 return 0; | |
| 20 | 1837 |
| 3 | 1838 if(ifofile->vtsi_mat->vts_pgcit == 0) /* mandatory */ |
| 1839 return 0; | |
| 20 | 1840 |
| 75 | 1841 ifofile->vts_pgcit = (pgcit_t *)calloc(1, sizeof(pgcit_t)); |
| 3 | 1842 if(!ifofile->vts_pgcit) |
| 1843 return 0; | |
| 1844 | |
| 75 | 1845 ifofile->vts_pgcit->ref_count = 1; |
| 20 | 1846 if(!ifoRead_PGCIT_internal(ifofile, ifofile->vts_pgcit, |
| 3 | 1847 ifofile->vtsi_mat->vts_pgcit * DVD_BLOCK_LEN)) { |
| 1848 free(ifofile->vts_pgcit); | |
| 1849 ifofile->vts_pgcit = 0; | |
| 1850 return 0; | |
| 1851 } | |
| 1852 | |
| 1853 return 1; | |
| 1854 } | |
| 1855 | |
| 75 | 1856 static int find_dup_pgc(pgci_srp_t *pgci_srp, uint32_t start_byte, int count) { |
| 1857 int i; | |
| 1858 | |
| 1859 for(i = 0; i < count; i++) { | |
| 1860 if(pgci_srp[i].pgc_start_byte == start_byte) { | |
| 1861 return i; | |
| 1862 } | |
| 1863 } | |
| 1864 return -1; | |
| 1865 } | |
| 1866 | |
| 20 | 1867 static int ifoRead_PGCIT_internal(ifo_handle_t *ifofile, pgcit_t *pgcit, |
| 3 | 1868 unsigned int offset) { |
| 1869 int i, info_length; | |
| 1870 uint8_t *data, *ptr; | |
| 20 | 1871 |
| 3 | 1872 if(!DVDFileSeek_(ifofile->file, offset)) |
| 1873 return 0; | |
| 1874 | |
| 1875 if(!(DVDReadBytes(ifofile->file, pgcit, PGCIT_SIZE))) | |
| 1876 return 0; | |
| 1877 | |
| 1878 B2N_16(pgcit->nr_of_pgci_srp); | |
| 1879 B2N_32(pgcit->last_byte); | |
| 20 | 1880 |
| 3 | 1881 CHECK_ZERO(pgcit->zero_1); |
| 1882 /* assert(pgcit->nr_of_pgci_srp != 0); | |
| 20 | 1883 Magic Knight Rayearth Daybreak is mastered very strange and has |
| 3 | 1884 Titles with 0 PTTs. */ |
| 1885 CHECK_VALUE(pgcit->nr_of_pgci_srp < 10000); /* ?? seen max of 1338 */ | |
| 20 | 1886 |
| 3 | 1887 info_length = pgcit->nr_of_pgci_srp * PGCI_SRP_SIZE; |
| 1888 data = malloc(info_length); | |
| 1889 if(!data) | |
| 1890 return 0; | |
| 1891 | |
| 1892 if(info_length && !(DVDReadBytes(ifofile->file, data, info_length))) { | |
| 1893 free(data); | |
| 1894 return 0; | |
| 1895 } | |
| 1896 | |
| 1897 pgcit->pgci_srp = malloc(pgcit->nr_of_pgci_srp * sizeof(pgci_srp_t)); | |
| 1898 if(!pgcit->pgci_srp) { | |
| 1899 free(data); | |
| 1900 return 0; | |
| 1901 } | |
| 1902 ptr = data; | |
| 1903 for(i = 0; i < pgcit->nr_of_pgci_srp; i++) { | |
| 1904 memcpy(&pgcit->pgci_srp[i], ptr, PGCI_SRP_SIZE); | |
| 1905 ptr += PGCI_SRP_SIZE; | |
| 1906 read_pgci_srp(&pgcit->pgci_srp[i]); | |
| 1907 CHECK_VALUE(pgcit->pgci_srp[i].unknown1 == 0); | |
| 1908 } | |
| 1909 free(data); | |
| 20 | 1910 |
| 3 | 1911 for(i = 0; i < pgcit->nr_of_pgci_srp; i++) |
| 1912 CHECK_VALUE(pgcit->pgci_srp[i].pgc_start_byte + PGC_SIZE <= pgcit->last_byte+1); | |
| 20 | 1913 |
| 3 | 1914 for(i = 0; i < pgcit->nr_of_pgci_srp; i++) { |
| 75 | 1915 int dup; |
| 1916 if((dup = find_dup_pgc(pgcit->pgci_srp, pgcit->pgci_srp[i].pgc_start_byte, i)) >= 0) { | |
| 1917 pgcit->pgci_srp[i].pgc = pgcit->pgci_srp[dup].pgc; | |
| 1918 pgcit->pgci_srp[i].pgc->ref_count++; | |
| 1919 continue; | |
| 1920 } | |
| 1921 pgcit->pgci_srp[i].pgc = calloc(1, sizeof(pgc_t)); | |
| 3 | 1922 if(!pgcit->pgci_srp[i].pgc) { |
| 1923 int j; | |
| 1924 for(j = 0; j < i; j++) { | |
| 75 | 1925 ifoFree_PGC(&pgcit->pgci_srp[j].pgc); |
| 3 | 1926 } |
| 1927 goto fail; | |
| 1928 } | |
| 75 | 1929 pgcit->pgci_srp[i].pgc->ref_count = 1; |
| 20 | 1930 if(!ifoRead_PGC(ifofile, pgcit->pgci_srp[i].pgc, |
| 3 | 1931 offset + pgcit->pgci_srp[i].pgc_start_byte)) { |
| 1932 int j; | |
| 75 | 1933 for(j = 0; j <= i; j++) { |
| 1934 ifoFree_PGC(&pgcit->pgci_srp[j].pgc); | |
| 3 | 1935 } |
| 73 | 1936 free(pgcit->pgci_srp[i].pgc); |
| 3 | 1937 goto fail; |
| 1938 } | |
| 1939 } | |
| 1940 | |
| 1941 return 1; | |
| 1942 fail: | |
| 1943 free(pgcit->pgci_srp); | |
| 1944 pgcit->pgci_srp = NULL; | |
| 1945 return 0; | |
| 1946 } | |
| 1947 | |
| 75 | 1948 static void ifoFree_PGCIT_internal(pgcit_t **pgcit) { |
| 1949 if(pgcit && *pgcit && (--(*pgcit)->ref_count <= 0)) { | |
| 3 | 1950 int i; |
| 75 | 1951 for(i = 0; i < (*pgcit)->nr_of_pgci_srp; i++) |
| 73 | 1952 { |
| 75 | 1953 ifoFree_PGC(&(*pgcit)->pgci_srp[i].pgc); |
| 73 | 1954 } |
| 75 | 1955 free((*pgcit)->pgci_srp); |
| 1956 free(*pgcit); | |
| 3 | 1957 } |
| 75 | 1958 if (pgcit) |
| 1959 *pgcit = NULL; | |
| 3 | 1960 } |
| 1961 | |
| 1962 void ifoFree_PGCIT(ifo_handle_t *ifofile) { | |
| 1963 if(!ifofile) | |
| 1964 return; | |
| 20 | 1965 |
| 3 | 1966 if(ifofile->vts_pgcit) { |
| 75 | 1967 ifoFree_PGCIT_internal(&ifofile->vts_pgcit); |
| 3 | 1968 } |
| 1969 } | |
| 1970 | |
| 75 | 1971 static int find_dup_lut(pgci_lu_t *lu, uint32_t start_byte, int count) { |
| 1972 int i; | |
| 1973 | |
| 1974 for(i = 0; i < count; i++) { | |
| 1975 if(lu[i].lang_start_byte == start_byte) { | |
| 1976 return i; | |
| 1977 } | |
| 1978 } | |
| 1979 return -1; | |
| 1980 } | |
| 3 | 1981 |
| 1982 int ifoRead_PGCI_UT(ifo_handle_t *ifofile) { | |
| 1983 pgci_ut_t *pgci_ut; | |
| 1984 unsigned int sector; | |
| 20 | 1985 unsigned int i; |
| 3 | 1986 int info_length; |
| 1987 uint8_t *data, *ptr; | |
| 1988 | |
| 1989 if(!ifofile) | |
| 1990 return 0; | |
| 20 | 1991 |
| 3 | 1992 if(ifofile->vmgi_mat) { |
| 1993 if(ifofile->vmgi_mat->vmgm_pgci_ut == 0) | |
| 1994 return 1; | |
| 1995 sector = ifofile->vmgi_mat->vmgm_pgci_ut; | |
| 1996 } else if(ifofile->vtsi_mat) { | |
| 1997 if(ifofile->vtsi_mat->vtsm_pgci_ut == 0) | |
| 1998 return 1; | |
| 1999 sector = ifofile->vtsi_mat->vtsm_pgci_ut; | |
| 2000 } else { | |
| 2001 return 0; | |
| 2002 } | |
| 20 | 2003 |
| 3 | 2004 ifofile->pgci_ut = (pgci_ut_t *)malloc(sizeof(pgci_ut_t)); |
| 2005 if(!ifofile->pgci_ut) | |
| 2006 return 0; | |
| 20 | 2007 |
| 3 | 2008 if(!DVDFileSeek_(ifofile->file, sector * DVD_BLOCK_LEN)) { |
| 2009 free(ifofile->pgci_ut); | |
| 2010 ifofile->pgci_ut = 0; | |
| 2011 return 0; | |
| 2012 } | |
| 20 | 2013 |
| 3 | 2014 if(!(DVDReadBytes(ifofile->file, ifofile->pgci_ut, PGCI_UT_SIZE))) { |
| 2015 free(ifofile->pgci_ut); | |
| 2016 ifofile->pgci_ut = 0; | |
| 2017 return 0; | |
| 2018 } | |
| 20 | 2019 |
| 3 | 2020 pgci_ut = ifofile->pgci_ut; |
| 20 | 2021 |
| 3 | 2022 B2N_16(pgci_ut->nr_of_lus); |
| 2023 B2N_32(pgci_ut->last_byte); | |
| 20 | 2024 |
| 3 | 2025 CHECK_ZERO(pgci_ut->zero_1); |
| 2026 CHECK_VALUE(pgci_ut->nr_of_lus != 0); | |
| 2027 CHECK_VALUE(pgci_ut->nr_of_lus < 100); /* ?? 3-4 ? */ | |
| 2028 CHECK_VALUE((uint32_t)pgci_ut->nr_of_lus * PGCI_LU_SIZE < pgci_ut->last_byte); | |
| 2029 | |
| 2030 info_length = pgci_ut->nr_of_lus * PGCI_LU_SIZE; | |
| 2031 data = malloc(info_length); | |
| 2032 if(!data) { | |
| 2033 free(pgci_ut); | |
| 2034 ifofile->pgci_ut = 0; | |
| 2035 return 0; | |
| 2036 } | |
| 2037 if(!(DVDReadBytes(ifofile->file, data, info_length))) { | |
| 2038 free(data); | |
| 2039 free(pgci_ut); | |
| 2040 ifofile->pgci_ut = 0; | |
| 2041 return 0; | |
| 2042 } | |
| 2043 | |
| 2044 pgci_ut->lu = malloc(pgci_ut->nr_of_lus * sizeof(pgci_lu_t)); | |
| 2045 if(!pgci_ut->lu) { | |
| 2046 free(data); | |
| 2047 free(pgci_ut); | |
| 2048 ifofile->pgci_ut = 0; | |
|
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
2049 return 0; |
| 3 | 2050 } |
| 2051 ptr = data; | |
| 2052 for(i = 0; i < pgci_ut->nr_of_lus; i++) { | |
| 2053 memcpy(&pgci_ut->lu[i], ptr, PGCI_LU_SIZE); | |
| 2054 ptr += PGCI_LU_SIZE; | |
| 20 | 2055 B2N_16(pgci_ut->lu[i].lang_code); |
| 2056 B2N_32(pgci_ut->lu[i].lang_start_byte); | |
| 3 | 2057 } |
| 2058 free(data); | |
| 20 | 2059 |
| 3 | 2060 for(i = 0; i < pgci_ut->nr_of_lus; i++) { |
| 2061 /* Maybe this is only defined for v1.1 and later titles? */ | |
| 2062 /* If the bits in 'lu[i].exists' are enumerated abcd efgh then: | |
|
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
2063 VTS_x_yy.IFO VIDEO_TS.IFO |
| 3 | 2064 a == 0x83 "Root" 0x82 "Title" |
| 2065 b == 0x84 "Subpicture" | |
| 2066 c == 0x85 "Audio" | |
| 2067 d == 0x86 "Angle" | |
| 2068 e == 0x87 "PTT" | |
| 2069 */ | |
| 2070 CHECK_VALUE((pgci_ut->lu[i].exists & 0x07) == 0); | |
| 2071 } | |
| 2072 | |
| 2073 for(i = 0; i < pgci_ut->nr_of_lus; i++) { | |
| 75 | 2074 int dup; |
| 2075 if((dup = find_dup_lut(pgci_ut->lu, pgci_ut->lu[i].lang_start_byte, i)) >= 0) { | |
| 2076 pgci_ut->lu[i].pgcit = pgci_ut->lu[dup].pgcit; | |
| 2077 pgci_ut->lu[i].pgcit->ref_count++; | |
| 2078 continue; | |
| 2079 } | |
| 3 | 2080 pgci_ut->lu[i].pgcit = malloc(sizeof(pgcit_t)); |
| 2081 if(!pgci_ut->lu[i].pgcit) { | |
| 2082 unsigned int j; | |
| 2083 for(j = 0; j < i; j++) { | |
| 75 | 2084 ifoFree_PGCIT_internal(&pgci_ut->lu[j].pgcit); |
| 3 | 2085 } |
| 2086 free(pgci_ut->lu); | |
| 2087 free(pgci_ut); | |
| 2088 ifofile->pgci_ut = 0; | |
| 2089 return 0; | |
| 2090 } | |
| 75 | 2091 pgci_ut->lu[i].pgcit->ref_count = 1; |
| 20 | 2092 if(!ifoRead_PGCIT_internal(ifofile, pgci_ut->lu[i].pgcit, |
| 2093 sector * DVD_BLOCK_LEN | |
| 3 | 2094 + pgci_ut->lu[i].lang_start_byte)) { |
| 2095 unsigned int j; | |
| 75 | 2096 for(j = 0; j <= i; j++) { |
| 2097 ifoFree_PGCIT_internal(&pgci_ut->lu[j].pgcit); | |
| 3 | 2098 } |
| 2099 free(pgci_ut->lu); | |
| 2100 free(pgci_ut); | |
| 2101 ifofile->pgci_ut = 0; | |
| 2102 return 0; | |
| 2103 } | |
|
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
2104 /* FIXME: Iterate and verify that all menus that should exists accordingly |
|
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
2105 * to pgci_ut->lu[i].exists really do? */ |
| 3 | 2106 } |
| 2107 | |
| 2108 return 1; | |
| 2109 } | |
| 2110 | |
| 2111 | |
| 2112 void ifoFree_PGCI_UT(ifo_handle_t *ifofile) { | |
| 2113 unsigned int i; | |
| 2114 | |
| 2115 if(!ifofile) | |
| 2116 return; | |
| 20 | 2117 |
| 3 | 2118 if(ifofile->pgci_ut) { |
| 2119 for(i = 0; i < ifofile->pgci_ut->nr_of_lus; i++) { | |
| 75 | 2120 ifoFree_PGCIT_internal(&ifofile->pgci_ut->lu[i].pgcit); |
| 3 | 2121 } |
| 2122 free(ifofile->pgci_ut->lu); | |
| 2123 free(ifofile->pgci_ut); | |
| 2124 ifofile->pgci_ut = 0; | |
| 2125 } | |
| 2126 } | |
| 2127 | |
| 20 | 2128 static int ifoRead_VTS_ATTRIBUTES(ifo_handle_t *ifofile, |
| 2129 vts_attributes_t *vts_attributes, | |
| 3 | 2130 unsigned int offset) { |
| 2131 unsigned int i; | |
| 2132 | |
| 2133 if(!DVDFileSeek_(ifofile->file, offset)) | |
| 2134 return 0; | |
| 2135 | |
| 2136 if(!(DVDReadBytes(ifofile->file, vts_attributes, sizeof(vts_attributes_t)))) | |
| 2137 return 0; | |
| 2138 | |
| 2139 read_video_attr(&vts_attributes->vtsm_vobs_attr); | |
| 2140 read_video_attr(&vts_attributes->vtstt_vobs_video_attr); | |
| 2141 read_audio_attr(&vts_attributes->vtsm_audio_attr); | |
| 2142 for(i=0; i<8; i++) | |
| 2143 read_audio_attr(&vts_attributes->vtstt_audio_attr[i]); | |
| 2144 read_subp_attr(&vts_attributes->vtsm_subp_attr); | |
| 2145 for(i=0; i<32; i++) | |
| 2146 read_subp_attr(&vts_attributes->vtstt_subp_attr[i]); | |
| 2147 B2N_32(vts_attributes->last_byte); | |
| 2148 B2N_32(vts_attributes->vts_cat); | |
| 20 | 2149 |
| 3 | 2150 CHECK_ZERO(vts_attributes->zero_1); |
| 2151 CHECK_ZERO(vts_attributes->zero_2); | |
| 2152 CHECK_ZERO(vts_attributes->zero_3); | |
| 2153 CHECK_ZERO(vts_attributes->zero_4); | |
| 2154 CHECK_ZERO(vts_attributes->zero_5); | |
| 2155 CHECK_ZERO(vts_attributes->zero_6); | |
| 2156 CHECK_ZERO(vts_attributes->zero_7); | |
| 2157 CHECK_VALUE(vts_attributes->nr_of_vtsm_audio_streams <= 1); | |
| 2158 CHECK_VALUE(vts_attributes->nr_of_vtsm_subp_streams <= 1); | |
| 2159 CHECK_VALUE(vts_attributes->nr_of_vtstt_audio_streams <= 8); | |
| 2160 for(i = vts_attributes->nr_of_vtstt_audio_streams; i < 8; i++) | |
| 2161 CHECK_ZERO(vts_attributes->vtstt_audio_attr[i]); | |
| 2162 CHECK_VALUE(vts_attributes->nr_of_vtstt_subp_streams <= 32); | |
| 2163 { | |
| 2164 unsigned int nr_coded; | |
| 20 | 2165 CHECK_VALUE(vts_attributes->last_byte + 1 >= VTS_ATTRIBUTES_MIN_SIZE); |
| 3 | 2166 nr_coded = (vts_attributes->last_byte + 1 - VTS_ATTRIBUTES_MIN_SIZE)/6; |
| 2167 /* This is often nr_coded = 70, how do you know how many there really are? */ | |
| 2168 if(nr_coded > 32) { /* We haven't read more from disk/file anyway */ | |
| 2169 nr_coded = 32; | |
| 2170 } | |
| 2171 CHECK_VALUE(vts_attributes->nr_of_vtstt_subp_streams <= nr_coded); | |
| 2172 for(i = vts_attributes->nr_of_vtstt_subp_streams; i < nr_coded; i++) | |
| 2173 CHECK_ZERO(vts_attributes->vtstt_subp_attr[i]); | |
| 2174 } | |
| 2175 | |
| 2176 return 1; | |
| 2177 } | |
| 2178 | |
| 2179 | |
| 2180 | |
| 2181 int ifoRead_VTS_ATRT(ifo_handle_t *ifofile) { | |
| 2182 vts_atrt_t *vts_atrt; | |
| 2183 unsigned int i, info_length, sector; | |
| 2184 uint32_t *data; | |
| 2185 | |
| 2186 if(!ifofile) | |
| 2187 return 0; | |
| 20 | 2188 |
| 3 | 2189 if(!ifofile->vmgi_mat) |
| 2190 return 0; | |
| 20 | 2191 |
| 3 | 2192 if(ifofile->vmgi_mat->vts_atrt == 0) /* mandatory */ |
| 2193 return 0; | |
| 20 | 2194 |
| 3 | 2195 sector = ifofile->vmgi_mat->vts_atrt; |
| 2196 if(!DVDFileSeek_(ifofile->file, sector * DVD_BLOCK_LEN)) | |
| 2197 return 0; | |
| 2198 | |
| 2199 vts_atrt = (vts_atrt_t *)malloc(sizeof(vts_atrt_t)); | |
| 2200 if(!vts_atrt) | |
| 2201 return 0; | |
| 2202 | |
| 2203 ifofile->vts_atrt = vts_atrt; | |
| 20 | 2204 |
| 3 | 2205 if(!(DVDReadBytes(ifofile->file, vts_atrt, VTS_ATRT_SIZE))) { |
| 2206 free(vts_atrt); | |
| 2207 ifofile->vts_atrt = 0; | |
| 2208 return 0; | |
| 2209 } | |
| 2210 | |
| 2211 B2N_16(vts_atrt->nr_of_vtss); | |
| 2212 B2N_32(vts_atrt->last_byte); | |
| 2213 | |
| 2214 CHECK_ZERO(vts_atrt->zero_1); | |
| 2215 CHECK_VALUE(vts_atrt->nr_of_vtss != 0); | |
| 2216 CHECK_VALUE(vts_atrt->nr_of_vtss < 100); /* ?? */ | |
| 20 | 2217 CHECK_VALUE((uint32_t)vts_atrt->nr_of_vtss * (4 + VTS_ATTRIBUTES_MIN_SIZE) + |
|
27
98951f8ec89c
cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents:
26
diff
changeset
|
2218 VTS_ATRT_SIZE < vts_atrt->last_byte + 1); |
| 3 | 2219 |
| 2220 info_length = vts_atrt->nr_of_vtss * sizeof(uint32_t); | |
| 2221 data = (uint32_t *)malloc(info_length); | |
| 2222 if(!data) { | |
| 2223 free(vts_atrt); | |
| 2224 ifofile->vts_atrt = 0; | |
| 2225 return 0; | |
| 2226 } | |
| 2227 | |
| 20 | 2228 vts_atrt->vts_atrt_offsets = data; |
| 3 | 2229 |
| 2230 if(!(DVDReadBytes(ifofile->file, data, info_length))) { | |
| 2231 free(data); | |
| 2232 free(vts_atrt); | |
| 2233 ifofile->vts_atrt = 0; | |
| 2234 return 0; | |
| 2235 } | |
| 20 | 2236 |
| 3 | 2237 for(i = 0; i < vts_atrt->nr_of_vtss; i++) { |
| 2238 B2N_32(data[i]); | |
| 2239 CHECK_VALUE(data[i] + VTS_ATTRIBUTES_MIN_SIZE < vts_atrt->last_byte + 1); | |
| 2240 } | |
| 20 | 2241 |
| 3 | 2242 info_length = vts_atrt->nr_of_vtss * sizeof(vts_attributes_t); |
| 2243 vts_atrt->vts = (vts_attributes_t *)malloc(info_length); | |
| 2244 if(!vts_atrt->vts) { | |
| 2245 free(data); | |
| 2246 free(vts_atrt); | |
| 2247 ifofile->vts_atrt = 0; | |
| 2248 return 0; | |
| 2249 } | |
| 2250 for(i = 0; i < vts_atrt->nr_of_vtss; i++) { | |
| 2251 unsigned int offset = data[i]; | |
| 2252 if(!ifoRead_VTS_ATTRIBUTES(ifofile, &(vts_atrt->vts[i]), | |
| 2253 (sector * DVD_BLOCK_LEN) + offset)) { | |
| 2254 free(data); | |
| 2255 free(vts_atrt); | |
| 2256 ifofile->vts_atrt = 0; | |
| 2257 return 0; | |
| 2258 } | |
| 2259 | |
| 2260 /* This assert cant be in ifoRead_VTS_ATTRIBUTES */ | |
| 2261 CHECK_VALUE(offset + vts_atrt->vts[i].last_byte <= vts_atrt->last_byte + 1); | |
| 2262 /* Is this check correct? */ | |
| 2263 } | |
| 2264 | |
| 2265 return 1; | |
| 2266 } | |
| 2267 | |
| 2268 | |
| 2269 void ifoFree_VTS_ATRT(ifo_handle_t *ifofile) { | |
| 2270 if(!ifofile) | |
| 2271 return; | |
| 20 | 2272 |
| 3 | 2273 if(ifofile->vts_atrt) { |
| 2274 free(ifofile->vts_atrt->vts); | |
| 2275 free(ifofile->vts_atrt->vts_atrt_offsets); | |
| 2276 free(ifofile->vts_atrt); | |
| 2277 ifofile->vts_atrt = 0; | |
| 2278 } | |
| 2279 } | |
| 2280 | |
| 2281 | |
| 2282 int ifoRead_TXTDT_MGI(ifo_handle_t *ifofile) { | |
| 2283 txtdt_mgi_t *txtdt_mgi; | |
| 2284 | |
| 2285 if(!ifofile) | |
| 2286 return 0; | |
| 20 | 2287 |
| 3 | 2288 if(!ifofile->vmgi_mat) |
| 2289 return 0; | |
| 20 | 2290 |
| 2291 /* Return successfully if there is nothing to read. */ | |
| 3 | 2292 if(ifofile->vmgi_mat->txtdt_mgi == 0) |
| 2293 return 1; | |
| 2294 | |
| 20 | 2295 if(!DVDFileSeek_(ifofile->file, |
| 26 | 2296 ifofile->vmgi_mat->txtdt_mgi * DVD_BLOCK_LEN)) |
| 3 | 2297 return 0; |
| 20 | 2298 |
| 3 | 2299 txtdt_mgi = (txtdt_mgi_t *)malloc(sizeof(txtdt_mgi_t)); |
| 2300 if(!txtdt_mgi) { | |
| 2301 return 0; | |
| 2302 } | |
| 2303 ifofile->txtdt_mgi = txtdt_mgi; | |
| 2304 | |
| 2305 if(!(DVDReadBytes(ifofile->file, txtdt_mgi, TXTDT_MGI_SIZE))) { | |
| 2306 fprintf(stderr, "libdvdread: Unable to read TXTDT_MGI.\n"); | |
| 2307 free(txtdt_mgi); | |
| 2308 ifofile->txtdt_mgi = 0; | |
| 2309 return 0; | |
| 2310 } | |
| 2311 | |
| 2312 /* fprintf(stderr, "-- Not done yet --\n"); */ | |
| 2313 return 1; | |
| 2314 } | |
| 2315 | |
| 2316 void ifoFree_TXTDT_MGI(ifo_handle_t *ifofile) { | |
| 2317 if(!ifofile) | |
| 2318 return; | |
| 20 | 2319 |
| 3 | 2320 if(ifofile->txtdt_mgi) { |
| 2321 free(ifofile->txtdt_mgi); | |
| 2322 ifofile->txtdt_mgi = 0; | |
| 2323 } | |
| 2324 } |
