comparison searching.c @ 130:f47065513ad8 src

do not assume PGs to be physically layed out in sequence on the disc
author mroi
date Thu, 20 Mar 2003 12:22:59 +0000
parents b48f53f7cff2
children ada79e606d8d
comparison
equal deleted inserted replaced
129:b48f53f7cff2 130:f47065513ad8
175 } else { 175 } else {
176 last_cell_nr = state->pgc->nr_of_cells; 176 last_cell_nr = state->pgc->nr_of_cells;
177 } 177 }
178 178
179 found = 0; 179 found = 0;
180 target += state->pgc->cell_playback[first_cell_nr-1].first_sector;
181 for(cell_nr = first_cell_nr; (cell_nr <= last_cell_nr) && !found; cell_nr ++) { 180 for(cell_nr = first_cell_nr; (cell_nr <= last_cell_nr) && !found; cell_nr ++) {
182 cell = &(state->pgc->cell_playback[cell_nr-1]); 181 cell = &(state->pgc->cell_playback[cell_nr-1]);
183 if((cell->first_sector <= target) && (cell->last_sector >= target)) { 182 length = cell->last_sector - cell->first_sector + 1;
183 if (target >= length) {
184 target -= length;
185 } else {
186 /* convert the target sector from PG-relative to absolute physical sector */
187 target += cell->first_sector;
184 found = 1; 188 found = 1;
185 state->cellN = cell_nr; 189 break;
186 state->blockN = 0;
187 state->cell_restart++;
188 } 190 }
189 } 191 }
190 192
191 if(found) { 193 if(found) {
192 int32_t vobu, start; 194 int32_t vobu, start;
193 #ifdef LOG_DEBUG 195 #ifdef LOG_DEBUG
194 fprintf(MSG_OUT, "libdvdnav: Seeking to cell %i from choice of %i to %i\n", 196 fprintf(MSG_OUT, "libdvdnav: Seeking to cell %i from choice of %i to %i\n",
195 state->cellN, first_cell_nr, last_cell_nr); 197 cell_nr, first_cell_nr, last_cell_nr);
196 #endif 198 #endif
197 dvdnav_scan_admap(this, state->domain, target, &vobu); 199 dvdnav_scan_admap(this, state->domain, target, &vobu);
198 start = state->pgc->cell_playback[state->cellN - 1].first_sector; 200
201 start = state->pgc->cell_playback[cell_nr-1].first_sector;
202 state->blockN = vobu - start;
203 state->cellN = cell_nr;
204 state->cell_restart++;
199 #ifdef LOG_DEBUG 205 #ifdef LOG_DEBUG
200 fprintf(MSG_OUT, "libdvdnav: After cellN=%u blockN=%u target=%x vobu=%x start=%x\n" , 206 fprintf(MSG_OUT, "libdvdnav: After cellN=%u blockN=%u target=%x vobu=%x start=%x\n" ,
201 state->cellN, 207 state->cellN,
202 state->blockN, 208 state->blockN,
203 target, 209 target,
204 vobu, 210 vobu,
205 start); 211 start);
206 #endif
207 state->blockN = vobu - start;
208 #ifdef LOG_DEBUG
209 fprintf(MSG_OUT, "libdvdnav: After vobu=%x start=%x blockN=%x\n" ,
210 vobu,
211 start,
212 state->blockN);
213 #endif 212 #endif
214 this->vm->hop_channel += HOP_SEEK; 213 this->vm->hop_channel += HOP_SEEK;
215 pthread_mutex_unlock(&this->vm_lock); 214 pthread_mutex_unlock(&this->vm_lock);
216 return S_OK; 215 return S_OK;
217 } 216 }
377 } 376 }
378 377
379 dvdnav_status_t dvdnav_get_position(dvdnav_t *this, unsigned int *pos, 378 dvdnav_status_t dvdnav_get_position(dvdnav_t *this, unsigned int *pos,
380 unsigned int *len) { 379 unsigned int *len) {
381 uint32_t cur_sector; 380 uint32_t cur_sector;
381 uint32_t cell_nr;
382 uint32_t first_cell_nr; 382 uint32_t first_cell_nr;
383 uint32_t last_cell_nr; 383 uint32_t last_cell_nr;
384 cell_playback_t *cell;
384 cell_playback_t *first_cell; 385 cell_playback_t *first_cell;
385 cell_playback_t *last_cell; 386 cell_playback_t *last_cell;
386 dvd_state_t *state; 387 dvd_state_t *state;
387 388
388 if(!this || !pos || !len) { 389 if(!this || !pos || !len) {
414 last_cell_nr = state->pgc->program_map[state->pgN] - 1; 415 last_cell_nr = state->pgc->program_map[state->pgN] - 1;
415 } else { 416 } else {
416 last_cell_nr = state->pgc->nr_of_cells; 417 last_cell_nr = state->pgc->nr_of_cells;
417 } 418 }
418 last_cell = &(state->pgc->cell_playback[last_cell_nr-1]); 419 last_cell = &(state->pgc->cell_playback[last_cell_nr-1]);
419 420
420 *pos= cur_sector - first_cell->first_sector; 421 *pos = -1;
421 *len= last_cell->last_sector - first_cell->first_sector; 422 *len = 0;
423 for (cell_nr = first_cell_nr; cell_nr <= last_cell_nr; cell_nr++) {
424 cell = &(state->pgc->cell_playback[cell_nr-1]);
425 if (cell_nr == state->cellN) {
426 /* the current sector is in this cell,
427 * pos is length of PG up to here + sector's offset in this cell */
428 *pos = *len + cur_sector - cell->first_sector;
429 }
430 *len += cell->last_sector - cell->first_sector + 1;
431 }
432
433 assert(*pos != -1);
434
422 pthread_mutex_unlock(&this->vm_lock); 435 pthread_mutex_unlock(&this->vm_lock);
423 436
424 return S_OK; 437 return S_OK;
425 } 438 }
426 439