changeset 256:6299ccea8a38 src

killing a lot of asserts and turning them into forced executions of Exit, moving the VM into the STOP domain; also use this condition to report failures right on VM start as problems with the disc (patch heavily inspired by Bastien)
author mroi
date Wed, 15 Dec 2004 21:16:58 +0000
parents 3e5192f8113f
children 0340d2236219
files dvdnav.c vm/vm.c vm/vm.h
diffstat 3 files changed, 48 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/dvdnav.c	Sat Nov 20 21:10:25 2004 +0000
+++ b/dvdnav.c	Wed Dec 15 21:16:58 2004 +0000
@@ -403,7 +403,10 @@
   
   if(!this->started) {
     /* Start the VM */
-    vm_start(this->vm);
+    if (!vm_start(this->vm)) {
+      printerr("Encrypted or faulty DVD");
+      return DVDNAV_STATUS_ERR;
+    }
     this->started = 1;
   }
 
--- a/vm/vm.c	Sat Nov 20 21:10:25 2004 +0000
+++ b/vm/vm.c	Wed Dec 15 21:16:58 2004 +0000
@@ -184,9 +184,9 @@
   }
 }
 
-static void ifoOpenNewVTSI(vm_t *vm, dvd_reader_t *dvd, int vtsN) {
+static int ifoOpenNewVTSI(vm_t *vm, dvd_reader_t *dvd, int vtsN) {
   if((vm->state).vtsN == vtsN) {
-    return; /*  We alread have it */
+    return 1; /*  We alread have it */
   }
   
   if(vm->vtsi != NULL)
@@ -194,30 +194,32 @@
   
   vm->vtsi = ifoOpenVTSI(dvd, vtsN);
   if(vm->vtsi == NULL) {
-    fprintf(MSG_OUT, "libdvdnav: ifoOpenVTSI failed - CRASHING!!!\n");
-    assert(0);
+    fprintf(MSG_OUT, "libdvdnav: ifoOpenVTSI failed\n");
+    return 0;
   }
   if(!ifoRead_VTS_PTT_SRPT(vm->vtsi)) {
-    fprintf(MSG_OUT, "libdvdnav: ifoRead_VTS_PTT_SRPT failed - CRASHING!!!\n");
-    assert(0);
+    fprintf(MSG_OUT, "libdvdnav: ifoRead_VTS_PTT_SRPT failed\n");
+    return 0;
   }
   if(!ifoRead_PGCIT(vm->vtsi)) {
-    fprintf(MSG_OUT, "libdvdnav: ifoRead_PGCIT failed - CRASHING!!!\n");
-    assert(0);
+    fprintf(MSG_OUT, "libdvdnav: ifoRead_PGCIT failed\n");
+    return 0;
   }
   if(!ifoRead_PGCI_UT(vm->vtsi)) {
-    fprintf(MSG_OUT, "libdvdnav: ifoRead_PGCI_UT failed - CRASHING!!!\n");
-    assert(0);
+    fprintf(MSG_OUT, "libdvdnav: ifoRead_PGCI_UT failed\n");
+    return 0;
   }
   if(!ifoRead_VOBU_ADMAP(vm->vtsi)) {
-    fprintf(MSG_OUT, "libdvdnav: ifoRead_VOBU_ADMAP vtsi failed - CRASHING\n");
-    assert(0);
+    fprintf(MSG_OUT, "libdvdnav: ifoRead_VOBU_ADMAP vtsi failed\n");
+    return 0;
   }
   if(!ifoRead_TITLE_VOBU_ADMAP(vm->vtsi)) {
-    fprintf(MSG_OUT, "libdvdnav: ifoRead_TITLE_VOBU_ADMAP vtsi failed - CRASHING\n");
-    assert(0);
+    fprintf(MSG_OUT, "libdvdnav: ifoRead_TITLE_VOBU_ADMAP vtsi failed\n");
+    return 0;
   }
   (vm->state).vtsN = vtsN;
+  
+  return 1;
 }
 
 
@@ -253,10 +255,11 @@
 
 /* Basic Handling */
 
-void vm_start(vm_t *vm) {
+int vm_start(vm_t *vm) {
   /* Set pgc to FP (First Play) pgc */
   set_FP_PGC(vm);
   process_command(vm, play_PGC(vm));
+  return !vm->stopped;
 }
 
 void vm_stop(vm_t *vm) {
@@ -382,7 +385,8 @@
   vtsN = (target->state).vtsN;
   if (vtsN > 0) {
     (target->state).vtsN = 0;
-    ifoOpenNewVTSI(target, target->dvd, vtsN);
+    if (!ifoOpenNewVTSI(target, target->dvd, vtsN))
+      assert(0);
   
     /* restore pgc pointer into the new vtsi */
     if (!set_PGCN(target, pgcN))
@@ -1280,9 +1284,10 @@
       if(link_values.data1 != 0)
 	(vm->state).HL_BTNN_REG = link_values.data1 << 10;
       assert((vm->state).pgc->next_pgc_nr != 0);
-      if(!set_PGCN(vm, (vm->state).pgc->next_pgc_nr))
-	assert(0);
-      link_values = play_PGC(vm);
+      if(set_PGCN(vm, (vm->state).pgc->next_pgc_nr))
+	link_values = play_PGC(vm);
+      else
+	link_values.command = Exit;
       break;
     case LinkPrevPGC:
       /* Link to Previous Program Chain */
@@ -1290,9 +1295,10 @@
       if(link_values.data1 != 0)
 	(vm->state).HL_BTNN_REG = link_values.data1 << 10;
       assert((vm->state).pgc->prev_pgc_nr != 0);
-      if(!set_PGCN(vm, (vm->state).pgc->prev_pgc_nr))
-	assert(0);
-      link_values = play_PGC(vm);
+      if(set_PGCN(vm, (vm->state).pgc->prev_pgc_nr))
+	link_values = play_PGC(vm);
+      else
+	link_values.command = Exit;
       break;
     case LinkGoUpPGC:
       /* Link to GoUp Program Chain */
@@ -1300,9 +1306,10 @@
       if(link_values.data1 != 0)
 	(vm->state).HL_BTNN_REG = link_values.data1 << 10;
       assert((vm->state).pgc->goup_pgc_nr != 0);
-      if(!set_PGCN(vm, (vm->state).pgc->goup_pgc_nr))
-	assert(0);
-      link_values = play_PGC(vm);
+      if(set_PGCN(vm, (vm->state).pgc->goup_pgc_nr))
+	link_values = play_PGC(vm);
+      else
+	link_values.command = Exit;
       break;
     case LinkTailPGC:
       /* Link to Tail of Program Chain */
@@ -1325,7 +1332,8 @@
 	}
 	
 	(vm->state).domain = VTS_DOMAIN;
-	ifoOpenNewVTSI(vm, vm->dvd, (vm->state).rsm_vtsN);
+	if (!ifoOpenNewVTSI(vm, vm->dvd, (vm->state).rsm_vtsN))
+	  assert(0);
 	set_PGCN(vm, (vm->state).rsm_pgcN);
 	
 	/* These should never be set in SystemSpace and/or MenuSpace */ 
@@ -1404,9 +1412,10 @@
       /* Stop SPRM9 Timer */
       /* Set SPRM1 and SPRM2 */
       assert((vm->state).domain == VMGM_DOMAIN || (vm->state).domain == FP_DOMAIN); /* ?? */
-      if(!set_TT(vm, link_values.data1))
-	assert(0);
-      link_values = play_PGC(vm);
+      if(set_TT(vm, link_values.data1))
+        link_values = play_PGC(vm);
+      else
+	link_values.command = Exit;
       break;
     case JumpVTS_TT:
       /* Jump to Title:data1 in same VTS Title Domain */
@@ -1463,7 +1472,8 @@
 	  /* the normal case */
 	  assert((vm->state).domain == VMGM_DOMAIN || (vm->state).domain == FP_DOMAIN); /* ?? */
 	  (vm->state).domain = VTSM_DOMAIN;
-	  ifoOpenNewVTSI(vm, vm->dvd, link_values.data1);  /* Also sets (vm->state).vtsN */
+	  if (!ifoOpenNewVTSI(vm, vm->dvd, link_values.data1))  /* Also sets (vm->state).vtsN */
+	    assert(0);
 	} else {
 	  /* This happens on some discs like "Captain Scarlet & the Mysterons" or
 	   * the German RC2 of "Anatomie" in VTSM. */
@@ -1576,8 +1586,9 @@
   
   (vm->state).domain = VTS_DOMAIN;
 
-  if(vtsN != (vm->state).vtsN)
-    ifoOpenNewVTSI(vm, vm->dvd, vtsN);  /* Also sets (vm->state).vtsN */
+  if (vtsN != (vm->state).vtsN)
+    if (!ifoOpenNewVTSI(vm, vm->dvd, vtsN))  /* Also sets (vm->state).vtsN */
+      return 0;
   
   if ((vts_ttn < 1) || (vts_ttn > vm->vtsi->vts_ptt_srpt->nr_of_srpts) ||
       (part < 1) || (part > vm->vtsi->vts_ptt_srpt->title[vts_ttn - 1].nr_of_ptts) ) {
--- a/vm/vm.h	Sat Nov 20 21:10:25 2004 +0000
+++ b/vm/vm.h	Wed Dec 15 21:16:58 2004 +0000
@@ -127,7 +127,7 @@
 dvd_reader_t *vm_get_dvd_reader(vm_t *vm);
 
 /* Basic Handling */
-void vm_start(vm_t *vm);
+int  vm_start(vm_t *vm);
 void vm_stop(vm_t *vm);
 int  vm_reset(vm_t *vm, const char *dvdroot);