1 /*
2  * This file is part of MPlayer.
3  *
4  * MPlayer is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * MPlayer is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #ifndef MPLAYER_PLAYTREE_H
20 #define MPLAYER_PLAYTREE_H
21 
22 /// \file
23 /// \ingroup Playtree
24 
25 struct stream;
26 struct m_config;
27 
28 /// \defgroup PlaytreeIterReturn Playtree iterator return code
29 /// \ingroup PlaytreeIter
30 ///@{
31 #define PLAY_TREE_ITER_ERROR 0
32 #define PLAY_TREE_ITER_ENTRY 1
33 #define PLAY_TREE_ITER_NODE  2
34 #define PLAY_TREE_ITER_END 3
35 ///@}
36 
37 /// \defgroup PlaytreeEntryTypes Playtree entry types
38 /// \ingroup Playtree
39 ///@{
40 #define PLAY_TREE_ENTRY_NODE -1
41 #define PLAY_TREE_ENTRY_DVD 0
42 #define PLAY_TREE_ENTRY_VCD 1
43 #define PLAY_TREE_ENTRY_TV    2
44 #define PLAY_TREE_ENTRY_FILE  3
45 ///@}
46 
47 
48 /// \defgroup PlaytreeEntryFlags Playtree flags
49 /// \ingroup Playtree
50 ///@{
51 /// Play the item children in random order.
52 #define PLAY_TREE_RND  (1<<0)
53 /// Playtree flags used by the iterator to mark items already "randomly" played.
54 #define PLAY_TREE_RND_PLAYED  (1<<8)
55 ///@}
56 
57 /// \defgroup PlaytreeIterMode Playtree iterator mode
58 /// \ingroup PlaytreeIter
59 ///@{
60 #define PLAY_TREE_ITER_NORMAL 0
61 #define PLAY_TREE_ITER_RND 1
62 ///@}
63 
64 /// \defgroup playtree Playtree
65 ///@{
66 
67 typedef struct play_tree play_tree_t;
68 /// \ingroup PlaytreeIter
69 typedef struct play_tree_iter play_tree_iter_t;
70 typedef struct play_tree_param play_tree_param_t;
71 
72 
73 #if 0
74 typedef struct play_tree_info play_tree_info_t;
75 // TODO : a attrib,val pair system and not something hardcoded
76 struct play_tree_info {
77   char* title;
78   char* author;
79   char* copyright;
80   char* abstract;
81   // Some more ??
82 }
83 #endif
84 
85 struct play_tree_param {
86   char* name;
87   char* value;
88 };
89 
90 
91 /// Playtree item
92 struct play_tree {
93   play_tree_t* parent;
94   play_tree_t* child;
95   play_tree_t* next;
96   play_tree_t* prev;
97 
98   //play_tree_info_t info;
99   play_tree_param_t* params;
100   int loop;
101   char** files;
102   int entry_type;
103   int flags;
104 };
105 
106 
107 /// \defgroup PlaytreeIter Playtree iterator
108 /// \ingroup Playtree
109 ///@{
110 
111 /// Playtree iterator
112 struct play_tree_iter {
113   /// Root of the iterated tree.
114   play_tree_t* root;
115   /// Current position in the tree.
116   play_tree_t* tree;
117   /// \ref Config used.
118   struct m_config* config;
119   /// Looping status
120   int loop;
121   /// Selected file in the current item.
122   int file;
123   /// Number of files in the current item.
124   int num_files;
125   int entry_pushed;
126   int mode;
127 
128   ///  loop/valid stack to save/revert status when we go up/down.
129   int* status_stack;
130   /// status stack size
131   int stack_size;
132 };
133 ///@}
134 
135 /// Create a new empty playtree item.
136 play_tree_t*
137 play_tree_new(void);
138 
139 /// Free a playtree item.
140 /** \param pt Item to free.
141  *  \param children If non-zero the item's children are recursively freed.
142  */
143 void
144 play_tree_free(play_tree_t* pt, int children);
145 
146 
147 /// Free an item and its siblings.
148 /** \param pt Item to free.
149  *  \param children If non-zero the items' children are recursively freed.
150  */
151 void
152 play_tree_free_list(play_tree_t* pt, int children);
153 
154 
155 /// Set the children of a playtree item.
156 void
157 play_tree_set_child(play_tree_t* pt, play_tree_t* child);
158 
159 /// Set the parent of a playtree item.
160 void
161 play_tree_set_parent(play_tree_t* pt, play_tree_t* parent);
162 
163 
164 /// Append an item after its siblings.
165 void
166 play_tree_append_entry(play_tree_t* pt, play_tree_t* entry);
167 
168 /// Prepend an item before its siblings.
169 void
170 play_tree_prepend_entry(play_tree_t* pt, play_tree_t* entry);
171 
172 /// Insert an item right after a siblings.
173 void
174 play_tree_insert_entry(play_tree_t* pt, play_tree_t* entry);
175 
176 /// Detach an item from the tree.
177 void
178 play_tree_remove(play_tree_t* pt, int free_it,int with_children);
179 
180 /// Add a file to an item.
181 void
182 play_tree_add_file(play_tree_t* pt,const char* file);
183 
184 /// Remove a file from an item.
185 int
186 play_tree_remove_file(play_tree_t* pt,const char* file);
187 
188 
189 /// Add a config paramter to an item.
190 void
191 play_tree_set_param(play_tree_t* pt, const char* name, const char* val);
192 
193 /// Remove a config parameter from an item.
194 int
195 play_tree_unset_param(play_tree_t* pt, const char* name);
196 
197 /// Copy the config parameters from one item to another.
198 void
199 play_tree_set_params_from(play_tree_t* dest,play_tree_t* src);
200 
201 /// \addtogroup PlaytreeIter
202 ///@{
203 
204 /// Create a new iterator.
205 play_tree_iter_t*
206 play_tree_iter_new(play_tree_t* pt, struct m_config* config);
207 
208 /// Duplicate an iterator.
209 play_tree_iter_t*
210 play_tree_iter_new_copy(play_tree_iter_t* old);
211 
212 /// Free an iterator.
213 void
214 play_tree_iter_free(play_tree_iter_t* iter);
215 
216 /// Step an iterator.
217 /** \param iter The iterator.
218  *  \param d The direction: d > 0 == next , d < 0 == prev
219  *  \param with_node TRUE == stop on nodes with children, FALSE == go directly to the next child
220  *  \return See \ref PlaytreeIterReturn.
221  */
222 int
223 play_tree_iter_step(play_tree_iter_t* iter, int d,int with_nodes);
224 
225 /// Step up, useful to break a loop, etc.
226 /** \param iter The iterator.
227  *  \param d The direction: d > 0 == next , d < 0 == prev
228  *  \param with_node TRUE == stop on nodes with children, FALSE == go directly to the next child
229  *  \return See \ref PlaytreeIterReturn.
230  */
231 int
232 play_tree_iter_up_step(play_tree_iter_t* iter, int d,int with_nodes);
233 
234 /// Enter a node child list, only useful when stopping on nodes.
235 int
236 play_tree_iter_down_step(play_tree_iter_t* iter, int d,int with_nodes);
237 
238 /// Get a file from the current item.
239 char*
240 play_tree_iter_get_file(play_tree_iter_t* iter, int d);
241 
242 ///@}
243 // PlaytreeIter group
244 
245 /// Create a playtree from a playlist file.
246 /** \ingroup PlaytreeParser
247  */
248 play_tree_t*
249 parse_playtree(struct stream *stream, int forced);
250 
251 /// Clean a tree by destroying all empty elements.
252 play_tree_t*
253 play_tree_cleanup(play_tree_t* pt);
254 
255 /// Create a playtree from a playlist file.
256 /** \ingroup PlaytreeParser
257  */
258 play_tree_t*
259 parse_playlist_file(char* file);
260 
261 /// \defgroup PtAPI Playtree highlevel API
262 /// \ingroup Playtree
263 /// Highlevel API with pt-suffix to different from low-level API
264 /// by Fabian Franz (mplayer@fabian-franz.de).
265 ///@{
266 
267 // Cleans up pt and creates a new iter.
268 play_tree_iter_t* pt_iter_create(play_tree_t** pt, struct m_config* config);
269 
270 /// Frees the iter.
271 void pt_iter_destroy(play_tree_iter_t** iter);
272 
273 /// Gets the next available file in the direction (d=-1 || d=+1).
274 char* pt_iter_get_file(play_tree_iter_t* iter, int d);
275 
276 // Two Macros that implement forward and backward direction.
277 #define pt_iter_get_next_file(iter) pt_iter_get_file(iter, 1)
278 #define pt_iter_get_prev_file(iter) pt_iter_get_file(iter, -1)
279 
280 /// Inserts entry into the playtree.
281 void pt_iter_insert_entry(play_tree_iter_t* iter, play_tree_t* entry);
282 
283 /// Replaces current entry in playtree with entry by doing insert and remove.
284 void pt_iter_replace_entry(play_tree_iter_t* iter, play_tree_t* entry);
285 
286 /// Adds a new file to the playtree, if it is not valid it is created.
287 void pt_add_file(play_tree_t** ppt, const char* filename);
288 
289 // Macro to use only the iter and not the other things.
290 #define pt_iter_add_file(iter, filename) pt_add_file(&iter->tree, filename)
291 
292 /// Resets the iter and goes back to head.
293 void pt_iter_goto_head(play_tree_iter_t* iter);
294 
295 ///@}
296 
297 ///@}
298 
299 #endif /* MPLAYER_PLAYTREE_H */
300