changeset 90:eeabf5a51b2b src

Improve chapter selection functions.
author jcdutton
date Tue, 03 Sep 2002 07:50:45 +0000
parents 0fbef4901e2c
children df9712507b30
files dvdnav.h navigation.c searching.c vm.c vm.h
diffstat 5 files changed, 63 insertions(+), 196 deletions(-) [+]
line wrap: on
line diff
--- a/dvdnav.h	Tue Sep 03 00:41:48 2002 +0000
+++ b/dvdnav.h	Tue Sep 03 07:50:45 2002 +0000
@@ -396,22 +396,6 @@
 
 /**
  * Stop playing the current title and start playback of the title
- * from the previous part (chapter).
- *
- * \param self Pointer to dvdnav_t associated with this operation.
- */
-dvdnav_status_t dvdnav_prev_part_search(dvdnav_t *self);
-
-/**
- * Stop playing the current title and start playback of the title
- * from the next part (chapter).
- *
- * \param self Pointer to dvdnav_t associated with this operation.
- */
-dvdnav_status_t dvdnav_next_part_search(dvdnav_t *self);
-
-/**
- * Stop playing the current title and start playback of the title
  * from the previous program (if it exists).
  *
  * \param self Pointer to dvdnav_t associated with this operation.
--- a/navigation.c	Tue Sep 03 00:41:48 2002 +0000
+++ b/navigation.c	Tue Sep 03 07:50:45 2002 +0000
@@ -56,6 +56,7 @@
   return S_OK;
 }
 
+/* This function should not be used. FIXME: Suggest alternative */
 dvdnav_status_t dvdnav_get_number_of_programs(dvdnav_t *this, int *programs) {
   if(!this)
    return S_ERR;
@@ -70,55 +71,34 @@
   return S_OK;
 }
 
+dvdnav_status_t dvdnav_current_title_info(dvdnav_t *this, int *title, int *part) {
+  if(!this || !this->vm)
+   return S_ERR;
+
+  if(!title || !part) {
+    printerr("Passed a NULL pointer");
+    return S_ERR;
+  }
+
+  return vm_get_current_title_part(this->vm, title, part);
+}
+
 dvdnav_status_t dvdnav_title_play(dvdnav_t *this, int title) {
-  int num_titles;
 
   if(!this) {
     return S_ERR;
   }
 
-  /* Check number of titles */
-  dvdnav_get_number_of_titles(this, &num_titles);
-  if((title > num_titles) || (title <= 0)) {
-    printerrf("Invalid title passed (%i, maximum %i)", title,
-	      num_titles);
-    return S_ERR;
-  }
-  
-  vm_start_title(this->vm, title);
-
-  return S_OK;
+  return dvdnav_part_play(this, title, 1);
 }
 
 dvdnav_status_t dvdnav_part_play(dvdnav_t *this, int title, int part) {
-  int num_titles, num_progs;
 
   if(!this) {
     return S_ERR;
   }
 
-  /* Check number of titles */
-  dvdnav_get_number_of_titles(this, &num_titles);
-  if((title > num_titles) || (title <= 0)) {
-    printerrf("Invalid title passed (%i, maximum %i)", title,
-	      num_titles);
-    return S_ERR;
-  }
- 
-  vm_start_title(this->vm, title);
-
-
-  /* Check number of parts */
-  num_progs = this->vm->state.pgc->nr_of_programs;
-  if((part > num_progs) || (part <= 0)) {
-    printerrf("Invalid program passed (%i, maximum %i)", part,
-	      num_progs);
-    return S_ERR;
-  }
-   
-  vm_jump_prog(this->vm, part);
-  
-  return S_OK;
+  return vm_jump_title_part(this->vm, title, part);
 }
 
 dvdnav_status_t dvdnav_part_play_auto_stop(dvdnav_t *this, int title,
--- a/searching.c	Tue Sep 03 00:41:48 2002 +0000
+++ b/searching.c	Tue Sep 03 07:50:45 2002 +0000
@@ -228,25 +228,6 @@
   return S_OK;
 }
 
