[Mplayer-cvslog] CVS: main playtree.c,1.3,1.4 playtree.h,1.2,1.3 cfg-common.h,1.21,1.22 cfgparser.c,1.39,1.40

Alban Bedel CVS albeu at mplayer.dev.hu
Thu Jan 17 21:24:39 CET 2002


Update of /cvsroot/mplayer/main
In directory mplayer:/var/tmp.root/cvs-serv15349

Modified Files:
	playtree.c playtree.h cfg-common.h cfgparser.c 
Log Message:
Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
like dvd://1 vcd://2 tv://5


Index: playtree.c
===================================================================
RCS file: /cvsroot/mplayer/main/playtree.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- playtree.c	14 Jan 2002 23:38:49 -0000	1.3
+++ playtree.c	17 Jan 2002 20:24:28 -0000	1.4
@@ -4,6 +4,7 @@
 #include <string.h>
 #include <stdio.h>
 #include <unistd.h>
+#include <errno.h>
 #ifdef MP_DEBUG
 #include <assert.h>
 #endif
@@ -13,11 +14,15 @@
 static int
 play_tree_is_valid(play_tree_t* pt);
 
+static void
+play_tree_iter_set_param(play_tree_iter_t* iter,char* opt,char* val);
+
 play_tree_t*
 play_tree_new(void) {
   play_tree_t* r = (play_tree_t*)calloc(1,sizeof(play_tree_t));
   if(r == NULL)
     mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",sizeof(play_tree_t));
+  r->entry_type = PLAY_TREE_ENTRY_NODE;
   return r;
 }
 
@@ -189,7 +194,7 @@
 
 #ifdef MP_DEBUG
   assert(pt != NULL);
-  assert(pt->files == NULL);
+  assert(pt->entry_type == PLAY_TREE_ENTRY_NODE);
 #endif
 
   for(iter = pt->child ; iter != NULL ; iter = iter->next)
@@ -234,6 +239,7 @@
 void
 play_tree_add_file(play_tree_t* pt,char* file) {
   int n = 0;
+  char* e;
 
 #ifdef MP_DEBUG
   assert(pt != NULL);
@@ -241,6 +247,10 @@
   assert(file != NULL);
 #endif
 
+  if(pt->entry_type != PLAY_TREE_ENTRY_NODE && 
+     pt->entry_type != PLAY_TREE_ENTRY_FILE)
+    return;
+
   if(pt->files) {
     for(n = 0 ; pt->files[n] != NULL ; n++)
       /* NOTHING */;
@@ -251,9 +261,21 @@
     return;
   }
 
-  pt->files[n] = strdup(file);
+  e = pt->files[n] = strdup(file);
   pt->files[n+1] = NULL;
 
+  if(strncasecmp(e,"vcd://",6) == 0 && strlen(&e[6]) > 0) {
+    pt->entry_type = PLAY_TREE_ENTRY_VCD;
+    memmove(e,e + 6,strlen(&e[6])+1);
+  } else if(strncasecmp(e,"dvd://",6) == 0 && strlen(&e[6]) > 0) {
+    pt->entry_type = PLAY_TREE_ENTRY_DVD;
+    memmove(e,&e[6],strlen(&e[6])+1);
+  } else if(strncasecmp(e,"tv://",5) == 0 && strlen(&e[5]) > 0) {
+    pt->entry_type = PLAY_TREE_ENTRY_TV;
+    memmove(e,&e[5],strlen(&e[5])+1);
+  } else
+    pt->entry_type = PLAY_TREE_ENTRY_FILE;
+
 }
 
 int
@@ -263,7 +285,7 @@
 #ifdef MP_DEBUG
   assert(pt != NULL);
   assert(file != NULL);
-  assert(pt->files != NULL);
+  assert(pt->entry_type != PLAY_TREE_ENTRY_NODE);
 #endif
 
   for(n=0 ; pt->files[n] != NULL ; n++) {
@@ -383,7 +405,9 @@
 	     pt->params[n].name,pt->params[n].value);      
     }
   }
-  //printf("Param pushed\n");
+
+  if(!pt->child)
+    iter->entry_pushed = 1;
   return 1;
 }
 
@@ -397,7 +421,7 @@
 
   if(iter->tree->params == NULL)
     return;
