changeset 122:29b046894eac src

use the new VM copy mechanism to try-run program skipping and report failure in case we end with a stopped VM
author mroi
date Wed, 12 Mar 2003 11:39:49 +0000
parents 545bd4fc0a16
children da88fc974592
files searching.c
diffstat 1 files changed, 18 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/searching.c	Wed Mar 12 11:38:51 2003 +0000
+++ b/searching.c	Wed Mar 12 11:39:49 2003 +0000
@@ -298,6 +298,7 @@
 }
 
 dvdnav_status_t dvdnav_next_pg_search(dvdnav_t *this) {
+  vm_t *try_vm;
 
   if(!this) {
     printerr("Passed a NULL pointer.");
@@ -314,12 +315,24 @@
 #ifdef LOG_DEBUG
   fprintf(MSG_OUT, "libdvdnav: next chapter\n");
 #endif
-  if (!vm_jump_next_pg(this->vm)) {
-    fprintf(MSG_OUT, "libdvdnav: next chapter failed.\n");
-    printerr("Skip to next chapter failed.");
-    pthread_mutex_unlock(&this->vm_lock);
-    return S_ERR;
+  /* make a copy of current VM and try to navigate the copy to the next PG */
+  try_vm = vm_new_copy(this->vm);
+  if (!vm_jump_next_pg(try_vm) || try_vm->stopped) {
+    vm_free_copy(try_vm);
+    /* next_pg failed, try to jump at least to the next cell */
+    try_vm = vm_new_copy(this->vm);
+    vm_get_next_cell(try_vm);
+    if (try_vm->stopped) {
+      vm_free_copy(try_vm);
+      fprintf(MSG_OUT, "libdvdnav: next chapter failed.\n");
+      printerr("Skip to next chapter failed.");
+      pthread_mutex_unlock(&this->vm_lock);
+      return S_ERR;
+    }
   }
+  /* merge changes on success */
+  vm_merge(this->vm, try_vm);
+  vm_free_copy(try_vm);
   this->position_current.still = 0;
   this->vm->hop_channel++;
 #ifdef LOG_DEBUG