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