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