mirror of
https://github.com/mpv-player/mpv
synced 2024-12-20 09:05:56 +01:00
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.
This commit is contained in:
parent
6e020e66e0
commit
89a17bcda6
@ -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
|
4
Makefile
4
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 \
|
||||
|
207
asxparser.c
207
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);
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Not recursively loading playlist %s\n",href);
|
||||
|
||||
ptp = play_tree_parser_new(stream, parser->mconfig, parser->deep+1);
|
||||
|
||||
pt = play_tree_parser_get_play_tree(ptp, 1);
|
||||
|
||||
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;
|
||||
}
|
||||
|
56
asxparser.h
56
asxparser.h
@ -19,59 +19,9 @@
|
||||
#ifndef MPLAYER_ASXPARSER_H
|
||||
#define MPLAYER_ASXPARSER_H
|
||||
|
||||
#include "playtree.h"
|
||||
#include <stdbool.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 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 */
|
||||
|
154
command.c
154
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;
|
||||
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_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;
|
||||
}
|
||||
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_TREE_UP_STEP: {
|
||||
int n = cmd->args[0].v.i > 0 ? 1 : -1;
|
||||
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_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;
|
||||
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;
|
||||
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
225
m_config.c
225
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)
|
||||
|
43
m_config.h
43
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.
|
||||
|
18
mp_core.h
18
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;
|
||||
|
24
mpcommon.h
24
mpcommon.h
@ -19,6 +19,8 @@
|
||||
#ifndef MPLAYER_MPCOMMON_H
|
||||
#define MPLAYER_MPCOMMON_H
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
// 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
|
||||
|
326
mplayer.c
326
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_config(mpctx->mconfig, mpctx->filename);
|
||||
load_per_extension_config(mpctx->mconfig, mpctx->filename);
|
||||
load_per_file_config(mpctx->mconfig, mpctx->filename);
|
||||
|
||||
if (opts->video_driver_list)
|
||||
load_per_output_config(mpctx->mconfig, PROFILE_CFG_VO,
|
||||
opts->video_driver_list[0]);
|
||||
@ -3780,6 +3759,10 @@ play_next_file:
|
||||
load_per_output_config(mpctx->mconfig, PROFILE_CFG_AO,
|
||||
opts->audio_driver_list[0]);
|
||||
|
||||
assert(mpctx->playlist->current);
|
||||
load_per_file_options(mpctx->mconfig, mpctx->playlist->current->params,
|
||||
mpctx->playlist->current->params_count);
|
||||
|
||||
// We must enable getch2 here to be able to interrupt network connection
|
||||
// or cache filling
|
||||
if (opts->consolecontrols && !slave_mode) {
|
||||
@ -3792,80 +3775,15 @@ play_next_file:
|
||||
mp_msg(MSGT_CPLAYER, MSGL_DBG2, "\n[[[init getch2]]]\n");
|
||||
}
|
||||
|
||||
// ================= idle loop (STOP state) =========================
|
||||
while (opts->player_idle_mode && !mpctx->filename) {
|
||||
uninit_player(mpctx, INITIALIZED_AO | INITIALIZED_VO);
|
||||
play_tree_t *entry = NULL;
|
||||
mp_cmd_t *cmd;
|
||||
while (!(cmd = mp_input_get_cmd(mpctx->input, WAKEUP_PERIOD * 1000,
|
||||
false)));
|
||||
switch (cmd->id) {
|
||||
case MP_CMD_LOADFILE:
|
||||
// prepare a tree entry with the new filename
|
||||
entry = play_tree_new();
|
||||
play_tree_add_file(entry, cmd->args[0].v.s);
|
||||
// The entry is added to the main playtree after the switch().
|
||||
break;
|
||||
case MP_CMD_LOADLIST:
|
||||
entry = parse_playlist_file(mpctx->mconfig, bstr0(cmd->args[0].v.s));
|
||||
break;
|
||||
case MP_CMD_QUIT:
|
||||
exit_player_with_rc(mpctx, EXIT_QUIT,
|
||||
(cmd->nargs > 0) ? cmd->args[0].v.i : 0);
|
||||
break;
|
||||
case MP_CMD_VO_FULLSCREEN:
|
||||
case MP_CMD_GET_PROPERTY:
|
||||
case MP_CMD_SET_PROPERTY:
|
||||
case MP_CMD_STEP_PROPERTY:
|
||||
run_command(mpctx, cmd);
|
||||
break;
|
||||
}
|
||||
|
||||
mp_cmd_free(cmd);
|
||||
|
||||
if (entry) { // user entered a command that gave a valid entry
|
||||
if (mpctx->playtree)
|
||||
// the playtree is always a node with one child. let's clear it
|
||||
play_tree_free_list(mpctx->playtree->child, 1);
|
||||
else
|
||||
// .. or make a brand new playtree
|
||||
mpctx->playtree = play_tree_new();
|
||||
|
||||
if (!mpctx->playtree)
|
||||
continue; // couldn't make playtree! wait for next command
|
||||
|
||||
play_tree_set_child(mpctx->playtree, entry);
|
||||
|
||||
/* Make iterator start at the top the of tree. */
|
||||
mpctx->playtree_iter = play_tree_iter_new(mpctx->playtree,
|
||||
mpctx->mconfig);
|
||||
if (!mpctx->playtree_iter)
|
||||
continue;
|
||||
|
||||
// find the first real item in the tree
|
||||
if (play_tree_iter_step(mpctx->playtree_iter, 0, 0) !=
|
||||
PLAY_TREE_ITER_ENTRY) {
|
||||
// no items!
|
||||
play_tree_iter_free(mpctx->playtree_iter);
|
||||
mpctx->playtree_iter = NULL;
|
||||
continue; // wait for next command
|
||||
}
|
||||
mpctx->filename = play_tree_iter_get_file(mpctx->playtree_iter, 1);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CONFIG_ASS
|
||||
ass_set_style_overrides(mpctx->ass_library, opts->ass_force_style_list);
|
||||
#endif
|
||||
if (mpctx->video_out && mpctx->sh_video && mpctx->video_out->config_ok)
|
||||
vo_control(mpctx->video_out, VOCTRL_RESUME, NULL);
|
||||
|
||||
if (mpctx->filename) {
|
||||
mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "Playing %s.\n", mpctx->filename);
|
||||
if (use_filename_title && opts->vo_wintitle == NULL)
|
||||
opts->vo_wintitle = talloc_strdup(NULL,
|
||||
mp_basename(mpctx->filename));
|
||||
}
|
||||
mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "Playing %s.\n", mpctx->filename);
|
||||
if (use_filename_title && opts->vo_wintitle == NULL)
|
||||
opts->vo_wintitle = talloc_strdup(NULL, mp_basename(mpctx->filename));
|
||||
|
||||
if (edl_output_filename) {
|
||||
if (edl_fd)
|
||||
@ -3884,7 +3802,7 @@ play_next_file:
|
||||
if (vo_vobsub == NULL)
|
||||
mp_tmsg(MSGT_CPLAYER, MSGL_ERR, "Cannot load subtitles: %s\n",
|
||||
opts->vobsub_name);
|
||||
} else if (opts->sub_auto && mpctx->filename) {
|
||||
} else if (opts->sub_auto) {
|
||||
char **vob = find_vob_subtitles(opts, mpctx->filename);
|
||||
for (int i = 0; i < MP_TALLOC_ELEMS(vob); i++) {
|
||||
vo_vobsub = vobsub_open(vob[i], spudec_ifo, 0, &vo_spudec);
|
||||
@ -3916,7 +3834,7 @@ play_next_file:
|
||||
|
||||
mpctx->stream = open_stream(mpctx->filename, opts, &mpctx->file_format);
|
||||
if (!mpctx->stream) { // error...
|
||||
mpctx->stop_play = libmpdemux_was_interrupted(mpctx, PT_NEXT_ENTRY);
|
||||
libmpdemux_was_interrupted(mpctx);
|
||||
goto goto_next_file;
|
||||
}
|
||||
mpctx->initialized_flags |= INITIALIZED_STREAM;
|
||||
@ -3927,12 +3845,19 @@ play_next_file:
|
||||
"MPlayer's playlist code is unsafe and should only be used with "
|
||||
"trusted sources.\nPlayback will probably fail.\n\n");
|
||||
#if 0
|
||||
play_tree_t *entry;
|
||||
// Handle playlist
|
||||
mp_msg(MSGT_CPLAYER, MSGL_V, "Parsing playlist %s...\n",
|
||||
mp_msg(MSGT_CPLAYER, MSGL_WARN, "Parsing playlist %s...\n",
|
||||
mpctx->filename);
|
||||
entry = parse_playtree(mpctx->stream, mpctx->mconfig, 0);
|
||||
mpctx->eof = playtree_add_playlist(mpctx, entry);
|
||||
bool empty = true;
|
||||
struct playlist *pl = playlist_parse(mpctx->stream);
|
||||
if (pl) {
|
||||
empty = pl->first == NULL;
|
||||
playlist_transfer_entries(mpctx->playlist, pl);
|
||||
talloc_free(pl);
|
||||
}
|
||||
if (empty)
|
||||
mp_msg(MSGT_CPLAYER, MSGL_ERR, "Playlist was invalid or empty!\n");
|
||||
mpctx->stop_play = PT_NEXT_ENTRY;
|
||||
goto goto_next_file;
|
||||
#endif
|
||||
}
|
||||
@ -3974,7 +3899,7 @@ goto_enable_cache:
|
||||
stream_cache_size * 1024 * (stream_cache_min_percent / 100.0),
|
||||
stream_cache_size * 1024 * (stream_cache_seek_min_percent / 100.0));
|
||||
if (res == 0)
|
||||
if ((mpctx->stop_play = libmpdemux_was_interrupted(mpctx, PT_NEXT_ENTRY)))
|
||||
if (libmpdemux_was_interrupted(mpctx))
|
||||
goto goto_next_file;
|
||||
}
|
||||
|
||||
@ -3988,7 +3913,7 @@ goto_enable_cache:
|
||||
|
||||
if (mpctx->demuxer && mpctx->demuxer->type == DEMUXER_TYPE_PLAYLIST) {
|
||||
unsigned char *playlist_entry;
|
||||
play_tree_t *list = NULL, *entry = NULL;
|
||||
int entries_added = 0;
|
||||
|
||||
while (ds_get_packet(mpctx->demuxer->video, &playlist_entry) > 0) {
|
||||
char *temp;
|
||||
@ -4005,8 +3930,6 @@ goto_enable_cache:
|
||||
if (!strcmp(playlist_entry, mpctx->filename)) // self-reference
|
||||
continue;
|
||||
|
||||
entry = play_tree_new();
|
||||
|
||||
if (mpctx->filename && !strcmp(mp_basename(playlist_entry),
|
||||
playlist_entry)) { // add reference path of current file
|
||||
temp = malloc((strlen(mpctx->filename) - strlen(mp_basename(
|
||||
@ -4021,26 +3944,22 @@ goto_enable_cache:
|
||||
free(temp);
|
||||
continue;
|
||||
}
|
||||
play_tree_add_file(entry, temp);
|
||||
playlist_add_file(mpctx->playlist, temp);
|
||||
entries_added++;
|
||||
mp_msg(MSGT_CPLAYER, MSGL_V,
|
||||
"Resolving reference to %s.\n", temp);
|
||||
free(temp);
|
||||
}
|
||||
} else
|
||||
play_tree_add_file(entry, playlist_entry);
|
||||
|
||||
if (!list)
|
||||
list = entry;
|
||||
else
|
||||
play_tree_append_entry(list, entry);
|
||||
} else {
|
||||
playlist_add_file(mpctx->playlist, playlist_entry);
|
||||
entries_added++;
|
||||
}
|
||||
}
|
||||
free_demuxer(mpctx->demuxer);
|
||||
mpctx->demuxer = NULL;
|
||||
|
||||
if (list) {
|
||||
entry = play_tree_new();
|
||||
play_tree_set_child(entry, list);
|
||||
mpctx->stop_play = playtree_add_playlist(mpctx, entry);
|
||||
if (entries_added) {
|
||||
mpctx->stop_play = PT_NEXT_ENTRY;
|
||||
goto goto_next_file;
|
||||
}
|
||||
}
|
||||
@ -4356,6 +4275,9 @@ goto_next_file: // don't jump here after ao/vo/getch initialization!
|
||||
|
||||
mp_msg(MSGT_CPLAYER, MSGL_INFO, "\n");
|
||||
|
||||
// xxx handle this as INITIALIZED_CONFIG?
|
||||
m_config_leave_file_local(mpctx->mconfig);
|
||||
|
||||
// time to uninit all, except global stuff:
|
||||
int uninitialize_parts = INITIALIZED_ALL;
|
||||
if (opts->fixed_vo)
|
||||
@ -4364,6 +4286,8 @@ goto_next_file: // don't jump here after ao/vo/getch initialization!
|
||||
uninitialize_parts -= INITIALIZED_AO;
|
||||
uninit_player(mpctx, uninitialize_parts);
|
||||
|
||||
mpctx->filename = NULL;
|
||||
|
||||
if (mpctx->set_of_sub_size > 0) {
|
||||
for (i = 0; i < mpctx->set_of_sub_size; ++i) {
|
||||
sub_free(mpctx->set_of_subtitles[i]);
|
||||
@ -4382,55 +4306,25 @@ goto_next_file: // don't jump here after ao/vo/getch initialization!
|
||||
ass_clear_fonts(mpctx->ass_library);
|
||||
#endif
|
||||
|
||||
if (!mpctx->stop_play) // In case some goto jumped here...
|
||||
if (!mpctx->stop_play || mpctx->stop_play == AT_END_OF_FILE)
|
||||
mpctx->stop_play = PT_NEXT_ENTRY;
|
||||
|
||||
int playtree_direction = 1;
|
||||
struct playlist_entry *new_entry = NULL;
|
||||
|
||||
if (mpctx->stop_play == PT_NEXT_ENTRY
|
||||
|| mpctx->stop_play == PT_PREV_ENTRY) {
|
||||
if (play_tree_iter_step(mpctx->playtree_iter, mpctx->play_tree_step, 0)
|
||||
!= PLAY_TREE_ITER_ENTRY) {
|
||||
play_tree_iter_free(mpctx->playtree_iter);
|
||||
mpctx->playtree_iter = NULL;
|
||||
}
|
||||
mpctx->play_tree_step = 1;
|
||||
} else if (mpctx->stop_play == PT_UP_NEXT ||
|
||||
mpctx->stop_play == PT_UP_PREV) {
|
||||
int direction = mpctx->stop_play == PT_UP_NEXT ? 1 : -1;
|
||||
if (mpctx->playtree_iter) {
|
||||
if (play_tree_iter_up_step(mpctx->playtree_iter, direction, 0) !=
|
||||
PLAY_TREE_ITER_ENTRY) {
|
||||
play_tree_iter_free(mpctx->playtree_iter);
|
||||
mpctx->playtree_iter = NULL;
|
||||
}
|
||||
}
|
||||
} else if (mpctx->stop_play == PT_STOP) {
|
||||
play_tree_iter_free(mpctx->playtree_iter);
|
||||
mpctx->playtree_iter = NULL;
|
||||
} else // NEXT PREV SRC
|
||||
playtree_direction = mpctx->stop_play == PT_PREV_SRC ? -1 : 1;
|
||||
|
||||
while (mpctx->playtree_iter != NULL) {
|
||||
mpctx->filename = play_tree_iter_get_file(mpctx->playtree_iter,
|
||||
playtree_direction);
|
||||
if (mpctx->filename == NULL) {
|
||||
if (play_tree_iter_step(mpctx->playtree_iter, playtree_direction,
|
||||
0) != PLAY_TREE_ITER_ENTRY) {
|
||||
play_tree_iter_free(mpctx->playtree_iter);
|
||||
mpctx->playtree_iter = NULL;
|
||||
}
|
||||
;
|
||||
} else
|
||||
break;
|
||||
if (mpctx->stop_play == PT_NEXT_ENTRY) {
|
||||
new_entry = playlist_get_next(mpctx->playlist, +1);
|
||||
} else if (mpctx->stop_play == PT_CURRENT_ENTRY) {
|
||||
new_entry = mpctx->playlist->current;
|
||||
} else { // PT_STOP
|
||||
playlist_clear(mpctx->playlist);
|
||||
}
|
||||
|
||||
if (mpctx->playtree_iter != NULL || opts->player_idle_mode) {
|
||||
if (!mpctx->playtree_iter)
|
||||
mpctx->filename = NULL;
|
||||
mpctx->stop_play = 0;
|
||||
mpctx->playlist->current = new_entry;
|
||||
mpctx->playlist->current_was_replaced = false;
|
||||
mpctx->stop_play = 0;
|
||||
|
||||
if (mpctx->playlist->current || opts->player_idle_mode)
|
||||
goto play_next_file;
|
||||
}
|
||||
|
||||
exit_player_with_rc(mpctx, EXIT_EOF, 0);
|
||||
|
||||
|
@ -19,9 +19,11 @@
|
||||
#ifndef MPLAYER_MACOSX_FINDER_ARGS_H
|
||||
#define MPLAYER_MACOSX_FINDER_ARGS_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "m_config.h"
|
||||
#include "playtree.h"
|
||||
|
||||
play_tree_t *macosx_finder_args(m_config_t *config, int argc, char **argv);
|
||||
struct playlist;
|
||||
bool *macosx_finder_args(m_config_t *config, struct playlist *files,
|
||||
int argc, char **argv);
|
||||
|
||||
#endif /* MPLAYER_MACOSX_FINDER_ARGS_H */
|
||||
|
@ -19,9 +19,11 @@
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <ApplicationServices/ApplicationServices.h>
|
||||
#include <stdio.h>
|
||||
#include "talloc.h"
|
||||
#include "playlist.h"
|
||||
#include "macosx_finder_args.h"
|
||||
|
||||
static play_tree_t *files = NULL;
|
||||
static struct playlist *files = NULL;
|
||||
|
||||
void macosx_wait_fileopen_events(void);
|
||||
void macosx_redirect_output_to_logfile(const char *filename);
|
||||
@ -34,19 +36,9 @@ bool psn_matches_current_process(char *psn_arg_to_check);
|
||||
@implementation FileOpenDelegate
|
||||
- (void)application:(NSApplication *)sender openFiles:(NSArray *)filenames
|
||||
{
|
||||
files = play_tree_new();
|
||||
play_tree_t *last_entry = nil;
|
||||
for (NSString *filename in filenames) {
|
||||
play_tree_t *entry = play_tree_new();
|
||||
play_tree_add_file(entry, [filename UTF8String]);
|
||||
|
||||
if (last_entry)
|
||||
play_tree_append_entry(files, entry);
|
||||
else
|
||||
play_tree_set_child(files, entry);
|
||||
|
||||
last_entry = entry;
|
||||
}
|
||||
files = talloc_zero(NULL, struct playlist);
|
||||
for (NSString *filename in filenames)
|
||||
playlist_add_file(files, [filename UTF8String]);
|
||||
[NSApp stop:nil]; // stop the runloop (give back control to mplayer2 code)
|
||||
}
|
||||
@end
|
||||
@ -83,7 +75,8 @@ bool psn_matches_current_process(char *psn_arg_to_check)
|
||||
return strcmp(psn_arg, psn_arg_to_check) == 0;
|
||||
}
|
||||
|
||||
play_tree_t *macosx_finder_args(m_config_t *config, int argc, char **argv)
|
||||
bool *macosx_finder_args(m_config_t *config, struct playlist *pl_files,
|
||||
int argc, char **argv)
|
||||
{
|
||||
if (argc==2 && psn_matches_current_process(argv[1])) {
|
||||
macosx_redirect_output_to_logfile("mplayer2");
|
||||
@ -91,5 +84,12 @@ play_tree_t *macosx_finder_args(m_config_t *config, int argc, char **argv)
|
||||
macosx_wait_fileopen_events();
|
||||
}
|
||||
|
||||
return files;
|
||||
if (files) {
|
||||
playlist_transfer_entries(pl_files, files);
|
||||
talloc_free(files);
|
||||
files = NULL;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
198
parser-mpcmd.c
198
parser-mpcmd.c
@ -28,7 +28,8 @@
|
||||
#include "mp_msg.h"
|
||||
#include "m_option.h"
|
||||
#include "m_config.h"
|
||||
#include "playtree.h"
|
||||
#include "playlist.h"
|
||||
#include "playlist_parser.h"
|
||||
#include "parser-mpcmd.h"
|
||||
#include "osdep/macosx_finder_args.h"
|
||||
|
||||
@ -38,16 +39,6 @@
|
||||
#define dvd_range(a) (a > 0 && a < 256)
|
||||
|
||||
|
||||
static inline void add_entry(play_tree_t **last_parentp,
|
||||
play_tree_t **last_entryp, play_tree_t *entry)
|
||||
{
|
||||
if (*last_entryp == NULL)
|
||||
play_tree_set_child(*last_parentp, entry);
|
||||
else
|
||||
play_tree_append_entry(*last_entryp, entry);
|
||||
*last_entryp = entry;
|
||||
}
|
||||
|
||||
static bool split_opt(struct bstr *opt, struct bstr *param, bool *old_syntax)
|
||||
{
|
||||
if (!bstr_startswith0(*opt, "-") || opt->len == 1)
|
||||
@ -92,15 +83,18 @@ static int map_to_option(struct m_config *config, bool old_syntax,
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Parse command line to set up config and playtree
|
||||
play_tree_t *m_config_parse_mp_command_line(m_config_t *config, int argc,
|
||||
char **argv)
|
||||
bool m_config_parse_mp_command_line(m_config_t *config, struct playlist *files,
|
||||
int argc, char **argv)
|
||||
{
|
||||
int mode = 0;
|
||||
bool no_more_opts = false;
|
||||
bool opt_exit = false; // exit immediately after parsing (help options)
|
||||
play_tree_t *last_parent, *last_entry = NULL, *root;
|
||||
struct playlist_entry *local_start = NULL;
|
||||
struct bstr orig_opt;
|
||||
bool shuffle = false;
|
||||
|
||||
int local_params_count = 0;
|
||||
struct playlist_param *local_params = 0;
|
||||
|
||||
assert(config != NULL);
|
||||
assert(argv != NULL);
|
||||
@ -109,13 +103,10 @@ play_tree_t *m_config_parse_mp_command_line(m_config_t *config, int argc,
|
||||
config->mode = M_COMMAND_LINE;
|
||||
mode = GLOBAL;
|
||||
#ifdef CONFIG_MACOSX_FINDER
|
||||
root = macosx_finder_args(config, argc, argv);
|
||||
if (root)
|
||||
return root;
|
||||
if (macosx_finder_args(config, files, argc, argv))
|
||||
return true;
|
||||
#endif
|
||||
|
||||
last_parent = root = play_tree_new();
|
||||
|
||||
for (int i = 1; i < argc; i++) {
|
||||
//next:
|
||||
struct bstr opt = bstr0(argv[i]);
|
||||
@ -125,103 +116,100 @@ play_tree_t *m_config_parse_mp_command_line(m_config_t *config, int argc,
|
||||
no_more_opts = true;
|
||||
continue;
|
||||
}
|
||||
if (!bstrcmp0(opt, "{")) {
|
||||
play_tree_t *entry = play_tree_new();
|
||||
mode = LOCAL;
|
||||
if (last_parent->flags & PLAY_TREE_RND)
|
||||
entry->flags |= PLAY_TREE_RND;
|
||||
if (last_entry == NULL)
|
||||
play_tree_set_child(last_parent, entry);
|
||||
else {
|
||||
play_tree_append_entry(last_entry, entry);
|
||||
last_entry = NULL;
|
||||
if (!bstrcmp0(opt, "--{")) {
|
||||
if (mode != GLOBAL) {
|
||||
mp_msg(MSGT_CFGPARSER, MSGL_ERR, "'--{' can not be nested\n");
|
||||
goto err_out;
|
||||
}
|
||||
last_parent = entry;
|
||||
mode = LOCAL;
|
||||
assert(!local_start);
|
||||
local_start = files->last;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!bstrcmp0(opt, "}")) {
|
||||
if (!last_parent || !last_parent->parent) {
|
||||
mp_msg(MSGT_CFGPARSER, MSGL_ERR, "too much }-\n");
|
||||
if (!bstrcmp0(opt, "--}")) {
|
||||
if (mode != LOCAL) {
|
||||
mp_msg(MSGT_CFGPARSER, MSGL_ERR, "too many closing '--}'\n");
|
||||
goto err_out;
|
||||
}
|
||||
last_entry = last_parent;
|
||||
last_parent = last_entry->parent;
|
||||
if (local_params_count) {
|
||||
// The files added between '{' and '}' are the entries from the
|
||||
// entry _after_ local_start, until the end of the list. If
|
||||
// local_start is NULL, the list was empty on '{', and we want
|
||||
// all files in the list.
|
||||
struct playlist_entry *cur
|
||||
= local_start ? local_start->next : files->first;
|
||||
if (!cur)
|
||||
mp_msg(MSGT_CFGPARSER, MSGL_WARN, "ignored options\n");
|
||||
while (cur) {
|
||||
playlist_entry_add_params(cur, local_params,
|
||||
local_params_count);
|
||||
cur = cur->next;
|
||||
}
|
||||
}
|
||||
local_params_count = 0;
|
||||
mode = GLOBAL;
|
||||
local_start = NULL;
|
||||
continue;
|
||||
}
|
||||
|
||||
struct bstr param = bstr0(i+1 < argc ? argv[i+1] : NULL);
|
||||
bool old_syntax;
|
||||
if (!no_more_opts && split_opt(&opt, ¶m, &old_syntax)) {
|
||||
const struct m_option *mp_opt;
|
||||
int ok = map_to_option(config, old_syntax, &mp_opt, &opt, ¶m);
|
||||
if (ok < 0) {
|
||||
if (ok == -3)
|
||||
mp_tmsg(MSGT_CFGPARSER, MSGL_ERR,
|
||||
"Option --%.*s can't be used with single-dash "
|
||||
"syntax\n", BSTR_P(opt));
|
||||
else if (ok == -2)
|
||||
mp_tmsg(MSGT_CFGPARSER, MSGL_ERR,
|
||||
"A --no-* option can't take parameters: "
|
||||
"--%.*s=%.*s\n", BSTR_P(opt), BSTR_P(param));
|
||||
else
|
||||
mp_tmsg(MSGT_CFGPARSER, MSGL_ERR,
|
||||
"Unknown option on the command line: --%.*s\n",
|
||||
BSTR_P(opt));
|
||||
goto print_err;
|
||||
}
|
||||
if (mode == LOCAL && (mp_opt->flags & M_OPT_GLOBAL)) {
|
||||
mp_tmsg(MSGT_CFGPARSER, MSGL_ERR,
|
||||
"Option --%.*s is global and can't be set per-file\n",
|
||||
BSTR_P(opt));
|
||||
goto print_err;
|
||||
}
|
||||
// Handle some special arguments outside option parser.
|
||||
// --loop when it applies to a group of files (per-file is option)
|
||||
if (bstrcasecmp0(opt, "loop") == 0 &&
|
||||
(!last_entry || last_entry->child)) {
|
||||
struct bstr rest;
|
||||
int l = bstrtoll(param, &rest, 0);
|
||||
if (!param.len || rest.len) {
|
||||
mp_tmsg(MSGT_CFGPARSER, MSGL_ERR,
|
||||
"The loop option must be an integer: \"%.*s\"\n",
|
||||
BSTR_P(param));
|
||||
goto print_err;
|
||||
} else {
|
||||
play_tree_t *pt = last_entry ? last_entry : last_parent;
|
||||
l = l <= 0 ? -1 : l;
|
||||
pt->loop = l;
|
||||
i += old_syntax;
|
||||
}
|
||||
} else if (bstrcasecmp0(opt, "shuffle") == 0) {
|
||||
if (last_entry && last_entry->child)
|
||||
last_entry->flags |= PLAY_TREE_RND;
|
||||
else
|
||||
last_parent->flags |= PLAY_TREE_RND;
|
||||
} else if (bstrcasecmp0(opt, "noshuffle") == 0 ||
|
||||
bstrcasecmp0(opt, "no-shuffle") == 0) {
|
||||
if (last_entry && last_entry->child)
|
||||
last_entry->flags &= ~PLAY_TREE_RND;
|
||||
else
|
||||
last_parent->flags &= ~PLAY_TREE_RND;
|
||||
if (bstrcasecmp0(opt, "shuffle") == 0) {
|
||||
shuffle = true;
|
||||
} else if (bstrcasecmp0(opt, "no-shuffle") == 0) {
|
||||
shuffle = false;
|
||||
} else if (bstrcasecmp0(opt, "playlist") == 0) {
|
||||
if (param.len <= 0)
|
||||
goto print_err;
|
||||
struct play_tree *entry = parse_playlist_file(config, param);
|
||||
if (!entry)
|
||||
// append the playlist to the local args
|
||||
char *param0 = bstrdup0(NULL, param);
|
||||
struct playlist *pl = playlist_parse_file(param0);
|
||||
talloc_free(param0);
|
||||
if (!pl)
|
||||
goto print_err;
|
||||
add_entry(&last_parent, &last_entry, entry);
|
||||
if ((last_parent->flags & PLAY_TREE_RND) && entry->child)
|
||||
entry->flags |= PLAY_TREE_RND;
|
||||
mode = LOCAL;
|
||||
playlist_transfer_entries(files, pl);
|
||||
talloc_free(pl);
|
||||
i += old_syntax;
|
||||
} else {
|
||||
// "normal" options
|
||||
const struct m_option *mp_opt;
|
||||
int ok = map_to_option(config, old_syntax, &mp_opt, &opt,
|
||||
¶m);
|
||||
if (ok < 0) {
|
||||
if (ok == -3)
|
||||
mp_tmsg(MSGT_CFGPARSER, MSGL_ERR,
|
||||
"Option --%.*s can't be used with single-dash "
|
||||
"syntax\n", BSTR_P(opt));
|
||||
else if (ok == -2)
|
||||
mp_tmsg(MSGT_CFGPARSER, MSGL_ERR,
|
||||
"A --no-* option can't take parameters: "
|
||||
"--%.*s=%.*s\n", BSTR_P(opt), BSTR_P(param));
|
||||
else
|
||||
mp_tmsg(MSGT_CFGPARSER, MSGL_ERR,
|
||||
"Unknown option on the command line: --%.*s\n",
|
||||
BSTR_P(opt));
|
||||
goto print_err;
|
||||
}
|
||||
int r;
|
||||
if (mode == GLOBAL || (mp_opt->flags & M_OPT_GLOBAL)) {
|
||||
if (mode == GLOBAL) {
|
||||
r = m_config_set_option(config, opt, param, old_syntax);
|
||||
} else {
|
||||
r = m_config_check_option(config, opt, param, old_syntax);
|
||||
if (r >= 0) {
|
||||
play_tree_t *pt = last_entry ? last_entry : last_parent;
|
||||
if (r == 0)
|
||||
param = bstr0(NULL); // for old_syntax case
|
||||
play_tree_set_param(pt, opt, param);
|
||||
struct playlist_param p = {opt, param};
|
||||
MP_TARRAY_APPEND(NULL, local_params,
|
||||
local_params_count, p);
|
||||
}
|
||||
}
|
||||
if (r <= M_OPT_EXIT) {
|
||||
@ -241,7 +229,6 @@ play_tree_t *m_config_parse_mp_command_line(m_config_t *config, int argc,
|
||||
}
|
||||
} else { /* filename */
|
||||
int is_dvdnav = strstr(argv[i], "dvdnav://") != NULL;
|
||||
play_tree_t *entry = play_tree_new();
|
||||
mp_msg(MSGT_CFGPARSER, MSGL_DBG2, "Adding file %s\n", argv[i]);
|
||||
// expand DVD filename entries like dvd://1-3 into component titles
|
||||
if (strstr(argv[i], "dvd://") != NULL || is_dvdnav) {
|
||||
@ -260,45 +247,48 @@ play_tree_t *m_config_parse_mp_command_line(m_config_t *config, int argc,
|
||||
if (dvd_range(start_title) && dvd_range(end_title)
|
||||
&& (start_title < end_title)) {
|
||||
for (int j = start_title; j <= end_title; j++) {
|
||||
if (j != start_title)
|
||||
entry = play_tree_new();
|
||||
char entbuf[15];
|
||||
snprintf(entbuf, sizeof(entbuf),
|
||||
is_dvdnav ? "dvdnav://%d" : "dvd://%d", j);
|
||||
play_tree_add_file(entry, entbuf);
|
||||
add_entry(&last_parent, &last_entry, entry);
|
||||
last_entry = entry;
|
||||
playlist_add_file(files, entbuf);
|
||||
}
|
||||
} else
|
||||
mp_tmsg(MSGT_CFGPARSER, MSGL_ERR,
|
||||
"Invalid play entry %s\n", argv[i]);
|
||||
|
||||
} else // dvd:// or dvd://x entry
|
||||
play_tree_add_file(entry, argv[i]);
|
||||
playlist_add_file(files, argv[i]);
|
||||
} else
|
||||
play_tree_add_file(entry, argv[i]);
|
||||
playlist_add_file(files, argv[i]);
|
||||
|
||||
// Lock stdin if it will be used as input
|
||||
if (strcasecmp(argv[i], "-") == 0)
|
||||
m_config_set_option0(config, "consolecontrols", "no", false);
|
||||
add_entry(&last_parent, &last_entry, entry);
|
||||
mode = LOCAL; // We start entry specific options
|
||||
}
|
||||
}
|
||||
|
||||
if (opt_exit)
|
||||
goto err_out;
|
||||
if (last_parent != root)
|
||||
mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Missing }- ?\n");
|
||||
return root;
|
||||
|
||||
if (mode != GLOBAL) {
|
||||
mp_tmsg(MSGT_CFGPARSER, MSGL_ERR,
|
||||
"Missing closing --} on command line.\n");
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
if (shuffle)
|
||||
playlist_shuffle(files);
|
||||
|
||||
talloc_free(local_params);
|
||||
return true;
|
||||
|
||||
print_err:
|
||||
mp_tmsg(MSGT_CFGPARSER, MSGL_FATAL,
|
||||
"Error parsing option on the command line: %.*s\n",
|
||||
BSTR_P(orig_opt));
|
||||
err_out:
|
||||
play_tree_free(root, 1);
|
||||
return NULL;
|
||||
talloc_free(local_params);
|
||||
return false;
|
||||
}
|
||||
|
||||
extern int mp_msg_levels[];
|
||||
|
@ -19,11 +19,11 @@
|
||||
#ifndef MPLAYER_PARSER_MPCMD_H
|
||||
#define MPLAYER_PARSER_MPCMD_H
|
||||
|
||||
#include "playtree.h"
|
||||
#include <stdbool.h>
|
||||
#include "m_config.h"
|
||||
|
||||
play_tree_t *m_config_parse_mp_command_line(m_config_t *config, int argc,
|
||||
char **argv);
|
||||
bool m_config_parse_mp_command_line(m_config_t *config, struct playlist *files,
|
||||
int argc, char **argv);
|
||||
int m_config_preparse_command_line(m_config_t *config, int argc, char **argv,
|
||||
int *verbose);
|
||||
|
||||
|
185
playlist.c
Normal file
185
playlist.c
Normal file
@ -0,0 +1,185 @@
|
||||
/*
|
||||
* This file is part of mplayer.
|
||||
*
|
||||
* mplayer is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* mplayer is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with mplayer. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include "config.h"
|
||||
#include "playlist.h"
|
||||
#include "mpcommon.h"
|
||||
#include "talloc.h"
|
||||
#include "path.h"
|
||||
|
||||
struct playlist_entry *playlist_entry_new(const char *filename)
|
||||
{
|
||||
struct playlist_entry *e = talloc_zero(NULL, struct playlist_entry);
|
||||
e->filename = talloc_strdup(e, filename);
|
||||
return e;
|
||||
}
|
||||
|
||||
void playlist_entry_add_param(struct playlist_entry *e, bstr name, bstr value)
|
||||
{
|
||||
struct playlist_param p = {bstrdup(e, name), bstrdup(e, value)};
|
||||
MP_TARRAY_APPEND(e, e->params, e->params_count, p);
|
||||
}
|
||||
|
||||
void playlist_entry_add_params(struct playlist_entry *e,
|
||||
struct playlist_param *params,
|
||||
int params_count)
|
||||
{
|
||||
for (int n = 0; n < params_count; n++)
|
||||
playlist_entry_add_param(e, params[n].name, params[n].value);
|
||||
}
|
||||
|
||||
// Add entry "add" after entry "after".
|
||||
// If "after" is NULL, add as first entry.
|
||||
// Post condition: add->prev == after
|
||||
void playlist_insert(struct playlist *pl, struct playlist_entry *after,
|
||||
struct playlist_entry *add)
|
||||
{
|
||||
assert(pl && add->pl == NULL && add->next == NULL && add->prev == NULL);
|
||||
if (after) {
|
||||
assert(after->pl == pl);
|
||||
assert(pl->first && pl->last);
|
||||
}
|
||||
add->prev = after;
|
||||
if (after) {
|
||||
add->next = after->next;
|
||||
after->next = add;
|
||||
} else {
|
||||
add->next = pl->first;
|
||||
pl->first = add;
|
||||
}
|
||||
if (add->next) {
|
||||
add->next->prev = add;
|
||||
} else {
|
||||
pl->last = add;
|
||||
}
|
||||
add->pl = pl;
|
||||
talloc_steal(pl, add);
|
||||
}
|
||||
|
||||
void playlist_add(struct playlist *pl, struct playlist_entry *add)
|
||||
{
|
||||
playlist_insert(pl, pl->last, add);
|
||||
}
|
||||
|
||||
static void playlist_unlink(struct playlist *pl, struct playlist_entry *entry)
|
||||
{
|
||||
assert(pl && entry->pl == pl);
|
||||
|
||||
if (pl->current == entry) {
|
||||
pl->current = entry->next;
|
||||
pl->current_was_replaced = true;
|
||||
}
|
||||
|
||||
if (entry->next) {
|
||||
entry->next->prev = entry->prev;
|
||||
} else {
|
||||
pl->last = entry->prev;
|
||||
}
|
||||
if (entry->prev) {
|
||||
entry->prev->next = entry->next;
|
||||
} else {
|
||||
pl->first = entry->next;
|
||||
}
|
||||
entry->next = entry->prev = NULL;
|
||||
// xxx: we'd want to reset the talloc parent of entry
|
||||
entry->pl = NULL;
|
||||
}
|
||||
|
||||
void playlist_remove(struct playlist *pl, struct playlist_entry *entry)
|
||||
{
|
||||
playlist_unlink(pl, entry);
|
||||
talloc_free(entry);
|
||||
}
|
||||
|
||||
void playlist_clear(struct playlist *pl)
|
||||
{
|
||||
while (pl->first)
|
||||
playlist_remove(pl, pl->first);
|
||||
assert(!pl->current);
|
||||
pl->current_was_replaced = false;
|
||||
}
|
||||
|
||||
void playlist_add_file(struct playlist *pl, const char *filename)
|
||||
{
|
||||
playlist_add(pl, playlist_entry_new(filename));
|
||||
}
|
||||
|
||||
static int playlist_count(struct playlist *pl)
|
||||
{
|
||||
int c = 0;
|
||||
for (struct playlist_entry *e = pl->first; e; e = e->next)
|
||||
c++;
|
||||
return c;
|
||||
}
|
||||
|
||||
void playlist_shuffle(struct playlist *pl)
|
||||
{
|
||||
struct playlist_entry *save_current = pl->current;
|
||||
bool save_replaced = pl->current_was_replaced;
|
||||
int count = playlist_count(pl);
|
||||
struct playlist_entry **arr = talloc_array(NULL, struct playlist_entry *,
|
||||
count);
|
||||
for (int n = 0; n < count; n++) {
|
||||
arr[n] = pl->first;
|
||||
playlist_unlink(pl, pl->first);
|
||||
}
|
||||
for (int n = 0; n < count; n++) {
|
||||
int other = (int)((double)(count) * rand() / (RAND_MAX + 1.0));
|
||||
struct playlist_entry *tmp = arr[n];
|
||||
arr[n] = arr[other];
|
||||
arr[other] = tmp;
|
||||
}
|
||||
for (int n = 0; n < count; n++)
|
||||
playlist_add(pl, arr[n]);
|
||||
talloc_free(arr);
|
||||
pl->current = save_current;
|
||||
pl->current_was_replaced = save_replaced;
|
||||
}
|
||||
|
||||
struct playlist_entry *playlist_get_next(struct playlist *pl, int direction)
|
||||
{
|
||||
assert(direction == -1 || direction == +1);
|
||||
if (!pl->current)
|
||||
return NULL;
|
||||
assert(pl->current->pl == pl);
|
||||
if (direction < 0)
|
||||
return pl->current->prev;
|
||||
return pl->current_was_replaced ? pl->current : pl->current->next;
|
||||
}
|
||||
|
||||
void playlist_add_base_path(struct playlist *pl, bstr base_path)
|
||||
{
|
||||
if (base_path.len == 0 || bstrcmp0(base_path, ".") == 0)
|
||||
return;
|
||||
for (struct playlist_entry *e = pl->first; e; e = e->next) {
|
||||
char *new_file = mp_path_join(e, base_path, bstr0(e->filename));
|
||||
talloc_free(e->filename);
|
||||
e->filename = new_file;
|
||||
}
|
||||
}
|
||||
|
||||
// Move all entries from source_pl to pl, appending them at the end of pl.
|
||||
// source_pl will be empty, and all entries have changed ownership to pl.
|
||||
void playlist_transfer_entries(struct playlist *pl, struct playlist *source_pl)
|
||||
{
|
||||
while (source_pl->first) {
|
||||
struct playlist_entry *e = source_pl->first;
|
||||
playlist_unlink(source_pl, e);
|
||||
playlist_add(pl, e);
|
||||
}
|
||||
}
|
67
playlist.h
Normal file
67
playlist.h
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* This file is part of mplayer.
|
||||
*
|
||||
* mplayer is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* mplayer is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with mplayer. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef MPLAYER_PLAYLIST_H
|
||||
#define MPLAYER_PLAYLIST_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "bstr.h"
|
||||
|
||||
struct playlist_param {
|
||||
bstr name, value;
|
||||
};
|
||||
|
||||
struct playlist_entry {
|
||||
struct playlist_entry *prev, *next;
|
||||
struct playlist *pl;
|
||||
|
||||
char *filename;
|
||||
|
||||
struct playlist_param *params;
|
||||
int params_count;
|
||||
};
|
||||
|
||||
struct playlist {
|
||||
struct playlist_entry *first, *last;
|
||||
|
||||
// This provides some sort of stable iterator. If this entry is removed from
|
||||
// the playlist, current is set to the next element (or NULL), and
|
||||
// current_was_replaced is set to true.
|
||||
struct playlist_entry *current;
|
||||
bool current_was_replaced;
|
||||
};
|
||||
|
||||
void playlist_entry_add_param(struct playlist_entry *e, bstr name, bstr value);
|
||||
void playlist_entry_add_params(struct playlist_entry *e,
|
||||
struct playlist_param *params,
|
||||
int params_count);
|
||||
|
||||
struct playlist_entry *playlist_entry_new(const char *filename);
|
||||
|
||||
void playlist_insert(struct playlist *pl, struct playlist_entry *after,
|
||||
struct playlist_entry *add);
|
||||
void playlist_add(struct playlist *pl, struct playlist_entry *add);
|
||||
void playlist_remove(struct playlist *pl, struct playlist_entry *entry);
|
||||
void playlist_clear(struct playlist *pl);
|
||||
|
||||
void playlist_add_file(struct playlist *pl, const char *filename);
|
||||
void playlist_shuffle(struct playlist *pl);
|
||||
struct playlist_entry *playlist_get_next(struct playlist *pl, int direction);
|
||||
void playlist_add_base_path(struct playlist *pl, bstr base_path);
|
||||
void playlist_transfer_entries(struct playlist *pl, struct playlist *source_pl);
|
||||
|
||||
#endif
|
@ -16,9 +16,6 @@
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
/// \file
|
||||
/// \ingroup PlaytreeParser
|
||||
|
||||
#include "config.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
@ -35,17 +32,26 @@
|
||||
#include "talloc.h"
|
||||
#include "asxparser.h"
|
||||
#include "m_config.h"
|
||||
#include "playtree.h"
|
||||
#include "playtreeparser.h"
|
||||
#include "playlist.h"
|
||||
#include "playlist_parser.h"
|
||||
#include "stream/stream.h"
|
||||
#include "libmpdemux/demuxer.h"
|
||||
#include "mp_msg.h"
|
||||
#include "path.h"
|
||||
|
||||
|
||||
#define BUF_STEP 1024
|
||||
|
||||
#define WHITES " \n\r\t"
|
||||
|
||||
typedef struct play_tree_parser {
|
||||
struct stream *stream;
|
||||
char *buffer,*iter,*line;
|
||||
int buffer_size , buffer_end;
|
||||
int keep;
|
||||
struct playlist *pl;
|
||||
} play_tree_parser_t;
|
||||
|
||||
static void
|
||||
strstrip(char* str) {
|
||||
char* i;
|
||||
@ -164,8 +170,7 @@ play_tree_parser_stop_keeping(play_tree_parser_t* p) {
|
||||
}
|
||||
|
||||
|
||||
static play_tree_t*
|
||||
parse_asx(play_tree_parser_t* p) {
|
||||
static bool parse_asx(play_tree_parser_t* p) {
|
||||
int comments = 0,get_line = 1;
|
||||
char* line = NULL;
|
||||
|
||||
@ -175,7 +180,7 @@ parse_asx(play_tree_parser_t* p) {
|
||||
if(get_line) {
|
||||
line = play_tree_parser_get_line(p);
|
||||
if(!line)
|
||||
return NULL;
|
||||
return false;
|
||||
strstrip(line);
|
||||
if(line[0] == '\0')
|
||||
continue;
|
||||
@ -184,7 +189,7 @@ parse_asx(play_tree_parser_t* p) {
|
||||
if(line[0] != '<') {
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"First char isn't '<' but '%c'\n",line[0]);
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_DBG3,"Buffer = [%s]\n",p->buffer);
|
||||
return NULL;
|
||||
return false;
|
||||
} else if(strncmp(line,"<!--",4) == 0) { // Comments
|
||||
comments = 1;
|
||||
line += 4;
|
||||
@ -193,7 +198,7 @@ parse_asx(play_tree_parser_t* p) {
|
||||
} else if(strncasecmp(line,"<ASX",4) == 0) // We got an asx element
|
||||
break;
|
||||
else // We don't get an asx
|
||||
return NULL;
|
||||
return false;
|
||||
} else { // Comments
|
||||
char* c;
|
||||
c = strchr(line,'-');
|
||||
@ -224,7 +229,7 @@ parse_asx(play_tree_parser_t* p) {
|
||||
/* NOTHING */;
|
||||
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_DBG3,"Parsing asx file: [%s]\n",p->buffer);
|
||||
return asx_parser_build_tree(p->mconfig, p->buffer,p->deep);
|
||||
return asx_parse(p->buffer,p->pl);
|
||||
}
|
||||
|
||||
static char*
|
||||
@ -281,12 +286,10 @@ pls_read_entry(char* line,pls_entry_t** _e,int* _max_entry,char** val) {
|
||||
}
|
||||
|
||||
|
||||
static play_tree_t*
|
||||
parse_pls(play_tree_parser_t* p) {
|
||||
static bool parse_pls(play_tree_parser_t* p) {
|
||||
char *line,*v;
|
||||
pls_entry_t* entries = NULL;
|
||||
int n_entries = 0,max_entry=0,num;
|
||||
play_tree_t *list = NULL, *entry = NULL, *last_entry = NULL;
|
||||
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_V,"Trying Winamp playlist...\n");
|
||||
while((line = play_tree_parser_get_line(p))) {
|
||||
@ -295,14 +298,14 @@ parse_pls(play_tree_parser_t* p) {
|
||||
break;
|
||||
}
|
||||
if (!line)
|
||||
return NULL;
|
||||
return false;
|
||||
if(strcasecmp(line,"[playlist]"))
|
||||
return NULL;
|
||||
return false;
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_V,"Detected Winamp playlist format\n");
|
||||
play_tree_parser_stop_keeping(p);
|
||||
line = play_tree_parser_get_line(p);
|
||||
if(!line)
|
||||
return NULL;
|
||||
return false;
|
||||
strstrip(line);
|
||||
if(strncasecmp(line,"NumberOfEntries",15) == 0) {
|
||||
v = pls_entry_get_value(line);
|
||||
@ -354,16 +357,10 @@ parse_pls(play_tree_parser_t* p) {
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Entry %d don't have a file !!!!\n",num+1);
|
||||
else {
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Adding entry %s\n",entries[num].file);
|
||||
entry = play_tree_new();
|
||||
play_tree_add_file(entry,entries[num].file);
|
||||
playlist_add_file(p->pl,entries[num].file);
|
||||
if (entries[num].length)
|
||||
play_tree_set_param(entry, bstr0("endpos"), bstr0(entries[num].length));
|
||||
playlist_entry_add_param(p->pl->last, bstr0("endpos"), bstr0(entries[num].length));
|
||||
free(entries[num].file);
|
||||
if(list)
|
||||
play_tree_append_entry(last_entry,entry);
|
||||
else
|
||||
list = entry;
|
||||
last_entry = entry;
|
||||
}
|
||||
// When we have info in playtree we add these info
|
||||
free(entries[num].title);
|
||||
@ -371,22 +368,14 @@ parse_pls(play_tree_parser_t* p) {
|
||||
}
|
||||
|
||||
free(entries);
|
||||
|
||||
if (!list)
|
||||
return NULL;
|
||||
|
||||
entry = play_tree_new();
|
||||
play_tree_set_child(entry,list);
|
||||
return entry;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
Reference Ini-Format: Each entry is assumed a reference
|
||||
*/
|
||||
static play_tree_t*
|
||||
parse_ref_ini(play_tree_parser_t* p) {
|
||||
static bool parse_ref_ini(play_tree_parser_t* p) {
|
||||
char *line,*v;
|
||||
play_tree_t *list = NULL, *entry = NULL, *last_entry = NULL;
|
||||
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_V,"Trying reference-ini playlist...\n");
|
||||
if (!(line = play_tree_parser_get_line(p)))
|
||||
@ -408,28 +397,17 @@ parse_ref_ini(play_tree_parser_t* p) {
|
||||
else
|
||||
{
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Adding entry %s\n",v);
|
||||
entry = play_tree_new();
|
||||
play_tree_add_file(entry,v);
|
||||
if(list)
|
||||
play_tree_append_entry(last_entry,entry);
|
||||
else
|
||||
list = entry;
|
||||
last_entry = entry;
|
||||
playlist_add_file(p->pl, v);
|
||||
}
|
||||
}
|
||||
line = play_tree_parser_get_line(p);
|
||||
}
|
||||
|
||||
if(!list) return NULL;
|
||||
entry = play_tree_new();
|
||||
play_tree_set_child(entry,list);
|
||||
return entry;
|
||||
return true;
|
||||
}
|
||||
|
||||
static play_tree_t*
|
||||
parse_m3u(play_tree_parser_t* p) {
|
||||
static bool parse_m3u(play_tree_parser_t* p) {
|
||||
char* line;
|
||||
play_tree_t *list = NULL, *entry = NULL, *last_entry = NULL;
|
||||
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_V,"Trying extended m3u playlist...\n");
|
||||
if (!(line = play_tree_parser_get_line(p)))
|
||||
@ -459,26 +437,15 @@ parse_m3u(play_tree_parser_t* p) {
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
entry = play_tree_new();
|
||||
play_tree_add_file(entry,line);
|
||||
if(!list)
|
||||
list = entry;
|
||||
else
|
||||
play_tree_append_entry(last_entry,entry);
|
||||
last_entry = entry;
|
||||
playlist_add_file(p->pl, line);
|
||||
}
|
||||
|
||||
if(!list) return NULL;
|
||||
entry = play_tree_new();
|
||||
play_tree_set_child(entry,list);
|
||||
return entry;
|
||||
return true;
|
||||
}
|
||||
|
||||
static play_tree_t*
|
||||
parse_smil(play_tree_parser_t* p) {
|
||||
static bool parse_smil(play_tree_parser_t* p) {
|
||||
int entrymode=0;
|
||||
char* line,source[512],*pos,*s_start,*s_end,*src_line;
|
||||
play_tree_t *list = NULL, *entry = NULL, *last_entry = NULL;
|
||||
int is_rmsmil = 0;
|
||||
unsigned int npkt, ttlpkt;
|
||||
|
||||
@ -591,13 +558,7 @@ parse_smil(play_tree_parser_t* p) {
|
||||
}
|
||||
strncpy(source,s_start,s_end-s_start);
|
||||
source[(s_end-s_start)]='\0'; // Null terminate
|
||||
entry = play_tree_new();
|
||||
play_tree_add_file(entry,source);
|
||||
if(!list) //Insert new entry
|
||||
list = entry;
|
||||
else
|
||||
play_tree_append_entry(last_entry,entry);
|
||||
last_entry = entry;
|
||||
playlist_add_file(p->pl, source);
|
||||
pos = s_end;
|
||||
}
|
||||
}
|
||||
@ -605,45 +566,11 @@ parse_smil(play_tree_parser_t* p) {
|
||||
} while((src_line = play_tree_parser_get_line(p)) != NULL);
|
||||
|
||||
free(line);
|
||||
|
||||
if(!list) return NULL; // Nothing found
|
||||
|
||||
entry = play_tree_new();
|
||||
play_tree_set_child(entry,list);
|
||||
return entry;
|
||||
return true;
|
||||
}
|
||||
|
||||
static play_tree_t*
|
||||
embedded_playlist_parse(struct m_config *mconfig, char *line) {
|
||||
int f=DEMUXER_TYPE_PLAYLIST;
|
||||
stream_t* stream;
|
||||
play_tree_parser_t* ptp;
|
||||
play_tree_t* entry;
|
||||
|
||||
// Get stream opened to link
|
||||
stream=open_stream(line,0,&f);
|
||||
if(!stream) {
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_WARN,"Can't open playlist %s\n",line);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//add new playtree
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_V,"Adding playlist %s to element entryref\n",line);
|
||||
|
||||
ptp = play_tree_parser_new(stream, mconfig, 1);
|
||||
entry = play_tree_parser_get_play_tree(ptp, 1);
|
||||
play_tree_parser_free(ptp);
|
||||
free_stream(stream);
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
static play_tree_t*
|
||||
parse_textplain(play_tree_parser_t* p) {
|
||||
static bool parse_textplain(play_tree_parser_t* p) {
|
||||
char* line;
|
||||
char *c;
|
||||
int embedded;
|
||||
play_tree_t *list = NULL, *entry = NULL, *last_entry = NULL;
|
||||
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_V,"Trying plaintext playlist...\n");
|
||||
play_tree_parser_stop_keeping(p);
|
||||
@ -653,41 +580,10 @@ parse_textplain(play_tree_parser_t* p) {
|
||||
if(line[0] == '\0' || line[0] == '#' || (line[0] == '/' && line[1] == '/'))
|
||||
continue;
|
||||
|
||||
//Special check for embedded smil or ram reference in file
|
||||
embedded = 0;
|
||||
if (strlen(line) > 5)
|
||||
for(c = line; c[0]; c++ )
|
||||
if ( ((c[0] == '.') && //start with . and next have smil with optional ? or &
|
||||
(tolower(c[1]) == 's') && (tolower(c[2])== 'm') &&
|
||||
(tolower(c[3]) == 'i') && (tolower(c[4]) == 'l') &&
|
||||
(!c[5] || c[5] == '?' || c[5] == '&')) || // or
|
||||
((c[0] == '.') && // start with . and next have smi or ram with optional ? or &
|
||||
( ((tolower(c[1]) == 's') && (tolower(c[2])== 'm') && (tolower(c[3]) == 'i')) ||
|
||||
((tolower(c[1]) == 'r') && (tolower(c[2])== 'a') && (tolower(c[3]) == 'm')) )
|
||||
&& (!c[4] || c[4] == '?' || c[4] == '&')) ){
|
||||
entry=embedded_playlist_parse(p->mconfig, line);
|
||||
embedded = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!embedded) { //regular file link
|
||||
entry = play_tree_new();
|
||||
play_tree_add_file(entry,line);
|
||||
}
|
||||
|
||||
if (entry != NULL) {
|
||||
if(!list)
|
||||
list = entry;
|
||||
else
|
||||
play_tree_append_entry(last_entry,entry);
|
||||
last_entry = entry;
|
||||
}
|
||||
playlist_add_file(p->pl,line);
|
||||
}
|
||||
|
||||
if(!list) return NULL;
|
||||
entry = play_tree_new();
|
||||
play_tree_set_child(entry,list);
|
||||
return entry;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -745,10 +641,9 @@ static void utf16_to_ascii(char *buf, int len) {
|
||||
buf[i] = 0; // just in case
|
||||
}
|
||||
|
||||
static play_tree_t *parse_nsc(play_tree_parser_t* p) {
|
||||
static bool parse_nsc(play_tree_parser_t* p) {
|
||||
char *line, *addr = NULL, *url, *unicast_url = NULL;
|
||||
int port = 0;
|
||||
play_tree_t *entry = NULL;
|
||||
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_V,"Trying nsc playlist...\n");
|
||||
while((line = play_tree_parser_get_line(p)) != NULL) {
|
||||
@ -758,7 +653,7 @@ static play_tree_t *parse_nsc(play_tree_parser_t* p) {
|
||||
if (strncasecmp(line,"[Address]", 9) == 0)
|
||||
break; // nsc header found
|
||||
else
|
||||
return NULL;
|
||||
return false;
|
||||
}
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_V,"Detected nsc playlist format\n");
|
||||
play_tree_parser_stop_keeping(p);
|
||||
@ -783,203 +678,103 @@ static play_tree_t *parse_nsc(play_tree_parser_t* p) {
|
||||
}
|
||||
}
|
||||
|
||||
bool success = false;
|
||||
|
||||
if (unicast_url)
|
||||
url = strdup(unicast_url);
|
||||
else if (addr && port) {
|
||||
url = malloc(strlen(addr) + 7 + 20 + 1);
|
||||
sprintf(url, "http://%s:%i", addr, port);
|
||||
} else
|
||||
goto out;
|
||||
goto err_out;
|
||||
|
||||
entry = play_tree_new();
|
||||
play_tree_add_file(entry, url);
|
||||
playlist_add_file(p->pl, url);
|
||||
free(url);
|
||||
out:
|
||||
success = true;
|
||||
err_out:
|
||||
free(addr);
|
||||
free(unicast_url);
|
||||
return entry;
|
||||
return success;
|
||||
}
|
||||
|
||||
play_tree_t*
|
||||
parse_playtree(stream_t *stream, struct m_config *mconfig, int forced) {
|
||||
play_tree_parser_t* p;
|
||||
play_tree_t* ret;
|
||||
|
||||
assert(stream != NULL);
|
||||
|
||||
p = play_tree_parser_new(stream, mconfig, 0);
|
||||
if(!p)
|
||||
return NULL;
|
||||
|
||||
ret = play_tree_parser_get_play_tree(p, forced);
|
||||
play_tree_parser_free(p);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void
|
||||
play_tree_add_basepath(play_tree_t* pt, char* bp) {
|
||||
int i,bl = strlen(bp),fl;
|
||||
|
||||
if(pt->child) {
|
||||
play_tree_t* i;
|
||||
for(i = pt->child ; i != NULL ; i = i->next)
|
||||
play_tree_add_basepath(i,bp);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!pt->files)
|
||||
return;
|
||||
|
||||
for(i = 0 ; pt->files[i] != NULL ; i++) {
|
||||
fl = strlen(pt->files[i]);
|
||||
// if we find a full unix path, url:// or X:\ at the beginning,
|
||||
// don't mangle it.
|
||||
if(fl <= 0 || strstr(pt->files[i],"://") || (strstr(pt->files[i],":\\") == pt->files[i] + 1) || (pt->files[i][0] == '/') )
|
||||
continue;
|
||||
// if the path begins with \ then prepend drive letter to it.
|
||||
if (pt->files[i][0] == '\\') {
|
||||
if (pt->files[i][1] == '\\')
|
||||
continue;
|
||||
pt->files[i] = realloc(pt->files[i], 2 + fl + 1);
|
||||
memmove(pt->files[i] + 2,pt->files[i],fl+1);
|
||||
memcpy(pt->files[i],bp,2);
|
||||
continue;
|
||||
}
|
||||
pt->files[i] = realloc(pt->files[i], bl + fl + 1);
|
||||
memmove(pt->files[i] + bl,pt->files[i],fl+1);
|
||||
memcpy(pt->files[i],bp,bl);
|
||||
}
|
||||
}
|
||||
|
||||
// Wrapper for play_tree_add_basepath (add base path from file)
|
||||
void play_tree_add_bpf(play_tree_t *pt, struct bstr filename)
|
||||
struct playlist *playlist_parse_file(const char *file)
|
||||
{
|
||||
char *ls, *file;
|
||||
|
||||
if (pt)
|
||||
{
|
||||
file = bstrdup0(NULL, filename);
|
||||
if (file)
|
||||
{
|
||||
ls = strrchr(file,'/');
|
||||
if(!ls) ls = strrchr(file,'\\');
|
||||
if(ls) {
|
||||
ls[1] = '\0';
|
||||
play_tree_add_basepath(pt,file);
|
||||
}
|
||||
talloc_free(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
play_tree_t*
|
||||
parse_playlist_file(struct m_config *mconfig, struct bstr file) {
|
||||
stream_t *stream;
|
||||
play_tree_t* ret;
|
||||
int f=DEMUXER_TYPE_PLAYLIST;
|
||||
|
||||
char *file0 = bstrdup0(NULL, file);
|
||||
stream = open_stream(file0, 0, &f);
|
||||
talloc_free(file0);
|
||||
|
||||
stream = open_stream(file, 0, &f);
|
||||
if(!stream) {
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_ERR,
|
||||
"Error while opening playlist file %.*s: %s\n",
|
||||
BSTR_P(file), strerror(errno));
|
||||
return NULL;
|
||||
"Error while opening playlist file %s: %s\n",
|
||||
file, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
mp_msg(MSGT_PLAYTREE, MSGL_V,
|
||||
"Parsing playlist file %.*s...\n", BSTR_P(file));
|
||||
"Parsing playlist file %s...\n", file);
|
||||
|
||||
ret = parse_playtree(stream, mconfig, 1);
|
||||
struct playlist *ret = playlist_parse(stream);
|
||||
free_stream(stream);
|
||||
|
||||
play_tree_add_bpf(ret, file);
|
||||
playlist_add_base_path(ret, mp_dirname(file));
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
typedef bool (*parser_fn)(play_tree_parser_t *);
|
||||
static const parser_fn pl_parsers[] = {
|
||||
parse_asx,
|
||||
parse_pls,
|
||||
parse_m3u,
|
||||
parse_ref_ini,
|
||||
parse_smil,
|
||||
parse_nsc,
|
||||
parse_textplain
|
||||
};
|
||||
|
||||
play_tree_parser_t*
|
||||
play_tree_parser_new(stream_t* stream, struct m_config *mconfig, int deep) {
|
||||
play_tree_parser_t* p;
|
||||
|
||||
p = calloc(1,sizeof(play_tree_parser_t));
|
||||
if(!p)
|
||||
return NULL;
|
||||
p->stream = stream;
|
||||
p->mconfig = mconfig;
|
||||
p->deep = deep;
|
||||
p->keep = 1;
|
||||
static struct playlist *do_parse(struct stream* stream, bool forced)
|
||||
{
|
||||
play_tree_parser_t p = {
|
||||
.stream = stream,
|
||||
.pl = talloc_zero(NULL, struct playlist),
|
||||
.keep = 1,
|
||||
};
|
||||
|
||||
return p;
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
play_tree_parser_free(play_tree_parser_t* p) {
|
||||
|
||||
assert(p != NULL);
|
||||
|
||||
free(p->buffer);
|
||||
free(p->line);
|
||||
free(p);
|
||||
}
|
||||
|
||||
play_tree_t*
|
||||
play_tree_parser_get_play_tree(play_tree_parser_t* p, int forced) {
|
||||
play_tree_t* tree = NULL;
|
||||
|
||||
assert(p != NULL);
|
||||
|
||||
while(play_tree_parser_get_line(p) != NULL) {
|
||||
play_tree_parser_reset(p);
|
||||
|
||||
tree = parse_asx(p);
|
||||
if(tree) break;
|
||||
play_tree_parser_reset(p);
|
||||
|
||||
tree = parse_pls(p);
|
||||
if(tree) break;
|
||||
play_tree_parser_reset(p);
|
||||
|
||||
tree = parse_m3u(p);
|
||||
if(tree) break;
|
||||
play_tree_parser_reset(p);
|
||||
|
||||
tree = parse_ref_ini(p);
|
||||
if(tree) break;
|
||||
play_tree_parser_reset(p);
|
||||
|
||||
tree = parse_smil(p);
|
||||
if(tree) break;
|
||||
play_tree_parser_reset(p);
|
||||
|
||||
tree = parse_nsc(p);
|
||||
if(tree) break;
|
||||
play_tree_parser_reset(p);
|
||||
|
||||
// Here come the others formats ( textplain must stay the last one )
|
||||
if (forced)
|
||||
{
|
||||
tree = parse_textplain(p);
|
||||
if(tree) break;
|
||||
bool success = false;
|
||||
if (play_tree_parser_get_line(&p) != NULL) {
|
||||
for (int n = 0; n < sizeof(pl_parsers) / sizeof(pl_parsers[0]); n++) {
|
||||
play_tree_parser_reset(&p);
|
||||
if (pl_parsers[n] == parse_textplain && !forced)
|
||||
break;
|
||||
if (pl_parsers[n](&p)) {
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if(tree)
|
||||
if(success)
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_V,"Playlist successfully parsed\n");
|
||||
else
|
||||
else {
|
||||
mp_msg(MSGT_PLAYTREE,((forced==1)?MSGL_ERR:MSGL_V),"Error while parsing playlist\n");
|
||||
talloc_free(p.pl);
|
||||
p.pl = NULL;
|
||||
}
|
||||
|
||||
if(tree)
|
||||
tree = play_tree_cleanup(tree);
|
||||
if (p.pl && !p.pl->first)
|
||||
mp_msg(MSGT_PLAYTREE,((forced==1)?MSGL_WARN:MSGL_V),"Warning: empty playlist\n");
|
||||
|
||||
if(!tree) mp_msg(MSGT_PLAYTREE,((forced==1)?MSGL_WARN:MSGL_V),"Warning: empty playlist\n");
|
||||
|
||||
return tree;
|
||||
return p.pl;
|
||||
}
|
||||
|
||||
struct playlist *playlist_parse(struct stream* stream)
|
||||
{
|
||||
return do_parse(stream, true);
|
||||
}
|
||||
|
||||
struct playlist *playlist_probe_and_parse(struct stream* stream)
|
||||
{
|
||||
return do_parse(stream, false);
|
||||
}
|
34
playlist_parser.h
Normal file
34
playlist_parser.h
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* This file is part of MPlayer.
|
||||
*
|
||||
* MPlayer is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* MPlayer is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef MPLAYER_PLAYLISTPARSER_H
|
||||
#define MPLAYER_PLAYLISTPARSER_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
struct stream;
|
||||
struct playlist;
|
||||
|
||||
// Parse the given stream as playlist. Append entries to pl. Return whether
|
||||
// there was an error when parsing.
|
||||
// deep = Parser depth. Some formats allow including other files,
|
||||
struct playlist *playlist_parse(struct stream* stream);
|
||||
struct playlist *playlist_probe_and_parse(struct stream* stream);
|
||||
struct playlist *playlist_parse_file(const char *file);
|
||||
|
||||
#endif
|
908
playtree.c
908
playtree.c
@ -1,908 +0,0 @@
|
||||
/*
|
||||
* This file is part of MPlayer.
|
||||
*
|
||||
* MPlayer is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* MPlayer is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
/// \file
|
||||
/// \ingroup Playtree
|
||||
|
||||
#include "config.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "talloc.h"
|
||||
|
||||
#include "m_config.h"
|
||||
#include "playtree.h"
|
||||
#include "mp_msg.h"
|
||||
|
||||
static int
|
||||
play_tree_is_valid(play_tree_t* pt);
|
||||
|
||||
play_tree_t*
|
||||
play_tree_new(void) {
|
||||
play_tree_t* r = calloc(1,sizeof(play_tree_t));
|
||||
r->entry_type = PLAY_TREE_ENTRY_NODE;
|
||||
return r;
|
||||
}
|
||||
|
||||
void
|
||||
play_tree_free(play_tree_t* pt, int children) {
|
||||
play_tree_t* iter;
|
||||
|
||||
assert(pt != NULL);
|
||||
|
||||
if(children) {
|
||||
for(iter = pt->child; iter != NULL; ) {
|
||||
play_tree_t* nxt=iter->next;
|
||||
play_tree_free(iter,1);
|
||||
iter = nxt;
|
||||
}
|
||||
pt->child = NULL;
|
||||
}
|
||||
|
||||
play_tree_remove(pt,0,0);
|
||||
|
||||
for(iter = pt->child ; iter != NULL ; iter = iter->next)
|
||||
iter->parent = NULL;
|
||||
|
||||
talloc_free(pt->params);
|
||||
|
||||
if(pt->files) {
|
||||
int i;
|
||||
for(i = 0 ; pt->files[i] != NULL ; i++)
|
||||
free(pt->files[i]);
|
||||
free(pt->files);
|
||||
}
|
||||
|
||||
free(pt);
|
||||
}
|
||||
|
||||
void
|
||||
play_tree_free_list(play_tree_t* pt, int children) {
|
||||
play_tree_t* iter;
|
||||
|
||||
assert(pt != NULL);
|
||||
|
||||
for(iter = pt ; iter->prev != NULL ; iter = iter->prev)
|
||||
/* NOTHING */;
|
||||
|
||||
while(iter) {
|
||||
play_tree_t* nxt = iter->next;
|
||||
play_tree_free(iter, children);
|
||||
iter = nxt;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
play_tree_append_entry(play_tree_t* pt, play_tree_t* entry) {
|
||||
play_tree_t* iter;
|
||||
|
||||
assert(pt != NULL);
|
||||
assert(entry != NULL);
|
||||
|
||||
if(pt == entry)
|
||||
return;
|
||||
|
||||
for(iter = pt ; iter->next != NULL ; iter = iter->next)
|
||||
/* NOTHING */;
|
||||
|
||||
entry->parent = iter->parent;
|
||||
entry->prev = iter;
|
||||
entry->next = NULL;
|
||||
iter->next = entry;
|
||||
}
|
||||
|
||||
void
|
||||
play_tree_prepend_entry(play_tree_t* pt, play_tree_t* entry) {
|
||||
play_tree_t* iter;
|
||||
|
||||
assert(pt != NULL);
|
||||
assert(entry != NULL);
|
||||
|
||||
for(iter = pt ; iter->prev != NULL; iter = iter->prev)
|
||||
/* NOTHING */;
|
||||
|
||||
entry->prev = NULL;
|
||||
entry->next = iter;
|
||||
entry->parent = iter->parent;
|
||||
|
||||
iter->prev = entry;
|
||||
if(entry->parent) {
|
||||
assert(entry->parent->child == iter);
|
||||
entry->parent->child = entry;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
play_tree_insert_entry(play_tree_t* pt, play_tree_t* entry) {
|
||||
|
||||
assert(pt != NULL);
|
||||
assert(entry != NULL);
|
||||
|
||||
entry->parent = pt->parent;
|
||||
entry->prev = pt;
|
||||
if(pt->next) {
|
||||
assert(pt->next->prev == pt);
|
||||
entry->next = pt->next;
|
||||
entry->next->prev = entry;
|
||||
} else
|
||||
entry->next = NULL;
|
||||
pt->next = entry;
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
play_tree_remove(play_tree_t* pt, int free_it, int with_children) {
|
||||
|
||||
assert(pt != NULL);
|
||||
|
||||
// Middle of list
|
||||
if(pt->prev && pt->next) {
|
||||
assert(pt->prev->next == pt);
|
||||
assert(pt->next->prev == pt);
|
||||
pt->prev->next = pt->next;
|
||||
pt->next->prev = pt->prev;
|
||||
} // End of list
|
||||
else if(pt->prev) {
|
||||
assert(pt->prev->next == pt);
|
||||
pt->prev->next = NULL;
|
||||
} // Beginning of list
|
||||
else if(pt->next) {
|
||||
assert(pt->next->prev == pt);
|
||||
pt->next->prev = NULL;
|
||||
if(pt->parent) {
|
||||
assert(pt->parent->child == pt);
|
||||
pt->parent->child = pt->next;
|
||||
}
|
||||
} // The only one
|
||||
else if(pt->parent) {
|
||||
assert(pt->parent->child == pt);
|
||||
pt->parent->child = NULL;
|
||||
}
|
||||
|
||||
pt->prev = pt->next = pt->parent = NULL;
|
||||
if(free_it)
|
||||
play_tree_free(pt,with_children);
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
play_tree_set_child(play_tree_t* pt, play_tree_t* child) {
|
||||
play_tree_t* iter;
|
||||
|
||||
/* Roughly validate input data. Both, pt and child are going to be
|
||||
* dereferenced, hence assure they're not NULL.
|
||||
*/
|
||||
if (!pt || !child) {
|
||||
mp_msg(MSGT_PLAYTREE, MSGL_ERR, "Internal error, attempt to add an empty child or use empty playlist\n");
|
||||
return;
|
||||
}
|
||||
|
||||
assert(pt->entry_type == PLAY_TREE_ENTRY_NODE);
|
||||
|
||||
//DEBUG_FF: Where are the children freed?
|
||||
// Attention in using this function!
|
||||
for(iter = pt->child ; iter != NULL ; iter = iter->next)
|
||||
iter->parent = NULL;
|
||||
|
||||
// Go back to first one
|
||||
for(iter = child ; iter->prev != NULL ; iter = iter->prev)
|
||||
/* NOTHING */;
|
||||
|
||||
pt->child = iter;
|
||||
|
||||
for( ; iter != NULL ; iter= iter->next)
|
||||
iter->parent = pt;
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
play_tree_set_parent(play_tree_t* pt, play_tree_t* parent) {
|
||||
play_tree_t* iter;
|
||||
|
||||
assert(pt != NULL);
|
||||
|
||||
if(pt->parent)
|
||||
pt->parent->child = NULL;
|
||||
|
||||
for(iter = pt ; iter != NULL ; iter = iter->next)
|
||||
iter->parent = parent;
|
||||
|
||||
if(pt->prev) {
|
||||
for(iter = pt->prev ; iter->prev != NULL ; iter = iter->prev)
|
||||
iter->parent = parent;
|
||||
iter->parent = parent;
|
||||
parent->child = iter;
|
||||
} else
|
||||
parent->child = pt;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
play_tree_add_file(play_tree_t* pt,const char* file) {
|
||||
int n = 0;
|
||||
|
||||
assert(pt != NULL);
|
||||
assert(pt->child == NULL);
|
||||
assert(file != NULL);
|
||||
|
||||
if(pt->entry_type != PLAY_TREE_ENTRY_NODE &&
|
||||
pt->entry_type != PLAY_TREE_ENTRY_FILE)
|
||||
return;
|
||||
|
||||
if(pt->files) {
|
||||
for(n = 0 ; pt->files[n] != NULL ; n++)
|
||||
/* NOTHING */;
|
||||
}
|
||||
pt->files = realloc(pt->files, (n + 2) * sizeof(char*));
|
||||
if(pt->files ==NULL) {
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",(n+2)*(int)sizeof(char*));
|
||||
return;
|
||||
}
|
||||
|
||||
pt->files[n] = strdup(file);
|
||||
pt->files[n+1] = NULL;
|
||||
|
||||
pt->entry_type = PLAY_TREE_ENTRY_FILE;
|
||||
|
||||
}
|
||||
|
||||
int
|
||||
play_tree_remove_file(play_tree_t* pt,const char* file) {
|
||||
int n,f = -1;
|
||||
|
||||
assert(pt != NULL);
|
||||
assert(file != NULL);
|
||||
assert(pt->entry_type != PLAY_TREE_ENTRY_NODE);
|
||||
|
||||
for(n=0 ; pt->files[n] != NULL ; n++) {
|
||||
if(strcmp(file,pt->files[n]) == 0)
|
||||
f = n;
|
||||
}
|
||||
|
||||
if(f < 0) // Not found
|
||||
return 0;
|
||||
|
||||
free(pt->files[f]);
|
||||
|
||||
if(n > 1) {
|
||||
memmove(&pt->files[f],&pt->files[f+1],(n-f)*sizeof(char*));
|
||||
pt->files = realloc(pt->files, n * sizeof(char*));
|
||||
if(pt->files == NULL) {
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",(n+2)*(int)sizeof(char*));
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
free(pt->files);
|
||||
pt->files = NULL;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
play_tree_set_param(play_tree_t* pt, struct bstr name, struct bstr val) {
|
||||
int n = 0;
|
||||
|
||||
assert(pt != NULL);
|
||||
|
||||
if(pt->params)
|
||||
for ( ; pt->params[n].name != NULL ; n++ ) { }
|
||||
|
||||
pt->params = talloc_realloc(NULL, pt->params, struct play_tree_param, n + 2);
|
||||
pt->params[n].name = bstrdup0(pt->params, name);
|
||||
pt->params[n].value = bstrdup0(pt->params, val);
|
||||
memset(&pt->params[n+1],0,sizeof(play_tree_param_t));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int
|
||||
play_tree_unset_param(play_tree_t* pt, const char* name) {
|
||||
int n,ni = -1;
|
||||
|
||||
assert(pt != NULL);
|
||||
assert(name != NULL);
|
||||
assert(pt->params != NULL);
|
||||
|
||||
for(n = 0 ; pt->params[n].name != NULL ; n++) {
|
||||
if(strcasecmp(pt->params[n].name,name) == 0)
|
||||
ni = n;
|
||||
}
|
||||
|
||||
if(ni < 0)
|
||||
return 0;
|
||||
|
||||
talloc_free(pt->params[ni].name);
|
||||
talloc_free(pt->params[ni].value);
|
||||
|
||||
if(n > 1) {
|
||||
memmove(&pt->params[ni],&pt->params[ni+1],(n-ni)*sizeof(play_tree_param_t));
|
||||
pt->params = talloc_realloc(NULL, pt->params, struct play_tree_param, n);
|
||||
} else {
|
||||
talloc_free(pt->params);
|
||||
pt->params = NULL;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
play_tree_set_params_from(play_tree_t* dest,play_tree_t* src) {
|
||||
int i;
|
||||
|
||||
assert(dest != NULL);
|
||||
assert(src != NULL);
|
||||
|
||||
if(!src->params)
|
||||
return;
|
||||
|
||||
for(i = 0; src->params[i].name != NULL ; i++)
|
||||
play_tree_set_param(dest, bstr0(src->params[i].name), bstr0(src->params[i].value));
|
||||
if(src->flags & PLAY_TREE_RND) // pass the random flag too
|
||||
dest->flags |= PLAY_TREE_RND;
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
play_tree_unset_flag(play_tree_t* pt, int flags , int deep) {
|
||||
play_tree_t* i;
|
||||
|
||||
pt->flags &= ~flags;
|
||||
|
||||
if(deep && pt->child) {
|
||||
if(deep > 0) deep--;
|
||||
for(i = pt->child ; i ; i = i->next)
|
||||
play_tree_unset_flag(i,flags,deep);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////// ITERATOR //////////////////////////////////////
|
||||
|
||||
static void
|
||||
play_tree_iter_push_params(play_tree_iter_t* iter) {
|
||||
int n;
|
||||
play_tree_t* pt;
|
||||
assert(iter->config != NULL);
|
||||
assert(iter->tree != NULL);
|
||||
|
||||
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_option0(iter->config, pt->params[n].name,
|
||||
pt->params[n].value, false)) < 0) {
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_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;
|
||||
}
|
||||
|
||||
// Shuffle the tree if the PLAY_TREE_RND flag is set, and unset it.
|
||||
// This is done recursively, but only the siblings with the same parent are
|
||||
// shuffled with each other.
|
||||
static void shuffle_tree(play_tree_t *pt) {
|
||||
if (!pt)
|
||||
return;
|
||||
|
||||
int count = 0;
|
||||
play_tree_t *child = pt->child;
|
||||
while (child) {
|
||||
// possibly shuffle children
|
||||
shuffle_tree(child);
|
||||
child = child->next;
|
||||
count++;
|
||||
}
|
||||
|
||||
if (pt->flags & PLAY_TREE_RND) {
|
||||
// Move a random element to the front and go to the next, until no
|
||||
// elements are left.
|
||||
// prev = pointer to next-link to the first yet-unshuffled entry
|
||||
play_tree_t** prev = &pt->child;
|
||||
while (count > 1) {
|
||||
int n = (int)((double)(count) * rand() / (RAND_MAX + 1.0));
|
||||
// move = element that is moved to front (inserted after prev)
|
||||
play_tree_t **before_move = prev;
|
||||
play_tree_t *move = *before_move;
|
||||
while (n > 0) {
|
||||
before_move = &move->next;
|
||||
move = *before_move;
|
||||
n--;
|
||||
}
|
||||
// unlink from old list
|
||||
*before_move = move->next;
|
||||
// insert between prev and the following element
|
||||
// note that move could be the first unshuffled element
|
||||
move->next = (*prev == move) ? move->next : *prev;
|
||||
*prev = move;
|
||||
prev = &move->next;
|
||||
count--;
|
||||
}
|
||||
// reconstruct prev links
|
||||
child = pt->child;
|
||||
play_tree_t *prev_child = NULL;
|
||||
while (child) {
|
||||
child->prev = prev_child;
|
||||
prev_child = child;
|
||||
child = child->next;
|
||||
}
|
||||
pt->flags = pt->flags & ~PLAY_TREE_RND;
|
||||
}
|
||||
}
|
||||
|
||||
play_tree_iter_t*
|
||||
play_tree_iter_new(play_tree_t* pt,m_config_t* config) {
|
||||
play_tree_iter_t* iter;
|
||||
|
||||
assert(pt != NULL);
|
||||
assert(config != NULL);
|
||||
|
||||
if( ! play_tree_is_valid(pt))
|
||||
return NULL;
|
||||
|
||||
iter = calloc(1,sizeof(play_tree_iter_t));
|
||||
if(! iter) {
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate new iterator (%d bytes of memory)\n",(int)sizeof(play_tree_iter_t));
|
||||
return NULL;
|
||||
}
|
||||
iter->root = pt;
|
||||
iter->tree = NULL;
|
||||
iter->config = config;
|
||||
|
||||
shuffle_tree(pt);
|
||||
|
||||
if(pt->parent)
|
||||
iter->loop = pt->parent->loop;
|
||||
|
||||
return iter;
|
||||
}
|
||||
|
||||
void
|
||||
play_tree_iter_free(play_tree_iter_t* iter) {
|
||||
|
||||
assert(iter != NULL);
|
||||
|
||||
if(iter->status_stack) {
|
||||
assert(iter->stack_size > 0);
|
||||
free(iter->status_stack);
|
||||
}
|
||||
|
||||
free(iter);
|
||||
}
|
||||
|
||||
static play_tree_t*
|
||||
play_tree_rnd_step(play_tree_t* pt) {
|
||||
int count = 0;
|
||||
int r;
|
||||
play_tree_t *i,*head;
|
||||
|
||||
// Count how many free choice we have
|
||||
for(i = pt ; i->prev ; i = i->prev)
|
||||
if(!(i->flags & PLAY_TREE_RND_PLAYED)) count++;
|
||||
head = i;
|
||||
if(!(i->flags & PLAY_TREE_RND_PLAYED)) count++;
|
||||
for(i = pt->next ; i ; i = i->next)
|
||||
if(!(i->flags & PLAY_TREE_RND_PLAYED)) count++;
|
||||
|
||||
if(!count) return NULL;
|
||||
|
||||
r = (int)((float)(count) * rand() / (RAND_MAX + 1.0));
|
||||
|
||||
for(i = head ; i ; i=i->next) {
|
||||
if(!(i->flags & PLAY_TREE_RND_PLAYED)) r--;
|
||||
if(r < 0) return i;
|
||||
}
|
||||
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Random stepping error\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
play_tree_iter_step(play_tree_iter_t* iter, int d,int with_nodes) {
|
||||
play_tree_t* pt;
|
||||
|
||||
if ( !iter ) return PLAY_TREE_ITER_ENTRY;
|
||||
if ( !iter->root ) return PLAY_TREE_ITER_ENTRY;
|
||||
|
||||
assert(iter != NULL);
|
||||
assert(iter->root != NULL);
|
||||
|
||||
if(iter->tree == NULL) {
|
||||
iter->tree = iter->root;
|
||||
return play_tree_iter_step(iter,0,with_nodes);
|
||||
}
|
||||
|
||||
if(iter->config && iter->entry_pushed > 0) {
|
||||
iter->entry_pushed = 0;
|
||||
m_config_pop(iter->config);
|
||||
}
|
||||
|
||||
if(iter->tree->parent && (iter->tree->parent->flags & PLAY_TREE_RND))
|
||||
iter->mode = PLAY_TREE_ITER_RND;
|
||||
else
|
||||
iter->mode = PLAY_TREE_ITER_NORMAL;
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
// Is it a valid entry?
|
||||
if(! play_tree_is_valid(pt)) {
|
||||
if(d == 0) { // Can this happen ? FF: Yes!
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"What to do now ???? Infinite loop if we continue\n");
|
||||
return PLAY_TREE_ITER_ERROR;
|
||||
} // Not a valid entry : go to next one
|
||||
return play_tree_iter_step(iter,d,with_nodes);
|
||||
}
|
||||
|
||||
assert(pt->files != NULL);
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
static int
|
||||
play_tree_is_valid(play_tree_t* pt) {
|
||||
play_tree_t* iter;
|
||||
|
||||
if(pt->entry_type != PLAY_TREE_ENTRY_NODE) {
|
||||
assert(pt->child == NULL);
|
||||
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 0;
|
||||
}
|
||||
|
||||
int
|
||||
play_tree_iter_up_step(play_tree_iter_t* iter, int d,int with_nodes) {
|
||||
|
||||
assert(iter != NULL);
|
||||
assert(iter->tree != NULL);
|
||||
|
||||
iter->file = -1;
|
||||
if(iter->tree->parent == iter->root->parent)
|
||||
return PLAY_TREE_ITER_END;
|
||||
|
||||
assert(iter->tree->parent != NULL);
|
||||
assert(iter->stack_size > 0);
|
||||
assert(iter->status_stack != NULL);
|
||||
|
||||
iter->stack_size--;
|
||||
iter->loop = iter->status_stack[iter->stack_size];
|
||||
if(iter->stack_size > 0)
|
||||
iter->status_stack = realloc(iter->status_stack, iter->stack_size * sizeof(int));
|
||||
else {
|
||||
free(iter->status_stack);
|
||||
iter->status_stack = NULL;
|
||||
}
|
||||
if(iter->stack_size > 0 && iter->status_stack == NULL) {
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",iter->stack_size*(int)sizeof(char*));
|
||||
return PLAY_TREE_ITER_ERROR;
|
||||
}
|
||||
iter->tree = iter->tree->parent;
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
return play_tree_iter_step(iter,d,with_nodes);
|
||||
}
|
||||
|
||||
int
|
||||
play_tree_iter_down_step(play_tree_iter_t* iter, int d,int with_nodes) {
|
||||
|
||||
assert(iter->tree->files == NULL);
|
||||
assert(iter->tree->child != NULL);
|
||||
assert(iter->tree->child->parent == iter->tree);
|
||||
|
||||
iter->file = -1;
|
||||
|
||||
// Push subtree params
|
||||
if(iter->config)
|
||||
play_tree_iter_push_params(iter);
|
||||
|
||||
iter->stack_size++;
|
||||
iter->status_stack = realloc(iter->status_stack, iter->stack_size * sizeof(int));
|
||||
if(iter->status_stack == NULL) {
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",iter->stack_size*(int)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;
|
||||
}
|
||||
|
||||
return play_tree_iter_step(iter,0,with_nodes);
|
||||
}
|
||||
|
||||
char*
|
||||
play_tree_iter_get_file(play_tree_iter_t* iter, int d) {
|
||||
assert(iter != NULL);
|
||||
assert(iter->tree->child == NULL);
|
||||
|
||||
if(iter->tree->files == NULL)
|
||||
return NULL;
|
||||
|
||||
assert(iter->num_files > 0);
|
||||
|
||||
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--;
|
||||
}
|
||||
return iter->tree->files[iter->file];
|
||||
}
|
||||
|
||||
play_tree_t*
|
||||
play_tree_cleanup(play_tree_t* pt) {
|
||||
play_tree_t* iter, *tmp, *first;
|
||||
|
||||
assert(pt != NULL);
|
||||
|
||||
if( ! play_tree_is_valid(pt)) {
|
||||
play_tree_remove(pt,1,1);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
first = pt->child;
|
||||
|
||||
for(iter = pt->child ; iter != NULL ; ) {
|
||||
tmp = iter;
|
||||
iter = iter->next;
|
||||
if(! play_tree_is_valid(tmp)) {
|
||||
play_tree_remove(tmp,1,1);
|
||||
if(tmp == first) first = iter;
|
||||
}
|
||||
}
|
||||
|
||||
for(iter = first ; iter != NULL ; ) {
|
||||
tmp = iter;
|
||||
iter = iter->next;
|
||||
play_tree_cleanup(tmp);
|
||||
}
|
||||
|
||||
return pt;
|
||||
|
||||
}
|
||||
|
||||
play_tree_iter_t*
|
||||
play_tree_iter_new_copy(play_tree_iter_t* old) {
|
||||
play_tree_iter_t* iter;
|
||||
|
||||
assert(old != NULL);
|
||||
|
||||
iter = malloc(sizeof(play_tree_iter_t));
|
||||
if(iter == NULL) {
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",(int)sizeof(play_tree_iter_t));
|
||||
return NULL;
|
||||
}
|
||||
;
|
||||
memcpy(iter,old,sizeof(play_tree_iter_t));
|
||||
if(old->status_stack) {
|
||||
iter->status_stack = malloc(old->stack_size * sizeof(int));
|
||||
if(iter->status_stack == NULL) {
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",old->stack_size * (int)sizeof(int));
|
||||
free(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 (mplayer@fabian-franz.de)
|
||||
//
|
||||
play_tree_iter_t* pt_iter_create(play_tree_t** ppt, m_config_t* config)
|
||||
{
|
||||
play_tree_iter_t* r=NULL;
|
||||
assert(*ppt!=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)
|
||||
{
|
||||
play_tree_iter_free(r);
|
||||
r = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
void pt_iter_destroy(play_tree_iter_t** iter)
|
||||
{
|
||||
if (iter && *iter)
|
||||
{
|
||||
free(*iter);
|
||||
iter=NULL;
|
||||
}
|
||||
}
|
||||
|
||||
char* pt_iter_get_file(play_tree_iter_t* iter, int d)
|
||||
{
|
||||
int i=0;
|
||||
char* r;
|
||||
|
||||
if (iter==NULL)
|
||||
return NULL;
|
||||
|
||||
r = play_tree_iter_get_file(iter,d);
|
||||
|
||||
while (!r && d!=0)
|
||||
{
|
||||
if (play_tree_iter_step(iter,d,0) != PLAY_TREE_ITER_ENTRY)
|
||||
break;
|
||||
r=play_tree_iter_get_file(iter,d);
|
||||
i++;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
void pt_iter_insert_entry(play_tree_iter_t* iter, play_tree_t* entry)
|
||||
{
|
||||
play_tree_t *pt = iter->tree;
|
||||
assert(pt!=NULL);
|
||||
assert(entry!=NULL);
|
||||
assert(entry!=pt);
|
||||
|
||||
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)
|
||||
{
|
||||
play_tree_t *pt = iter->tree;
|
||||
|
||||
pt_iter_insert_entry(iter, entry);
|
||||
play_tree_remove(pt, 1, 1);
|
||||
iter->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();
|
||||
|
||||
play_tree_add_file(entry, filename);
|
||||
if (pt)
|
||||
play_tree_append_entry(pt, entry);
|
||||
else
|
||||
{
|
||||
pt=entry;
|
||||
*ppt=pt;
|
||||
}
|
||||
play_tree_set_params_from(entry,pt);
|
||||
}
|
||||
|
||||
void pt_iter_goto_head(play_tree_iter_t* iter)
|
||||
{
|
||||
iter->tree=iter->root;
|
||||
play_tree_iter_step(iter, 0, 0);
|
||||
}
|
302
playtree.h
302
playtree.h
@ -1,302 +0,0 @@
|
||||
/*
|
||||
* This file is part of MPlayer.
|
||||
*
|
||||
* MPlayer is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* MPlayer is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef MPLAYER_PLAYTREE_H
|
||||
#define MPLAYER_PLAYTREE_H
|
||||
|
||||
#include "bstr.h"
|
||||
|
||||
/// \file
|
||||
/// \ingroup Playtree
|
||||
|
||||
struct stream;
|
||||
struct m_config;
|
||||
|
||||
/// \defgroup PlaytreeIterReturn Playtree iterator return code
|
||||
/// \ingroup PlaytreeIter
|
||||
///@{
|
||||
#define PLAY_TREE_ITER_ERROR 0
|
||||
#define PLAY_TREE_ITER_ENTRY 1
|
||||
#define PLAY_TREE_ITER_NODE 2
|
||||
#define PLAY_TREE_ITER_END 3
|
||||
///@}
|
||||
|
||||
/// \defgroup PlaytreeEntryTypes Playtree entry types
|
||||
/// \ingroup Playtree
|
||||
///@{
|
||||
#define PLAY_TREE_ENTRY_NODE -1
|
||||
#define PLAY_TREE_ENTRY_DVD 0
|
||||
#define PLAY_TREE_ENTRY_VCD 1
|
||||
#define PLAY_TREE_ENTRY_TV 2
|
||||
#define PLAY_TREE_ENTRY_FILE 3
|
||||
///@}
|
||||
|
||||
|
||||
/// \defgroup PlaytreeEntryFlags Playtree flags
|
||||
/// \ingroup Playtree
|
||||
///@{
|
||||
/// Play the item children in random order.
|
||||
#define PLAY_TREE_RND (1<<0)
|
||||
/// Playtree flags used by the iterator to mark items already "randomly" played.
|
||||
#define PLAY_TREE_RND_PLAYED (1<<8)
|
||||
///@}
|
||||
|
||||
/// \defgroup PlaytreeIterMode Playtree iterator mode
|
||||
/// \ingroup PlaytreeIter
|
||||
///@{
|
||||
#define PLAY_TREE_ITER_NORMAL 0
|
||||
#define PLAY_TREE_ITER_RND 1
|
||||
///@}
|
||||
|
||||
/// \defgroup Playtree
|
||||
///@{
|
||||
|
||||
typedef struct play_tree play_tree_t;
|
||||
/// \ingroup PlaytreeIter
|
||||
typedef struct play_tree_iter play_tree_iter_t;
|
||||
typedef struct play_tree_param play_tree_param_t;
|
||||
|
||||
|
||||
#if 0
|
||||
typedef struct play_tree_info play_tree_info_t;
|
||||
// TODO : a attrib,val pair system and not something hardcoded
|
||||
struct play_tree_info {
|
||||
char* title;
|
||||
char* author;
|
||||
char* copyright;
|
||||
char* abstract;
|
||||
// Some more ??
|
||||
}
|
||||
#endif
|
||||
|
||||
struct play_tree_param {
|
||||
char* name;
|
||||
char* value;
|
||||
};
|
||||
|
||||
|
||||
/// Playtree item
|
||||
struct play_tree {
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
/// \defgroup PlaytreeIter Playtree iterator
|
||||
/// \ingroup Playtree
|
||||
///@{
|
||||
|
||||
/// Playtree iterator
|
||||
struct play_tree_iter {
|
||||
/// Root of the iterated tree.
|
||||
play_tree_t* root;
|
||||
/// Current position in the tree.
|
||||
play_tree_t* tree;
|
||||
/// \ref Config used.
|
||||
struct m_config* config;
|
||||
/// Looping status
|
||||
int loop;
|
||||
/// Selected file in the current item.
|
||||
int file;
|
||||
/// Number of files in the current item.
|
||||
int num_files;
|
||||
int entry_pushed;
|
||||
int mode;
|
||||
|
||||
/// loop/valid stack to save/revert status when we go up/down.
|
||||
int* status_stack;
|
||||
/// status stack size
|
||||
int stack_size;
|
||||
};
|
||||
///@}
|
||||
|
||||
/// Create a new empty playtree item.
|
||||
play_tree_t*
|
||||
play_tree_new(void);
|
||||
|
||||
/// Free a playtree item.
|
||||
/** \param pt Item to free.
|
||||
* \param children If non-zero the item's children are recursively freed.
|
||||
*/
|
||||
void
|
||||
play_tree_free(play_tree_t* pt, int children);
|
||||
|
||||
|
||||
/// Free an item and its siblings.
|
||||
/** \param pt Item to free.
|
||||
* \param children If non-zero the items' children are recursively freed.
|
||||
*/
|
||||
void
|
||||
play_tree_free_list(play_tree_t* pt, int children);
|
||||
|
||||
|
||||
/// Set the children of a playtree item.
|
||||
void
|
||||
play_tree_set_child(play_tree_t* pt, play_tree_t* child);
|
||||
|
||||
/// Set the parent of a playtree item.
|
||||
void
|
||||
play_tree_set_parent(play_tree_t* pt, play_tree_t* parent);
|
||||
|
||||
|
||||
/// Append an item after its siblings.
|
||||
void
|
||||
play_tree_append_entry(play_tree_t* pt, play_tree_t* entry);
|
||||
|
||||
/// Prepend an item before its siblings.
|
||||
void
|
||||
play_tree_prepend_entry(play_tree_t* pt, play_tree_t* entry);
|
||||
|
||||
/// Insert an item right after a siblings.
|
||||
void
|
||||
play_tree_insert_entry(play_tree_t* pt, play_tree_t* entry);
|
||||
|
||||
/// Detach an item from the tree.
|
||||
void
|
||||
play_tree_remove(play_tree_t* pt, int free_it,int with_children);
|
||||
|
||||
/// Add a file to an item.
|
||||
void
|
||||
play_tree_add_file(play_tree_t* pt,const char* file);
|
||||
|
||||
/// Remove a file from an item.
|
||||
int
|
||||
play_tree_remove_file(play_tree_t* pt,const char* file);
|
||||
|
||||
|
||||
/// Add a config paramter to an item.
|
||||
void
|
||||
play_tree_set_param(play_tree_t* pt, struct bstr name, struct bstr val);
|
||||
|
||||
/// Remove a config parameter from an item.
|
||||
int
|
||||
play_tree_unset_param(play_tree_t* pt, const char* name);
|
||||
|
||||
/// Copy the config parameters from one item to another.
|
||||
void
|
||||
play_tree_set_params_from(play_tree_t* dest,play_tree_t* src);
|
||||
|
||||
/// \addtogroup PlaytreeIter
|
||||
///@{
|
||||
|
||||
/// Create a new iterator.
|
||||
play_tree_iter_t*
|
||||
play_tree_iter_new(play_tree_t* pt, struct m_config* config);
|
||||
|
||||
/// Duplicate an iterator.
|
||||
play_tree_iter_t*
|
||||
play_tree_iter_new_copy(play_tree_iter_t* old);
|
||||
|
||||
/// Free an iterator.
|
||||
void
|
||||
play_tree_iter_free(play_tree_iter_t* iter);
|
||||
|
||||
/// Step an iterator.
|
||||
/** \param iter The iterator.
|
||||
* \param d The direction: d > 0 == next , d < 0 == prev
|
||||
* \param with_node TRUE == stop on nodes with children, FALSE == go directly to the next child
|
||||
* \return See \ref PlaytreeIterReturn.
|
||||
*/
|
||||
int
|
||||
play_tree_iter_step(play_tree_iter_t* iter, int d,int with_nodes);
|
||||
|
||||
/// Step up, useful to break a loop, etc.
|
||||
/** \param iter The iterator.
|
||||
* \param d The direction: d > 0 == next , d < 0 == prev
|
||||
* \param with_node TRUE == stop on nodes with children, FALSE == go directly to the next child
|
||||
* \return See \ref PlaytreeIterReturn.
|
||||
*/
|
||||
int
|
||||
play_tree_iter_up_step(play_tree_iter_t* iter, int d,int with_nodes);
|
||||
|
||||
/// Enter a node child list, only useful when stopping on nodes.
|
||||
int
|
||||
play_tree_iter_down_step(play_tree_iter_t* iter, int d,int with_nodes);
|
||||
|
||||
/// Get a file from the current item.
|
||||
char*
|
||||
play_tree_iter_get_file(play_tree_iter_t* iter, int d);
|
||||
|
||||
///@}
|
||||
// PlaytreeIter group
|
||||
|
||||
/// Create a playtree from a playlist file.
|
||||
/** \ingroup PlaytreeParser
|
||||
*/
|
||||
struct m_config;
|
||||
play_tree_t*
|
||||
parse_playtree(struct stream *stream, struct m_config *mconfig, int forced);
|
||||
|
||||
/// Clean a tree by destroying all empty elements.
|
||||
play_tree_t*
|
||||
play_tree_cleanup(play_tree_t* pt);
|
||||
|
||||
/// Create a playtree from a playlist file.
|
||||
/** \ingroup PlaytreeParser
|
||||
*/
|
||||
play_tree_t*
|
||||
parse_playlist_file(struct m_config *mconfig, struct bstr file);
|
||||
|
||||
/// \defgroup PtAPI Playtree highlevel API
|
||||
/// \ingroup Playtree
|
||||
/// Highlevel API with pt-suffix to different from low-level API
|
||||
/// by Fabian Franz (mplayer@fabian-franz.de).
|
||||
///@{
|
||||
|
||||
// Cleans up pt and creates a new iter.
|
||||
play_tree_iter_t* pt_iter_create(play_tree_t** pt, struct m_config* config);
|
||||
|
||||
/// Frees the iter.
|
||||
void pt_iter_destroy(play_tree_iter_t** iter);
|
||||
|
||||
/// Gets the next available file in the direction (d=-1 || d=+1).
|
||||
char* pt_iter_get_file(play_tree_iter_t* iter, int d);
|
||||
|
||||
// Two Macros that implement forward and backward direction.
|
||||
#define pt_iter_get_next_file(iter) pt_iter_get_file(iter, 1)
|
||||
#define pt_iter_get_prev_file(iter) pt_iter_get_file(iter, -1)
|
||||
|
||||
/// Inserts entry into the playtree.
|
||||
void pt_iter_insert_entry(play_tree_iter_t* iter, play_tree_t* entry);
|
||||
|
||||
/// Replaces current entry in playtree with entry by doing insert and remove.
|
||||
void pt_iter_replace_entry(play_tree_iter_t* iter, play_tree_t* entry);
|
||||
|
||||
/// Adds a new file to the playtree, if it is not valid it is created.
|
||||
void pt_add_file(play_tree_t** ppt, const char* filename);
|
||||
|
||||
// A macro to use only the iter and not the other things.
|
||||
#define pt_iter_add_file(iter, filename) pt_add_file(&iter->tree, filename)
|
||||
|
||||
/// Resets the iter and goes back to head.
|
||||
void pt_iter_goto_head(play_tree_iter_t* iter);
|
||||
|
||||
///@}
|
||||
|
||||
///@}
|
||||
|
||||
#endif /* MPLAYER_PLAYTREE_H */
|
@ -1,73 +0,0 @@
|
||||
/*
|
||||
* This file is part of MPlayer.
|
||||
*
|
||||
* MPlayer is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* MPlayer is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef MPLAYER_PLAYTREEPARSER_H
|
||||
#define MPLAYER_PLAYTREEPARSER_H
|
||||
|
||||
#include "playtree.h"
|
||||
#include "bstr.h"
|
||||
|
||||
/// \defgroup PlaytreeParser Playtree parser
|
||||
/// \ingroup Playtree
|
||||
///
|
||||
/// The playtree parser allows to read various playlist formats. It reads from
|
||||
/// a stream allowing to handle playlists from local files and the network.
|
||||
///@{
|
||||
|
||||
/// \file
|
||||
|
||||
struct stream;
|
||||
|
||||
typedef struct play_tree_parser {
|
||||
struct stream *stream;
|
||||
struct m_config *mconfig;
|
||||
char *buffer,*iter,*line;
|
||||
int buffer_size , buffer_end;
|
||||
int deep,keep;
|
||||
} play_tree_parser_t;
|
||||
|
||||
/// Create a new parser.
|
||||
/** \param stream The stream to read from.
|
||||
* \param deep Parser depth. Some formats allow including other files,
|
||||
* this is used to track the inclusion depth.
|
||||
* \return The new parser.
|
||||
*/
|
||||
play_tree_parser_t*
|
||||
play_tree_parser_new(struct stream* stream, struct m_config *mconfig, int deep);
|
||||
|
||||
/// Destroy a parser.
|
||||
void
|
||||
play_tree_parser_free(play_tree_parser_t* p);
|
||||
|
||||
/// Build a playtree from the playlist opened with the parser.
|
||||
/** \param p The parser.
|
||||
* \param forced If non-zero the playlist file was explicitly
|
||||
* given by the user, allow falling back on
|
||||
* one filename per line playlist.
|
||||
* \return A new playtree or NULL on error.
|
||||
*/
|
||||
play_tree_t*
|
||||
play_tree_parser_get_play_tree(play_tree_parser_t* p, int forced);
|
||||
|
||||
/// Wrapper for play_tree_add_basepath (add base path from file).
|
||||
void
|
||||
play_tree_add_bpf(play_tree_t* pt, struct bstr filename);
|
||||
|
||||
///@}
|
||||
|
||||
#endif /* MPLAYER_PLAYTREEPARSER_H */
|
Loading…
Reference in New Issue
Block a user