-  //printf("Poping params\n");
+  iter->entry_pushed = 0;
   m_config_pop(iter->config);
 }
 
@@ -457,12 +481,10 @@
     return play_tree_iter_step(iter,0,with_nodes);
   }
 
-  if(iter->config && iter->entry_pushed) {
+  if(iter->config && iter->entry_pushed)
     play_tree_iter_pop_params(iter);
-    iter->entry_pushed = 0;
-  }
 
-  iter->file = 0;
+  iter->file = -1;
   if( d > 0 )
     pt = iter->tree->next;
   else if(d < 0)
@@ -511,14 +533,15 @@
 #ifdef MP_DEBUG
   assert(pt->files != NULL);
 #endif
-  
+
   iter->tree = pt;
+    
   for(d = 0 ; iter->tree->files[d] != NULL ; d++)
     /* NOTHING */;
   iter->num_files = d;
-  
+
   if(iter->config)
-    iter->entry_pushed = play_tree_iter_push_params(iter);
+    play_tree_iter_push_params(iter);
 
   return PLAY_TREE_ITER_ENTRY;
 
@@ -532,8 +555,12 @@
   assert(pt != NULL);
 #endif
 
-  if(pt->files != NULL)
+  if(pt->entry_type != PLAY_TREE_ENTRY_NODE) {
+#ifdef MP_DEBUG
+    assert(pt->child == NULL);
+#endif
     return 1;
+  }
   else if (pt->child != NULL) {
     for(iter = pt->child ; iter != NULL ; iter = iter->next) {
       if(play_tree_is_valid(iter))
@@ -552,7 +579,7 @@
   //printf("PT : Go UP\n");
 #endif
   
-  iter->file = 0;
+  iter->file = -1;
   if(iter->tree->parent == iter->root->parent)
     return PLAY_TREE_ITER_END;
 
@@ -588,7 +615,7 @@
   //printf("PT : Go DOWN\n");
 #endif
 
-  iter->file = 0;
+  iter->file = -1;
 
   //  Push subtree params
   if(iter->config)
@@ -617,7 +644,7 @@
 
 char*
 play_tree_iter_get_file(play_tree_iter_t* iter, int d) {
-  
+  char* entry;
 #ifdef MP_DEBUG
   assert(iter != NULL);
   assert(iter->tree->child == NULL);
@@ -626,16 +653,43 @@
   if(iter->tree->files == NULL)
     return NULL;
 
+#ifdef MP_DEBUG
+  assert(iter->num_files > 0);
+#endif
+
+  if(iter->file >= iter->num_files-1 || iter->file < -1)
+    return NULL;
+
   if(d > 0) {
-    if(iter->tree->files[iter->file] == NULL)
-      return NULL;
-    iter->file++;
+    if(iter->file >= iter->num_files - 1)
+      iter->file = 0;
+    else
+      iter->file++;
   } else if(d < 0) {
-    if(iter->file == 0)
-      return NULL;
-    iter->file--;
-  } 
-  return iter->tree->files[iter->file-1];
+    if(iter->file <= 0)
+      iter->file = iter->num_files - 1;
+    else
+      iter->file--;
+  }
+  entry = iter->tree->files[iter->file];
+
+  switch(iter->tree->entry_type) {
+  case PLAY_TREE_ENTRY_DVD :
+    play_tree_iter_set_param(iter,"dvd",entry);
+    break;
+  case PLAY_TREE_ENTRY_VCD :
+    play_tree_iter_set_param(iter,"vcd",entry);
+    break;
+  case PLAY_TREE_ENTRY_TV : 
+    {
+      char* val = (char*)malloc(strlen(entry) + 11 + 1);
+      sprintf(val,"on:channel=%s",entry);
+      play_tree_iter_set_param(iter,"tv",val);
+      break;
+    }
+  }
+
+  return entry;
 }
 
 play_tree_t*
@@ -700,3 +754,27 @@
 
   return iter;
 }
