annotate dvdread/ifo_read.c @ 328:727b18c5824b src

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