audio: restore volume setting after AO reinit if needed
[mplayer.git] / playtree.c
blob22205d3bf54c3fdbfd7bfdea156730e0804531d9
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 /// \file
20 /// \ingroup Playtree
22 #include "config.h"
23 #include <stdlib.h>
24 #include <string.h>
25 #include <stdio.h>
26 #include <unistd.h>
27 #include <errno.h>
28 #include <assert.h>
30 #include "talloc.h"
32 #include "m_config.h"
33 #include "playtree.h"
34 #include "mp_msg.h"
36 static int
37 play_tree_is_valid(play_tree_t* pt);
39 play_tree_t*
40 play_tree_new(void) {
41 play_tree_t* r = calloc(1,sizeof(play_tree_t));
42 r->entry_type = PLAY_TREE_ENTRY_NODE;
43 return r;
46 void
47 play_tree_free(play_tree_t* pt, int children) {
48 play_tree_t* iter;
50 assert(pt != NULL);
52 if(children) {
53 for(iter = pt->child; iter != NULL; ) {
54 play_tree_t* nxt=iter->next;
55 play_tree_free(iter,1);
56 iter = nxt;
58 pt->child = NULL;
61 play_tree_remove(pt,0,0);
63 for(iter = pt->child ; iter != NULL ; iter = iter->next)
64 iter->parent = NULL;
66 talloc_free(pt->params);
68 if(pt->files) {
69 int i;
70 for(i = 0 ; pt->files[i] != NULL ; i++)
71 free(pt->files[i]);
72 free(pt->files);
75 free(pt);
78 void
79 play_tree_free_list(play_tree_t* pt, int children) {
80 play_tree_t* iter;
82 assert(pt != NULL);
84 for(iter = pt ; iter->prev != NULL ; iter = iter->prev)
85 /* NOTHING */;
87 while(iter) {
88 play_tree_t* nxt = iter->next;
89 play_tree_free(iter, children);
90 iter = nxt;
96 void
97 play_tree_append_entry(play_tree_t* pt, play_tree_t* entry) {
98 play_tree_t* iter;
100 assert(pt != NULL);
101 assert(entry != NULL);
103 if(pt == entry)
104 return;
106 for(iter = pt ; iter->next != NULL ; iter = iter->next)
107 /* NOTHING */;
109 entry->parent = iter->parent;
110 entry->prev = iter;
111 entry->next = NULL;
112 iter->next = entry;
115 void
116 play_tree_prepend_entry(play_tree_t* pt, play_tree_t* entry) {
117 play_tree_t* iter;
119 assert(pt != NULL);
120 assert(entry != NULL);
122 for(iter = pt ; iter->prev != NULL; iter = iter->prev)
123 /* NOTHING */;
125 entry->prev = NULL;
126 entry->next = iter;
127 entry->parent = iter->parent;
129 iter->prev = entry;
130 if(entry->parent) {
131 assert(entry->parent->child == iter);
132 entry->parent->child = entry;
136 void
137 play_tree_insert_entry(play_tree_t* pt, play_tree_t* entry) {
139 assert(pt != NULL);
140 assert(entry != NULL);
142 entry->parent = pt->parent;
143 entry->prev = pt;
144 if(pt->next) {
145 assert(pt->next->prev == pt);
146 entry->next = pt->next;
147 entry->next->prev = entry;
148 } else
149 entry->next = NULL;
150 pt->next = entry;
154 void
155 play_tree_remove(play_tree_t* pt, int free_it, int with_children) {
157 assert(pt != NULL);
159 // Middle of list
160 if(pt->prev && pt->next) {
161 assert(pt->prev->next == pt);
162 assert(pt->next->prev == pt);
163 pt->prev->next = pt->next;
164 pt->next->prev = pt->prev;
165 } // End of list
166 else if(pt->prev) {
167 assert(pt->prev->next == pt);
168 pt->prev->next = NULL;
169 } // Beginning of list
170 else if(pt->next) {
171 assert(pt->next->prev == pt);
172 pt->next->prev = NULL;
173 if(pt->parent) {
174 assert(pt->parent->child == pt);
175 pt->parent->child = pt->next;
177 } // The only one
178 else if(pt->parent) {
179 assert(pt->parent->child == pt);
180 pt->parent->child = NULL;
183 pt->prev = pt->next = pt->parent = NULL;
184 if(free_it)
185 play_tree_free(pt,with_children);
189 void
190 play_tree_set_child(play_tree_t* pt, play_tree_t* child) {
191 play_tree_t* iter;
193 /* Roughly validate input data. Both, pt and child are going to be
194 * dereferenced, hence assure they're not NULL.
196 if (!pt || !child) {
197 mp_msg(MSGT_PLAYTREE, MSGL_ERR, "Internal error, attempt to add an empty child or use empty playlist\n");
198 return;
201 assert(pt->entry_type == PLAY_TREE_ENTRY_NODE);
203 //DEBUG_FF: Where are the children freed?
204 // Attention in using this function!
205 for(iter = pt->child ; iter != NULL ; iter = iter->next)
206 iter->parent = NULL;
208 // Go back to first one
209 for(iter = child ; iter->prev != NULL ; iter = iter->prev)
210 /* NOTHING */;
212 pt->child = iter;
214 for( ; iter != NULL ; iter= iter->next)
215 iter->parent = pt;
219 void
220 play_tree_set_parent(play_tree_t* pt, play_tree_t* parent) {
221 play_tree_t* iter;
223 assert(pt != NULL);
225 if(pt->parent)
226 pt->parent->child = NULL;
228 for(iter = pt ; iter != NULL ; iter = iter->next)
229 iter->parent = parent;
231 if(pt->prev) {
232 for(iter = pt->prev ; iter->prev != NULL ; iter = iter->prev)
233 iter->parent = parent;
234 iter->parent = parent;
235 parent->child = iter;
236 } else
237 parent->child = pt;
242 void
243 play_tree_add_file(play_tree_t* pt,const char* file) {
244 int n = 0;
246 assert(pt != NULL);
247 assert(pt->child == NULL);
248 assert(file != NULL);
250 if(pt->entry_type != PLAY_TREE_ENTRY_NODE &&
251 pt->entry_type != PLAY_TREE_ENTRY_FILE)
252 return;
254 if(pt->files) {
255 for(n = 0 ; pt->files[n] != NULL ; n++)
256 /* NOTHING */;
258 pt->files = realloc(pt->files, (n + 2) * sizeof(char*));
259 if(pt->files ==NULL) {
260 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",(n+2)*(int)sizeof(char*));
261 return;
264 pt->files[n] = strdup(file);
265 pt->files[n+1] = NULL;
267 pt->entry_type = PLAY_TREE_ENTRY_FILE;
272 play_tree_remove_file(play_tree_t* pt,const char* file) {
273 int n,f = -1;
275 assert(pt != NULL);
276 assert(file != NULL);
277 assert(pt->entry_type != PLAY_TREE_ENTRY_NODE);
279 for(n=0 ; pt->files[n] != NULL ; n++) {
280 if(strcmp(file,pt->files[n]) == 0)
281 f = n;
284 if(f < 0) // Not found
285 return 0;
287 free(pt->files[f]);
289 if(n > 1) {
290 memmove(&pt->files[f],&pt->files[f+1],(n-f)*sizeof(char*));
291 pt->files = realloc(pt->files, n * sizeof(char*));
292 if(pt->files == NULL) {
293 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",(n+2)*(int)sizeof(char*));
294 return -1;
296 } else {
297 free(pt->files);
298 pt->files = NULL;
301 return 1;
304 void
305 play_tree_set_param(play_tree_t* pt, struct bstr name, struct bstr val) {
306 int n = 0;
308 assert(pt != NULL);
310 if(pt->params)
311 for ( ; pt->params[n].name != NULL ; n++ ) { }
313 pt->params = talloc_realloc(NULL, pt->params, struct play_tree_param, n + 2);
314 pt->params[n].name = bstrdup0(pt->params, name);
315 pt->params[n].value = bstrdup0(pt->params, val);
316 memset(&pt->params[n+1],0,sizeof(play_tree_param_t));
318 return;
322 play_tree_unset_param(play_tree_t* pt, const char* name) {
323 int n,ni = -1;
325 assert(pt != NULL);
326 assert(name != NULL);
327 assert(pt->params != NULL);
329 for(n = 0 ; pt->params[n].name != NULL ; n++) {
330 if(strcasecmp(pt->params[n].name,name) == 0)
331 ni = n;
334 if(ni < 0)
335 return 0;
337 talloc_free(pt->params[ni].name);
338 talloc_free(pt->params[ni].value);
340 if(n > 1) {
341 memmove(&pt->params[ni],&pt->params[ni+1],(n-ni)*sizeof(play_tree_param_t));
342 pt->params = talloc_realloc(NULL, pt->params, struct play_tree_param, n);
343 } else {
344 talloc_free(pt->params);
345 pt->params = NULL;
348 return 1;
351 void
352 play_tree_set_params_from(play_tree_t* dest,play_tree_t* src) {
353 int i;
355 assert(dest != NULL);
356 assert(src != NULL);
358 if(!src->params)
359 return;
361 for(i = 0; src->params[i].name != NULL ; i++)
362 play_tree_set_param(dest, bstr(src->params[i].name), bstr(src->params[i].value));
363 if(src->flags & PLAY_TREE_RND) // pass the random flag too
364 dest->flags |= PLAY_TREE_RND;
368 static void
369 play_tree_unset_flag(play_tree_t* pt, int flags , int deep) {
370 play_tree_t* i;
372 pt->flags &= ~flags;
374 if(deep && pt->child) {
375 if(deep > 0) deep--;
376 for(i = pt->child ; i ; i = i->next)
377 play_tree_unset_flag(i,flags,deep);
382 //////////////////////////////////// ITERATOR //////////////////////////////////////
384 static void
385 play_tree_iter_push_params(play_tree_iter_t* iter) {
386 int n;
387 play_tree_t* pt;
388 assert(iter->config != NULL);
389 assert(iter->tree != NULL);
391 pt = iter->tree;
393 // We always push a config because we can set some option
394 // while playing
395 m_config_push(iter->config);
397 if(pt->params == NULL)
398 return;
401 for(n = 0; pt->params[n].name != NULL ; n++) {
402 int e;
403 if((e = m_config_set_option0(iter->config, pt->params[n].name,
404 pt->params[n].value, false)) < 0) {
405 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Error %d while setting option '%s' with value '%s'\n",e,
406 pt->params[n].name,pt->params[n].value);
410 if(!pt->child)
411 iter->entry_pushed = 1;
414 play_tree_iter_t*
415 play_tree_iter_new(play_tree_t* pt,m_config_t* config) {
416 play_tree_iter_t* iter;
418 assert(pt != NULL);
419 assert(config != NULL);
421 if( ! play_tree_is_valid(pt))
422 return NULL;
424 iter = calloc(1,sizeof(play_tree_iter_t));
425 if(! iter) {
426 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate new iterator (%d bytes of memory)\n",(int)sizeof(play_tree_iter_t));
427 return NULL;
429 iter->root = pt;
430 iter->tree = NULL;
431 iter->config = config;
433 if(pt->parent)
434 iter->loop = pt->parent->loop;
436 return iter;
439 void
440 play_tree_iter_free(play_tree_iter_t* iter) {
442 assert(iter != NULL);
444 if(iter->status_stack) {
445 assert(iter->stack_size > 0);
446 free(iter->status_stack);
449 free(iter);
452 static play_tree_t*
453 play_tree_rnd_step(play_tree_t* pt) {
454 int count = 0;
455 int r;
456 play_tree_t *i,*head;
458 // Count how many free choice we have
459 for(i = pt ; i->prev ; i = i->prev)
460 if(!(i->flags & PLAY_TREE_RND_PLAYED)) count++;
461 head = i;
462 if(!(i->flags & PLAY_TREE_RND_PLAYED)) count++;
463 for(i = pt->next ; i ; i = i->next)
464 if(!(i->flags & PLAY_TREE_RND_PLAYED)) count++;
466 if(!count) return NULL;
468 r = (int)((float)(count) * rand() / (RAND_MAX + 1.0));
470 for(i = head ; i ; i=i->next) {
471 if(!(i->flags & PLAY_TREE_RND_PLAYED)) r--;
472 if(r < 0) return i;
475 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Random stepping error\n");
476 return NULL;
481 play_tree_iter_step(play_tree_iter_t* iter, int d,int with_nodes) {
482 play_tree_t* pt;
484 if ( !iter ) return PLAY_TREE_ITER_ENTRY;
485 if ( !iter->root ) return PLAY_TREE_ITER_ENTRY;
487 assert(iter != NULL);
488 assert(iter->root != NULL);
490 if(iter->tree == NULL) {
491 iter->tree = iter->root;
492 return play_tree_iter_step(iter,0,with_nodes);
495 if(iter->config && iter->entry_pushed > 0) {
496 iter->entry_pushed = 0;
497 m_config_pop(iter->config);
500 if(iter->tree->parent && (iter->tree->parent->flags & PLAY_TREE_RND))
501 iter->mode = PLAY_TREE_ITER_RND;
502 else
503 iter->mode = PLAY_TREE_ITER_NORMAL;
505 iter->file = -1;
506 if(iter->mode == PLAY_TREE_ITER_RND)
507 pt = play_tree_rnd_step(iter->tree);
508 else if( d > 0 ) {
509 int i;
510 pt = iter->tree;
511 for(i = d ; i > 0 && pt ; i--)
512 pt = pt->next;
513 d = i ? i : 1;
514 } else if(d < 0) {
515 int i;
516 pt = iter->tree;
517 for(i = d ; i < 0 && pt ; i++)
518 pt = pt->prev;
519 d = i ? i : -1;
520 } else
521 pt = iter->tree;
523 if(pt == NULL) { // No next
524 // Must we loop?
525 if (iter->mode == PLAY_TREE_ITER_RND) {
526 if (iter->root->loop == 0)
527 return PLAY_TREE_ITER_END;
528 play_tree_unset_flag(iter->root, PLAY_TREE_RND_PLAYED, -1);
529 if (iter->root->loop > 0) iter->root->loop--;
530 // try again
531 return play_tree_iter_step(iter, 0, with_nodes);
532 } else
533 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) ) ) ) {
534 if(d > 0) { // Go back to the first one
535 for(pt = iter->tree ; pt->prev != NULL; pt = pt->prev)
536 /* NOTHNG */;
537 if(iter->loop > 0) iter->loop--;
538 } else if( d < 0 ) { // Or the last one
539 for(pt = iter->tree ; pt->next != NULL; pt = pt->next)
540 /* NOTHNG */;
541 if(iter->loop >= 0 && iter->loop < iter->tree->parent->loop) iter->loop++;
543 iter->tree = pt;
544 return play_tree_iter_step(iter,0,with_nodes);
546 // Go up one level
547 return play_tree_iter_up_step(iter,d,with_nodes);
551 // Is there any valid child?
552 if(pt->child && play_tree_is_valid(pt->child)) {
553 iter->tree = pt;
554 if(with_nodes) { // Stop on the node
555 return PLAY_TREE_ITER_NODE;
556 } else // Or follow it
557 return play_tree_iter_down_step(iter,d,with_nodes);
560 // Is it a valid entry?
561 if(! play_tree_is_valid(pt)) {
562 if(d == 0) { // Can this happen ? FF: Yes!
563 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"What to do now ???? Infinite loop if we continue\n");
564 return PLAY_TREE_ITER_ERROR;
565 } // Not a valid entry : go to next one
566 return play_tree_iter_step(iter,d,with_nodes);
569 assert(pt->files != NULL);
571 iter->tree = pt;
573 for(d = 0 ; iter->tree->files[d] != NULL ; d++)
574 /* NOTHING */;
575 iter->num_files = d;
577 if(iter->config) {
578 play_tree_iter_push_params(iter);
579 iter->entry_pushed = 1;
580 if(iter->mode == PLAY_TREE_ITER_RND)
581 pt->flags |= PLAY_TREE_RND_PLAYED;
584 return PLAY_TREE_ITER_ENTRY;
588 static int
589 play_tree_is_valid(play_tree_t* pt) {
590 play_tree_t* iter;
592 if(pt->entry_type != PLAY_TREE_ENTRY_NODE) {
593 assert(pt->child == NULL);
594 return 1;
596 else if (pt->child != NULL) {
597 for(iter = pt->child ; iter != NULL ; iter = iter->next) {
598 if(play_tree_is_valid(iter))
599 return 1;
602 return 0;
606 play_tree_iter_up_step(play_tree_iter_t* iter, int d,int with_nodes) {
608 assert(iter != NULL);
609 assert(iter->tree != NULL);
611 iter->file = -1;
612 if(iter->tree->parent == iter->root->parent)
613 return PLAY_TREE_ITER_END;
615 assert(iter->tree->parent != NULL);
616 assert(iter->stack_size > 0);
617 assert(iter->status_stack != NULL);
619 iter->stack_size--;
620 iter->loop = iter->status_stack[iter->stack_size];
621 if(iter->stack_size > 0)
622 iter->status_stack = realloc(iter->status_stack, iter->stack_size * sizeof(int));
623 else {
624 free(iter->status_stack);
625 iter->status_stack = NULL;
627 if(iter->stack_size > 0 && iter->status_stack == NULL) {
628 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",iter->stack_size*(int)sizeof(char*));
629 return PLAY_TREE_ITER_ERROR;
631 iter->tree = iter->tree->parent;
633 // Pop subtree params
634 if(iter->config) {
635 m_config_pop(iter->config);
636 if(iter->mode == PLAY_TREE_ITER_RND)
637 iter->tree->flags |= PLAY_TREE_RND_PLAYED;
640 return play_tree_iter_step(iter,d,with_nodes);
644 play_tree_iter_down_step(play_tree_iter_t* iter, int d,int with_nodes) {
646 assert(iter->tree->files == NULL);
647 assert(iter->tree->child != NULL);
648 assert(iter->tree->child->parent == iter->tree);
650 iter->file = -1;
652 // Push subtree params
653 if(iter->config)
654 play_tree_iter_push_params(iter);
656 iter->stack_size++;
657 iter->status_stack = realloc(iter->status_stack, iter->stack_size * sizeof(int));
658 if(iter->status_stack == NULL) {
659 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",iter->stack_size*(int)sizeof(int));
660 return PLAY_TREE_ITER_ERROR;
662 iter->status_stack[iter->stack_size-1] = iter->loop;
663 // Set new status
664 iter->loop = iter->tree->loop-1;
665 if(d >= 0)
666 iter->tree = iter->tree->child;
667 else {
668 play_tree_t* pt;
669 for(pt = iter->tree->child ; pt->next != NULL ; pt = pt->next)
670 /*NOTING*/;
671 iter->tree = pt;
674 return play_tree_iter_step(iter,0,with_nodes);
677 char*
678 play_tree_iter_get_file(play_tree_iter_t* iter, int d) {
679 assert(iter != NULL);
680 assert(iter->tree->child == NULL);
682 if(iter->tree->files == NULL)
683 return NULL;
685 assert(iter->num_files > 0);
687 if(iter->file >= iter->num_files-1 || iter->file < -1)
688 return NULL;
690 if(d > 0) {
691 if(iter->file >= iter->num_files - 1)
692 iter->file = 0;
693 else
694 iter->file++;
695 } else if(d < 0) {
696 if(iter->file <= 0)
697 iter->file = iter->num_files - 1;
698 else
699 iter->file--;
701 return iter->tree->files[iter->file];
704 play_tree_t*
705 play_tree_cleanup(play_tree_t* pt) {
706 play_tree_t* iter, *tmp, *first;
708 assert(pt != NULL);
710 if( ! play_tree_is_valid(pt)) {
711 play_tree_remove(pt,1,1);
712 return NULL;
715 first = pt->child;
717 for(iter = pt->child ; iter != NULL ; ) {
718 tmp = iter;
719 iter = iter->next;
720 if(! play_tree_is_valid(tmp)) {
721 play_tree_remove(tmp,1,1);
722 if(tmp == first) first = iter;
726 for(iter = first ; iter != NULL ; ) {
727 tmp = iter;
728 iter = iter->next;
729 play_tree_cleanup(tmp);
732 return pt;
736 play_tree_iter_t*
737 play_tree_iter_new_copy(play_tree_iter_t* old) {
738 play_tree_iter_t* iter;
740 assert(old != NULL);
742 iter = malloc(sizeof(play_tree_iter_t));
743 if(iter == NULL) {
744 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",(int)sizeof(play_tree_iter_t));
745 return NULL;
748 memcpy(iter,old,sizeof(play_tree_iter_t));
749 if(old->status_stack) {
750 iter->status_stack = malloc(old->stack_size * sizeof(int));
751 if(iter->status_stack == NULL) {
752 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",old->stack_size * (int)sizeof(int));
753 free(iter);
754 return NULL;
756 memcpy(iter->status_stack,old->status_stack,iter->stack_size*sizeof(int));
758 iter->config = NULL;
760 return iter;
763 // HIGH Level API, by Fabian Franz (mplayer@fabian-franz.de)
765 play_tree_iter_t* pt_iter_create(play_tree_t** ppt, m_config_t* config)
767 play_tree_iter_t* r=NULL;
768 assert(*ppt!=NULL);
770 *ppt=play_tree_cleanup(*ppt);
772 if(*ppt) {
773 r = play_tree_iter_new(*ppt,config);
774 if (r && play_tree_iter_step(r,0,0) != PLAY_TREE_ITER_ENTRY)
776 play_tree_iter_free(r);
777 r = NULL;
781 return r;
784 void pt_iter_destroy(play_tree_iter_t** iter)
786 if (iter && *iter)
788 free(*iter);
789 iter=NULL;
793 char* pt_iter_get_file(play_tree_iter_t* iter, int d)
795 int i=0;
796 char* r;
798 if (iter==NULL)
799 return NULL;
801 r = play_tree_iter_get_file(iter,d);
803 while (!r && d!=0)
805 if (play_tree_iter_step(iter,d,0) != PLAY_TREE_ITER_ENTRY)
806 break;
807 r=play_tree_iter_get_file(iter,d);
808 i++;
811 return r;
814 void pt_iter_insert_entry(play_tree_iter_t* iter, play_tree_t* entry)
816 play_tree_t *pt = iter->tree;
817 assert(pt!=NULL);
818 assert(entry!=NULL);
819 assert(entry!=pt);
821 play_tree_insert_entry(pt, entry);
822 play_tree_set_params_from(entry,pt);
825 void pt_iter_replace_entry(play_tree_iter_t* iter, play_tree_t* entry)
827 play_tree_t *pt = iter->tree;
829 pt_iter_insert_entry(iter, entry);
830 play_tree_remove(pt, 1, 1);
831 iter->tree=entry;
834 //Add a new file as a new entry
835 void pt_add_file(play_tree_t** ppt, const char* filename)
837 play_tree_t *pt = *ppt, *entry = play_tree_new();
839 play_tree_add_file(entry, filename);
840 if (pt)
841 play_tree_append_entry(pt, entry);
842 else
844 pt=entry;
845 *ppt=pt;
847 play_tree_set_params_from(entry,pt);
850 void pt_iter_goto_head(play_tree_iter_t* iter)
852 iter->tree=iter->root;
853 play_tree_iter_step(iter, 0, 0);