Mercurial > mplayer.hg
comparison playtree.c @ 4220:fe2c20d52a25
Fixed a few bugs and added support for VCD/DVD/TV in playlist using virtual url
like dvd://1 vcd://2 tv://5
author | albeu |
---|---|
date | Thu, 17 Jan 2002 20:24:28 +0000 |
parents | 22fadd4022b5 |
children | f04c49aa2408 |
comparison
equal
deleted
inserted
replaced
4219:70888f501b4a | 4220:fe2c20d52a25 |
---|---|
2 #include "config.h" | 2 #include "config.h" |
3 #include <stdlib.h> | 3 #include <stdlib.h> |
4 #include <string.h> | 4 #include <string.h> |
5 #include <stdio.h> | 5 #include <stdio.h> |
6 #include <unistd.h> | 6 #include <unistd.h> |
7 #include <errno.h> | |
7 #ifdef MP_DEBUG | 8 #ifdef MP_DEBUG |
8 #include <assert.h> | 9 #include <assert.h> |
9 #endif | 10 #endif |
10 #include "playtree.h" | 11 #include "playtree.h" |
11 #include "mp_msg.h" | 12 #include "mp_msg.h" |
12 | 13 |
13 static int | 14 static int |
14 play_tree_is_valid(play_tree_t* pt); | 15 play_tree_is_valid(play_tree_t* pt); |
16 | |
17 static void | |
18 play_tree_iter_set_param(play_tree_iter_t* iter,char* opt,char* val); | |
15 | 19 |
16 play_tree_t* | 20 play_tree_t* |
17 play_tree_new(void) { | 21 play_tree_new(void) { |
18 play_tree_t* r = (play_tree_t*)calloc(1,sizeof(play_tree_t)); | 22 play_tree_t* r = (play_tree_t*)calloc(1,sizeof(play_tree_t)); |
19 if(r == NULL) | 23 if(r == NULL) |
20 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",sizeof(play_tree_t)); | 24 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",sizeof(play_tree_t)); |
25 r->entry_type = PLAY_TREE_ENTRY_NODE; | |
21 return r; | 26 return r; |
22 } | 27 } |
23 | 28 |
24 void | 29 void |
25 play_tree_free(play_tree_t* pt, int childs) { | 30 play_tree_free(play_tree_t* pt, int childs) { |
187 play_tree_set_child(play_tree_t* pt, play_tree_t* child) { | 192 play_tree_set_child(play_tree_t* pt, play_tree_t* child) { |
188 play_tree_t* iter; | 193 play_tree_t* iter; |
189 | 194 |
190 #ifdef MP_DEBUG | 195 #ifdef MP_DEBUG |
191 assert(pt != NULL); | 196 assert(pt != NULL); |
192 assert(pt->files == NULL); | 197 assert(pt->entry_type == PLAY_TREE_ENTRY_NODE); |
193 #endif | 198 #endif |
194 | 199 |
195 for(iter = pt->child ; iter != NULL ; iter = iter->next) | 200 for(iter = pt->child ; iter != NULL ; iter = iter->next) |
196 iter->parent = NULL; | 201 iter->parent = NULL; |
197 | 202 |
232 | 237 |
233 | 238 |
234 void | 239 void |
235 play_tree_add_file(play_tree_t* pt,char* file) { | 240 play_tree_add_file(play_tree_t* pt,char* file) { |
236 int n = 0; | 241 int n = 0; |
242 char* e; | |
237 | 243 |
238 #ifdef MP_DEBUG | 244 #ifdef MP_DEBUG |
239 assert(pt != NULL); | 245 assert(pt != NULL); |
240 assert(pt->child == NULL); | 246 assert(pt->child == NULL); |
241 assert(file != NULL); | 247 assert(file != NULL); |
242 #endif | 248 #endif |
249 | |
250 if(pt->entry_type != PLAY_TREE_ENTRY_NODE && | |
251 pt->entry_type != PLAY_TREE_ENTRY_FILE) | |
252 return; | |
243 | 253 |
244 if(pt->files) { | 254 if(pt->files) { |
245 for(n = 0 ; pt->files[n] != NULL ; n++) | 255 for(n = 0 ; pt->files[n] != NULL ; n++) |
246 /* NOTHING */; | 256 /* NOTHING */; |
247 } | 257 } |
249 if(pt->files ==NULL) { | 259 if(pt->files ==NULL) { |
250 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",(n+2)*sizeof(char*)); | 260 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",(n+2)*sizeof(char*)); |
251 return; | 261 return; |
252 } | 262 } |
253 | 263 |
254 pt->files[n] = strdup(file); | 264 e = pt->files[n] = strdup(file); |
255 pt->files[n+1] = NULL; | 265 pt->files[n+1] = NULL; |
266 | |
267 if(strncasecmp(e,"vcd://",6) == 0 && strlen(&e[6]) > 0) { | |
268 pt->entry_type = PLAY_TREE_ENTRY_VCD; | |
269 memmove(e,e + 6,strlen(&e[6])+1); | |
270 } else if(strncasecmp(e,"dvd://",6) == 0 && strlen(&e[6]) > 0) { | |
271 pt->entry_type = PLAY_TREE_ENTRY_DVD; | |
272 memmove(e,&e[6],strlen(&e[6])+1); | |
273 } else if(strncasecmp(e,"tv://",5) == 0 && strlen(&e[5]) > 0) { | |
274 pt->entry_type = PLAY_TREE_ENTRY_TV; | |
275 memmove(e,&e[5],strlen(&e[5])+1); | |
276 } else | |
277 pt->entry_type = PLAY_TREE_ENTRY_FILE; | |
256 | 278 |
257 } | 279 } |
258 | 280 |
259 int | 281 int |
260 play_tree_remove_file(play_tree_t* pt,char* file) { | 282 play_tree_remove_file(play_tree_t* pt,char* file) { |
261 int n,f = -1; | 283 int n,f = -1; |
262 | 284 |
263 #ifdef MP_DEBUG | 285 #ifdef MP_DEBUG |
264 assert(pt != NULL); | 286 assert(pt != NULL); |
265 assert(file != NULL); | 287 assert(file != NULL); |
266 assert(pt->files != NULL); | 288 assert(pt->entry_type != PLAY_TREE_ENTRY_NODE); |
267 #endif | 289 #endif |
268 | 290 |
269 for(n=0 ; pt->files[n] != NULL ; n++) { | 291 for(n=0 ; pt->files[n] != NULL ; n++) { |
270 if(strcmp(file,pt->files[n]) == 0) | 292 if(strcmp(file,pt->files[n]) == 0) |
271 f = n; | 293 f = n; |
381 if(m_config_set_option(iter->config,pt->params[n].name,pt->params[n].value) < 0) { | 403 if(m_config_set_option(iter->config,pt->params[n].name,pt->params[n].value) < 0) { |
382 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Error while setting option '%s' with value '%s'\n", | 404 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Error while setting option '%s' with value '%s'\n", |
383 pt->params[n].name,pt->params[n].value); | 405 pt->params[n].name,pt->params[n].value); |
384 } | 406 } |
385 } | 407 } |
386 //printf("Param pushed\n"); | 408 |
409 if(!pt->child) | |
410 iter->entry_pushed = 1; | |
387 return 1; | 411 return 1; |
388 } | 412 } |
389 | 413 |
390 static void | 414 static void |
391 play_tree_iter_pop_params(play_tree_iter_t* iter) { | 415 play_tree_iter_pop_params(play_tree_iter_t* iter) { |
395 assert(iter->config != NULL); | 419 assert(iter->config != NULL); |
396 #endif | 420 #endif |
397 | 421 |
398 if(iter->tree->params == NULL) | 422 if(iter->tree->params == NULL) |
399 return; | 423 return; |
400 //printf("Poping params\n"); | 424 iter->entry_pushed = 0; |
401 m_config_pop(iter->config); | 425 m_config_pop(iter->config); |
402 } | 426 } |
403 | 427 |
404 play_tree_iter_t* | 428 play_tree_iter_t* |
405 play_tree_iter_new(play_tree_t* pt,m_config_t* config) { | 429 play_tree_iter_new(play_tree_t* pt,m_config_t* config) { |
455 if(iter->tree == NULL) { | 479 if(iter->tree == NULL) { |
456 iter->tree = iter->root; | 480 iter->tree = iter->root; |
457 return play_tree_iter_step(iter,0,with_nodes); | 481 return play_tree_iter_step(iter,0,with_nodes); |
458 } | 482 } |
459 | 483 |
460 if(iter->config && iter->entry_pushed) { | 484 if(iter->config && iter->entry_pushed) |
461 play_tree_iter_pop_params(iter); | 485 play_tree_iter_pop_params(iter); |
462 iter->entry_pushed = 0; | 486 |
463 } | 487 iter->file = -1; |
464 | |
465 iter->file = 0; | |
466 if( d > 0 ) | 488 if( d > 0 ) |
467 pt = iter->tree->next; | 489 pt = iter->tree->next; |
468 else if(d < 0) | 490 else if(d < 0) |
469 pt = iter->tree->prev; | 491 pt = iter->tree->prev; |
470 else | 492 else |
509 } | 531 } |
510 | 532 |
511 #ifdef MP_DEBUG | 533 #ifdef MP_DEBUG |
512 assert(pt->files != NULL); | 534 assert(pt->files != NULL); |
513 #endif | 535 #endif |
514 | 536 |
515 iter->tree = pt; | 537 iter->tree = pt; |
538 | |
516 for(d = 0 ; iter->tree->files[d] != NULL ; d++) | 539 for(d = 0 ; iter->tree->files[d] != NULL ; d++) |
517 /* NOTHING */; | 540 /* NOTHING */; |
518 iter->num_files = d; | 541 iter->num_files = d; |
519 | 542 |
520 if(iter->config) | 543 if(iter->config) |
521 iter->entry_pushed = play_tree_iter_push_params(iter); | 544 play_tree_iter_push_params(iter); |
522 | 545 |
523 return PLAY_TREE_ITER_ENTRY; | 546 return PLAY_TREE_ITER_ENTRY; |
524 | 547 |
525 } | 548 } |
526 | 549 |
530 | 553 |
531 #ifdef MP_DEBUG | 554 #ifdef MP_DEBUG |
532 assert(pt != NULL); | 555 assert(pt != NULL); |
533 #endif | 556 #endif |
534 | 557 |
535 if(pt->files != NULL) | 558 if(pt->entry_type != PLAY_TREE_ENTRY_NODE) { |
559 #ifdef MP_DEBUG | |
560 assert(pt->child == NULL); | |
561 #endif | |
536 return 1; | 562 return 1; |
563 } | |
537 else if (pt->child != NULL) { | 564 else if (pt->child != NULL) { |
538 for(iter = pt->child ; iter != NULL ; iter = iter->next) { | 565 for(iter = pt->child ; iter != NULL ; iter = iter->next) { |
539 if(play_tree_is_valid(iter)) | 566 if(play_tree_is_valid(iter)) |
540 return 1; | 567 return 1; |
541 } | 568 } |
550 assert(iter != NULL); | 577 assert(iter != NULL); |
551 assert(iter->tree != NULL); | 578 assert(iter->tree != NULL); |
552 //printf("PT : Go UP\n"); | 579 //printf("PT : Go UP\n"); |
553 #endif | 580 #endif |
554 | 581 |
555 iter->file = 0; | 582 iter->file = -1; |
556 if(iter->tree->parent == iter->root->parent) | 583 if(iter->tree->parent == iter->root->parent) |
557 return PLAY_TREE_ITER_END; | 584 return PLAY_TREE_ITER_END; |
558 | 585 |
559 #ifdef MP_DEBUG | 586 #ifdef MP_DEBUG |
560 assert(iter->tree->parent != NULL); | 587 assert(iter->tree->parent != NULL); |
586 assert(iter->tree->child != NULL); | 613 assert(iter->tree->child != NULL); |
587 assert(iter->tree->child->parent == iter->tree); | 614 assert(iter->tree->child->parent == iter->tree); |
588 //printf("PT : Go DOWN\n"); | 615 //printf("PT : Go DOWN\n"); |
589 #endif | 616 #endif |
590 | 617 |
591 iter->file = 0; | 618 iter->file = -1; |
592 | 619 |
593 // Push subtree params | 620 // Push subtree params |
594 if(iter->config) | 621 if(iter->config) |
595 play_tree_iter_push_params(iter); | 622 play_tree_iter_push_params(iter); |
596 | 623 |
615 return play_tree_iter_step(iter,0,with_nodes); | 642 return play_tree_iter_step(iter,0,with_nodes); |
616 } | 643 } |
617 | 644 |
618 char* | 645 char* |
619 play_tree_iter_get_file(play_tree_iter_t* iter, int d) { | 646 play_tree_iter_get_file(play_tree_iter_t* iter, int d) { |
620 | 647 char* entry; |
621 #ifdef MP_DEBUG | 648 #ifdef MP_DEBUG |
622 assert(iter != NULL); | 649 assert(iter != NULL); |
623 assert(iter->tree->child == NULL); | 650 assert(iter->tree->child == NULL); |
624 #endif | 651 #endif |
625 | 652 |
626 if(iter->tree->files == NULL) | 653 if(iter->tree->files == NULL) |
627 return NULL; | 654 return NULL; |
628 | 655 |
656 #ifdef MP_DEBUG | |
657 assert(iter->num_files > 0); | |
658 #endif | |
659 | |
660 if(iter->file >= iter->num_files-1 || iter->file < -1) | |
661 return NULL; | |
662 | |
629 if(d > 0) { | 663 if(d > 0) { |
630 if(iter->tree->files[iter->file] == NULL) | 664 if(iter->file >= iter->num_files - 1) |
631 return NULL; | 665 iter->file = 0; |
632 iter->file++; | 666 else |
667 iter->file++; | |
633 } else if(d < 0) { | 668 } else if(d < 0) { |
634 if(iter->file == 0) | 669 if(iter->file <= 0) |
635 return NULL; | 670 iter->file = iter->num_files - 1; |
636 iter->file--; | 671 else |
637 } | 672 iter->file--; |
638 return iter->tree->files[iter->file-1]; | 673 } |
674 entry = iter->tree->files[iter->file]; | |
675 | |
676 switch(iter->tree->entry_type) { | |
677 case PLAY_TREE_ENTRY_DVD : | |
678 play_tree_iter_set_param(iter,"dvd",entry); | |
679 break; | |
680 case PLAY_TREE_ENTRY_VCD : | |
681 play_tree_iter_set_param(iter,"vcd",entry); | |
682 break; | |
683 case PLAY_TREE_ENTRY_TV : | |
684 { | |
685 char* val = (char*)malloc(strlen(entry) + 11 + 1); | |
686 sprintf(val,"on:channel=%s",entry); | |
687 play_tree_iter_set_param(iter,"tv",val); | |
688 break; | |
689 } | |
690 } | |
691 | |
692 return entry; | |
639 } | 693 } |
640 | 694 |
641 play_tree_t* | 695 play_tree_t* |
642 play_tree_cleanup(play_tree_t* pt) { | 696 play_tree_cleanup(play_tree_t* pt) { |
643 play_tree_t* iter, *tmp, *first; | 697 play_tree_t* iter, *tmp, *first; |
698 } | 752 } |
699 iter->config = NULL; | 753 iter->config = NULL; |
700 | 754 |
701 return iter; | 755 return iter; |
702 } | 756 } |
757 | |
758 static void | |
759 play_tree_iter_set_param(play_tree_iter_t* iter,char* opt,char* val) { | |
760 int push = 0; | |
761 play_tree_t* pt; | |
762 #ifdef MP_DEBUG | |
763 assert(iter != NULL); | |
764 assert(iter->tree != NULL); | |
765 #endif | |
766 | |
767 pt = iter->tree; | |
768 | |
769 if(iter->tree->params == NULL) | |
770 push = 1; | |
771 | |
772 play_tree_set_param(iter->tree,opt,val); | |
773 | |
774 if(push) | |
775 play_tree_iter_push_params(iter); | |
776 else if(iter->config) | |
777 m_config_set_option(iter->config,opt,val); | |
778 | |
779 } | |
780 |