From 89a17bcda6c166e98861723b8adc9989f2724c34 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 31 Jul 2012 21:33:26 +0200 Subject: mplayer: turn playtree into a list, and change per-file option handling Summary: - There is no playtree anymore. It's reduced to a simple list. - Options are now always global. You can still have per-file options, but these are optional and require special syntax. - The slave command pt_step has been removed, and playlist_next and playlist_prev added. (See etc/input.conf changes.) This is a user visible incompatible change, and will break slave-mode applications. - The pt_clear slave command is renamed to playlist_clear. - Playtree entries could have multiple files. This is not the case anymore, and playlist entries have always exactly one entry. Whenever something adds more than one file (like ASX playlists or dvd:// or dvdnav:// on the command line), all files are added as separate playlist entries. Note that some of the changes are quite deep and violent. Expect regressions. The playlist parsing code in particular is of low quality. I didn't try to improve it, and merely spent to least effort necessary to keep it somehow working. (Especially ASX playlist handling.) The playtree code was complicated and bloated. It was also barely used. Most users don't even know that mplayer manages the playlist as tree, or how to use it. The most obscure features was probably specifying a tree on command line (with '{' and '}' to create/close tree nodes). It filled the player code with complexity and confused users with weird slave commands like pt_up. Replace the playtree with a simple flat playlist. Playlist parsers that actually return trees are changed to append all files to the playlist pre-order. It used to be the responsibility of the playtree code to change per-file config options. Now this is done by the player core, and the playlist code is free of such details. Options are not per-file by default anymore. This was a very obscure and complicated feature that confused even experienced users. Consider the following command line: mplayer file1.mkv file2.mkv --no-audio file3.mkv This will disable the audio for file2.mkv only, because options are per-file by default. To make the option affect all files, you're supposed to put it before the first file. This is bad, because normally you don't need per-file options. They are very rarely needed, and the only reasonable use cases I can imagine are use of the encode backend (mplayer encode branch), or for debugging. The normal use case is made harder, and the feature is perceived as bug. Even worse, correct usage is hard to explain for users. Make all options global by default. The position of an option isn't significant anymore (except for options that compensate each other, consider --shuffle --no-shuffle). One other important change is that no options are reset anymore if a new file is started. If you change settings with slave mode commands, they will not be changed by playing a new file. (Exceptions include settings that are too file specific, like audio/subtitle stream selection.) There is still some need for per-file options. Debugging and encoding are use cases that profit from per-file options. Per-file profiles (as well as per-protocol and per-VO/AO options) need the implementation related mechanisms to backup and restore options when the playback file changes. Simplify the save-slot stuff, which is possible because there is no hierarchical play tree anymore. Now there's a simple backup field. Add a way to specify per-file options on command line. Example: mplayer f1.mkv -o0 --{ -o1 f2.mkv -o2 f3.mkv --} f4.mkv -o3 will have the following options per file set: f1.mkv, f4.mkv: -o0 -o3 f2.mkv, f3.mkv: -o0 -o3 -o1 -o2 The options --{ and --} start and end per-file options. All files inside the { } will be affected by the options equally (similar to how global options and multiple files are handled). When playback of a file starts, the per-file options are set according to the command line. When playback ends, the per-file options are restored to the values when playback started. --- DOCS/OUTDATED-tech/playtree | 123 ------ Makefile | 4 +- asxparser.c | 207 ++++------ asxparser.h | 56 +-- command.c | 154 +++---- etc/input.conf | 14 +- input/input.c | 32 +- input/input.h | 10 +- libvo/video_out.c | 5 +- m_config.c | 225 +++++----- m_config.h | 43 +- mp_core.h | 18 +- mpcommon.h | 24 ++ mplayer.c | 326 +++++---------- osdep/macosx_finder_args.h | 6 +- osdep/macosx_finder_args.m | 32 +- parser-mpcmd.c | 198 +++++---- parser-mpcmd.h | 6 +- playlist.c | 185 +++++++++ playlist.h | 67 +++ playlist_parser.c | 780 +++++++++++++++++++++++++++++++++++ playlist_parser.h | 34 ++ playtree.c | 908 ---------------------------------------- playtree.h | 302 -------------- playtreeparser.c | 985 -------------------------------------------- playtreeparser.h | 73 ---- 26 files changed, 1597 insertions(+), 3220 deletions(-) delete mode 100644 DOCS/OUTDATED-tech/playtree create mode 100644 playlist.c create mode 100644 playlist.h create mode 100644 playlist_parser.c create mode 100644 playlist_parser.h delete mode 100644 playtree.c delete mode 100644 playtree.h delete mode 100644 playtreeparser.c delete mode 100644 playtreeparser.h diff --git a/DOCS/OUTDATED-tech/playtree b/DOCS/OUTDATED-tech/playtree deleted file mode 100644 index 2aaf5a175e..0000000000 --- a/DOCS/OUTDATED-tech/playtree +++ /dev/null @@ -1,123 +0,0 @@ - -How work the playtree ? - -Good question, I try to explain but note that it's the first doc -I write :) - -First there is two things. The playtree itself and the iterator. -The playtree represent the data and the iterator is used by -mplayer to go from entry to entry. - -First the play_tree struct : - - -struct play_tree { - play_tree_t* parent; - play_tree_t* child; - play_tree_t* next; - play_tree_t* prev; - - play_tree_param_t* params; - int loop; - char** files; - int entry_type; -}; - -The play_tree_t* hold the links in the 4 directions, the params hold -all parameters of this entry, loop is obvious (loop < 0 mean infint loop), -files hold all the files of this entry and entry_type obviously tell the -type of this entry (Node, file, dvd, vcd ot tv). - -An entry can hold more than one file, why ? - -Because an entry can be a network stream and usually you have more than -one server. But all send the same thing, so it's only on entry with sevral -sources. - -Then how do I use this stuff ? - -First you create an entry using the play_tree_new func. This create the struct -and fill it with defaults values. -Then this can become a node or a leaf. It will become a node as soon as you link it -to another one using either play_tree_set_child or play_tree_set_parent. -Or it will become a leaf as soon as you use play_tree_add_file on it. -If an entry contain at least one file it can't become an node (an assert will be -raised) and if en entry has a child you can't add file to (here also an assert will -be raised). -Then to create a list of entry you should use play_tree_append_entry, -play_tree_prepend_entry or play_tree_insert_entry. -In all this function you can use any entry of the the list as first argument, -no need that it's the first one. The same apply when you set the child of a node, -the child argument can be any entry in a list. -To remove an entry from the tree use play_tree_remove. If the second arg (free_it) -is true it will also free it, if the entry should be freed and the third -arg is true it will also free the children. - -When your tree is ready you can then use play_tree_cleanup to remove all unuseful -entries. - -If you want to load a playlist you can use parse_playtree which take a stream_t -as argument or parse_playlist_file which take a filename as argument. -Both function will return NULL in case of failure or a new (cleaned) tree that -you can add somewhere in your tree. - -How do I add DVD, VCD or TV entry to the tree ? - -You should use some virtual URL as filename like : - dvd://x where x is the title number. - vcd://x where x is the track number - tv://x where x is the channel - - -My playtree is ready now, what with this play_tree_iter ? - -This is an iterator used to go trough the tree. It handle itself -loop of list and setting mplayer config according to the params -of each entry. -It's created with play_tree_iter_new which take as argument a play_tree_t -and an m_config_t which is then used to set/unset the params of each entry. -After creation the iter point to nothing, you should init with a first step. -To go to another entry in the list you should use play_tree_iter_step. The -second argument is the direction of the step : positive value go frontward, -negative go backward and 0 don't move. The third tell if must care of -node or not. If it's true, the iterator will stop on nodes, otherwise it go -to the next valid entry. -This function return different values : -PLAY_TREE_ITER_ERROR : obvious -PLAY_TREE_ITER_ENTRY : we are now on an entry -PLAY_TREE_ITER_NODE : we are now on a node -PLAY_TREE_ITER_END : we are now at end -(( Note : I must add a PLAY_TREE_ITER_BEGINNING for the beginning. Don't know -what it will return in a such case. PLAY_TREE_ITER_ERROR ? )) - -There is also play_tree_iter_up_step which can be used to break a loop or skip -the current list. The argument are the same than play_tree_iter_step. The -difference is that it go back to parent of the current list, and then step according -to the arguments. - -Then when your iter returned PLAY_TREE_ITER_ENTRY you can use -play_tree_iter_get_file to get the file. If you call it more than one time -it will return the next file for this entry or loop trough the list if no more -file are available. You can now how many files are available using -iter->num_files and which one it returned using iter->file. -In case the entry is a DVD, VCD or TV channel the returned string is not a filename -but "DVD title x", "VCD track x" or "TV channel x". -To distinc those case from a normal file you can check iter->tree->entry_type. -It will contain one of PLAY_TREE_ENTRY_DVD, PLAY_TREE_ENTRY_VCD, -PLAY_TREE_ENTRY_TV or PLAY_TREE_ENTRY_FILE. - -If you need to make some check with the iter, such as will next entry be valid, etc -You must create a clone with play_tree_iter_new_copy. This iter will not affect -the config, so you can do all you want with it. - -Then when you have finish with the iter free it with play_tree_iter_free. - - -Ok, that's all for now. To have some exemples look into mplayer.c ;) -First just after config parsing, the iterator is created there. Also -after stream opening, in case the stream is a playlist it replace the -entry which contained the playlist by the result of the parsing. -In the event handling it check if a step can be done, etc. And finnaly -at the end it go the next entry. - -Suggestion, flames, etc about this doc must go to albeu@free.fr diff --git a/Makefile b/Makefile index 01c4d59305..f3209ff528 100644 --- a/Makefile +++ b/Makefile @@ -218,8 +218,8 @@ SRCS_COMMON = asxparser.c \ mpcommon.c \ parser-cfg.c \ path.c \ - playtree.c \ - playtreeparser.c \ + playlist.c \ + playlist_parser.c \ subopt-helper.c \ talloc.c \ libaf/af.c \ diff --git a/asxparser.c b/asxparser.c index 5d0d811ab4..89cf7bd1a1 100644 --- a/asxparser.c +++ b/asxparser.c @@ -24,13 +24,62 @@ #include #include -#include "playtree.h" -#include "playtreeparser.h" +#include "playlist.h" +#include "playlist_parser.h" #include "stream/stream.h" #include "libmpdemux/demuxer.h" #include "asxparser.h" #include "mp_msg.h" -#include "m_config.h" + + +typedef struct ASX_Parser_t ASX_Parser_t; + +typedef struct { + char* buffer; + int line; +} ASX_LineSave_t; + +struct ASX_Parser_t { + int line; // Curent line + ASX_LineSave_t *ret_stack; + int ret_stack_size; + char* last_body; + int deep; + struct playlist *pl; +}; + +ASX_Parser_t *asx_parser_new(struct playlist *pl); + +void +asx_parser_free(ASX_Parser_t* parser); + +/* + * Return -1 on error, 0 when nothing is found, 1 on sucess + */ +int +asx_get_element(ASX_Parser_t* parser,char** _buffer, + char** _element,char** _body,char*** _attribs); + +int +asx_parse_attribs(ASX_Parser_t* parser,char* buffer,char*** _attribs); + +/////// Attribs utils + +char* +asx_get_attrib(const char* attrib,char** attribs); + +int +asx_attrib_to_enum(const char* val,char** valid_vals); + +#define asx_free_attribs(a) asx_list_free(&a,free) + +////// List utils + +typedef void (*ASX_FreeFunc)(void* arg); + +void +asx_list_free(void* list_ptr,ASX_FreeFunc free_func); + ////// List utils @@ -77,11 +126,10 @@ asx_attrib_to_enum(const char* val,char** valid_vals) { #define asx_warning_attrib_required(p,e,a) mp_msg(MSGT_PLAYTREE,MSGL_WARN,"At line %d : element %s don't have the required attribute %s",p->line,e,a) #define asx_warning_body_parse_error(p,e) mp_msg(MSGT_PLAYTREE,MSGL_WARN,"At line %d : error while parsing %s body",p->line,e) -ASX_Parser_t* -asx_parser_new(struct m_config *mconfig) +ASX_Parser_t *asx_parser_new(struct playlist *pl) { ASX_Parser_t* parser = calloc(1,sizeof(ASX_Parser_t)); - parser->mconfig = mconfig; + parser->pl = pl; return parser; } @@ -388,7 +436,7 @@ asx_get_element(ASX_Parser_t* parser,char** _buffer, } static void -asx_parse_ref(ASX_Parser_t* parser, char** attribs, play_tree_t* pt) { +asx_parse_ref(ASX_Parser_t* parser, char** attribs) { char *href; href = asx_get_attrib("HREF",attribs); @@ -409,7 +457,7 @@ asx_parse_ref(ASX_Parser_t* parser, char** attribs, play_tree_t* pt) { } #endif - play_tree_add_file(pt,href); + playlist_add_file(parser->pl, href); mp_msg(MSGT_PLAYTREE,MSGL_V,"Adding file %s to element entry\n",href); @@ -417,212 +465,137 @@ asx_parse_ref(ASX_Parser_t* parser, char** attribs, play_tree_t* pt) { } -static play_tree_t* -asx_parse_entryref(ASX_Parser_t* parser,char* buffer,char** _attribs) { - play_tree_t* pt; +static void asx_parse_entryref(ASX_Parser_t* parser,char* buffer,char** _attribs) { char *href; stream_t* stream; - play_tree_parser_t* ptp; int f=DEMUXER_TYPE_UNKNOWN; if(parser->deep > 0) - return NULL; + return; href = asx_get_attrib("HREF",_attribs); if(href == NULL) { asx_warning_attrib_required(parser,"ENTRYREF" ,"HREF" ); - return NULL; + return; } stream=open_stream(href,0,&f); if(!stream) { mp_msg(MSGT_PLAYTREE,MSGL_WARN,"Can't open playlist %s\n",href); free(href); - return NULL; + return; } - mp_msg(MSGT_PLAYTREE,MSGL_V,"Adding playlist %s to element entryref\n",href); - - ptp = play_tree_parser_new(stream, parser->mconfig, parser->deep+1); - - pt = play_tree_parser_get_play_tree(ptp, 1); + mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Not recursively loading playlist %s\n",href); - play_tree_parser_free(ptp); free_stream(stream); free(href); //mp_msg(MSGT_PLAYTREE,MSGL_INFO,"Need to implement entryref\n"); - - return pt; } -static play_tree_t* -asx_parse_entry(ASX_Parser_t* parser,char* buffer,char** _attribs) { +static void asx_parse_entry(ASX_Parser_t* parser,char* buffer,char** _attribs) { char *element,*body,**attribs; - int r,nref=0; - play_tree_t *ref; - - ref = play_tree_new(); + int r; while(buffer && buffer[0] != '\0') { r = asx_get_element(parser,&buffer,&element,&body,&attribs); if(r < 0) { asx_warning_body_parse_error(parser,"ENTRY"); - return NULL; + return; } else if (r == 0) { // No more element break; } if(strcasecmp(element,"REF") == 0) { - asx_parse_ref(parser,attribs,ref); + asx_parse_ref(parser,attribs); mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Adding element %s to entry\n",element); - nref++; } else mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Ignoring element %s\n",element); free(body); asx_free_attribs(attribs); } - if(nref <= 0) { - play_tree_free(ref,1); - return NULL; - } - return ref; - } -static play_tree_t* -asx_parse_repeat(ASX_Parser_t* parser,char* buffer,char** _attribs) { +static void asx_parse_repeat(ASX_Parser_t* parser,char* buffer,char** _attribs) { char *element,*body,**attribs; - play_tree_t *repeat, *list=NULL, *entry; - char* count; int r; - repeat = play_tree_new(); - - count = asx_get_attrib("COUNT",_attribs); - if(count == NULL) { - mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Setting element repeat loop to infinit\n"); - repeat->loop = -1; // Infinit - } else { - repeat->loop = atoi(count); - free(count); - if(repeat->loop == 0) repeat->loop = 1; - mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Setting element repeat loop to %d\n",repeat->loop); - } + asx_get_attrib("COUNT",_attribs); + mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Ignoring repeated playlist entries\n"); while(buffer && buffer[0] != '\0') { r = asx_get_element(parser,&buffer,&element,&body,&attribs); if(r < 0) { asx_warning_body_parse_error(parser,"REPEAT"); - return NULL; + return; } else if (r == 0) { // No more element break; } if(strcasecmp(element,"ENTRY") == 0) { - entry = asx_parse_entry(parser,body,attribs); - if(entry) { - if(!list) list = entry; - else play_tree_append_entry(list,entry); - mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Adding element %s to repeat\n",element); - } + asx_parse_entry(parser,body,attribs); } else if(strcasecmp(element,"ENTRYREF") == 0) { - entry = asx_parse_entryref(parser,body,attribs); - if(entry) { - if(!list) list = entry; - else play_tree_append_entry(list,entry); - mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Adding element %s to repeat\n",element); - } + asx_parse_entryref(parser,body,attribs); } else if(strcasecmp(element,"REPEAT") == 0) { - entry = asx_parse_repeat(parser,body,attribs); - if(entry) { - if(!list) list = entry; - else play_tree_append_entry(list,entry); - mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Adding element %s to repeat\n",element); - } + asx_parse_repeat(parser,body,attribs); } else mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Ignoring element %s\n",element); free(body); asx_free_attribs(attribs); } - if(!list) { - play_tree_free(repeat,1); - return NULL; - } - play_tree_set_child(repeat,list); - - return repeat; - } - -play_tree_t* -asx_parser_build_tree(struct m_config *mconfig, char* buffer,int deep) { +bool asx_parse(char* buffer, struct playlist *pl) +{ char *element,*asx_body,**asx_attribs,*body = NULL, **attribs; int r; - play_tree_t *asx,*entry,*list = NULL; - ASX_Parser_t* parser = asx_parser_new(mconfig); + ASX_Parser_t* parser = asx_parser_new(pl); parser->line = 1; - parser->deep = deep; + parser->deep = 0; r = asx_get_element(parser,&buffer,&element,&asx_body,&asx_attribs); if(r < 0) { mp_msg(MSGT_PLAYTREE,MSGL_ERR,"At line %d : Syntax error ???",parser->line); asx_parser_free(parser); - return NULL; + return false; } else if(r == 0) { // No contents mp_msg(MSGT_PLAYTREE,MSGL_ERR,"empty asx element"); asx_parser_free(parser); - return NULL; + return false; } if(strcasecmp(element,"ASX") != 0) { mp_msg(MSGT_PLAYTREE,MSGL_ERR,"first element isn't ASX, it's %s\n",element); asx_free_attribs(asx_attribs); asx_parser_free(parser); - return NULL; + return false; } if(!asx_body) { mp_msg(MSGT_PLAYTREE,MSGL_ERR,"ASX element is empty"); asx_free_attribs(asx_attribs); asx_parser_free(parser); - return NULL; + return false; } - asx = play_tree_new(); buffer = asx_body; while(buffer && buffer[0] != '\0') { r = asx_get_element(parser,&buffer,&element,&body,&attribs); if(r < 0) { asx_warning_body_parse_error(parser,"ASX"); asx_parser_free(parser); - return NULL; + return false; } else if (r == 0) { // No more element break; } if(strcasecmp(element,"ENTRY") == 0) { - entry = asx_parse_entry(parser,body,attribs); - if(entry) { - if(!list) list = entry; - else play_tree_append_entry(list,entry); - mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Adding element %s to asx\n",element); - } + asx_parse_entry(parser,body,attribs); } else if(strcasecmp(element,"ENTRYREF") == 0) { - entry = asx_parse_entryref(parser,body,attribs); - if(entry) { - if(!list) list = entry; - else play_tree_append_entry(list,entry); - mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Adding element %s to asx\n",element); - } + asx_parse_entryref(parser,body,attribs); } else if(strcasecmp(element,"REPEAT") == 0) { - entry = asx_parse_repeat(parser,body,attribs); - if(entry) { - if(!list) list = entry; - else play_tree_append_entry(list,entry); - mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Adding element %s to asx\n",element); - } + asx_parse_repeat(parser,body,attribs); } else mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Ignoring element %s\n",element); free(body); @@ -632,15 +605,5 @@ asx_parser_build_tree(struct m_config *mconfig, char* buffer,int deep) { free(asx_body); asx_free_attribs(asx_attribs); asx_parser_free(parser); - - - if(!list) { - play_tree_free(asx,1); - - return NULL; - } - - play_tree_set_child(asx,list); - - return asx; + return true; } diff --git a/asxparser.h b/asxparser.h index 57577101fb..e49a2cedc0 100644 --- a/asxparser.h +++ b/asxparser.h @@ -19,59 +19,9 @@ #ifndef MPLAYER_ASXPARSER_H #define MPLAYER_ASXPARSER_H -#include "playtree.h" +#include -typedef struct ASX_Parser_t ASX_Parser_t; - -typedef struct { - char* buffer; - int line; -} ASX_LineSave_t; - -struct ASX_Parser_t { - int line; // Curent line - ASX_LineSave_t *ret_stack; - int ret_stack_size; - char* last_body; - int deep; - struct m_config *mconfig; -}; - -struct m_config; -ASX_Parser_t* -asx_parser_new(struct m_config *mconfig); - -void -asx_parser_free(ASX_Parser_t* parser); - -/* - * Return -1 on error, 0 when nothing is found, 1 on sucess - */ -int -asx_get_element(ASX_Parser_t* parser,char** _buffer, - char** _element,char** _body,char*** _attribs); - -int -asx_parse_attribs(ASX_Parser_t* parser,char* buffer,char*** _attribs); - -/////// Attribs utils - -char* -asx_get_attrib(const char* attrib,char** attribs); - -int -asx_attrib_to_enum(const char* val,char** valid_vals); - -#define asx_free_attribs(a) asx_list_free(&a,free) - -////// List utils - -typedef void (*ASX_FreeFunc)(void* arg); - -void -asx_list_free(void* list_ptr,ASX_FreeFunc free_func); - -play_tree_t* -asx_parser_build_tree(struct m_config *mconfig, char* buffer, int ref); +struct playlist; +bool asx_parse(char* buffer, struct playlist *pl); #endif /* MPLAYER_ASXPARSER_H */ diff --git a/command.c b/command.c index d90d3ee76b..72f978d3be 100644 --- a/command.c +++ b/command.c @@ -32,6 +32,8 @@ #include "libmpdemux/stheader.h" #include "codec-cfg.h" #include "mplayer.h" +#include "playlist.h" +#include "playlist_parser.h" #include "sub/sub.h" #include "sub/dec_sub.h" #include "m_option.h" @@ -43,7 +45,7 @@ #include "mp_osd.h" #include "libvo/video_out.h" #include "libvo/csputils.h" -#include "playtree.h" +#include "playlist.h" #include "libao2/audio_out.h" #include "mpcommon.h" #include "mixer.h" @@ -2771,28 +2773,6 @@ static void remove_subtitle_range(MPContext *mpctx, int start, int count) } } -static void do_clear_pt(struct play_tree *node, struct play_tree *exclude) -{ - while (node) { - do_clear_pt(node->child, exclude); - struct play_tree *next = node->next; - // do not delete root node, or nodes that could lead to "exclude" node - if (node->parent && !node->child && node != exclude) - play_tree_remove(node, 1, 1); - node = next; - } -} - -static void clear_play_tree(MPContext *mpctx) -{ - struct play_tree *exclude = NULL; - if (mpctx->playtree_iter) { - assert(mpctx->playtree == mpctx->playtree_iter->root); - exclude = mpctx->playtree_iter->tree; - } - do_clear_pt(mpctx->playtree, exclude); -} - static char *format_time(double time) { int h, m, s = time; @@ -3085,54 +3065,21 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd) exit_player_with_rc(mpctx, EXIT_QUIT, (cmd->nargs > 0) ? cmd->args[0].v.i : 0); - case MP_CMD_PLAY_TREE_STEP: { - int n = cmd->args[0].v.i == 0 ? 1 : cmd->args[0].v.i; - int force = cmd->args[1].v.i; - - { - if (!force && mpctx->playtree_iter) { - play_tree_iter_t *i = - play_tree_iter_new_copy(mpctx->playtree_iter); - if (play_tree_iter_step(i, n, 0) == - PLAY_TREE_ITER_ENTRY) - mpctx->stop_play = - (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY; - play_tree_iter_free(i); - } else - mpctx->stop_play = (n > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY; - if (mpctx->stop_play) - mpctx->play_tree_step = n; - } - break; - } - - case MP_CMD_PLAY_TREE_UP_STEP: { - int n = cmd->args[0].v.i > 0 ? 1 : -1; - int force = cmd->args[1].v.i; + case MP_CMD_PLAYLIST_NEXT: + case MP_CMD_PLAYLIST_PREV: + { + int dir = cmd->id == MP_CMD_PLAYLIST_PREV ? -1 : +1; + int force = cmd->args[0].v.i; - if (!force && mpctx->playtree_iter) { - play_tree_iter_t *i = - play_tree_iter_new_copy(mpctx->playtree_iter); - if (play_tree_iter_up_step(i, n, 0) == PLAY_TREE_ITER_ENTRY) - mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV; - play_tree_iter_free(i); - } else - mpctx->stop_play = (n > 0) ? PT_UP_NEXT : PT_UP_PREV; + struct playlist_entry *e = playlist_get_next(mpctx->playlist, dir); + if (!e && !force) + break; + mpctx->playlist->current = e; + mpctx->playlist->current_was_replaced = false; + mpctx->stop_play = PT_CURRENT_ENTRY; break; } - case MP_CMD_PLAY_ALT_SRC_STEP: - if (mpctx->playtree_iter && mpctx->playtree_iter->num_files > 1) { - int v = cmd->args[0].v.i; - if (v > 0 - && mpctx->playtree_iter->file < - mpctx->playtree_iter->num_files) - mpctx->stop_play = PT_NEXT_SRC; - else if (v < 0 && mpctx->playtree_iter->file > 1) - mpctx->stop_play = PT_PREV_SRC; - } - break; - case MP_CMD_SUB_STEP: if (sh_video) { int movement = cmd->args[0].v.i; @@ -3198,56 +3145,59 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd) } case MP_CMD_LOADFILE: { - play_tree_t *e = play_tree_new(); - play_tree_add_file(e, cmd->args[0].v.s); + char *filename = cmd->args[0].v.s; + bool append = cmd->args[1].v.i; - if (cmd->args[1].v.i) // append - play_tree_append_entry(mpctx->playtree->child, e); - else { - // Go back to the starting point. - while (play_tree_iter_up_step(mpctx->playtree_iter, 0, 1) - != PLAY_TREE_ITER_END) - /* NOP */; - play_tree_free_list(mpctx->playtree->child, 1); - play_tree_set_child(mpctx->playtree, e); - pt_iter_goto_head(mpctx->playtree_iter); - mpctx->stop_play = PT_NEXT_SRC; + if (!append) + playlist_clear(mpctx->playlist); + + playlist_add(mpctx->playlist, playlist_entry_new(filename)); + + if (!append) { + mpctx->playlist->current = mpctx->playlist->first; + mpctx->playlist->current_was_replaced = false; + mpctx->stop_play = PT_CURRENT_ENTRY; } break; } case MP_CMD_LOADLIST: { - play_tree_t *e = parse_playlist_file(mpctx->mconfig, - bstr0(cmd->args[0].v.s)); - if (!e) + char *filename = cmd->args[0].v.s; + bool append = cmd->args[1].v.i; + struct playlist *pl = playlist_parse_file(filename); + if (!pl) { + if (!append) + playlist_clear(mpctx->playlist); + playlist_transfer_entries(mpctx->playlist, pl); + talloc_free(pl); + + if (!append) + mpctx->stop_play = PT_NEXT_ENTRY; + } else { mp_tmsg(MSGT_CPLAYER, MSGL_ERR, - "\nUnable to load playlist %s.\n", cmd->args[0].v.s); - else { - if (cmd->args[1].v.i) // append - play_tree_append_entry(mpctx->playtree->child, e); - else { - // Go back to the starting point. - while (play_tree_iter_up_step(mpctx->playtree_iter, 0, 1) - != PLAY_TREE_ITER_END) - /* NOP */; - play_tree_free_list(mpctx->playtree->child, 1); - play_tree_set_child(mpctx->playtree, e); - pt_iter_goto_head(mpctx->playtree_iter); - mpctx->stop_play = PT_NEXT_SRC; - } + "\nUnable to load playlist %s.\n", filename); } break; } - case MP_CMD_PLAY_TREE_CLEAR: - clear_play_tree(mpctx); + case MP_CMD_PLAYLIST_CLEAR: { + // Supposed to clear the playlist, except the currently played item. + if (mpctx->playlist->current_was_replaced) + mpctx->playlist->current = NULL; + while (mpctx->playlist->first) { + struct playlist_entry *e = mpctx->playlist->first; + if (e == mpctx->playlist->current) { + e = e->next; + if (!e) + break; + } + playlist_remove(mpctx->playlist, e); + } break; + } case MP_CMD_STOP: // Go back to the starting point. - while (play_tree_iter_up_step(mpctx->playtree_iter, 0, 1) != - PLAY_TREE_ITER_END) - /* NOP */; mpctx->stop_play = PT_STOP; break; diff --git a/etc/input.conf b/etc/input.conf index 46bc17d500..0bfc5ca607 100644 --- a/etc/input.conf +++ b/etc/input.conf @@ -57,13 +57,9 @@ ESC quit p pause # toggle pause/playback mode . frame_step # advance one frame and pause SPACE pause -HOME pt_up_step 1 -END pt_up_step -1 -> pt_step 1 # skip to next file -ENTER pt_step 1 1 # skip to next file or quit -< pt_step -1 # skip to previous file -INS alt_src_step 1 -DEL alt_src_step -1 +> playlist_next # skip to next file +ENTER playlist_next 1 # skip to next file or quit +< playlist_prev # skip to previous file o osd # cycle through OSD mode I osd_show_property_text "${filename}" # display filename in osd P osd_show_progression @@ -121,8 +117,8 @@ PLAYPAUSE pause STOP quit FORWARD seek 60 REWIND seek -60 -NEXT pt_step 1 -PREV pt_step -1 +NEXT playlist_next +PREV playlist_prev VOLUME_UP volume 1 VOLUME_DOWN volume -1 MUTE mute diff --git a/input/input.c b/input/input.c index dbc29d964f..836c9df14a 100644 --- a/input/input.c +++ b/input/input.c @@ -108,9 +108,8 @@ static const mp_cmd_t mp_cmds[] = { { MP_CMD_STOP, "stop", }, { MP_CMD_PAUSE, "pause", }, { MP_CMD_FRAME_STEP, "frame_step", }, - { MP_CMD_PLAY_TREE_STEP, "pt_step", { ARG_INT, OARG_INT(0) } }, - { MP_CMD_PLAY_TREE_UP_STEP, "pt_up_step", { ARG_INT, OARG_INT(0) } }, - { MP_CMD_PLAY_ALT_SRC_STEP, "alt_src_step", { ARG_INT } }, + { MP_CMD_PLAYLIST_NEXT, "playlist_next", { OARG_INT(0) } }, + { MP_CMD_PLAYLIST_PREV, "playlist_prev", { OARG_INT(0) } }, { MP_CMD_LOOP, "loop", { ARG_INT, OARG_INT(0) } }, { MP_CMD_SUB_DELAY, "sub_delay", { ARG_FLOAT, OARG_INT(0) } }, { MP_CMD_SUB_STEP, "sub_step", { ARG_INT, OARG_INT(0) } }, @@ -193,7 +192,7 @@ static const mp_cmd_t mp_cmds[] = { { MP_CMD_SWITCH_VSYNC, "switch_vsync", { OARG_INT(0) } }, { MP_CMD_LOADFILE, "loadfile", { ARG_STRING, OARG_INT(0) } }, { MP_CMD_LOADLIST, "loadlist", { ARG_STRING, OARG_INT(0) } }, - { MP_CMD_PLAY_TREE_CLEAR, "pt_clear", }, + { MP_CMD_PLAYLIST_CLEAR, "playlist_clear", }, { MP_CMD_RUN, "run", { ARG_STRING } }, { MP_CMD_CAPTURING, "capturing", }, { MP_CMD_VF_CHANGE_RECTANGLE, "change_rectangle", { ARG_INT, ARG_INT } }, @@ -444,13 +443,9 @@ static const struct cmd_bind def_cmd_binds[] = { { { 'p', 0 }, "pause" }, { { ' ', 0 }, "pause" }, { { '.', 0 }, "frame_step" }, - { { KEY_HOME, 0 }, "pt_up_step 1" }, - { { KEY_END, 0 }, "pt_up_step -1" }, - { { '>', 0 }, "pt_step 1" }, - { { KEY_ENTER, 0 }, "pt_step 1 1" }, - { { '<', 0 }, "pt_step -1" }, - { { KEY_INS, 0 }, "alt_src_step 1" }, - { { KEY_DEL, 0 }, "alt_src_step -1" }, + { { '>', 0 }, "playlist_next" }, + { { KEY_ENTER, 0 }, "playlist_next 1" }, + { { '<', 0 }, "playlist_prev" }, { { 'o', 0 }, "osd" }, { { 'I', 0 }, "osd_show_property_text \"${filename}\"" }, { { 'P', 0 }, "osd_show_progression" }, @@ -537,8 +532,8 @@ static const struct cmd_bind def_cmd_binds[] = { { { KEY_STOP, 0 }, "quit" }, { { KEY_FORWARD, 0 }, "seek 60" }, { { KEY_REWIND, 0 }, "seek -60" }, - { { KEY_NEXT, 0 }, "pt_step 1" }, - { { KEY_PREV, 0 }, "pt_step -1" }, + { { KEY_NEXT, 0 }, "playlist_next" }, + { { KEY_PREV, 0 }, "playlist_prev" }, { { KEY_VOLUME_UP, 0 }, "volume 1" }, { { KEY_VOLUME_DOWN, 0 }, "volume -1" }, { { KEY_MUTE, 0 }, "mute" }, @@ -709,13 +704,12 @@ static char *get_key_combo_name(int *keys, int max) return ret; } -static bool is_abort_cmd(int cmd_id) +bool mp_input_is_abort_cmd(int cmd_id) { switch (cmd_id) { case MP_CMD_QUIT: - case MP_CMD_PLAY_TREE_STEP: - case MP_CMD_PLAY_TREE_UP_STEP: - case MP_CMD_PLAY_ALT_SRC_STEP: + case MP_CMD_PLAYLIST_NEXT: + case MP_CMD_PLAYLIST_PREV: return true; } return false; @@ -732,7 +726,7 @@ static int queue_count_cmds(struct cmd_queue *queue) static bool queue_has_abort_cmds(struct cmd_queue *queue) { for (struct mp_cmd *cmd = queue->first; cmd; cmd = cmd->queue_next) { - if (is_abort_cmd(cmd->id)) + if (mp_input_is_abort_cmd(cmd->id)) return true; } return false; @@ -1339,7 +1333,7 @@ void mp_input_feed_key(struct input_ctx *ictx, int code) return; struct cmd_queue *queue = &ictx->key_cmd_queue; if (queue_count_cmds(queue) >= ictx->key_fifo_size && - (!is_abort_cmd(cmd->id) || queue_has_abort_cmds(queue))) + (!mp_input_is_abort_cmd(cmd->id) || queue_has_abort_cmds(queue))) return; queue_add(queue, cmd, false); } diff --git a/input/input.h b/input/input.h index 977901b6d3..922cc21bbc 100644 --- a/input/input.h +++ b/input/input.h @@ -28,9 +28,8 @@ enum mp_command_type { MP_CMD_QUIT, MP_CMD_PAUSE, MP_CMD_GRAB_FRAMES, // deprecated: was a no-op command for years - MP_CMD_PLAY_TREE_STEP, - MP_CMD_PLAY_TREE_UP_STEP, - MP_CMD_PLAY_ALT_SRC_STEP, + MP_CMD_PLAYLIST_NEXT, + MP_CMD_PLAYLIST_PREV, MP_CMD_SUB_DELAY, MP_CMD_OSD, MP_CMD_VOLUME, @@ -52,7 +51,7 @@ enum mp_command_type { MP_CMD_MUTE, MP_CMD_LOADFILE, MP_CMD_LOADLIST, - MP_CMD_PLAY_TREE_CLEAR, + MP_CMD_PLAYLIST_CLEAR, MP_CMD_VF_CHANGE_RECTANGLE, MP_CMD_GAMMA, MP_CMD_SUB_VISIBILITY, @@ -201,6 +200,9 @@ typedef struct mp_cmd { } mp_cmd_t; +// Executing this command will abort playback (play something else, or quit). +bool mp_input_is_abort_cmd(int cmd_id); + /* Add a new command input source. * "fd" is a file descriptor (use a negative value if you don't use any fd) * "select" tells whether to use select() on the fd to determine when to diff --git a/libvo/video_out.c b/libvo/video_out.c index ce0ccd137a..7f78a2d07c 100644 --- a/libvo/video_out.c +++ b/libvo/video_out.c @@ -176,12 +176,11 @@ static int vo_preinit(struct vo *vo, char *arg) if (vo->driver->privsize) vo->priv = talloc_zero_size(vo, vo->driver->privsize); if (vo->driver->options) { - struct m_config *cfg = m_config_simple(vo->driver->options); - m_config_initialize(cfg, vo->priv); + struct m_config *cfg = m_config_simple(vo->driver->options, vo->priv); char n[50]; int l = snprintf(n, sizeof(n), "vo/%s", vo->driver->info->short_name); assert(l < sizeof(n)); - int r = m_config_parse_suboptions(cfg, vo->priv, n, arg); + int r = m_config_parse_suboptions(cfg, n, arg); talloc_free(cfg); if (r < 0) return r; diff --git a/m_config.c b/m_config.c index 0c5677a7cc..5b8dc77ba7 100644 --- a/m_config.c +++ b/m_config.c @@ -140,22 +140,26 @@ static int list_options(struct m_option *opt, char *name, char *param) return M_OPT_EXIT; } -static void m_option_save(const struct m_config *config, - const struct m_option *opt, void *dst) +static void *optstruct_ptr(const struct m_config *config, + const struct m_option *opt) { - if (opt->type->copy) { - const void *src = m_option_get_ptr(opt, config->optstruct); - opt->type->copy(opt, dst, src, NULL); - } + return m_option_get_ptr(opt, config->optstruct); } -static void m_option_set(void *optstruct, - const struct m_option *opt, const void *src) +static void optstruct_get(const struct m_config *config, + const struct m_option *opt, + void *dst) { - if (opt->type->copy) { - void *dst = m_option_get_ptr(opt, optstruct); - opt->type->copy(opt, dst, src, optstruct); - } + if (opt->type->copy) + opt->type->copy(opt, dst, optstruct_ptr(config, opt), NULL); +} + +static void optstruct_set(const struct m_config *config, + const struct m_option *opt, + const void *src) +{ + if (opt->type->copy) + opt->type->copy(opt, optstruct_ptr(config, opt), src, config->optstruct); } @@ -164,6 +168,23 @@ static void m_config_add_option(struct m_config *config, const struct m_option *arg, const char *prefix, char *disabled_feature); +static int config_destroy(void *p) +{ + struct m_config *config = p; + for (struct m_config_option *copt = config->opts; copt; copt = copt->next) { + if (copt->flags & M_CFG_OPT_ALIAS) + continue; + if (copt->opt->type->flags & M_OPT_TYPE_DYNAMIC) { + void *ptr = m_option_get_ptr(copt->opt, config->optstruct); + if (ptr) + m_option_free(copt->opt, ptr); + } + if (copt->global_backup) + m_option_free(copt->opt, copt->global_backup); + } + return 0; +} + struct m_config *m_config_new(void *optstruct, int includefunc(struct m_config *conf, char *filename)) @@ -177,8 +198,7 @@ struct m_config *m_config_new(void *optstruct, }; config = talloc_zero(NULL, struct m_config); - config->full = true; - config->lvl = 1; // 0 Is the defaults + talloc_set_destructor(config, config_destroy); struct m_option *self_opts = talloc_memdup(config, ref_opts, sizeof(ref_opts)); for (int i = 1; self_opts[i].name; i++) @@ -197,113 +217,56 @@ struct m_config *m_config_new(void *optstruct, return config; } -struct m_config *m_config_simple(const struct m_option *options) +struct m_config *m_config_simple(const struct m_option *options, + void *optstruct) { - struct m_config *config = talloc_zero(NULL, struct m_config); + struct m_config *config = talloc_struct(NULL, struct m_config, { + .optstruct = optstruct, + }); + talloc_set_destructor(config, config_destroy); m_config_register_options(config, options); return config; } void m_config_free(struct m_config *config) { - assert(config->full); // use talloc_free() for simple - struct m_config_option *copt; - for (copt = config->opts; copt; copt = copt->next) { - if (copt->flags & M_CFG_OPT_ALIAS) - continue; - if (copt->opt->type->flags & M_OPT_TYPE_DYNAMIC) { - void *ptr = m_option_get_ptr(copt->opt, config->optstruct); - if (ptr) - m_option_free(copt->opt, ptr); - } - struct m_config_save_slot *sl; - for (sl = copt->slots; sl; sl = sl->prev) - m_option_free(copt->opt, sl->data); - } talloc_free(config); } -void m_config_initialize(struct m_config *config, void *optstruct) +static void ensure_backup(struct m_config *config, struct m_config_option *co) { - struct m_config_option *copt; - for (copt = config->opts; copt; copt = copt->next) { - const struct m_option *opt = copt->opt; - if (!opt->defval) - continue; - m_option_set(optstruct, opt, opt->defval); - } + if (!config->file_local_mode) + return; + if (co->opt->type->flags & M_OPT_TYPE_HAS_CHILD) + return; + if (co->opt->flags & (M_OPT_GLOBAL | M_OPT_NOSAVE)) + return; + if (co->flags & M_CFG_OPT_ALIAS) + return; + if (co->global_backup) + return; + co->global_backup = talloc_zero_size(co, co->opt->type->size); + optstruct_get(config, co->opt, co->global_backup); } -void m_config_push(struct m_config *config) +void m_config_enter_file_local(struct m_config *config) { - struct m_config_option *co; - struct m_config_save_slot *slot; - - assert(config != NULL); - assert(config->lvl > 0); - - config->lvl++; - - for (co = config->opts; co; co = co->next) { - if (co->opt->type->flags & M_OPT_TYPE_HAS_CHILD) - continue; - if (co->opt->flags & (M_OPT_GLOBAL | M_OPT_NOSAVE)) - continue; - if (co->flags & M_CFG_OPT_ALIAS) - continue; - - // Update the current status - m_option_save(config, co->opt, co->slots->data); - - // Allocate a new slot - slot = talloc_zero_size(co, sizeof(struct m_config_save_slot) + - co->opt->type->size); - slot->lvl = config->lvl; - slot->prev = co->slots; - co->slots = slot; - m_option_copy(co->opt, co->slots->data, co->slots->prev->data); - // Reset our set flag - co->flags &= ~M_CFG_OPT_SET; - } - - mp_msg(MSGT_CFGPARSER, MSGL_DBG2, - "Config pushed level is now %d\n", config->lvl); + assert(!config->file_local_mode); + config->file_local_mode = true; } -void m_config_pop(struct m_config *config) +void m_config_leave_file_local(struct m_config *config) { - struct m_config_option *co; - struct m_config_save_slot *slot; - - assert(config != NULL); - assert(config->lvl > 1); - - for (co = config->opts; co; co = co->next) { - int pop = 0; - if (co->opt->type->flags & M_OPT_TYPE_HAS_CHILD) - continue; - if (co->opt->flags & (M_OPT_GLOBAL | M_OPT_NOSAVE)) - continue; - if (co->flags & M_CFG_OPT_ALIAS) - continue; - if (co->slots->lvl > config->lvl) - mp_msg(MSGT_CFGPARSER, MSGL_WARN, - "Save slot found from lvl %d is too old: %d !!!\n", - config->lvl, co->slots->lvl); - - while (co->slots->lvl >= config->lvl) { - m_option_free(co->opt, co->slots->data); - slot = co->slots; - co->slots = slot->prev; - talloc_free(slot); - pop++; + assert(config->file_local_mode); + config->file_local_mode = false; + for (struct m_config_option *co = config->opts; co; co = co->next) { + if (co->global_backup) { + optstruct_set(config, co->opt, co->global_backup); + m_option_free(co->opt, co->global_backup); + talloc_free(co->global_backup); + co->global_backup = NULL; } - if (pop) // We removed some ctx -> set the previous value - m_option_set(config->optstruct, co->opt, co->slots->data); } - - config->lvl--; - mp_msg(MSGT_CFGPARSER, MSGL_DBG2, "Config poped level=%d\n", config->lvl); } static void add_options(struct m_config *config, const struct m_option *defs, @@ -332,15 +295,12 @@ static void m_config_add_option(struct m_config *config, char *disabled_feature) { struct m_config_option *co; - struct m_config_save_slot *sl; assert(config != NULL); - assert(config->lvl > 0 || !config->full); assert(arg != NULL); // Allocate a new entry for this option - co = talloc_zero_size(config, - sizeof(struct m_config_option) + arg->type->size); + co = talloc_zero(config, struct m_config_option); co->opt = arg; co->disabled_feature = disabled_feature; @@ -361,33 +321,33 @@ static void m_config_add_option(struct m_config *config, if (arg->new ? (i->opt->new && i->opt->offset == arg->offset) : (!i->opt->new && i->opt->p == arg->p)) { // So we don't save the same vars more than 1 time - co->slots = i->slots; co->flags |= M_CFG_OPT_ALIAS; break; } } } - if (config->full && !(co->flags & M_CFG_OPT_ALIAS)) { - // Allocate a slot for the defaults - sl = talloc_zero_size(co, sizeof(struct m_config_save_slot) + - arg->type->size); - m_option_save(config, arg, sl->data); - // Hack to avoid too much trouble with dynamically allocated data: - // We replace original default and always use a dynamic version - if (!arg->new && (arg->type->flags & M_OPT_TYPE_DYNAMIC)) { - char **hackptr = m_option_get_ptr(arg, config->optstruct); - if (hackptr && *hackptr) { - *hackptr = NULL; - m_option_set(config->optstruct, arg, sl->data); + if (co->flags & M_CFG_OPT_ALIAS) { + assert(!arg->defval); + } else { + if (arg->defval) { + // Target data in optstruct is supposed to be cleared (consider + // m_option freeing previously set dynamic data). + optstruct_set(config, arg, arg->defval); + } else if (!arg->new && (arg->type->flags & M_OPT_TYPE_DYNAMIC)) { + // Initialize dynamically managed fields from static data (like + // string options): copy the option into temporary memory, + // clear the original option (to void m_option freeing the + // static data), copy it back. + void *init_data = optstruct_ptr(config, arg); + if (init_data) { + void *temp = talloc_zero_size(NULL, arg->type->size); + m_option_copy(arg, temp, init_data); + memset(init_data, 0, arg->type->size); + optstruct_set(config, arg, temp); + m_option_free(arg, temp); + talloc_free(temp); } } - sl->lvl = 0; - sl->prev = NULL; - co->slots = talloc_zero_size(co, sizeof(struct m_config_save_slot) + - arg->type->size); - co->slots->prev = sl; - co->slots->lvl = config->lvl; - m_option_copy(co->opt, co->slots->data, sl->data); } } co->next = config->opts; @@ -398,7 +358,6 @@ int m_config_register_options(struct m_config *config, const struct m_option *args) { assert(config != NULL); - assert(config->lvl > 0 || !config->full); assert(args != NULL); add_options(config, args, NULL, NULL); @@ -432,7 +391,6 @@ static int m_config_parse_option(struct m_config *config, void *optstruct, bool ambiguous_param, bool set) { assert(config != NULL); - assert(config->lvl > 0 || !config->full); assert(name.len != 0); struct m_config_option *co = m_config_get_co(config, name); @@ -483,6 +441,9 @@ static int m_config_parse_option(struct m_config *config, void *optstruct, return parse_subopts(config, optstruct, co->name, prefix, param, set); } + if (set) + ensure_backup(config, co); + void *dst = set ? m_option_get_ptr(co->opt, optstruct) : NULL; int r = co->opt->type->parse(co->opt, name, param, ambiguous_param, dst, optstruct); @@ -573,12 +534,13 @@ int m_config_check_option(struct m_config *config, struct bstr name, return r; } -int m_config_parse_suboptions(struct m_config *config, void *optstruct, - char *name, char *subopts) +int m_config_parse_suboptions(struct m_config *config, char *name, + char *subopts) { if (!subopts || !*subopts) return 0; - return parse_subopts(config, optstruct, name, "", bstr0(subopts), true); + return parse_subopts(config, config->optstruct, name, "", bstr0(subopts), + true); } @@ -588,7 +550,6 @@ const struct m_option *m_config_get_option(const struct m_config *config, struct m_config_option *co; assert(config != NULL); - assert(config->lvl > 0 || !config->full); co = m_config_get_co(config, name); if (co) diff --git a/m_config.h b/m_config.h index 623b754718..56413b60a4 100644 --- a/m_config.h +++ b/m_config.h @@ -31,17 +31,6 @@ typedef struct m_profile m_profile_t; struct m_option; struct m_option_type; -// Config option save slot -struct m_config_save_slot { - // Previous level slot. - struct m_config_save_slot *prev; - // Level at which the save was made. - int lvl; - // We have to store other datatypes in this as well, - // so make sure we get properly aligned addresses. - unsigned char data[0] __attribute__ ((aligned(8))); -}; - // Config option struct m_config_option { struct m_config_option *next; @@ -51,8 +40,8 @@ struct m_config_option { char *disabled_feature; // Option description. const struct m_option *opt; - // Save slot stack. - struct m_config_save_slot *slots; + // Raw value of the backup of the global value (or NULL). + void *global_backup; // See \ref ConfigOptionFlags. unsigned int flags; }; @@ -86,9 +75,12 @@ typedef struct m_config { /** This contains all options and suboptions. */ struct m_config_option *opts; - // Current stack level. - int lvl; enum option_source mode; + // When options are set (via m_config_set_option or m_config_set_profile), + // back up the old value (unless it's already backed up). Used for restoring + // global options when per-file options are set. + bool file_local_mode; + // List of defined profiles. struct m_profile *profiles; // Depth when recursively including profiles. @@ -96,7 +88,6 @@ typedef struct m_config { void *optstruct; // struct mpopts or other int (*includefunc)(struct m_config *conf, char *filename); - bool full; // main config with save slot handling etc } m_config_t; @@ -111,22 +102,14 @@ struct m_config * m_config_new(void *optstruct, int includefunc(struct m_config *conf, char *filename)); -struct m_config *m_config_simple(const struct m_option *options); - -void m_config_initialize(struct m_config *conf, void *optstruct); +struct m_config *m_config_simple(const struct m_option *options, + void *optstruct); // Free a config object. void m_config_free(struct m_config *config); -/* Push a new context. - * \param config The config object. - */ -void m_config_push(struct m_config *config); - -/* Pop the current context restoring the previous context state. - * \param config The config object. - */ -void m_config_pop(struct m_config *config); +void m_config_enter_file_local(struct m_config *config); +void m_config_leave_file_local(struct m_config *config); /* Register some options to be used. * \param config The config object. @@ -167,8 +150,8 @@ static inline int m_config_check_option0(struct m_config *config, return m_config_check_option(config, bstr0(name), bstr0(param), ambiguous); } -int m_config_parse_suboptions(struct m_config *config, void *optstruct, - char *name, char *subopts); +int m_config_parse_suboptions(struct m_config *config, char *name, + char *subopts); /* Get the option matching the given name. diff --git a/mp_core.h b/mp_core.h index f216ddf0cb..db2624c014 100644 --- a/mp_core.h +++ b/mp_core.h @@ -49,15 +49,11 @@ enum stop_play_reason { - KEEP_PLAYING = 0, // must be 0, numeric values of others do not matter - AT_END_OF_FILE, - PT_NEXT_ENTRY, - PT_PREV_ENTRY, - PT_NEXT_SRC, - PT_PREV_SRC, - PT_UP_NEXT, - PT_UP_PREV, - PT_STOP, + KEEP_PLAYING = 0, // must be 0, numeric values of others do not matter + AT_END_OF_FILE, // file has ended normally, prepare to play next + PT_NEXT_ENTRY, // prepare to play next entry in playlist + PT_CURRENT_ENTRY, // prepare to play mpctx->playlist->current + PT_STOP, // stop playback, clear playlist }; enum exit_reason { @@ -101,11 +97,9 @@ typedef struct MPContext { unsigned int osd_visible; int osd_function; - struct play_tree *playtree; - struct play_tree_iter *playtree_iter; + struct playlist *playlist; char *filename; // currently playing file enum stop_play_reason stop_play; - int play_tree_step; unsigned int initialized_flags; // which subsystems have been initialized struct content_source *sources; diff --git a/mpcommon.h b/mpcommon.h index 2ff66fed40..87f074c6f2 100644 --- a/mpcommon.h +++ b/mpcommon.h @@ -19,6 +19,8 @@ #ifndef MPLAYER_MPCOMMON_H #define MPLAYER_MPCOMMON_H +#include + // both int64_t and double should be able to represent this exactly #define MP_NOPTS_VALUE (-1LL<<63) @@ -31,6 +33,28 @@ #define MP_RESIZE_ARRAY(ctx, p, count) do { \ p = talloc_realloc_size((ctx), p, (count) * sizeof(p[0])); } while (0) + +#define MP_TARRAY_GROW(ctx, p, nextidx) \ + do { \ + size_t nextidx_ = (nextidx); \ + size_t nelems_ = MP_TALLOC_ELEMS(p); \ + if (nextidx_ <= nelems_) \ + p = talloc_realloc_size((ctx), p, \ + (nextidx_ + 1) * sizeof((p)[0]) * 2);\ + } while (0) + +#define MP_TARRAY_APPEND(ctx, p, idxvar, val) \ + do { \ + MP_TARRAY_GROW(ctx, p, idxvar); \ + p[idxvar] = (val); \ + idxvar++; \ + } while (0) + +#define MP_EXPAND_ARGS(...) __VA_ARGS__ + +#define talloc_struct(ctx, type, ...) \ + talloc_memdup(ctx, &(type) MP_EXPAND_ARGS(__VA_ARGS__), sizeof(type)) + #ifdef __GNUC__ /** Use gcc attribute to check printf fns. a1 is the 1-based index of diff --git a/mplayer.c b/mplayer.c index 9cb0b40ecd..af57ebb337 100644 --- a/mplayer.c +++ b/mplayer.c @@ -119,8 +119,8 @@ char *heartbeat_cmd; //**************************************************************************// // Playtree //**************************************************************************// -#include "playtree.h" -#include "playtreeparser.h" +#include "playlist.h" +#include "playlist_parser.h" //**************************************************************************// // Config @@ -685,13 +685,6 @@ void exit_player_with_rc(struct MPContext *mpctx, enum exit_reason how, int rc) mpctx->ass_library = NULL; #endif - if (mpctx->playtree_iter) - play_tree_iter_free(mpctx->playtree_iter); - mpctx->playtree_iter = NULL; - if (mpctx->playtree) - play_tree_free(mpctx->playtree, 1); - mpctx->playtree = NULL; - talloc_free(mpctx->key_fifo); switch (how) { @@ -876,62 +869,36 @@ static void load_per_file_config(m_config_t *conf, const char * const file) } } +static void load_per_file_options(m_config_t *conf, + struct playlist_param *params, + int params_count) +{ + for (int n = 0; n < params_count; n++) + m_config_set_option(conf, params[n].name, params[n].value, false); +} + /* When libmpdemux performs a blocking operation (network connection or * cache filling) if the operation fails we use this function to check * if it was interrupted by the user. - * The function returns a new value for eof. */ -static int libmpdemux_was_interrupted(struct MPContext *mpctx, int stop_play) + * The function returns whether it was interrupted. */ +static bool libmpdemux_was_interrupted(struct MPContext *mpctx) { - mp_cmd_t *cmd; - if ((cmd = mp_input_get_cmd(mpctx->input, 0, 0)) != NULL) { - switch (cmd->id) { - case MP_CMD_QUIT: - exit_player_with_rc(mpctx, EXIT_QUIT, - (cmd->nargs > 0) ? cmd->args[0].v.i : 0); - case MP_CMD_PLAY_TREE_STEP: { - stop_play = (cmd->args[0].v.i > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY; - mpctx->play_tree_step = - (cmd->args[0].v.i == 0) ? 1 : cmd->args[0].v.i; - } break; - case MP_CMD_PLAY_TREE_UP_STEP: { - stop_play = (cmd->args[0].v.i > 0) ? PT_UP_NEXT : PT_UP_PREV; - } break; - case MP_CMD_PLAY_ALT_SRC_STEP: { - stop_play = (cmd->args[0].v.i > 0) ? PT_NEXT_SRC : PT_PREV_SRC; - } break; + // Basically, give queued up user commands a chance to run, if the normal + // play loop (which does run_command()) hasn't been executed for a while. + mp_cmd_t *cmd = mp_input_get_cmd(mpctx->input, 0, 0); + if (cmd) { + // Only run "safe" commands. Consider the case someone queues up a + // command to load a file, and immediately after that to select a + // subtitle stream. This function can be called between opening the + // file and opening the demuxer. We don't want the subtitle command to + // be lost. + if (mp_input_is_abort_cmd(cmd->id)) { + run_command(mpctx, cmd); + mp_cmd_free(cmd); } - mp_cmd_free(cmd); } - return stop_play; -} - -static int playtree_add_playlist(struct MPContext *mpctx, play_tree_t *entry) -{ - play_tree_add_bpf(entry, bstr0(mpctx->filename)); - - { - if (!entry) { - entry = mpctx->playtree_iter->tree; - if (play_tree_iter_step(mpctx->playtree_iter, 1, 0) - != PLAY_TREE_ITER_ENTRY) - return PT_NEXT_ENTRY; - if (mpctx->playtree_iter->tree == entry) { // Single file loop - if (play_tree_iter_up_step(mpctx->playtree_iter, 1, 0) - != PLAY_TREE_ITER_ENTRY) - return PT_NEXT_ENTRY; - } - play_tree_remove(entry, 1, 1); - return PT_NEXT_SRC; - } - play_tree_insert_entry(mpctx->playtree_iter->tree, entry); - play_tree_set_params_from(entry, mpctx->playtree_iter->tree); - entry = mpctx->playtree_iter->tree; - if (play_tree_iter_step(mpctx->playtree_iter, 1, 0) - != PLAY_TREE_ITER_ENTRY) - return PT_NEXT_ENTRY; - play_tree_remove(entry, 1, 1); - } - return PT_NEXT_SRC; + return mpctx->stop_play != KEEP_PLAYING + || mpctx->stop_play != AT_END_OF_FILE; } void add_subtitles(struct MPContext *mpctx, char *filename, float fps, @@ -3508,6 +3475,20 @@ static int select_audio(demuxer_t *demuxer, int audio_id, char **audio_lang) return demuxer->audio->id; } +// Waiting for the slave master to send us a new file to play. +static void idle_loop(struct MPContext *mpctx) +{ + // ================= idle loop (STOP state) ========================= + while (mpctx->opts.player_idle_mode && !mpctx->playlist->current) { + uninit_player(mpctx, INITIALIZED_AO | INITIALIZED_VO); + mp_cmd_t *cmd; + while (!(cmd = mp_input_get_cmd(mpctx->input, WAKEUP_PERIOD * 1000, + false))); + run_command(mpctx, cmd); + mp_cmd_free(cmd); + } +} + static void print_version(int always) { mp_msg(MSGT_CPLAYER, always ? MSGL_INFO : MSGL_V, @@ -3552,7 +3533,6 @@ int main(int argc, char *argv[]) *mpctx = (struct MPContext){ .osd_function = OSD_PLAY, .begin_skip = MP_NOPTS_VALUE, - .play_tree_step = 1, .global_sub_pos = -1, .set_of_sub_pos = -1, .file_format = DEMUXER_TYPE_UNKNOWN, @@ -3577,7 +3557,6 @@ int main(int argc, char *argv[]) m_config_register_options(mpctx->mconfig, mplayer_opts); m_config_register_options(mpctx->mconfig, common_opts); mp_input_register_options(mpctx->mconfig); - m_config_initialize(mpctx->mconfig, opts); // Preparse the command line m_config_preparse_command_line(mpctx->mconfig, argc, argv, &verbose); @@ -3597,24 +3576,13 @@ int main(int argc, char *argv[]) parse_cfgfiles(mpctx, mpctx->mconfig); - mpctx->playtree = m_config_parse_mp_command_line(mpctx->mconfig, argc, argv); - if (mpctx->playtree == NULL) + mpctx->playlist = talloc_struct(mpctx, struct playlist, {0}); + if (m_config_parse_mp_command_line(mpctx->mconfig, mpctx->playlist, + argc, argv)) + { + mpctx->playlist->current = mpctx->playlist->first; + } else { opt_exit = 1; - else { - mpctx->playtree = play_tree_cleanup(mpctx->playtree); - if (mpctx->playtree) { - mpctx->playtree_iter = play_tree_iter_new(mpctx->playtree, - mpctx->mconfig); - if (mpctx->playtree_iter) { - if (play_tree_iter_step(mpctx->playtree_iter, 0, 0) != - PLAY_TREE_ITER_ENTRY) { - play_tree_iter_free(mpctx->playtree_iter); - mpctx->playtree_iter = NULL; - } - mpctx->filename = play_tree_iter_get_file(mpctx->playtree_iter, - 1); - } - } } #if defined(__MINGW32__) || defined(__CYGWIN__) @@ -3717,7 +3685,7 @@ int main(int argc, char *argv[]) if (opt_exit) exit_player(mpctx, EXIT_NONE); - if (!mpctx->filename && !opts->player_idle_mode) { + if (!mpctx->playlist->first && !opts->player_idle_mode) { // no file/vcd/dvd -> show HELP: print_version(true); mp_msg(MSGT_CPLAYER, MSGL_INFO, "%s", mp_gtext(help_text)); @@ -3763,16 +3731,27 @@ int main(int argc, char *argv[]) play_next_file: + mpctx->stop_play = 0; + // init global sub numbers mpctx->global_sub_size = 0; memset(mpctx->sub_counts, 0, sizeof(mpctx->sub_counts)); - if (mpctx->filename) { - load_per_protocol_config(mpctx->mconfig, mpctx->filename); - load_per_extension_config(mpctx->mconfig, mpctx->filename); - load_per_file_config(mpctx->mconfig, mpctx->filename); + mpctx->filename = NULL; + if (mpctx->playlist->current) + mpctx->filename = mpctx->playlist->current->filename; + + if (!mpctx->filename) { + idle_loop(mpctx); + goto play_next_file; } + m_config_enter_file_local(mpctx->mconfig); + + load_per_protocol_confi