annotate dvdread/ifo_read.c @ 364:23607807ff65 src

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