changeset 4:99bed5d6db2f src

Added reset patch from Kees Cook <kees@outflux.net>
author richwareham
date Tue, 02 Apr 2002 18:22:27 +0000
parents 328eadb3f37e
children c1b55dc1bfed
files dvdnav.c dvdnav.h vm.c
diffstat 3 files changed, 135 insertions(+), 56 deletions(-) [+]
line wrap: on
line diff
--- a/dvdnav.c	Mon Apr 01 18:56:28 2002 +0000
+++ b/dvdnav.c	Tue Apr 02 18:22:27 2002 +0000
@@ -35,6 +35,53 @@
 #include <stdlib.h>
 #include <stdio.h>
 
+dvdnav_status_t dvdnav_clear(dvdnav_t * self) {
+  if (!self) {
+    printerr("Passed a NULL pointer");
+    return S_ERR;
+  }
+  /* clear everything except path, file, vm, mutex, readahead */
+
+  // path
+  if (self->file) DVDCloseFile(self->file);
+  self->file = NULL;
+  self->open_vtsN = -1;
+  self->open_domain = -1;
+  self->vobu_start=0;
+  self->vobu_length=0;
+  self->blockN=0;
+  self->next_vobu=0;
+  self->cell = NULL;
+  self->jmp_blockN=0;
+  self->jmp_vobu_start=0;
+  self->seekto_block=0;
+
+  memset(&self->pci,0,sizeof(self->pci));
+  memset(&self->dsi,0,sizeof(self->dsi));
+
+  /* Set initial values of flags */
+  self->expecting_nav_packet = 1;
+  self->at_soc = 1;
+  self->still_frame = -1;
+  self->jumping = 0;
+  self->seeking = 0;
+  self->stop = 0;
+  self->highlight_changed = 0;
+  self->spu_clut_changed = 0;
+  self->spu_stream_changed = 0;
+  self->audio_stream_changed = 0;
+  self->started=0;
+  // self->use_read_ahead
+
+  self->hli_state=0;
+
+  self->cache_start_sector = -1;
+  self->cache_block_count = 0;
+  self->cache_valid = 0;
+
+  return S_OK;
+}
+
 dvdnav_status_t dvdnav_open(dvdnav_t** dest, char *path) {
   dvdnav_t *self;
   
@@ -63,28 +110,7 @@
   /* Set the path. FIXME: Is a deep copy 'right' */
   strncpy(self->path, path, MAX_PATH_LEN);
 
-  /* Set initial values of flags */
-  self->expecting_nav_packet = 1;
-  self->started = 0;
-  
-  self->open_vtsN = -1;
-  self->open_domain = -1;
-  self->file = NULL;
-  self->cell = NULL;
-  self->at_soc = 1;
-  self->jumping = 0;
-  self->seeking = 0;
-  self->still_frame = -1;
-  self->cache_buffer = NULL;
-  self->cache_start_sector = -1;
-  self->cache_block_count = 0;
-  self->cache_valid = 0;
-  self->use_read_ahead = 1;
-  self->stop = 0;
-  self->highlight_changed = 0;
-  self->spu_clut_changed = 0;
-
-  self->vobu_start = self->vobu_length = 0;
+  dvdnav_clear(self);
  
   /* Pre-open and close a file so that the CSS-keys are cached. */
   self->file = DVDOpenFile(vm_get_dvd_reader(self->vm), 0, DVD_READ_MENU_VOBS);
@@ -129,6 +155,35 @@
   return S_OK;
 }
 
