Mercurial > libdvdnav.hg
annotate vm/vm.c @ 279:130c10495b66 src
replaced 08llx with PRIx64; patch by Diego Petteno'
author | nicodvb |
---|---|
date | Tue, 17 Apr 2007 20:57:17 +0000 |
parents | 97ad00b13609 |
children | 52877d182e96 |
rev | line source |
---|---|
225 | 1 /* |
2 * Copyright (C) 2000, 2001 Håkan Hjort | |
3 * Copyright (C) 2001 Rich Wareham <richwareham@users.sourceforge.net> | |
243
e75c52894630
* assert(0) does not always and the program (see NDEBUG)
mroi
parents:
229
diff
changeset
|
4 * 2002-2004 the dvdnav project |
225 | 5 * |
6 * This file is part of libdvdnav, a DVD navigation library. It is modified | |
7 * from a file originally part of the Ogle DVD player. | |
8 * | |
9 * libdvdnav is free software; you can redistribute it and/or modify | |
10 * it under the terms of the GNU General Public License as published by | |
11 * the Free Software Foundation; either version 2 of the License, or | |
12 * (at your option) any later version. | |
13 * | |
14 * libdvdnav is distributed in the hope that it will be useful, | |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 * GNU General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
20 * along with this program; if not, write to the Free Software | |
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA | |
22 * | |
23 * $Id$ | |
24 * | |
25 */ | |
26 | |
27 #ifdef HAVE_CONFIG_H | |
28 #include "config.h" | |
29 #endif | |
30 | |
31 #include <stdio.h> | |
32 #include <string.h> | |
33 #include <stdlib.h> | |
34 #include <unistd.h> | |
35 #include <inttypes.h> | |
36 #include <assert.h> | |
37 #include <sys/types.h> | |
38 #include <sys/stat.h> | |
39 #include <fcntl.h> | |
40 | |
41 #include "ifo_types.h" | |
42 #include "ifo_read.h" | |
43 | |
44 #include "dvdnav_internal.h" | |
45 | |
46 #ifdef _MSC_VER | |
47 #include <io.h> /* read() */ | |
48 #endif /* _MSC_VER */ | |
49 | |
50 /* | |
51 #define STRICT | |
52 */ | |
53 | |
54 /* Local prototypes */ | |
55 | |
56 /* get_XYZ returns a value. | |
57 * set_XYZ sets state using passed parameters. | |
58 * returns success/failure. | |
59 */ | |
60 | |
61 /* Play */ | |
62 static link_t play_PGC(vm_t *vm); | |
63 static link_t play_PGC_PG(vm_t *vm, int pgN); | |
64 static link_t play_PGC_post(vm_t *vm); | |
65 static link_t play_PG(vm_t *vm); | |
66 static link_t play_Cell(vm_t *vm); | |
67 static link_t play_Cell_post(vm_t *vm); | |
68 | |
69 /* Process link - returns 1 if a hop has been performed */ | |
70 static int process_command(vm_t *vm,link_t link_values); | |
71 | |
72 /* Set */ | |
73 static int set_TT(vm_t *vm, int tt); | |
74 static int set_PTT(vm_t *vm, int tt, int ptt); | |
75 static int set_VTS_TT(vm_t *vm, int vtsN, int vts_ttn); | |
76 static int set_VTS_PTT(vm_t *vm, int vtsN, int vts_ttn, int part); | |
77 static int set_FP_PGC(vm_t *vm); | |
78 static int set_MENU(vm_t *vm, int menu); | |
79 static int set_PGCN(vm_t *vm, int pgcN); | |
80 static int set_PGN(vm_t *vm); /* Set PGN based on (vm->state).CellN */ | |
81 static void set_RSMinfo(vm_t *vm, int cellN, int blockN); | |
82 | |
83 /* Get */ | |
84 static int get_TT(vm_t *vm, int vtsN, int vts_ttn); | |
85 static int get_ID(vm_t *vm, int id); | |
86 static int get_PGCN(vm_t *vm); | |
87 | |
88 static pgcit_t* get_MENU_PGCIT(vm_t *vm, ifo_handle_t *h, uint16_t lang); | |
89 static pgcit_t* get_PGCIT(vm_t *vm); | |
90 | |
91 | |
92 /* Helper functions */ | |
93 | |
94 #ifdef TRACE | |
95 static void vm_print_current_domain_state(vm_t *vm) { | |
96 switch((vm->state).domain) { | |
97 case VTS_DOMAIN: | |
98 fprintf(MSG_OUT, "libdvdnav: Video Title Domain: -\n"); | |
99 break; | |
100 | |
101 case VTSM_DOMAIN: | |
102 fprintf(MSG_OUT, "libdvdnav: Video Title Menu Domain: -\n"); | |
103 break; | |
104 | |
105 case VMGM_DOMAIN: | |
106 fprintf(MSG_OUT, "libdvdnav: Video Manager Menu Domain: -\n"); | |
107 break; | |
108 | |
109 case FP_DOMAIN: | |
110 fprintf(MSG_OUT, "libdvdnav: First Play Domain: -\n"); | |
111 break; | |
112 | |
113 default: | |
114 fprintf(MSG_OUT, "libdvdnav: Unknown Domain: -\n"); | |
115 break; | |
116 } | |
117 fprintf(MSG_OUT, "libdvdnav: VTS:%d PGC:%d PG:%u CELL:%u BLOCK:%u VTS_TTN:%u TTN:%u TT_PGCN:%u\n", | |
118 (vm->state).vtsN, | |
119 get_PGCN(vm), | |
120 (vm->state).pgN, | |
121 (vm->state).cellN, | |
122 (vm->state).blockN, | |
123 (vm->state).VTS_TTN_REG, | |
124 (vm->state).TTN_REG, | |
125 (vm->state).TT_PGCN_REG); | |
126 } | |
127 #endif | |
128 | |
129 static void dvd_read_name(char *name, const char *device) { | |
229 | 130 /* Because we are compiling with _FILE_OFFSET_BITS=64 |
131 * all off_t are 64bit. | |
132 */ | |
133 off_t off; | |
225 | 134 int fd, i; |
135 uint8_t data[DVD_VIDEO_LB_LEN]; | |
136 | |
137 /* Read DVD name */ | |
244
a27c81078c3c
removing O_EXCL, since it does not work with DVD images
mroi
parents:
243
diff
changeset
|
138 fd = open(device, O_RDONLY); |
225 | 139 if (fd > 0) { |
229 | 140 off = lseek( fd, 32 * (off_t) DVD_VIDEO_LB_LEN, SEEK_SET ); |
141 if( off == ( 32 * (off_t) DVD_VIDEO_LB_LEN ) ) { | |
225 | 142 off = read( fd, data, DVD_VIDEO_LB_LEN ); |
143 close(fd); | |
229 | 144 if (off == ( (off_t) DVD_VIDEO_LB_LEN )) { |
225 | 145 fprintf(MSG_OUT, "libdvdnav: DVD Title: "); |
146 for(i=25; i < 73; i++ ) { | |
147 if((data[i] == 0)) break; | |
148 if((data[i] > 32) && (data[i] < 127)) { | |
149 fprintf(MSG_OUT, "%c", data[i]); | |
150 } else { | |
151 fprintf(MSG_OUT, " "); | |
152 } | |
153 } | |
154 strncpy(name, &data[25], 48); | |
155 name[48] = 0; | |
156 fprintf(MSG_OUT, "\nlibdvdnav: DVD Serial Number: "); | |
157 for(i=73; i < 89; i++ ) { | |
158 if((data[i] == 0)) break; | |
159 if((data[i] > 32) && (data[i] < 127)) { | |
160 fprintf(MSG_OUT, "%c", data[i]); | |
161 } else { | |
162 fprintf(MSG_OUT, " "); | |
163 } | |
164 } | |
165 fprintf(MSG_OUT, "\nlibdvdnav: DVD Title (Alternative): "); | |
166 for(i=89; i < 128; i++ ) { | |
167 if((data[i] == 0)) break; | |
168 if((data[i] > 32) && (data[i] < 127)) { | |
169 fprintf(MSG_OUT, "%c", data[i]); | |
170 } else { | |
171 fprintf(MSG_OUT, " "); | |
172 } | |
173 } | |
174 fprintf(MSG_OUT, "\n"); | |
175 } else { | |
176 fprintf(MSG_OUT, "libdvdnav: Can't read name block. Probably not a DVD-ROM device.\n"); | |
177 } | |
178 } else { | |
179 fprintf(MSG_OUT, "libdvdnav: Can't seek to block %u\n", 32 ); | |
180 } | |
181 close(fd); | |
182 } else { | |
183 fprintf(MSG_OUT, "NAME OPEN FAILED\n"); | |
184 } | |
185 } | |
186 | |
256
6299ccea8a38
killing a lot of asserts and turning them into forced executions of Exit,
mroi
parents:
254
diff
changeset
|
187 static int ifoOpenNewVTSI(vm_t *vm, dvd_reader_t *dvd, int vtsN) { |
225 | 188 if((vm->state).vtsN == vtsN) { |
256
6299ccea8a38
killing a lot of asserts and turning them into forced executions of Exit,
mroi
parents:
254
diff
changeset
|
189 return 1; /* We alread have it */ |
225 | 190 } |
191 | |
192 if(vm->vtsi != NULL) | |
193 ifoClose(vm->vtsi); | |
194 | |
195 vm->vtsi = ifoOpenVTSI(dvd, vtsN); | |
196 if(vm->vtsi == NULL) { | |
256
6299ccea8a38
killing a lot of asserts and turning them into forced executions of Exit,
mroi
parents:
254
diff
changeset
|
197 fprintf(MSG_OUT, "libdvdnav: ifoOpenVTSI failed\n"); |
6299ccea8a38
killing a lot of asserts and turning them into forced executions of Exit,
mroi
parents:
254
diff
changeset
|
198 return 0; |
225 | 199 } |
200 if(!ifoRead_VTS_PTT_SRPT(vm->vtsi)) { | |
256
6299ccea8a38
killing a lot of asserts and turning them into forced executions of Exit,
mroi
parents:
254
diff
changeset
|
201 fprintf(MSG_OUT, "libdvdnav: ifoRead_VTS_PTT_SRPT failed\n"); |
6299ccea8a38
killing a lot of asserts and turning them into forced executions of Exit,
mroi
parents:
254
diff
changeset
|
202 return 0; |
225 | 203 } |
204 if(!ifoRead_PGCIT(vm->vtsi)) { | |
256
6299ccea8a38
killing a lot of asserts and turning them into forced executions of Exit,
mroi
parents:
254
diff
changeset
|
205 fprintf(MSG_OUT, "libdvdnav: ifoRead_PGCIT failed\n"); |
6299ccea8a38
killing a lot of asserts and turning them into forced executions of Exit,
mroi
parents:
254
diff
changeset
|
206 return 0; |
225 | 207 } |
208 if(!ifoRead_PGCI_UT(vm->vtsi)) { | |
256
6299ccea8a38
killing a lot of asserts and turning them into forced executions of Exit,
mroi
parents:
254
diff
changeset
|
209 fprintf(MSG_OUT, "libdvdnav: ifoRead_PGCI_UT failed\n"); |
6299ccea8a38
killing a lot of asserts and turning them into forced executions of Exit,
mroi
parents:
254
diff
changeset
|
210 return 0; |
225 | 211 } |
212 if(!ifoRead_VOBU_ADMAP(vm->vtsi)) { | |
256
6299ccea8a38
killing a lot of asserts and turning them into forced executions of Exit,
mroi
parents:
254
diff
changeset
|
213 fprintf(MSG_OUT, "libdvdnav: ifoRead_VOBU_ADMAP vtsi failed\n"); |
6299ccea8a38
killing a lot of asserts and turning them into forced executions of Exit,
mroi
parents:
254
diff
changeset
|
214 return 0; |
225 | 215 } |
216 if(!ifoRead_TITLE_VOBU_ADMAP(vm->vtsi)) { | |
256
6299ccea8a38
killing a lot of asserts and turning them into forced executions of Exit,
mroi
parents:
254
diff
changeset
|
217 fprintf(MSG_OUT, "libdvdnav: ifoRead_TITLE_VOBU_ADMAP vtsi failed\n"); |
6299ccea8a38
killing a lot of asserts and turning them into forced executions of Exit,
mroi
parents:
254
diff
changeset
|
218 return 0; |
225 | 219 } |
220 (vm->state).vtsN = vtsN; | |
256
6299ccea8a38
killing a lot of asserts and turning them into forced executions of Exit,
mroi
parents:
254
diff
changeset
|
221 |
6299ccea8a38
killing a lot of asserts and turning them into forced executions of Exit,
mroi
parents:
254
diff
changeset
|
222 return 1; |
225 | 223 } |
224 | |
225 | |
226 /* Initialisation & Destruction */ | |
227 | |
228 vm_t* vm_new_vm() { | |
229 return (vm_t*)calloc(sizeof(vm_t), sizeof(char)); | |
230 } | |
231 | |
232 void vm_free_vm(vm_t *vm) { | |
233 vm_stop(vm); | |
234 free(vm); | |
235 } | |
236 | |
237 | |
238 /* IFO Access */ | |
239 | |
240 ifo_handle_t *vm_get_vmgi(vm_t *vm) { | |
241 return vm->vmgi; | |
242 } | |
243 | |
244 ifo_handle_t *vm_get_vtsi(vm_t *vm) { | |
245 return vm->vtsi; | |
246 } | |
247 | |
248 | |
249 /* Reader Access */ | |
250 | |
251 dvd_reader_t *vm_get_dvd_reader(vm_t *vm) { | |
252 return vm->dvd; | |
253 } | |
254 | |
255 | |
256 /* Basic Handling */ | |
257 | |
256
6299ccea8a38
killing a lot of asserts and turning them into forced executions of Exit,
mroi
parents:
254
diff
changeset
|
258 int vm_start(vm_t *vm) { |
225 | 259 /* Set pgc to FP (First Play) pgc */ |
260 set_FP_PGC(vm); | |
261 process_command(vm, play_PGC(vm)); | |
256
6299ccea8a38
killing a lot of asserts and turning them into forced executions of Exit,
mroi
parents:
254
diff
changeset
|
262 return !vm->stopped; |
225 | 263 } |
264 | |
265 void vm_stop(vm_t *vm) { | |
266 if(vm->vmgi) { | |
267 ifoClose(vm->vmgi); | |
268 vm->vmgi=NULL; | |
269 } | |
270 if(vm->vtsi) { | |
271 ifoClose(vm->vtsi); | |
272 vm->vtsi=NULL; | |
273 } | |
274 if(vm->dvd) { | |
275 DVDClose(vm->dvd); | |
276 vm->dvd=NULL; | |
277 } | |
278 vm->stopped = 1; | |
279 } | |
280 | |
281 int vm_reset(vm_t *vm, const char *dvdroot) { | |
282 /* Setup State */ | |
283 memset((vm->state).registers.SPRM, 0, sizeof((vm->state).registers.SPRM)); | |
284 memset((vm->state).registers.GPRM, 0, sizeof((vm->state).registers.GPRM)); | |
285 memset((vm->state).registers.GPRM_mode, 0, sizeof((vm->state).registers.GPRM_mode)); | |
286 memset((vm->state).registers.GPRM_mode, 0, sizeof((vm->state).registers.GPRM_mode)); | |
287 memset((vm->state).registers.GPRM_time, 0, sizeof((vm->state).registers.GPRM_time)); | |
288 (vm->state).registers.SPRM[0] = ('e'<<8)|'n'; /* Player Menu Languange code */ | |
289 (vm->state).AST_REG = 15; /* 15 why? */ | |
290 (vm->state).SPST_REG = 62; /* 62 why? */ | |
291 (vm->state).AGL_REG = 1; | |
292 (vm->state).TTN_REG = 1; | |
293 (vm->state).VTS_TTN_REG = 1; | |
294 /* (vm->state).TT_PGCN_REG = 0 */ | |
295 (vm->state).PTTN_REG = 1; | |
296 (vm->state).HL_BTNN_REG = 1 << 10; | |
297 (vm->state).PTL_REG = 15; /* Parental Level */ | |
298 (vm->state).registers.SPRM[12] = ('U'<<8)|'S'; /* Parental Management Country Code */ | |
299 (vm->state).registers.SPRM[16] = ('e'<<8)|'n'; /* Initial Language Code for Audio */ | |
300 (vm->state).registers.SPRM[18] = ('e'<<8)|'n'; /* Initial Language Code for Spu */ | |
301 (vm->state).registers.SPRM[20] = 0x1; /* Player Regional Code Mask. Region free! */ | |
302 (vm->state).registers.SPRM[14] = 0x100; /* Try Pan&Scan */ | |
303 | |
304 (vm->state).pgN = 0; | |
305 (vm->state).cellN = 0; | |
306 (vm->state).cell_restart = 0; | |
307 | |
308 (vm->state).domain = FP_DOMAIN; | |
309 (vm->state).rsm_vtsN = 0; | |
310 (vm->state).rsm_cellN = 0; | |
311 (vm->state).rsm_blockN = 0; | |
312 | |
313 (vm->state).vtsN = -1; | |
314 | |
315 if (vm->dvd && dvdroot) { | |
316 /* a new dvd device has been requested */ | |
317 vm_stop(vm); | |
318 } | |
319 if (!vm->dvd) { | |
320 vm->dvd = DVDOpen(dvdroot); | |
321 if(!vm->dvd) { | |
260 | 322 fprintf(MSG_OUT, "libdvdnav: vm: failed to open/read the DVD\n"); |
225 | 323 return 0; |
324 } | |
325 dvd_read_name(vm->dvd_name, dvdroot); | |
326 vm->map = remap_loadmap(vm->dvd_name); | |
327 vm->vmgi = ifoOpenVMGI(vm->dvd); | |
328 if(!vm->vmgi) { | |
260 | 329 fprintf(MSG_OUT, "libdvdnav: vm: failed to read VIDEO_TS.IFO\n"); |
225 | 330 return 0; |
331 } | |
332 if(!ifoRead_FP_PGC(vm->vmgi)) { | |
333 fprintf(MSG_OUT, "libdvdnav: vm: ifoRead_FP_PGC failed\n"); | |
334 return 0; | |
335 } | |
336 if(!ifoRead_TT_SRPT(vm->vmgi)) { | |
337 fprintf(MSG_OUT, "libdvdnav: vm: ifoRead_TT_SRPT failed\n"); | |
338 return 0; | |
339 } | |
340 if(!ifoRead_PGCI_UT(vm->vmgi)) { | |
341 fprintf(MSG_OUT, "libdvdnav: vm: ifoRead_PGCI_UT failed\n"); | |
342 return 0; | |
343 } | |
344 if(!ifoRead_PTL_MAIT(vm->vmgi)) { | |
345 fprintf(MSG_OUT, "libdvdnav: vm: ifoRead_PTL_MAIT failed\n"); | |
346 /* return 0; Not really used for now.. */ | |
347 } | |
348 if(!ifoRead_VTS_ATRT(vm->vmgi)) { | |
349 fprintf(MSG_OUT, "libdvdnav: vm: ifoRead_VTS_ATRT failed\n"); | |
350 /* return 0; Not really used for now.. */ | |
351 } | |
352 if(!ifoRead_VOBU_ADMAP(vm->vmgi)) { | |
353 fprintf(MSG_OUT, "libdvdnav: vm: ifoRead_VOBU_ADMAP vgmi failed\n"); | |
354 /* return 0; Not really used for now.. */ | |
355 } | |
356 /* ifoRead_TXTDT_MGI(vmgi); Not implemented yet */ | |
357 } | |
358 if (vm->vmgi) { | |
359 int i, mask; | |
360 fprintf(MSG_OUT, "libdvdnav: DVD disk reports itself with Region mask 0x%08x. Regions:", | |
361 vm->vmgi->vmgi_mat->vmg_category); | |
362 for (i = 1, mask = 1; i <= 8; i++, mask <<= 1) | |
363 if (((vm->vmgi->vmgi_mat->vmg_category >> 16) & mask) == 0) | |
364 fprintf(MSG_OUT, " %d", i); | |
365 fprintf(MSG_OUT, "\n"); | |
366 } | |
367 return 1; | |
368 } | |
369 | |
370 | |
371 /* copying and merging */ | |
372 | |
373 vm_t *vm_new_copy(vm_t *source) { | |
374 vm_t *target = vm_new_vm(); | |
375 int vtsN; | |
376 int pgcN = get_PGCN(source); | |
377 int pgN = (source->state).pgN; | |
378 | |
379 assert(pgcN); | |
380 | |
381 memcpy(target, source, sizeof(vm_t)); | |
382 | |
383 /* open a new vtsi handle, because the copy might switch to another VTS */ | |
384 target->vtsi = NULL; | |
385 vtsN = (target->state).vtsN; | |
386 if (vtsN > 0) { | |
387 (target->state).vtsN = 0; | |
256
6299ccea8a38
killing a lot of asserts and turning them into forced executions of Exit,
mroi
parents:
254
diff
changeset
|
388 if (!ifoOpenNewVTSI(target, target->dvd, vtsN)) |
6299ccea8a38
killing a lot of asserts and turning them into forced executions of Exit,
mroi
parents:
254
diff
changeset
|
389 assert(0); |
225 | 390 |
391 /* restore pgc pointer into the new vtsi */ | |
392 if (!set_PGCN(target, pgcN)) | |
393 assert(0); | |
394 (target->state).pgN = pgN; | |
395 } | |
396 | |
397 return target; | |
398 } | |
399 | |
400 void vm_merge(vm_t *target, vm_t *source) { | |
401 if(target->vtsi) | |
402 ifoClose(target->vtsi); | |
403 memcpy(target, source, sizeof(vm_t)); | |
404 memset(source, 0, sizeof(vm_t)); | |
405 } | |
406 | |
407 void vm_free_copy(vm_t *vm) { | |
408 if(vm->vtsi) | |
409 ifoClose(vm->vtsi); | |
410 free(vm); | |
411 } | |
412 | |
413 | |
414 /* regular playback */ | |
415 | |
416 void vm_position_get(vm_t *vm, vm_position_t *position) { | |
417 position->button = (vm->state).HL_BTNN_REG >> 10; | |
418 position->vts = (vm->state).vtsN; | |
419 position->domain = (vm->state).domain; | |
420 position->spu_channel = (vm->state).SPST_REG; | |
421 position->audio_channel = (vm->state).AST_REG; | |
422 position->angle_channel = (vm->state).AGL_REG; | |
423 position->hop_channel = vm->hop_channel; /* Increases by one on each hop */ | |
424 position->cell = (vm->state).cellN; | |
425 position->cell_restart = (vm->state).cell_restart; | |
426 position->cell_start = (vm->state).pgc->cell_playback[(vm->state).cellN - 1].first_sector; | |
427 position->still = (vm->state).pgc->cell_playback[(vm->state).cellN - 1].still_time; | |
428 position->block = (vm->state).blockN; | |
429 | |
430 /* handle PGC stills at PGC end */ | |
431 if ((vm->state).cellN == (vm->state).pgc->nr_of_cells) | |
432 position->still += (vm->state).pgc->still_time; | |
433 /* still already determined */ | |
434 if (position->still) | |
435 return; | |
436 /* This is a rough fix for some strange still situations on some strange DVDs. | |
437 * There are discs (like the German "Back to the Future" RC2) where the only | |
438 * indication of a still is a cell playback time higher than the time the frames | |
439 * in this cell actually take to play (like 1 frame with 1 minute playback time). | |
440 * On the said BTTF disc, for these cells last_sector and last_vobu_start_sector | |
441 * are equal and the cells are very short, so we abuse these conditions to | |
442 * detect such discs. I consider these discs broken, so the fix is somewhat | |
443 * broken, too. */ | |
444 if (((vm->state).pgc->cell_playback[(vm->state).cellN - 1].last_sector == | |
445 (vm->state).pgc->cell_playback[(vm->state).cellN - 1].last_vobu_start_sector) && | |
446 ((vm->state).pgc->cell_playback[(vm->state).cellN - 1].last_sector - | |
447 (vm->state).pgc->cell_playback[(vm->state).cellN - 1].first_sector < 1024)) { | |
448 int time; | |
449 int size = (vm->state).pgc->cell_playback[(vm->state).cellN - 1].last_sector - | |
450 (vm->state).pgc->cell_playback[(vm->state).cellN - 1].first_sector; | |
451 time = ((vm->state).pgc->cell_playback[(vm->state).cellN - 1].playback_time.hour >> 4 ) * 36000; | |
452 time += ((vm->state).pgc->cell_playback[(vm->state).cellN - 1].playback_time.hour & 0x0f) * 3600; | |
453 time += ((vm->state).pgc->cell_playback[(vm->state).cellN - 1].playback_time.minute >> 4 ) * 600; | |
454 time += ((vm->state).pgc->cell_playback[(vm->state).cellN - 1].playback_time.minute & 0x0f) * 60; | |
455 time += ((vm->state).pgc->cell_playback[(vm->state).cellN - 1].playback_time.second >> 4 ) * 10; | |
456 time += ((vm->state).pgc->cell_playback[(vm->state).cellN - 1].playback_time.second & 0x0f) * 1; | |
246 | 457 if (!time || size / time > 30) |
225 | 458 /* datarate is too high, it might be a very short, but regular cell */ |
459 return; | |
460 if (time > 0xff) time = 0xff; | |
461 position->still = time; | |
462 } | |
463 } | |
464 | |
465 void vm_get_next_cell(vm_t *vm) { | |
466 process_command(vm, play_Cell_post(vm)); | |
467 } | |
468 | |
469 | |
470 /* Jumping */ | |
471 | |
472 int vm_jump_pg(vm_t *vm, int pg) { | |
473 (vm->state).pgN = pg; | |
474 process_command(vm, play_PG(vm)); | |
475 return 1; | |
476 } | |
477 | |
478 int vm_jump_cell_block(vm_t *vm, int cell, int block) { | |
479 (vm->state).cellN = cell; | |
480 process_command(vm, play_Cell(vm)); | |
481 /* play_Cell can jump to a different cell in case of angles */ | |
482 if ((vm->state).cellN == cell) | |
483 (vm->state).blockN = block; | |
484 return 1; | |
485 } | |
486 | |
487 int vm_jump_title_part(vm_t *vm, int title, int part) { | |
488 link_t link; | |
489 | |
490 if(!set_PTT(vm, title, part)) | |
491 return 0; | |
492 /* Some DVDs do not want us to jump directly into a title and have | |
493 * PGC pre commands taking us back to some menu. Since we do not like that, | |
494 * we do not execute PGC pre commands that would do a jump. */ | |
495 /* process_command(vm, play_PGC_PG(vm, (vm->state).pgN)); */ | |
496 link = play_PGC_PG(vm, (vm->state).pgN); | |
497 if (link.command != PlayThis) | |
498 /* jump occured -> ignore it and play the PG anyway */ | |
499 process_command(vm, play_PG(vm)); | |
500 else | |
501 process_command(vm, link); | |
502 return 1; | |
503 } | |
504 | |
505 int vm_jump_top_pg(vm_t *vm) { | |
506 process_command(vm, play_PG(vm)); | |
507 return 1; | |
508 } | |
509 | |
510 int vm_jump_next_pg(vm_t *vm) { | |
511 if((vm->state).pgN >= (vm->state).pgc->nr_of_programs) { | |
512 /* last program -> move to TailPGC */ | |
513 process_command(vm, play_PGC_post(vm)); | |
514 return 1; | |
515 } else { | |
516 vm_jump_pg(vm, (vm->state).pgN + 1); | |
517 return 1; | |
518 } | |
519 } | |
520 | |
521 int vm_jump_prev_pg(vm_t *vm) { | |
522 if ((vm->state).pgN <= 1) { | |
523 /* first program -> move to last program of previous PGC */ | |
524 if ((vm->state).pgc->prev_pgc_nr && set_PGCN(vm, (vm->state).pgc->prev_pgc_nr)) { | |
525 process_command(vm, play_PGC(vm)); | |
526 vm_jump_pg(vm, (vm->state).pgc->nr_of_programs); | |
527 return 1; | |
528 } | |
529 return 0; | |
530 } else { | |
531 vm_jump_pg(vm, (vm->state).pgN - 1); | |
532 return 1; | |
533 } | |
534 } | |
535 | |
536 int vm_jump_up(vm_t *vm) { | |
537 if((vm->state).pgc->goup_pgc_nr && set_PGCN(vm, (vm->state).pgc->goup_pgc_nr)) { | |
538 process_command(vm, play_PGC(vm)); | |
539 return 1; | |
540 } | |
541 return 0; | |
542 } | |
543 | |
544 int vm_jump_menu(vm_t *vm, DVDMenuID_t menuid) { | |
545 domain_t old_domain = (vm->state).domain; | |
546 | |
547 switch ((vm->state).domain) { | |
548 case VTS_DOMAIN: | |
549 set_RSMinfo(vm, 0, (vm->state).blockN); | |
550 /* FALL THROUGH */ | |
551 case VTSM_DOMAIN: | |
552 case VMGM_DOMAIN: | |
553 switch(menuid) { | |
554 case DVD_MENU_Title: | |
555 case DVD_MENU_Escape: | |
556 (vm->state).domain = VMGM_DOMAIN; | |
557 break; | |
558 case DVD_MENU_Root: | |
559 case DVD_MENU_Subpicture: | |
560 case DVD_MENU_Audio: | |
561 case DVD_MENU_Angle: | |
562 case DVD_MENU_Part: | |
563 (vm->state).domain = VTSM_DOMAIN; | |
564 break; | |
565 } | |
566 if(get_PGCIT(vm) && set_MENU(vm, menuid)) { | |
567 process_command(vm, play_PGC(vm)); | |
568 return 1; /* Jump */ | |
569 } else { | |
570 (vm->state).domain = old_domain; | |
571 } | |
572 break; | |
573 case FP_DOMAIN: /* FIXME XXX $$$ What should we do here? */ | |
574 break; | |
575 } | |
576 | |
577 return 0; | |
578 } | |
579 | |
580 int vm_jump_resume(vm_t *vm) { | |
581 link_t link_values = { LinkRSM, 0, 0, 0 }; | |
582 | |
583 if (!(vm->state).rsm_vtsN) /* Do we have resume info? */ | |
584 return 0; | |
585 if (!process_command(vm, link_values)) | |
586 return 0; | |
587 return 1; | |
588 } | |
589 | |
590 int vm_exec_cmd(vm_t *vm, vm_cmd_t *cmd) { | |
591 link_t link_values; | |
592 | |
593 if(vmEval_CMD(cmd, 1, &(vm->state).registers, &link_values)) | |
594 return process_command(vm, link_values); | |
595 else | |
596 return 0; /* It updated some state thats all... */ | |
597 } | |
598 | |
599 | |
600 /* getting information */ | |
601 | |
602 int vm_get_current_menu(vm_t *vm, int *menuid) { | |
603 pgcit_t* pgcit; | |
604 int pgcn; | |
605 pgcn = (vm->state).pgcN; | |
606 pgcit = get_PGCIT(vm); | |
607 *menuid = pgcit->pgci_srp[pgcn - 1].entry_id & 0xf ; | |
608 return 1; | |
609 } | |
610 | |
611 int vm_get_current_title_part(vm_t *vm, int *title_result, int *part_result) { | |
612 vts_ptt_srpt_t *vts_ptt_srpt; | |
613 int title, part = 0, vts_ttn; | |
614 int found; | |
615 int16_t pgcN, pgN; | |
616 | |
617 vts_ptt_srpt = vm->vtsi->vts_ptt_srpt; | |
618 pgcN = get_PGCN(vm); | |
619 pgN = vm->state.pgN; | |
620 | |
621 found = 0; | |
622 for (vts_ttn = 0; (vts_ttn < vts_ptt_srpt->nr_of_srpts) && !found; vts_ttn++) { | |
623 for (part = 0; (part < vts_ptt_srpt->title[vts_ttn].nr_of_ptts) && !found; part++) { | |
624 if (vts_ptt_srpt->title[vts_ttn].ptt[part].pgcn == pgcN) { | |
625 if (vts_ptt_srpt->title[vts_ttn].ptt[part].pgn == pgN) { | |
626 found = 1; | |
627 break; | |
628 } | |
629 if (part > 0 && vts_ptt_srpt->title[vts_ttn].ptt[part].pgn > pgN && | |
630 vts_ptt_srpt->title[vts_ttn].ptt[part - 1].pgn < pgN) { | |
631 part--; | |
632 found = 1; | |
633 break; | |
634 } | |
635 } | |
636 } | |
637 if (found) break; | |
638 } | |
639 vts_ttn++; | |
640 part++; | |
641 | |
642 if (!found) { | |
643 fprintf(MSG_OUT, "libdvdnav: chapter NOT FOUND!\n"); | |
644 return 0; | |
645 } | |
646 | |
647 title = get_TT(vm, vm->state.vtsN, vts_ttn); | |
648 | |
649 #ifdef TRACE | |
650 if (title) { | |
651 fprintf(MSG_OUT, "libdvdnav: ************ this chapter FOUND!\n"); | |
652 fprintf(MSG_OUT, "libdvdnav: VTS_PTT_SRPT - Title %3i part %3i: PGC: %3i PG: %3i\n", | |
653 title, part, | |
654 vts_ptt_srpt->title[vts_ttn-1].ptt[part-1].pgcn , | |
655 vts_ptt_srpt->title[vts_ttn-1].ptt[part-1].pgn ); | |
656 } | |
657 #endif | |
658 *title_result = title; | |
659 *part_result = part; | |
660 return 1; | |
661 } | |
662 | |
663 /* Return the substream id for 'logical' audio stream audioN. | |
664 * 0 <= audioN < 8 | |
665 */ | |
666 int vm_get_audio_stream(vm_t *vm, int audioN) { | |
667 int streamN = -1; | |
668 | |
669 if((vm->state).domain != VTS_DOMAIN) | |
670 audioN = 0; | |
671 | |
672 if(audioN < 8) { | |
673 /* Is there any control info for this logical stream */ | |
674 if((vm->state).pgc->audio_control[audioN] & (1<<15)) { | |
675 streamN = ((vm->state).pgc->audio_control[audioN] >> 8) & 0x07; | |
676 } | |
677 } | |
678 | |
679 if((vm->state).domain != VTS_DOMAIN && streamN == -1) | |
680 streamN = 0; | |
681 | |
682 /* FIXME: Should also check in vtsi/vmgi status what kind of stream | |
683 * it is (ac3/lpcm/dts/sdds...) to find the right (sub)stream id */ | |
684 return streamN; | |
685 } | |
686 | |
687 /* Return the substream id for 'logical' subpicture stream subpN and given mode. | |
688 * 0 <= subpN < 32 | |
689 * mode == 0 - widescreen | |
690 * mode == 1 - letterbox | |
691 * mode == 2 - pan&scan | |
692 */ | |
693 int vm_get_subp_stream(vm_t *vm, int subpN, int mode) { | |
694 int streamN = -1; | |
695 int source_aspect = vm_get_video_aspect(vm); | |
696 | |
697 if((vm->state).domain != VTS_DOMAIN) | |
698 subpN = 0; | |
699 | |
700 if(subpN < 32) { /* a valid logical stream */ | |
701 /* Is this logical stream present */ | |
702 if((vm->state).pgc->subp_control[subpN] & (1<<31)) { | |
703 if(source_aspect == 0) /* 4:3 */ | |
704 streamN = ((vm->state).pgc->subp_control[subpN] >> 24) & 0x1f; | |
705 if(source_aspect == 3) /* 16:9 */ | |
706 switch (mode) { | |
707 case 0: | |
708 streamN = ((vm->state).pgc->subp_control[subpN] >> 16) & 0x1f; | |
709 break; | |
710 case 1: | |
711 streamN = ((vm->state).pgc->subp_control[subpN] >> 8) & 0x1f; | |
712 break; | |
713 case 2: | |
714 streamN = (vm->state).pgc->subp_control[subpN] & 0x1f; | |
715 } | |
716 } | |
717 } | |
718 | |
247 | 719 if((vm->state).domain != VTS_DOMAIN && streamN == -1) |
720 streamN = 0; | |
225 | 721 |
722 /* FIXME: Should also check in vtsi/vmgi status what kind of stream it is. */ | |
723 return streamN; | |
724 } | |
725 | |
726 int vm_get_audio_active_stream(vm_t *vm) { | |
727 int audioN; | |
728 int streamN; | |
729 audioN = (vm->state).AST_REG ; | |
730 streamN = vm_get_audio_stream(vm, audioN); | |
731 | |
732 /* If no such stream, then select the first one that exists. */ | |
733 if(streamN == -1) { | |
734 for(audioN = 0; audioN < 8; audioN++) { | |
735 if((vm->state).pgc->audio_control[audioN] & (1<<15)) { | |
736 if ((streamN = vm_get_audio_stream(vm, audioN)) >= 0) | |
737 break; | |
738 } | |
739 } | |
740 } | |
741 | |
742 return streamN; | |
743 } | |
744 | |
745 int vm_get_subp_active_stream(vm_t *vm, int mode) { | |
746 int subpN; | |
747 int streamN; | |
748 subpN = (vm->state).SPST_REG & ~0x40; | |
749 streamN = vm_get_subp_stream(vm, subpN, mode); | |
750 | |
751 /* If no such stream, then select the first one that exists. */ | |
752 if(streamN == -1) { | |
753 for(subpN = 0; subpN < 32; subpN++) { | |
754 if((vm->state).pgc->subp_control[subpN] & (1<<31)) { | |
755 if ((streamN = vm_get_subp_stream(vm, subpN, mode)) >= 0) | |
756 break; | |
757 } | |
758 } | |
759 } | |
760 | |
761 if((vm->state).domain == VTS_DOMAIN && !((vm->state).SPST_REG & 0x40)) | |
762 /* Bit 7 set means hide, and only let Forced display show */ | |
763 return (streamN | 0x80); | |
764 else | |
765 return streamN; | |
766 } | |
767 | |
768 void vm_get_angle_info(vm_t *vm, int *current, int *num_avail) { | |
769 *num_avail = 1; | |
770 *current = 1; | |
771 | |
772 if((vm->state).domain == VTS_DOMAIN) { | |
773 title_info_t *title; | |
774 /* TTN_REG does not allways point to the correct title.. */ | |
775 if((vm->state).TTN_REG > vm->vmgi->tt_srpt->nr_of_srpts) | |
776 return; | |
777 title = &vm->vmgi->tt_srpt->title[(vm->state).TTN_REG - 1]; | |
778 if(title->title_set_nr != (vm->state).vtsN || | |
779 title->vts_ttn != (vm->state).VTS_TTN_REG) | |
780 return; | |
781 *num_avail = title->nr_of_angles; | |
782 *current = (vm->state).AGL_REG; | |
783 } | |
784 } | |
785 | |
786 #if 0 | |
787 /* currently unused */ | |
788 void vm_get_audio_info(vm_t *vm, int *current, int *num_avail) { | |
789 switch ((vm->state).domain) { | |
790 case VTS_DOMAIN: | |
791 *num_avail = vm->vtsi->vtsi_mat->nr_of_vts_audio_streams; | |
792 *current = (vm->state).AST_REG; | |
793 break; | |
794 case VTSM_DOMAIN: | |
795 *num_avail = vm->vtsi->vtsi_mat->nr_of_vtsm_audio_streams; /* 1 */ | |
796 *current = 1; | |
797 break; | |
798 case VMGM_DOMAIN: | |
799 case FP_DOMAIN: | |
800 *num_avail = vm->vmgi->vmgi_mat->nr_of_vmgm_audio_streams; /* 1 */ | |
801 *current = 1; | |
802 break; | |
803 } | |
804 } | |
805 | |
806 /* currently unused */ | |
807 void vm_get_subp_info(vm_t *vm, int *current, int *num_avail) { | |
808 switch ((vm->state).domain) { | |
809 case VTS_DOMAIN: | |
810 *num_avail = vm->vtsi->vtsi_mat->nr_of_vts_subp_streams; | |
811 *current = (vm->state).SPST_REG; | |
812 break; | |
813 case VTSM_DOMAIN: | |
814 *num_avail = vm->vtsi->vtsi_mat->nr_of_vtsm_subp_streams; /* 1 */ | |
815 *current = 0x41; | |
816 break; | |
817 case VMGM_DOMAIN: | |
818 case FP_DOMAIN: | |
819 *num_avail = vm->vmgi->vmgi_mat->nr_of_vmgm_subp_streams; /* 1 */ | |
820 *current = 0x41; | |
821 break; | |
822 } | |
823 } | |
824 | |
825 /* currently unused */ | |
826 void vm_get_video_res(vm_t *vm, int *width, int *height) { | |
827 video_attr_t attr = vm_get_video_attr(vm); | |
828 | |
829 if(attr.video_format != 0) | |
830 *height = 576; | |
831 else | |
832 *height = 480; | |
833 switch(attr.picture_size) { | |
834 case 0: | |
835 *width = 720; | |
836 break; | |
837 case 1: | |
838 *width = 704; | |
839 break; | |
840 case 2: | |
841 *width = 352; | |
842 break; | |
843 case 3: | |
844 *width = 352; | |
845 *height /= 2; | |
846 break; | |
847 } | |
848 } | |
849 #endif | |
850 | |
851 int vm_get_video_aspect(vm_t *vm) { | |
852 int aspect = vm_get_video_attr(vm).display_aspect_ratio; | |
853 | |
854 assert(aspect == 0 || aspect == 3); | |
855 (vm->state).registers.SPRM[14] &= ~(0x3 << 10); | |
856 (vm->state).registers.SPRM[14] |= aspect << 10; | |
857 | |
858 return aspect; | |
859 } | |
860 | |
861 int vm_get_video_scale_permission(vm_t *vm) { | |
862 return vm_get_video_attr(vm).permitted_df; | |
863 } | |
864 | |
865 video_attr_t vm_get_video_attr(vm_t *vm) { | |
866 switch ((vm->state).domain) { | |
867 case VTS_DOMAIN: | |
868 return vm->vtsi->vtsi_mat->vts_video_attr; | |
869 case VTSM_DOMAIN: | |
870 return vm->vtsi->vtsi_mat->vtsm_video_attr; | |
871 case VMGM_DOMAIN: | |
872 case FP_DOMAIN: | |
873 return vm->vmgi->vmgi_mat->vmgm_video_attr; | |
243
e75c52894630
* assert(0) does not always and the program (see NDEBUG)
mroi
parents:
229
diff
changeset
|
874 default: |
e75c52894630
* assert(0) does not always and the program (see NDEBUG)
mroi
parents:
229
diff
changeset
|
875 abort(); |
225 | 876 } |
877 } | |
878 | |
879 audio_attr_t vm_get_audio_attr(vm_t *vm, int streamN) { | |
880 switch ((vm->state).domain) { | |
881 case VTS_DOMAIN: | |
882 return vm->vtsi->vtsi_mat->vts_audio_attr[streamN]; | |
883 case VTSM_DOMAIN: | |
884 return vm->vtsi->vtsi_mat->vtsm_audio_attr; | |
885 case VMGM_DOMAIN: | |
886 case FP_DOMAIN: | |
887 return vm->vmgi->vmgi_mat->vmgm_audio_attr; | |
243
e75c52894630
* assert(0) does not always and the program (see NDEBUG)
mroi
parents:
229
diff
changeset
|
888 default: |
e75c52894630
* assert(0) does not always and the program (see NDEBUG)
mroi
parents:
229
diff
changeset
|
889 abort(); |
225 | 890 } |
891 } | |
892 | |
893 subp_attr_t vm_get_subp_attr(vm_t *vm, int streamN) { | |
894 switch ((vm->state).domain) { | |
895 case VTS_DOMAIN: | |
896 return vm->vtsi->vtsi_mat->vts_subp_attr[streamN]; | |
897 case VTSM_DOMAIN: | |
898 return vm->vtsi->vtsi_mat->vtsm_subp_attr; | |
899 case VMGM_DOMAIN: | |
900 case FP_DOMAIN: | |
901 return vm->vmgi->vmgi_mat->vmgm_subp_attr; | |
243
e75c52894630
* assert(0) does not always and the program (see NDEBUG)
mroi
parents:
229
diff
changeset
|
902 default: |
e75c52894630
* assert(0) does not always and the program (see NDEBUG)
mroi
parents:
229
diff
changeset
|
903 abort(); |
225 | 904 } |
905 } | |
906 | |
907 | |
908 /* Playback control */ | |
909 | |
910 static link_t play_PGC(vm_t *vm) { | |
911 link_t link_values; | |
912 | |
913 #ifdef TRACE | |
914 fprintf(MSG_OUT, "libdvdnav: play_PGC:"); | |
915 if((vm->state).domain != FP_DOMAIN) { | |
916 fprintf(MSG_OUT, " (vm->state).pgcN (%i)\n", get_PGCN(vm)); | |
917 } else { | |
918 fprintf(MSG_OUT, " first_play_pgc\n"); | |
919 } | |
920 #endif | |
921 | |
922 /* This must be set before the pre-commands are executed because they | |
923 * might contain a CallSS that will save resume state */ | |
924 | |
925 /* FIXME: This may be only a temporary fix for something... */ | |
926 (vm->state).pgN = 1; | |
927 (vm->state).cellN = 0; | |
928 (vm->state).blockN = 0; | |
929 | |
930 /* eval -> updates the state and returns either | |
931 - some kind of jump (Jump(TT/SS/VTS_TTN/CallSS/link C/PG/PGC/PTTN) | |
932 - just play video i.e first PG | |
933 (This is what happens if you fall of the end of the pre_cmds) | |
934 - or an error (are there more cases?) */ | |
935 if((vm->state).pgc->command_tbl && (vm->state).pgc->command_tbl->nr_of_pre) { | |
936 if(vmEval_CMD((vm->state).pgc->command_tbl->pre_cmds, | |
937 (vm->state).pgc->command_tbl->nr_of_pre, | |
938 &(vm->state).registers, &link_values)) { | |
939 /* link_values contains the 'jump' return value */ | |
940 return link_values; | |
941 } else { | |
942 #ifdef TRACE | |
943 fprintf(MSG_OUT, "libdvdnav: PGC pre commands didn't do a Jump, Link or Call\n"); | |
944 #endif | |
945 } | |
946 } | |
947 return play_PG(vm); | |
948 } | |
949 | |
950 static link_t play_PGC_PG(vm_t *vm, int pgN) { | |
951 link_t link_values; | |
952 | |
953 #ifdef TRACE | |
954 fprintf(MSG_OUT, "libdvdnav: play_PGC_PG:"); | |
955 if((vm->state).domain != FP_DOMAIN) { | |
956 fprintf(MSG_OUT, " (vm->state).pgcN (%i)\n", get_PGCN(vm)); | |
957 } else { | |
958 fprintf(MSG_OUT, " first_play_pgc\n"); | |
959 } | |
960 #endif | |
961 | |
962 /* This must be set before the pre-commands are executed because they | |
963 * might contain a CallSS that will save resume state */ | |
964 | |
965 /* FIXME: This may be only a temporary fix for something... */ | |
966 (vm->state).pgN = pgN; | |
967 (vm->state).cellN = 0; | |
968 (vm->state).blockN = 0; | |
969 | |
970 /* eval -> updates the state and returns either | |
971 - some kind of jump (Jump(TT/SS/VTS_TTN/CallSS/link C/PG/PGC/PTTN) | |
972 - just play video i.e first PG | |
973 (This is what happens if you fall of the end of the pre_cmds) | |
974 - or an error (are there more cases?) */ | |
975 if((vm->state).pgc->command_tbl && (vm->state).pgc->command_tbl->nr_of_pre) { | |
976 if(vmEval_CMD((vm->state).pgc->command_tbl->pre_cmds, | |
977 (vm->state).pgc->command_tbl->nr_of_pre, | |
978 &(vm->state).registers, &link_values)) { | |
979 /* link_values contains the 'jump' return value */ | |
980 return link_values; | |
981 } else { | |
982 #ifdef TRACE | |
983 fprintf(MSG_OUT, "libdvdnav: PGC pre commands didn't do a Jump, Link or Call\n"); | |
984 #endif | |
985 } | |
986 } | |
987 return play_PG(vm); | |
988 } | |
989 | |
990 static link_t play_PGC_post(vm_t *vm) { | |
991 link_t link_values; | |
992 | |
993 #ifdef TRACE | |
994 fprintf(MSG_OUT, "libdvdnav: play_PGC_post:\n"); | |
995 #endif | |
996 | |
997 /* eval -> updates the state and returns either | |
998 - some kind of jump (Jump(TT/SS/VTS_TTN/CallSS/link C/PG/PGC/PTTN) | |
999 - just go to next PGC | |
1000 (This is what happens if you fall of the end of the post_cmds) | |
1001 - or an error (are there more cases?) */ | |
1002 if((vm->state).pgc->command_tbl && (vm->state).pgc->command_tbl->nr_of_post && | |
1003 vmEval_CMD((vm->state).pgc->command_tbl->post_cmds, | |
1004 (vm->state).pgc->command_tbl->nr_of_post, | |
1005 &(vm->state).registers, &link_values)) { | |
1006 return link_values; | |
1007 } | |
1008 | |
1009 #ifdef TRACE | |
1010 fprintf(MSG_OUT, "libdvdnav: ** Fell of the end of the pgc, continuing in NextPGC\n"); | |
1011 #endif | |
1012 /* Should end up in the STOP_DOMAIN if next_pgc is 0. */ | |
1013 if(!set_PGCN(vm, (vm->state).pgc->next_pgc_nr)) { | |
1014 link_values.command = Exit; | |
1015 return link_values; | |
1016 } | |
1017 return play_PGC(vm); | |
1018 } | |
1019 | |
1020 static link_t play_PG(vm_t *vm) { | |
1021 #ifdef TRACE | |
1022 fprintf(MSG_OUT, "libdvdnav: play_PG: (vm->state).pgN (%i)\n", (vm->state).pgN); | |
1023 #endif | |
1024 | |
1025 assert((vm->state).pgN > 0); | |
1026 if((vm->state).pgN > (vm->state).pgc->nr_of_programs) { | |
1027 #ifdef TRACE | |
1028 fprintf(MSG_OUT, "libdvdnav: play_PG: (vm->state).pgN (%i) > pgc->nr_of_programs (%i)\n", | |
1029 (vm->state).pgN, (vm->state).pgc->nr_of_programs ); | |
1030 #endif | |
1031 assert((vm->state).pgN == (vm->state).pgc->nr_of_programs + 1); | |
1032 return play_PGC_post(vm); | |
1033 } | |
1034 | |
1035 (vm->state).cellN = (vm->state).pgc->program_map[(vm->state).pgN - 1]; | |
1036 | |
1037 return play_Cell(vm); | |
1038 } | |
1039 | |
1040 static link_t play_Cell(vm_t *vm) { | |
1041 static const link_t play_this = {PlayThis, /* Block in Cell */ 0, 0, 0}; | |
1042 | |
1043 #ifdef TRACE | |
1044 fprintf(MSG_OUT, "libdvdnav: play_Cell: (vm->state).cellN (%i)\n", (vm->state).cellN); | |
1045 #endif | |
1046 | |
1047 assert((vm->state).cellN > 0); | |
1048 if((vm->state).cellN > (vm->state).pgc->nr_of_cells) { | |
1049 #ifdef TRACE | |
1050 fprintf(MSG_OUT, "libdvdnav: (vm->state).cellN (%i) > pgc->nr_of_cells (%i)\n", | |
1051 (vm->state).cellN, (vm->state).pgc->nr_of_cells ); | |
1052 #endif | |
1053 assert((vm->state).cellN == (vm->state).pgc->nr_of_cells + 1); | |
1054 return play_PGC_post(vm); | |
1055 } | |
1056 | |
1057 /* Multi angle/Interleaved */ | |
1058 switch((vm->state).pgc->cell_playback[(vm->state).cellN - 1].block_mode) { | |
1059 case 0: /* Normal */ | |
1060 assert((vm->state).pgc->cell_playback[(vm->state).cellN - 1].block_type == 0); | |
1061 break; | |
1062 case 1: /* The first cell in the block */ | |
1063 switch((vm->state).pgc->cell_playback[(vm->state).cellN - 1].block_type) { | |
1064 case 0: /* Not part of a block */ | |
1065 assert(0); | |
243
e75c52894630
* assert(0) does not always and the program (see NDEBUG)
mroi
parents:
229
diff
changeset
|
1066 break; |
225 | 1067 case 1: /* Angle block */ |
1068 /* Loop and check each cell instead? So we don't get outside the block? */ | |
1069 (vm->state).cellN += (vm->state).AGL_REG - 1; | |
1070 #ifdef STRICT | |
1071 assert((vm->state).cellN <= (vm->state).pgc->nr_of_cells); | |
1072 assert((vm->state).pgc->cell_playback[(vm->state).cellN - 1].block_mode != 0); | |
1073 assert((vm->state).pgc->cell_playback[(vm->state).cellN - 1].block_type == 1); | |
1074 #else | |
1075 if (!((vm->state).cellN <= (vm->state).pgc->nr_of_cells) || | |
1076 !((vm->state).pgc->cell_playback[(vm->state).cellN - 1].block_mode != 0) || | |
1077 !((vm->state).pgc->cell_playback[(vm->state).cellN - 1].block_type == 1)) { | |
1078 fprintf(MSG_OUT, "libdvdnav: Invalid angle block\n"); | |
1079 (vm->state).cellN -= (vm->state).AGL_REG - 1; | |
1080 } | |
1081 #endif | |
1082 break; | |
1083 case 2: /* ?? */ | |
1084 case 3: /* ?? */ | |
1085 default: | |
1086 fprintf(MSG_OUT, "libdvdnav: Invalid? Cell block_mode (%d), block_type (%d)\n", | |
1087 (vm->state).pgc->cell_playback[(vm->state).cellN - 1].block_mode, | |
1088 (vm->state).pgc->cell_playback[(vm->state).cellN - 1].block_type); | |
1089 assert(0); | |
1090 } | |
1091 break; | |
1092 case 2: /* Cell in the block */ | |
1093 case 3: /* Last cell in the block */ | |
1094 /* These might perhaps happen for RSM or LinkC commands? */ | |
1095 default: | |
1096 fprintf(MSG_OUT, "libdvdnav: Cell is in block but did not enter at first cell!\n"); | |
1097 } | |
1098 | |
1099 /* Updates (vm->state).pgN and PTTN_REG */ | |
1100 if(!set_PGN(vm)) { | |
1101 /* Should not happen */ | |
1102 assert(0); | |
1103 return play_PGC_post(vm); | |
1104 } | |
1105 (vm->state).cell_restart++; | |
1106 (vm->state).blockN = 0; | |
1107 #ifdef TRACE | |
1108 fprintf(MSG_OUT, "libdvdnav: Cell should restart here\n"); | |
1109 #endif | |
1110 return play_this; | |
1111 } | |
1112 | |
1113 static link_t play_Cell_post(vm_t *vm) { | |
1114 cell_playback_t *cell; | |
1115 | |
1116 #ifdef TRACE | |
1117 fprintf(MSG_OUT, "libdvdnav: play_Cell_post: (vm->state).cellN (%i)\n", (vm->state).cellN); | |
1118 #endif | |
1119 | |
1120 cell = &(vm->state).pgc->cell_playback[(vm->state).cellN - 1]; | |
1121 | |
1122 /* Still time is already taken care of before we get called. */ | |
1123 | |
1124 /* Deal with a Cell command, if any */ | |
1125 if(cell->cell_cmd_nr != 0) { | |
1126 link_t link_values; | |
1127 | |
1128 /* These asserts are now not needed. | |
1129 * Some DVDs have no cell commands listed in the PGC, | |
1130 * but the Cell itself points to a cell command that does not exist. | |
1131 * For this situation, just ignore the cell command and continue. | |
1132 * | |
1133 * assert((vm->state).pgc->command_tbl != NULL); | |
1134 * assert((vm->state).pgc->command_tbl->nr_of_cell >= cell->cell_cmd_nr); | |
1135 */ | |
1136 | |
1137 if ((vm->state).pgc->command_tbl != NULL && | |
1138 (vm->state).pgc->command_tbl->nr_of_cell >= cell->cell_cmd_nr) { | |
1139 #ifdef TRACE | |
1140 fprintf(MSG_OUT, "libdvdnav: Cell command present, executing\n"); | |
1141 #endif | |
1142 if(vmEval_CMD(&(vm->state).pgc->command_tbl->cell_cmds[cell->cell_cmd_nr - 1], 1, | |
1143 &(vm->state).registers, &link_values)) { | |
1144 return link_values; | |
1145 } else { | |
1146 #ifdef TRACE | |
1147 fprintf(MSG_OUT, "libdvdnav: Cell command didn't do a Jump, Link or Call\n"); | |
1148 #endif | |
1149 } | |
1150 } else { | |
1151 #ifdef TRACE | |
1152 fprintf(MSG_OUT, "libdvdnav: Invalid Cell command\n"); | |
1153 #endif | |
1154 } | |
1155 } | |
1156 | |
1157 /* Where to continue after playing the cell... */ | |
1158 /* Multi angle/Interleaved */ | |
1159 switch((vm->state).pgc->cell_playback[(vm->state).cellN - 1].block_mode) { | |
1160 case 0: /* Normal */ | |
1161 assert((vm->state).pgc->cell_playback[(vm->state).cellN - 1].block_type == 0); | |
1162 (vm->state).cellN++; | |
1163 break; | |
1164 case 1: /* The first cell in the block */ | |
1165 case 2: /* A cell in the block */ | |
1166 case 3: /* The last cell in the block */ | |
1167 default: | |
1168 switch((vm->state).pgc->cell_playback[(vm->state).cellN - 1].block_type) { | |
1169 case 0: /* Not part of a block */ | |
1170 assert(0); | |
243
e75c52894630
* assert(0) does not always and the program (see NDEBUG)
mroi
parents:
229
diff
changeset
|
1171 break; |
225 | 1172 case 1: /* Angle block */ |
1173 /* Skip the 'other' angles */ | |
1174 (vm->state).cellN++; | |
1175 while((vm->state).cellN <= (vm->state).pgc->nr_of_cells && | |
1176 (vm->state).pgc->cell_playback[(vm->state).cellN - 1].block_mode >= 2) { | |
1177 (vm->state).cellN++; | |
1178 } | |
1179 break; | |
1180 case 2: /* ?? */ | |
1181 case 3: /* ?? */ | |
1182 default: | |
1183 fprintf(MSG_OUT, "libdvdnav: Invalid? Cell block_mode (%d), block_type (%d)\n", | |
1184 (vm->state).pgc->cell_playback[(vm->state).cellN - 1].block_mode, | |
1185 (vm->state).pgc->cell_playback[(vm->state).cellN - 1].block_type); | |
1186 assert(0); | |
1187 } | |
1188 break; | |
1189 } | |
1190 | |
1191 /* Figure out the correct pgN for the new cell */ | |
1192 if(!set_PGN(vm)) { | |
1193 #ifdef TRACE | |
1194 fprintf(MSG_OUT, "libdvdnav: last cell in this PGC\n"); | |
1195 #endif | |
1196 return play_PGC_post(vm); | |
1197 } | |
1198 return play_Cell(vm); | |
1199 } | |
1200 | |
1201 | |
1202 /* link processing */ | |
1203 | |
1204 static int process_command(vm_t *vm, link_t link_values) { | |
1205 | |
1206 while(link_values.command != PlayThis) { | |
1207 | |
1208 #ifdef TRACE | |
1209 fprintf(MSG_OUT, "libdvdnav: Before printout starts:\n"); | |
1210 vm_print_link(link_values); | |
1211 fprintf(MSG_OUT, "libdvdnav: Link values %i %i %i %i\n", link_values.command, | |
1212 link_values.data1, link_values.data2, link_values.data3); | |
1213 vm_print_current_domain_state(vm); | |
1214 fprintf(MSG_OUT, "libdvdnav: Before printout ends.\n"); | |
1215 #endif | |
1216 | |
1217 switch(link_values.command) { | |
1218 case LinkNoLink: | |
1219 /* BUTTON number:data1 */ | |
1220 if(link_values.data1 != 0) | |
1221 (vm->state).HL_BTNN_REG = link_values.data1 << 10; | |
1222 return 0; /* no actual jump */ | |
1223 | |
1224 case LinkTopC: | |
1225 /* Restart playing from the beginning of the current Cell. */ | |
1226 /* BUTTON number:data1 */ | |
1227 if(link_values.data1 != 0) | |
1228 (vm->state).HL_BTNN_REG = link_values.data1 << 10; | |
1229 link_values = play_Cell(vm); | |
1230 break; | |
1231 case LinkNextC: | |
1232 /* Link to Next Cell */ | |
1233 /* BUTTON number:data1 */ | |
1234 if(link_values.data1 != 0) | |
1235 (vm->state).HL_BTNN_REG = link_values.data1 << 10; | |
1236 (vm->state).cellN += 1; | |
1237 link_values = play_Cell(vm); | |
1238 break; | |
1239 case LinkPrevC: | |
1240 /* Link to Previous Cell */ | |
1241 /* BUTTON number:data1 */ | |
1242 if(link_values.data1 != 0) | |
1243 (vm->state).HL_BTNN_REG = link_values.data1 << 10; | |
1244 assert((vm->state).cellN > 1); | |
1245 (vm->state).cellN -= 1; | |
1246 link_values = play_Cell(vm); | |
1247 break; | |
1248 | |
1249 case LinkTopPG: | |
1250 /* Link to Top of current Program */ | |
1251 /* BUTTON number:data1 */ | |
1252 if(link_values.data1 != 0) | |
1253 (vm->state).HL_BTNN_REG = link_values.data1 << 10; | |
1254 link_values = play_PG(vm); | |
1255 break; | |
1256 case LinkNextPG: | |
1257 /* Link to Next Program */ | |
1258 /* BUTTON number:data1 */ | |
1259 if(link_values.data1 != 0) | |
1260 (vm->state).HL_BTNN_REG = link_values.data1 << 10; | |
1261 (vm->state).pgN += 1; | |
1262 link_values = play_PG(vm); | |
1263 break; | |
1264 case LinkPrevPG: | |
1265 /* Link to Previous Program */ | |
1266 /* BUTTON number:data1 */ | |
1267 if(link_values.data1 != 0) | |
1268 (vm->state).HL_BTNN_REG = link_values.data1 << 10; | |
1269 assert((vm->state).pgN > 1); | |
1270 (vm->state).pgN -= 1; | |
1271 link_values = play_PG(vm); | |
1272 break; | |
1273 | |
1274 case LinkTopPGC: | |
1275 /* Restart playing from beginning of current Program Chain */ | |
1276 /* BUTTON number:data1 */ | |
1277 if(link_values.data1 != 0) | |
1278 (vm->state).HL_BTNN_REG = link_values.data1 << 10; | |
1279 link_values = play_PGC(vm); | |
1280 break; | |
1281 case LinkNextPGC: | |
1282 /* Link to Next Program Chain */ | |
1283 /* BUTTON number:data1 */ | |
1284 if(link_values.data1 != 0) | |
1285 (vm->state).HL_BTNN_REG = link_values.data1 << 10; | |
1286 assert((vm->state).pgc->next_pgc_nr != 0); | |
256
6299ccea8a38
killing a lot of asserts and turning them into forced executions of Exit,
mroi
parents:
254
diff
changeset
|
1287 if(set_PGCN(vm, (vm->state).pgc->next_pgc_nr)) |
6299ccea8a38
killing a lot of asserts and turning them into forced executions of Exit,
mroi
parents:
254
diff
changeset
|
1288 link_values = play_PGC(vm); |
6299ccea8a38
killing a lot of asserts and turning them into forced executions of Exit,
mroi
parents:
254
diff
changeset
|
1289 else |
6299ccea8a38
killing a lot of asserts and turning them into forced executions of Exit,
mroi
parents:
254
diff
changeset
|
1290 link_values.command = Exit; |
225 | 1291 break; |
1292 case LinkPrevPGC: | |
1293 /* Link to Previous Program Chain */ | |
1294 /* BUTTON number:data1 */ | |
1295 if(link_values.data1 != 0) | |
1296 (vm->state).HL_BTNN_REG = link_values.data1 << 10; | |
1297 assert((vm->state).pgc->prev_pgc_nr != 0); | |
256
6299ccea8a38
killing a lot of asserts and turning them into forced executions of Exit,
mroi
parents:
254
diff
changeset
|
1298 if(set_PGCN(vm, (vm->state).pgc->prev_pgc_nr)) |
6299ccea8a38
killing a lot of asserts and turning them into forced executions of Exit,
mroi
parents:
254
diff
changeset
|
1299 link_values = play_PGC(vm); |
6299ccea8a38
killing a lot of asserts and turning them into forced executions of Exit,
mroi
parents:
254
diff
changeset
|
1300 else |
6299ccea8a38
killing a lot of asserts and turning them into forced executions of Exit,
mroi
parents:
254
diff
changeset
|
1301 link_values.command = Exit; |
225 | 1302 break; |
1303 case LinkGoUpPGC: | |
1304 /* Link to GoUp Program Chain */ | |
1305 /* BUTTON number:data1 */ | |
1306 if(link_values.data1 != 0) | |
1307 (vm->state).HL_BTNN_REG = link_values.data1 << 10; | |
1308 assert((vm->state).pgc->goup_pgc_nr != 0); | |
256
6299ccea8a38
killing a lot of asserts and turning them into forced executions of Exit,
mroi
parents:
254
diff
changeset
|
1309 if(set_PGCN(vm, (vm->state).pgc->goup_pgc_nr)) |
6299ccea8a38
killing a lot of asserts and turning them into forced executions of Exit,
mroi
parents:
254
diff
changeset
|
1310 link_values = play_PGC(vm); |
6299ccea8a38
killing a lot of asserts and turning them into forced executions of Exit,
mroi
parents:
254
diff
changeset
|
1311 else |
6299ccea8a38
killing a lot of asserts and turning them into forced executions of Exit,
mroi
parents:
254
diff
changeset
|
1312 link_values.command = Exit; |
225 | 1313 break; |
1314 case LinkTailPGC: | |
1315 /* Link to Tail of Program Chain */ | |
1316 /* BUTTON number:data1 */ | |
1317 if(link_values.data1 != 0) | |
1318 (vm->state).HL_BTNN_REG = link_values.data1 << 10; | |
1319 link_values = play_PGC_post(vm); | |
1320 break; | |
1321 | |
1322 case LinkRSM: | |
1323 { | |
1324 /* Link to Resume point */ | |
1325 int i; | |
1326 | |
1327 /* Check and see if there is any rsm info!! */ | |
1328 if (!(vm->state).rsm_vtsN) { | |
1329 fprintf(MSG_OUT, "libdvdnav: trying to resume without any resume info set\n"); | |
1330 link_values.command = Exit; | |
1331 break; | |
1332 } | |
1333 | |
1334 (vm->state).domain = VTS_DOMAIN; | |
256
6299ccea8a38
killing a lot of asserts and turning them into forced executions of Exit,
mroi
parents:
254
diff
changeset
|
1335 if (!ifoOpenNewVTSI(vm, vm->dvd, (vm->state).rsm_vtsN)) |
6299ccea8a38
killing a lot of asserts and turning them into forced executions of Exit,
mroi
parents:
254
diff
changeset
|
1336 assert(0); |
225 | 1337 set_PGCN(vm, (vm->state).rsm_pgcN); |
1338 | |
1339 /* These should never be set in SystemSpace and/or MenuSpace */ | |
1340 /* (vm->state).TTN_REG = rsm_tt; ?? */ | |
1341 /* (vm->state).TT_PGCN_REG = (vm->state).rsm_pgcN; ?? */ | |
1342 for(i = 0; i < 5; i++) { | |
1343 (vm->state).registers.SPRM[4 + i] = (vm->state).rsm_regs[i]; | |
1344 } | |
1345 | |
1346 if(link_values.data1 != 0) | |
1347 (vm->state).HL_BTNN_REG = link_values.data1 << 10; | |
1348 | |
1349 if((vm->state).rsm_cellN == 0) { | |
1350 assert((vm->state).cellN); /* Checking if this ever happens */ | |
1351 (vm->state).pgN = 1; | |
1352 link_values = play_PG(vm); | |
1353 } else { | |
252
aee8af592d66
fix a long-standing problem: sometimes, hitting Escape in the movie and then
mroi
parents:
247
diff
changeset
|
1354 /* (vm->state).pgN = ?? this gets the right value in set_PGN() below */ |
225 | 1355 (vm->state).cellN = (vm->state).rsm_cellN; |
1356 link_values.command = PlayThis; | |
252
aee8af592d66
fix a long-standing problem: sometimes, hitting Escape in the movie and then
mroi
parents:
247
diff
changeset
|
1357 link_values.data1 = (vm->state).rsm_blockN & 0xffff; |
aee8af592d66
fix a long-standing problem: sometimes, hitting Escape in the movie and then
mroi
parents:
247
diff
changeset
|
1358 link_values.data2 = (vm->state).rsm_blockN >> 16; |
225 | 1359 if(!set_PGN(vm)) { |
1360 /* Were at the end of the PGC, should not happen for a RSM */ | |
1361 assert(0); | |
1362 link_values.command = LinkTailPGC; | |
1363 link_values.data1 = 0; /* No button */ | |
1364 } | |
1365 } | |
1366 } | |
1367 break; | |
1368 case LinkPGCN: | |
1369 /* Link to Program Chain Number:data1 */ | |
1370 if(!set_PGCN(vm, link_values.data1)) | |
1371 assert(0); | |
1372 link_values = play_PGC(vm); | |
1373 break; | |
1374 case LinkPTTN: | |
1375 /* Link to Part of current Title Number:data1 */ | |
1376 /* BUTTON number:data2 */ | |
1377 /* PGC Pre-Commands are not executed */ | |
1378 assert((vm->state).domain == VTS_DOMAIN); | |
1379 if(link_values.data2 != 0) | |
1380 (vm->state).HL_BTNN_REG = link_values.data2 << 10; | |
1381 if(!set_VTS_PTT(vm, (vm->state).vtsN, (vm->state).VTS_TTN_REG, link_values.data1)) | |
1382 assert(0); | |
1383 link_values = play_PG(vm); | |
1384 break; | |
1385 case LinkPGN: | |
1386 /* Link to Program Number:data1 */ | |
1387 /* BUTTON number:data2 */ | |
1388 if(link_values.data2 != 0) | |
1389 (vm->state).HL_BTNN_REG = link_values.data2 << 10; | |
1390 /* Update any other state, PTTN perhaps? */ | |
1391 (vm->state).pgN = link_values.data1; | |
1392 link_values = play_PG(vm); | |
1393 break; | |
1394 case LinkCN: | |
1395 /* Link to Cell Number:data1 */ | |
1396 /* BUTTON number:data2 */ | |
1397 if(link_values.data2 != 0) | |
1398 (vm->state).HL_BTNN_REG = link_values.data2 << 10; | |
1399 /* Update any other state, pgN, PTTN perhaps? */ | |
1400 (vm->state).cellN = link_values.data1; | |
1401 link_values = play_Cell(vm); | |
1402 break; | |
1403 | |
1404 case Exit: | |
1405 vm->stopped = 1; | |
1406 return 0; | |
1407 | |
1408 case JumpTT: | |
1409 /* Jump to VTS Title Domain */ | |
1410 /* Only allowed from the First Play domain(PGC) */ | |
1411 /* or the Video Manager domain (VMG) */ | |
1412 /* Stop SPRM9 Timer */ | |
1413 /* Set SPRM1 and SPRM2 */ | |
1414 assert((vm->state).domain == VMGM_DOMAIN || (vm->state).domain == FP_DOMAIN); /* ?? */ | |
256
6299ccea8a38
killing a lot of asserts and turning them into forced executions of Exit,
mroi
parents:
254
diff
changeset
|
1415 if(set_TT(vm, link_values.data1)) |
6299ccea8a38
killing a lot of asserts and turning them into forced executions of Exit,
mroi
parents:
254
diff
changeset
|
1416 link_values = play_PGC(vm); |
6299ccea8a38
killing a lot of asserts and turning them into forced executions of Exit,
mroi
parents:
254
diff
changeset
|
1417 else |
6299ccea8a38
killing a lot of asserts and turning them into forced executions of Exit,
mroi
parents:
254
diff
changeset
|
1418 link_values.command = Exit; |
225 | 1419 break; |
1420 case JumpVTS_TT: | |
1421 /* Jump to Title:data1 in same VTS Title Domain */ | |
1422 /* Only allowed from the VTS Menu Domain(VTSM) */ | |
1423 /* or the Video Title Set Domain(VTS) */ | |
1424 /* Stop SPRM9 Timer */ | |
1425 /* Set SPRM1 and SPRM2 */ | |
1426 assert((vm->state).domain == VTSM_DOMAIN || (vm->state).domain == VTS_DOMAIN); /* ?? */ | |
1427 if(!set_VTS_TT(vm, (vm->state).vtsN, link_values.data1)) | |
1428 assert(0); | |
1429 link_values = play_PGC(vm); | |
1430 break; | |
1431 case JumpVTS_PTT: | |
1432 /* Jump to Part:data2 of Title:data1 in same VTS Title Domain */ | |
1433 /* Only allowed from the VTS Menu Domain(VTSM) */ | |
1434 /* or the Video Title Set Domain(VTS) */ | |
1435 /* Stop SPRM9 Timer */ | |
1436 /* Set SPRM1 and SPRM2 */ | |
1437 assert((vm->state).domain == VTSM_DOMAIN || (vm->state).domain == VTS_DOMAIN); /* ?? */ | |
1438 if(!set_VTS_PTT(vm, (vm->state).vtsN, link_values.data1, link_values.data2)) | |
1439 assert(0); | |
1440 link_values = play_PGC_PG(vm, (vm->state).pgN); | |
1441 break; | |
1442 | |
1443 case JumpSS_FP: | |
1444 /* Jump to First Play Domain */ | |
1445 /* Only allowed from the VTS Menu Domain(VTSM) */ | |
1446 /* or the Video Manager domain (VMG) */ | |
1447 /* Stop SPRM9 Timer and any GPRM counters */ | |
1448 assert((vm->state).domain == VMGM_DOMAIN || (vm->state).domain == VTSM_DOMAIN); /* ?? */ | |
1449 if (!set_FP_PGC(vm)) | |
1450 assert(0); | |
1451 link_values = play_PGC(vm); | |
1452 break; | |
1453 case JumpSS_VMGM_MENU: | |
1454 /* Jump to Video Manger domain - Title Menu:data1 or any PGC in VMG */ | |
1455 /* Allowed from anywhere except the VTS Title domain */ | |
1456 /* Stop SPRM9 Timer and any GPRM counters */ | |
1457 assert((vm->state).domain != VTS_DOMAIN); /* ?? */ | |
1458 (vm->state).domain = VMGM_DOMAIN; | |
1459 if(!set_MENU(vm, link_values.data1)) | |
1460 assert(0); | |
1461 link_values = play_PGC(vm); | |
1462 break; | |
1463 case JumpSS_VTSM: | |
1464 /* Jump to a menu in Video Title domain, */ | |
1465 /* or to a Menu is the current VTS */ | |
1466 /* Stop SPRM9 Timer and any GPRM counters */ | |
1467 /* ifoOpenNewVTSI:data1 */ | |
1468 /* VTS_TTN_REG:data2 */ | |
1469 /* get_MENU:data3 */ | |
1470 if(link_values.data1 != 0) { | |
1471 if (link_values.data1 != (vm->state).vtsN) { | |
1472 /* the normal case */ | |
1473 assert((vm->state).domain == VMGM_DOMAIN || (vm->state).domain == FP_DOMAIN); /* ?? */ | |
1474 (vm->state).domain = VTSM_DOMAIN; | |
256
6299ccea8a38
killing a lot of asserts and turning them into forced executions of Exit,
mroi
parents:
254
diff
changeset
|
1475 if (!ifoOpenNewVTSI(vm, vm->dvd, link_values.data1)) /* Also sets (vm->state).vtsN */ |
6299ccea8a38
killing a lot of asserts and turning them into forced executions of Exit,
mroi
parents:
254
diff
changeset
|
1476 assert(0); |
225 | 1477 } else { |
1478 /* This happens on some discs like "Captain Scarlet & the Mysterons" or | |
1479 * the German RC2 of "Anatomie" in VTSM. */ | |
1480 assert((vm->state).domain == VTSM_DOMAIN || | |
1481 (vm->state).domain == VMGM_DOMAIN || (vm->state).domain == FP_DOMAIN); /* ?? */ | |
1482 (vm->state).domain = VTSM_DOMAIN; | |
1483 } | |
1484 } else { | |
1485 /* This happens on 'The Fifth Element' region 2. */ | |
1486 assert((vm->state).domain == VTSM_DOMAIN); | |
1487 } | |
1488 /* I don't know what title is supposed to be used for. */ | |
1489 /* Alien or Aliens has this != 1, I think. */ | |
1490 /* assert(link_values.data2 == 1); */ | |
1491 (vm->state).VTS_TTN_REG = link_values.data2; | |
1492 /* TTN_REG (SPRM4), VTS_TTN_REG (SPRM5), TT_PGCN_REG (SPRM6) are linked, */ | |
1493 /* so if one changes, the others must change to match it. */ | |
1494 (vm->state).TTN_REG = get_TT(vm, (vm->state).vtsN, (vm->state).VTS_TTN_REG); | |
1495 if(!set_MENU(vm, link_values.data3)) | |
1496 assert(0); | |
1497 link_values = play_PGC(vm); | |
1498 break; | |
1499 case JumpSS_VMGM_PGC: | |
1500 /* set_PGCN:data1 */ | |
1501 /* Stop SPRM9 Timer and any GPRM counters */ | |
1502 assert((vm->state).domain != VTS_DOMAIN); /* ?? */ | |
1503 (vm->state).domain = VMGM_DOMAIN; | |
1504 if(!set_PGCN(vm, link_values.data1)) | |
1505 assert(0); | |
1506 link_values = play_PGC(vm); | |
1507 break; | |
1508 | |
1509 case CallSS_FP: | |
1510 /* set_RSMinfo:data1 */ | |
1511 assert((vm->state).domain == VTS_DOMAIN); /* ?? */ | |
1512 /* Must be called before domain is changed */ | |
1513 set_RSMinfo(vm, link_values.data1, /* We dont have block info */ 0); | |
1514 set_FP_PGC(vm); | |
1515 link_values = play_PGC(vm); | |
1516 break; | |
1517 case CallSS_VMGM_MENU: | |
1518 /* set_MENU:data1 */ | |
1519 /* set_RSMinfo:data2 */ | |
1520 assert((vm->state).domain == VTS_DOMAIN); /* ?? */ | |
1521 /* Must be called before domain is changed */ | |
1522 set_RSMinfo(vm, link_values.data2, /* We dont have block info */ 0); | |
1523 (vm->state).domain = VMGM_DOMAIN; | |
1524 if(!set_MENU(vm, link_values.data1)) | |
1525 assert(0); | |
1526 link_values = play_PGC(vm); | |
1527 break; | |
1528 case CallSS_VTSM: | |
1529 /* set_MENU:data1 */ | |
1530 /* set_RSMinfo:data2 */ | |
1531 assert((vm->state).domain == VTS_DOMAIN); /* ?? */ | |
1532 /* Must be called before domain is changed */ | |
1533 set_RSMinfo(vm, link_values.data2, /* We dont have block info */ 0); | |
1534 (vm->state).domain = VTSM_DOMAIN; | |
1535 if(!set_MENU(vm, link_values.data1)) | |
1536 assert(0); | |
1537 link_values = play_PGC(vm); | |
1538 break; | |
1539 case CallSS_VMGM_PGC: | |
1540 /* set_PGC:data1 */ | |
1541 /* set_RSMinfo:data2 */ | |
1542 assert((vm->state).domain == VTS_DOMAIN); /* ?? */ | |
1543 /* Must be called before domain is changed */ | |
1544 set_RSMinfo(vm, link_values.data2, /* We dont have block info */ 0); | |
1545 (vm->state).domain = VMGM_DOMAIN; | |
1546 if(!set_PGCN(vm, link_values.data1)) | |
1547 assert(0); | |
1548 link_values = play_PGC(vm); | |
1549 break; | |
1550 case PlayThis: | |
1551 /* Should never happen. */ | |
1552 assert(0); | |
1553 break; | |
1554 } | |
1555 | |
1556 #ifdef TRACE | |
1557 fprintf(MSG_OUT, "libdvdnav: After printout starts:\n"); | |
1558 vm_print_current_domain_state(vm); | |
1559 fprintf(MSG_OUT, "libdvdnav: After printout ends.\n"); | |
1560 #endif | |
1561 | |
1562 } | |
252
aee8af592d66
fix a long-standing problem: sometimes, hitting Escape in the movie and then
mroi
parents:
247
diff
changeset
|
1563 (vm->state).blockN = link_values.data1 | (link_values.data2 << 16); |
225 | 1564 return 1; |
1565 } | |
1566 | |
1567 | |
1568 /* Set functions */ | |
1569 | |
1570 static int set_TT(vm_t *vm, int tt) { | |
1571 return set_PTT(vm, tt, 1); | |
1572 } | |
1573 | |
1574 static int set_PTT(vm_t *vm, int tt, int ptt) { | |
1575 assert(tt <= vm->vmgi->tt_srpt->nr_of_srpts); | |
1576 return set_VTS_PTT(vm, vm->vmgi->tt_srpt->title[tt - 1].title_set_nr, | |
1577 vm->vmgi->tt_srpt->title[tt - 1].vts_ttn, ptt); | |
1578 } | |
1579 | |
1580 static int set_VTS_TT(vm_t *vm, int vtsN, int vts_ttn) { | |
1581 return set_VTS_PTT(vm, vtsN, vts_ttn, 1); | |
1582 } | |
1583 | |
1584 static int set_VTS_PTT(vm_t *vm, int vtsN, int vts_ttn, int part) { | |
1585 int pgcN, pgN, res; | |
1586 | |
1587 (vm->state).domain = VTS_DOMAIN; | |
1588 | |
256
6299ccea8a38
killing a lot of asserts and turning them into forced executions of Exit,
mroi
parents:
254
diff
changeset
|
1589 if (vtsN != (vm->state).vtsN) |
6299ccea8a38
killing a lot of asserts and turning them into forced executions of Exit,
mroi
parents:
254
diff
changeset
|
1590 if (!ifoOpenNewVTSI(vm, vm->dvd, vtsN)) /* Also sets (vm->state).vtsN */ |
6299ccea8a38
killing a lot of asserts and turning them into forced executions of Exit,
mroi
parents:
254
diff
changeset
|
1591 return 0; |
225 | 1592 |
1593 if ((vts_ttn < 1) || (vts_ttn > vm->vtsi->vts_ptt_srpt->nr_of_srpts) || | |
1594 (part < 1) || (part > vm->vtsi->vts_ptt_srpt->title[vts_ttn - 1].nr_of_ptts) ) { | |
1595 return 0; | |
1596 } | |
1597 | |
1598 pgcN = vm->vtsi->vts_ptt_srpt->title[vts_ttn - 1].ptt[part - 1].pgcn; | |
1599 pgN = vm->vtsi->vts_ptt_srpt->title[vts_ttn - 1].ptt[part - 1].pgn; | |
1600 | |
1601 (vm->state).TT_PGCN_REG = pgcN; | |
1602 (vm->state).PTTN_REG = part; | |
1603 (vm->state).TTN_REG = get_TT(vm, vtsN, vts_ttn); | |
1604 assert( (vm->state.TTN_REG) != 0 ); | |
1605 (vm->state).VTS_TTN_REG = vts_ttn; | |
1606 (vm->state).vtsN = vtsN; /* Not sure about this one. We can get to it easily from TTN_REG */ | |
1607 /* Any other registers? */ | |
1608 | |
1609 res = set_PGCN(vm, pgcN); /* This clobber's state.pgN (sets it to 1), but we don't want clobbering here. */ | |
1610 (vm->state).pgN = pgN; | |
1611 return res; | |
1612 } | |
1613 | |
1614 static int set_FP_PGC(vm_t *vm) { | |
1615 (vm->state).domain = FP_DOMAIN; | |
254
f78669338b49
Fix segfault if the DVD does not contain a FP_PGC.
jcdutton
parents:
252
diff
changeset
|
1616 if (!vm->vmgi->first_play_pgc) { |
f78669338b49
Fix segfault if the DVD does not contain a FP_PGC.
jcdutton
parents:
252
diff
changeset
|
1617 return set_PGCN(vm, 1); |
f78669338b49
Fix segfault if the DVD does not contain a FP_PGC.
jcdutton
parents:
252
diff
changeset
|
1618 } |
225 | 1619 (vm->state).pgc = vm->vmgi->first_play_pgc; |
1620 (vm->state).pgcN = vm->vmgi->vmgi_mat->first_play_pgc; | |
1621 return 1; | |
1622 } | |
1623 | |
1624 | |
1625 static int set_MENU(vm_t *vm, int menu) { | |
1626 assert((vm->state).domain == VMGM_DOMAIN || (vm->state).domain == VTSM_DOMAIN); | |
1627 return set_PGCN(vm, get_ID(vm, menu)); | |
1628 } | |
1629 | |
1630 static int set_PGCN(vm_t *vm, int pgcN) { | |
1631 pgcit_t *pgcit; | |
1632 | |
1633 pgcit = get_PGCIT(vm); | |
1634 assert(pgcit != NULL); /* ?? Make this return -1 instead */ | |
1635 | |
1636 if(pgcN < 1 || pgcN > pgcit->nr_of_pgci_srp) { | |
1637 #ifdef TRACE | |
1638 fprintf(MSG_OUT, "libdvdnav: ** No such pgcN = %d\n", pgcN); | |
1639 #endif | |
1640 return 0; | |
1641 } | |
1642 | |
1643 (vm->state).pgc = pgcit->pgci_srp[pgcN - 1].pgc; | |
1644 (vm->state).pgcN = pgcN; | |
1645 (vm->state).pgN = 1; | |
1646 | |
1647 if((vm->state).domain == VTS_DOMAIN) | |
1648 (vm->state).TT_PGCN_REG = pgcN; | |
1649 | |
1650 return 1; | |
1651 } | |
1652 | |
1653 /* Figure out the correct pgN from the cell and update (vm->state). */ | |
1654 static int set_PGN(vm_t *vm) { | |
1655 int new_pgN = 0; | |
1656 | |
1657 while(new_pgN < (vm->state).pgc->nr_of_programs | |
1658 && (vm->state).cellN >= (vm->state).pgc->program_map[new_pgN]) | |
1659 new_pgN++; | |
1660 | |
1661 if(new_pgN == (vm->state).pgc->nr_of_programs) /* We are at the last program */ | |
1662 if((vm->state).cellN > (vm->state).pgc->nr_of_cells) | |
1663 return 0; /* We are past the last cell */ | |
1664 | |
1665 (vm->state).pgN = new_pgN; | |
1666 | |
1667 if((vm->state).domain == VTS_DOMAIN) { | |
1668 playback_type_t *pb_ty; | |
1669 if((vm->state).TTN_REG > vm->vmgi->tt_srpt->nr_of_srpts) | |
1670 return 0; /* ?? */ | |
1671 pb_ty = &vm->vmgi->tt_srpt->title[(vm->state).TTN_REG - 1].pb_ty; | |
1672 if(pb_ty->multi_or_random_pgc_title == /* One_Sequential_PGC_Title */ 0) { | |
1673 int dummy, part; | |
1674 vm_get_current_title_part(vm, &dummy, &part); | |
1675 (vm->state).PTTN_REG = part; | |
1676 } else { | |
1677 /* FIXME: Handle RANDOM or SHUFFLE titles. */ | |
1678 fprintf(MSG_OUT, "libdvdnav: RANDOM or SHUFFLE titles are NOT handled yet.\n"); | |
1679 } | |
1680 } | |
1681 return 1; | |
1682 } | |
1683 | |
1684 /* Must be called before domain is changed (set_PGCN()) */ | |
1685 static void set_RSMinfo(vm_t *vm, int cellN, int blockN) { | |
1686 int i; | |
1687 | |
1688 if(cellN) { | |
1689 (vm->state).rsm_cellN = cellN; | |
1690 (vm->state).rsm_blockN = blockN; | |
1691 } else { | |
1692 (vm->state).rsm_cellN = (vm->state).cellN; | |
1693 (vm->state).rsm_blockN = blockN; | |
1694 } | |
1695 (vm->state).rsm_vtsN = (vm->state).vtsN; | |
1696 (vm->state).rsm_pgcN = get_PGCN(vm); | |
1697 | |
1698 /* assert((vm->state).rsm_pgcN == (vm->state).TT_PGCN_REG); for VTS_DOMAIN */ | |
1699 | |
1700 for(i = 0; i < 5; i++) { | |
1701 (vm->state).rsm_regs[i] = (vm->state).registers.SPRM[4 + i]; | |
1702 } | |
1703 } | |
1704 | |
1705 | |
1706 /* Get functions */ | |
1707 | |
1708 /* Searches the TT tables, to find the current TT. | |
1709 * returns the current TT. | |
1710 * returns 0 if not found. | |
1711 */ | |
1712 static int get_TT(vm_t *vm, int vtsN, int vts_ttn) { | |
1713 int i; | |
1714 int tt=0; | |
1715 | |
1716 for(i = 1; i <= vm->vmgi->tt_srpt->nr_of_srpts; i++) { | |
1717 if( vm->vmgi->tt_srpt->title[i - 1].title_set_nr == vtsN && | |
1718 vm->vmgi->tt_srpt->title[i - 1].vts_ttn == vts_ttn) { | |
1719 tt=i; | |
1720 break; | |
1721 } | |
1722 } | |
1723 return tt; | |
1724 } | |
1725 | |
1726 /* Search for entry_id match of the PGC Category in the current VTS PGCIT table. | |
1727 * Return pgcN based on entry_id match. | |
1728 */ | |
1729 static int get_ID(vm_t *vm, int id) { | |
1730 int pgcN, i; | |
1731 pgcit_t *pgcit; | |
1732 | |
1733 /* Relies on state to get the correct pgcit. */ | |
1734 pgcit = get_PGCIT(vm); | |
1735 assert(pgcit != NULL); | |
1736 #ifdef TRACE | |
1737 fprintf(MSG_OUT, "libdvdnav: ** Searching for menu (0x%x) entry PGC\n", id); | |
1738 #endif | |
1739 | |
1740 /* Force high bit set. */ | |
1741 id |=0x80; | |
1742 | |
1743 /* Get menu/title */ | |
1744 for(i = 0; i < pgcit->nr_of_pgci_srp; i++) { | |
1745 if( (pgcit->pgci_srp[i].entry_id) == id) { | |
1746 pgcN = i + 1; | |
1747 #ifdef TRACE | |
1748 fprintf(MSG_OUT, "libdvdnav: Found menu.\n"); | |
1749 #endif | |
1750 return pgcN; | |
1751 } | |
1752 } | |
1753 #ifdef TRACE | |
1754 fprintf(MSG_OUT, "libdvdnav: ** No such id/menu (0x%02x) entry PGC\n", id & 0x7f); | |
1755 for(i = 0; i < pgcit->nr_of_pgci_srp; i++) { | |
1756 if ( (pgcit->pgci_srp[i].entry_id & 0x80) == 0x80) { | |
1757 fprintf(MSG_OUT, "libdvdnav: Available menus: 0x%x\n", | |
1758 pgcit->pgci_srp[i].entry_id & 0x7f); | |
1759 } | |
1760 } | |
1761 #endif | |
1762 return 0; /* error */ | |
1763 } | |
1764 | |
1765 /* FIXME: we have a pgcN member in the vm's state now, so this should be obsolete */ | |
1766 static int get_PGCN(vm_t *vm) { | |
1767 pgcit_t *pgcit; | |
1768 int pgcN = 1; | |
1769 | |
1770 pgcit = get_PGCIT(vm); | |
1771 | |
1772 if (pgcit) { | |
1773 while(pgcN <= pgcit->nr_of_pgci_srp) { | |
1774 if(pgcit->pgci_srp[pgcN - 1].pgc == (vm->state).pgc) { | |
1775 assert((vm->state).pgcN == pgcN); | |
1776 return pgcN; | |
1777 } | |
1778 pgcN++; | |
1779 } | |
1780 } | |
1781 fprintf(MSG_OUT, "libdvdnav: get_PGCN failed. Was trying to find pgcN in domain %d\n", | |
1782 (vm->state).domain); | |
1783 return 0; /* error */ | |
1784 } | |
1785 | |
1786 static pgcit_t* get_MENU_PGCIT(vm_t *vm, ifo_handle_t *h, uint16_t lang) { | |
1787 int i; | |
1788 | |
1789 if(h == NULL || h->pgci_ut == NULL) { | |
1790 fprintf(MSG_OUT, "libdvdnav: *** pgci_ut handle is NULL ***\n"); | |
1791 return NULL; /* error? */ | |
1792 } | |
1793 | |
1794 i = 0; | |
1795 while(i < h->pgci_ut->nr_of_lus | |
1796 && h->pgci_ut->lu[i].lang_code != lang) | |
1797 i++; | |
1798 if(i == h->pgci_ut->nr_of_lus) { | |
1799 fprintf(MSG_OUT, "libdvdnav: Language '%c%c' not found, using '%c%c' instead\n", | |
1800 (char)(lang >> 8), (char)(lang & 0xff), | |
1801 (char)(h->pgci_ut->lu[0].lang_code >> 8), | |
1802 (char)(h->pgci_ut->lu[0].lang_code & 0xff)); | |
1803 fprintf(MSG_OUT, "libdvdnav: Menu Languages available: "); | |
1804 for(i = 0; i < h->pgci_ut->nr_of_lus; i++) { | |
1805 fprintf(MSG_OUT, "%c%c ", | |
1806 (char)(h->pgci_ut->lu[i].lang_code >> 8), | |
1807 (char)(h->pgci_ut->lu[i].lang_code & 0xff)); | |
1808 } | |
1809 fprintf(MSG_OUT, "\n"); | |
1810 i = 0; /* error? */ | |
1811 } | |
1812 | |
1813 return h->pgci_ut->lu[i].pgcit; | |
1814 } | |
1815 | |
1816 /* Uses state to decide what to return */ | |
1817 static pgcit_t* get_PGCIT(vm_t *vm) { | |
1818 pgcit_t *pgcit; | |
1819 | |
1820 switch ((vm->state).domain) { | |
1821 case VTS_DOMAIN: | |
1822 pgcit = vm->vtsi->vts_pgcit; | |
1823 break; | |
1824 case VTSM_DOMAIN: | |
1825 pgcit = get_MENU_PGCIT(vm, vm->vtsi, (vm->state).registers.SPRM[0]); | |
1826 break; | |
1827 case VMGM_DOMAIN: | |
1828 case FP_DOMAIN: | |
1829 pgcit = get_MENU_PGCIT(vm, vm->vmgi, (vm->state).registers.SPRM[0]); | |
1830 break; | |
1831 default: | |
243
e75c52894630
* assert(0) does not always and the program (see NDEBUG)
mroi
parents:
229
diff
changeset
|
1832 abort(); |
225 | 1833 } |
1834 | |
1835 return pgcit; | |
1836 } | |
1837 | |
1838 | |
1839 /* Debug functions */ | |
1840 | |
1841 #ifdef TRACE | |
1842 void vm_position_print(vm_t *vm, vm_position_t *position) { | |
1843 fprintf(MSG_OUT, "libdvdnav: But=%x Spu=%x Aud=%x Ang=%x Hop=%x vts=%x dom=%x cell=%x cell_restart=%x cell_start=%x still=%x block=%x\n", | |
1844 position->button, | |
1845 position->spu_channel, | |
1846 position->audio_channel, | |
1847 position->angle_channel, | |
1848 position->hop_channel, | |
1849 position->vts, | |
1850 position->domain, | |
1851 position->cell, | |
1852 position->cell_restart, | |
1853 position->cell_start, | |
1854 position->still, | |
1855 position->block); | |
1856 } | |
1857 #endif | |
1858 |