annotate ifo_read.c @ 83:bed968b9bd99 src

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