📄 playtree
字号:
How work the playtree ? Good question, I try to explain but note that it's the first docI write :)First there is two things. The playtree itself and the iterator.The playtree represent the data and the iterator is used bymplayer 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 holdall 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 thanone server. But all send the same thing, so it's only on entry with sevralsources.Then how do I use this stuff ?First you create an entry using the play_tree_new func. This create the structand fill it with defaults values.Then this can become a node or a leaf. It will become a node as soon as you link itto 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 beraised) and if en entry has a child you can't add file to (here also an assert willbe 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 thirdarg is true it will also free the children.When your tree is ready you can then use play_tree_cleanup to remove all unusefulentries.If you want to load a playlist you can use parse_playtree which take a stream_tas 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 thatyou 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 channelMy playtree is ready now, what with this play_tree_iter ?This is an iterator used to go trough the tree. It handle itselfloop of list and setting mplayer config according to the paramsof each entry.It's created with play_tree_iter_new which take as argument a play_tree_tand 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. Thesecond 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 ofnode or not. If it's true, the iterator will stop on nodes, otherwise it goto the next valid entry.This function return different values :PLAY_TREE_ITER_ERROR : obviousPLAY_TREE_ITER_ENTRY : we are now on an entryPLAY_TREE_ITER_NODE : we are now on a nodePLAY_TREE_ITER_END : we are now at end(( Note : I must add a PLAY_TREE_ITER_BEGINING for the begining. Don't knowwhat 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 skipthe current list. The argument are the same than play_tree_iter_step. Thedifference is that it go back to parent of the current list, and then step accordingto the arguments.Then when your iter returned PLAY_TREE_ITER_ENTRY you can useplay_tree_iter_get_file to get the file. If you call it more than one timeit will return the next file for this entry or loop trough the list if no morefile are available. You can now how many files are available usingiter->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 filenamebut "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, etcYou must create a clone with play_tree_iter_new_copy. This iter will not affectthe 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. Alsoafter stream opening, in case the stream is a playlist it replace theentry which contained the playlist by the result of the parsing.In the event handling it check if a step can be done, etc. And finnalyat the end it go the next entry.Suggestion, flames, etc about this doc must go to albeu@free.fr
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -