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