+dvdnav_status_t dvdnav_reset(dvdnav_t *self) {
+  dvdnav_status_t result;
+
+  printf("dvdnav:reset:called\n");
+  if(!self) {
+    printerr("Passed a NULL pointer");
+    return S_ERR;
+  }
+  printf("getting lock\n");
+  pthread_mutex_lock(&self->vm_lock); 
+  printf("reseting vm\n");
+  if(vm_reset(self->vm, NULL) == -1) {
+    printerr("Error restarting the VM");
+    pthread_mutex_unlock(&self->vm_lock); 
+    return S_ERR;
+  }
+  printf("clearing dvdnav\n");
+  result=dvdnav_clear(self);
+  printf("starting vm\n");
+  if(!self->started) {
+    /* Start the VM */
+    vm_start(self->vm);
+    self->started = 1;
+  }
+  printf("unlocking\n");
+  pthread_mutex_unlock(&self->vm_lock); 
+  return result;
+}
+
 dvdnav_status_t dvdnav_path(dvdnav_t *self, char** path) {
   if(!self || !path || !(*path)) {
     return S_ERR;
@@ -931,6 +986,9 @@
 
 /*
  * $Log$
+ * Revision 1.3  2002/04/02 18:22:27  richwareham
+ * Added reset patch from Kees Cook <kees@outflux.net>
+ *
  * Revision 1.2  2002/04/01 18:56:28  richwareham
  * Added initial example programs directory and make sure all debug/error output goes to stderr.
  *
--- a/dvdnav.h	Mon Apr 01 18:56:28 2002 +0000
+++ b/dvdnav.h	Tue Apr 02 18:22:27 2002 +0000
@@ -69,6 +69,14 @@
 dvdnav_status_t dvdnav_close(dvdnav_t *self);
 
 /**
+ * Resets the VM and buffers in a previously opened dvdnav
+ *
+ * Arguments:
+ *   self     -- dvdnav_t to reset.
+ */
+dvdnav_status_t dvdnav_reset(dvdnav_t *self);
+
+/**
  * Fills a pointer wiht a value pointing to a string describing
  * the path associated with an open dvdnav_t. It assigns it NULL
  * on error.
--- a/vm.c	Mon Apr 01 18:56:28 2002 +0000
+++ b/vm.c	Tue Apr 02 18:22:27 2002 +0000
@@ -115,14 +115,17 @@
 
   if(self->vmgi) {
     ifoClose(self->vmgi);
+    self->vmgi=NULL;
   }
 
   if(self->vtsi) {
     ifoClose(self->vtsi);
+    self->vmgi=NULL;
   }
   
   if(self->dvd) {
     DVDClose(self->dvd);
+    self->dvd=NULL;
   }
 }
 
@@ -193,42 +196,49 @@
   
   (self->state).vtsN = -1;
   
-  self->dvd = DVDOpen(dvdroot);
-  if(!self->dvd) {
-    fprintf(stderr, "vm: faild to open/read the DVD\n");
-    return -1;
-  }
-
-  self->vmgi = ifoOpenVMGI(self->dvd);
-  if(!self->vmgi) {
-    fprintf(stderr, "vm: faild to read VIDEO_TS.IFO\n");
-    return -1;
-  }
-  if(!ifoRead_FP_PGC(self->vmgi)) {
-    fprintf(stderr, "vm: ifoRead_FP_PGC failed\n");
-    return -1;
+  if (self->dvd && dvdroot) {
+    // a new dvd device has been requested
+    vm_stop(self);
   }
-  if(!ifoRead_TT_SRPT(self->vmgi)) {
-    fprintf(stderr, "vm: ifoRead_TT_SRPT failed\n");
-    return -1;
-  }
-  if(!ifoRead_PGCI_UT(self->vmgi)) {
-    fprintf(stderr, "vm: ifoRead_PGCI_UT failed\n");
-    return -1;
+  if (!self->dvd) {
+    self->dvd = DVDOpen(dvdroot);
+    if(!self->dvd) {
+      fprintf(stderr, "vm: faild to open/read the DVD\n");
+      return -1;
+    }
+
+    self->vmgi = ifoOpenVMGI(self->dvd);
+    if(!self->vmgi) {
+      fprintf(stderr, "vm: faild to read VIDEO_TS.IFO\n");
+      return -1;
+    }
+    if(!ifoRead_FP_PGC(self->vmgi)) {
+      fprintf(stderr, "vm: ifoRead_FP_PGC failed\n");
+      return -1;
+    }
+    if(!ifoRead_TT_SRPT(self->vmgi)) {
+      fprintf(stderr, "vm: ifoRead_TT_SRPT failed\n");
+      return -1;
+    }
+    if(!ifoRead_PGCI_UT(self->vmgi)) {
+      fprintf(stderr, "vm: ifoRead_PGCI_UT failed\n");
+      return -1;
+    }
+    if(!ifoRead_PTL_MAIT(self->vmgi)) {
+      fprintf(stderr, "vm: ifoRead_PTL_MAIT failed\n");
+      ; /*  return -1; Not really used for now.. */
+    }
+    if(!ifoRead_VTS_ATRT(self->vmgi)) {
+      fprintf(stderr, "vm: ifoRead_VTS_ATRT failed\n");
+      ; /*  return -1; Not really used for now.. */
+    }
+    if(!ifoRead_VOBU_ADMAP(self->vmgi)) {
+      fprintf(stderr, "vm: ifoRead_VOBU_ADMAP vgmi failed\n");
+      ; /*  return -1; Not really used for now.. */
+    }
+    /* ifoRead_TXTDT_MGI(vmgi); Not implemented yet */
   }
-  if(!ifoRead_PTL_MAIT(self->vmgi)) {
-    fprintf(stderr, "vm: ifoRead_PTL_MAIT failed\n");
-    ; /*  return -1; Not really used for now.. */
-  }
-  if(!ifoRead_VTS_ATRT(self->vmgi)) {
-    fprintf(stderr, "vm: ifoRead_VTS_ATRT failed\n");
-    ; /*  return -1; Not really used for now.. */
-  }
-  if(!ifoRead_VOBU_ADMAP(self->vmgi)) {
-    fprintf(stderr, "vm: ifoRead_VOBU_ADMAP vgmi failed\n");
-    ; /*  return -1; Not really used for now.. */
-  }
-  /* ifoRead_TXTDT_MGI(vmgi); Not implemented yet */
+  else fprintf(stderr, "vm: reset\n");
 
   return 0;
 }
@@ -1522,6 +1532,9 @@
 
 /*
  * $Log$
+ * Revision 1.3  2002/04/02 18:22:27  richwareham
+ * Added reset patch from Kees Cook <kees@outflux.net>
+ *
  * Revision 1.2  2002/04/01 18:56:28  richwareham
  * Added initial example programs directory and make sure all debug/error output goes to stderr.
  *