comparison src/adplug/adplug-xmms.cc @ 703:cae46214b8bf trunk

[svn] - rework AdPlug to use VFS properly see http://sacredspiral.co.uk/~nenolod/adplug-vfs-ng.diff for a diff.
author nenolod
date Fri, 23 Feb 2007 20:23:34 -0800
parents 914c96de3244
children 4709ce4e209e
comparison
equal deleted inserted replaced
702:d25b51e90542 703:cae46214b8bf
85 GtkLabel *infobox; 85 GtkLabel *infobox;
86 GtkDialog *infodlg; 86 GtkDialog *infodlg;
87 } plr = { 0, 0, 0, 0, -1, "", NULL, 0.0f, false, 0, NULL, NULL }; 87 } plr = { 0, 0, 0, 0, -1, "", NULL, 0.0f, false, 0, NULL, NULL };
88 88
89 static InputPlayback *playback; 89 static InputPlayback *playback;
90
91 // XXX: this function is not in the public API yet.
92 extern "C" VFSFile *vfs_buffered_file_new_from_uri(gchar *uri);
90 93
91 /***** Debugging *****/ 94 /***** Debugging *****/
92 95
93 #ifdef DEBUG 96 #ifdef DEBUG
94 97
394 rowstr[0] = g_strdup(t1); rowstr[1] = g_strdup(t2); 397 rowstr[0] = g_strdup(t1); rowstr[1] = g_strdup(t2);
395 gtk_clist_append(instlist, rowstr); 398 gtk_clist_append(instlist, rowstr);
396 g_free(rowstr[0]); g_free(rowstr[1]); 399 g_free(rowstr[0]); g_free(rowstr[1]);
397 } 400 }
398 401
399 static CPlayer *factory(const std::string &filename, Copl *newopl) 402 static CPlayer *factory(VFSFile *fd, Copl *newopl)
400 { 403 {
401 CPlayers::const_iterator i; 404 CPlayers::const_iterator i;
402 405
403 dbg_printf("factory(\"%s\",opl): ", filename.c_str()); 406 dbg_printf("factory(%p<%s>,opl): ", fd, fd->uri != NULL ? fd->uri : "unknown");
404 return CAdPlug::factory(filename, newopl, cfg.players); 407 return CAdPlug::factory(fd, newopl, cfg.players);
405 } 408 }
406 409
407 static void adplug_stop(InputPlayback *data); 410 static void adplug_stop(InputPlayback *data);
408 static void adplug_play(InputPlayback *data); 411 static void adplug_play(InputPlayback *data);
409 412
427 } 430 }
428 431
429 static void adplug_info_box(char *filename) 432 static void adplug_info_box(char *filename)
430 { 433 {
431 CSilentopl tmpopl; 434 CSilentopl tmpopl;
435 VFSFile *fd = vfs_buffered_file_new_from_uri(filename);
436
437 if (!fd) return;
438
432 CPlayer *p = (strcmp(filename, plr.filename) || !plr.p) ? 439 CPlayer *p = (strcmp(filename, plr.filename) || !plr.p) ?
433 factory(filename, &tmpopl) : plr.p; 440 factory(fd, &tmpopl) : plr.p;
434 441
435 if(!p) return; // bail out if no player could be created 442 if(!p) return; // bail out if no player could be created
436 if(p == plr.p && plr.infodlg) return; // only one info box for active song 443 if(p == plr.p && plr.infodlg) return; // only one info box for active song
437 444
438 std::ostringstream infotext; 445 std::ostringstream infotext;
590 597
591 static void *play_loop(void *data) 598 static void *play_loop(void *data)
592 /* Main playback thread. Takes the filename to play as argument. */ 599 /* Main playback thread. Takes the filename to play as argument. */
593 { 600 {
594 InputPlayback *playback = (InputPlayback *) data; 601 InputPlayback *playback = (InputPlayback *) data;
595 char *filename = (char *) playback->data; 602 char *filename = (char *) playback->filename;
596 dbg_printf("play_loop(\"%s\"): ", filename); 603 dbg_printf("play_loop(\"%s\"): ", filename);
597 CEmuopl opl(cfg.freq, cfg.bit16, cfg.stereo); 604 CEmuopl opl(cfg.freq, cfg.bit16, cfg.stereo);
598 long toadd = 0, i, towrite; 605 long toadd = 0, i, towrite;
599 char *sndbuf, *sndbufpos; 606 char *sndbuf, *sndbufpos;
600 bool playing = true, // Song self-end indicator. 607 bool playing = true, // Song self-end indicator.
601 bit16 = cfg.bit16, // Duplicate config, so it doesn't affect us if 608 bit16 = cfg.bit16, // Duplicate config, so it doesn't affect us if
602 stereo = cfg.stereo; // the user changes it while we're playing. 609 stereo = cfg.stereo; // the user changes it while we're playing.
603 unsigned long freq = cfg.freq; 610 unsigned long freq = cfg.freq;
604 611
612 // we use VfsBufferedFile class here because adplug does a lot of
613 // probing. a short delay before probing begins is better than
614 // a lot of delay during probing.
615 VFSFile *fd = vfs_buffered_file_new_from_uri(playback->filename);
616
617 if (!fd) { plr.playing = false; g_thread_exit(NULL); }
618
605 // Try to load module 619 // Try to load module
606 dbg_printf("factory, "); 620 dbg_printf("factory, ");
607 if(!(plr.p = factory(filename, &opl))) { 621 if(!(plr.p = factory(fd, &opl))) {
608 dbg_printf("error!\n"); 622 dbg_printf("error!\n");
609 // MessageBox("AdPlug :: Error", "File could not be opened!", "Ok"); 623 // MessageBox("AdPlug :: Error", "File could not be opened!", "Ok");
610 plr.playing = false; 624 plr.playing = false;
611 g_thread_exit(NULL); 625 g_thread_exit(NULL);
612 } 626 }
701 delete plr.p; plr.p = 0; 715 delete plr.p; plr.p = 0;
702 if(plr.songtitle) { free(plr.songtitle); plr.songtitle = NULL; } 716 if(plr.songtitle) { free(plr.songtitle); plr.songtitle = NULL; }
703 free(sndbuf); 717 free(sndbuf);
704 plr.playing = false; // important! XMMS won't get a self-ended song without it. 718 plr.playing = false; // important! XMMS won't get a self-ended song without it.
705 dbg_printf(".\n"); 719 dbg_printf(".\n");
720 vfs_fclose(fd);
706 g_thread_exit(NULL); 721 g_thread_exit(NULL);
707 return(NULL); 722 return(NULL);
708 } 723 }
709 724
710 // sampsize macro not useful anymore. 725 // sampsize macro not useful anymore.
711 #undef sampsize 726 #undef sampsize
712 727
713 /***** Informational *****/ 728 /***** Informational *****/
714 729
715 static int adplug_is_our_file(char *filename) 730 static int adplug_is_our_fd(gchar *filename, VFSFile *fd)
716 { 731 {
717 CSilentopl tmpopl; 732 CSilentopl tmpopl;
718 CPlayer *p = factory(filename,&tmpopl); 733
734 CPlayer *p = factory(fd,&tmpopl);
719 735
720 dbg_printf("adplug_is_our_file(\"%s\"): returned ",filename); 736 dbg_printf("adplug_is_our_file(\"%s\"): returned ",filename);
721 737
722 if(p) { 738 if(p) {
723 delete p; 739 delete p;
727 743
728 dbg_printf("FALSE\n"); 744 dbg_printf("FALSE\n");
729 return FALSE; 745 return FALSE;
730 } 746 }
731 747
748 static int adplug_is_our_file(char *filename)
749 {
750 CSilentopl tmpopl;
751 VFSFile *fd = vfs_buffered_file_new_from_uri(filename); if (!fd) return FALSE;
752
753 CPlayer *p = factory(fd,&tmpopl);
754
755 dbg_printf("adplug_is_our_file(\"%s\"): returned ",filename);
756
757 if(p) {
758 delete p;
759 dbg_printf("TRUE\n");
760 return TRUE;
761 }
762
763 dbg_printf("FALSE\n");
764 return FALSE;
765 }
766
732 static int adplug_get_time(InputPlayback *data) 767 static int adplug_get_time(InputPlayback *data)
733 { 768 {
734 if(audio_error) { dbg_printf("adplug_get_time(): returned -2\n"); return -2; } 769 if(audio_error) { dbg_printf("adplug_get_time(): returned -2\n"); return -2; }
735 if(!plr.playing) { dbg_printf("adplug_get_time(): returned -1\n"); return -1; } 770 if(!plr.playing) { dbg_printf("adplug_get_time(): returned -1\n"); return -1; }
736 return playback->output->output_time(); 771 return playback->output->output_time();
737 } 772 }
738 773
739 static void adplug_song_info(char *filename, char **title, int *length) 774 static void adplug_song_info(char *filename, char **title, int *length)
740 { 775 {
741 CSilentopl tmpopl; 776 CSilentopl tmpopl;
742 CPlayer *p = factory(filename, &tmpopl); 777 VFSFile *fd = vfs_buffered_file_new_from_uri(filename);
778
779 if (!fd) return;
780
781 CPlayer *p = factory(fd, &tmpopl);
743 782
744 dbg_printf("adplug_song_info(\"%s\", \"%s\", %d): ", filename, *title, *length); 783 dbg_printf("adplug_song_info(\"%s\", \"%s\", %d): ", filename, *title, *length);
745 784
746 if(p) { 785 if(p) {
747 // allocate and set title string 786 // allocate and set title string
927 NULL, // add_vis_pcm (filled by XMMS) 966 NULL, // add_vis_pcm (filled by XMMS)
928 NULL, // set_info (filled by XMMS) 967 NULL, // set_info (filled by XMMS)
929 NULL, // set_info_text (filled by XMMS) 968 NULL, // set_info_text (filled by XMMS)
930 adplug_song_info, 969 adplug_song_info,
931 adplug_info_box, // adplug_info_box was here (but it used deprecated GTK+ functions) 970 adplug_info_box, // adplug_info_box was here (but it used deprecated GTK+ functions)
932 NULL // output plugin (filled by XMMS) 971 NULL, // output plugin (filled by XMMS)
972 NULL,
973 NULL,
974 NULL,
975 adplug_is_our_fd,
976 NULL,
933 }; 977 };
934 978
935 extern "C" InputPlugin *get_iplugin_info(void) 979 extern "C" InputPlugin *get_iplugin_info(void)
936 { 980 {
937 return &adplug_ip; 981 return &adplug_ip;