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