0
|
1 /*
|
|
2 * Copyright (C) 2000 Rich Wareham <richwareham@users.sourceforge.net>
|
|
3 *
|
|
4 * This file is part of libdvdnav, a DVD navigation library.
|
|
5 *
|
|
6 * libdvdnav is free software; you can redistribute it and/or modify
|
|
7 * it under the terms of the GNU General Public License as published by
|
|
8 * the Free Software Foundation; either version 2 of the License, or
|
|
9 * (at your option) any later version.
|
|
10 *
|
|
11 * libdvdnav is distributed in the hope that it will be useful,
|
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 * GNU General Public License for more details.
|
|
15 *
|
|
16 * You should have received a copy of the GNU General Public License
|
|
17 * along with this program; if not, write to the Free Software
|
|
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
19 *
|
|
20 * $Id$
|
|
21 *
|
|
22 */
|
|
23
|
|
24 #ifdef HAVE_CONFIG_H
|
|
25 #include "config.h"
|
|
26 #endif
|
|
27
|
|
28 #include <dvdnav.h>
|
|
29 #include "dvdnav_internal.h"
|
|
30
|
|
31 #include "vm.h"
|
|
32 #include <dvdread/nav_types.h>
|
|
33
|
|
34 /* Searching API calls */
|
|
35
|
|
36 dvdnav_status_t dvdnav_time_search(dvdnav_t *self,
|
|
37 unsigned long int time) {
|
|
38 /* Time search the current PGC based on the xxx table */
|
|
39 return S_OK;
|
|
40 }
|
|
41
|
|
42 dvdnav_status_t dvdnav_sector_search(dvdnav_t *self,
|
|
43 unsigned long int offset, int origin) {
|
|
44 /* FIXME: Implement */
|
|
45
|
|
46 uint32_t target = 0;
|
|
47 uint32_t length = 0;
|
|
48 uint32_t first_cell_nr, last_cell_nr, cell_nr, fnd_cell_nr;
|
|
49 int found;
|
|
50 cell_playback_t *cell, *fnd_cell;
|
|
51 dvd_state_t *state;
|
|
52 dvdnav_status_t result;
|
|
53
|
|
54 if((!self) || (!self->vm) )
|
|
55 return -1;
|
|
56
|
|
57 state = &(self->vm->state);
|
|
58 if((!state) || (!state->pgc) )
|
|
59 return -1;
|
|
60
|
|
61 if(offset == 0)
|
|
62 return -1;
|
|
63
|
|
64 if(self->still_frame != -1)
|
|
65 /* Cannot do seeking in a still frame. */
|
|
66 return -1;
|
|
67
|
|
68 pthread_mutex_lock(&self->vm_lock);
|
|
69 result = dvdnav_get_position(self, &target, &length);
|
|
70 fprintf(stderr,"FIXME: seeking to offset=%lu pos=%u length=%u\n", offset, target, length);
|
|
71 fprintf(stderr,"FIXME: Before cellN=%u blockN=%u\n" ,
|
|
72 state->cellN,
|
|
73 state->blockN);
|
|
74 if(!result) {
|
|
75 pthread_mutex_unlock(&self->vm_lock);
|
|
76 return -1;
|
|
77 }
|
|
78
|
|
79 switch(origin) {
|
|
80 case SEEK_SET:
|
|
81 if(offset > length) {
|
|
82 pthread_mutex_unlock(&self->vm_lock);
|
|
83 return -1;
|
|
84 }
|
|
85 target = offset;
|
|
86 break;
|
|
87 case SEEK_CUR:
|
|
88 if(target + offset > length) {
|
|
89 pthread_mutex_unlock(&self->vm_lock);
|
|
90 return -1;
|
|
91 }
|
|
92 target += offset;
|
|
93 break;
|
|
94 case SEEK_END:
|
|
95 if(length - offset < 0) {
|
|
96 pthread_mutex_unlock(&self->vm_lock);
|
|
97 return -1;
|
|
98 }
|
|
99 target = length - offset;
|
|
100 default:
|
|
101 /* Error occured */
|
|
102 pthread_mutex_unlock(&self->vm_lock);
|
|
103 return -1;
|
|
104 }
|
|
105
|
|
106 /* First find closest cell number in program */
|
|
107 first_cell_nr = state->pgc->program_map[state->pgN-1];
|
|
108 if(state->pgN < state->pgc->nr_of_programs) {
|
|
109 last_cell_nr = state->pgc->program_map[state->pgN] - 1;
|
|
110 } else {
|
|
111 last_cell_nr = state->pgc->nr_of_cells;
|
|
112 }
|
|
113
|
|
114 found = 0; target += state->pgc->cell_playback[first_cell_nr-1].first_sector;
|
|
115 fnd_cell_nr = last_cell_nr + 1;
|
|
116 for(cell_nr = first_cell_nr; (cell_nr <= last_cell_nr) && !found; cell_nr ++) {
|
|
117 cell = &(state->pgc->cell_playback[cell_nr-1]);
|
|
118 if((cell->first_sector <= target) && (cell->last_sector >= target)) {
|
|
119 state->cellN = cell_nr;
|
|
120 state->blockN = 0;
|
|
121 found = 1;
|
|
122 fnd_cell_nr = cell_nr;
|
|
123 fnd_cell = cell;
|
|
124 }
|
|
125 }
|
|
126
|
|
127 if(fnd_cell_nr <= last_cell_nr) {
|
|
128 printf("Seeking to cell %i from choice of %i to %i\n",
|
|
129 fnd_cell_nr, first_cell_nr, last_cell_nr);
|
|
130 self->seekto_block = target;
|
|
131 self->seeking = 1;
|
|
132 /*
|
|
133 * Clut does not actually change,
|
|
134 * but as the decoders have been closed then opened,
|
|
135 * A new clut has to be sent.
|
|
136 */
|
|
137 self->spu_clut_changed = 1;
|
|
138 //ogle_do_post_jump(ogle);
|
|
139 fprintf(stderr,"FIXME: After cellN=%u blockN=%u\n" ,
|
|
140 state->cellN,
|
|
141 state->blockN);
|
|
142
|
|
143 pthread_mutex_unlock(&self->vm_lock);
|
|
144 return target;
|
|
145 } else {
|
|
146 fprintf(stderr, "Error when seeking, asked to seek outside program\n");
|
|
147 }
|
|
148
|
|
149
|
|
150
|
|
151 printf("FIXME: Implement seeking to location %u\n", target);
|
|
152
|
|
153 // self->seekto_block=target;
|
|
154 // self->seeking = 1;
|
|
155
|
|
156 pthread_mutex_unlock(&self->vm_lock);
|
|
157 return -1;
|
|
158 }
|
|
159
|
|
160 dvdnav_status_t dvdnav_part_search(dvdnav_t *self, int part) {
|
|
161 return S_OK;
|
|
162 }
|
|
163
|
|
164 dvdnav_status_t dvdnav_prev_pg_search(dvdnav_t *self) {
|
|
165 dvd_state_t *state;
|
|
166 state = &(self->vm->state);
|
|
167 /* Make sure this is not the first chapter */
|
|
168
|
|
169 if(state->pgN <= 1 ) {
|
|
170 printf("dvdnav: at first chapter. prev chapter failed.\n");
|
|
171 return S_ERR;
|
|
172 }
|
|
173 printf("dvdnav: previous chapter\n");
|
|
174 vm_jump_prog(self->vm, state->pgN - 1);
|
|
175 dvdnav_do_post_jump(self);
|
|
176 printf("dvdnav: previous chapter done\n");
|
|
177
|
|
178 return S_OK;
|
|
179 }
|
|
180
|
|
181 dvdnav_status_t dvdnav_top_pg_search(dvdnav_t *self) {
|
|
182
|
|
183 printf("dvdnav: top chapter. NOP.\n");
|
|
184
|
|
185 return S_OK;
|
|
186 }
|
|
187
|
|
188 dvdnav_status_t dvdnav_next_pg_search(dvdnav_t *self) {
|
|
189 dvd_state_t *state;
|
|
190 state = &(self->vm->state);
|
|
191 /* Make sure this is not the last chapter */
|
|
192 if(state->pgN >= state->pgc->nr_of_programs) {
|
|
193 printf("dvdnav: at last chapter. next chapter failed.\n");
|
|
194 return S_ERR;
|
|
195 }
|
|
196 printf("dvdnav: next chapter\n");
|
|
197 vm_jump_prog(self->vm, state->pgN + 1);
|
|
198 dvdnav_do_post_jump(self);
|
|
199 printf("dvdnav: next chapter done\n");
|
|
200
|
|
201 return S_OK;
|
|
202 }
|
|
203
|
|
204 dvdnav_status_t dvdnav_menu_call(dvdnav_t *self, DVDMenuID_t menu) {
|
|
205 dvd_state_t *state;
|
|
206
|
|
207 pthread_mutex_lock(&self->vm_lock);
|
|
208 state = &(self->vm->state);
|
|
209 vm_menu_call(self->vm, menu, 0);
|
|
210 dvdnav_do_post_jump(self);
|
|
211 pthread_mutex_unlock(&self->vm_lock);
|
|
212 return S_OK;
|
|
213 }
|
|
214
|
|
215 dvdnav_status_t dvdnav_current_title_info(dvdnav_t *self, int *tt, int *pr) {
|
|
216 int vts_ttn = 0;
|
|
217 int vts, i;
|
|
218 domain_t domain;
|
|
219 tt_srpt_t* srpt;
|
|
220
|
|
221 if(!self)
|
|
222 return S_ERR;
|
|
223
|
|
224 if(!tt || !pr) {
|
|
225 printerr("Passed a NULL pointer");
|
|
226 }
|
|
227
|
|
228 if(tt)
|
|
229 *tt = -1;
|
|
230 if(*pr)
|
|
231 *pr = -1;
|
|
232
|
|
233 domain = self->vm->state.domain;
|
|
234 if((domain == FP_DOMAIN) || (domain == VMGM_DOMAIN)) {
|
|
235 /* Not in a title */
|
|
236 return S_OK;
|
|
237 }
|
|
238
|
|
239 vts_ttn = self->vm->state.VTS_TTN_REG;
|
|
240 vts = self->vm->state.vtsN;
|
|
241
|
|
242 if(pr) {
|
|
243 *pr = self->vm->state.pgN;
|
|
244 }
|
|
245
|
|
246 /* Search TT_SRPT for title */
|
|
247 if(!(vm_get_vmgi(self->vm))) {
|
|
248 printerr("Oh poo, no SRPT");
|
|
249 return S_ERR;
|
|
250 }
|
|
251
|
|
252 srpt = vm_get_vmgi(self->vm)->tt_srpt;
|
|
253 for(i=0; i<srpt->nr_of_srpts; i++) {
|
|
254 title_info_t* info = &(srpt->title[i]);
|
|
255 if((info->title_set_nr == vts) && (info->vts_ttn == vts_ttn)) {
|
|
256 if(tt)
|
|
257 *tt = i+1;
|
|
258 }
|
|
259 }
|
|
260
|
|
261 return S_OK;
|
|
262 }
|
|
263
|
|
264 static char __title_str[] = "DVDNAV";
|
|
265
|
|
266 dvdnav_status_t dvdnav_get_title_string(dvdnav_t *self, char **title_str) {
|
|
267 if(!self)
|
|
268 return S_ERR;
|
|
269
|
|
270 if(!title_str) {
|
|
271 printerr("Passed a NULL pointer");
|
|
272 return S_ERR;
|
|
273 }
|
|
274
|
|
275 (*title_str) = __title_str;
|
|
276
|
|
277 return S_OK;
|
|
278 }
|
|
279
|
|
280 dvdnav_status_t dvdnav_get_position(dvdnav_t *self, unsigned int* pos,
|
|
281 unsigned int *len) {
|
|
282 uint32_t cur_sector;
|
|
283 uint32_t first_cell_nr;
|
|
284 uint32_t last_cell_nr;
|
|
285 cell_playback_t *first_cell;
|
|
286 cell_playback_t *last_cell;
|
|
287 dvd_state_t *state;
|
|
288 if((!self) || (!self->vm) )
|
|
289 return 0;
|
|
290
|
|
291 state = &(self->vm->state);
|
|
292 if((!state) || (!state->pgc) )
|
|
293 return 0;
|
|
294
|
|
295 /* Sanity check */
|
|
296 if(state->pgN > state->pgc->nr_of_programs) {
|
|
297 return 0;
|
|
298 }
|
|
299
|
|
300 /* Get current sector */
|
|
301 cur_sector = self->vobu_start + self->blockN;
|
|
302
|
|
303 /* Find start cell of program. */
|
|
304 first_cell_nr = state->pgc->program_map[state->pgN-1];
|
|
305 first_cell = &(state->pgc->cell_playback[first_cell_nr-1]);
|
|
306 if(state->pgN < state->pgc->nr_of_programs) {
|
|
307 last_cell_nr = state->pgc->program_map[state->pgN] - 1;
|
|
308 } else {
|
|
309 last_cell_nr = state->pgc->nr_of_cells;
|
|
310 }
|
|
311 last_cell = &(state->pgc->cell_playback[last_cell_nr-1]);
|
|
312
|
|
313 *pos= cur_sector - first_cell->first_sector;
|
|
314 *len= last_cell->last_sector - first_cell->first_sector;
|
|
315 /* printf("dvdnav:searching:current pos=%u length=%u\n",*pos,*len); */
|
|
316
|
|
317
|
|
318 return S_OK;
|
|
319 }
|
|
320
|