+
+static void
+play_tree_iter_set_param(play_tree_iter_t* iter,char* opt,char* val) {
+  int push = 0;
+  play_tree_t* pt;
+#ifdef MP_DEBUG
+  assert(iter != NULL);
+  assert(iter->tree != NULL);
+#endif
+
+  pt = iter->tree;
+  
+  if(iter->tree->params == NULL)
+    push = 1;
+
+  play_tree_set_param(iter->tree,opt,val);
+
+  if(push)
+    play_tree_iter_push_params(iter);
+  else if(iter->config)
+    m_config_set_option(iter->config,opt,val);
+
+}
+

Index: playtree.h
===================================================================
RCS file: /cvsroot/mplayer/main/playtree.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- playtree.h	14 Jan 2002 23:38:49 -0000	1.2
+++ playtree.h	17 Jan 2002 20:24:28 -0000	1.3
@@ -10,6 +10,12 @@
 #define PLAY_TREE_ITER_NODE  2
 #define PLAY_TREE_ITER_END 3
 
+#define PLAY_TREE_ENTRY_NODE -1
+#define PLAY_TREE_ENTRY_DVD 0
+#define PLAY_TREE_ENTRY_VCD 1
+#define PLAY_TREE_ENTRY_TV    2
+#define PLAY_TREE_ENTRY_FILE  3
+
 typedef struct play_tree play_tree_t;
 typedef struct play_tree_iter play_tree_iter_t;
 typedef struct play_tree_param play_tree_param_t;
@@ -44,6 +50,7 @@
   play_tree_param_t* params;
   int loop;
   char** files;
+  int entry_type;
 };
   
 struct play_tree_iter {

Index: cfg-common.h
===================================================================
RCS file: /cvsroot/mplayer/main/cfg-common.h,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- cfg-common.h	14 Jan 2002 23:54:31 -0000	1.21
+++ cfg-common.h	17 Jan 2002 20:24:28 -0000	1.22
@@ -8,10 +8,12 @@
 #endif
 #ifdef HAVE_VCD
 	{"vcd", &vcd_track, CONF_TYPE_INT, CONF_RANGE, 1, 99, NULL},
+	{"cdrom-device", &cdrom_device, CONF_TYPE_STRING, 0, 0, 0, NULL},
 #else
 	{"vcd", "VCD support is NOT available on this system!\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
 #endif
 #ifdef USE_DVDREAD
+	{"dvd-device", &dvd_device,  CONF_TYPE_STRING, 0, 0, 0, NULL}, 
 	{"dvd", &dvd_title, CONF_TYPE_INT, CONF_RANGE, 1, 99, NULL},
 	{"dvdangle", &dvd_angle, CONF_TYPE_INT, CONF_RANGE, 1, 99, NULL},
 	{"chapter", &dvd_chapter, CONF_TYPE_INT, CONF_RANGE, 1, 99, NULL},
@@ -115,6 +117,7 @@
 extern int vivo_param_width;
 extern int vivo_param_height;
 extern int vivo_param_vformat;
+extern char *dvd_device, *cdrom_device;
 
 struct config vivoopts_conf[]={
 	{"version", &vivo_param_version, CONF_TYPE_INT, 0, 0, 0, NULL},

Index: cfgparser.c
===================================================================
RCS file: /cvsroot/mplayer/main/cfgparser.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- cfgparser.c	14 Jan 2002 23:38:49 -0000	1.39
+++ cfgparser.c	17 Jan 2002 20:24:28 -0000	1.40
@@ -300,7 +300,7 @@
 
 	mp_msg(MSGT_CFGPARSER, MSGL_DBG3, "read_option: conf=%p opt='%s' param='%s'\n",
 	    conf, opt, param);
-	for(nconf = 0 ;  conf_list&& conf_list[nconf] != NULL; nconf++) {
+	for(nconf = 0 ;  conf_list[nconf] != NULL; nconf++) {
 	  conf = conf_list[nconf];
 		for (i = 0; conf[i].name != NULL; i++) {
 			int namelength;
@@ -563,7 +563,7 @@
 			break;
 	}
 out:
-	if(config->global == 0 && ! (conf[i].flags & CONF_GLOBAL)) {
+	if(ret >= 0 && config->global == 0 && ! (conf[i].flags & CONF_GLOBAL)) {
 	  play_tree_t* dest = config->last_entry ? config->last_entry : config->last_parent;
 #ifdef MP_DEBUG
 	  assert(dest != NULL);




More information about the MPlayer-cvslog mailing list