Mercurial > audlegacy-plugins
comparison src/madplug/plugin.c @ 1329:4b07404814ca
- reduce the number of file open in loading.
- make use of new vfs_is_remote() and vfs_is_streaming().
| author | Yoshiki Yazawa <yaz@cc.rim.or.jp> |
|---|---|
| date | Sun, 22 Jul 2007 22:21:28 +0900 |
| parents | 38fb3bb3e21e |
| children | ebded68de2dd f8b498451a84 |
comparison
equal
deleted
inserted
replaced
| 1328:38fb3bb3e21e | 1329:4b07404814ca |
|---|---|
| 286 ((unsigned long) hbuf[2] << 8) | (unsigned long) hbuf[3]; | 286 ((unsigned long) hbuf[2] << 8) | (unsigned long) hbuf[3]; |
| 287 } | 287 } |
| 288 | 288 |
| 289 gboolean audmad_is_remote(gchar *url) | 289 gboolean audmad_is_remote(gchar *url) |
| 290 { | 290 { |
| 291 if (!strncasecmp("http://", url, 7) | 291 gboolean rv = vfs_is_remote(url); |
| 292 || !strncasecmp("https://", url, 8) | 292 return rv; |
| 293 || !strncasecmp("lastfm://", url, 9)) | |
| 294 return TRUE; | |
| 295 else | |
| 296 return FALSE; | |
| 297 } | 293 } |
| 298 | 294 |
| 299 // audacious vfs fast version | 295 // audacious vfs fast version |
| 300 static int audmad_is_our_fd(char *filename, VFSFile *fin) | 296 static int audmad_is_our_fd(char *filename, VFSFile *fin) |
| 301 { | 297 { |
| 636 gchar *realfn = NULL; | 632 gchar *realfn = NULL; |
| 637 | 633 |
| 638 struct id3_file *id3file = NULL; | 634 struct id3_file *id3file = NULL; |
| 639 struct id3_tag *tag = NULL; | 635 struct id3_tag *tag = NULL; |
| 640 | 636 |
| 637 gboolean local_fd = FALSE; | |
| 638 | |
| 641 #ifdef DEBUG | 639 #ifdef DEBUG |
| 642 string = str_to_utf8(filename); | 640 string = str_to_utf8(filename); |
| 643 g_message("f: mad: audmad_get_song_tuple: %s", string); | 641 g_message("f: mad: audmad_get_song_tuple: %s", string); |
| 644 g_free(string); | 642 g_free(string); |
| 645 string = NULL; | 643 string = NULL; |
| 646 #endif | 644 #endif |
| 647 | 645 |
| 648 if(info.remote && mad_timer_count(info.duration, MAD_UNITS_SECONDS) <= 0){ | 646 if(info.remote && mad_timer_count(info.duration, MAD_UNITS_SECONDS) <= 0){ |
| 649 if(fd || (info.playback && info.playback->playing)) { | 647 if((fd && vfs_is_streaming(fd)) || (info.playback && info.playback->playing)) { |
| 650 gchar *tmp = NULL; | 648 gchar *tmp = NULL; |
| 651 tuple = bmp_title_input_new(); | 649 tuple = bmp_title_input_new(); |
| 652 | 650 |
| 653 #ifdef DEBUG | 651 #ifdef DEBUG |
| 654 if(info.playback) | 652 if(info.playback) |
| 690 return NULL; | 688 return NULL; |
| 691 } /* info.remote */ | 689 } /* info.remote */ |
| 692 | 690 |
| 693 tuple = bmp_title_input_new(); | 691 tuple = bmp_title_input_new(); |
| 694 | 692 |
| 695 if (!fd) | 693 // if !fd, pre-open the file with vfs_fopen() and reuse fd. |
| 696 id3file = id3_file_open(filename, ID3_FILE_MODE_READONLY); | 694 if(!fd) { |
| 697 else | 695 fd = vfs_fopen(filename, "rb"); |
| 698 id3file = id3_file_vfsopen(fd, ID3_FILE_MODE_READONLY); | 696 if(!fd) |
| 697 return NULL; | |
| 698 local_fd = TRUE; | |
| 699 } | |
| 700 | |
| 701 id3file = id3_file_vfsopen(fd, ID3_FILE_MODE_READONLY); | |
| 699 | 702 |
| 700 if (id3file) { | 703 if (id3file) { |
| 701 | 704 |
| 702 tag = id3_file_tag(id3file); | 705 tag = id3_file_tag(id3file); |
| 703 if (tag) { | 706 if (tag) { |
| 737 string = NULL; | 740 string = NULL; |
| 738 } | 741 } |
| 739 else { | 742 else { |
| 740 char *dummy = NULL; | 743 char *dummy = NULL; |
| 741 int length = 0; | 744 int length = 0; |
| 742 audmad_get_song_length(filename, &length, fd ? fd : NULL); | 745 audmad_get_song_length(filename, &length, fd); |
| 743 tuple->length = length; | 746 tuple->length = length; |
| 744 g_free(dummy); | 747 g_free(dummy); |
| 745 } | 748 } |
| 746 | 749 |
| 747 // track number | 750 // track number |
| 760 tuple->comment = | 763 tuple->comment = |
| 761 input_id3_get_string(tag, ID3_FRAME_COMMENT); | 764 input_id3_get_string(tag, ID3_FRAME_COMMENT); |
| 762 | 765 |
| 763 } | 766 } |
| 764 id3_file_close(id3file); | 767 id3_file_close(id3file); |
| 765 } | 768 } // id3file |
| 766 else { // no id3tag | 769 else { // no id3tag |
| 767 realfn = g_filename_from_uri(filename, NULL, NULL); | 770 realfn = g_filename_from_uri(filename, NULL, NULL); |
| 768 tuple->file_name = g_path_get_basename(realfn ? realfn : filename); | 771 tuple->file_name = g_path_get_basename(realfn ? realfn : filename); |
| 769 tuple->file_path = g_path_get_dirname(realfn ? realfn : filename); | 772 tuple->file_path = g_path_get_dirname(realfn ? realfn : filename); |
| 770 tuple->file_ext = extname(realfn ? realfn : filename); | 773 tuple->file_ext = extname(realfn ? realfn : filename); |
| 772 // length | 775 // length |
| 773 { | 776 { |
| 774 char *dummy = NULL; | 777 char *dummy = NULL; |
| 775 int length = 0; | 778 int length = 0; |
| 776 if(tuple->length == -1) { | 779 if(tuple->length == -1) { |
| 777 audmad_get_song_length(filename, &length, fd ? fd : NULL); | 780 audmad_get_song_length(filename, &length, fd); |
| 778 tuple->length = length; | 781 tuple->length = length; |
| 779 } | 782 } |
| 780 g_free(dummy); | 783 g_free(dummy); |
| 781 } | 784 } |
| 782 } | 785 } |
| 786 | |
| 787 if(local_fd) | |
| 788 vfs_fclose(fd); | |
| 789 | |
| 783 #ifdef DEBUG | 790 #ifdef DEBUG |
| 784 g_message("e: mad: audmad_get_song_tuple"); | 791 g_message("e: mad: audmad_get_song_tuple"); |
| 785 #endif | 792 #endif |
| 786 return tuple; | 793 return tuple; |
| 787 } | 794 } |
