annotate libmpdvdkit2/ifo_read.c @ 15296:f2c1c1034d66

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