-dvdnav_status_t dvdnav_prev_part_search(dvdnav_t *this) {
-
-  if((!this) || (!this->vm)  )
-    return S_ERR;
-  
-  vm_prev_part(this->vm);
-  /* FIXME: handle errors */
-  return S_OK;
-}
-
-dvdnav_status_t dvdnav_next_part_search(dvdnav_t *this) {
-  if((!this) || (!this->vm)  )
-    return S_ERR;
-
-  vm_next_part(this->vm);
-  /* FIXME: handle errors */
-  return S_OK;
-}
-
 dvdnav_status_t dvdnav_prev_pg_search(dvdnav_t *this) {
   dvd_state_t *state;
 
@@ -317,56 +298,6 @@
   return S_OK;
 }
 
-dvdnav_status_t dvdnav_current_title_info(dvdnav_t *this, int *tt, int *pr) {
-int vts_ttn = 0;
-  int vts, i;
-  domain_t domain;
-  tt_srpt_t* srpt;
-  
-  if(!this)
-   return S_ERR;
-
-  if(!tt || !pr) {
-    printerr("Passed a NULL pointer");
-  }
-
-  if(tt)
-   *tt = -1;
-  if(*pr)
-   *pr = -1;
-
-  domain = this->vm->state.domain;
-  if((domain == FP_DOMAIN) || (domain == VMGM_DOMAIN)) {
-    /* Not in a title */
-    return S_OK;
-  }
-  
-  vts_ttn = this->vm->state.VTS_TTN_REG;
-  vts = this->vm->state.vtsN;
-
-  /* FIXME: pr should be found by searching the VTS_SRPT table. Not just the pgN */
-  if(pr) {
-    *pr = this->vm->state.pgN;
-  }
-
-  /* Search TT_SRPT for title */
-  if(!(vm_get_vmgi(this->vm))) {
-    printerr("Oh poo, no SRPT");
-    return S_ERR;
-  }
-  
-  srpt = vm_get_vmgi(this->vm)->tt_srpt;
-  for(i=0; i<srpt->nr_of_srpts; i++) {
-    title_info_t* info = &(srpt->title[i]);
-    if((info->title_set_nr == vts) && (info->vts_ttn == vts_ttn)) {
-      if(tt)
-       *tt = i+1;
-    }
-  }
-
-  return S_OK;
-}
-
 static char __title_str[] = "DVDNAV";
 
 dvdnav_status_t dvdnav_get_title_string(dvdnav_t *this, char **title_str) {
--- a/vm.c	Tue Sep 03 00:41:48 2002 +0000
+++ b/vm.c	Tue Sep 03 07:50:45 2002 +0000
@@ -438,17 +438,24 @@
   return vm_top_pg(vm);
 }
 
