1 diff -Naur libdvdnav.orig/src/searching.c libdvdnav/src/searching.c
2 --- libdvdnav.orig/src/searching.c 2009-01-08 14:57:11.000000000 -0800
3 +++ libdvdnav/src/searching.c 2009-09-12 15:36:14.403299590 -0700
5 /* Return placed in vobu. */
6 /* Returns error status */
7 /* FIXME: Maybe need to handle seeking outside current cell. */
8 -static dvdnav_status_t dvdnav_scan_admap(dvdnav_t *this, int32_t domain, uint32_t seekto_block, uint32_t *vobu) {
9 +static dvdnav_status_t dvdnav_scan_admap(dvdnav_t *this, int32_t domain, uint32_t seekto_block, int next, uint32_t *vobu) {
10 vobu_admap_t *admap = NULL;
14 vobu_start = next_vobu;
18 + *vobu = next ? next_vobu : vobu_start;
19 return DVDNAV_STATUS_OK;
21 fprintf(MSG_OUT, "libdvdnav: admap not located\n");
23 fprintf(MSG_OUT, "libdvdnav: Seeking to cell %i from choice of %i to %i\n",
24 cell_nr, first_cell_nr, last_cell_nr);
26 - if (dvdnav_scan_admap(this, state->domain, target, &vobu) == DVDNAV_STATUS_OK) {
27 + if (dvdnav_scan_admap(this, state->domain, target, 0, &vobu) == DVDNAV_STATUS_OK) {
28 uint32_t start = state->pgc->cell_playback[cell_nr-1].first_sector;
30 if (vm_jump_cell_block(this->vm, cell_nr, vobu - start)) {
32 dvdnav_status_t dvdnav_sector_search(dvdnav_t *this,
33 uint64_t offset, int32_t origin) {
35 + uint32_t current_pos;
36 + uint32_t cur_sector;
37 + uint32_t cur_cell_nr;
39 uint32_t first_cell_nr, last_cell_nr, cell_nr;
42 cell_playback_t *cell;
44 dvdnav_status_t result;
46 fprintf(MSG_OUT, "libdvdnav: Before cellN=%u blockN=%u\n", state->cellN, state->blockN);
49 + current_pos = target;
50 + cur_sector = this->vobu.vobu_start + this->vobu.blockN;
51 + cur_cell_nr = state->cellN;
55 if(offset >= length) {
57 pthread_mutex_unlock(&this->vm_lock);
58 return DVDNAV_STATUS_ERR;
60 + forward = target > current_pos;
62 this->cur_cell_time = 0;
63 if (this->pgc_based) {
66 /* convert the target sector from Cell-relative to absolute physical sector */
67 target += cell->first_sector;
68 + if (forward && (cell_nr == cur_cell_nr)) {
70 + /* if we are seeking forward from the current position, make sure
71 + * we move to a new position that is after our current position.
72 + * simply truncating to the vobu will go backwards */
73 + if (dvdnav_scan_admap(this, state->domain, target, 0, &vobu) != DVDNAV_STATUS_OK)
75 + if (vobu <= cur_sector) {
76 + if (dvdnav_scan_admap(this, state->domain, target, 1, &vobu) != DVDNAV_STATUS_OK)
78 + if (vobu > cell->last_sector) {
79 + if (cell_nr == last_cell_nr)
82 + cell = &(state->pgc->cell_playback[cell_nr-1]);
83 + target = cell->first_sector;
93 fprintf(MSG_OUT, "libdvdnav: Seeking to cell %i from choice of %i to %i\n",
94 cell_nr, first_cell_nr, last_cell_nr);
96 - if (dvdnav_scan_admap(this, state->domain, target, &vobu) == DVDNAV_STATUS_OK) {
97 + if (dvdnav_scan_admap(this, state->domain, target, 0, &vobu) == DVDNAV_STATUS_OK) {
98 int32_t start = state->pgc->cell_playback[cell_nr-1].first_sector;
100 if (vm_jump_cell_block(this->vm, cell_nr, vobu - start)) {