changeset 113:ec2df154be56 src

slightly improved logic of program skipping: previous program: -> if PG > 1, jump to PG - 1 -> otherwise, if prev_PGC is set, jump to last PG of prev_PGC -> otherwise fail next program: -> if PG < last_PG, jump to PG + 1 -> otherwise, if next_PGC is set, jump to first PG of next_PGC -> otherwise, move to last Cell of current PG and ask the VM for the next Cell
author mroi
date Mon, 13 Jan 2003 13:33:45 +0000
parents 50ee8763a312
children b6834e6359cf
files searching.c vm.c
diffstat 2 files changed, 43 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/searching.c	Mon Jan 06 19:59:28 2003 +0000
+++ b/searching.c	Mon Jan 13 13:33:45 2003 +0000
@@ -238,14 +238,12 @@
     return S_ERR;
 
   pthread_mutex_lock(&this->vm_lock);
-  /* Make sure this is not the first chapter */
-  if(state->pgN <= 1 ) {
-    fprintf(MSG_OUT, "libdvdnav: at first chapter. prev chapter failed.\n");
+  fprintf(MSG_OUT, "libdvdnav: previous chapter\n");
+  if (!vm_prev_pg(this->vm)) {
+    fprintf(MSG_OUT, "libdvdnav: prev chapter failed.\n");
     pthread_mutex_unlock(&this->vm_lock);
     return S_ERR;
   }
-  fprintf(MSG_OUT, "libdvdnav: previous chapter\n");
-  vm_jump_prog(this->vm, state->pgN - 1);
   this->position_current.still = 0;
   this->vm->hop_channel++;
   fprintf(MSG_OUT, "libdvdnav: previous chapter done\n");
@@ -275,14 +273,11 @@
     return S_ERR;
 
   pthread_mutex_lock(&this->vm_lock);
-  /* Make sure this is not the last chapter */
-  if(state->pgN >= state->pgc->nr_of_programs) {
-    fprintf(MSG_OUT, "libdvdnav: at last chapter. jumping to end of last cell.\n");
-    this->vm->state.cellN = this->vm->state.pgc->nr_of_cells;
-    vm_get_next_cell(this->vm);
-  } else {
-    fprintf(MSG_OUT, "libdvdnav: next chapter\n");
-    vm_jump_prog(this->vm, state->pgN + 1);
+  fprintf(MSG_OUT, "libdvdnav: next chapter\n");
+  if (!vm_next_pg(this->vm)) {
+    fprintf(MSG_OUT, "libdvdnav: next chapter failed.\n");
+    pthread_mutex_unlock(&this->vm_lock);
+    return S_ERR;
   }
   this->position_current.still = 0;
   this->vm->hop_channel++;
--- a/vm.c	Mon Jan 06 19:59:28 2003 +0000
+++ b/vm.c	Mon Jan 13 13:33:45 2003 +0000
@@ -513,21 +513,35 @@
 
 int vm_next_pg(vm_t *vm)
 {
-  /*  Do we need to get a updated pgN value first? */
-  (vm->state).pgN += 1; 
-  return vm_top_pg(vm);
+  if((vm->state).pgN >= (vm->state).pgc->nr_of_programs) {
+    /* last program -> move to first program of next PGC */
+    if ((vm->state).pgc->next_pgc_nr != 0 && set_PGC(vm, (vm->state).pgc->next_pgc_nr) == 0) {
+      vm_jump_prog(vm, 1);
+      return 1;
+    }
+    /* something failed, try to move to the cell after the last */
+    (vm->state).cellN = (vm->state).pgc->nr_of_cells;
+    vm_get_next_cell(vm);
+    return 1;
+  } else {
+    vm_jump_prog(vm, (vm->state).pgN + 1);
+    return 1;
+  }
 }
 
 int vm_prev_pg(vm_t *vm)
 {
-  /*  Do we need to get a updated pgN value first? */
-  (vm->state).pgN -= 1;
-  if((vm->state).pgN == 0) {
-    /*  Check for previous PGCN ?  */
-    (vm->state).pgN = 1;
-    /*  return 0; */
+  if ((vm->state).pgN <= 1) {
+    /* first program -> move to last program of previous PGC */
+    if ((vm->state).pgc->prev_pgc_nr != 0 && set_PGC(vm, (vm->state).pgc->prev_pgc_nr) == 0) {
+      vm_jump_prog(vm, (vm->state).pgc->nr_of_programs);
+      return 1;
+    }
+    return 0;
+  } else {
+    vm_jump_prog(vm, (vm->state).pgN - 1);
+    return 1;
   }
-  return vm_top_pg(vm);
 }
 
 /* Get the current title and part from the current playing position. */
@@ -2031,6 +2045,17 @@
 
 /*
  * $Log$
+ * Revision 1.42  2003/01/13 13:33:45  mroi
+ * slightly improved logic of program skipping:
+ * previous program:
+ * -> if PG > 1, jump to PG - 1
+ * -> otherwise, if prev_PGC is set, jump to last PG of prev_PGC
+ * -> otherwise fail
+ * next program:
+ * -> if PG < last_PG, jump to PG + 1
+ * -> otherwise, if next_PGC is set, jump to first PG of next_PGC
+ * -> otherwise, move to last Cell of current PG and ask the VM for the next Cell
+ *
  * Revision 1.41  2003/01/06 19:59:28  mroi
  * implement LinkNoLink
  * (in this whole lot of DVDs I watched with libdvdnav, Disney's