OSDN Git Service

x264 bump to r1339-82b80ef
[handbrake-jp/handbrake-jp-git.git] / contrib / libdvdnav / A05-forward-seek.patch
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
4 @@ -47,7 +47,7 @@
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;
11  
12  #ifdef LOG_DEBUG
13 @@ -89,7 +89,7 @@
14        vobu_start = next_vobu;
15        address++;
16      }
17 -    *vobu = vobu_start;
18 +    *vobu = next ? next_vobu : vobu_start;
19      return DVDNAV_STATUS_OK;
20    }
21    fprintf(MSG_OUT, "libdvdnav: admap not located\n");
22 @@ -160,7 +160,7 @@
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);
25  #endif
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;
29  
30        if (vm_jump_cell_block(this->vm, cell_nr, vobu - start)) {
31 @@ -184,9 +184,13 @@
32  dvdnav_status_t dvdnav_sector_search(dvdnav_t *this,
33                                      uint64_t offset, int32_t origin) {
34    uint32_t target = 0;
35 +  uint32_t current_pos;
36 +  uint32_t cur_sector;
37 +  uint32_t cur_cell_nr;
38    uint32_t length = 0;
39    uint32_t first_cell_nr, last_cell_nr, cell_nr;
40    int32_t found;
41 +  int forward = 0;
42    cell_playback_t *cell;
43    dvd_state_t *state;
44    dvdnav_status_t result;
45 @@ -213,6 +217,10 @@
46    fprintf(MSG_OUT, "libdvdnav: Before cellN=%u blockN=%u\n", state->cellN, state->blockN);
47  #endif
48  
49 +  current_pos = target;
50 +  cur_sector = this->vobu.vobu_start + this->vobu.blockN;
51 +  cur_cell_nr = state->cellN;
52 +
53    switch(origin) {
54     case SEEK_SET:
55      if(offset >= length) {
56 @@ -244,6 +252,7 @@
57      pthread_mutex_unlock(&this->vm_lock);
58      return DVDNAV_STATUS_ERR;
59    }
60 +  forward = target > current_pos;
61  
62    this->cur_cell_time = 0;
63    if (this->pgc_based) {
64 @@ -270,6 +279,27 @@
65      } else {
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)) {
69 +        uint32_t vobu;
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)
74 +          break;
75 +        if (vobu <= cur_sector) {
76 +          if (dvdnav_scan_admap(this, state->domain, target, 1, &vobu) != DVDNAV_STATUS_OK)
77 +            break;
78 +          if (vobu > cell->last_sector) {
79 +            if (cell_nr == last_cell_nr)
80 +              break;
81 +            cell_nr++;
82 +            cell =  &(state->pgc->cell_playback[cell_nr-1]);
83 +            target = cell->first_sector;
84 +          } else {
85 +            target = vobu;
86 +          }
87 +        }
88 +      }
89        found = 1;
90        break;
91      }
92 @@ -281,7 +311,7 @@
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);
95  #endif
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;
99  
100        if (vm_jump_cell_block(this->vm, cell_nr, vobu - start)) {