[52d456]: src / searching.c  Maximize  Restore  History

Download this file

321 lines (263 with data), 8.0 kB

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

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks