[Mplayerxp-cvslog] SF.net SVN: mplayerxp:[602] mplayerxp
Brought to you by:
olov
From: <nic...@us...> - 2012-12-26 11:39:28
|
Revision: 602 http://mplayerxp.svn.sourceforge.net/mplayerxp/?rev=602&view=rev Author: nickols_k Date: 2012-12-26 11:39:18 +0000 (Wed, 26 Dec 2012) Log Message: ----------- First attempt to remove illegal-patch! Note: gdb shows that malefactor(s) didn't stop destructive attacks on my project and substituted justly coded class. Well, according on sources this class doesn't work with mp_conf at all. Starting program: /Data/-SF.NET-/MPXP/mplayerxp/mplayerxp/ffmpeg -ao alsa:hw:1 -vo x11 M/l.avi -v -v -v -v ... Breakpoint 1, mpxp::MPlayerXP (argc=10, argv=0x7fffffffda88, envp= 0x7fffffffdae0) at mplayerxp.cpp:1699 1699 if(!mp_conf.xp) { (gdb) n 1704 if(mp_conf.test_av) { (gdb) print mp_conf.verbose $6 = 0 (gdb) n 1710 xp_num_cpu=get_number_cpu(); (gdb) n 1712 get_mmx_optimizations(); (gdb) n 1714 if(mp_conf.shuffle_playback) MPXPSys.playtree->flags|=PLAY_TREE_RND; (gdb) n 1715 else MPXPSys.playtree->flags&=~PLAY_TREE_RND; (gdb) n 1717 MPXPSys.playtree = play_tree_cleanup(MPXPSys.playtree); (gdb) print mp_conf.verbose $7 = 0 (gdb) n 1718 if(MPXPSys.playtree) { (gdb) print mp_conf.verbose $8 = 0 (gdb) n 1717 MPXPSys.playtree = play_tree_cleanup(MPXPSys.playtree); (gdb) print mp_conf.verbose $9 = 0 (gdb) n 1718 if(MPXPSys.playtree) { (gdb) print mp_conf.verbose $10 = 0 (gdb) n 1719 MPXPSys.playtree_iter = new _PlayTree_Iter(MPXPSys.playtree,m_config); (gdb) print mp_conf.verbose $11 = 0 (gdb) n 1720 if(MPXPSys.playtree_iter) { (gdb) print mp_conf.verbose $12 = 0 (gdb) n 1719 MPXPSys.playtree_iter = new _PlayTree_Iter(MPXPSys.playtree,m_config); (gdb) print mp_conf.verbose $13 = 0 (gdb) n 1720 if(MPXPSys.playtree_iter) { (gdb) print mp_conf.verbose $14 = 0 (gdb) print mp_conf.verbose $15 = 0 (gdb) n 1721 if(MPXPSys.playtree_iter->step(0,0) != PLAY_TREE_ITER_ENTRY) { (gdb) print mp_conf.verbose $16 = 0 (gdb) n 1725 filename = MPXPSys.playtree_iter->get_file(1); (gdb) print mp_conf.verbose $17 = 2 (gdb) print filename $18 = {static npos = <optimized out>, _M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>}, _M_p = 0x1126058 <_ZNSs4_Rep20_S_empty_rep_storageE@@GLIBCXX_3.4+24> ""}} (gdb) n 1729 mpxp_context().engine().xp_core->num_a_buffs = vo_conf.xp_buffs; (gdb) print filename $19 = {static npos = <optimized out>, _M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>}, _M_p = 0x26770e8 "M/l.avi"}} (gdb) Modified Paths: -------------- mplayerxp/libmpconf/cfgparser.cpp mplayerxp/libmpconf/cfgparser.h mplayerxp/libmpconf/codec-cfg.cpp mplayerxp/libmpconf/subopt-helper.cpp mplayerxp/libmpsub/vobsub.cpp mplayerxp/libmpsub/vobsub.h mplayerxp/libplaytree/playtree.cpp mplayerxp/libplaytree/playtree.h mplayerxp/libplaytree/playtreeparser.cpp mplayerxp/mplayerxp.cpp mplayerxp/mplayerxp.h mplayerxp/postproc/libmenu/menu_pt.cpp Modified: mplayerxp/libmpconf/cfgparser.cpp =================================================================== --- mplayerxp/libmpconf/cfgparser.cpp 2012-12-25 16:17:37 UTC (rev 601) +++ mplayerxp/libmpconf/cfgparser.cpp 2012-12-26 11:39:18 UTC (rev 602) @@ -19,18 +19,15 @@ #include <string.h> #include <errno.h> -#define COMMAND_LINE 0 -#define CONFIG_FILE 1 +enum { + COMMAND_LINE=0, + CONFIG_FILE=1, -#define CONFIG_GLOBAL (1<<0) -#define CONFIG_RUNNING (1<<1) + CONFIG_GLOBAL=(1<<0), + CONFIG_RUNNING=(1<<1), -#define MAX_RECURSION_DEPTH 8 - -#ifdef MP_DEBUG -#include <assert.h> -#endif - + MAX_RECURSION_DEPTH=8 +}; #include "mplayerxp.h" #include "cfgparser.h" #include "libplaytree/playtree.h" @@ -51,14 +48,6 @@ config_save_t* save; int sl=0; -#ifdef MP_DEBUG - assert(config != NULL); - assert(config.cs_level >= 0); - assert(conf != NULL); - assert(opt != NULL); - assert( ! (conf->flags & CONF_NOSAVE)); -#endif - switch(conf->type) { case CONF_TYPE_PRINT : case CONF_TYPE_SUBCONFIG : @@ -116,13 +105,6 @@ config_save_t* iter=NULL; int i=-1; -#ifdef MP_DEBUG - assert(config != NULL); - assert(config.cs_level >= 0); - assert(save != NULL); -#endif - - arg = save->opt_name ? save->opt_name : save->opt->name; MSG_DBG2("Reverting option %s\n",arg); @@ -176,11 +158,6 @@ void m_config_push(m_config_t& config) { -#ifdef MP_DEBUG - assert(config != NULL); - assert(config.cs_level >= 0); -#endif - config.cs_level++; config.config_stack = (config_save_t**)mp_realloc(config.config_stack ,sizeof(config_save_t*)*(config.cs_level+1)); if(config.config_stack == NULL) { @@ -196,11 +173,6 @@ int i,ret= 1; config_save_t* cs; -#ifdef MP_DEBUG - assert(config != NULL); - //assert(config.cs_level > 0); -#endif - if(config.config_stack[config.cs_level] != NULL) { cs = config.config_stack[config.cs_level]; for(i=0; cs[i].opt != NULL ; i++ ) { @@ -221,9 +193,6 @@ } m_config_t& m_config_new(play_tree_t* pt,libinput_t&libinput) { -#ifdef MP_DEBUG - assert(pt != NULL); -#endif m_config_t& config = *new(zeromem) m_config_t(libinput); config.config_stack = (config_save_t**)mp_calloc(1,sizeof(config_save_t*)); SET_GLOBAL(config); // We always start with global options @@ -240,9 +209,6 @@ void m_config_free(m_config_t* config) { unsigned i; -#ifdef MP_DEBUG - assert(config != NULL); -#endif for(i=0;i<config->dynasize;i++) delete config->dynamics[i]; delete config->dynamics; config->dynasize=0; @@ -254,16 +220,6 @@ static int init_conf(m_config_t& config, int mode) { -#ifdef MP_DEBUG - assert(config != NULL); - assert(config.pt != NULL); - assert(config.last_entry == NULL || config.last_entry->parent == config.pt); - - if (mode != COMMAND_LINE && mode != CONFIG_FILE) { - MSG_ERR( "init_conf: wrong mode!\n"); - return -1; - } -#endif config.parser_mode = mode; config.dynamics=NULL; config.dynasize=0; @@ -274,10 +230,6 @@ static int config_is_entry_option(m_config_t& config,const char *opt,const char *param) { play_tree_t* entry = NULL; -#ifdef MP_DEBUG - assert(config.pt != NULL); -#endif - if(strcasecmp(opt,"playlist") == 0) { // We handle playlist here if(!param) return ERR_MISSING_PARAM; @@ -316,11 +268,6 @@ char *endptr; const config_t* conf=NULL; -#ifdef MP_DEBUG - assert(config != NULL); - assert(conf_list != NULL); - assert(opt != NULL); -#endif MSG_DBG3( "read_option: conf=%p opt='%s' param='%s'\n", conf, opt, param); for(nconf = 0 ; conf_list[nconf] != NULL; nconf++) { @@ -496,67 +443,6 @@ } ret = 1; break; -#if 0 -// we have handled it in other function - case CONF_TYPE_SUBCONFIG: - { - char *subparam; - char *subopt; - int subconf_optnr; - config_t *subconf; - config_t *sublist[] = { NULL , NULL }; - char *token; - char *p; - - if (param == NULL) - goto err_missing_param; - - subparam = new char [strlen(param)+1]; - subopt = new char [strlen(param)+1]; - p = mp_strdup(param); // In case that param is a static string (cf man strtok) - - subconf = conf[i].p; - sublist[0] = subconf; - for (subconf_optnr = 0; subconf[subconf_optnr].name != NULL; subconf_optnr++) - /* NOTHING */; - config.sub_conf = opt; - token = strtok(p, (char *)&(":")); - while(token) - { - int sscanf_ret; - /* clear out */ - subopt[0] = subparam[0] = 0; - - sscanf_ret = sscanf(token, "%[^=]=%s", subopt, subparam); - - MSG_DBG3( "token: '%s', i=%d, subopt='%s', subparam='%s' (ret: %d)\n", token, i, subopt, subparam, sscanf_ret); - switch(sscanf_ret) - { - case 1: - subparam[0] = 0; - case 2: - if ((ret = config_read_option(config,sublist, subopt, subparam)) < 0) - { - MSG_ERR( "Subconfig parsing returned error: %d in token: %s\n", - ret, token); - goto out; - } - break; - default: - MSG_ERR( "Invalid subconfig argument! ('%s')\n", token); - ret = ERR_NOT_AN_OPTION; - goto out; - } - token = strtok(NULL, (char *)&(":")); - } - config.sub_conf = NULL; - delete subparam; - delete subopt; - delete p; - ret = 1; - break; - } -#endif case CONF_TYPE_PRINT: MSG_INFO("%s", (char *) conf[i].p); exit(1); @@ -568,9 +454,6 @@ if(ret >= 0 && ! IS_RUNNING(config) && ! IS_GLOBAL(config) && ! (conf[i].flags & CONF_GLOBAL) && conf[i].type != CONF_TYPE_SUBCONFIG ) { play_tree_t* dest = config.last_entry ? config.last_entry : config.last_parent; char* o; -#ifdef MP_DEBUG - assert(dest != NULL); -#endif if(config.sub_conf) { o = new char [(strlen(config.sub_conf) + 1 + strlen(opt) + 1)]; sprintf(o,"%s:%s",config.sub_conf,opt); @@ -596,14 +479,9 @@ int m_config_set_option(m_config_t& config,const char *opt,const char *param) { const char *e; const config_t**clist=config.opt_list; -#ifdef MP_DEBUG - assert(config != NULL); - assert(config.opt_list != NULL); - assert(opt != NULL); -#endif MSG_DBG2( "Setting option %s=%s\n",opt,param); clist = config.opt_list; -#if 1 + if(strchr(opt,'.')) { int flg,ret; const config_t *subconf=NULL; @@ -633,7 +511,7 @@ config.flags=flg; return ret; } -#endif + e = strchr(opt,':'); if(e && e[1] != '\0') { int ret; @@ -658,12 +536,12 @@ return config_read_option(config,config.opt_list,opt,param); } +static void PRINT_LINENUM(const std::string& conffile,int line_num) { mpxp_err<<conffile<<"("<<line_num<<")"<<std::endl; } +static const int MAX_LINE_LEN=1000; +static const int MAX_OPT_LEN=100; +static const int MAX_PARAM_LEN=100; MPXP_Rc m_config_parse_config_file(m_config_t& config,const char *conffile) { -#define PRINT_LINENUM MSG_ERR("%s(%d): ", conffile, line_num) -#define MAX_LINE_LEN 1000 -#define MAX_OPT_LEN 100 -#define MAX_PARAM_LEN 100 FILE *fp; char *line; char opt[MAX_OPT_LEN + 1]; @@ -677,10 +555,6 @@ MPXP_Rc ret = MPXP_Ok; int errors = 0; -#ifdef MP_DEBUG - assert(config != NULL); - // assert(conf_list != NULL); -#endif if (++config.recursion_depth > 1) MSG_INFO("Reading config file: %s", conffile); if (config.recursion_depth > MAX_RECURSION_DEPTH) { @@ -730,34 +604,29 @@ line[line_pos] != '='; /* NOTHING */) { opt[opt_pos++] = line[line_pos++]; if (opt_pos >= MAX_OPT_LEN) { - PRINT_LINENUM; - MSG_ERR("too long option\n"); + PRINT_LINENUM(conffile,line_num); + mpxp_err<<"too long option"<<std::endl; errors++; ret = MPXP_False; goto nextline; } } if (opt_pos == 0) { - PRINT_LINENUM; - MSG_ERR("parse error\n"); + PRINT_LINENUM(conffile,line_num); + mpxp_err<<"parse error"<<std::endl; ret = MPXP_False; errors++; continue; } opt[opt_pos] = '\0'; -#ifdef MP_DEBUG - PRINT_LINENUM; - MSG_DBG2("option: %s\n", opt); -#endif - /* skip whitespaces */ while (isspace(line[line_pos])) ++line_pos; /* check '=' */ if (line[line_pos++] != '=') { - PRINT_LINENUM; - MSG_ERR("option without parameter\n"); + PRINT_LINENUM(conffile,line_num); + mpxp_err<<"option without parameter"<<std::endl; ret = MPXP_False; errors++; continue; @@ -773,8 +642,8 @@ for (param_pos = 0; line[line_pos] != c; /* NOTHING */) { param[param_pos++] = line[line_pos++]; if (param_pos >= MAX_PARAM_LEN) { - PRINT_LINENUM; - MSG_ERR("too long parameter\n"); + PRINT_LINENUM(conffile,line_num); + mpxp_err<<"too long parameter"<<std::endl; ret = MPXP_False; errors++; goto nextline; @@ -786,8 +655,8 @@ && line[line_pos] != '#'; /* NOTHING */) { param[param_pos++] = line[line_pos++]; if (param_pos >= MAX_PARAM_LEN) { - PRINT_LINENUM; - MSG_ERR("too long parameter\n"); + PRINT_LINENUM(conffile,line_num); + mpxp_err<<"too long parameter"<<std::endl; ret = MPXP_False; errors++; goto nextline; @@ -798,26 +667,21 @@ /* did we read a parameter? */ if (param_pos == 0) { - PRINT_LINENUM; - MSG_ERR("option without parameter\n"); + PRINT_LINENUM(conffile,line_num); + mpxp_err<<"option without parameter"<<std::endl; ret = MPXP_False; errors++; continue; } -#ifdef MP_DEBUG - PRINT_LINENUM; - MSG_DBG2("parameter: %s\n", param); -#endif - /* now, check if we have some more chars on the line */ /* whitespace... */ while (isspace(line[line_pos])) ++line_pos; /* EOL / comment */ if (line[line_pos] != '\0' && line[line_pos] != '#') { - PRINT_LINENUM; - MSG_ERR("extra characters on line: %s\n", line+line_pos); + PRINT_LINENUM(conffile,line_num); + mpxp_err<<"extra characters on line: "<<line+line_pos<<std::endl; ret = MPXP_False; } @@ -828,8 +692,8 @@ case ERR_OUT_OF_RANGE: case ERR_NO_SUBCONF: case ERR_FUNC_ERR: - PRINT_LINENUM; - MSG_ERR("%s\n", opt); + PRINT_LINENUM(conffile,line_num); + mpxp_err<<opt<<std::endl; ret = MPXP_False; errors++; continue; @@ -846,7 +710,8 @@ return ret; } -MPXP_Rc m_config_parse_command_line(m_config_t& config, int argc, char **argv, char **envp) +namespace mpxp { +MPXP_Rc mpxp_parse_command_line(m_config_t& config, int argc, char **argv, char **envp) { int i; int tmp; @@ -854,14 +719,6 @@ int no_more_opts = 0; UNUSED(envp); -#ifdef MP_DEBUG - assert(config != NULL); - assert(config.pt != NULL); - assert(argv != NULL); - assert(envp != NULL); - assert(argc >= 1); -#endif - if (init_conf(config, COMMAND_LINE) == -1) return MPXP_False; if(config.last_parent == NULL) config.last_parent = config.pt; /* in order to work recursion detection properly in parse_config_file */ @@ -972,25 +829,17 @@ UNSET_GLOBAL(config); SET_RUNNING(config); return MPXP_Ok; -#if 0 -err_out_mem: - MSG_ERR( "can't allocate memory for filenames (%s)\n", strerror(errno)); -#endif err_out: --config.recursion_depth; MSG_ERR( "command line: %s\n", argv[i]); return MPXP_False; } +} // namespace mpxp int m_config_register_options(m_config_t& config,const config_t *args) { int list_len = 0; const config_t** conf_list = config.opt_list; -#ifdef MP_DEBUG - assert(config != NULL); - assert(args != NULL); -#endif - if(conf_list) { for ( ; conf_list[list_len] != NULL; list_len++) /* NOTHING */; @@ -1029,11 +878,6 @@ const config_t **conf_list; const config_t* cl[] = { NULL, NULL }; -#ifdef MP_DEBUG - assert(config != NULL); - assert(arg != NULL); -#endif - e = strchr(arg,':'); if(e) { @@ -1052,11 +896,6 @@ any_t* m_config_get_option_ptr(const m_config_t& config,const char* arg) { const config_t* conf; -#ifdef MP_DEBUG - assert(config != NULL); - assert(arg != NULL); -#endif - conf = m_config_get_option(config,arg); if(!conf) return NULL; return conf->p; @@ -1065,11 +904,6 @@ int m_config_get_int (const m_config_t& config,const char* arg,int* err_ret) { int *ret; -#ifdef MP_DEBUG - assert(config != NULL); - assert(arg != NULL); -#endif - ret = (int*)m_config_get_option_ptr(config,arg); if(err_ret) *err_ret = 0; @@ -1084,11 +918,6 @@ float m_config_get_float (const m_config_t& config,const char* arg,int* err_ret) { float *ret; -#ifdef MP_DEBUG - assert(config != NULL); - assert(arg != NULL); -#endif - ret = (float*)m_config_get_option_ptr(config,arg); if(err_ret) *err_ret = 0; @@ -1106,11 +935,6 @@ int m_config_set_int(m_config_t& config,const char* arg,int val) { const config_t* opt; -#ifdef MP_DEBUG - assert(config != NULL); - assert(arg != NULL); -#endif - opt = m_config_get_option(config,arg); if(!opt || opt->type != CONF_TYPE_INT) @@ -1130,11 +954,6 @@ int m_config_set_float(m_config_t& config,const char* arg,float val) { const config_t* opt; -#ifdef MP_DEBUG - assert(config != NULL); - assert(arg != NULL); -#endif - opt = m_config_get_option(config,arg); if(!opt || opt->type != CONF_TYPE_FLOAT) @@ -1155,11 +974,6 @@ int m_config_switch_flag(m_config_t& config,const char* opt) { const config_t *conf; -#ifdef MP_DEBUG - assert(config != NULL); - assert(opt != NULL); -#endif - conf = m_config_get_option(config,opt); if(!conf || conf->type != CONF_TYPE_FLAG) return 0; if( AS_INT(conf) == conf->min) AS_INT(conf,conf->max); @@ -1172,11 +986,6 @@ int m_config_set_flag(m_config_t& config,const char* opt, int state) { const config_t *conf; -#ifdef MP_DEBUG - assert(config != NULL); - assert(opt != NULL); -#endif - conf = m_config_get_option(config,opt); if(!conf || conf->type != CONF_TYPE_FLAG) return 0; if(state) AS_INT(conf,conf->max); @@ -1186,11 +995,6 @@ int m_config_get_flag(const m_config_t& config,const char* opt) { -#ifdef MP_DEBUG - assert(config != NULL); - assert(opt != NULL); -#endif - const config_t* conf = m_config_get_option(config,opt); if(!conf || conf->type != CONF_TYPE_FLAG) return -1; if(AS_INT(conf) == conf->max) return 1; @@ -1203,11 +1007,6 @@ config_save_t* save; int l,i; -#ifdef MP_DEBUG - assert(config != NULL); - assert(arg != NULL); -#endif - opt = m_config_get_option(config,arg); if(!opt) @@ -1325,5 +1124,3 @@ j++; }; } - -#undef AS_INT Modified: mplayerxp/libmpconf/cfgparser.h =================================================================== --- mplayerxp/libmpconf/cfgparser.h 2012-12-25 16:17:37 UTC (rev 601) +++ mplayerxp/libmpconf/cfgparser.h 2012-12-26 11:39:18 UTC (rev 602) @@ -89,7 +89,9 @@ * -1 on error (invalid option...) * 1 otherwise */ -MPXP_Rc m_config_parse_command_line(m_config_t& config, int argc, char **argv, char **envp); +namespace mpxp { + MPXP_Rc mpxp_parse_command_line(m_config_t& config, int argc, char **argv, char **envp); +} m_config_t& m_config_new(play_tree_t* pt,libinput_t&libinput); Modified: mplayerxp/libmpconf/codec-cfg.cpp =================================================================== --- mplayerxp/libmpconf/codec-cfg.cpp 2012-12-25 16:17:37 UTC (rev 601) +++ mplayerxp/libmpconf/codec-cfg.cpp 2012-12-26 11:39:18 UTC (rev 602) @@ -18,7 +18,6 @@ #include <unistd.h> #include <errno.h> #include <ctype.h> -#include <assert.h> #include <string.h> // for mmioFOURCC: Modified: mplayerxp/libmpconf/subopt-helper.cpp =================================================================== --- mplayerxp/libmpconf/subopt-helper.cpp 2012-12-25 16:17:37 UTC (rev 601) +++ mplayerxp/libmpconf/subopt-helper.cpp 2012-12-26 11:39:18 UTC (rev 602) @@ -22,15 +22,10 @@ #include <stdlib.h> #include <string.h> #include <limits.h> -#include <assert.h> #include "subopt-helper.h" #include "global_msg.h" -#ifndef MP_DEBUG - #define NDEBUG -#endif - /* prototypes for argument parsing */ static char const * parse_int( char const * const str, int * const valp ); static char const * parse_str( char const * const str, strarg_t * const valp ); @@ -99,8 +94,6 @@ /* option was found */ next = 1; - assert( opts[idx].valp && "Need a pointer to store the arg!" ); - /* type specific code */ if ( opts[idx].type == OPT_ARG_BOOL ) { @@ -164,7 +157,6 @@ (float *)opts[idx].valp ); break; default: - assert( 0 && "Arg type of suboption doesn't exist!" ); last = NULL; // break parsing! } @@ -238,8 +230,6 @@ { char * endp; - assert( str && "parse_int(): str == NULL" ); - *valp = (int)strtol( str, &endp, 0 ); /* nothing was converted */ @@ -252,8 +242,6 @@ { char * endp; - assert( str && "parse_float(): str == NULL" ); - *valp = strtod( str, &endp ); /* nothing was converted */ @@ -262,7 +250,7 @@ return endp; } -#define QUOTE_CHAR '%' +static const char QUOTE_CHAR='%'; static char const * parse_str( char const * str, strarg_t * const valp ) { char const * match = strchr( str, ':' ); Modified: mplayerxp/libmpsub/vobsub.cpp =================================================================== --- mplayerxp/libmpsub/vobsub.cpp 2012-12-25 16:17:37 UTC (rev 601) +++ mplayerxp/libmpsub/vobsub.cpp 2012-12-26 11:39:18 UTC (rev 602) @@ -82,7 +82,7 @@ int fd; }; -static mpeg_t * __FASTCALL__ mpeg_open(const char *filename) +static mpeg_t * __FASTCALL__ mpeg_open(const std::string& filename) { mpeg_t *res = new(zeromem) mpeg_t; int err = res == NULL; @@ -93,7 +93,7 @@ res->packet = NULL; res->packet_size = 0; res->packet_reserve = 0; - fd = open(filename, O_RDONLY); + fd = ::open(filename.c_str(), O_RDONLY); err = fd < 0; if (!err) { res->stream = new(zeromem) Stream(Stream::Type_Seekable); @@ -297,7 +297,7 @@ }; struct packet_queue_t { - char *id; + std::string id; packet_t *packets; unsigned int packets_reserve; unsigned int packets_size; @@ -320,7 +320,7 @@ static void __FASTCALL__ packet_queue_construct(packet_queue_t *queue) { - queue->id = NULL; + queue->id = ""; queue->packets = NULL; queue->packets_reserve = 0; queue->packets_size = 0; @@ -439,25 +439,16 @@ return 0; } -static int __FASTCALL__ vobsub_add_id(vobsub_t *vob, const char *id, size_t idlen, const unsigned int _index) +static int __FASTCALL__ vobsub_add_id(vobsub_t *vob, const std::string& id, const unsigned int _index) { if (vobsub_ensure_spu_stream(vob, _index) < 0) return -1; - if (id && idlen) { - if (vob->spu_streams[_index].id) - delete vob->spu_streams[_index].id; - vob->spu_streams[_index].id = new char [idlen + 1]; - if (vob->spu_streams[_index].id == NULL) { - MSG_ERR("vobsub_add_id: mp_malloc failure"); - return -1; - } - vob->spu_streams[_index].id[idlen] = 0; - memcpy(vob->spu_streams[_index].id, id, idlen); + if (!id.empty()) { + vob->spu_streams[_index].id=id; } vob->spu_streams_current = _index; if (mp_conf.verbose) - MSG_ERR( "[vobsub] subtitle (vobsubid): %d language %s\n", - _index, vob->spu_streams[_index].id); + mpxp_err<<"[vobsub] subtitle (vobsubid): "<<_index<<" language "<<vob->spu_streams[_index].id<<std::endl; return 0; } @@ -503,7 +494,7 @@ ++q; if (!isdigit(*q)) return -1; - return vobsub_add_id(vob, p, idlen, atoi(q)); + return vobsub_add_id(vob, p, atoi(q)); } static int __FASTCALL__ vobsub_parse_timestamp(vobsub_t *vob, const char *line) @@ -778,23 +769,23 @@ return res; } -int __FASTCALL__ vobsub_parse_ifo(any_t* _vob, const char *const name, unsigned int *palette, unsigned int *width, unsigned int *height, int force, int sid, char *langid) +int __FASTCALL__ vobsub_parse_ifo(any_t* _vob, const std::string& name, unsigned int *palette, unsigned int *width, unsigned int *height, int force, int sid, std::string& langid) { vobsub_t *vob = (vobsub_t*)_vob; int res = -1; - FILE *fd = fopen(name, "rb"); + FILE *fd = ::fopen(name.c_str(), "rb"); if (fd == NULL) { if (force) - MSG_WARN("VobSub: Can't open IFO file\n"); + mpxp_warn<<"VobSub: Can't open IFO file"<<std::endl; } else { // parse IFO header unsigned char block[0x800]; const char *const ifo_magic = "DVDVIDEO-VTS"; if (fread(block, sizeof(block), 1, fd) != 1) { if (force) - MSG_ERR("VobSub: Can't read IFO header\n"); + mpxp_err<<"VobSub: Can't read IFO header"<<std::endl; } else if (memcmp(block, ifo_magic, strlen(ifo_magic) + 1)) - MSG_ERR("VobSub: Bad magic in IFO header\n"); + mpxp_err<<"VobSub: Bad magic in IFO header"<<std::endl; else { unsigned long pgci_sector = block[0xcc] << 24 | block[0xcd] << 16 | block[0xce] << 8 | block[0xcf]; @@ -817,17 +808,15 @@ *height /= 2; break; default: - MSG_WARN("Vobsub: Unknown resolution %d \n", resolution); + mpxp_warn<<"Vobsub: Unknown resolution "<<resolution<<std::endl; } - if (langid && 0 <= sid && sid < 32) { - unsigned char *tmp = block + 0x256 + sid * 6 + 2; - langid[0] = tmp[0]; - langid[1] = tmp[1]; - langid[2] = 0; + if (!langid.empty() && 0 <= sid && sid < 32) { + char *tmp = (char *)block + 0x256 + sid * 6 + 2; + langid.assign(tmp,2); } if (fseek(fd, pgci_sector * sizeof(block), SEEK_SET) || fread(block, sizeof(block), 1, fd) != 1) - MSG_ERR("VobSub: Can't read IFO PGCI\n"); + mpxp_err<<"VobSub: Can't read IFO PGCI"<<std::endl; else { unsigned long idx; unsigned long pgc_offset = block[0xc] << 24 | block[0xd] << 16 @@ -846,13 +835,12 @@ return res; } -any_t* __FASTCALL__ vobsub_open(const char *const name,const char *const ifo,const int force,any_t** spu) +any_t* __FASTCALL__ vobsub_open(const std::string& name,const char *const ifo,const int force,any_t** spu) { vobsub_t *vob = new(zeromem) vobsub_t; if(spu) *spu = NULL; if (vob) { - char *buf; vob->custom = 0; vob->have_palette = 0; vob->orig_frame_width = 0; @@ -862,107 +850,95 @@ vob->spu_streams_current = 0; vob->delay = 0; vob->forced_subs=0; - buf = new char [strlen(name) + 5]; - if (buf) { - FILE *fd; - mpeg_t *mpg; - /* read in the info file */ - if(!ifo) { - strcpy(buf, name); - strcat(buf, ".ifo"); - vobsub_parse_ifo(vob,buf, vob->palette, &vob->orig_frame_width, &vob->orig_frame_height, force, -1, NULL); - } else - vobsub_parse_ifo(vob,ifo, vob->palette, &vob->orig_frame_width, &vob->orig_frame_height, force, -1, NULL); - /* read in the index */ - strcpy(buf, name); - strcat(buf, ".idx"); - fd = fopen(buf, "rb"); - if (fd == NULL) { - if(force) - MSG_ERR("VobSub: Can't open IDX file\n"); - else { - delete buf; - delete vob; - return NULL; - } - } else { - while (vobsub_parse_one_line(vob, fd) >= 0) - /* NOOP */ ; - fclose(fd); + std::string buf; + FILE *fd; + mpeg_t *mpg; + /* read in the info file */ + std::string stmp=""; + if(!ifo) { + buf=name+".ifo"; + vobsub_parse_ifo(vob,buf, vob->palette, &vob->orig_frame_width, &vob->orig_frame_height, force, -1, stmp); + } else + vobsub_parse_ifo(vob,ifo, vob->palette, &vob->orig_frame_width, &vob->orig_frame_height, force, -1, stmp); + /* read in the index */ + buf=name+".idx"; + fd = ::fopen(buf.c_str(), "rb"); + if (fd == NULL) { + if(force) + mpxp_err<<"VobSub: Can't open IDX file"<<std::endl; + else { + delete vob; + return NULL; } - /* if no palette in .idx then use custom colors */ - if ((vob->custom == 0)&&(vob->have_palette!=1)) - vob->custom = 1; - if (spu && vob->orig_frame_width && vob->orig_frame_height) - *spu = spudec_new_scaled_vobsub(vob->palette, vob->cuspal, vob->custom, vob->orig_frame_width, vob->orig_frame_height); + } else { + while (vobsub_parse_one_line(vob, fd) >= 0) /* NOOP */ ; + ::fclose(fd); + } + /* if no palette in .idx then use custom colors */ + if ((vob->custom == 0)&&(vob->have_palette!=1)) + vob->custom = 1; + if (spu && vob->orig_frame_width && vob->orig_frame_height) + *spu = spudec_new_scaled_vobsub(vob->palette, vob->cuspal, vob->custom, vob->orig_frame_width, vob->orig_frame_height); - /* read the indexed mpeg_stream */ - strcpy(buf, name); - strcat(buf, ".sub"); - mpg = mpeg_open(buf); - if (mpg == NULL) { - if(force) - MSG_ERR("VobSub: Can't open SUB file\n"); - else { - - delete buf; + /* read the indexed mpeg_stream */ + buf=name+".sub"; + mpg = mpeg_open(buf); + if (mpg == NULL) { + if(force) mpxp_err<<"VobSub: Can't open SUB file"<<std::endl; + else { delete vob; return NULL; - } - } else { - long last_pts_diff = 0; - while (!mpeg_eof(mpg)) { - off_t pos = mpeg_tell(mpg); - if (mpeg_run(mpg) < 0) { - if (!mpeg_eof(mpg)) - MSG_ERR("VobSub: mpeg_run error\n"); - break; - } - if (mpg->packet_size) { - if ((mpg->aid & 0xe0) == 0x20) { - unsigned int sid = mpg->aid & 0x1f; - if (vobsub_ensure_spu_stream(vob, sid) >= 0) { - packet_queue_t *queue = vob->spu_streams + sid; - /* get the packet to fill */ - if (queue->packets_size == 0 && packet_queue_grow(queue) < 0) - abort(); - while (queue->current_index + 1 < queue->packets_size - && queue->packets[queue->current_index + 1].filepos <= pos) - ++queue->current_index; - if (queue->current_index < queue->packets_size) { - packet_t *pkt; - if (queue->packets[queue->current_index].data) { - /* insert a new packet and fix the PTS ! */ - packet_queue_insert(queue); - queue->packets[queue->current_index].pts100 = - mpg->pts + last_pts_diff; - } - pkt = queue->packets + queue->current_index; - if (pkt->pts100 != UINT_MAX) { - if (queue->packets_size > 1) - last_pts_diff = pkt->pts100 - mpg->pts; - else - pkt->pts100 = mpg->pts; - /* FIXME: should not use mpg_sub internal informations, make a copy */ - pkt->data = mpg->packet; - pkt->size = mpg->packet_size; - mpg->packet = NULL; - mpg->packet_reserve = 0; - mpg->packet_size = 0; - } + } + } else { + long last_pts_diff = 0; + while (!mpeg_eof(mpg)) { + off_t pos = mpeg_tell(mpg); + if (mpeg_run(mpg) < 0) { + if (!mpeg_eof(mpg)) mpxp_err<<"VobSub: mpeg_run error"<<std::endl; + break; + } + if (mpg->packet_size) { + if ((mpg->aid & 0xe0) == 0x20) { + unsigned int sid = mpg->aid & 0x1f; + if (vobsub_ensure_spu_stream(vob, sid) >= 0) { + packet_queue_t *queue = vob->spu_streams + sid; + /* get the packet to fill */ + if (queue->packets_size == 0 && packet_queue_grow(queue) < 0) + abort(); + while (queue->current_index + 1 < queue->packets_size + && queue->packets[queue->current_index + 1].filepos <= pos) + ++queue->current_index; + if (queue->current_index < queue->packets_size) { + packet_t *pkt; + if (queue->packets[queue->current_index].data) { + /* insert a new packet and fix the PTS ! */ + packet_queue_insert(queue); + queue->packets[queue->current_index].pts100 = + mpg->pts + last_pts_diff; } + pkt = queue->packets + queue->current_index; + if (pkt->pts100 != UINT_MAX) { + if (queue->packets_size > 1) + last_pts_diff = pkt->pts100 - mpg->pts; + else + pkt->pts100 = mpg->pts; + /* FIXME: should not use mpg_sub internal informations, make a copy */ + pkt->data = mpg->packet; + pkt->size = mpg->packet_size; + mpg->packet = NULL; + mpg->packet_reserve = 0; + mpg->packet_size = 0; + } } - else - MSG_WARN("don't know what to do with subtitle #%u\n", sid); } + else mpxp_warn<<"don't know what to do with subtitle #"<<sid<<std::endl; } } - vob->spu_streams_current = vob->spu_streams_size; - while (vob->spu_streams_current-- > 0) - vob->spu_streams[vob->spu_streams_current].current_index = 0; - mpeg_free(mpg); } - delete buf; + vob->spu_streams_current = vob->spu_streams_size; + while (vob->spu_streams_current-- > 0) + vob->spu_streams[vob->spu_streams_current].current_index = 0; + mpeg_free(mpg); } } return vob; @@ -989,10 +965,10 @@ } } -char * __FASTCALL__ vobsub_get_id(any_t*vobhandle, unsigned int _index) +std::string __FASTCALL__ vobsub_get_id(any_t*vobhandle, unsigned int _index) { vobsub_t *vob = (vobsub_t *) vobhandle; - return (_index < vob->spu_streams_size) ? vob->spu_streams[_index].id : NULL; + return (_index < vob->spu_streams_size) ? vob->spu_streams[_index].id : ""; } unsigned int __FASTCALL__ vobsub_get_forced_subs_flag(void const * const vobhandle) @@ -1003,21 +979,22 @@ return 0; } -int __FASTCALL__ vobsub_set_from_lang(any_t*vobhandle,const char * lang) +int __FASTCALL__ vobsub_set_from_lang(any_t*vobhandle,const std::string& lang) { unsigned i; + size_t pos=0; vobsub_t *vob= (vobsub_t *) vobhandle; - while(lang && strlen(lang) >= 2){ + while(!lang.empty() && lang.length() >= 2){ for(i=0; i < vob->spu_streams_size; i++) - if (vob->spu_streams[i].id) - if ((strncmp(vob->spu_streams[i].id, lang, 2)==0)){ + if (!vob->spu_streams[i].id.empty()) + if (vob->spu_streams[i].id==lang.substr(pos,2)){ mp_conf.vobsub_id=i; - MSG_INFO("Selected VOBSUB language: %d language: %s\n", i, vob->spu_streams[i].id); + mpxp_info<<"Selected VOBSUB language: "<<i<<" language: "<<vob->spu_streams[i].id<<std::endl; return 0; } - lang+=2;while (lang[0]==',' || lang[0]==' ') ++lang; + pos+=2;while (lang[pos]==',' || lang[pos]==' ') ++pos; } - MSG_WARN("No matching VOBSUB language found!\n"); + mpxp_warn<<"No matching VOBSUB language found!"<<std::endl; return -1; } @@ -1035,7 +1012,7 @@ } if (vob->spu_streams && 0 <= mp_conf.vobsub_id && (unsigned) mp_conf.vobsub_id < vob->spu_streams_size) { /* do not seek if we don't know the id */ - if (vobsub_get_id(vob, mp_conf.vobsub_id) == NULL) return; + if (vobsub_get_id(vob, mp_conf.vobsub_id).empty()) return; queue = vob->spu_streams + mp_conf.vobsub_id; queue->current_index = 0; while (queue->current_index < queue->packets_size Modified: mplayerxp/libmpsub/vobsub.h =================================================================== --- mplayerxp/libmpsub/vobsub.h 2012-12-25 16:17:37 UTC (rev 601) +++ mplayerxp/libmpsub/vobsub.h 2012-12-26 11:39:18 UTC (rev 602) @@ -3,13 +3,13 @@ #include "libmpdemux/demuxer.h" // for seek_args_t -extern any_t* __FASTCALL__ vobsub_open(const char *subname, const char *const ifo, const int force, any_t** spu); +extern any_t* __FASTCALL__ vobsub_open(const std::string& subname, const char *const ifo, const int force, any_t** spu); extern void __FASTCALL__ vobsub_close(any_t*__self); extern void __FASTCALL__ vobsub_reset(any_t*vob); extern int __FASTCALL__ vobsub_get_packet(any_t*vobhandle, float pts,any_t** data, int* timestamp); -extern int __FASTCALL__ vobsub_parse_ifo(any_t* vob, const char *const name, unsigned int *palette, unsigned int *width, unsigned int *height, int force, int sid, char *langid); -extern char * __FASTCALL__ vobsub_get_id(any_t* vob, unsigned int index); -extern int __FASTCALL__ vobsub_set_from_lang(any_t*vobhandle,const char * lang); +extern int __FASTCALL__ vobsub_parse_ifo(any_t* vob, const std::string& name, unsigned int *palette, unsigned int *width, unsigned int *height, int force, int sid, std::string& langid); +extern std::string __FASTCALL__ vobsub_get_id(any_t* vob, unsigned int index); +extern int __FASTCALL__ vobsub_set_from_lang(any_t*vobhandle,const std::string& lang); extern unsigned int __FASTCALL__ vobsub_get_forced_subs_flag(void const * const vobhandle); extern void __FASTCALL__ vobsub_seek(any_t* vob,const seek_args_t* seek); /// Convert palette value in idx file to yuv. Modified: mplayerxp/libplaytree/playtree.cpp =================================================================== --- mplayerxp/libplaytree/playtree.cpp 2012-12-25 16:17:37 UTC (rev 601) +++ mplayerxp/libplaytree/playtree.cpp 2012-12-26 11:39:18 UTC (rev 602) @@ -8,9 +8,6 @@ #include <unistd.h> #include <errno.h> #include <time.h> -#ifdef MP_DEBUG -#include <assert.h> -#endif #include "libmpstream2/stream.h" #include "playtree.h" #include "playtree_msg.h" @@ -31,10 +28,6 @@ play_tree_free(play_tree_t* pt, int childs) { play_tree_t* iter; -#ifdef MP_DEBUG - assert(pt != NULL); -#endif - if(childs) { for(iter = pt->child; iter != NULL; ) { play_tree_t* nxt=iter->next; @@ -64,10 +57,6 @@ play_tree_free_list(play_tree_t* pt, int childs) { play_tree_t* iter; -#ifdef MP_DEBUG - assert(pt != NULL); -#endif - for(iter = pt ; iter->prev != NULL ; iter = iter->prev) /* NOTHING */; @@ -83,11 +72,6 @@ play_tree_append_entry(play_tree_t* pt, play_tree_t* entry) { play_tree_t* iter; -#ifdef MP_DEBUG - assert(pt != NULL); - assert(entry != NULL); -#endif - if(pt == entry) return; @@ -104,11 +88,6 @@ play_tree_prepend_entry(play_tree_t* pt, play_tree_t* entry) { play_tree_t* iter; -#ifdef MP_DEBUG - assert(pt != NULL); - assert(entry != NULL); -#endif - for(iter = pt ; iter->prev != NULL; iter = iter->prev) /* NOTHING */; @@ -118,9 +97,6 @@ iter->prev = entry; if(entry->parent) { -#ifdef MP_DEBUG - assert(entry->parent->child == iter); -#endif entry->parent->child = entry; } } @@ -128,17 +104,9 @@ void play_tree_insert_entry(play_tree_t* pt, play_tree_t* entry) { -#ifdef MP_DEBUG - assert(pt != NULL); - assert(entry != NULL); -#endif - entry->parent = pt->parent; entry->prev = pt; if(pt->next) { -#ifdef MP_DEBUG - assert(pt->next->prev == pt); -#endif entry->next = pt->next; entry->next->prev = entry; } else @@ -150,41 +118,21 @@ void play_tree_remove(play_tree_t* pt, int free_it,int with_childs) { -#ifdef MP_DEBUG - assert(pt != NULL); -#endif - // Middle of list if(pt->prev && pt->next) { -#ifdef MP_DEBUG - 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) { -#ifdef MP_DEBUG - assert(pt->prev->next == pt); -#endif pt->prev->next = NULL; } // Begining of list else if(pt->next) { -#ifdef MP_DEBUG - assert(pt->next->prev == pt); -#endif pt->next->prev = NULL; if(pt->parent) { -#ifdef MP_DEBUG - assert(pt->parent->child == pt); -#endif pt->parent->child = pt->next; } } // The only one else if(pt->parent) { -#ifdef MP_DEBUG - assert(pt->parent->child == pt); -#endif pt->parent->child = NULL; } @@ -198,11 +146,6 @@ play_tree_set_child(play_tree_t* pt, play_tree_t* child) { play_tree_t* iter; -#ifdef MP_DEBUG - assert(pt != NULL); - assert(pt->entry_type == PLAY_TREE_ENTRY_NODE); -#endif - for(iter = pt->child ; iter != NULL ; iter = iter->next) iter->parent = NULL; @@ -221,10 +164,6 @@ play_tree_set_parent(play_tree_t* pt, play_tree_t* parent) { play_tree_t* iter; -#ifdef MP_DEBUG - assert(pt != NULL); -#endif - if(pt->parent) pt->parent->child = NULL; @@ -247,12 +186,6 @@ int n = 0; char* e; -#ifdef MP_DEBUG - assert(pt != NULL); - assert(pt->child == NULL); - assert(file != NULL); -#endif - if(pt->entry_type != PLAY_TREE_ENTRY_NODE && pt->entry_type != PLAY_TREE_ENTRY_FILE) return; @@ -261,7 +194,7 @@ for(n = 0 ; pt->files[n] != NULL ; n++) /* NOTHING */; } - pt->files = (char**)mp_realloc(pt->files,(n+2)*sizeof(char*)); + pt->files = (char**)mp_realloc((any_t*)pt->files,(n+2)*sizeof(char*)); if(pt->files ==NULL) { MSG_ERR("Can't allocate %d bytes of memory\n",(n+2)*sizeof(char*)); return; @@ -288,12 +221,6 @@ play_tree_remove_file(play_tree_t* pt,const char* file) { int n,f = -1; -#ifdef MP_DEBUG - assert(pt != NULL); - assert(file != NULL); - assert(pt->entry_type != PLAY_TREE_ENTRY_NODE); -#endif - for(n=0 ; pt->files[n] != NULL ; n++) { if(strcmp(file,pt->files[n]) == 0) f = n; @@ -302,15 +229,11 @@ if(f < 0) // Not found return 0; -#ifdef MP_DEBUG - assert(n > f); -#endif - delete pt->files[f]; if(n > 1) { memmove(&pt->files[f],&pt->files[f+1],(n-f)*sizeof(char*)); - pt->files = (char**)mp_realloc(pt->files,n*sizeof(char*)); + pt->files = (char**)mp_realloc((any_t*)pt->files,n*sizeof(char*)); if(pt->files == NULL) { MSG_ERR("Can't allocate %d bytes of memory\n",(n+2)*sizeof(char*)); return -1; @@ -326,11 +249,6 @@ void play_tree_set_param(play_tree_t* pt,const char* name,const char* val) { int n = 0,ni = -1; -#ifdef MP_DEBUG - 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) @@ -360,12 +278,6 @@ int play_tree_unset_param(play_tree_t* pt,const char* name) { int n,ni = -1; -#ifdef MP_DEBUG - 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; @@ -395,11 +307,6 @@ void play_tree_set_params_from(play_tree_t* dest,const play_tree_t* src) { int i; -#ifdef MP_DEBUG - assert(dest != NULL); - assert(src != NULL); -#endif - if(!src->params) return; @@ -435,80 +342,6 @@ } } -static void -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; - - // We always push a config because we can set some option - // while playing - m_config_push(*iter->config); - - if(pt->params == NULL) - return; - - - for(n = 0; pt->params[n].name != NULL ; n++) { - int e; - if((e = m_config_set_option(*iter->config,pt->params[n].name,pt->params[n].value)) < 0) { - MSG_ERR("Error %d while setting option '%s' with value '%s'\n",e, - pt->params[n].name,pt->params[n].value); - } - } - - if(!pt->child) - iter->entry_pushed = 1; - return; -} - -play_tree_iter_t* -play_tree_iter_new(play_tree_t* pt,m_config_t& config) { - play_tree_iter_t* iter; - -#ifdef MP_DEBUG - assert(pt != NULL); - assert(config != NULL); -#endif - - if( ! play_tree_is_valid(pt)) - return NULL; - - iter = (play_tree_iter_t*)mp_calloc(1,sizeof(play_tree_iter_t)); - if(! iter) return NULL; - iter->root = pt; - iter->tree = NULL; - iter->config = &config; - - if(pt->parent) - iter->loop = pt->parent->loop; - - return iter; -} - -void -play_tree_iter_free(play_tree_iter_t* iter) { - -#ifdef MP_DEBUG - assert(iter != NULL); -#endif - - if(iter->status_stack) { -#ifdef MP_DEBUG - assert(iter->stack_size > 0); -#endif - delete iter->status_stack; - } - - delete iter; -} - static play_tree_t* play_tree_rnd_step(play_tree_t* pt) { int count = 0; @@ -545,300 +378,232 @@ return NULL; } -int -play_tree_iter_step(play_tree_iter_t* iter, int d,int with_nodes) { - play_tree_t* pt; - int rnd; -#ifdef MP_DEBUG - assert(iter != NULL); - assert(iter->root != NULL); -#endif +namespace mpxp { +_PlayTree_Iter::_PlayTree_Iter(play_tree_t* pt,m_config_t& _config) + :root(pt), + tree(NULL), + config(_config) { + if(pt->parent) loop = pt->parent->loop; +} - if(iter->tree == NULL) { - iter->tree = iter->root; - return play_tree_iter_step(iter,0,with_nodes); - } +_PlayTree_Iter::_PlayTree_Iter(const _PlayTree_Iter& old) + :root(old.root), + tree(old.tree), + config(old.config), + loop(old.loop), + file(old.file), + num_files(old.num_files), + mode(old.mode) {} - if(iter->config && iter->entry_pushed > 0) { - iter->entry_pushed = 0; - m_config_pop(*iter->config); - } +_PlayTree_Iter::~_PlayTree_Iter() {} - if(iter->tree->parent && (iter->tree->parent->flags & PLAY_TREE_RND)) - rnd=iter->mode = PLAY_TREE_ITER_RND; - else - rnd=iter->mode = PLAY_TREE_ITER_NORMAL; +void _PlayTree_Iter::push_params() { + int n; + play_tree_t* pt; - iter->file = -1; - if(iter->mode == PLAY_TREE_ITER_RND) - pt = play_tree_rnd_step(iter->tree); - else if( d > 0 ) { - int i; - pt = iter->tree; - for(i = d ; i > 0 && pt ; i--) - pt = pt->next; - d = i ? i : 1; - } else if(d < 0) { - int i; - pt = iter->tree; - for(i = d ; i < 0 && pt ; i++) - pt = pt->prev; - d = i ? i : -1; - } else - pt = iter->tree; + pt = tree; - if(pt == NULL) { // No next - // Must we loop? - if (iter->mode == PLAY_TREE_ITER_RND) { - if (iter->root->loop == 0) - return PLAY_TREE_ITER_END; - play_tree_unset_flag(iter->root, PLAY_TREE_RND_PLAYED, -1); - if (iter->root->loop > 0) iter->root->loop--; - // try again - return play_tree_iter_step(iter, 0, with_nodes); - } else - 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); + // We always push a config because we can set some option + // while playing + m_config_push(config); - } + if(pt->params == NULL) return; - // Is there any valid child? - 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); - } + for(n = 0; pt->params[n].name != NULL ; n++) { + int e; + if((e = m_config_set_option(config,pt->params[n].name,pt->params[n].value)) < 0) + mpxp_err<<"Error "<<e<<" while setting option '"<<pt->params[n].name<<"' with value '"<<pt->params[n].value<<"'"<<std::endl; + } - // Is it a valid entry? - if(! play_tree_is_valid(pt)) { - if(d == 0 && rnd==PLAY_TREE_ITER_NORMAL) { // Can this happen ? FF: Yes! - MSG_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); - } - -#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) { - play_tree_iter_push_params(iter); - iter->entry_pushed = 1; - if(iter->mode == PLAY_TREE_ITER_RND) - pt->flags |= PLAY_TREE_RND_PLAYED; - } - - return PLAY_TREE_ITER_ENTRY; - + if(!pt->child) entry_pushed = 1; + return; } -static int -play_tree_is_valid(play_tree_t* pt) { - play_tree_t* iter; +int _PlayTree_Iter::step(int d,int with_nodes) { + play_tree_t* pt; + int rnd; -#ifdef MP_DEBUG - assert(pt != NULL); -#endif + if(tree == NULL) { + tree = root; + return step(0,with_nodes); + } - 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)) - return 1; + if(entry_pushed > 0) { + entry_pushed = 0; + m_config_pop(config); } - } - return 0; -} -int -play_tree_iter_up_step(play_tree_iter_t* iter, int d,int with_nodes) { + if(tree->parent && (tree->parent->flags & PLAY_TREE_RND)) + rnd=mode = PLAY_TREE_ITER_RND; + else + rnd=mode = PLAY_TREE_ITER_NORMAL; -#ifdef MP_DEBUG - assert(iter != NULL); - assert(iter->tree != NULL); -#endif + file = -1; + if(mode == PLAY_TREE_ITER_RND) pt = play_tree_rnd_step(tree); + else if( d > 0 ) { + int i; + pt = tree; + for(i = d ; i > 0 && pt ; i--) pt = pt->next; + d = i ? i : 1; + } else if(d < 0) { + int i; + pt = tree; + for(i = d ; i < 0 && pt ; i++) pt = pt->prev; + d = i ? i : -1; + } else pt = tree; - iter->file = -1; - if(iter->tree->parent == iter->root->parent) - return PLAY_TREE_ITER_END; + if(pt == NULL) { // No next + // Must we loop? + if (mode == PLAY_TREE_ITER_RND) { + if (root->loop == 0) return PLAY_TREE_ITER_END; + play_tree_unset_flag(root, PLAY_TREE_RND_PLAYED, -1); + if (root->loop > 0) root->loop--; + // try again + return step(0, with_nodes); + } else if(tree->parent && tree->parent->loop != 0 && ((d > 0 && loop != 0) || ( d < 0 && (loop < 0 || loop < tree->parent->loop)))) { + if(d > 0) { // Go back to the first one + for(pt = tree ; pt->prev != NULL; pt = pt->prev) /* NOTHNG */; + if(loop > 0) loop--; + } else if( d < 0 ) { // Or the last one + for(pt = tree ; pt->next != NULL; pt = pt->next) /* NOTHNG */; + if(loop >= 0 && loop < tree->parent->loop) loop++; + } + tree = pt; + return step(0,with_nodes); + } + // Go up one level + return up_step(d,with_nodes); + } + // Is there any valid child? + if(pt->child && play_tree_is_valid(pt->child)) { + tree = pt; + if(with_nodes) { // Stop on the node + return PLAY_TREE_ITER_NODE; + } else // Or follow it + return down_step(d,with_nodes); + } + // Is it a valid entry? + if(! play_tree_is_valid(pt)) { + if(d == 0 && rnd==PLAY_TREE_ITER_NORMAL) { // Can this happen ? FF: Yes! + mpxp_err<<"What to do now ???? Infinite loop if we continue"<<std::endl; + return PLAY_TREE_ITER_ERROR; + } // Not a valid entry : go to next one + return step(d,with_nodes); + } -#ifdef MP_DEBUG - assert(iter->tree->parent != NULL); - assert(iter->stack_size > 0); - assert(iter->status_stack != NULL); -#endif + tree = pt; - iter->stack_size--; - iter->loop = iter->status_stack[iter->stack_size]; - if(iter->stack_size > 0) - iter->status_stack = (int*)mp_realloc(iter->status_stack,iter->stack_size*sizeof(int)); - else { - delete iter->status_stack; - iter->status_stack = NULL; - } - if(iter->stack_size > 0 && iter->status_stack == NULL) { - MSG_ERR("Can't allocate %d bytes of memory\n",iter->stack_size*sizeof(char*)); - return PLAY_TREE_ITER_ERROR; - } - iter->tree = iter->tree->parent; + for(d = 0 ; tree->files[d] != NULL ; d++) /* NOTHING */; + num_files = d; - // Pop subtree params - if(iter->config) { - m_config_pop(*iter->config); - if(iter->mode == PLAY_TREE_ITER_RND) - iter->tree->flags |= PLAY_TREE_RND_PLAYED; - } + push_params(); + entry_pushed = 1; + if(mode == PLAY_TREE_ITER_RND) pt->flags |= PLAY_TREE_RND_PLAYED; - return play_tree_iter_step(iter,d,with_nodes); + return PLAY_TREE_ITER_ENTRY; } -int -play_tree_iter_down_step(play_tree_iter_t* iter, int d,int with_nodes) { +int _PlayTree_Iter::up_step(int d,int with_nodes) { + file = -1; + if(tree->parent == root->parent) return PLAY_TREE_ITER_END; -#ifdef MP_DEBUG - assert(iter->tree->files == NULL); - assert(iter->tree->child != NULL); - assert(iter->tree->child->parent == iter->tree); -#endif + loop = status_stack.top(); status_stack.pop(); + tree = tree->parent; - iter->file = -1; + // Pop subtree params + m_config_pop(config); + if(mode == PLAY_TREE_ITER_RND) tree->flags |= PLAY_TREE_RND_PLAYED; + return step(d,with_nodes); +} - // Push subtree params - if(iter->config) - play_tree_iter_push_params(iter); +int _PlayTree_Iter::down_step(int d,int with_nodes) { + file = -1; - iter->stack_size++; - iter->status_stack = (int*)mp_realloc(iter->status_stack,iter->stack_size*sizeof(int)); - if(iter->status_stack == NULL) { - MSG_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; - } + // Push subtree params + push_params(); - return play_tree_iter_step(iter,0,with_nodes); + status_stack.push(loop); + // Set new status + loop = tree->loop-1; + if(d >= 0) tree = tree->child; + else { + play_tree_t* pt; + for(pt = tree->child ; pt->next != NULL ; pt = pt->next) /*NOTING*/; + tree = pt; + } + return step(0,with_nodes); } -// This is used as a file name for vcd/tv/dvd -char playtree_ret_filename[256]; +std::string _PlayTree_Iter::get_file(int d) { + const char* entry; -const char* -play_tree_iter_get_file(play_tree_iter_t* iter, int d) { - const char* entry; -#ifdef MP_DEBUG - assert(iter != NULL); - assert(iter->tree->child == NULL); -#endif + if(tree->files == NULL) return ""; + if(file >= num_files-1 || file < -1) return ""; + if(d > 0) { + if(file >= num_files - 1) file = 0; + else file++; + } else if(d < 0) { + if(file <= 0) file = num_files - 1; + else file--; + } + entry = tree->files[file]; - if(iter->tree->files == NULL) - return NULL; + switch(tree->entry_type) { + case PLAY_TREE_ENTRY_DVD : + if(strlen(entry) == 0) entry = "1"; + m_config_set_option(config,"dvd",entry); + return std::string("DVD title ")+entry; + case PLAY_TREE_ENTRY_VCD : + if(strlen(entry) == 0) entry = "1"; + m_config_set_option(config,"vcd",entry); + return std::string("vcd://")+entry; + case PLAY_TREE_ENTRY_TV: { + if(strlen(entry) != 0) { + char *val = new char [strlen(entry) + 11 + 1]; + const char* e; + std::string rs; + sprintf(val,"on:channel=%s",entry); + m_config_set_option(config,"tv",val); + rs="TV channel "; + e = strchr(entry,':'); + if(!e) rs+=std::string(entry).substr(0,255-11); + else { + if(entry-e > 255) e = entry+255; + rs+=std::string(entry).substr(0,val-e); + } + delete val; + return rs; + } else m_config_set_option(config,"tv","on"); + return "TV"; + } + default: break; + } + return entry; +} -#ifdef MP_DEBUG - assert(iter->num_files > 0); -#endif +} // namespace mpxp - if(iter->file >= iter->num_files-1 || iter->file < -1) - return NULL; - if(d > 0) { - if(iter->file >= iter->num_files - 1) - iter->file = 0; - else - iter->file++; - } else if(d < 0) { - if(iter->file <= 0) - iter->file = iter->num_files - 1; - else - iter->file--; - } - entry = iter->tree->files[iter->file]; +static int +play_tree_is_valid(play_tree_t* pt) { + play_tree_t* iter; - switch(iter->tree->entry_type) { - case PLAY_TREE_ENTRY_DVD : - 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; - case PLAY_TREE_ENTRY_VCD : - if(strlen(entry) == 0) entry = "1"; - if(iter->config) - m_config_set_option(*iter->config,"vcd",entry); - snprintf(playtree_ret_filename,255,"vcd://%s",entry); - return playtree_ret_filename; - case PLAY_TREE_ENTRY_TV : - { - if(strlen(entry) != 0) { - char *s,*val = (char*)mp_malloc(strlen(entry) + 11 + 1); - const char* e; - 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'; - } - delete val; - return playtree_ret_filename; - } else { - if(iter->config) - m_config_set_option(*iter->config,"tv","on"); - return "TV"; - } + if(pt->entry_type != PLAY_TREE_ENTRY_NODE) { + return 1; + } + else if (pt->child != NULL) { + for(iter = pt->child ; iter != NULL ; iter = iter->next) { + if(play_tree_is_valid(iter)) + return 1; } } - - return entry; + return 0; } play_tree_t* play_tree_cleanup(play_tree_t* pt) { play_tree_t* iter, *tmp, *first; -#ifdef MP_DEBUG - assert(pt != NULL); -#endif - if( ! play_tree_is_valid(pt)) { play_tree_remove(pt,1,1); return NULL; @@ -865,50 +630,19 @@ } -play_tree_iter_t* play_tree_iter_new_copy(play_tree_iter_t const* old) { - play_tree_iter_t* iter; - -#ifdef MP_DEBUG - assert(old != NULL); -#endif - - iter = (play_tree_iter_t*)mp_malloc(sizeof(play_tree_iter_t)); - if(iter == NULL) { - MSG_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*)mp_malloc(old->stack_size * sizeof(int)); - if(iter->status_stack == NULL) { - MSG_ERR("Can't allocate %d bytes of memory\n",old->stack_size * sizeof(int)); - delete iter; - return NULL; - } - memcpy(iter->status_stack,old->status_stack,iter->stack_size*sizeof(int)); - } - iter->config = NULL; - - return iter; -} - // HIGH Level API, by Fabian Franz (mp...@fa...) // -play_tree_iter_t* pt_iter_create(play_tree_t** ppt, m_config_t& config) +_PlayTree_Iter* pt_iter_create(play_tree_t** ppt, m_config_t& config) { - play_tree_iter_t* r=NULL; -#ifdef MP_DEBUG - assert(*ppt!=NULL); -#endif + _PlayTree_Iter* r=NULL; *ppt=play_tree_cleanup(*ppt); if(*ppt) { - r = play_tree_iter_new(*ppt,config); - if (r && play_tree_iter_step(r,0,0) != PLAY_TREE_ITER_ENTRY) + r = new _PlayTree_Iter(*ppt,config); + if (r && r->step(0,0) != PLAY_TREE_ITER_ENTRY) { - play_tree_iter_free(r); + delete r; r = NULL; } } @@ -916,7 +650,7 @@ return r; } -void pt_iter_destroy(play_tree_iter_t** iter) +void pt_iter_destroy(_PlayTree_Iter** iter) { if (iter && *iter) { @@ -925,56 +659,47 @@ } } -const char* pt_iter_get_file(play_tree_iter_t* iter, int d) +std::string pt_iter_get_file(_PlayTree_Iter* iter, int d) { int i=0; - const char* r; + std::string r; if (iter==NULL) return NULL; - r = play_tree_iter_get_file(iter,d); + r = iter->get_file(d); - while (!r && d!=0) + while (r.empty() && d!=0) { - if (play_tree_iter_step(iter,d,0) != PLAY_TREE_ITER_ENTRY) - break; - r=play_tree_iter_get_file(iter,d); + if (iter->step(d,0) != PLAY_TREE_ITER_ENTRY) break; + r=iter->get_file(d); i++; } return r; } -void pt_iter_insert_entry(play_tree_iter_t* iter, play_tree_t* entry) +void pt_iter_insert_entry(_PlayTree_Iter* iter, play_tree_t* entry) { - play_tree_t *pt = iter->tree; -#ifdef MP_DEBUG - assert(pt!=NULL); - assert(entry!=NULL); - assert(entry!=pt); -#endif + play_tree_t *pt = iter->get_tree(); play_tree_insert_entry(pt, entry); play_tree_set_params_from(entry,pt); } -void pt_iter_replace_entry(play_tree_iter_t* iter, play_tree_t* entry) +void pt_iter_replace_entry(_PlayTree_Iter* iter, play_tree_t* entry) { - play_tree_t *pt = iter->tree; + play_tree_t *pt = iter->get_tree(); pt_iter_insert_entry(iter, entry); play_tree_remove(pt, 1, 1); - iter->tree=entry; + iter->set_tree(entry); } //Add a new file as a new entry void pt_add_file(play_tree_t** ppt,const char* filename) { play_tree_t *pt = *ppt, *entry = play_tree_new(); -#ifdef MP_DEBUG - assert(entry!=NULL); -#endif play_tree_add_file(entry, filename); if (pt) @@ -1001,8 +726,8 @@ } } -void pt_iter_goto_head(play_tree_iter_t* iter) +void pt_iter_goto_head(_PlayTree_Iter* iter) { - iter->tree=iter->root; - play_tree_iter_step(iter, 0, 0); + iter->reset_tree(); + iter->step(0, 0); } Modified: mplayerxp/libplaytree/playtree.h =================================================================== --- mplayerxp/libplaytree/playtree.h 2012-12-25 16:17:37 UTC (rev 601) +++ mplayerxp/libplaytree/playtree.h 2012-12-26 11:39:18 UTC (rev 602) @@ -1,6 +1,9 @@ #ifndef __PLAYTREE_H #define __PLAYTREE_H +#include "osdep/mplib.h" +#include <stack> + struct m_config_t; namespace mpxp { struct Stream; @@ -40,38 +43,66 @@ ///@{ struct play_tree_param_t { - char* name; - char* value; + const char* name; + const char* value; }; struct play_tree_t { - play_tree_t* parent; - play_tree_t* child; - play_tree_t* next; - play_tree_t* prev; + play_tree_t* parent; + play_tree_t* child; + play_tree_t* next; + play_tree_t* prev; //play_tree_info_t info; - play_tree_param_t* params; - int loop; - char** files; - int entry_type; - int flags; + play_tree_param_t* params; + int loop; + char** files; + int entry_type; + int flags; }; -struct play_tree_iter_t { - play_tree_t* root; // Iter root tree - play_tree_t* tree; // Current tree - m_config_t* config; - int loop; // Looping status - int file; - int num_files; - int entry_pushed; - int mode; +namespace mpxp { + struct _PlayTree_Iter : public Opaque { + public: + _PlayTree_Iter(play_tree... [truncated message content] |