Mercurial > libdvdnav.hg
comparison searching.c @ 22:3c1df0cb3aee src
Start of rewrite of libdvdnav. Still need to re-implement seeking.
author | jcdutton |
---|---|
date | Mon, 22 Apr 2002 22:01:28 +0000 |
parents | 66708b4a1b5e |
children | 870a0a1eee41 |
comparison
equal
deleted
inserted
replaced
21:d2d73f2ad8d3 | 22:3c1df0cb3aee |
---|---|
31 #include "vm.h" | 31 #include "vm.h" |
32 #include <dvdread/nav_types.h> | 32 #include <dvdread/nav_types.h> |
33 | 33 |
34 /* Searching API calls */ | 34 /* Searching API calls */ |
35 | 35 |
36 dvdnav_status_t dvdnav_time_search(dvdnav_t *self, | 36 dvdnav_status_t dvdnav_time_search(dvdnav_t *this, |
37 unsigned long int time) { | 37 unsigned long int time) { |
38 /* Time search the current PGC based on the xxx table */ | 38 /* Time search the current PGC based on the xxx table */ |
39 return S_OK; | 39 return S_OK; |
40 } | 40 } |
41 | 41 |
42 dvdnav_status_t dvdnav_sector_search(dvdnav_t *self, | 42 dvdnav_status_t dvdnav_sector_search(dvdnav_t *this, |
43 unsigned long int offset, int origin) { | 43 unsigned long int offset, int origin) { |
44 /* FIXME: Implement */ | 44 /* FIXME: Implement */ |
45 | 45 |
46 uint32_t target = 0; | 46 uint32_t target = 0; |
47 uint32_t length = 0; | 47 uint32_t length = 0; |
49 int found; | 49 int found; |
50 cell_playback_t *cell, *fnd_cell; | 50 cell_playback_t *cell, *fnd_cell; |
51 dvd_state_t *state; | 51 dvd_state_t *state; |
52 dvdnav_status_t result; | 52 dvdnav_status_t result; |
53 | 53 |
54 if((!self) || (!self->vm) ) | 54 if((!this) || (!this->vm) ) |
55 return -1; | 55 return -1; |
56 | 56 |
57 state = &(self->vm->state); | 57 state = &(this->vm->state); |
58 if((!state) || (!state->pgc) ) | 58 if((!state) || (!state->pgc) ) |
59 return -1; | 59 return -1; |
60 | 60 |
61 if(offset == 0) | 61 if(offset == 0) |
62 return -1; | 62 return -1; |
63 | 63 |
64 if(self->still_frame != -1) | 64 if(this->position_current.still != 0) |
65 /* Cannot do seeking in a still frame. */ | 65 /* Cannot do seeking in a still frame. */ |
66 return -1; | 66 return -1; |
67 | 67 |
68 pthread_mutex_lock(&self->vm_lock); | 68 pthread_mutex_lock(&this->vm_lock); |
69 result = dvdnav_get_position(self, &target, &length); | 69 result = dvdnav_get_position(this, &target, &length); |
70 fprintf(stderr,"FIXME: seeking to offset=%lu pos=%u length=%u\n", offset, 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" , | 71 fprintf(stderr,"FIXME: Before cellN=%u blockN=%u\n" , |
72 state->cellN, | 72 state->cellN, |
73 state->blockN); | 73 state->blockN); |
74 if(!result) { | 74 if(!result) { |
75 pthread_mutex_unlock(&self->vm_lock); | 75 pthread_mutex_unlock(&this->vm_lock); |
76 return -1; | 76 return -1; |
77 } | 77 } |
78 | 78 |
79 switch(origin) { | 79 switch(origin) { |
80 case SEEK_SET: | 80 case SEEK_SET: |
81 if(offset > length) { | 81 if(offset > length) { |
82 pthread_mutex_unlock(&self->vm_lock); | 82 pthread_mutex_unlock(&this->vm_lock); |
83 return -1; | 83 return -1; |
84 } | 84 } |
85 target = offset; | 85 target = offset; |
86 break; | 86 break; |
87 case SEEK_CUR: | 87 case SEEK_CUR: |
88 if(target + offset > length) { | 88 if(target + offset > length) { |
89 pthread_mutex_unlock(&self->vm_lock); | 89 pthread_mutex_unlock(&this->vm_lock); |
90 return -1; | 90 return -1; |
91 } | 91 } |
92 target += offset; | 92 target += offset; |
93 break; | 93 break; |
94 case SEEK_END: | 94 case SEEK_END: |
95 if(length - offset < 0) { | 95 if(length - offset < 0) { |
96 pthread_mutex_unlock(&self->vm_lock); | 96 pthread_mutex_unlock(&this->vm_lock); |
97 return -1; | 97 return -1; |
98 } | 98 } |
99 target = length - offset; | 99 target = length - offset; |
100 default: | 100 default: |
101 /* Error occured */ | 101 /* Error occured */ |
102 pthread_mutex_unlock(&self->vm_lock); | 102 pthread_mutex_unlock(&this->vm_lock); |
103 return -1; | 103 return -1; |
104 } | 104 } |
105 | 105 |
106 /* First find closest cell number in program */ | 106 /* First find closest cell number in program */ |
107 first_cell_nr = state->pgc->program_map[state->pgN-1]; | 107 first_cell_nr = state->pgc->program_map[state->pgN-1]; |
125 } | 125 } |
126 | 126 |
127 if(fnd_cell_nr <= last_cell_nr) { | 127 if(fnd_cell_nr <= last_cell_nr) { |
128 fprintf(stderr,"Seeking to cell %i from choice of %i to %i\n", | 128 fprintf(stderr,"Seeking to cell %i from choice of %i to %i\n", |
129 fnd_cell_nr, first_cell_nr, last_cell_nr); | 129 fnd_cell_nr, first_cell_nr, last_cell_nr); |
130 self->seekto_block = target; | 130 this->seekto_block = target; |
131 self->seeking = 1; | 131 this->seeking = 1; |
132 /* | 132 /* |
133 * Clut does not actually change, | 133 * Clut does not actually change, |
134 * but as the decoders have been closed then opened, | 134 * but as the decoders have been closed then opened, |
135 * A new clut has to be sent. | 135 * A new clut has to be sent. |
136 */ | 136 */ |
137 self->spu_clut_changed = 1; | 137 this->spu_clut_changed = 1; |
138 //ogle_do_post_jump(ogle); | 138 //ogle_do_post_jump(ogle); |
139 fprintf(stderr,"FIXME: After cellN=%u blockN=%u\n" , | 139 fprintf(stderr,"FIXME: After cellN=%u blockN=%u\n" , |
140 state->cellN, | 140 state->cellN, |
141 state->blockN); | 141 state->blockN); |
142 | 142 |
143 pthread_mutex_unlock(&self->vm_lock); | 143 pthread_mutex_unlock(&this->vm_lock); |
144 return target; | 144 return target; |
145 } else { | 145 } else { |
146 fprintf(stderr, "Error when seeking, asked to seek outside program\n"); | 146 fprintf(stderr, "Error when seeking, asked to seek outside program\n"); |
147 } | 147 } |
148 | 148 |
149 | 149 |
150 | 150 |
151 fprintf(stderr,"FIXME: Implement seeking to location %u\n", target); | 151 fprintf(stderr,"FIXME: Implement seeking to location %u\n", target); |
152 | 152 |
153 // self->seekto_block=target; | 153 // this->seekto_block=target; |
154 // self->seeking = 1; | 154 // this->seeking = 1; |
155 | 155 |
156 pthread_mutex_unlock(&self->vm_lock); | 156 pthread_mutex_unlock(&this->vm_lock); |
157 return -1; | 157 return -1; |
158 } | 158 } |
159 | 159 |
160 dvdnav_status_t dvdnav_part_search(dvdnav_t *self, int part) { | 160 dvdnav_status_t dvdnav_part_search(dvdnav_t *this, int part) { |
161 return S_OK; | 161 return S_OK; |
162 } | 162 } |
163 | 163 |
164 dvdnav_status_t dvdnav_prev_pg_search(dvdnav_t *self) { | 164 dvdnav_status_t dvdnav_prev_pg_search(dvdnav_t *this) { |
165 dvd_state_t *state; | 165 dvd_state_t *state; |
166 state = &(self->vm->state); | 166 state = &(this->vm->state); |
167 /* Make sure this is not the first chapter */ | 167 /* Make sure this is not the first chapter */ |
168 | 168 |
169 if(state->pgN <= 1 ) { | 169 if(state->pgN <= 1 ) { |
170 fprintf(stderr,"dvdnav: at first chapter. prev chapter failed.\n"); | 170 fprintf(stderr,"dvdnav: at first chapter. prev chapter failed.\n"); |
171 return S_ERR; | 171 return S_ERR; |
172 } | 172 } |
173 fprintf(stderr,"dvdnav: previous chapter\n"); | 173 fprintf(stderr,"dvdnav: previous chapter\n"); |
174 vm_jump_prog(self->vm, state->pgN - 1); | 174 vm_jump_prog(this->vm, state->pgN - 1); |
175 dvdnav_do_post_jump(self); | 175 dvdnav_do_post_jump(this); |
176 this->vm->hop_channel++; | |
176 fprintf(stderr,"dvdnav: previous chapter done\n"); | 177 fprintf(stderr,"dvdnav: previous chapter done\n"); |
177 | 178 |
178 return S_OK; | 179 return S_OK; |
179 } | 180 } |
180 | 181 |
181 dvdnav_status_t dvdnav_top_pg_search(dvdnav_t *self) { | 182 dvdnav_status_t dvdnav_top_pg_search(dvdnav_t *this) { |
182 | 183 |
183 fprintf(stderr,"dvdnav: top chapter. NOP.\n"); | 184 fprintf(stderr,"dvdnav: top chapter. NOP.\n"); |
184 | 185 |
185 return S_OK; | 186 return S_OK; |
186 } | 187 } |
187 | 188 |
188 dvdnav_status_t dvdnav_next_pg_search(dvdnav_t *self) { | 189 dvdnav_status_t dvdnav_next_pg_search(dvdnav_t *this) { |
189 dvd_state_t *state; | 190 dvd_state_t *state; |
190 state = &(self->vm->state); | 191 state = &(this->vm->state); |
191 /* Make sure this is not the last chapter */ | 192 /* Make sure this is not the last chapter */ |
192 if(state->pgN >= state->pgc->nr_of_programs) { | 193 if(state->pgN >= state->pgc->nr_of_programs) { |
193 fprintf(stderr,"dvdnav: at last chapter. next chapter failed.\n"); | 194 fprintf(stderr,"dvdnav: at last chapter. next chapter failed.\n"); |
194 return S_ERR; | 195 return S_ERR; |
195 } | 196 } |
196 fprintf(stderr,"dvdnav: next chapter\n"); | 197 fprintf(stderr,"dvdnav: next chapter\n"); |
197 vm_jump_prog(self->vm, state->pgN + 1); | 198 vm_jump_prog(this->vm, state->pgN + 1); |
198 dvdnav_do_post_jump(self); | 199 dvdnav_do_post_jump(this); |
200 this->vm->hop_channel++; | |
199 fprintf(stderr,"dvdnav: next chapter done\n"); | 201 fprintf(stderr,"dvdnav: next chapter done\n"); |
200 | 202 |
201 return S_OK; | 203 return S_OK; |
202 } | 204 } |
203 | 205 |
204 dvdnav_status_t dvdnav_menu_call(dvdnav_t *self, DVDMenuID_t menu) { | 206 dvdnav_status_t dvdnav_menu_call(dvdnav_t *this, DVDMenuID_t menu) { |
205 dvd_state_t *state; | 207 dvd_state_t *state; |
206 | 208 |
207 pthread_mutex_lock(&self->vm_lock); | 209 pthread_mutex_lock(&this->vm_lock); |
208 state = &(self->vm->state); | 210 state = &(this->vm->state); |
209 vm_menu_call(self->vm, menu, 0); | 211 vm_menu_call(this->vm, menu, 0); |
210 dvdnav_do_post_jump(self); | 212 dvdnav_do_post_jump(this); |
211 pthread_mutex_unlock(&self->vm_lock); | 213 pthread_mutex_unlock(&this->vm_lock); |
212 return S_OK; | 214 return S_OK; |
213 } | 215 } |
214 | 216 |
215 dvdnav_status_t dvdnav_current_title_info(dvdnav_t *self, int *tt, int *pr) { | 217 dvdnav_status_t dvdnav_current_title_info(dvdnav_t *this, int *tt, int *pr) { |
216 int vts_ttn = 0; | 218 int vts_ttn = 0; |
217 int vts, i; | 219 int vts, i; |
218 domain_t domain; | 220 domain_t domain; |
219 tt_srpt_t* srpt; | 221 tt_srpt_t* srpt; |
220 | 222 |
221 if(!self) | 223 if(!this) |
222 return S_ERR; | 224 return S_ERR; |
223 | 225 |
224 if(!tt || !pr) { | 226 if(!tt || !pr) { |
225 printerr("Passed a NULL pointer"); | 227 printerr("Passed a NULL pointer"); |
226 } | 228 } |
228 if(tt) | 230 if(tt) |
229 *tt = -1; | 231 *tt = -1; |
230 if(*pr) | 232 if(*pr) |
231 *pr = -1; | 233 *pr = -1; |
232 | 234 |
233 domain = self->vm->state.domain; | 235 domain = this->vm->state.domain; |
234 if((domain == FP_DOMAIN) || (domain == VMGM_DOMAIN)) { | 236 if((domain == FP_DOMAIN) || (domain == VMGM_DOMAIN)) { |
235 /* Not in a title */ | 237 /* Not in a title */ |
236 return S_OK; | 238 return S_OK; |
237 } | 239 } |
238 | 240 |
239 vts_ttn = self->vm->state.VTS_TTN_REG; | 241 vts_ttn = this->vm->state.VTS_TTN_REG; |
240 vts = self->vm->state.vtsN; | 242 vts = this->vm->state.vtsN; |
241 | 243 |
242 if(pr) { | 244 if(pr) { |
243 *pr = self->vm->state.pgN; | 245 *pr = this->vm->state.pgN; |
244 } | 246 } |
245 | 247 |
246 /* Search TT_SRPT for title */ | 248 /* Search TT_SRPT for title */ |
247 if(!(vm_get_vmgi(self->vm))) { | 249 if(!(vm_get_vmgi(this->vm))) { |
248 printerr("Oh poo, no SRPT"); | 250 printerr("Oh poo, no SRPT"); |
249 return S_ERR; | 251 return S_ERR; |
250 } | 252 } |
251 | 253 |
252 srpt = vm_get_vmgi(self->vm)->tt_srpt; | 254 srpt = vm_get_vmgi(this->vm)->tt_srpt; |
253 for(i=0; i<srpt->nr_of_srpts; i++) { | 255 for(i=0; i<srpt->nr_of_srpts; i++) { |
254 title_info_t* info = &(srpt->title[i]); | 256 title_info_t* info = &(srpt->title[i]); |
255 if((info->title_set_nr == vts) && (info->vts_ttn == vts_ttn)) { | 257 if((info->title_set_nr == vts) && (info->vts_ttn == vts_ttn)) { |
256 if(tt) | 258 if(tt) |
257 *tt = i+1; | 259 *tt = i+1; |
261 return S_OK; | 263 return S_OK; |
262 } | 264 } |
263 | 265 |
264 static char __title_str[] = "DVDNAV"; | 266 static char __title_str[] = "DVDNAV"; |
265 | 267 |
266 dvdnav_status_t dvdnav_get_title_string(dvdnav_t *self, char **title_str) { | 268 dvdnav_status_t dvdnav_get_title_string(dvdnav_t *this, char **title_str) { |
267 if(!self) | 269 if(!this) |
268 return S_ERR; | 270 return S_ERR; |
269 | 271 |
270 if(!title_str) { | 272 if(!title_str) { |
271 printerr("Passed a NULL pointer"); | 273 printerr("Passed a NULL pointer"); |
272 return S_ERR; | 274 return S_ERR; |
275 (*title_str) = __title_str; | 277 (*title_str) = __title_str; |
276 | 278 |
277 return S_OK; | 279 return S_OK; |
278 } | 280 } |
279 | 281 |
280 dvdnav_status_t dvdnav_get_position(dvdnav_t *self, unsigned int* pos, | 282 dvdnav_status_t dvdnav_get_position(dvdnav_t *this, unsigned int* pos, |
281 unsigned int *len) { | 283 unsigned int *len) { |
282 uint32_t cur_sector; | 284 uint32_t cur_sector; |
283 uint32_t first_cell_nr; | 285 uint32_t first_cell_nr; |
284 uint32_t last_cell_nr; | 286 uint32_t last_cell_nr; |
285 cell_playback_t *first_cell; | 287 cell_playback_t *first_cell; |
286 cell_playback_t *last_cell; | 288 cell_playback_t *last_cell; |
287 dvd_state_t *state; | 289 dvd_state_t *state; |
288 if((!self) || (!self->vm) ) | 290 if((!this) || (!this->vm) ) |
289 return 0; | 291 return 0; |
290 | 292 |
291 state = &(self->vm->state); | 293 state = &(this->vm->state); |
292 if((!state) || (!state->pgc) ) | 294 if((!state) || (!state->pgc) ) |
293 return 0; | 295 return 0; |
294 | 296 |
295 /* Sanity check */ | 297 /* Sanity check */ |
296 if(state->pgN > state->pgc->nr_of_programs) { | 298 if(state->pgN > state->pgc->nr_of_programs) { |
297 return 0; | 299 return 0; |
298 } | 300 } |
299 | 301 |
300 /* Get current sector */ | 302 /* Get current sector */ |
301 cur_sector = self->vobu_start + self->blockN; | 303 cur_sector = this->vobu.vobu_start + this->vobu.blockN; |
302 | 304 |
303 /* Find start cell of program. */ | 305 /* Find start cell of program. */ |
304 first_cell_nr = state->pgc->program_map[state->pgN-1]; | 306 first_cell_nr = state->pgc->program_map[state->pgN-1]; |
305 first_cell = &(state->pgc->cell_playback[first_cell_nr-1]); | 307 first_cell = &(state->pgc->cell_playback[first_cell_nr-1]); |
306 if(state->pgN < state->pgc->nr_of_programs) { | 308 if(state->pgN < state->pgc->nr_of_programs) { |
316 | 318 |
317 | 319 |
318 return S_OK; | 320 return S_OK; |
319 } | 321 } |
320 | 322 |
321 dvdnav_status_t dvdnav_get_position_in_title(dvdnav_t *self, | 323 dvdnav_status_t dvdnav_get_position_in_title(dvdnav_t *this, |
322 unsigned int *pos, | 324 unsigned int *pos, |
323 unsigned int *len) { | 325 unsigned int *len) { |
324 uint32_t cur_sector; | 326 uint32_t cur_sector; |
325 uint32_t first_cell_nr; | 327 uint32_t first_cell_nr; |
326 uint32_t last_cell_nr; | 328 uint32_t last_cell_nr; |
327 cell_playback_t *first_cell; | 329 cell_playback_t *first_cell; |
328 cell_playback_t *last_cell; | 330 cell_playback_t *last_cell; |
329 dvd_state_t *state; | 331 dvd_state_t *state; |
330 if((!self) || (!self->vm) ) | 332 if((!this) || (!this->vm) ) |
331 return S_ERR; | 333 return S_ERR; |
332 | 334 |
333 state = &(self->vm->state); | 335 state = &(this->vm->state); |
334 if((!state) || (!state->pgc) ) | 336 if((!state) || (!state->pgc) ) |
335 return S_ERR; | 337 return S_ERR; |
336 | 338 |
337 /* Sanity check */ | 339 /* Sanity check */ |
338 if(state->pgN > state->pgc->nr_of_programs) { | 340 if(state->pgN > state->pgc->nr_of_programs) { |
339 return S_ERR; | 341 return S_ERR; |
340 } | 342 } |
341 | 343 |
342 /* Get current sector */ | 344 /* Get current sector */ |
343 cur_sector = self->vobu_start + self->blockN; | 345 cur_sector = this->vobu.vobu_start + this->vobu.blockN; |
344 | 346 |
345 /* Now find first and last cells in title. */ | 347 /* Now find first and last cells in title. */ |
346 first_cell_nr = state->pgc->program_map[0]; | 348 first_cell_nr = state->pgc->program_map[0]; |
347 first_cell = &(state->pgc->cell_playback[first_cell_nr-1]); | 349 first_cell = &(state->pgc->cell_playback[first_cell_nr-1]); |
348 last_cell_nr = state->pgc->nr_of_cells; | 350 last_cell_nr = state->pgc->nr_of_cells; |