diff 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
line wrap: on
line diff
--- a/searching.c	Sun Mar 23 15:24:31 2003 +0000
+++ b/searching.c	Mon Mar 24 16:42:59 2003 +0000
@@ -77,7 +77,7 @@
     int found = 0;
 
     /* Search through ADMAP for best sector */
-    vobu_start = 0x3fffffff;
+    vobu_start = SRI_END_OF_CELL;
     /* FIXME: Implement a faster search algorithm */
     while((!found) && ((address<<2) < admap->last_byte)) {
       next_vobu = admap->vobu_start_sectors[address];
@@ -120,10 +120,6 @@
   }
   
   result = dvdnav_get_position(this, &target, &length);
-#ifdef LOG_DEBUG
-  fprintf(MSG_OUT, "libdvdnav: seeking to offset=%lu pos=%u length=%u\n", offset, target, length); 
-  fprintf(MSG_OUT, "libdvdnav: Before cellN=%u blockN=%u\n", state->cellN, state->blockN);
-#endif
   if(!result) {
     return S_ERR;
   }
@@ -135,6 +131,10 @@
     pthread_mutex_unlock(&this->vm_lock);
     return S_ERR;
   }
+#ifdef LOG_DEBUG
+  fprintf(MSG_OUT, "libdvdnav: seeking to offset=%lu pos=%u length=%u\n", offset, target, length); 
+  fprintf(MSG_OUT, "libdvdnav: Before cellN=%u blockN=%u\n", state->cellN, state->blockN);
+#endif
 
   switch(origin) {
    case SEEK_SET:
@@ -167,7 +167,7 @@
     pthread_mutex_unlock(&this->vm_lock);
     return S_ERR;
   }
-
+  
   if (this->pgc_based) {
     first_cell_nr = 1;
     last_cell_nr = state->pgc->nr_of_cells;
@@ -196,31 +196,27 @@
   }
 
   if(found) {
-    int32_t vobu, start;
+    int32_t vobu;
 #ifdef LOG_DEBUG
     fprintf(MSG_OUT, "libdvdnav: Seeking to cell %i from choice of %i to %i\n",
 	    cell_nr, first_cell_nr, last_cell_nr);
 #endif
-    dvdnav_scan_admap(this, state->domain, target, &vobu);
-
-    start         = state->pgc->cell_playback[cell_nr-1].first_sector;
-    state->blockN = vobu - start;
-    state->cellN  = cell_nr;
-    state->cell_restart++;
+    if (dvdnav_scan_admap(this, state->domain, target, &vobu) == S_OK) {
+      int32_t start = state->pgc->cell_playback[cell_nr-1].first_sector;
+      
+      if (vm_jump_cell_block(this->vm, cell_nr, vobu - start)) {
 #ifdef LOG_DEBUG
-    fprintf(MSG_OUT, "libdvdnav: After cellN=%u blockN=%u target=%x vobu=%x start=%x\n" ,
-      state->cellN,
-      state->blockN,
-      target,
-      vobu,
-      start);
+        fprintf(MSG_OUT, "libdvdnav: After cellN=%u blockN=%u target=%x vobu=%x start=%x\n" ,
+          state->cellN, state->blockN, target, vobu, start);
 #endif
-    this->vm->hop_channel += HOP_SEEK;
-    pthread_mutex_unlock(&this->vm_lock);
-    return S_OK;
+        this->vm->hop_channel += HOP_SEEK;
+        pthread_mutex_unlock(&this->vm_lock);
+        return S_OK;
+      }
+    }
   }
   
-  fprintf(MSG_OUT, "libdvdnav: Error when seeking, asked to seek outside program\n");
+  fprintf(MSG_OUT, "libdvdnav: Error when seeking\n");
   fprintf(MSG_OUT, "libdvdnav: FIXME: Implement seeking to location %u\n", target); 
   printerr("Error when seeking.");
   pthread_mutex_unlock(&this->vm_lock);