Mercurial > libdvdnav.hg
comparison searching.c @ 133:d09a81cf65ce src
determine correct PG and PTT numbers when seeking across PG boundaries
author | mroi |
---|---|
date | Mon, 24 Mar 2003 16:42:59 +0000 |
parents | f22458f928b8 |
children | 5897ff629f7c |
comparison
equal
deleted
inserted
replaced
132:f22458f928b8 | 133:d09a81cf65ce |
---|---|
75 int32_t address = 0; | 75 int32_t address = 0; |
76 int32_t vobu_start, next_vobu; | 76 int32_t vobu_start, next_vobu; |
77 int found = 0; | 77 int found = 0; |
78 | 78 |
79 /* Search through ADMAP for best sector */ | 79 /* Search through ADMAP for best sector */ |
80 vobu_start = 0x3fffffff; | 80 vobu_start = SRI_END_OF_CELL; |
81 /* FIXME: Implement a faster search algorithm */ | 81 /* FIXME: Implement a faster search algorithm */ |
82 while((!found) && ((address<<2) < admap->last_byte)) { | 82 while((!found) && ((address<<2) < admap->last_byte)) { |
83 next_vobu = admap->vobu_start_sectors[address]; | 83 next_vobu = admap->vobu_start_sectors[address]; |
84 | 84 |
85 /* fprintf(MSG_OUT, "libdvdnav: Found block %u\n", next_vobu); */ | 85 /* fprintf(MSG_OUT, "libdvdnav: Found block %u\n", next_vobu); */ |
118 printerr("Cannot seek in a still frame."); | 118 printerr("Cannot seek in a still frame."); |
119 return S_ERR; | 119 return S_ERR; |
120 } | 120 } |
121 | 121 |
122 result = dvdnav_get_position(this, &target, &length); | 122 result = dvdnav_get_position(this, &target, &length); |
123 if(!result) { | |
124 return S_ERR; | |
125 } | |
126 | |
127 pthread_mutex_lock(&this->vm_lock); | |
128 state = &(this->vm->state); | |
129 if(!state->pgc) { | |
130 printerr("No current PGC."); | |
131 pthread_mutex_unlock(&this->vm_lock); | |
132 return S_ERR; | |
133 } | |
123 #ifdef LOG_DEBUG | 134 #ifdef LOG_DEBUG |
124 fprintf(MSG_OUT, "libdvdnav: seeking to offset=%lu pos=%u length=%u\n", offset, target, length); | 135 fprintf(MSG_OUT, "libdvdnav: seeking to offset=%lu pos=%u length=%u\n", offset, target, length); |
125 fprintf(MSG_OUT, "libdvdnav: Before cellN=%u blockN=%u\n", state->cellN, state->blockN); | 136 fprintf(MSG_OUT, "libdvdnav: Before cellN=%u blockN=%u\n", state->cellN, state->blockN); |
126 #endif | 137 #endif |
127 if(!result) { | |
128 return S_ERR; | |
129 } | |
130 | |
131 pthread_mutex_lock(&this->vm_lock); | |
132 state = &(this->vm->state); | |
133 if(!state->pgc) { | |
134 printerr("No current PGC."); | |
135 pthread_mutex_unlock(&this->vm_lock); | |
136 return S_ERR; | |
137 } | |
138 | 138 |
139 switch(origin) { | 139 switch(origin) { |
140 case SEEK_SET: | 140 case SEEK_SET: |
141 if(offset > length) { | 141 if(offset > length) { |
142 printerr("Request to seek behind end."); | 142 printerr("Request to seek behind end."); |
165 /* Error occured */ | 165 /* Error occured */ |
166 printerr("Illegal seek mode."); | 166 printerr("Illegal seek mode."); |
167 pthread_mutex_unlock(&this->vm_lock); | 167 pthread_mutex_unlock(&this->vm_lock); |
168 return S_ERR; | 168 return S_ERR; |
169 } | 169 } |
170 | 170 |
171 if (this->pgc_based) { | 171 if (this->pgc_based) { |
172 first_cell_nr = 1; | 172 first_cell_nr = 1; |
173 last_cell_nr = state->pgc->nr_of_cells; | 173 last_cell_nr = state->pgc->nr_of_cells; |
174 } else { | 174 } else { |
175 /* Find start cell of program. */ | 175 /* Find start cell of program. */ |
194 break; | 194 break; |
195 } | 195 } |
196 } | 196 } |
197 | 197 |
198 if(found) { | 198 if(found) { |
199 int32_t vobu, start; | 199 int32_t vobu; |
200 #ifdef LOG_DEBUG | 200 #ifdef LOG_DEBUG |
201 fprintf(MSG_OUT, "libdvdnav: Seeking to cell %i from choice of %i to %i\n", | 201 fprintf(MSG_OUT, "libdvdnav: Seeking to cell %i from choice of %i to %i\n", |
202 cell_nr, first_cell_nr, last_cell_nr); | 202 cell_nr, first_cell_nr, last_cell_nr); |
203 #endif | 203 #endif |
204 dvdnav_scan_admap(this, state->domain, target, &vobu); | 204 if (dvdnav_scan_admap(this, state->domain, target, &vobu) == S_OK) { |
205 | 205 int32_t start = state->pgc->cell_playback[cell_nr-1].first_sector; |
206 start = state->pgc->cell_playback[cell_nr-1].first_sector; | 206 |
207 state->blockN = vobu - start; | 207 if (vm_jump_cell_block(this->vm, cell_nr, vobu - start)) { |
208 state->cellN = cell_nr; | 208 #ifdef LOG_DEBUG |
209 state->cell_restart++; | 209 fprintf(MSG_OUT, "libdvdnav: After cellN=%u blockN=%u target=%x vobu=%x start=%x\n" , |
210 #ifdef LOG_DEBUG | 210 state->cellN, state->blockN, target, vobu, start); |
211 fprintf(MSG_OUT, "libdvdnav: After cellN=%u blockN=%u target=%x vobu=%x start=%x\n" , | 211 #endif |
212 state->cellN, | 212 this->vm->hop_channel += HOP_SEEK; |
213 state->blockN, | 213 pthread_mutex_unlock(&this->vm_lock); |
214 target, | 214 return S_OK; |
215 vobu, | 215 } |
216 start); | 216 } |
217 #endif | 217 } |
218 this->vm->hop_channel += HOP_SEEK; | 218 |
219 pthread_mutex_unlock(&this->vm_lock); | 219 fprintf(MSG_OUT, "libdvdnav: Error when seeking\n"); |
220 return S_OK; | |
221 } | |
222 | |
223 fprintf(MSG_OUT, "libdvdnav: Error when seeking, asked to seek outside program\n"); | |
224 fprintf(MSG_OUT, "libdvdnav: FIXME: Implement seeking to location %u\n", target); | 220 fprintf(MSG_OUT, "libdvdnav: FIXME: Implement seeking to location %u\n", target); |
225 printerr("Error when seeking."); | 221 printerr("Error when seeking."); |
226 pthread_mutex_unlock(&this->vm_lock); | 222 pthread_mutex_unlock(&this->vm_lock); |
227 return S_ERR; | 223 return S_ERR; |
228 } | 224 } |