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