annotate playtree.c @ 34938:e28d06b74813

Set some new HAVE_ defines unconditionally to 0.
author cehoyos
date Tue, 17 Jul 2012 07:51:55 +0000
parents 2df1a5fee8a7
children 389d43c448b3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30429
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29726
diff changeset
1 /*
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29726
diff changeset
2 * This file is part of MPlayer.
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29726
diff changeset
3 *
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29726
diff changeset
4 * MPlayer is free software; you can redistribute it and/or modify
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29726
diff changeset
5 * it under the terms of the GNU General Public License as published by
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29726
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29726
diff changeset
7 * (at your option) any later version.
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29726
diff changeset
8 *
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29726
diff changeset
9 * MPlayer is distributed in the hope that it will be useful,
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29726
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29726
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29726
diff changeset
12 * GNU General Public License for more details.
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29726
diff changeset
13 *
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29726
diff changeset
14 * You should have received a copy of the GNU General Public License along
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29726
diff changeset
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29726
diff changeset
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29726
diff changeset
17 */
18265
1a14fde7680d Doxygen Attack! - Chapter 3
albeu
parents: 13884
diff changeset
18
1a14fde7680d Doxygen Attack! - Chapter 3
albeu
parents: 13884
diff changeset
19 /// \file
1a14fde7680d Doxygen Attack! - Chapter 3
albeu
parents: 13884
diff changeset
20 /// \ingroup Playtree
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
21
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
22 #include "config.h"
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
23 #include <stdlib.h>
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
24 #include <string.h>
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
25 #include <stdio.h>
4050
da61596bcd87 FreeBSD fix
nexus
parents: 4043
diff changeset
26 #include <unistd.h>
4220
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
27 #include <errno.h>
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
28 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
29 #include <assert.h>
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
30 #endif
9748
f74f8b809697 Use new config headers
albeu
parents: 9290
diff changeset
31 #include "m_config.h"
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
32 #include "playtree.h"
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
33 #include "mp_msg.h"
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
34
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
35 static int
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
36 play_tree_is_valid(play_tree_t* pt);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
37
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
38 play_tree_t*
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
39 play_tree_new(void) {
18879
cc65a585fdcc rm unnecesary casts from void* - part 3
reynaldo
parents: 18869
diff changeset
40 play_tree_t* r = calloc(1,sizeof(play_tree_t));
28320
aac3629b180d Actually abort (return NULL) in the alloc-failure check in play_tree_new
reimar
parents: 27088
diff changeset
41 if(r == NULL) {
23614
bab9e6c606cc Cast sizeof() to int in mp_msg arguments so it fits the format string on 64bit
reimar
parents: 18886
diff changeset
42 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",(int)sizeof(play_tree_t));
28320
aac3629b180d Actually abort (return NULL) in the alloc-failure check in play_tree_new
reimar
parents: 27088
diff changeset
43 return NULL;
aac3629b180d Actually abort (return NULL) in the alloc-failure check in play_tree_new
reimar
parents: 27088
diff changeset
44 }
4220
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
45 r->entry_type = PLAY_TREE_ENTRY_NODE;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
46 return r;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
47 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
48
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
49 void
23872
4d936284a5ec typo fix: childs --> children
diego
parents: 23614
diff changeset
50 play_tree_free(play_tree_t* pt, int children) {
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
51 play_tree_t* iter;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
52
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
53 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
54 assert(pt != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
55 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
56
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
57 if(children) {
8062
ed2d3e7e7e36 10L found by jeroen dobbelaere <jeroen dot dobbelaere at acunia dot com>
albeu
parents: 5802
diff changeset
58 for(iter = pt->child; iter != NULL; ) {
ed2d3e7e7e36 10L found by jeroen dobbelaere <jeroen dot dobbelaere at acunia dot com>
albeu
parents: 5802
diff changeset
59 play_tree_t* nxt=iter->next;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
60 play_tree_free(iter,1);
8062
ed2d3e7e7e36 10L found by jeroen dobbelaere <jeroen dot dobbelaere at acunia dot com>
albeu
parents: 5802
diff changeset
61 iter = nxt;
ed2d3e7e7e36 10L found by jeroen dobbelaere <jeroen dot dobbelaere at acunia dot com>
albeu
parents: 5802
diff changeset
62 }
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
63 pt->child = NULL;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
64 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
65
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
66 play_tree_remove(pt,0,0);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
67
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
68 for(iter = pt->child ; iter != NULL ; iter = iter->next)
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
69 iter->parent = NULL;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
70
33277
16dcb1b753eb Free playtree params.
reimar
parents: 32511
diff changeset
71 if (pt->params) {
16dcb1b753eb Free playtree params.
reimar
parents: 32511
diff changeset
72 int i;
16dcb1b753eb Free playtree params.
reimar
parents: 32511
diff changeset
73 for(i = 0 ; pt->params[i].name != NULL ; i++) {
16dcb1b753eb Free playtree params.
reimar
parents: 32511
diff changeset
74 free(pt->params[i].name);
16dcb1b753eb Free playtree params.
reimar
parents: 32511
diff changeset
75 free(pt->params[i].value);
16dcb1b753eb Free playtree params.
reimar
parents: 32511
diff changeset
76 }
16dcb1b753eb Free playtree params.
reimar
parents: 32511
diff changeset
77 free(pt->params);
16dcb1b753eb Free playtree params.
reimar
parents: 32511
diff changeset
78 }
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
79 if(pt->files) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
80 int i;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
81 for(i = 0 ; pt->files[i] != NULL ; i++)
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
82 free(pt->files[i]);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
83 free(pt->files);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
84 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
85
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
86 free(pt);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
87 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
88
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
89 void
23872
4d936284a5ec typo fix: childs --> children
diego
parents: 23614
diff changeset
90 play_tree_free_list(play_tree_t* pt, int children) {
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
91 play_tree_t* iter;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
92
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
93 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
94 assert(pt != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
95 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
96
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
97 for(iter = pt ; iter->prev != NULL ; iter = iter->prev)
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
98 /* NOTHING */;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
99
8062
ed2d3e7e7e36 10L found by jeroen dobbelaere <jeroen dot dobbelaere at acunia dot com>
albeu
parents: 5802
diff changeset
100 while(iter) {
ed2d3e7e7e36 10L found by jeroen dobbelaere <jeroen dot dobbelaere at acunia dot com>
albeu
parents: 5802
diff changeset
101 play_tree_t* nxt = iter->next;
23872
4d936284a5ec typo fix: childs --> children
diego
parents: 23614
diff changeset
102 play_tree_free(iter, children);
8062
ed2d3e7e7e36 10L found by jeroen dobbelaere <jeroen dot dobbelaere at acunia dot com>
albeu
parents: 5802
diff changeset
103 iter = nxt;
ed2d3e7e7e36 10L found by jeroen dobbelaere <jeroen dot dobbelaere at acunia dot com>
albeu
parents: 5802
diff changeset
104 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
105
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
106
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
107 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
108
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
109 void
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
110 play_tree_append_entry(play_tree_t* pt, play_tree_t* entry) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
111 play_tree_t* iter;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
112
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
113 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
114 assert(pt != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
115 assert(entry != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
116 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
117
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
118 if(pt == entry)
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
119 return;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
120
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
121 for(iter = pt ; iter->next != NULL ; iter = iter->next)
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
122 /* NOTHING */;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
123
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
124 entry->parent = iter->parent;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
125 entry->prev = iter;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
126 entry->next = NULL;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
127 iter->next = entry;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
128 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
129
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
130 void
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
131 play_tree_prepend_entry(play_tree_t* pt, play_tree_t* entry) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
132 play_tree_t* iter;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
133
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
134 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
135 assert(pt != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
136 assert(entry != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
137 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
138
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
139 for(iter = pt ; iter->prev != NULL; iter = iter->prev)
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
140 /* NOTHING */;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
141
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
142 entry->prev = NULL;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
143 entry->next = iter;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
144 entry->parent = iter->parent;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
145
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
146 iter->prev = entry;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
147 if(entry->parent) {
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
148 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
149 assert(entry->parent->child == iter);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
150 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
151 entry->parent->child = entry;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
152 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
153 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
154
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
155 void
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
156 play_tree_insert_entry(play_tree_t* pt, play_tree_t* entry) {
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
157
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
158 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
159 assert(pt != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
160 assert(entry != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
161 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
162
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
163 entry->parent = pt->parent;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
164 entry->prev = pt;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
165 if(pt->next) {
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
166 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
167 assert(pt->next->prev == pt);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
168 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
169 entry->next = pt->next;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
170 entry->next->prev = entry;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
171 } else
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
172 entry->next = NULL;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
173 pt->next = entry;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
174
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
175 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
176
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
177 void
23872
4d936284a5ec typo fix: childs --> children
diego
parents: 23614
diff changeset
178 play_tree_remove(play_tree_t* pt, int free_it, int with_children) {
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
179
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
180 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
181 assert(pt != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
182 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
183
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
184 // Middle of list
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
185 if(pt->prev && pt->next) {
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
186 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
187 assert(pt->prev->next == pt);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
188 assert(pt->next->prev == pt);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
189 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
190 pt->prev->next = pt->next;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
191 pt->next->prev = pt->prev;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
192 } // End of list
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
193 else if(pt->prev) {
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
194 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
195 assert(pt->prev->next == pt);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
196 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
197 pt->prev->next = NULL;
25489
52f6429a9ba7 typo: begining --> beginning
diego
parents: 23872
diff changeset
198 } // Beginning of list
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
199 else if(pt->next) {
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
200 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
201 assert(pt->next->prev == pt);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
202 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
203 pt->next->prev = NULL;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
204 if(pt->parent) {
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
205 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
206 assert(pt->parent->child == pt);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
207 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
208 pt->parent->child = pt->next;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
209 }
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
210 } // The only one
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
211 else if(pt->parent) {
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
212 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
213 assert(pt->parent->child == pt);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
214 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
215 pt->parent->child = NULL;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
216 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
217
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
218 pt->prev = pt->next = pt->parent = NULL;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
219 if(free_it)
23872
4d936284a5ec typo fix: childs --> children
diego
parents: 23614
diff changeset
220 play_tree_free(pt,with_children);
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
221
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
222 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
223
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
224 void
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
225 play_tree_set_child(play_tree_t* pt, play_tree_t* child) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
226 play_tree_t* iter;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
227
31879
253f7779fe98 sanity check to avoid a segmentation fault in playtree.c on empty playlists.
siretart
parents: 31320
diff changeset
228 /* Roughly validate input data. Both, pt and child are going to be
253f7779fe98 sanity check to avoid a segmentation fault in playtree.c on empty playlists.
siretart
parents: 31320
diff changeset
229 * dereferenced, hence assure they're not NULL.
253f7779fe98 sanity check to avoid a segmentation fault in playtree.c on empty playlists.
siretart
parents: 31320
diff changeset
230 */
253f7779fe98 sanity check to avoid a segmentation fault in playtree.c on empty playlists.
siretart
parents: 31320
diff changeset
231 if (!pt || !child) {
253f7779fe98 sanity check to avoid a segmentation fault in playtree.c on empty playlists.
siretart
parents: 31320
diff changeset
232 mp_msg(MSGT_PLAYTREE, MSGL_ERR, "Internal error, attempt to add an empty child or use empty playlist\n");
253f7779fe98 sanity check to avoid a segmentation fault in playtree.c on empty playlists.
siretart
parents: 31320
diff changeset
233 return;
253f7779fe98 sanity check to avoid a segmentation fault in playtree.c on empty playlists.
siretart
parents: 31320
diff changeset
234 }
253f7779fe98 sanity check to avoid a segmentation fault in playtree.c on empty playlists.
siretart
parents: 31320
diff changeset
235
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
236 #ifdef MP_DEBUG
4220
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
237 assert(pt->entry_type == PLAY_TREE_ENTRY_NODE);
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
238 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
239
23872
4d936284a5ec typo fix: childs --> children
diego
parents: 23614
diff changeset
240 //DEBUG_FF: Where are the children freed?
9290
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
241 // Attention in using this function!
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
242 for(iter = pt->child ; iter != NULL ; iter = iter->next)
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
243 iter->parent = NULL;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
244
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
245 // Go back to first one
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
246 for(iter = child ; iter->prev != NULL ; iter = iter->prev)
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
247 /* NOTHING */;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
248
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
249 pt->child = iter;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
250
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
251 for( ; iter != NULL ; iter= iter->next)
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
252 iter->parent = pt;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
253
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
254 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
255
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
256 void
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
257 play_tree_set_parent(play_tree_t* pt, play_tree_t* parent) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
258 play_tree_t* iter;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
259
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
260 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
261 assert(pt != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
262 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
263
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
264 if(pt->parent)
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
265 pt->parent->child = NULL;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
266
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
267 for(iter = pt ; iter != NULL ; iter = iter->next)
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
268 iter->parent = parent;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
269
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
270 if(pt->prev) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
271 for(iter = pt->prev ; iter->prev != NULL ; iter = iter->prev)
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
272 iter->parent = parent;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
273 iter->parent = parent;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
274 parent->child = iter;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
275 } else
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
276 parent->child = pt;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
277
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
278 }
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
279
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
280
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
281 void
33520
2df1a5fee8a7 Mark some char * arguments that are strdup'd const,
reimar
parents: 33519
diff changeset
282 play_tree_add_file(play_tree_t* pt,const char* file) {
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
283 int n = 0;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
284
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
285 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
286 assert(pt != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
287 assert(pt->child == NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
288 assert(file != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
289 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
290
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
291 if(pt->entry_type != PLAY_TREE_ENTRY_NODE &&
4220
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
292 pt->entry_type != PLAY_TREE_ENTRY_FILE)
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
293 return;
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
294
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
295 if(pt->files) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
296 for(n = 0 ; pt->files[n] != NULL ; n++)
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
297 /* NOTHING */;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
298 }
30702
9fc9d1e788aa Do not cast the results of malloc/calloc/realloc.
diego
parents: 30590
diff changeset
299 pt->files = realloc(pt->files, (n + 2) * sizeof(char*));
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
300 if(pt->files ==NULL) {
23614
bab9e6c606cc Cast sizeof() to int in mp_msg arguments so it fits the format string on 64bit
reimar
parents: 18886
diff changeset
301 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",(n+2)*(int)sizeof(char*));
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
302 return;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
303 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
304
33278
679b4e6d506c Remove unused variable.
reimar
parents: 33277
diff changeset
305 pt->files[n] = strdup(file);
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
306 pt->files[n+1] = NULL;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
307
9748
f74f8b809697 Use new config headers
albeu
parents: 9290
diff changeset
308 pt->entry_type = PLAY_TREE_ENTRY_FILE;
4220
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
309
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
310 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
311
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
312 int
33520
2df1a5fee8a7 Mark some char * arguments that are strdup'd const,
reimar
parents: 33519
diff changeset
313 play_tree_remove_file(play_tree_t* pt,const char* file) {
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
314 int n,f = -1;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
315
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
316 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
317 assert(pt != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
318 assert(file != NULL);
4220
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
319 assert(pt->entry_type != PLAY_TREE_ENTRY_NODE);
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
320 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
321
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
322 for(n=0 ; pt->files[n] != NULL ; n++) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
323 if(strcmp(file,pt->files[n]) == 0)
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
324 f = n;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
325 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
326
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
327 if(f < 0) // Not found
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
328 return 0;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
329
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
330 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
331 assert(n > f);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
332 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
333
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
334 free(pt->files[f]);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
335
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
336 if(n > 1) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
337 memmove(&pt->files[f],&pt->files[f+1],(n-f)*sizeof(char*));
30702
9fc9d1e788aa Do not cast the results of malloc/calloc/realloc.
diego
parents: 30590
diff changeset
338 pt->files = realloc(pt->files, n * sizeof(char*));
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
339 if(pt->files == NULL) {
23614
bab9e6c606cc Cast sizeof() to int in mp_msg arguments so it fits the format string on 64bit
reimar
parents: 18886
diff changeset
340 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",(n+2)*(int)sizeof(char*));
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
341 return -1;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
342 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
343 } else {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
344 free(pt->files);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
345 pt->files = NULL;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
346 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
347
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
348 return 1;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
349 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
350
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
351 void
33520
2df1a5fee8a7 Mark some char * arguments that are strdup'd const,
reimar
parents: 33519
diff changeset
352 play_tree_set_param(play_tree_t* pt, const char* name, const char* val) {
29726
0d05687720a9 Remove redundant duplicate option handling in the playtree.
adrian
parents: 29263
diff changeset
353 int n = 0;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
354
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
355 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
356 assert(pt != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
357 assert(name != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
358 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
359
29726
0d05687720a9 Remove redundant duplicate option handling in the playtree.
adrian
parents: 29263
diff changeset
360 if(pt->params)
0d05687720a9 Remove redundant duplicate option handling in the playtree.
adrian
parents: 29263
diff changeset
361 for ( ; pt->params[n].name != NULL ; n++ ) { }
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
362
30702
9fc9d1e788aa Do not cast the results of malloc/calloc/realloc.
diego
parents: 30590
diff changeset
363 pt->params = realloc(pt->params, (n + 2) * sizeof(play_tree_param_t));
9290
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
364 if(pt->params == NULL) {
23614
bab9e6c606cc Cast sizeof() to int in mp_msg arguments so it fits the format string on 64bit
reimar
parents: 18886
diff changeset
365 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't realloc params (%d bytes of memory)\n",(n+2)*(int)sizeof(play_tree_param_t));
9290
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
366 return;
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
367 }
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
368 pt->params[n].name = strdup(name);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
369 pt->params[n].value = val != NULL ? strdup(val) : NULL;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
370 memset(&pt->params[n+1],0,sizeof(play_tree_param_t));
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
371
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
372 return;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
373 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
374
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
375 int
33520
2df1a5fee8a7 Mark some char * arguments that are strdup'd const,
reimar
parents: 33519
diff changeset
376 play_tree_unset_param(play_tree_t* pt, const char* name) {
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
377 int n,ni = -1;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
378
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
379 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
380 assert(pt != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
381 assert(name != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
382 assert(pt->params != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
383 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
384
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
385 for(n = 0 ; pt->params[n].name != NULL ; n++) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
386 if(strcasecmp(pt->params[n].name,name) == 0)
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
387 ni = n;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
388 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
389
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
390 if(ni < 0)
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
391 return 0;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
392
32511
b39155e98ac3 Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents: 31879
diff changeset
393 free(pt->params[ni].name);
b39155e98ac3 Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents: 31879
diff changeset
394 free(pt->params[ni].value);
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
395
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
396 if(n > 1) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
397 memmove(&pt->params[ni],&pt->params[ni+1],(n-ni)*sizeof(play_tree_param_t));
30702
9fc9d1e788aa Do not cast the results of malloc/calloc/realloc.
diego
parents: 30590
diff changeset
398 pt->params = realloc(pt->params, n * sizeof(play_tree_param_t));
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
399 if(pt->params == NULL) {
23614
bab9e6c606cc Cast sizeof() to int in mp_msg arguments so it fits the format string on 64bit
reimar
parents: 18886
diff changeset
400 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",n*(int)sizeof(play_tree_param_t));
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
401 return -1;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
402 }
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
403 } else {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
404 free(pt->params);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
405 pt->params = NULL;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
406 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
407
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
408 return 1;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
409 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
410
5217
3e7152b383ca Set the params given to a playlist url to the playlist
albeu
parents: 4974
diff changeset
411 void
3e7152b383ca Set the params given to a playlist url to the playlist
albeu
parents: 4974
diff changeset
412 play_tree_set_params_from(play_tree_t* dest,play_tree_t* src) {
3e7152b383ca Set the params given to a playlist url to the playlist
albeu
parents: 4974
diff changeset
413 int i;
3e7152b383ca Set the params given to a playlist url to the playlist
albeu
parents: 4974
diff changeset
414
3e7152b383ca Set the params given to a playlist url to the playlist
albeu
parents: 4974
diff changeset
415 #ifdef MP_DEBUG
3e7152b383ca Set the params given to a playlist url to the playlist
albeu
parents: 4974
diff changeset
416 assert(dest != NULL);
3e7152b383ca Set the params given to a playlist url to the playlist
albeu
parents: 4974
diff changeset
417 assert(src != NULL);
3e7152b383ca Set the params given to a playlist url to the playlist
albeu
parents: 4974
diff changeset
418 #endif
3e7152b383ca Set the params given to a playlist url to the playlist
albeu
parents: 4974
diff changeset
419
3e7152b383ca Set the params given to a playlist url to the playlist
albeu
parents: 4974
diff changeset
420 if(!src->params)
3e7152b383ca Set the params given to a playlist url to the playlist
albeu
parents: 4974
diff changeset
421 return;
3e7152b383ca Set the params given to a playlist url to the playlist
albeu
parents: 4974
diff changeset
422
3e7152b383ca Set the params given to a playlist url to the playlist
albeu
parents: 4974
diff changeset
423 for(i = 0; src->params[i].name != NULL ; i++)
3e7152b383ca Set the params given to a playlist url to the playlist
albeu
parents: 4974
diff changeset
424 play_tree_set_param(dest,src->params[i].name,src->params[i].value);
10394
59982e3c403b Fix -shuffle with remote playlist
albeu
parents: 9748
diff changeset
425 if(src->flags & PLAY_TREE_RND) // pass the random flag too
59982e3c403b Fix -shuffle with remote playlist
albeu
parents: 9748
diff changeset
426 dest->flags |= PLAY_TREE_RND;
5217
3e7152b383ca Set the params given to a playlist url to the playlist
albeu
parents: 4974
diff changeset
427
3e7152b383ca Set the params given to a playlist url to the playlist
albeu
parents: 4974
diff changeset
428 }
3e7152b383ca Set the params given to a playlist url to the playlist
albeu
parents: 4974
diff changeset
429
30590
d218228dc74d Mark some more functions that are not used outside of their files as static.
diego
parents: 30429
diff changeset
430 static void
8174
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
431 play_tree_unset_flag(play_tree_t* pt, int flags , int deep) {
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
432 play_tree_t* i;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
433
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
434 pt->flags &= ~flags;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
435
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
436 if(deep && pt->child) {
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
437 if(deep > 0) deep--;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
438 for(i = pt->child ; i ; i = i->next)
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
439 play_tree_unset_flag(i,flags,deep);
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
440 }
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
441 }
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
442
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
443
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
444 //////////////////////////////////// ITERATOR //////////////////////////////////////
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
445
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
446 static void
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
447 play_tree_iter_push_params(play_tree_iter_t* iter) {
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
448 int n;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
449 play_tree_t* pt;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
450 #ifdef MP_DEBUG
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
451 assert(iter != NULL);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
452 assert(iter->config != NULL);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
453 assert(iter->tree != NULL);
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
454 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
455
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
456 pt = iter->tree;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
457
4268
83aedfde69f8 Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents: 4254
diff changeset
458 // We always push a config because we can set some option
83aedfde69f8 Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents: 4254
diff changeset
459 // while playing
83aedfde69f8 Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents: 4254
diff changeset
460 m_config_push(iter->config);
83aedfde69f8 Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents: 4254
diff changeset
461
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
462 if(pt->params == NULL)
4268
83aedfde69f8 Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents: 4254
diff changeset
463 return;
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
464
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
465
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
466 for(n = 0; pt->params[n].name != NULL ; n++) {
4292
1cee88ee8db5 Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents: 4268
diff changeset
467 int e;
1cee88ee8db5 Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents: 4268
diff changeset
468 if((e = m_config_set_option(iter->config,pt->params[n].name,pt->params[n].value)) < 0) {
1cee88ee8db5 Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents: 4268
diff changeset
469 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Error %d while setting option '%s' with value '%s'\n",e,
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
470 pt->params[n].name,pt->params[n].value);
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
471 }
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
472 }
4220
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
473
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
474 if(!pt->child)
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
475 iter->entry_pushed = 1;
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
476 }
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
477
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
478 play_tree_iter_t*
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
479 play_tree_iter_new(play_tree_t* pt,m_config_t* config) {
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
480 play_tree_iter_t* iter;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
481
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
482 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
483 assert(pt != NULL);
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
484 assert(config != NULL);
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
485 #endif
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
486
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
487 if( ! play_tree_is_valid(pt))
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
488 return NULL;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
489
18879
cc65a585fdcc rm unnecesary casts from void* - part 3
reynaldo
parents: 18869
diff changeset
490 iter = calloc(1,sizeof(play_tree_iter_t));
9290
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
491 if(! iter) {
23614
bab9e6c606cc Cast sizeof() to int in mp_msg arguments so it fits the format string on 64bit
reimar
parents: 18886
diff changeset
492 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate new iterator (%d bytes of memory)\n",(int)sizeof(play_tree_iter_t));
9290
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
493 return NULL;
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
494 }
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
495 iter->root = pt;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
496 iter->tree = NULL;
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
497 iter->config = config;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
498
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
499 if(pt->parent)
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
500 iter->loop = pt->parent->loop;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
501
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
502 return iter;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
503 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
504
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
505 void
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
506 play_tree_iter_free(play_tree_iter_t* iter) {
4960
d3d05270c09d workaround for gui a short time.
pontscho
parents: 4781
diff changeset
507
33482
7e41f14e7778 Fix segmentation fault when pressing U (stop playing) in GUI.
ib
parents: 33278
diff changeset
508 if (!iter) return;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
509
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
510 if(iter->status_stack) {
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
511 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
512 assert(iter->stack_size > 0);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
513 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
514 free(iter->status_stack);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
515 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
516
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
517 free(iter);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
518 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
519
8174
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
520 static play_tree_t*
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
521 play_tree_rnd_step(play_tree_t* pt) {
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
522 int count = 0;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
523 int r;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
524 play_tree_t *i,*head;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
525
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
526 // Count how many free choice we have
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
527 for(i = pt ; i->prev ; i = i->prev)
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
528 if(!(i->flags & PLAY_TREE_RND_PLAYED)) count++;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
529 head = i;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
530 if(!(i->flags & PLAY_TREE_RND_PLAYED)) count++;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
531 for(i = pt->next ; i ; i = i->next)
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
532 if(!(i->flags & PLAY_TREE_RND_PLAYED)) count++;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
533
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
534 if(!count) return NULL;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
535
13884
a6b4bfa42178 fix "last file is always played last" bug.
reimar
parents: 13708
diff changeset
536 r = (int)((float)(count) * rand() / (RAND_MAX + 1.0));
8174
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
537
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
538 for(i = head ; i ; i=i->next) {
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
539 if(!(i->flags & PLAY_TREE_RND_PLAYED)) r--;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
540 if(r < 0) return i;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
541 }
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
542
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
543 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Random stepping error\n");
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
544 return NULL;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
545 }
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
546
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
547
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
548 int
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
549 play_tree_iter_step(play_tree_iter_t* iter, int d,int with_nodes) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
550 play_tree_t* pt;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
551
5651
b8d8d72776f2 fix playlist bug with gui and rewrite mousecursor show/hide code
pontscho
parents: 5217
diff changeset
552 if ( !iter ) return PLAY_TREE_ITER_ENTRY;
b8d8d72776f2 fix playlist bug with gui and rewrite mousecursor show/hide code
pontscho
parents: 5217
diff changeset
553 if ( !iter->root ) return PLAY_TREE_ITER_ENTRY;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
554
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
555 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
556 assert(iter != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
557 assert(iter->root != NULL);
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
558 //printf("PT : Stepping = %d\n",d);
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
559 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
560
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
561 if(iter->tree == NULL) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
562 iter->tree = iter->root;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
563 return play_tree_iter_step(iter,0,with_nodes);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
564 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
565
4268
83aedfde69f8 Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents: 4254
diff changeset
566 if(iter->config && iter->entry_pushed > 0) {
4781
e370779ac77f In the good way this time, (1 and 0 was swaped 10*10^10l for me ;))
albeu
parents: 4768
diff changeset
567 iter->entry_pushed = 0;
4268
83aedfde69f8 Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents: 4254
diff changeset
568 m_config_pop(iter->config);
83aedfde69f8 Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents: 4254
diff changeset
569 }
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
570
8174
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
571 if(iter->tree->parent && (iter->tree->parent->flags & PLAY_TREE_RND))
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
572 iter->mode = PLAY_TREE_ITER_RND;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
573 else
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
574 iter->mode = PLAY_TREE_ITER_NORMAL;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
575
4220
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
576 iter->file = -1;
8174
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
577 if(iter->mode == PLAY_TREE_ITER_RND)
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
578 pt = play_tree_rnd_step(iter->tree);
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
579 else if( d > 0 ) {
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
580 int i;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
581 pt = iter->tree;
8174
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
582 for(i = d ; i > 0 && pt ; i--)
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
583 pt = pt->next;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
584 d = i ? i : 1;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
585 } else if(d < 0) {
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
586 int i;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
587 pt = iter->tree;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
588 for(i = d ; i < 0 && pt ; i++)
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
589 pt = pt->prev;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
590 d = i ? i : -1;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
591 } else
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
592 pt = iter->tree;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
593
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
594 if(pt == NULL) { // No next
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
595 // Must we loop?
13708
c29255ab4712 fix -loop in combination with -shuffle
reimar
parents: 12646
diff changeset
596 if (iter->mode == PLAY_TREE_ITER_RND) {
c29255ab4712 fix -loop in combination with -shuffle
reimar
parents: 12646
diff changeset
597 if (iter->root->loop == 0)
c29255ab4712 fix -loop in combination with -shuffle
reimar
parents: 12646
diff changeset
598 return PLAY_TREE_ITER_END;
c29255ab4712 fix -loop in combination with -shuffle
reimar
parents: 12646
diff changeset
599 play_tree_unset_flag(iter->root, PLAY_TREE_RND_PLAYED, -1);
c29255ab4712 fix -loop in combination with -shuffle
reimar
parents: 12646
diff changeset
600 if (iter->root->loop > 0) iter->root->loop--;
c29255ab4712 fix -loop in combination with -shuffle
reimar
parents: 12646
diff changeset
601 // try again
c29255ab4712 fix -loop in combination with -shuffle
reimar
parents: 12646
diff changeset
602 return play_tree_iter_step(iter, 0, with_nodes);
c29255ab4712 fix -loop in combination with -shuffle
reimar
parents: 12646
diff changeset
603 } else
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
604 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) ) ) ) {
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
605 if(d > 0) { // Go back to the first one
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
606 for(pt = iter->tree ; pt->prev != NULL; pt = pt->prev)
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
607 /* NOTHNG */;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
608 if(iter->loop > 0) iter->loop--;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
609 } else if( d < 0 ) { // Or the last one
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
610 for(pt = iter->tree ; pt->next != NULL; pt = pt->next)
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
611 /* NOTHNG */;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
612 if(iter->loop >= 0 && iter->loop < iter->tree->parent->loop) iter->loop++;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
613 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
614 iter->tree = pt;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
615 return play_tree_iter_step(iter,0,with_nodes);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
616 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
617 // Go up one level
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
618 return play_tree_iter_up_step(iter,d,with_nodes);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
619
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
620 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
621
23872
4d936284a5ec typo fix: childs --> children
diego
parents: 23614
diff changeset
622 // Is there any valid child?
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
623 if(pt->child && play_tree_is_valid(pt->child)) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
624 iter->tree = pt;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
625 if(with_nodes) { // Stop on the node
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
626 return PLAY_TREE_ITER_NODE;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
627 } else // Or follow it
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
628 return play_tree_iter_down_step(iter,d,with_nodes);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
629 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
630
23872
4d936284a5ec typo fix: childs --> children
diego
parents: 23614
diff changeset
631 // Is it a valid entry?
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
632 if(! play_tree_is_valid(pt)) {
9290
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
633 if(d == 0) { // Can this happen ? FF: Yes!
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
634 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"What to do now ???? Infinite loop if we continue\n");
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
635 return PLAY_TREE_ITER_ERROR;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
636 } // Not a valid entry : go to next one
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
637 return play_tree_iter_step(iter,d,with_nodes);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
638 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
639
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
640 #ifdef MP_DEBUG
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
641 assert(pt->files != NULL);
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
642 #endif
4220
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
643
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
644 iter->tree = pt;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
645
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
646 for(d = 0 ; iter->tree->files[d] != NULL ; d++)
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
647 /* NOTHING */;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
648 iter->num_files = d;
4220
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
649
4268
83aedfde69f8 Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents: 4254
diff changeset
650 if(iter->config) {
4220
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
651 play_tree_iter_push_params(iter);
4781
e370779ac77f In the good way this time, (1 and 0 was swaped 10*10^10l for me ;))
albeu
parents: 4768
diff changeset
652 iter->entry_pushed = 1;
8174
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
653 if(iter->mode == PLAY_TREE_ITER_RND)
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
654 pt->flags |= PLAY_TREE_RND_PLAYED;
4268
83aedfde69f8 Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents: 4254
diff changeset
655 }
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
656
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
657 return PLAY_TREE_ITER_ENTRY;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
658
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
659 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
660
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
661 static int
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
662 play_tree_is_valid(play_tree_t* pt) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
663 play_tree_t* iter;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
664
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
665 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
666 assert(pt != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
667 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
668
4220
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
669 if(pt->entry_type != PLAY_TREE_ENTRY_NODE) {
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
670 #ifdef MP_DEBUG
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
671 assert(pt->child == NULL);
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
672 #endif
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
673 return 1;
4220
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
674 }
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
675 else if (pt->child != NULL) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
676 for(iter = pt->child ; iter != NULL ; iter = iter->next) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
677 if(play_tree_is_valid(iter))
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
678 return 1;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
679 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
680 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
681 return 0;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
682 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
683
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
684 int
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
685 play_tree_iter_up_step(play_tree_iter_t* iter, int d,int with_nodes) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
686
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
687 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
688 assert(iter != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
689 assert(iter->tree != NULL);
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
690 //printf("PT : Go UP\n");
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
691 #endif
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
692
4220
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
693 iter->file = -1;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
694 if(iter->tree->parent == iter->root->parent)
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
695 return PLAY_TREE_ITER_END;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
696
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
697 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
698 assert(iter->tree->parent != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
699 assert(iter->stack_size > 0);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
700 assert(iter->status_stack != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
701 #endif
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
702
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
703 iter->stack_size--;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
704 iter->loop = iter->status_stack[iter->stack_size];
5802
35f19046f809 Portability fix with realloc
albeu
parents: 5651
diff changeset
705 if(iter->stack_size > 0)
30702
9fc9d1e788aa Do not cast the results of malloc/calloc/realloc.
diego
parents: 30590
diff changeset
706 iter->status_stack = realloc(iter->status_stack, iter->stack_size * sizeof(int));
5802
35f19046f809 Portability fix with realloc
albeu
parents: 5651
diff changeset
707 else {
35f19046f809 Portability fix with realloc
albeu
parents: 5651
diff changeset
708 free(iter->status_stack);
35f19046f809 Portability fix with realloc
albeu
parents: 5651
diff changeset
709 iter->status_stack = NULL;
35f19046f809 Portability fix with realloc
albeu
parents: 5651
diff changeset
710 }
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
711 if(iter->stack_size > 0 && iter->status_stack == NULL) {
23614
bab9e6c606cc Cast sizeof() to int in mp_msg arguments so it fits the format string on 64bit
reimar
parents: 18886
diff changeset
712 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",iter->stack_size*(int)sizeof(char*));
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
713 return PLAY_TREE_ITER_ERROR;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
714 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
715 iter->tree = iter->tree->parent;
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
716
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
717 // Pop subtree params
27088
26c73d63f619 revert non-acked r27106
ben
parents: 27074
diff changeset
718 if(iter->config) {
4268
83aedfde69f8 Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents: 4254
diff changeset
719 m_config_pop(iter->config);
8174
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
720 if(iter->mode == PLAY_TREE_ITER_RND)
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
721 iter->tree->flags |= PLAY_TREE_RND_PLAYED;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
722 }
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
723
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
724 return play_tree_iter_step(iter,d,with_nodes);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
725 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
726
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
727 int
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
728 play_tree_iter_down_step(play_tree_iter_t* iter, int d,int with_nodes) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
729
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
730 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
731 assert(iter->tree->files == NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
732 assert(iter->tree->child != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
733 assert(iter->tree->child->parent == iter->tree);
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
734 //printf("PT : Go DOWN\n");
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
735 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
736
4220
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
737 iter->file = -1;
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
738
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
739 // Push subtree params
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
740 if(iter->config)
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
741 play_tree_iter_push_params(iter);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
742
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
743 iter->stack_size++;
30702
9fc9d1e788aa Do not cast the results of malloc/calloc/realloc.
diego
parents: 30590
diff changeset
744 iter->status_stack = realloc(iter->status_stack, iter->stack_size * sizeof(int));
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
745 if(iter->status_stack == NULL) {
23614
bab9e6c606cc Cast sizeof() to int in mp_msg arguments so it fits the format string on 64bit
reimar
parents: 18886
diff changeset
746 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",iter->stack_size*(int)sizeof(int));
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
747 return PLAY_TREE_ITER_ERROR;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
748 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
749 iter->status_stack[iter->stack_size-1] = iter->loop;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
750 // Set new status
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
751 iter->loop = iter->tree->loop-1;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
752 if(d >= 0)
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
753 iter->tree = iter->tree->child;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
754 else {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
755 play_tree_t* pt;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
756 for(pt = iter->tree->child ; pt->next != NULL ; pt = pt->next)
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
757 /*NOTING*/;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
758 iter->tree = pt;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
759 }
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
760
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
761 return play_tree_iter_step(iter,0,with_nodes);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
762 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
763
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
764 char*
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
765 play_tree_iter_get_file(play_tree_iter_t* iter, int d) {
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
766 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
767 assert(iter != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
768 assert(iter->tree->child == NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
769 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
770
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
771 if(iter->tree->files == NULL)
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
772 return NULL;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
773
4220
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
774 #ifdef MP_DEBUG
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
775 assert(iter->num_files > 0);
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
776 #endif
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
777
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
778 if(iter->file >= iter->num_files-1 || iter->file < -1)
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
779 return NULL;
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
780
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
781 if(d > 0) {
4220
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
782 if(iter->file >= iter->num_files - 1)
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
783 iter->file = 0;
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
784 else
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
785 iter->file++;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
786 } else if(d < 0) {
4220
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
787 if(iter->file <= 0)
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
788 iter->file = iter->num_files - 1;
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
789 else
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
790 iter->file--;
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
791 }
9748
f74f8b809697 Use new config headers
albeu
parents: 9290
diff changeset
792 return iter->tree->files[iter->file];
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
793 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
794
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
795 play_tree_t*
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
796 play_tree_cleanup(play_tree_t* pt) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
797 play_tree_t* iter, *tmp, *first;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
798
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
799 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
800 assert(pt != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
801 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
802
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
803 if( ! play_tree_is_valid(pt)) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
804 play_tree_remove(pt,1,1);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
805 return NULL;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
806 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
807
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
808 first = pt->child;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
809
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
810 for(iter = pt->child ; iter != NULL ; ) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
811 tmp = iter;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
812 iter = iter->next;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
813 if(! play_tree_is_valid(tmp)) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
814 play_tree_remove(tmp,1,1);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
815 if(tmp == first) first = iter;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
816 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
817 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
818
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
819 for(iter = first ; iter != NULL ; ) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
820 tmp = iter;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
821 iter = iter->next;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
822 play_tree_cleanup(tmp);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
823 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
824
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
825 return pt;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
826
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
827 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
828
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
829 play_tree_iter_t*
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
830 play_tree_iter_new_copy(play_tree_iter_t* old) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
831 play_tree_iter_t* iter;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
832
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
833 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
834 assert(old != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
835 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
836
18869
682a16136d6c rm unnecesary void* casts - part 1
reynaldo
parents: 18265
diff changeset
837 iter = malloc(sizeof(play_tree_iter_t));
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
838 if(iter == NULL) {
23614
bab9e6c606cc Cast sizeof() to int in mp_msg arguments so it fits the format string on 64bit
reimar
parents: 18886
diff changeset
839 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",(int)sizeof(play_tree_iter_t));
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
840 return NULL;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
841 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
842 ;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
843 memcpy(iter,old,sizeof(play_tree_iter_t));
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
844 if(old->status_stack) {
18869
682a16136d6c rm unnecesary void* casts - part 1
reynaldo
parents: 18265
diff changeset
845 iter->status_stack = malloc(old->stack_size * sizeof(int));
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
846 if(iter->status_stack == NULL) {
23614
bab9e6c606cc Cast sizeof() to int in mp_msg arguments so it fits the format string on 64bit
reimar
parents: 18886
diff changeset
847 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",old->stack_size * (int)sizeof(int));
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
848 free(iter);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
849 return NULL;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
850 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
851 memcpy(iter->status_stack,old->status_stack,iter->stack_size*sizeof(int));
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
852 }
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
853 iter->config = NULL;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
854
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
855 return iter;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
856 }
4220
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
857
9290
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
858 // HIGH Level API, by Fabian Franz (mplayer@fabian-franz.de)
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
859 //
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
860 play_tree_iter_t* pt_iter_create(play_tree_t** ppt, m_config_t* config)
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
861 {
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
862 play_tree_iter_t* r=NULL;
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
863 #ifdef MP_DEBUG
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
864 assert(*ppt!=NULL);
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
865 #endif
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
866
9290
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
867 *ppt=play_tree_cleanup(*ppt);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
868
9290
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
869 if(*ppt) {
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
870 r = play_tree_iter_new(*ppt,config);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
871 if (r && play_tree_iter_step(r,0,0) != PLAY_TREE_ITER_ENTRY)
9290
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
872 {
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
873 play_tree_iter_free(r);
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
874 r = NULL;
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
875 }
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
876 }
4220
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
877
9290
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
878 return r;
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
879 }
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
880
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
881 void pt_iter_destroy(play_tree_iter_t** iter)
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
882 {
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
883 if (iter && *iter)
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
884 {
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
885 free(*iter);
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
886 iter=NULL;
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
887 }
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
888 }
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
889
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
890 char* pt_iter_get_file(play_tree_iter_t* iter, int d)
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
891 {
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
892 int i=0;
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
893 char* r;
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
894
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
895 if (iter==NULL)
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
896 return NULL;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
897
9290
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
898 r = play_tree_iter_get_file(iter,d);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
899
9290
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
900 while (!r && d!=0)
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
901 {
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
902 if (play_tree_iter_step(iter,d,0) != PLAY_TREE_ITER_ENTRY)
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
903 break;
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
904 r=play_tree_iter_get_file(iter,d);
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
905 i++;
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
906 }
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
907
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
908 return r;
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
909 }
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
910
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
911 void pt_iter_insert_entry(play_tree_iter_t* iter, play_tree_t* entry)
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
912 {
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
913 play_tree_t *pt = iter->tree;
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
914 #ifdef MP_DEBUG
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
915 assert(pt!=NULL);
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
916 assert(entry!=NULL);
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
917 assert(entry!=pt);
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
918 #endif
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
919
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
920 play_tree_insert_entry(pt, entry);
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
921 play_tree_set_params_from(entry,pt);
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
922 }
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
923
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
924 void pt_iter_replace_entry(play_tree_iter_t* iter, play_tree_t* entry)
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
925 {
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
926 play_tree_t *pt = iter->tree;
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
927
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
928 pt_iter_insert_entry(iter, entry);
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
929 play_tree_remove(pt, 1, 1);
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
930 iter->tree=entry;
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
931 }
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
932
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
933 //Add a new file as a new entry
33520
2df1a5fee8a7 Mark some char * arguments that are strdup'd const,
reimar
parents: 33519
diff changeset
934 void pt_add_file(play_tree_t** ppt, const char* filename)
9290
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
935 {
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
936 play_tree_t *pt = *ppt, *entry = play_tree_new();
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
937 #ifdef MP_DEBUG
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
938 assert(entry!=NULL);
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
939 #endif
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
940
9290
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
941 play_tree_add_file(entry, filename);
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
942 if (pt)
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
943 play_tree_append_entry(pt, entry);
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
944 else
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
945 {
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
946 pt=entry;
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
947 *ppt=pt;
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
948 }
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
949 play_tree_set_params_from(entry,pt);
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
950 }
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
951
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
952 void pt_iter_goto_head(play_tree_iter_t* iter)
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
953 {
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
954 iter->tree=iter->root;
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
955 play_tree_iter_step(iter, 0, 0);
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
956 }