-int vm_prev_part(vm_t *vm)
+/* Get the current title and part from the current playing position. */
+/* returns S_ERR if not in the VTS_DOMAIN */
+/* FIXME: Should we do some locking here ? */
+int vm_get_current_title_part(vm_t *vm, int *title_result, int *part_result)
 {
-  link_t link_values;
   vts_ptt_srpt_t *vts_ptt_srpt;
-  int title, part=0;
+  int title=0, part=0;
   int found = 0;
   int16_t pgcN, pgN;
 
   if((!vm) || (!vm->vtsi) )
     return S_ERR;
 
+  if(!title_result || !part_result) {
+    fprintf(MSG_OUT, "libdvdnav:vm_get_current_title_part: Passed a NULL pointer");
+    return S_ERR;
+  }
+
   if(!(vm->state.pgc) )
     return S_ERR;
   if (vm->state.domain != VTS_DOMAIN)
@@ -458,7 +465,7 @@
   pgN = vm->state.pgN;
   printf("VTS_PTT_SRPT - PGC: %3i PG: %3i\n",
     pgcN, pgN);
-  for(title=0;( (title<vts_ptt_srpt->nr_of_srpts) && (found == 0) );title++) {
+  for(title=0;( (title < vts_ptt_srpt->nr_of_srpts) && (found == 0) );title++) {
     for(part=0;((part < vts_ptt_srpt->title[title].nr_of_ptts) && (found == 0));part++) {
       if ( (vts_ptt_srpt->title[title].ptt[part].pgcn == pgcN) &&
            (vts_ptt_srpt->title[title].ptt[part].pgn == pgN ) ) {
@@ -480,14 +487,36 @@
     fprintf(MSG_OUT, "libdvdnav: ************ this chapter NOT FOUND!\n");
     return S_ERR;
   }
-  /* Make sure this is not the first chapter */
-  if(part <= 1 ) {
-    fprintf(MSG_OUT, "libdvdnav: at first chapter. prev chapter failed.\n");
+  *title_result = title;
+  *part_result = part;
+  return 1;
+}
+
+/* Jump to a particlar part of a particlar title on this vts */
+/* returns S_ERR if not in the VTS_DOMAIN */
+/* FIXME: Should we do some locking here ? */
+int vm_jump_title_part(vm_t *vm, int title, int part) {
+  link_t link_values;
+  int vtsN;
+
+  if((!vm) || (!vm->vtsi) || (!vm->vmgi) )
+    return S_ERR;
+
+  if(!(vm->state.pgc) )
+    return S_ERR;
+/*  if ( (title < 1) || (title > vm->vtsi->vts_ptt_srpt->nr_of_srpts) ||
+       (part  < 1) || (part  > vm->vtsi->vts_ptt_srpt->title[title].nr_of_ptts) ) {
     return S_ERR;
   }
-  part--;  /* Previous chapter */
-  if(set_VTS_PTT(vm,(vm->state).vtsN, title, part) == -1)
-    assert(0);
+ */
+  if( (title < 1) || (title > vm->vmgi->tt_srpt->nr_of_srpts) ) {
+    return S_ERR;
+  }
+  vtsN = vm->vmgi->tt_srpt->title[title - 1].title_set_nr;
+
+  if(set_VTS_PTT(vm, vtsN, title, part) == -1) {
+    return S_ERR;
+  }
   link_values = play_PGC_PG( vm, (vm->state).pgN ); 
   link_values = process_command(vm,link_values);
   assert(link_values.command == PlayThis);
@@ -500,68 +529,6 @@
   return 1;
 }
 
-
-int vm_next_part(vm_t *vm)
-{
-  link_t link_values;
-  vts_ptt_srpt_t *vts_ptt_srpt;
-  int title, part=0;
-  int found = 0;
-  int16_t pgcN, pgN;
-
-  if((!vm) || (!vm->vtsi) )
-    return S_ERR;
-
-  if(!(vm->state.pgc) )
-    return S_ERR;
-  if (vm->state.domain != VTS_DOMAIN)
-    return S_ERR;
-  vts_ptt_srpt = vm->vtsi->vts_ptt_srpt;
-  pgcN = get_PGCN(vm);
-  pgN = vm->state.pgN;
-  printf("VTS_PTT_SRPT - PGC: %3i PG: %3i\n",
-    pgcN, pgN);
-  for(title=0;( (title<vts_ptt_srpt->nr_of_srpts) && (found == 0) );title++) {
-    for(part=0;((part < vts_ptt_srpt->title[title].nr_of_ptts) && (found == 0));part++) {
-      if ( (vts_ptt_srpt->title[title].ptt[part].pgcn == pgcN) &&
-           (vts_ptt_srpt->title[title].ptt[part].pgn == pgN ) ) {
-        found = 1;
-        break;
-      }
-    }
-    if (found != 0) break;
-  }
-  title++;
-  part++;
-  if (found == 1) {
-    fprintf(MSG_OUT, "libdvdnav: ************ this chapter FOUND!\n");
-    printf("VTS_PTT_SRPT - Title %3i part %3i: PGC: %3i PG: %3i\n",
-             title, part,
-             vts_ptt_srpt->title[title-1].ptt[part-1].pgcn ,
-             vts_ptt_srpt->title[title-1].ptt[part-1].pgn );
-  } else {
-    fprintf(MSG_OUT, "libdvdnav: ************ this chapter NOT FOUND!\n");
-  }
-  /* Make sure this is not the last chapter */
-  if(part >= vts_ptt_srpt->title[title-1].nr_of_ptts) {
-    fprintf(MSG_OUT, "libdvdnav: at last chapter. next chapter failed.\n");
-    return S_ERR;
-  }
-  part++;  /* Next chapter */
-  if(set_VTS_PTT(vm,(vm->state).vtsN, title, part) == -1)
-    assert(0);
-  link_values = play_PGC_PG( vm, (vm->state).pgN );
-  link_values = process_command(vm,link_values);
-  assert(link_values.command == PlayThis);
-  (vm->state).blockN = link_values.data1;
-  assert( (vm->state).blockN == 0 );
-  vm->hop_channel++;
-
-  fprintf(MSG_OUT, "libdvdnav: next chapter done\n");
-
-  return 1;
-}
-
 static domain_t menuid2domain(DVDMenuID_t menuid)
 {
   domain_t result = VTSM_DOMAIN; /*  Really shouldn't have to.. */
@@ -1695,8 +1662,10 @@
   if(vtsN != (vm->state).vtsN)
     ifoOpenNewVTSI(vm, vm->dvd, vtsN); /*  Also sets (vm->state).vtsN */
   
-  assert(vts_ttn <= vm->vtsi->vts_ptt_srpt->nr_of_srpts);
-  assert(part <= vm->vtsi->vts_ptt_srpt->title[vts_ttn - 1].nr_of_ptts);
+  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) ) {
+    return S_ERR;
+  }
   
   pgcN = vm->vtsi->vts_ptt_srpt->title[vts_ttn - 1].ptt[part - 1].pgcn;
   pgN = vm->vtsi->vts_ptt_srpt->title[vts_ttn - 1].ptt[part - 1].pgn;
@@ -1957,6 +1926,9 @@
 
 /*
  * $Log$
+ * Revision 1.34  2002/09/03 07:50:45  jcdutton
+ * Improve chapter selection functions.
+ *
  * Revision 1.33  2002/09/02 03:20:01  jcdutton
  * Implement proper prev/next chapter/part.
  * I don't know why someone has not noticed the problem until now.
--- a/vm.h	Tue Sep 03 00:41:48 2002 +0000
+++ b/vm.h	Tue Sep 03 07:50:45 2002 +0000
@@ -123,6 +123,7 @@
 /* Jumping */
 int vm_start_title(vm_t *vm, int tt);
 int vm_jump_prog(vm_t *vm, int pr);
+int vm_jump_title_part(vm_t *vm, int title, int part);
 
 /* Other calls */
 int vm_reset(vm_t *vm, char *dvdroot); /*  , register_t regs); */
@@ -137,8 +138,6 @@
 int vm_top_pg(vm_t *vm);
 int vm_next_pg(vm_t *vm);
 int vm_prev_pg(vm_t *vm);
-int vm_next_part(vm_t *vm);
-int vm_prev_part(vm_t *vm);
 int vm_get_audio_stream(vm_t *vm, int audioN);
 int vm_get_audio_active_stream(vm_t *vm);
 int vm_get_subp_stream(vm_t *vm, int subpN, int mode);
@@ -146,6 +145,7 @@
 void vm_get_angle_info(vm_t *vm, int *num_avail, int *current);
 void vm_get_audio_info(vm_t *vm, int *num_avail, int *current);
 void vm_get_subp_info(vm_t *vm, int *num_avail, int *current);
+int vm_get_current_title_part(vm_t *vm, int *title_result, int *part_result);
 
 subp_attr_t vm_get_subp_attr(vm_t *vm, int streamN);
 audio_attr_t vm_get_audio_attr(vm_t *vm, int streamN);