annotate playtree.c @ 29390:80c32e67306c

The Makefile variable names for external libraries in FFmpeg changed. Adapt their names in config.mak, closes Bugzilla #1513.
author diego
date Sun, 19 Jul 2009 21:09:00 +0000
parents 0f1b5b68af32
children 0d05687720a9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18265
1a14fde7680d Doxygen Attack! - Chapter 3
albeu
parents: 13884
diff changeset
1
1a14fde7680d Doxygen Attack! - Chapter 3
albeu
parents: 13884
diff changeset
2 /// \file
1a14fde7680d Doxygen Attack! - Chapter 3
albeu
parents: 13884
diff changeset
3 /// \ingroup Playtree
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
4
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
5 #include "config.h"
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
6 #include <stdlib.h>
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
7 #include <string.h>
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
8 #include <stdio.h>
4050
da61596bcd87 FreeBSD fix
nexus
parents: 4043
diff changeset
9 #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
10 #include <errno.h>
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
11 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
12 #include <assert.h>
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
13 #endif
9748
f74f8b809697 Use new config headers
albeu
parents: 9290
diff changeset
14 #include "m_config.h"
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
15 #include "playtree.h"
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
16 #include "mp_msg.h"
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
17
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
18 static int
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
19 play_tree_is_valid(play_tree_t* pt);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
20
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
21 play_tree_t*
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
22 play_tree_new(void) {
18879
cc65a585fdcc rm unnecesary casts from void* - part 3
reynaldo
parents: 18869
diff changeset
23 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
24 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
25 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
26 return NULL;
aac3629b180d Actually abort (return NULL) in the alloc-failure check in play_tree_new
reimar
parents: 27088
diff changeset
27 }
4220
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
28 r->entry_type = PLAY_TREE_ENTRY_NODE;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
29 return r;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
30 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
31
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
32 void
23872
4d936284a5ec typo fix: childs --> children
diego
parents: 23614
diff changeset
33 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
34 play_tree_t* iter;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
35
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
36 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
37 assert(pt != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
38 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
39
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
40 if(children) {
8062
ed2d3e7e7e36 10L found by jeroen dobbelaere <jeroen dot dobbelaere at acunia dot com>
albeu
parents: 5802
diff changeset
41 for(iter = pt->child; iter != NULL; ) {
ed2d3e7e7e36 10L found by jeroen dobbelaere <jeroen dot dobbelaere at acunia dot com>
albeu
parents: 5802
diff changeset
42 play_tree_t* nxt=iter->next;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
43 play_tree_free(iter,1);
8062
ed2d3e7e7e36 10L found by jeroen dobbelaere <jeroen dot dobbelaere at acunia dot com>
albeu
parents: 5802
diff changeset
44 iter = nxt;
ed2d3e7e7e36 10L found by jeroen dobbelaere <jeroen dot dobbelaere at acunia dot com>
albeu
parents: 5802
diff changeset
45 }
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
46 pt->child = NULL;
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 play_tree_remove(pt,0,0);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
50
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
51 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
52 iter->parent = NULL;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
53
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
54 //if(pt->params) free(pt->params);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
55 if(pt->files) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
56 int i;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
57 for(i = 0 ; pt->files[i] != NULL ; i++)
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
58 free(pt->files[i]);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
59 free(pt->files);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
60 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
61
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
62 free(pt);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
63 }
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 void
23872
4d936284a5ec typo fix: childs --> children
diego
parents: 23614
diff changeset
66 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
67 play_tree_t* iter;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
68
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
69 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
70 assert(pt != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
71 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
72
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
73 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
74 /* NOTHING */;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
75
8062
ed2d3e7e7e36 10L found by jeroen dobbelaere <jeroen dot dobbelaere at acunia dot com>
albeu
parents: 5802
diff changeset
76 while(iter) {
ed2d3e7e7e36 10L found by jeroen dobbelaere <jeroen dot dobbelaere at acunia dot com>
albeu
parents: 5802
diff changeset
77 play_tree_t* nxt = iter->next;
23872
4d936284a5ec typo fix: childs --> children
diego
parents: 23614
diff changeset
78 play_tree_free(iter, children);
8062
ed2d3e7e7e36 10L found by jeroen dobbelaere <jeroen dot dobbelaere at acunia dot com>
albeu
parents: 5802
diff changeset
79 iter = nxt;
ed2d3e7e7e36 10L found by jeroen dobbelaere <jeroen dot dobbelaere at acunia dot com>
albeu
parents: 5802
diff changeset
80 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
81
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
82
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
83 }
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 void
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
86 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
87 play_tree_t* iter;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
88
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
89 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
90 assert(pt != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
91 assert(entry != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
92 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
93
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
94 if(pt == entry)
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
95 return;
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->next != NULL ; iter = iter->next)
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
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
100 entry->parent = iter->parent;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
101 entry->prev = iter;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
102 entry->next = NULL;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
103 iter->next = entry;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
104 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
105
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
106 void
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
107 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
108 play_tree_t* iter;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
109
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
110 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
111 assert(pt != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
112 assert(entry != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
113 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
114
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
115 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
116 /* NOTHING */;
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 entry->prev = NULL;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
119 entry->next = iter;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
120 entry->parent = iter->parent;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
121
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
122 iter->prev = entry;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
123 if(entry->parent) {
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
124 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
125 assert(entry->parent->child == iter);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
126 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
127 entry->parent->child = 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
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
131 void
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
132 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
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 entry->parent = pt->parent;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
140 entry->prev = pt;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
141 if(pt->next) {
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
142 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
143 assert(pt->next->prev == pt);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
144 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
145 entry->next = pt->next;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
146 entry->next->prev = entry;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
147 } else
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
148 entry->next = NULL;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
149 pt->next = entry;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
150
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
151 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
152
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
153 void
23872
4d936284a5ec typo fix: childs --> children
diego
parents: 23614
diff changeset
154 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
155
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
156 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
157 assert(pt != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
158 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
159
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
160 // Middle of list
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
161 if(pt->prev && pt->next) {
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
162 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
163 assert(pt->prev->next == pt);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
164 assert(pt->next->prev == pt);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
165 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
166 pt->prev->next = pt->next;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
167 pt->next->prev = pt->prev;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
168 } // End of list
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
169 else if(pt->prev) {
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
170 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
171 assert(pt->prev->next == pt);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
172 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
173 pt->prev->next = NULL;
25489
52f6429a9ba7 typo: begining --> beginning
diego
parents: 23872
diff changeset
174 } // Beginning of list
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
175 else if(pt->next) {
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
176 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
177 assert(pt->next->prev == pt);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
178 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
179 pt->next->prev = NULL;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
180 if(pt->parent) {
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
181 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
182 assert(pt->parent->child == pt);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
183 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
184 pt->parent->child = pt->next;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
185 }
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
186 } // The only one
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
187 else if(pt->parent) {
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
188 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
189 assert(pt->parent->child == pt);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
190 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
191 pt->parent->child = NULL;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
192 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
193
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
194 pt->prev = pt->next = pt->parent = NULL;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
195 if(free_it)
23872
4d936284a5ec typo fix: childs --> children
diego
parents: 23614
diff changeset
196 play_tree_free(pt,with_children);
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
197
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
198 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
199
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
200 void
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
201 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
202 play_tree_t* iter;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
203
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
204 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
205 assert(pt != NULL);
4220
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
206 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
207 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
208
23872
4d936284a5ec typo fix: childs --> children
diego
parents: 23614
diff changeset
209 //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
210 // Attention in using this function!
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
211 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
212 iter->parent = NULL;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
213
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
214 // Go back to first one
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
215 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
216 /* NOTHING */;
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->child = iter;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
219
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
220 for( ; iter != NULL ; iter= iter->next)
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
221 iter->parent = pt;
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
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
225 void
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
226 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
227 play_tree_t* iter;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
228
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
229 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
230 assert(pt != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
231 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
232
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
233 if(pt->parent)
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
234 pt->parent->child = NULL;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
235
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
236 for(iter = pt ; iter != NULL ; iter = iter->next)
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
237 iter->parent = parent;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
238
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
239 if(pt->prev) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
240 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
241 iter->parent = parent;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
242 iter->parent = parent;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
243 parent->child = iter;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
244 } else
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
245 parent->child = pt;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
246
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
247 }
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
248
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
249
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
250 void
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
251 play_tree_add_file(play_tree_t* pt,char* file) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
252 int n = 0;
4220
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
253 char* e;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
254
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
255 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
256 assert(pt != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
257 assert(pt->child == NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
258 assert(file != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
259 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
260
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
261 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
262 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
263 return;
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
264
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
265 if(pt->files) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
266 for(n = 0 ; pt->files[n] != NULL ; n++)
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
267 /* NOTHING */;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
268 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
269 pt->files = (char**)realloc(pt->files,(n+2)*sizeof(char*));
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
270 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
271 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
272 return;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
273 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
274
4220
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
275 e = pt->files[n] = strdup(file);
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
276 pt->files[n+1] = NULL;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
277
9748
f74f8b809697 Use new config headers
albeu
parents: 9290
diff changeset
278 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
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
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
282 int
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
283 play_tree_remove_file(play_tree_t* pt,char* file) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
284 int n,f = -1;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
285
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
286 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
287 assert(pt != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
288 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
289 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
290 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
291
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
292 for(n=0 ; pt->files[n] != NULL ; n++) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
293 if(strcmp(file,pt->files[n]) == 0)
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
294 f = n;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
295 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
296
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
297 if(f < 0) // Not found
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
298 return 0;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
299
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
300 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
301 assert(n > f);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
302 #endif
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 free(pt->files[f]);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
305
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
306 if(n > 1) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
307 memmove(&pt->files[f],&pt->files[f+1],(n-f)*sizeof(char*));
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
308 pt->files = (char**)realloc(pt->files,n*sizeof(char*));
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
309 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
310 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
311 return -1;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
312 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
313 } else {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
314 free(pt->files);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
315 pt->files = NULL;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
316 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
317
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
318 return 1;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
319 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
320
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
321 void
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
322 play_tree_set_param(play_tree_t* pt, char* name, char* val) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
323 int n = 0,ni = -1;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
324
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
325 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
326 assert(pt != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
327 assert(name != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
328 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
329
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
330 if(pt->params) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
331 for( ; pt->params[n].name != NULL ; n++) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
332 if(strcasecmp(pt->params[n].name,name) == 0)
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
333 ni = n;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
334 }
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
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
337 if(ni > 0) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
338 if(pt->params[n].value != NULL) free(pt->params[n].value);
4254
f04c49aa2408 Few bug fix and improvment in config/playtree system
albeu
parents: 4220
diff changeset
339 pt->params[n].value = val != NULL ? strdup(val) : NULL;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
340 return;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
341 }
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 pt->params = (play_tree_param_t*)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
344 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
345 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
346 return;
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
347 }
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
348 pt->params[n].name = strdup(name);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
349 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
350 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
351
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
352 return;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
353 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
354
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
355 int
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
356 play_tree_unset_param(play_tree_t* pt, char* name) {
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
357 int n,ni = -1;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
358
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
359 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
360 assert(pt != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
361 assert(name != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
362 assert(pt->params != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
363 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
364
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
365 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
366 if(strcasecmp(pt->params[n].name,name) == 0)
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
367 ni = n;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
368 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
369
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
370 if(ni < 0)
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
371 return 0;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
372
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
373 if(pt->params[ni].name) free(pt->params[ni].name);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
374 if(pt->params[ni].value) free(pt->params[ni].value);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
375
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
376 if(n > 1) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
377 memmove(&pt->params[ni],&pt->params[ni+1],(n-ni)*sizeof(play_tree_param_t));
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
378 pt->params = (play_tree_param_t*)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
379 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
380 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
381 return -1;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
382 }
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
383 } else {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
384 free(pt->params);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
385 pt->params = NULL;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
386 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
387
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
388 return 1;
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
5217
3e7152b383ca Set the params given to a playlist url to the playlist
albeu
parents: 4974
diff changeset
391 void
3e7152b383ca Set the params given to a playlist url to the playlist
albeu
parents: 4974
diff changeset
392 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
393 int i;
3e7152b383ca Set the params given to a playlist url to the playlist
albeu
parents: 4974
diff changeset
394
3e7152b383ca Set the params given to a playlist url to the playlist
albeu
parents: 4974
diff changeset
395 #ifdef MP_DEBUG
3e7152b383ca Set the params given to a playlist url to the playlist
albeu
parents: 4974
diff changeset
396 assert(dest != NULL);
3e7152b383ca Set the params given to a playlist url to the playlist
albeu
parents: 4974
diff changeset
397 assert(src != NULL);
3e7152b383ca Set the params given to a playlist url to the playlist
albeu
parents: 4974
diff changeset
398 #endif
3e7152b383ca Set the params given to a playlist url to the playlist
albeu
parents: 4974
diff changeset
399
3e7152b383ca Set the params given to a playlist url to the playlist
albeu
parents: 4974
diff changeset
400 if(!src->params)
3e7152b383ca Set the params given to a playlist url to the playlist
albeu
parents: 4974
diff changeset
401 return;
3e7152b383ca Set the params given to a playlist url to the playlist
albeu
parents: 4974
diff changeset
402
3e7152b383ca Set the params given to a playlist url to the playlist
albeu
parents: 4974
diff changeset
403 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
404 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
405 if(src->flags & PLAY_TREE_RND) // pass the random flag too
59982e3c403b Fix -shuffle with remote playlist
albeu
parents: 9748
diff changeset
406 dest->flags |= PLAY_TREE_RND;
5217
3e7152b383ca Set the params given to a playlist url to the playlist
albeu
parents: 4974
diff changeset
407
3e7152b383ca Set the params given to a playlist url to the playlist
albeu
parents: 4974
diff changeset
408 }
3e7152b383ca Set the params given to a playlist url to the playlist
albeu
parents: 4974
diff changeset
409
23872
4d936284a5ec typo fix: childs --> children
diego
parents: 23614
diff changeset
410 // all children if deep < 0
8174
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
411 void
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
412 play_tree_set_flag(play_tree_t* pt, int flags , int deep) {
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
413 play_tree_t* i;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
414
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
415 pt->flags |= flags;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
416
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
417 if(deep && pt->child) {
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
418 if(deep > 0) deep--;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
419 for(i = pt->child ; i ; i = i->next)
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
420 play_tree_set_flag(i,flags,deep);
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
421 }
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
422 }
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
423
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
424 void
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
425 play_tree_unset_flag(play_tree_t* pt, int flags , int deep) {
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
426 play_tree_t* i;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
427
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
428 pt->flags &= ~flags;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
429
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
430 if(deep && pt->child) {
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
431 if(deep > 0) deep--;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
432 for(i = pt->child ; i ; i = i->next)
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
433 play_tree_unset_flag(i,flags,deep);
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
434 }
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
435 }
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
436
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
437
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
438 //////////////////////////////////// ITERATOR //////////////////////////////////////
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
439
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
440 static void
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
441 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
442 int n;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
443 play_tree_t* pt;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
444 #ifdef MP_DEBUG
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
445 assert(iter != NULL);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
446 assert(iter->config != NULL);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
447 assert(iter->tree != NULL);
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
448 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
449
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
450 pt = iter->tree;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
451
4268
83aedfde69f8 Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents: 4254
diff changeset
452 // 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
453 // while playing
83aedfde69f8 Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents: 4254
diff changeset
454 m_config_push(iter->config);
83aedfde69f8 Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents: 4254
diff changeset
455
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
456 if(pt->params == NULL)
4268
83aedfde69f8 Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents: 4254
diff changeset
457 return;
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
458
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
459
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
460 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
461 int e;
1cee88ee8db5 Bug fix for subconfig option. A -tv option containing the on parameter
albeu
parents: 4268
diff changeset
462 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
463 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
464 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
465 }
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
466 }
4220
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
467
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
468 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
469 iter->entry_pushed = 1;
4268
83aedfde69f8 Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents: 4254
diff changeset
470 return;
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
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
473 play_tree_iter_t*
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
474 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
475 play_tree_iter_t* iter;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
476
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
477 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
478 assert(pt != NULL);
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
479 assert(config != NULL);
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
480 #endif
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
481
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
482 if( ! play_tree_is_valid(pt))
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
483 return NULL;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
484
18879
cc65a585fdcc rm unnecesary casts from void* - part 3
reynaldo
parents: 18869
diff changeset
485 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
486 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
487 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
488 return NULL;
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
489 }
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
490 iter->root = pt;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
491 iter->tree = NULL;
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
492 iter->config = config;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
493
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
494 if(pt->parent)
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
495 iter->loop = pt->parent->loop;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
496
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
497 return iter;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
498 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
499
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
500 void
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
501 play_tree_iter_free(play_tree_iter_t* iter) {
4960
d3d05270c09d workaround for gui a short time.
pontscho
parents: 4781
diff changeset
502
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
503 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
504 assert(iter != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
505 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
506
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
507 if(iter->status_stack) {
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
508 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
509 assert(iter->stack_size > 0);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
510 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
511 free(iter->status_stack);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
512 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
513
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
514 free(iter);
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
8174
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
517 static play_tree_t*
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
518 play_tree_rnd_step(play_tree_t* pt) {
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
519 int count = 0;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
520 int r;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
521 play_tree_t *i,*head;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
522
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
523 // Count how many free choice we have
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
524 for(i = pt ; i->prev ; i = i->prev)
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
525 if(!(i->flags & PLAY_TREE_RND_PLAYED)) count++;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
526 head = i;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
527 if(!(i->flags & PLAY_TREE_RND_PLAYED)) count++;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
528 for(i = pt->next ; i ; i = i->next)
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
529 if(!(i->flags & PLAY_TREE_RND_PLAYED)) count++;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
530
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
531 if(!count) return NULL;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
532
13884
a6b4bfa42178 fix "last file is always played last" bug.
reimar
parents: 13708
diff changeset
533 r = (int)((float)(count) * rand() / (RAND_MAX + 1.0));
8174
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
534
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
535 for(i = head ; i ; i=i->next) {
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
536 if(!(i->flags & PLAY_TREE_RND_PLAYED)) r--;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
537 if(r < 0) return i;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
538 }
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
539
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
540 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Random stepping error\n");
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
541 return NULL;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
542 }
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
543
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
544
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
545 int
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
546 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
547 play_tree_t* pt;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
548
5651
b8d8d72776f2 fix playlist bug with gui and rewrite mousecursor show/hide code
pontscho
parents: 5217
diff changeset
549 if ( !iter ) return PLAY_TREE_ITER_ENTRY;
b8d8d72776f2 fix playlist bug with gui and rewrite mousecursor show/hide code
pontscho
parents: 5217
diff changeset
550 if ( !iter->root ) return PLAY_TREE_ITER_ENTRY;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
551
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
552 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
553 assert(iter != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
554 assert(iter->root != NULL);
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
555 //printf("PT : Stepping = %d\n",d);
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
556 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
557
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
558 if(iter->tree == NULL) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
559 iter->tree = iter->root;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
560 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
561 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
562
4268
83aedfde69f8 Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents: 4254
diff changeset
563 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
564 iter->entry_pushed = 0;
4268
83aedfde69f8 Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents: 4254
diff changeset
565 m_config_pop(iter->config);
83aedfde69f8 Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents: 4254
diff changeset
566 }
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
567
8174
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
568 if(iter->tree->parent && (iter->tree->parent->flags & PLAY_TREE_RND))
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
569 iter->mode = PLAY_TREE_ITER_RND;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
570 else
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
571 iter->mode = PLAY_TREE_ITER_NORMAL;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
572
4220
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
573 iter->file = -1;
8174
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
574 if(iter->mode == PLAY_TREE_ITER_RND)
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
575 pt = play_tree_rnd_step(iter->tree);
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
576 else if( d > 0 ) {
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
577 int i;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
578 pt = iter->tree;
8174
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
579 for(i = d ; i > 0 && pt ; i--)
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
580 pt = pt->next;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
581 d = i ? i : 1;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
582 } else if(d < 0) {
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
583 int i;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
584 pt = iter->tree;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
585 for(i = d ; i < 0 && pt ; i++)
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
586 pt = pt->prev;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
587 d = i ? i : -1;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
588 } else
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
589 pt = iter->tree;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
590
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
591 if(pt == NULL) { // No next
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
592 // Must we loop?
13708
c29255ab4712 fix -loop in combination with -shuffle
reimar
parents: 12646
diff changeset
593 if (iter->mode == PLAY_TREE_ITER_RND) {
c29255ab4712 fix -loop in combination with -shuffle
reimar
parents: 12646
diff changeset
594 if (iter->root->loop == 0)
c29255ab4712 fix -loop in combination with -shuffle
reimar
parents: 12646
diff changeset
595 return PLAY_TREE_ITER_END;
c29255ab4712 fix -loop in combination with -shuffle
reimar
parents: 12646
diff changeset
596 play_tree_unset_flag(iter->root, PLAY_TREE_RND_PLAYED, -1);
c29255ab4712 fix -loop in combination with -shuffle
reimar
parents: 12646
diff changeset
597 if (iter->root->loop > 0) iter->root->loop--;
c29255ab4712 fix -loop in combination with -shuffle
reimar
parents: 12646
diff changeset
598 // try again
c29255ab4712 fix -loop in combination with -shuffle
reimar
parents: 12646
diff changeset
599 return play_tree_iter_step(iter, 0, with_nodes);
c29255ab4712 fix -loop in combination with -shuffle
reimar
parents: 12646
diff changeset
600 } else
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
601 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
602 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
603 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
604 /* NOTHNG */;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
605 if(iter->loop > 0) iter->loop--;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
606 } else if( d < 0 ) { // Or the last one
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
607 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
608 /* NOTHNG */;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
609 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
610 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
611 iter->tree = pt;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
612 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
613 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
614 // Go up one level
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
615 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
616
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
617 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
618
23872
4d936284a5ec typo fix: childs --> children
diego
parents: 23614
diff changeset
619 // Is there any valid child?
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
620 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
621 iter->tree = pt;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
622 if(with_nodes) { // Stop on the node
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
623 return PLAY_TREE_ITER_NODE;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
624 } else // Or follow it
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
625 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
626 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
627
23872
4d936284a5ec typo fix: childs --> children
diego
parents: 23614
diff changeset
628 // Is it a valid entry?
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
629 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
630 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
631 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
632 return PLAY_TREE_ITER_ERROR;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
633 } // Not a valid entry : go to next one
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
634 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
635 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
636
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
637 #ifdef MP_DEBUG
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
638 assert(pt->files != NULL);
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
639 #endif
4220
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
640
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
641 iter->tree = pt;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
642
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
643 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
644 /* NOTHING */;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
645 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
646
4268
83aedfde69f8 Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents: 4254
diff changeset
647 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
648 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
649 iter->entry_pushed = 1;
8174
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
650 if(iter->mode == PLAY_TREE_ITER_RND)
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
651 pt->flags |= PLAY_TREE_RND_PLAYED;
4268
83aedfde69f8 Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents: 4254
diff changeset
652 }
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
653
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
654 return PLAY_TREE_ITER_ENTRY;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
655
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
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
658 static int
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
659 play_tree_is_valid(play_tree_t* pt) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
660 play_tree_t* iter;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
661
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
662 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
663 assert(pt != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
664 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
665
4220
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
666 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
667 #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
668 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
669 #endif
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
670 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
671 }
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
672 else if (pt->child != NULL) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
673 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
674 if(play_tree_is_valid(iter))
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
675 return 1;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
676 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
677 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
678 return 0;
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 int
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
682 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
683
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
684 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
685 assert(iter != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
686 assert(iter->tree != NULL);
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
687 //printf("PT : Go UP\n");
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
688 #endif
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
689
4220
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
690 iter->file = -1;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
691 if(iter->tree->parent == iter->root->parent)
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
692 return PLAY_TREE_ITER_END;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
693
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
694 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
695 assert(iter->tree->parent != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
696 assert(iter->stack_size > 0);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
697 assert(iter->status_stack != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
698 #endif
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
699
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
700 iter->stack_size--;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
701 iter->loop = iter->status_stack[iter->stack_size];
5802
35f19046f809 Portability fix with realloc
albeu
parents: 5651
diff changeset
702 if(iter->stack_size > 0)
35f19046f809 Portability fix with realloc
albeu
parents: 5651
diff changeset
703 iter->status_stack = (int*)realloc(iter->status_stack,iter->stack_size*sizeof(int));
35f19046f809 Portability fix with realloc
albeu
parents: 5651
diff changeset
704 else {
35f19046f809 Portability fix with realloc
albeu
parents: 5651
diff changeset
705 free(iter->status_stack);
35f19046f809 Portability fix with realloc
albeu
parents: 5651
diff changeset
706 iter->status_stack = NULL;
35f19046f809 Portability fix with realloc
albeu
parents: 5651
diff changeset
707 }
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
708 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
709 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
710 return PLAY_TREE_ITER_ERROR;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
711 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
712 iter->tree = iter->tree->parent;
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
713
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
714 // Pop subtree params
27088
26c73d63f619 revert non-acked r27106
ben
parents: 27074
diff changeset
715 if(iter->config) {
4268
83aedfde69f8 Some improvment and make -vcd -dvd options considered as playlist entry
albeu
parents: 4254
diff changeset
716 m_config_pop(iter->config);
8174
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
717 if(iter->mode == PLAY_TREE_ITER_RND)
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
718 iter->tree->flags |= PLAY_TREE_RND_PLAYED;
014e0ea85bdb Add random stepping support
albeu
parents: 8164
diff changeset
719 }
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
720
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
721 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
722 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
723
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
724 int
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
725 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
726
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
727 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
728 assert(iter->tree->files == NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
729 assert(iter->tree->child != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
730 assert(iter->tree->child->parent == iter->tree);
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
731 //printf("PT : Go DOWN\n");
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
732 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
733
4220
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
734 iter->file = -1;
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
735
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
736 // Push subtree params
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
737 if(iter->config)
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
738 play_tree_iter_push_params(iter);
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
739
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
740 iter->stack_size++;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
741 iter->status_stack = (int*)realloc(iter->status_stack,iter->stack_size*sizeof(int));
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
742 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
743 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
744 return PLAY_TREE_ITER_ERROR;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
745 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
746 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
747 // Set new status
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
748 iter->loop = iter->tree->loop-1;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
749 if(d >= 0)
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
750 iter->tree = iter->tree->child;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
751 else {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
752 play_tree_t* pt;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
753 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
754 /*NOTING*/;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
755 iter->tree = pt;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
756 }
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
757
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
758 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
759 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
760
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
761 char*
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
762 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
763 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
764 assert(iter != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
765 assert(iter->tree->child == NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
766 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
767
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
768 if(iter->tree->files == NULL)
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
769 return NULL;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
770
4220
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
771 #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
772 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
773 #endif
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
774
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
775 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
776 return NULL;
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
777
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
778 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
779 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
780 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
781 else
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
782 iter->file++;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
783 } 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
784 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
785 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
786 else
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
787 iter->file--;
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
788 }
9748
f74f8b809697 Use new config headers
albeu
parents: 9290
diff changeset
789 return iter->tree->files[iter->file];
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
790 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
791
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
792 play_tree_t*
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
793 play_tree_cleanup(play_tree_t* pt) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
794 play_tree_t* iter, *tmp, *first;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
795
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
796 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
797 assert(pt != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
798 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
799
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
800 if( ! play_tree_is_valid(pt)) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
801 play_tree_remove(pt,1,1);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
802 return NULL;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
803 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
804
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
805 first = pt->child;
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 for(iter = pt->child ; iter != NULL ; ) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
808 tmp = iter;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
809 iter = iter->next;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
810 if(! play_tree_is_valid(tmp)) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
811 play_tree_remove(tmp,1,1);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
812 if(tmp == first) first = iter;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
813 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
814 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
815
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
816 for(iter = first ; iter != NULL ; ) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
817 tmp = iter;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
818 iter = iter->next;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
819 play_tree_cleanup(tmp);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
820 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
821
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
822 return pt;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
823
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
824 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
825
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
826 play_tree_iter_t*
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
827 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
828 play_tree_iter_t* iter;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
829
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
830 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
831 assert(old != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
832 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
833
18869
682a16136d6c rm unnecesary void* casts - part 1
reynaldo
parents: 18265
diff changeset
834 iter = malloc(sizeof(play_tree_iter_t));
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
835 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
836 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
837 return NULL;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
838 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
839 ;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
840 memcpy(iter,old,sizeof(play_tree_iter_t));
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
841 if(old->status_stack) {
18869
682a16136d6c rm unnecesary void* casts - part 1
reynaldo
parents: 18265
diff changeset
842 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
843 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
844 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
845 free(iter);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
846 return NULL;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
847 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
848 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
849 }
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
850 iter->config = NULL;
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4050
diff changeset
851
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
852 return iter;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
853 }
4220
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
854
9290
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
855 // 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
856 //
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
857 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
858 {
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
859 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
860 #ifdef MP_DEBUG
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
861 assert(*ppt!=NULL);
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
862 #endif
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
863
9290
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
864 *ppt=play_tree_cleanup(*ppt);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
865
9290
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
866 if(*ppt) {
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
867 r = play_tree_iter_new(*ppt,config);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
868 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
869 {
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
870 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
871 r = NULL;
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 }
4220
fe2c20d52a25 Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
albeu
parents: 4156
diff changeset
874
9290
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
875 return r;
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
876 }
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
877
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
878 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
879 {
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
880 if (iter && *iter)
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
881 {
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
882 free(*iter);
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
883 iter=NULL;
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 }
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
886
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
887 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
888 {
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
889 int i=0;
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
890 char* r;
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 if (iter==NULL)
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
893 return NULL;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
894
9290
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
895 r = play_tree_iter_get_file(iter,d);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
896
9290
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
897 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
898 {
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
899 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
900 break;
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
901 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
902 i++;
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
903 }
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
904
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
905 return r;
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 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
909 {
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
910 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
911 #ifdef MP_DEBUG
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
912 assert(pt!=NULL);
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
913 assert(entry!=NULL);
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
914 assert(entry!=pt);
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
915 #endif
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
916
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
917 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
918 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
919 }
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
920
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
921 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
922 {
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
923 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
924
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
925 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
926 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
927 iter->tree=entry;
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
928 }
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
929
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
930 //Add a new file as a new entry
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
931 void pt_add_file(play_tree_t** ppt, char* filename)
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 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
934 #ifdef MP_DEBUG
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
935 assert(entry!=NULL);
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
936 #endif
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28320
diff changeset
937
9290
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
938 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
939 if (pt)
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
940 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
941 else
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
942 {
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
943 pt=entry;
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
944 *ppt=pt;
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 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
947 }
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 void pt_add_gui_file(play_tree_t** ppt, char* path, char* file)
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
950 {
12646
9a495bdc3a1e string handling security fixes
diego
parents: 10394
diff changeset
951 char* wholename = malloc(strlen(path)+strlen(file)+2);
9290
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
952
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
953 if (wholename)
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
954 {
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
955 strcpy(wholename, path);
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
956 strcat(wholename, "/");
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
957 strcat(wholename, file);
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
958 pt_add_file(ppt, wholename);
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
959 free(wholename); // As pt_add_file strdups it anyway!
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
960 }
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
961 }
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
962
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
963 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
964 {
0e043196d176 this patch adds a high-level-api to playtree, allowing to use it more easily
arpi
parents: 8174
diff changeset
965 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
966 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
967 }