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