Mercurial > libdvdnav.hg
comparison searching.c @ 388:90ca650854e0 src
Remove all trailing whitespace,
patch by Erik Hovland *erik$hovland dot org%
author | rathann |
---|---|
date | Sat, 06 Sep 2008 21:55:51 +0000 |
parents | 579a3538d284 |
children | d3c273ced49c |
comparison
equal
deleted
inserted
replaced
387:4e28052eb201 | 388:90ca650854e0 |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2000 Rich Wareham <richwareham@users.sourceforge.net> | 2 * Copyright (C) 2000 Rich Wareham <richwareham@users.sourceforge.net> |
3 * | 3 * |
4 * This file is part of libdvdnav, a DVD navigation library. | 4 * This file is part of libdvdnav, a DVD navigation library. |
5 * | 5 * |
6 * libdvdnav is free software; you can redistribute it and/or modify | 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 | 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 | 8 * the Free Software Foundation; either version 2 of the License, or |
9 * (at your option) any later version. | 9 * (at your option) any later version. |
10 * | 10 * |
11 * libdvdnav is distributed in the hope that it will be useful, | 11 * libdvdnav is distributed in the hope that it will be useful, |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 * GNU General Public License for more details. | 14 * GNU General Public License for more details. |
15 * | 15 * |
16 * You should have received a copy of the GNU General Public License | 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 | 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 | 18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
19 * | 19 * |
20 * $Id$ | 20 * $Id$ |
102 | 102 |
103 /* FIXME: right now, this function does not use the time tables but interpolates | 103 /* FIXME: right now, this function does not use the time tables but interpolates |
104 only the cell times */ | 104 only the cell times */ |
105 dvdnav_status_t dvdnav_time_search(dvdnav_t *this, | 105 dvdnav_status_t dvdnav_time_search(dvdnav_t *this, |
106 uint64_t time) { | 106 uint64_t time) { |
107 | 107 |
108 uint64_t target = time; | 108 uint64_t target = time; |
109 uint64_t length = 0; | 109 uint64_t length = 0; |
110 uint32_t first_cell_nr, last_cell_nr, cell_nr; | 110 uint32_t first_cell_nr, last_cell_nr, cell_nr; |
111 int32_t found; | 111 int32_t found; |
112 cell_playback_t *cell; | 112 cell_playback_t *cell; |
114 | 114 |
115 if(this->position_current.still != 0) { | 115 if(this->position_current.still != 0) { |
116 printerr("Cannot seek in a still frame."); | 116 printerr("Cannot seek in a still frame."); |
117 return DVDNAV_STATUS_ERR; | 117 return DVDNAV_STATUS_ERR; |
118 } | 118 } |
119 | 119 |
120 pthread_mutex_lock(&this->vm_lock); | 120 pthread_mutex_lock(&this->vm_lock); |
121 state = &(this->vm->state); | 121 state = &(this->vm->state); |
122 if(!state->pgc) { | 122 if(!state->pgc) { |
123 printerr("No current PGC."); | 123 printerr("No current PGC."); |
124 pthread_mutex_unlock(&this->vm_lock); | 124 pthread_mutex_unlock(&this->vm_lock); |
125 return DVDNAV_STATUS_ERR; | 125 return DVDNAV_STATUS_ERR; |
126 } | 126 } |
127 | 127 |
128 | 128 |
129 this->cur_cell_time = 0; | 129 this->cur_cell_time = 0; |
130 if (this->pgc_based) { | 130 if (this->pgc_based) { |
131 first_cell_nr = 1; | 131 first_cell_nr = 1; |
132 last_cell_nr = state->pgc->nr_of_cells; | 132 last_cell_nr = state->pgc->nr_of_cells; |
133 } else { | 133 } else { |
134 /* Find start cell of program. */ | 134 /* Find start cell of program. */ |
150 target -= length; | 150 target -= length; |
151 } else { | 151 } else { |
152 /* FIXME: there must be a better way than interpolation */ | 152 /* FIXME: there must be a better way than interpolation */ |
153 target = target * (cell->last_sector - cell->first_sector + 1) / length; | 153 target = target * (cell->last_sector - cell->first_sector + 1) / length; |
154 target += cell->first_sector; | 154 target += cell->first_sector; |
155 | 155 |
156 found = 1; | 156 found = 1; |
157 break; | 157 break; |
158 } | 158 } |
159 } | 159 } |
160 | 160 |
164 fprintf(MSG_OUT, "libdvdnav: Seeking to cell %i from choice of %i to %i\n", | 164 fprintf(MSG_OUT, "libdvdnav: Seeking to cell %i from choice of %i to %i\n", |
165 cell_nr, first_cell_nr, last_cell_nr); | 165 cell_nr, first_cell_nr, last_cell_nr); |
166 #endif | 166 #endif |
167 if (dvdnav_scan_admap(this, state->domain, target, &vobu) == DVDNAV_STATUS_OK) { | 167 if (dvdnav_scan_admap(this, state->domain, target, &vobu) == DVDNAV_STATUS_OK) { |
168 uint32_t start = state->pgc->cell_playback[cell_nr-1].first_sector; | 168 uint32_t start = state->pgc->cell_playback[cell_nr-1].first_sector; |
169 | 169 |
170 if (vm_jump_cell_block(this->vm, cell_nr, vobu - start)) { | 170 if (vm_jump_cell_block(this->vm, cell_nr, vobu - start)) { |
171 #ifdef LOG_DEBUG | 171 #ifdef LOG_DEBUG |
172 fprintf(MSG_OUT, "libdvdnav: After cellN=%u blockN=%u target=%x vobu=%x start=%x\n" , | 172 fprintf(MSG_OUT, "libdvdnav: After cellN=%u blockN=%u target=%x vobu=%x start=%x\n" , |
173 state->cellN, state->blockN, target, vobu, start); | 173 state->cellN, state->blockN, target, vobu, start); |
174 #endif | 174 #endif |
176 pthread_mutex_unlock(&this->vm_lock); | 176 pthread_mutex_unlock(&this->vm_lock); |
177 return DVDNAV_STATUS_OK; | 177 return DVDNAV_STATUS_OK; |
178 } | 178 } |
179 } | 179 } |
180 } | 180 } |
181 | 181 |
182 fprintf(MSG_OUT, "libdvdnav: Error when seeking\n"); | 182 fprintf(MSG_OUT, "libdvdnav: Error when seeking\n"); |
183 printerr("Error when seeking."); | 183 printerr("Error when seeking."); |
184 pthread_mutex_unlock(&this->vm_lock); | 184 pthread_mutex_unlock(&this->vm_lock); |
185 return DVDNAV_STATUS_ERR; | 185 return DVDNAV_STATUS_ERR; |
186 } | 186 } |
197 | 197 |
198 if(this->position_current.still != 0) { | 198 if(this->position_current.still != 0) { |
199 printerr("Cannot seek in a still frame."); | 199 printerr("Cannot seek in a still frame."); |
200 return DVDNAV_STATUS_ERR; | 200 return DVDNAV_STATUS_ERR; |
201 } | 201 } |
202 | 202 |
203 result = dvdnav_get_position(this, &target, &length); | 203 result = dvdnav_get_position(this, &target, &length); |
204 if(!result) { | 204 if(!result) { |
205 return DVDNAV_STATUS_ERR; | 205 return DVDNAV_STATUS_ERR; |
206 } | 206 } |
207 | 207 |
208 pthread_mutex_lock(&this->vm_lock); | 208 pthread_mutex_lock(&this->vm_lock); |
209 state = &(this->vm->state); | 209 state = &(this->vm->state); |
210 if(!state->pgc) { | 210 if(!state->pgc) { |
211 printerr("No current PGC."); | 211 printerr("No current PGC."); |
212 pthread_mutex_unlock(&this->vm_lock); | 212 pthread_mutex_unlock(&this->vm_lock); |
213 return DVDNAV_STATUS_ERR; | 213 return DVDNAV_STATUS_ERR; |
214 } | 214 } |
215 #ifdef LOG_DEBUG | 215 #ifdef LOG_DEBUG |
216 fprintf(MSG_OUT, "libdvdnav: seeking to offset=%lu pos=%u length=%u\n", offset, target, length); | 216 fprintf(MSG_OUT, "libdvdnav: seeking to offset=%lu pos=%u length=%u\n", offset, target, length); |
217 fprintf(MSG_OUT, "libdvdnav: Before cellN=%u blockN=%u\n", state->cellN, state->blockN); | 217 fprintf(MSG_OUT, "libdvdnav: Before cellN=%u blockN=%u\n", state->cellN, state->blockN); |
218 #endif | 218 #endif |
219 | 219 |
220 switch(origin) { | 220 switch(origin) { |
221 case SEEK_SET: | 221 case SEEK_SET: |
246 /* Error occured */ | 246 /* Error occured */ |
247 printerr("Illegal seek mode."); | 247 printerr("Illegal seek mode."); |
248 pthread_mutex_unlock(&this->vm_lock); | 248 pthread_mutex_unlock(&this->vm_lock); |
249 return DVDNAV_STATUS_ERR; | 249 return DVDNAV_STATUS_ERR; |
250 } | 250 } |
251 | 251 |
252 this->cur_cell_time = 0; | 252 this->cur_cell_time = 0; |
253 if (this->pgc_based) { | 253 if (this->pgc_based) { |
254 first_cell_nr = 1; | 254 first_cell_nr = 1; |
255 last_cell_nr = state->pgc->nr_of_cells; | 255 last_cell_nr = state->pgc->nr_of_cells; |
256 } else { | 256 } else { |
285 fprintf(MSG_OUT, "libdvdnav: Seeking to cell %i from choice of %i to %i\n", | 285 fprintf(MSG_OUT, "libdvdnav: Seeking to cell %i from choice of %i to %i\n", |
286 cell_nr, first_cell_nr, last_cell_nr); | 286 cell_nr, first_cell_nr, last_cell_nr); |
287 #endif | 287 #endif |
288 if (dvdnav_scan_admap(this, state->domain, target, &vobu) == DVDNAV_STATUS_OK) { | 288 if (dvdnav_scan_admap(this, state->domain, target, &vobu) == DVDNAV_STATUS_OK) { |
289 int32_t start = state->pgc->cell_playback[cell_nr-1].first_sector; | 289 int32_t start = state->pgc->cell_playback[cell_nr-1].first_sector; |
290 | 290 |
291 if (vm_jump_cell_block(this->vm, cell_nr, vobu - start)) { | 291 if (vm_jump_cell_block(this->vm, cell_nr, vobu - start)) { |
292 #ifdef LOG_DEBUG | 292 #ifdef LOG_DEBUG |
293 fprintf(MSG_OUT, "libdvdnav: After cellN=%u blockN=%u target=%x vobu=%x start=%x\n" , | 293 fprintf(MSG_OUT, "libdvdnav: After cellN=%u blockN=%u target=%x vobu=%x start=%x\n" , |
294 state->cellN, state->blockN, target, vobu, start); | 294 state->cellN, state->blockN, target, vobu, start); |
295 #endif | 295 #endif |
297 pthread_mutex_unlock(&this->vm_lock); | 297 pthread_mutex_unlock(&this->vm_lock); |
298 return DVDNAV_STATUS_OK; | 298 return DVDNAV_STATUS_OK; |
299 } | 299 } |
300 } | 300 } |
301 } | 301 } |
302 | 302 |
303 fprintf(MSG_OUT, "libdvdnav: Error when seeking\n"); | 303 fprintf(MSG_OUT, "libdvdnav: Error when seeking\n"); |
304 fprintf(MSG_OUT, "libdvdnav: FIXME: Implement seeking to location %u\n", target); | 304 fprintf(MSG_OUT, "libdvdnav: FIXME: Implement seeking to location %u\n", target); |
305 printerr("Error when seeking."); | 305 printerr("Error when seeking."); |
306 pthread_mutex_unlock(&this->vm_lock); | 306 pthread_mutex_unlock(&this->vm_lock); |
307 return DVDNAV_STATUS_ERR; | 307 return DVDNAV_STATUS_ERR; |
308 } | 308 } |
309 | 309 |
310 dvdnav_status_t dvdnav_part_search(dvdnav_t *this, int32_t part) { | 310 dvdnav_status_t dvdnav_part_search(dvdnav_t *this, int32_t part) { |
311 int32_t title, old_part; | 311 int32_t title, old_part; |
312 | 312 |
313 if (dvdnav_current_title_info(this, &title, &old_part) == DVDNAV_STATUS_OK) | 313 if (dvdnav_current_title_info(this, &title, &old_part) == DVDNAV_STATUS_OK) |
314 return dvdnav_part_play(this, title, part); | 314 return dvdnav_part_play(this, title, part); |
315 return DVDNAV_STATUS_ERR; | 315 return DVDNAV_STATUS_ERR; |
316 } | 316 } |
317 | 317 |
413 return DVDNAV_STATUS_OK; | 413 return DVDNAV_STATUS_OK; |
414 } | 414 } |
415 | 415 |
416 dvdnav_status_t dvdnav_menu_call(dvdnav_t *this, DVDMenuID_t menu) { | 416 dvdnav_status_t dvdnav_menu_call(dvdnav_t *this, DVDMenuID_t menu) { |
417 vm_t *try_vm; | 417 vm_t *try_vm; |
418 | 418 |
419 pthread_mutex_lock(&this->vm_lock); | 419 pthread_mutex_lock(&this->vm_lock); |
420 if(!this->vm->state.pgc) { | 420 if(!this->vm->state.pgc) { |
421 printerr("No current PGC."); | 421 printerr("No current PGC."); |
422 pthread_mutex_unlock(&this->vm_lock); | 422 pthread_mutex_unlock(&this->vm_lock); |
423 return DVDNAV_STATUS_ERR; | 423 return DVDNAV_STATUS_ERR; |
424 } | 424 } |
425 | 425 |
426 this->cur_cell_time = 0; | 426 this->cur_cell_time = 0; |
427 /* make a copy of current VM and try to navigate the copy to the menu */ | 427 /* make a copy of current VM and try to navigate the copy to the menu */ |
428 try_vm = vm_new_copy(this->vm); | 428 try_vm = vm_new_copy(this->vm); |
429 if ( (menu == DVD_MENU_Escape) && (this->vm->state.domain != VTS_DOMAIN)) { | 429 if ( (menu == DVD_MENU_Escape) && (this->vm->state.domain != VTS_DOMAIN)) { |
430 /* Try resume */ | 430 /* Try resume */ |
432 /* merge changes on success */ | 432 /* merge changes on success */ |
433 vm_merge(this->vm, try_vm); | 433 vm_merge(this->vm, try_vm); |
434 vm_free_copy(try_vm); | 434 vm_free_copy(try_vm); |
435 this->position_current.still = 0; | 435 this->position_current.still = 0; |
436 this->vm->hop_channel++; | 436 this->vm->hop_channel++; |
437 pthread_mutex_unlock(&this->vm_lock); | 437 pthread_mutex_unlock(&this->vm_lock); |
438 return DVDNAV_STATUS_OK; | 438 return DVDNAV_STATUS_OK; |
439 } | 439 } |
440 } | 440 } |
441 if (menu == DVD_MENU_Escape) menu = DVD_MENU_Root; | 441 if (menu == DVD_MENU_Escape) menu = DVD_MENU_Root; |
442 | 442 |
443 if (vm_jump_menu(try_vm, menu) && !try_vm->stopped) { | 443 if (vm_jump_menu(try_vm, menu) && !try_vm->stopped) { |
444 /* merge changes on success */ | 444 /* merge changes on success */ |
445 vm_merge(this->vm, try_vm); | 445 vm_merge(this->vm, try_vm); |
446 vm_free_copy(try_vm); | 446 vm_free_copy(try_vm); |
447 this->position_current.still = 0; | 447 this->position_current.still = 0; |
448 this->vm->hop_channel++; | 448 this->vm->hop_channel++; |
449 pthread_mutex_unlock(&this->vm_lock); | 449 pthread_mutex_unlock(&this->vm_lock); |
450 return DVDNAV_STATUS_OK; | 450 return DVDNAV_STATUS_OK; |
451 } else { | 451 } else { |
452 vm_free_copy(try_vm); | 452 vm_free_copy(try_vm); |
453 printerr("No such menu or menu not reachable."); | 453 printerr("No such menu or menu not reachable."); |
454 pthread_mutex_unlock(&this->vm_lock); | 454 pthread_mutex_unlock(&this->vm_lock); |
455 return DVDNAV_STATUS_ERR; | 455 return DVDNAV_STATUS_ERR; |
456 } | 456 } |
457 } | 457 } |
458 | 458 |
459 dvdnav_status_t dvdnav_get_position(dvdnav_t *this, uint32_t *pos, | 459 dvdnav_status_t dvdnav_get_position(dvdnav_t *this, uint32_t *pos, |
509 * pos is length of PG up to here + sector's offset in this cell */ | 509 * pos is length of PG up to here + sector's offset in this cell */ |
510 *pos = *len + cur_sector - cell->first_sector; | 510 *pos = *len + cur_sector - cell->first_sector; |
511 } | 511 } |
512 *len += cell->last_sector - cell->first_sector + 1; | 512 *len += cell->last_sector - cell->first_sector + 1; |
513 } | 513 } |
514 | 514 |
515 assert((signed)*pos != -1); | 515 assert((signed)*pos != -1); |
516 | 516 |
517 pthread_mutex_unlock(&this->vm_lock); | 517 pthread_mutex_unlock(&this->vm_lock); |
518 | 518 |
519 return DVDNAV_STATUS_OK; | 519 return DVDNAV_STATUS_OK; |
541 /* Now find first and last cells in title. */ | 541 /* Now find first and last cells in title. */ |
542 first_cell_nr = state->pgc->program_map[0]; | 542 first_cell_nr = state->pgc->program_map[0]; |
543 first_cell = &(state->pgc->cell_playback[first_cell_nr-1]); | 543 first_cell = &(state->pgc->cell_playback[first_cell_nr-1]); |
544 last_cell_nr = state->pgc->nr_of_cells; | 544 last_cell_nr = state->pgc->nr_of_cells; |
545 last_cell = &(state->pgc->cell_playback[last_cell_nr-1]); | 545 last_cell = &(state->pgc->cell_playback[last_cell_nr-1]); |
546 | 546 |
547 *pos = cur_sector - first_cell->first_sector; | 547 *pos = cur_sector - first_cell->first_sector; |
548 *len = last_cell->last_sector - first_cell->first_sector; | 548 *len = last_cell->last_sector - first_cell->first_sector; |
549 | 549 |
550 return DVDNAV_STATUS_OK; | 550 return DVDNAV_STATUS_OK; |
551 } | 551 } |
552 | 552 |
553 uint32_t dvdnav_describe_title_chapters(dvdnav_t *this, int32_t title, uint64_t **times, uint64_t *duration) { | 553 uint32_t dvdnav_describe_title_chapters(dvdnav_t *this, int32_t title, uint64_t **times, uint64_t *duration) { |
554 int32_t retval=0; | 554 int32_t retval=0; |
575 ifo = vm_get_title_ifo(this->vm, title); | 575 ifo = vm_get_title_ifo(this->vm, title); |
576 if(!ifo || !ifo->vts_pgcit) { | 576 if(!ifo || !ifo->vts_pgcit) { |
577 printerr("Couldn't open IFO for chosen title, exit."); | 577 printerr("Couldn't open IFO for chosen title, exit."); |
578 goto fail; | 578 goto fail; |
579 } | 579 } |
580 | 580 |
581 ptitle = &this->vm->vmgi->tt_srpt->title[title-1]; | 581 ptitle = &this->vm->vmgi->tt_srpt->title[title-1]; |
582 parts = ptitle->nr_of_ptts; | 582 parts = ptitle->nr_of_ptts; |
583 ptt = ifo->vts_ptt_srpt->title[ptitle->vts_ttn-1].ptt; | 583 ptt = ifo->vts_ptt_srpt->title[ptitle->vts_ttn-1].ptt; |
584 | 584 |
585 tmp = calloc(1, sizeof(uint64_t)*parts); | 585 tmp = calloc(1, sizeof(uint64_t)*parts); |
586 if(!tmp) | 586 if(!tmp) |
587 goto fail; | 587 goto fail; |
588 | 588 |
589 length = 0; | 589 length = 0; |
590 for(i=0; i<parts; i++) { | 590 for(i=0; i<parts; i++) { |
591 uint32_t cellnr, endcellnr; | 591 uint32_t cellnr, endcellnr; |
592 pgc = ifo->vts_pgcit->pgci_srp[ptt[i].pgcn-1].pgc; | 592 pgc = ifo->vts_pgcit->pgci_srp[ptt[i].pgcn-1].pgc; |
593 if(ptt[i].pgn > pgc->nr_of_programs) { | 593 if(ptt[i].pgn > pgc->nr_of_programs) { |
594 printerr("WRONG part number."); | 594 printerr("WRONG part number."); |
595 goto fail; | 595 goto fail; |
596 } | 596 } |
597 | 597 |
598 cellnr = pgc->program_map[ptt[i].pgn-1]; | 598 cellnr = pgc->program_map[ptt[i].pgn-1]; |
599 if(ptt[i].pgn < pgc->nr_of_programs) | 599 if(ptt[i].pgn < pgc->nr_of_programs) |
600 endcellnr = pgc->program_map[ptt[i].pgn]; | 600 endcellnr = pgc->program_map[ptt[i].pgn]; |
601 else | 601 else |
602 endcellnr = 0; | 602 endcellnr = 0; |
603 | 603 |
604 do { | 604 do { |
605 cell = &pgc->cell_playback[cellnr-1]; | 605 cell = &pgc->cell_playback[cellnr-1]; |
606 if(!(cell->block_type == BLOCK_TYPE_ANGLE_BLOCK && | 606 if(!(cell->block_type == BLOCK_TYPE_ANGLE_BLOCK && |
607 cell->block_mode != BLOCK_MODE_FIRST_CELL | 607 cell->block_mode != BLOCK_MODE_FIRST_CELL |
608 )) | 608 )) |