Debian Codegraph @

src/vm/vmget.c

raw
1 /*
2 * Copyright (C) 2000, 2001 Håkan Hjort
3 * Copyright (C) 2001 Rich Wareham <[email protected]>
4 * 2002-2004 the dvdnav project
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 along
20 * with libdvdnav; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 */
23
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #include <assert.h>
29 #include <inttypes.h>
30 #include <stdio.h>
31 #include <string.h>
32 #include <stdlib.h>
33
34 #include <dvdread/nav_types.h>
35 #include <dvdread/ifo_read.h>
36 #include "dvdnav/dvdnav.h"
37
38 #include "decoder.h"
39 #include "vm.h"
40 #include "getset.h"
41 #include "dvdnav_internal.h"
42 #include "logger.h"
43
44 /* getting information */
45
46 int vm_get_current_menu(vm_t *vm, int *menuid) {
47 const pgcit_t* pgcit;
48 int pgcn;
49 pgcn = (vm->state).pgcN;
50 pgcit = get_PGCIT(vm);
51 if(pgcit==NULL) return 0;
52 *menuid = pgcit->pgci_srp[pgcn - 1].entry_id & 0xf ;
53 return 1;
54 }
55
56 int vm_get_current_title_part(vm_t *vm, int *title_result, int *part_result) {
57 vts_ptt_srpt_t *vts_ptt_srpt;
58 int title, part = 0, vts_ttn;
59 int found;
60 int16_t pgcN, pgN;
61
62 vts_ptt_srpt = vm->vtsi->vts_ptt_srpt;
63 pgcN = get_PGCN(vm);
64 pgN = vm->state.pgN;
65
66 found = 0;
67 for (vts_ttn = 0; (vts_ttn < vts_ptt_srpt->nr_of_srpts) && !found; vts_ttn++) {
68 for (part = 0; (part < vts_ptt_srpt->title[vts_ttn].nr_of_ptts) && !found; part++) {
69 if (vts_ptt_srpt->title[vts_ttn].ptt[part].pgcn == pgcN) {
70 if (vts_ptt_srpt->title[vts_ttn].ptt[part].pgn == pgN) {
71 found = 1;
72 break;
73 }
74 if (part > 0 && vts_ptt_srpt->title[vts_ttn].ptt[part].pgn > pgN &&
75 vts_ptt_srpt->title[vts_ttn].ptt[part - 1].pgn < pgN) {
76 part--;
77 found = 1;
78 break;
79 }
80 }
81 }
82 if (found) break;
83 }
84 vts_ttn++;
85 part++;
86
87 if (!found) {
88 Log1(vm, "chapter NOT FOUND!");
89 return 0;
90 }
91
92 title = get_TT(vm, vm->state.vtsN, vts_ttn);
93
94 #ifdef TRACE
95 if (title) {
96 Log3(vm, "************ this chapter FOUND!");
97 Log3(vm, "VTS_PTT_SRPT - Title %3i part %3i: PGC: %3i PG: %3i",
98 title, part,
99 vts_ptt_srpt->title[vts_ttn-1].ptt[part-1].pgcn ,
100 vts_ptt_srpt->title[vts_ttn-1].ptt[part-1].pgn );
101 }
102 #endif
103 *title_result = title;
104 *part_result = part;
105 return 1;
106 }
107
108 /* Return the substream id for 'logical' audio stream audioN.
109 * 0 <= audioN < 8
110 */
111 int vm_get_audio_stream(vm_t *vm, int audioN) {
112 int streamN = -1;
113
114 if((vm->state).domain != DVD_DOMAIN_VTSTitle)
115 audioN = 0;
116
117 if(audioN < 8) {
118 /* Is there any control info for this logical stream */
119 if((vm->state).pgc->audio_control[audioN] & (1<<15)) {
120 streamN = ((vm->state).pgc->audio_control[audioN] >> 8) & 0x07;
121 }
122 }
123
124 if((vm->state).domain != DVD_DOMAIN_VTSTitle && streamN == -1)
125 streamN = 0;
126
127 /* FIXME: Should also check in vtsi/vmgi status what kind of stream
128 * it is (ac3/lpcm/dts/sdds...) to find the right (sub)stream id */
129 return streamN;
130 }
131
132 /* Return the substream id for 'logical' subpicture stream subpN and given mode.
133 * 0 <= subpN < 32
134 * mode == 0 - widescreen
135 * mode == 1 - letterbox
136 * mode == 2 - pan&scan
137 */
138 int vm_get_subp_stream(vm_t *vm, int subpN, int mode) {
139 int streamN = -1;
140 int source_aspect = vm_get_video_aspect(vm);
141
142 if((vm->state).domain != DVD_DOMAIN_VTSTitle)
143 subpN = 0;
144
145 if(subpN < 32) { /* a valid logical stream */
146 /* Is this logical stream present */
147 if((vm->state).pgc->subp_control[subpN] & (1u<<31)) {
148 if(source_aspect == 0) /* 4:3 */
149 streamN = ((vm->state).pgc->subp_control[subpN] >> 24) & 0x1f;
150 if(source_aspect == 3) /* 16:9 */
151 switch (mode) {
152 case 0:
153 streamN = ((vm->state).pgc->subp_control[subpN] >> 16) & 0x1f;
154 break;
155 case 1:
156 streamN = ((vm->state).pgc->subp_control[subpN] >> 8) & 0x1f;
157 break;
158 case 2:
159 streamN = (vm->state).pgc->subp_control[subpN] & 0x1f;
160 }
161 }
162 }
163
164 if((vm->state).domain != DVD_DOMAIN_VTSTitle && streamN == -1)
165 streamN = 0;
166
167 /* FIXME: Should also check in vtsi/vmgi status what kind of stream it is. */
168 return streamN;
169 }
170
171 int vm_get_audio_active_stream(vm_t *vm) {
172 int audioN;
173 int streamN;
174 audioN = (vm->state).AST_REG ;
175 streamN = vm_get_audio_stream(vm, audioN);
176
177 /* If no such stream, then select the first one that exists. */
178 if(streamN == -1) {
179 for(audioN = 0; audioN < 8; audioN++) {
180 if((vm->state).pgc->audio_control[audioN] & (1<<15)) {
181 if ((streamN = vm_get_audio_stream(vm, audioN)) >= 0)
182 break;
183 }
184 }
185 }
186
187 return streamN;
188 }
189
190 int vm_get_subp_active_stream(vm_t *vm, int mode) {
191 int subpN;
192 int streamN;
193 subpN = (vm->state).SPST_REG & ~0x40;
194 streamN = vm_get_subp_stream(vm, subpN, mode);
195
196 /* If no such stream, then select the first one that exists. */
197 if(streamN == -1) {
198 for(subpN = 0; subpN < 32; subpN++) {
199 if((vm->state).pgc->subp_control[subpN] & (1<<31)) {
200 if ((streamN = vm_get_subp_stream(vm, subpN, mode)) >= 0)
201 break;
202 }
203 }
204 }
205
206 if((vm->state).domain == DVD_DOMAIN_VTSTitle && !((vm->state).SPST_REG & 0x40))
207 /* Bit 7 set means hide, and only let Forced display show */
208 return (streamN | 0x80);
209 else
210 return streamN;
211 }
212
213 void vm_get_angle_info(vm_t *vm, int *current, int *num_avail) {
214 *num_avail = 1;
215 *current = 1;
216
217 if((vm->state).domain == DVD_DOMAIN_VTSTitle) {
218 const title_info_t *title;
219 /* TTN_REG does not always point to the correct title.. */
220 if((vm->state).TTN_REG > vm->vmgi->tt_srpt->nr_of_srpts)
221 return;
222 title = &vm->vmgi->tt_srpt->title[(vm->state).TTN_REG - 1];
223 if(title->title_set_nr != (vm->state).vtsN ||
224 title->vts_ttn != (vm->state).VTS_TTN_REG)
225 return;
226 *num_avail = title->nr_of_angles;
227 *current = (vm->state).AGL_REG;
228 }
229 }
230
231 #if 0
232 /* currently unused */
233 void vm_get_audio_info(vm_t *vm, int *current, int *num_avail) {
234 switch ((vm->state).domain) {
235 case DVD_DOMAIN_VTSTitle:
236 *num_avail = vm->vtsi->vtsi_mat->nr_of_vts_audio_streams;
237 *current = (vm->state).AST_REG;
238 break;
239 case DVD_DOMAIN_VTSMenu:
240 *num_avail = vm->vtsi->vtsi_mat->nr_of_vtsm_audio_streams; /* 1 */
241 *current = 1;
242 break;
243 case DVD_DOMAIN_VMGM:
244 case DVD_DOMAIN_FirstPlay:
245 *num_avail = vm->vmgi->vmgi_mat->nr_of_vmgm_audio_streams; /* 1 */
246 *current = 1;
247 break;
248 }
249 }
250
251 /* currently unused */
252 void vm_get_subp_info(vm_t *vm, int *current, int *num_avail) {
253 switch ((vm->state).domain) {
254 case DVD_DOMAIN_VTSTitle:
255 *num_avail = vm->vtsi->vtsi_mat->nr_of_vts_subp_streams;
256 *current = (vm->state).SPST_REG;
257 break;
258 case DVD_DOMAIN_VTSMenu:
259 *num_avail = vm->vtsi->vtsi_mat->nr_of_vtsm_subp_streams; /* 1 */
260 *current = 0x41;
261 break;
262 case DVD_DOMAIN_VMGM:
263 case DVD_DOMAIN_FirstPlay:
264 *num_avail = vm->vmgi->vmgi_mat->nr_of_vmgm_subp_streams; /* 1 */
265 *current = 0x41;
266 break;
267 }
268 }
269 #endif
270
271 void vm_get_video_res(vm_t *vm, int *width, int *height) {
272 video_attr_t attr = vm_get_video_attr(vm);
273
274 if(attr.video_format != 0)
275 *height = 576;
276 else
277 *height = 480;
278 switch(attr.picture_size) {
279 case 0:
280 *width = 720;
281 break;
282 case 1:
283 *width = 704;
284 break;
285 case 2:
286 *width = 352;
287 break;
288 case 3:
289 *width = 352;
290 *height /= 2;
291 break;
292 }
293 }
294
295 int vm_get_video_aspect(vm_t *vm) {
296 int aspect = vm_get_video_attr(vm).display_aspect_ratio;
297
298 if(aspect != 0 && aspect != 3) {
299 Log1(vm, "display aspect ratio is unexpected: %d!", aspect);
300 return -1;
301 }
302
303 (vm->state).registers.SPRM[14] &= ~(0x3 << 10);
304 (vm->state).registers.SPRM[14] |= aspect << 10;
305
306 return aspect;
307 }
308
309 int vm_get_video_scale_permission(vm_t *vm) {
310 return vm_get_video_attr(vm).permitted_df;
311 }
312
313 video_attr_t vm_get_video_attr(vm_t *vm) {
314 switch ((vm->state).domain) {
315 case DVD_DOMAIN_VTSTitle:
316 return vm->vtsi->vtsi_mat->vts_video_attr;
317 case DVD_DOMAIN_VTSMenu:
318 return vm->vtsi->vtsi_mat->vtsm_video_attr;
319 case DVD_DOMAIN_VMGM:
320 case DVD_DOMAIN_FirstPlay:
321 return vm->vmgi->vmgi_mat->vmgm_video_attr;
322 default:
323 assert(0);
324 }
325 }
326
327 audio_attr_t vm_get_audio_attr(vm_t *vm, int streamN) {
328 switch ((vm->state).domain) {
329 case DVD_DOMAIN_VTSTitle:
330 return vm->vtsi->vtsi_mat->vts_audio_attr[streamN];
331 case DVD_DOMAIN_VTSMenu:
332 return vm->vtsi->vtsi_mat->vtsm_audio_attr;
333 case DVD_DOMAIN_VMGM:
334 case DVD_DOMAIN_FirstPlay:
335 return vm->vmgi->vmgi_mat->vmgm_audio_attr;
336 default:
337 assert(0);
338 }
339 }
340
341 subp_attr_t vm_get_subp_attr(vm_t *vm, int streamN) {
342 switch ((vm->state).domain) {
343 case DVD_DOMAIN_VTSTitle:
344 return vm->vtsi->vtsi_mat->vts_subp_attr[streamN];
345 case DVD_DOMAIN_VTSMenu:
346 return vm->vtsi->vtsi_mat->vtsm_subp_attr;
347 case DVD_DOMAIN_VMGM:
348 case DVD_DOMAIN_FirstPlay:
349 return vm->vmgi->vmgi_mat->vmgm_subp_attr;
350 default:
351 assert(0);
352 }
353 }