comparison libdvdread/nav_read.c @ 367:1274107d0eac src

moved dvdread to libdvdread; it's the first step for the separation of the lib from dvdnav
author nicodvb
date Sat, 31 May 2008 12:29:19 +0000
parents dvdread/nav_read.c@a5319a5c34f4
children
comparison
equal deleted inserted replaced
366:5b8539cacebf 367:1274107d0eac
1 /*
2 * Copyright (C) 2000, 2001, 2002, 2003 Håkan Hjort <d95hjort@dtek.chalmers.se>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
19 #include "config.h"
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <inttypes.h>
25
26 #include "bswap.h"
27 #include "nav_types.h"
28 #include "nav_read.h"
29 #include "dvdread_internal.h"
30 #include "bitreader.h"
31
32 #define getbits_init dvdread_getbits_init
33 #define getbits dvdread_getbits
34
35 void navRead_PCI(pci_t *pci, unsigned char *buffer) {
36 int32_t i, j;
37 getbits_state_t state;
38 if (!getbits_init(&state, buffer)) abort(); /* Passed NULL pointers */
39
40 /* pci pci_gi */
41 pci->pci_gi.nv_pck_lbn = getbits(&state, 32 );
42 pci->pci_gi.vobu_cat = getbits(&state, 16 );
43 pci->pci_gi.zero1 = getbits(&state, 16 );
44 pci->pci_gi.vobu_uop_ctl.zero = getbits(&state, 7 );
45 pci->pci_gi.vobu_uop_ctl.video_pres_mode_change = getbits(&state, 1 );
46
47 pci->pci_gi.vobu_uop_ctl.karaoke_audio_pres_mode_change = getbits(&state, 1 );
48 pci->pci_gi.vobu_uop_ctl.angle_change = getbits(&state, 1 );
49 pci->pci_gi.vobu_uop_ctl.subpic_stream_change = getbits(&state, 1 );
50 pci->pci_gi.vobu_uop_ctl.audio_stream_change = getbits(&state, 1 );
51 pci->pci_gi.vobu_uop_ctl.pause_on = getbits(&state, 1 );
52 pci->pci_gi.vobu_uop_ctl.still_off = getbits(&state, 1 );
53 pci->pci_gi.vobu_uop_ctl.button_select_or_activate = getbits(&state, 1 );
54 pci->pci_gi.vobu_uop_ctl.resume = getbits(&state, 1 );
55
56 pci->pci_gi.vobu_uop_ctl.chapter_menu_call = getbits(&state, 1 );
57 pci->pci_gi.vobu_uop_ctl.angle_menu_call = getbits(&state, 1 );
58 pci->pci_gi.vobu_uop_ctl.audio_menu_call = getbits(&state, 1 );
59 pci->pci_gi.vobu_uop_ctl.subpic_menu_call = getbits(&state, 1 );
60 pci->pci_gi.vobu_uop_ctl.root_menu_call = getbits(&state, 1 );
61 pci->pci_gi.vobu_uop_ctl.title_menu_call = getbits(&state, 1 );
62 pci->pci_gi.vobu_uop_ctl.backward_scan = getbits(&state, 1 );
63 pci->pci_gi.vobu_uop_ctl.forward_scan = getbits(&state, 1 );
64
65 pci->pci_gi.vobu_uop_ctl.next_pg_search = getbits(&state, 1 );
66 pci->pci_gi.vobu_uop_ctl.prev_or_top_pg_search = getbits(&state, 1 );
67 pci->pci_gi.vobu_uop_ctl.time_or_chapter_search = getbits(&state, 1 );
68 pci->pci_gi.vobu_uop_ctl.go_up = getbits(&state, 1 );
69 pci->pci_gi.vobu_uop_ctl.stop = getbits(&state, 1 );
70 pci->pci_gi.vobu_uop_ctl.title_play = getbits(&state, 1 );
71 pci->pci_gi.vobu_uop_ctl.chapter_search_or_play = getbits(&state, 1 );
72 pci->pci_gi.vobu_uop_ctl.title_or_time_play = getbits(&state, 1 );
73 pci->pci_gi.vobu_s_ptm = getbits(&state, 32 );
74 pci->pci_gi.vobu_e_ptm = getbits(&state, 32 );
75 pci->pci_gi.vobu_se_e_ptm = getbits(&state, 32 );
76 pci->pci_gi.e_eltm.hour = getbits(&state, 8 );
77 pci->pci_gi.e_eltm.minute = getbits(&state, 8 );
78 pci->pci_gi.e_eltm.second = getbits(&state, 8 );
79 pci->pci_gi.e_eltm.frame_u = getbits(&state, 8 );
80 for(i = 0; i < 32; i++)
81 pci->pci_gi.vobu_isrc[i] = getbits(&state, 8 );
82
83 /* pci nsml_agli */
84 for(i = 0; i < 9; i++)
85 pci->nsml_agli.nsml_agl_dsta[i] = getbits(&state, 32 );
86
87 /* pci hli hli_gi */
88 pci->hli.hl_gi.hli_ss = getbits(&state, 16 );
89 pci->hli.hl_gi.hli_s_ptm = getbits(&state, 32 );
90 pci->hli.hl_gi.hli_e_ptm = getbits(&state, 32 );
91 pci->hli.hl_gi.btn_se_e_ptm = getbits(&state, 32 );
92 pci->hli.hl_gi.zero1 = getbits(&state, 2 );
93 pci->hli.hl_gi.btngr_ns = getbits(&state, 2 );
94 pci->hli.hl_gi.zero2 = getbits(&state, 1 );
95 pci->hli.hl_gi.btngr1_dsp_ty = getbits(&state, 3 );
96 pci->hli.hl_gi.zero3 = getbits(&state, 1 );
97 pci->hli.hl_gi.btngr2_dsp_ty = getbits(&state, 3 );
98 pci->hli.hl_gi.zero4 = getbits(&state, 1 );
99 pci->hli.hl_gi.btngr3_dsp_ty = getbits(&state, 3 );
100 pci->hli.hl_gi.btn_ofn = getbits(&state, 8 );
101 pci->hli.hl_gi.btn_ns = getbits(&state, 8 );
102 pci->hli.hl_gi.nsl_btn_ns = getbits(&state, 8 );
103 pci->hli.hl_gi.zero5 = getbits(&state, 8 );
104 pci->hli.hl_gi.fosl_btnn = getbits(&state, 8 );
105 pci->hli.hl_gi.foac_btnn = getbits(&state, 8 );
106
107 /* pci hli btn_colit */
108 for(i = 0; i < 3; i++)
109 for(j = 0; j < 2; j++)
110 pci->hli.btn_colit.btn_coli[i][j] = getbits(&state, 32 );
111
112 /* NOTE: I've had to change the structure from the disk layout to get
113 * the packing to work with Sun's Forte C compiler. */
114
115 /* pci hli btni */
116 for(i = 0; i < 36; i++) {
117 pci->hli.btnit[i].btn_coln = getbits(&state, 2 );
118 pci->hli.btnit[i].x_start = getbits(&state, 10 );
119 pci->hli.btnit[i].zero1 = getbits(&state, 2 );
120 pci->hli.btnit[i].x_end = getbits(&state, 10 );
121
122 pci->hli.btnit[i].auto_action_mode = getbits(&state, 2 );
123 pci->hli.btnit[i].y_start = getbits(&state, 10 );
124 pci->hli.btnit[i].zero2 = getbits(&state, 2 );
125 pci->hli.btnit[i].y_end = getbits(&state, 10 );
126
127 pci->hli.btnit[i].zero3 = getbits(&state, 2 );
128 pci->hli.btnit[i].up = getbits(&state, 6 );
129 pci->hli.btnit[i].zero4 = getbits(&state, 2 );
130 pci->hli.btnit[i].down = getbits(&state, 6 );
131 pci->hli.btnit[i].zero5 = getbits(&state, 2 );
132 pci->hli.btnit[i].left = getbits(&state, 6 );
133 pci->hli.btnit[i].zero6 = getbits(&state, 2 );
134 pci->hli.btnit[i].right = getbits(&state, 6 );
135 /* pci vm_cmd */
136 for(j = 0; j < 8; j++)
137 pci->hli.btnit[i].cmd.bytes[j] = getbits(&state, 8 );
138 }
139
140
141
142 #ifndef NDEBUG
143 /* Asserts */
144
145 /* pci pci gi */
146 CHECK_VALUE(pci->pci_gi.zero1 == 0);
147
148 /* pci hli hli_gi */
149 CHECK_VALUE(pci->hli.hl_gi.zero1 == 0);
150 CHECK_VALUE(pci->hli.hl_gi.zero2 == 0);
151 CHECK_VALUE(pci->hli.hl_gi.zero3 == 0);
152 CHECK_VALUE(pci->hli.hl_gi.zero4 == 0);
153 CHECK_VALUE(pci->hli.hl_gi.zero5 == 0);
154
155 /* Are there buttons defined here? */
156 if((pci->hli.hl_gi.hli_ss & 0x03) != 0) {
157 CHECK_VALUE(pci->hli.hl_gi.btn_ns != 0);
158 CHECK_VALUE(pci->hli.hl_gi.btngr_ns != 0);
159 } else {
160 CHECK_VALUE((pci->hli.hl_gi.btn_ns != 0 && pci->hli.hl_gi.btngr_ns != 0)
161 || (pci->hli.hl_gi.btn_ns == 0 && pci->hli.hl_gi.btngr_ns == 0));
162 }
163
164 /* pci hli btnit */
165 for(i = 0; i < pci->hli.hl_gi.btngr_ns; i++) {
166 for(j = 0; j < (36 / pci->hli.hl_gi.btngr_ns); j++) {
167 int n = (36 / pci->hli.hl_gi.btngr_ns) * i + j;
168 CHECK_VALUE(pci->hli.btnit[n].zero1 == 0);
169 CHECK_VALUE(pci->hli.btnit[n].zero2 == 0);
170 CHECK_VALUE(pci->hli.btnit[n].zero3 == 0);
171 CHECK_VALUE(pci->hli.btnit[n].zero4 == 0);
172 CHECK_VALUE(pci->hli.btnit[n].zero5 == 0);
173 CHECK_VALUE(pci->hli.btnit[n].zero6 == 0);
174
175 if (j < pci->hli.hl_gi.btn_ns) {
176 CHECK_VALUE(pci->hli.btnit[n].x_start <= pci->hli.btnit[n].x_end);
177 CHECK_VALUE(pci->hli.btnit[n].y_start <= pci->hli.btnit[n].y_end);
178 CHECK_VALUE(pci->hli.btnit[n].up <= pci->hli.hl_gi.btn_ns);
179 CHECK_VALUE(pci->hli.btnit[n].down <= pci->hli.hl_gi.btn_ns);
180 CHECK_VALUE(pci->hli.btnit[n].left <= pci->hli.hl_gi.btn_ns);
181 CHECK_VALUE(pci->hli.btnit[n].right <= pci->hli.hl_gi.btn_ns);
182 /* vmcmd_verify(pci->hli.btnit[n].cmd); */
183 } else {
184 int k;
185 CHECK_VALUE(pci->hli.btnit[n].btn_coln == 0);
186 CHECK_VALUE(pci->hli.btnit[n].auto_action_mode == 0);
187 CHECK_VALUE(pci->hli.btnit[n].x_start == 0);
188 CHECK_VALUE(pci->hli.btnit[n].y_start == 0);
189 CHECK_VALUE(pci->hli.btnit[n].x_end == 0);
190 CHECK_VALUE(pci->hli.btnit[n].y_end == 0);
191 CHECK_VALUE(pci->hli.btnit[n].up == 0);
192 CHECK_VALUE(pci->hli.btnit[n].down == 0);
193 CHECK_VALUE(pci->hli.btnit[n].left == 0);
194 CHECK_VALUE(pci->hli.btnit[n].right == 0);
195 for (k = 0; k < 8; k++)
196 CHECK_VALUE(pci->hli.btnit[n].cmd.bytes[k] == 0); /* CHECK_ZERO? */
197 }
198 }
199 }
200 #endif /* !NDEBUG */
201 }
202
203 void navRead_DSI(dsi_t *dsi, unsigned char *buffer) {
204 int i;
205 getbits_state_t state;
206 if (!getbits_init(&state, buffer)) abort(); /* Passed NULL pointers */
207
208 /* dsi dsi gi */
209 dsi->dsi_gi.nv_pck_scr = getbits(&state, 32 );
210 dsi->dsi_gi.nv_pck_lbn = getbits(&state, 32 );
211 dsi->dsi_gi.vobu_ea = getbits(&state, 32 );
212 dsi->dsi_gi.vobu_1stref_ea = getbits(&state, 32 );
213 dsi->dsi_gi.vobu_2ndref_ea = getbits(&state, 32 );
214 dsi->dsi_gi.vobu_3rdref_ea = getbits(&state, 32 );
215 dsi->dsi_gi.vobu_vob_idn = getbits(&state, 16 );
216 dsi->dsi_gi.zero1 = getbits(&state, 8 );
217 dsi->dsi_gi.vobu_c_idn = getbits(&state, 8 );
218 dsi->dsi_gi.c_eltm.hour = getbits(&state, 8 );
219 dsi->dsi_gi.c_eltm.minute = getbits(&state, 8 );
220 dsi->dsi_gi.c_eltm.second = getbits(&state, 8 );
221 dsi->dsi_gi.c_eltm.frame_u = getbits(&state, 8 );
222
223 /* dsi sml pbi */
224 dsi->sml_pbi.category = getbits(&state, 16 );
225 dsi->sml_pbi.ilvu_ea = getbits(&state, 32 );
226 dsi->sml_pbi.ilvu_sa = getbits(&state, 32 );
227 dsi->sml_pbi.size = getbits(&state, 16 );
228 dsi->sml_pbi.vob_v_s_s_ptm = getbits(&state, 32 );
229 dsi->sml_pbi.vob_v_e_e_ptm = getbits(&state, 32 );
230 for(i = 0; i < 8; i++) {
231 dsi->sml_pbi.vob_a[i].stp_ptm1 = getbits(&state, 32 );
232 dsi->sml_pbi.vob_a[i].stp_ptm2 = getbits(&state, 32 );
233 dsi->sml_pbi.vob_a[i].gap_len1 = getbits(&state, 32 );
234 dsi->sml_pbi.vob_a[i].gap_len2 = getbits(&state, 32 );
235 }
236
237 /* dsi sml agli */
238 for(i = 0; i < 9; i++) {
239 dsi->sml_agli.data[ i ].address = getbits(&state, 32 );
240 dsi->sml_agli.data[ i ].size = getbits(&state, 16 );
241 }
242
243 /* dsi vobu sri */
244 dsi->vobu_sri.next_video = getbits(&state, 32 );
245 for(i = 0; i < 19; i++)
246 dsi->vobu_sri.fwda[i] = getbits(&state, 32 );
247 dsi->vobu_sri.next_vobu = getbits(&state, 32 );
248 dsi->vobu_sri.prev_vobu = getbits(&state, 32 );
249 for(i = 0; i < 19; i++)
250 dsi->vobu_sri.bwda[i] = getbits(&state, 32 );
251 dsi->vobu_sri.prev_video = getbits(&state, 32 );
252
253 /* dsi synci */
254 for(i = 0; i < 8; i++)
255 dsi->synci.a_synca[i] = getbits(&state, 16 );
256 for(i = 0; i < 32; i++)
257 dsi->synci.sp_synca[i] = getbits(&state, 32 );
258
259
260 /* Asserts */
261
262 /* dsi dsi gi */
263 CHECK_VALUE(dsi->dsi_gi.zero1 == 0);
264 }
265