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