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