diff options
author | wm4 <wm4@nowhere> | 2012-07-31 21:33:26 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2012-07-31 21:33:26 +0200 |
commit | 89a17bcda6c166e98861723b8adc9989f2724c34 (patch) | |
tree | f89e05ea12d48c92b04c90c5d447521d29db711c /asxparser.c | |
parent | 6e020e66e0e454e8c7f1eeb17e85b90262e95386 (diff) | |
download | mpv-89a17bcda6c166e98861723b8adc9989f2724c34.tar.bz2 mpv-89a17bcda6c166e98861723b8adc9989f2724c34.tar.xz |
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.
Diffstat (limited to 'asxparser.c')
-rw-r--r-- | asxparser.c | 207 |
1 files changed, 85 insertions, 122 deletions
diff --git a/asxparser.c b/asxparser.c index 5d0d811ab4..89cf7bd1a1 100644 --- a/asxparser.c +++ b/asxparser.c @@ -24,13 +24,62 @@ #include <string.h> #include <unistd.h> -#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; } |