2002-01-08 01:24:25 +00:00
|
|
|
|
2002-01-14 23:38:49 +00:00
|
|
|
#include "config.h"
|
2002-01-08 01:24:25 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
2002-01-08 12:10:33 +00:00
|
|
|
#include <unistd.h>
|
2002-01-17 20:24:28 +00:00
|
|
|
#include <errno.h>
|
2002-01-14 23:38:49 +00:00
|
|
|
#ifdef MP_DEBUG
|
2002-01-08 01:24:25 +00:00
|
|
|
#include <assert.h>
|
2002-01-14 23:38:49 +00:00
|
|
|
#endif
|
2002-01-08 01:24:25 +00:00
|
|
|
#include "playtree.h"
|
|
|
|
#include "mp_msg.h"
|
|
|
|
|
|
|
|
static int
|
|
|
|
play_tree_is_valid(play_tree_t* pt);
|
|
|
|
|
|
|
|
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));
|
2002-01-17 20:24:28 +00:00
|
|
|
r->entry_type = PLAY_TREE_ENTRY_NODE;
|
2002-01-08 01:24:25 +00:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
play_tree_free(play_tree_t* pt, int childs) {
|
|
|
|
play_tree_t* iter;
|
|
|
|
|
2002-01-14 23:38:49 +00:00
|
|
|
#ifdef MP_DEBUG
|
2002-01-08 01:24:25 +00:00
|
|
|
assert(pt != NULL);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(childs) {
|
|
|
|
for(iter = pt->child; iter != NULL; iter = iter->next)
|
|
|
|
play_tree_free(iter,1);
|
|
|
|
pt->child = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
play_tree_remove(pt,0,0);
|
|
|
|
|
|
|
|
for(iter = pt->child ; iter != NULL ; iter = iter->next)
|
|
|
|
iter->parent = NULL;
|
|
|
|
|
|
|
|
//if(pt->params) free(pt->params);
|
|
|
|
if(pt->files) {
|
|
|
|
int i;
|
|
|
|
for(i = 0 ; pt->files[i] != NULL ; i++)
|
|
|
|
free(pt->files[i]);
|
|
|
|
free(pt->files);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(pt);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
play_tree_free_list(play_tree_t* pt, int childs) {
|
|
|
|
play_tree_t* iter;
|
|
|
|
|
2002-01-14 23:38:49 +00:00
|
|
|
#ifdef MP_DEBUG
|
2002-01-08 01:24:25 +00:00
|
|
|
assert(pt != NULL);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for(iter = pt ; iter->prev != NULL ; iter = iter->prev)
|
|
|
|
/* NOTHING */;
|
|
|
|
|
|
|
|
for( ; iter != NULL ; iter = iter->next)
|
|
|
|
play_tree_free(iter,childs);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
play_tree_append_entry(play_tree_t* pt, play_tree_t* entry) {
|
|
|
|
play_tree_t* iter;
|
|
|
|
|
2002-01-14 23:38:49 +00:00
|
|
|
#ifdef MP_DEBUG
|
2002-01-08 01:24:25 +00:00
|
|
|
assert(pt != NULL);
|
|
|
|
assert(entry != NULL);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(pt == entry)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for(iter = pt ; iter->next != NULL ; iter = iter->next)
|
|
|
|
/* NOTHING */;
|
|
|
|
|
|
|
|
entry->parent = iter->parent;
|
|
|
|
entry->prev = iter;
|
|
|
|
entry->next = NULL;
|
|
|
|
iter->next = entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
play_tree_prepend_entry(play_tree_t* pt, play_tree_t* entry) {
|
|
|
|
play_tree_t* iter;
|
|
|
|
|
2002-01-14 23:38:49 +00:00
|
|
|
#ifdef MP_DEBUG
|
2002-01-08 01:24:25 +00:00
|
|
|
assert(pt != NULL);
|
|
|
|
assert(entry != NULL);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for(iter = pt ; iter->prev != NULL; iter = iter->prev)
|
|
|
|
/* NOTHING */;
|
|
|
|
|
|
|
|
entry->prev = NULL;
|
|
|
|
entry->next = iter;
|
|
|
|
entry->parent = iter->parent;
|
|
|
|
|
|
|
|
iter->prev = entry;
|
|
|
|
if(entry->parent) {
|
2002-01-14 23:38:49 +00:00
|
|
|
#ifdef MP_DEBUG
|
2002-01-08 01:24:25 +00:00
|
|
|
assert(entry->parent->child == iter);
|
|
|
|
#endif
|
|
|
|
entry->parent->child = entry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
play_tree_insert_entry(play_tree_t* pt, play_tree_t* entry) {
|
|
|
|
|
2002-01-14 23:38:49 +00:00
|
|
|
#ifdef MP_DEBUG
|
2002-01-08 01:24:25 +00:00
|
|
|
assert(pt != NULL);
|
|
|
|
assert(entry != NULL);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
entry->parent = pt->parent;
|
|
|
|
entry->prev = pt;
|
|
|
|
if(pt->next) {
|
2002-01-14 23:38:49 +00:00
|
|
|
#ifdef MP_DEBUG
|
2002-01-08 01:24:25 +00:00
|
|
|
assert(pt->next->prev == pt);
|
|
|
|
#endif
|
|
|
|
entry->next = pt->next;
|
|
|
|
entry->next->prev = entry;
|
|
|
|
} else
|
|
|
|
entry->next = NULL;
|
|
|
|
pt->next = entry;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
play_tree_remove(play_tree_t* pt, int free_it,int with_childs) {
|
|
|
|
|
2002-01-14 23:38:49 +00:00
|
|
|
#ifdef MP_DEBUG
|
2002-01-08 01:24:25 +00:00
|
|
|
assert(pt != NULL);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Middle of list
|
|
|
|
if(pt->prev && pt->next) {
|
2002-01-14 23:38:49 +00:00
|
|
|
#ifdef MP_DEBUG
|
2002-01-08 01:24:25 +00:00
|
|
|
assert(pt->prev->next == pt);
|
|
|
|
assert(pt->next->prev == pt);
|
|
|
|
#endif
|
|
|
|
pt->prev->next = pt->next;
|
|
|
|
pt->next->prev = pt->prev;
|
|
|
|
} // End of list
|
|
|
|
else if(pt->prev) {
|
2002-01-14 23:38:49 +00:00
|
|
|
#ifdef MP_DEBUG
|
2002-01-08 01:24:25 +00:00
|
|
|
assert(pt->prev->next == pt);
|
|
|
|
#endif
|
|
|
|
pt->prev->next = NULL;
|
|
|
|
} // Begining of list
|
|
|
|
else if(pt->next) {
|
2002-01-14 23:38:49 +00:00
|
|
|
#ifdef MP_DEBUG
|
2002-01-08 01:24:25 +00:00
|
|
|
assert(pt->next->prev == pt);
|
|
|
|
#endif
|
|
|
|
pt->next->prev = NULL;
|
|
|
|
if(pt->parent) {
|
2002-01-14 23:38:49 +00:00
|
|
|
#ifdef MP_DEBUG
|
2002-01-08 01:24:25 +00:00
|
|
|
assert(pt->parent->child == pt);
|
|
|
|
#endif
|
|
|
|
pt->parent->child = pt->next;
|
|
|
|
}
|
|
|
|
} // The only one
|
|
|
|
else if(pt->parent) {
|
2002-01-14 23:38:49 +00:00
|
|
|
#ifdef MP_DEBUG
|
2002-01-08 01:24:25 +00:00
|
|
|
assert(pt->parent->child == pt);
|
|
|
|
#endif
|
|
|
|
pt->parent->child = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
pt->prev = pt->next = pt->parent = NULL;
|
|
|
|
if(free_it)
|
|
|
|
play_tree_free(pt,with_childs);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
play_tree_set_child(play_tree_t* pt, play_tree_t* child) {
|
|
|
|
play_tree_t* iter;
|
|
|
|
|
2002-01-14 23:38:49 +00:00
|
|
|
#ifdef MP_DEBUG
|
2002-01-08 01:24:25 +00:00
|
|
|
assert(pt != NULL);
|
2002-01-17 20:24:28 +00:00
|
|
|
assert(pt->entry_type == PLAY_TREE_ENTRY_NODE);
|
2002-01-08 01:24:25 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
for(iter = pt->child ; iter != NULL ; iter = iter->next)
|
|
|
|
iter->parent = NULL;
|
|
|
|
|
|
|
|
// Go back to first one
|
|
|
|
for(iter = child ; iter->prev != NULL ; iter = iter->prev)
|
|
|
|
/* NOTHING */;
|
|
|
|
|
|
|
|
pt->child = iter;
|
|
|
|
|
|
|
|
for( ; iter != NULL ; iter= iter->next)
|
|
|
|
iter->parent = pt;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
play_tree_set_parent(play_tree_t* pt, play_tree_t* parent) {
|
|
|
|
play_tree_t* iter;
|
|
|
|
|
2002-01-14 23:38:49 +00:00
|
|
|
#ifdef MP_DEBUG
|
2002-01-08 01:24:25 +00:00
|
|
|
assert(pt != NULL);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(pt->parent)
|
|
|
|
pt->parent->child = NULL;
|
|
|
|
|
|
|
|
for(iter = pt ; iter != NULL ; iter = iter->next)
|
|
|
|
iter->parent = parent;
|
|
|
|
|
|
|
|
if(pt->prev) {
|
|
|
|
for(iter = pt->prev ; iter->prev != NULL ; iter = iter->prev)
|
|
|
|
iter->parent = parent;
|
|
|
|
iter->parent = parent;
|
|
|
|
parent->child = iter;
|
|
|
|
} else
|
|
|
|
parent->child = pt;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
play_tree_add_file(play_tree_t* pt,char* file) {
|
|
|
|
int n = 0;
|
2002-01-17 20:24:28 +00:00
|
|
|
char* e;
|
2002-01-08 01:24:25 +00:00
|
|
|
|
2002-01-14 23:38:49 +00:00
|
|
|
#ifdef MP_DEBUG
|
2002-01-08 01:24:25 +00:00
|
|
|
assert(pt != NULL);
|
|
|
|
assert(pt->child == NULL);
|
|
|
|
assert(file != NULL);
|
|
|
|
#endif
|
|
|
|
|
2002-01-17 20:24:28 +00:00
|
|
|
if(pt->entry_type != PLAY_TREE_ENTRY_NODE &&
|
|
|
|
pt->entry_type != PLAY_TREE_ENTRY_FILE)
|
|
|
|
return;
|
|
|
|
|
2002-01-08 01:24:25 +00:00
|
|
|
if(pt->files) {
|
|
|
|
for(n = 0 ; pt->files[n] != NULL ; n++)
|
|
|
|
/* NOTHING */;
|
|
|
|
}
|
|
|
|
pt->files = (char**)realloc(pt->files,(n+2)*sizeof(char*));
|
|
|
|
if(pt->files ==NULL) {
|
|
|
|
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",(n+2)*sizeof(char*));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-01-17 20:24:28 +00:00
|
|
|
e = pt->files[n] = strdup(file);
|
2002-01-08 01:24:25 +00:00
|
|
|
pt->files[n+1] = NULL;
|
|
|
|
|
2002-01-19 22:16:47 +00:00
|
|
|
if(strncasecmp(e,"vcd://",6) == 0) {
|
2002-01-17 20:24:28 +00:00
|
|
|
pt->entry_type = PLAY_TREE_ENTRY_VCD;
|
|
|
|
memmove(e,e + 6,strlen(&e[6])+1);
|
2002-01-19 22:16:47 +00:00
|
|
|
} else if(strncasecmp(e,"dvd://",6) == 0) {
|
2002-01-17 20:24:28 +00:00
|
|
|
pt->entry_type = PLAY_TREE_ENTRY_DVD;
|
|
|
|
memmove(e,&e[6],strlen(&e[6])+1);
|
2002-01-19 22:16:47 +00:00
|
|
|
} else if(strncasecmp(e,"tv://",5) == 0) {
|
2002-01-17 20:24:28 +00:00
|
|
|
pt->entry_type = PLAY_TREE_ENTRY_TV;
|
|
|
|
memmove(e,&e[5],strlen(&e[5])+1);
|
|
|
|
} else
|
|
|
|
pt->entry_type = PLAY_TREE_ENTRY_FILE;
|
|
|
|
|
2002-01-08 01:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
play_tree_remove_file(play_tree_t* pt,char* file) {
|
|
|
|
int n,f = -1;
|
|
|
|
|
2002-01-14 23:38:49 +00:00
|
|
|
#ifdef MP_DEBUG
|
2002-01-08 01:24:25 +00:00
|
|
|
assert(pt != NULL);
|
|
|
|
assert(file != NULL);
|
2002-01-17 20:24:28 +00:00
|
|
|
assert(pt->entry_type != PLAY_TREE_ENTRY_NODE);
|
2002-01-08 01:24:25 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
for(n=0 ; pt->files[n] != NULL ; n++) {
|
|
|
|
if(strcmp(file,pt->files[n]) == 0)
|
|
|
|
f = n;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(f < 0) // Not found
|
|
|
|
return 0;
|
|
|
|
|
2002-01-14 23:38:49 +00:00
|
|
|
#ifdef MP_DEBUG
|
2002-01-08 01:24:25 +00:00
|
|
|
assert(n > f);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
free(pt->files[f]);
|
|
|
|
|
|
|
|
if(n > 1) {
|
|
|
|
memmove(&pt->files[f],&pt->files[f+1],(n-f)*sizeof(char*));
|
|
|
|
pt->files = (char**)realloc(pt->files,n*sizeof(char*));
|
|
|
|
if(pt->files == NULL) {
|
|
|
|
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",(n+2)*sizeof(char*));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
free(pt->files);
|
|
|
|
pt->files = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
play_tree_set_param(play_tree_t* pt, char* name, char* val) {
|
|
|
|
int n = 0,ni = -1;
|
|
|
|
|
2002-01-14 23:38:49 +00:00
|
|
|
#ifdef MP_DEBUG
|
2002-01-08 01:24:25 +00:00
|
|
|
assert(pt != NULL);
|
|
|
|
assert(name != NULL);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(pt->params) {
|
|
|
|
for( ; pt->params[n].name != NULL ; n++) {
|
|
|
|
if(strcasecmp(pt->params[n].name,name) == 0)
|
|
|
|
ni = n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ni > 0) {
|
|
|
|
if(pt->params[n].value != NULL) free(pt->params[n].value);
|
2002-01-19 16:58:04 +00:00
|
|
|
pt->params[n].value = val != NULL ? strdup(val) : NULL;
|
2002-01-08 01:24:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pt->params = (play_tree_param_t*)realloc(pt->params,(n+2)*sizeof(play_tree_param_t));
|
2002-01-19 16:58:04 +00:00
|
|
|
if(pt->params == NULL)
|
|
|
|
printf("Can't realloc params\n");
|
2002-01-08 01:24:25 +00:00
|
|
|
pt->params[n].name = strdup(name);
|
|
|
|
pt->params[n].value = val != NULL ? strdup(val) : NULL;
|
|
|
|
memset(&pt->params[n+1],0,sizeof(play_tree_param_t));
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
play_tree_unset_param(play_tree_t* pt, char* name) {
|
2002-01-14 23:38:49 +00:00
|
|
|
int n,ni = -1;
|
2002-01-08 01:24:25 +00:00
|
|
|
|
2002-01-14 23:38:49 +00:00
|
|
|
#ifdef MP_DEBUG
|
2002-01-08 01:24:25 +00:00
|
|
|
assert(pt != NULL);
|
|
|
|
assert(name != NULL);
|
|
|
|
assert(pt->params != NULL);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for(n = 0 ; pt->params[n].name != NULL ; n++) {
|
|
|
|
if(strcasecmp(pt->params[n].name,name) == 0)
|
|
|
|
ni = n;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ni < 0)
|
|
|
|
return 0;
|
|
|
|
|
2002-01-14 23:38:49 +00:00
|
|
|
if(pt->params[ni].name) free(pt->params[ni].name);
|
|
|
|
if(pt->params[ni].value) free(pt->params[ni].value);
|
|
|
|
|
2002-01-08 01:24:25 +00:00
|
|
|
if(n > 1) {
|
|
|
|
memmove(&pt->params[ni],&pt->params[ni+1],(n-ni)*sizeof(play_tree_param_t));
|
|
|
|
pt->params = (play_tree_param_t*)realloc(pt->params,n*sizeof(play_tree_param_t));
|
2002-01-14 23:38:49 +00:00
|
|
|
if(pt->params == NULL) {
|
|
|
|
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",n*sizeof(play_tree_param_t));
|
|
|
|
return -1;
|
|
|
|
}
|
2002-01-08 01:24:25 +00:00
|
|
|
} else {
|
|
|
|
free(pt->params);
|
|
|
|
pt->params = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-01-19 22:16:47 +00:00
|
|
|
static void
|
2002-01-14 23:38:49 +00:00
|
|
|
play_tree_iter_push_params(play_tree_iter_t* iter) {
|
|
|
|
int n;
|
|
|
|
play_tree_t* pt;
|
|
|
|
#ifdef MP_DEBUG
|
|
|
|
assert(iter != NULL);
|
|
|
|
assert(iter->config != NULL);
|
|
|
|
assert(iter->tree != NULL);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
pt = iter->tree;
|
|
|
|
|
2002-01-19 22:16:47 +00:00
|
|
|
// We always push a config because we can set some option
|
|
|
|
// while playing
|
|
|
|
m_config_push(iter->config);
|
|
|
|
|
2002-01-14 23:38:49 +00:00
|
|
|
if(pt->params == NULL)
|
2002-01-19 22:16:47 +00:00
|
|
|
return;
|
2002-01-14 23:38:49 +00:00
|
|
|
|
2002-01-19 22:16:47 +00:00
|
|
|
|
2002-01-14 23:38:49 +00:00
|
|
|
for(n = 0; pt->params[n].name != NULL ; n++) {
|
2002-01-21 10:45:53 +00:00
|
|
|
int e;
|
|
|
|
if((e = m_config_set_option(iter->config,pt->params[n].name,pt->params[n].value)) < 0) {
|
|
|
|
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Error %d while setting option '%s' with value '%s'\n",e,
|
2002-01-14 23:38:49 +00:00
|
|
|
pt->params[n].name,pt->params[n].value);
|
|
|
|
}
|
|
|
|
}
|
2002-01-17 20:24:28 +00:00
|
|
|
|
|
|
|
if(!pt->child)
|
|
|
|
iter->entry_pushed = 1;
|
2002-01-19 22:16:47 +00:00
|
|
|
return;
|
2002-01-14 23:38:49 +00:00
|
|
|
}
|
|
|
|
|
2002-01-08 01:24:25 +00:00
|
|
|
play_tree_iter_t*
|
2002-01-14 23:38:49 +00:00
|
|
|
play_tree_iter_new(play_tree_t* pt,m_config_t* config) {
|
2002-01-08 01:24:25 +00:00
|
|
|
play_tree_iter_t* iter;
|
|
|
|
|
2002-01-14 23:38:49 +00:00
|
|
|
#ifdef MP_DEBUG
|
2002-01-08 01:24:25 +00:00
|
|
|
assert(pt != NULL);
|
2002-01-14 23:38:49 +00:00
|
|
|
assert(config != NULL);
|
2002-01-08 01:24:25 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if( ! play_tree_is_valid(pt))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
iter = (play_tree_iter_t*)calloc(1,sizeof(play_tree_iter_t));
|
|
|
|
if(! iter) return NULL;
|
|
|
|
iter->root = pt;
|
|
|
|
iter->tree = NULL;
|
2002-01-14 23:38:49 +00:00
|
|
|
iter->config = config;
|
2002-01-08 01:24:25 +00:00
|
|
|
|
|
|
|
if(pt->parent)
|
|
|
|
iter->loop = pt->parent->loop;
|
|
|
|
|
|
|
|
return iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
play_tree_iter_free(play_tree_iter_t* iter) {
|
|
|
|
|
2002-01-14 23:38:49 +00:00
|
|
|
#ifdef MP_DEBUG
|
2002-01-08 01:24:25 +00:00
|
|
|
assert(iter != NULL);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(iter->status_stack) {
|
2002-01-14 23:38:49 +00:00
|
|
|
#ifdef MP_DEBUG
|
2002-01-08 01:24:25 +00:00
|
|
|
assert(iter->stack_size > 0);
|
|
|
|
#endif
|
|
|
|
free(iter->status_stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(iter);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
play_tree_iter_step(play_tree_iter_t* iter, int d,int with_nodes) {
|
|
|
|
play_tree_t* pt;
|
|
|
|
|
2002-01-14 23:38:49 +00:00
|
|
|
#ifdef MP_DEBUG
|
2002-01-08 01:24:25 +00:00
|
|
|
assert(iter != NULL);
|
|
|
|
assert(iter->root != NULL);
|
2002-01-14 23:38:49 +00:00
|
|
|
//printf("PT : Stepping = %d\n",d);
|
2002-01-08 01:24:25 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if(iter->tree == NULL) {
|
|
|
|
iter->tree = iter->root;
|
|
|
|
return play_tree_iter_step(iter,0,with_nodes);
|
|
|
|
}
|
|
|
|
|
2002-01-19 22:16:47 +00:00
|
|
|
if(iter->config && iter->entry_pushed > 0) {
|
2002-02-21 13:11:31 +00:00
|
|
|
iter->entry_pushed = 0;
|
2002-01-19 22:16:47 +00:00
|
|
|
m_config_pop(iter->config);
|
|
|
|
}
|
2002-01-14 23:38:49 +00:00
|
|
|
|
2002-01-17 20:24:28 +00:00
|
|
|
iter->file = -1;
|
2002-01-08 01:24:25 +00:00
|
|
|
if( d > 0 )
|
|
|
|
pt = iter->tree->next;
|
|
|
|
else if(d < 0)
|
|
|
|
pt = iter->tree->prev;
|
|
|
|
else
|
|
|
|
pt = iter->tree;
|
|
|
|
|
|
|
|
if(pt == NULL) { // No next
|
|
|
|
// Must we loop?
|
|
|
|
if(iter->tree->parent && iter->tree->parent->loop != 0 && ((d > 0 && iter->loop != 0) || ( d < 0 && (iter->loop < 0 || iter->loop < iter->tree->parent->loop) ) ) ) {
|
|
|
|
if(d > 0) { // Go back to the first one
|
|
|
|
for(pt = iter->tree ; pt->prev != NULL; pt = pt->prev)
|
|
|
|
/* NOTHNG */;
|
|
|
|
if(iter->loop > 0) iter->loop--;
|
|
|
|
} else if( d < 0 ) { // Or the last one
|
|
|
|
for(pt = iter->tree ; pt->next != NULL; pt = pt->next)
|
|
|
|
/* NOTHNG */;
|
|
|
|
if(iter->loop >= 0 && iter->loop < iter->tree->parent->loop) iter->loop++;
|
|
|
|
}
|
|
|
|
iter->tree = pt;
|
|
|
|
return play_tree_iter_step(iter,0,with_nodes);
|
|
|
|
}
|
|
|
|
// Go up one level
|
|
|
|
return play_tree_iter_up_step(iter,d,with_nodes);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Is there any valid childs ?
|
|
|
|
if(pt->child && play_tree_is_valid(pt->child)) {
|
|
|
|
iter->tree = pt;
|
|
|
|
if(with_nodes) { // Stop on the node
|
|
|
|
return PLAY_TREE_ITER_NODE;
|
|
|
|
} else // Or follow it
|
|
|
|
return play_tree_iter_down_step(iter,d,with_nodes);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Is it a valid enty ?
|
|
|
|
if(! play_tree_is_valid(pt)) {
|
|
|
|
if(d == 0) { // Can this happen ?
|
|
|
|
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"What to do now ???? Infinite loop if we continue\n");
|
|
|
|
return PLAY_TREE_ITER_ERROR;
|
|
|
|
} // Not a valid entry : go to next one
|
|
|
|
return play_tree_iter_step(iter,d,with_nodes);
|
|
|
|
}
|
|
|
|
|
2002-01-14 23:38:49 +00:00
|
|
|
#ifdef MP_DEBUG
|
|
|
|
assert(pt->files != NULL);
|
2002-01-08 01:24:25 +00:00
|
|
|
#endif
|
2002-01-17 20:24:28 +00:00
|
|
|
|
2002-01-08 01:24:25 +00:00
|
|
|
iter->tree = pt;
|
2002-01-17 20:24:28 +00:00
|
|
|
|
2002-01-08 01:24:25 +00:00
|
|
|
for(d = 0 ; iter->tree->files[d] != NULL ; d++)
|
|
|
|
/* NOTHING */;
|
|
|
|
iter->num_files = d;
|
2002-01-17 20:24:28 +00:00
|
|
|
|
2002-01-19 22:16:47 +00:00
|
|
|
if(iter->config) {
|
2002-01-17 20:24:28 +00:00
|
|
|
play_tree_iter_push_params(iter);
|
2002-02-21 13:11:31 +00:00
|
|
|
iter->entry_pushed = 1;
|
2002-01-19 22:16:47 +00:00
|
|
|
}
|
2002-01-08 01:24:25 +00:00
|
|
|
|
|
|
|
return PLAY_TREE_ITER_ENTRY;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
play_tree_is_valid(play_tree_t* pt) {
|
|
|
|
play_tree_t* iter;
|
|
|
|
|
2002-01-14 23:38:49 +00:00
|
|
|
#ifdef MP_DEBUG
|
2002-01-08 01:24:25 +00:00
|
|
|
assert(pt != NULL);
|
|
|
|
#endif
|
|
|
|
|
2002-01-17 20:24:28 +00:00
|
|
|
if(pt->entry_type != PLAY_TREE_ENTRY_NODE) {
|
|
|
|
#ifdef MP_DEBUG
|
|
|
|
assert(pt->child == NULL);
|
|
|
|
#endif
|
2002-01-08 01:24:25 +00:00
|
|
|
return 1;
|
2002-01-17 20:24:28 +00:00
|
|
|
}
|
2002-01-08 01:24:25 +00:00
|
|
|
else if (pt->child != NULL) {
|
|
|
|
for(iter = pt->child ; iter != NULL ; iter = iter->next) {
|
|
|
|
if(play_tree_is_valid(iter))
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
play_tree_iter_up_step(play_tree_iter_t* iter, int d,int with_nodes) {
|
|
|
|
|
2002-01-14 23:38:49 +00:00
|
|
|
#ifdef MP_DEBUG
|
2002-01-08 01:24:25 +00:00
|
|
|
assert(iter != NULL);
|
|
|
|
assert(iter->tree != NULL);
|
2002-01-14 23:38:49 +00:00
|
|
|
//printf("PT : Go UP\n");
|
2002-01-08 01:24:25 +00:00
|
|
|
#endif
|
|
|
|
|
2002-01-17 20:24:28 +00:00
|
|
|
iter->file = -1;
|
2002-01-08 01:24:25 +00:00
|
|
|
if(iter->tree->parent == iter->root->parent)
|
|
|
|
return PLAY_TREE_ITER_END;
|
|
|
|
|
2002-01-14 23:38:49 +00:00
|
|
|
#ifdef MP_DEBUG
|
2002-01-08 01:24:25 +00:00
|
|
|
assert(iter->tree->parent != NULL);
|
|
|
|
assert(iter->stack_size > 0);
|
|
|
|
assert(iter->status_stack != NULL);
|
|
|
|
#endif
|
2002-01-14 23:38:49 +00:00
|
|
|
|
2002-01-08 01:24:25 +00:00
|
|
|
iter->stack_size--;
|
|
|
|
iter->loop = iter->status_stack[iter->stack_size];
|
|
|
|
iter->status_stack = (int*)realloc(iter->status_stack,iter->stack_size*sizeof(int));
|
|
|
|
if(iter->stack_size > 0 && iter->status_stack == NULL) {
|
|
|
|
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",iter->stack_size*sizeof(char*));
|
|
|
|
return PLAY_TREE_ITER_ERROR;
|
|
|
|
}
|
|
|
|
iter->tree = iter->tree->parent;
|
2002-01-14 23:38:49 +00:00
|
|
|
|
|
|
|
// Pop subtree params
|
|
|
|
if(iter->config)
|
2002-01-19 22:16:47 +00:00
|
|
|
m_config_pop(iter->config);
|
2002-01-14 23:38:49 +00:00
|
|
|
|
2002-01-08 01:24:25 +00:00
|
|
|
return play_tree_iter_step(iter,d,with_nodes);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
play_tree_iter_down_step(play_tree_iter_t* iter, int d,int with_nodes) {
|
|
|
|
|
2002-01-14 23:38:49 +00:00
|
|
|
#ifdef MP_DEBUG
|
2002-01-08 01:24:25 +00:00
|
|
|
assert(iter->tree->files == NULL);
|
|
|
|
assert(iter->tree->child != NULL);
|
|
|
|
assert(iter->tree->child->parent == iter->tree);
|
2002-01-14 23:38:49 +00:00
|
|
|
//printf("PT : Go DOWN\n");
|
2002-01-08 01:24:25 +00:00
|
|
|
#endif
|
|
|
|
|
2002-01-17 20:24:28 +00:00
|
|
|
iter->file = -1;
|
2002-01-14 23:38:49 +00:00
|
|
|
|
|
|
|
// Push subtree params
|
|
|
|
if(iter->config)
|
|
|
|
play_tree_iter_push_params(iter);
|
|
|
|
|
2002-01-08 01:24:25 +00:00
|
|
|
iter->stack_size++;
|
|
|
|
iter->status_stack = (int*)realloc(iter->status_stack,iter->stack_size*sizeof(int));
|
|
|
|
if(iter->status_stack == NULL) {
|
|
|
|
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",iter->stack_size*sizeof(int));
|
|
|
|
return PLAY_TREE_ITER_ERROR;
|
|
|
|
}
|
|
|
|
iter->status_stack[iter->stack_size-1] = iter->loop;
|
|
|
|
// Set new status
|
|
|
|
iter->loop = iter->tree->loop-1;
|
|
|
|
if(d >= 0)
|
|
|
|
iter->tree = iter->tree->child;
|
|
|
|
else {
|
|
|
|
play_tree_t* pt;
|
|
|
|
for(pt = iter->tree->child ; pt->next != NULL ; pt = pt->next)
|
|
|
|
/*NOTING*/;
|
|
|
|
iter->tree = pt;
|
|
|
|
}
|
2002-01-14 23:38:49 +00:00
|
|
|
|
2002-01-08 01:24:25 +00:00
|
|
|
return play_tree_iter_step(iter,0,with_nodes);
|
|
|
|
}
|
|
|
|
|
2002-01-19 22:16:47 +00:00
|
|
|
// This is used as a file name for vcd/tv/dvd
|
|
|
|
char playtree_ret_filename[256];
|
|
|
|
|
2002-01-08 01:24:25 +00:00
|
|
|
char*
|
|
|
|
play_tree_iter_get_file(play_tree_iter_t* iter, int d) {
|
2002-01-17 20:24:28 +00:00
|
|
|
char* entry;
|
2002-01-14 23:38:49 +00:00
|
|
|
#ifdef MP_DEBUG
|
2002-01-08 01:24:25 +00:00
|
|
|
assert(iter != NULL);
|
|
|
|
assert(iter->tree->child == NULL);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(iter->tree->files == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2002-01-17 20:24:28 +00:00
|
|
|
#ifdef MP_DEBUG
|
|
|
|
assert(iter->num_files > 0);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(iter->file >= iter->num_files-1 || iter->file < -1)
|
|
|
|
return NULL;
|
|
|
|
|
2002-01-08 01:24:25 +00:00
|
|
|
if(d > 0) {
|
2002-01-17 20:24:28 +00:00
|
|
|
if(iter->file >= iter->num_files - 1)
|
|
|
|
iter->file = 0;
|
|
|
|
else
|
|
|
|
iter->file++;
|
2002-01-08 01:24:25 +00:00
|
|
|
} else if(d < 0) {
|
2002-01-17 20:24:28 +00:00
|
|
|
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 :
|
2002-01-19 22:16:47 +00:00
|
|
|
if(strlen(entry) == 0) entry = "1";
|
|
|
|
if(iter->config)
|
|
|
|
m_config_set_option(iter->config,"dvd",entry);
|
|
|
|
snprintf(playtree_ret_filename,255,"DVD title %s",entry);
|
|
|
|
return playtree_ret_filename;
|
2002-01-17 20:24:28 +00:00
|
|
|
case PLAY_TREE_ENTRY_VCD :
|
2002-01-19 22:16:47 +00:00
|
|
|
if(strlen(entry) == 0) entry = "1";
|
|
|
|
if(iter->config)
|
|
|
|
m_config_set_option(iter->config,"vcd",entry);
|
|
|
|
snprintf(playtree_ret_filename,255,"VCD track %s",entry);
|
|
|
|
return playtree_ret_filename;
|
2002-01-17 20:24:28 +00:00
|
|
|
case PLAY_TREE_ENTRY_TV :
|
|
|
|
{
|
2002-01-19 22:16:47 +00:00
|
|
|
if(strlen(entry) != 0) {
|
|
|
|
char *s,*e, *val = (char*)malloc(strlen(entry) + 11 + 1);
|
|
|
|
sprintf(val,"on:channel=%s",entry);
|
|
|
|
if(iter->config)
|
|
|
|
m_config_set_option(iter->config,"tv",val);
|
|
|
|
s = playtree_ret_filename + sprintf(playtree_ret_filename,"TV channel ");
|
|
|
|
e = strchr(entry,':');
|
|
|
|
if(!e) strncpy(s,entry,255-11);
|
|
|
|
else {
|
|
|
|
if(entry-e > 255) e = entry+255;
|
|
|
|
strncpy(s,entry,val-e);
|
|
|
|
s[val-e] = '\0';
|
|
|
|
}
|
|
|
|
return playtree_ret_filename;
|
|
|
|
} else {
|
|
|
|
if(iter->config)
|
|
|
|
m_config_set_option(iter->config,"tv","on");
|
|
|
|
return "TV";
|
|
|
|
}
|
2002-01-17 20:24:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return entry;
|
2002-01-08 01:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
play_tree_t*
|
|
|
|
play_tree_cleanup(play_tree_t* pt) {
|
|
|
|
play_tree_t* iter, *tmp, *first;
|
|
|
|
|
2002-01-14 23:38:49 +00:00
|
|
|
#ifdef MP_DEBUG
|
2002-01-08 01:24:25 +00:00
|
|
|
assert(pt != NULL);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if( ! play_tree_is_valid(pt)) {
|
|
|
|
play_tree_remove(pt,1,1);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
first = pt->child;
|
|
|
|
|
|
|
|
for(iter = pt->child ; iter != NULL ; ) {
|
|
|
|
tmp = iter;
|
|
|
|
iter = iter->next;
|
|
|
|
if(! play_tree_is_valid(tmp)) {
|
|
|
|
play_tree_remove(tmp,1,1);
|
|
|
|
if(tmp == first) first = iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(iter = first ; iter != NULL ; ) {
|
|
|
|
tmp = iter;
|
|
|
|
iter = iter->next;
|
|
|
|
play_tree_cleanup(tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
return pt;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
play_tree_iter_t*
|
|
|
|
play_tree_iter_new_copy(play_tree_iter_t* old) {
|
|
|
|
play_tree_iter_t* iter;
|
|
|
|
|
2002-01-14 23:38:49 +00:00
|
|
|
#ifdef MP_DEBUG
|
2002-01-08 01:24:25 +00:00
|
|
|
assert(old != NULL);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
iter = (play_tree_iter_t*)malloc(sizeof(play_tree_iter_t));
|
|
|
|
if(iter == NULL) {
|
|
|
|
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",sizeof(play_tree_iter_t));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
memcpy(iter,old,sizeof(play_tree_iter_t));
|
|
|
|
if(old->status_stack) {
|
|
|
|
iter->status_stack = (int*)malloc(old->stack_size * sizeof(int));
|
|
|
|
if(iter->status_stack == NULL) {
|
|
|
|
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",old->stack_size * sizeof(int));
|
|
|
|
free(iter);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
memcpy(iter->status_stack,old->status_stack,iter->stack_size*sizeof(int));
|
|
|
|
}
|
2002-01-14 23:38:49 +00:00
|
|
|
iter->config = NULL;
|
|
|
|
|
2002-01-08 01:24:25 +00:00
|
|
|
return iter;
|
|
|
|
}
|
2002-01-17 20:24:28 +00:00
|
|
|
|
|
|
|
|