comparison src/madplug/plugin.c @ 2214:9a869d4bb0d3

make use of AUDDBG() for debug print out.
author Yoshiki Yazawa <yaz@cc.rim.or.jp>
date Thu, 06 Dec 2007 23:25:24 +0900
parents 0b67fb27db58
children a5c96af75300
comparison
equal deleted inserted replaced
2213:137187e7a379 2214:9a869d4bb0d3
17 * You should have received a copy of the GNU General Public License 17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software 18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */ 20 */
21 21
22 /* #define AUD_DEBUG 1 */
23
22 #include "config.h" 24 #include "config.h"
23 #include "plugin.h" 25 #include "plugin.h"
24 #include "input.h" 26 #include "input.h"
25 27
26 #include <math.h> 28 #include <math.h>
100 if ( text != NULL ) 102 if ( text != NULL )
101 x = g_strtod(text, NULL); 103 x = g_strtod(text, NULL);
102 else 104 else
103 x = 0; 105 x = 0;
104 config->pregain_scale = (x != 0) ? pow(10.0, x / 20) : 1; 106 config->pregain_scale = (x != 0) ? pow(10.0, x / 20) : 1;
105 #ifdef DEBUG 107 AUDDBG("pregain=[%s] -> %g -> %g", text, x, config->pregain_scale);
106 g_message("pregain=[%s] -> %g -> %g", text, x, config->pregain_scale);
107 #endif
108 text = config->replaygain.default_db; 108 text = config->replaygain.default_db;
109 if ( text != NULL ) 109 if ( text != NULL )
110 x = g_strtod(text, NULL); 110 x = g_strtod(text, NULL);
111 else 111 else
112 x = 0; 112 x = 0;
113 config->replaygain.default_scale = (x != 0) ? pow(10.0, x / 20) : 1; 113 config->replaygain.default_scale = (x != 0) ? pow(10.0, x / 20) : 1;
114 #ifdef DEBUG 114 AUDDBG("RG.default=[%s] -> %g -> %g", text, x,
115 g_message("RG.default=[%s] -> %g -> %g", text, x,
116 config->replaygain.default_scale); 115 config->replaygain.default_scale);
117 #endif
118 } 116 }
119 117
120 static void audmad_init() 118 static void audmad_init()
121 { 119 {
122 ConfigDb *db = NULL; 120 ConfigDb *db = NULL;
403 return rtn; 401 return rtn;
404 } 402 }
405 403
406 static void audmad_stop(InputPlayback *playback) 404 static void audmad_stop(InputPlayback *playback)
407 { 405 {
408 #ifdef DEBUG 406 AUDDBG("f: audmad_stop");
409 g_message("f: audmad_stop");
410 #endif
411 g_mutex_lock(mad_mutex); 407 g_mutex_lock(mad_mutex);
412 info.playback = playback; 408 info.playback = playback;
413 g_mutex_unlock(mad_mutex); 409 g_mutex_unlock(mad_mutex);
414 410
415 if (decode_thread) { 411 if (decode_thread) {
417 g_mutex_lock(mad_mutex); 413 g_mutex_lock(mad_mutex);
418 info.playback->playing = 0; 414 info.playback->playing = 0;
419 g_mutex_unlock(mad_mutex); 415 g_mutex_unlock(mad_mutex);
420 g_cond_signal(mad_cond); 416 g_cond_signal(mad_cond);
421 417
422 #ifdef DEBUG 418 AUDDBG("waiting for thread");
423 g_message("waiting for thread");
424 #endif
425 g_thread_join(decode_thread); 419 g_thread_join(decode_thread);
426 #ifdef DEBUG 420 AUDDBG("thread done");
427 g_message("thread done"); 421
428 #endif
429 input_term(&info); 422 input_term(&info);
430 decode_thread = NULL; 423 decode_thread = NULL;
431 424
432 } 425 }
433 #ifdef DEBUG 426 AUDDBG("e: audmad_stop");
434 g_message("e: audmad_stop");
435 #endif
436 } 427 }
437 428
438 static void audmad_play_file(InputPlayback *playback) 429 static void audmad_play_file(InputPlayback *playback)
439 { 430 {
440 gboolean rtn; 431 gboolean rtn;
441 gchar *url = playback->filename; 432 gchar *url = playback->filename;
442 433
443 #ifdef DEBUG 434 #ifdef AUD_DEBUG
444 { 435 {
445 gchar *tmp = g_filename_to_utf8(url, -1, NULL, NULL, NULL); 436 gchar *tmp = g_filename_to_utf8(url, -1, NULL, NULL, NULL);
446 g_message("playing %s", tmp); 437 AUDDBG("playing %s", tmp);
447 g_free(tmp); 438 g_free(tmp);
448 } 439 }
449 #endif /* DEBUG */ 440 #endif /* DEBUG */
450 441
451 if (input_init(&info, url, NULL) == FALSE) { 442 if (input_init(&info, url, NULL) == FALSE) {
501 */ 492 */
502 static void 493 static void
503 audmad_get_song_info(char *url, char **title, int *length) 494 audmad_get_song_info(char *url, char **title, int *length)
504 { 495 {
505 struct mad_info_t myinfo; 496 struct mad_info_t myinfo;
506 #ifdef DEBUG 497 #ifdef AUD_DEBUG
507 gchar *tmp = g_filename_to_utf8(url, -1, NULL, NULL, NULL); 498 gchar *tmp = g_filename_to_utf8(url, -1, NULL, NULL, NULL);
508 g_message("f: audmad_get_song_info: %s", tmp); 499 AUDDBG("f: audmad_get_song_info: %s", tmp);
509 g_free(tmp); 500 g_free(tmp);
510 #endif /* DEBUG */ 501 #endif /* DEBUG */
511 502
512 if (input_init(&myinfo, url, NULL) == FALSE) { 503 if (input_init(&myinfo, url, NULL) == FALSE) {
513 #ifdef DEBUG 504 AUDDBG("error initialising input");
514 g_message("error initialising input");
515 #endif
516 return; 505 return;
517 } 506 }
518 507
519 if (input_get_info(&myinfo, info.remote ? TRUE : audmad_config.fast_play_time_calc) == TRUE) { 508 if (input_get_info(&myinfo, info.remote ? TRUE : audmad_config.fast_play_time_calc) == TRUE) {
520 if(aud_tuple_get_string(myinfo.tuple, -1, "track-name")) 509 if(aud_tuple_get_string(myinfo.tuple, -1, "track-name"))
529 else { 518 else {
530 *title = g_strdup(url); 519 *title = g_strdup(url);
531 *length = -1; 520 *length = -1;
532 } 521 }
533 input_term(&myinfo); 522 input_term(&myinfo);
534 #ifdef DEBUG 523 AUDDBG("e: audmad_get_song_info");
535 g_message("e: audmad_get_song_info");
536 #endif /* DEBUG */
537 } 524 }
538 525
539 static gboolean 526 static gboolean
540 audmad_fill_info(struct mad_info_t *info, VFSFile *fd) 527 audmad_fill_info(struct mad_info_t *info, VFSFile *fd)
541 { 528 {
542 if (fd == NULL || info == NULL) return FALSE; 529 if (fd == NULL || info == NULL) return FALSE;
543 #ifdef DEBUG 530 AUDDBG("f: audmad_fill_info(): %s", fd->uri);
544 g_message("f: audmad_fill_info(): %s", fd->uri);
545 #endif
546 531
547 if (input_init(info, fd->uri, fd) == FALSE) { 532 if (input_init(info, fd->uri, fd) == FALSE) {
548 #ifdef DEBUG 533 AUDDBG("audmad_fill_info(): error initialising input");
549 g_message("audmad_fill_info(): error initialising input");
550 #endif
551 return FALSE; 534 return FALSE;
552 } 535 }
553 536
554 info->fileinfo_request = FALSE; /* we don't need to read tuple again */ 537 info->fileinfo_request = FALSE; /* we don't need to read tuple again */
555 return input_get_info(info, aud_vfs_is_remote(fd->uri) ? TRUE : audmad_config.fast_play_time_calc); 538 return input_get_info(info, aud_vfs_is_remote(fd->uri) ? TRUE : audmad_config.fast_play_time_calc);
635 struct mad_info_t myinfo; 618 struct mad_info_t myinfo;
636 619
637 gboolean local_fd = FALSE; 620 gboolean local_fd = FALSE;
638 int length; 621 int length;
639 622
640 #ifdef DEBUG 623 #ifdef AUD_DEBUG
641 string = aud_str_to_utf8(filename); 624 string = aud_str_to_utf8(filename);
642 g_message("f: mad: audmad_get_song_tuple: %s", string); 625 AUDDBG("f: mad: audmad_get_song_tuple: %s", string);
643 g_free(string); 626 g_free(string);
644 string = NULL; 627 string = NULL;
645 #endif 628 #endif
646 629
647 /* isn't is obfuscated? --eugene */ 630 /* isn't is obfuscated? --eugene */
649 if(info.remote && mad_timer_count(info.duration, MAD_UNITS_SECONDS) <= 0){ 632 if(info.remote && mad_timer_count(info.duration, MAD_UNITS_SECONDS) <= 0){
650 if((fd && aud_vfs_is_streaming(fd)) || (info.playback && info.playback->playing)) { 633 if((fd && aud_vfs_is_streaming(fd)) || (info.playback && info.playback->playing)) {
651 gchar *tmp = NULL; 634 gchar *tmp = NULL;
652 tuple = aud_tuple_new_from_filename(filename); 635 tuple = aud_tuple_new_from_filename(filename);
653 636
654 #ifdef DEBUG 637 #ifdef AUD_DEBUG
655 if(info.playback) 638 if(info.playback)
656 g_message("info.playback->playing = %d",info.playback->playing); 639 AUDDBG("info.playback->playing = %d",info.playback->playing);
657 #endif 640 #endif
658 tmp = aud_vfs_get_metadata(info.infile ? info.infile : fd, "track-name"); 641 tmp = aud_vfs_get_metadata(info.infile ? info.infile : fd, "track-name");
659 if(tmp){ 642 if(tmp){
660 gchar *scratch; 643 gchar *scratch;
661 644
676 g_free(scratch); 659 g_free(scratch);
677 660
678 tmp = NULL; 661 tmp = NULL;
679 } 662 }
680 663
681 #ifdef DEBUG 664 AUDDBG("audmad_get_song_tuple: track_name = %s", aud_tuple_get_string(tuple, -1, "track-name"));
682 g_message("audmad_get_song_tuple: track_name = %s", aud_tuple_get_string(tuple, -1, "track-name")); 665 AUDDBG("audmad_get_song_tuple: stream_name = %s", aud_tuple_get_string(tuple, -1, "stream-name"));
683 g_message("audmad_get_song_tuple: stream_name = %s", aud_tuple_get_string(tuple, -1, "stream-name"));
684 #endif
685 aud_tuple_associate_int(tuple, FIELD_LENGTH, NULL, -1); 666 aud_tuple_associate_int(tuple, FIELD_LENGTH, NULL, -1);
686 aud_tuple_associate_int(tuple, FIELD_MTIME, NULL, 0); // this indicates streaming 667 aud_tuple_associate_int(tuple, FIELD_MTIME, NULL, 0); // this indicates streaming
687 #ifdef DEBUG 668 AUDDBG("get_song_tuple: remote: tuple");
688 g_message("get_song_tuple: remote: tuple");
689 #endif
690 return tuple; 669 return tuple;
691 } 670 }
692 #ifdef DEBUG 671 AUDDBG("get_song_tuple: remote: NULL");
693 g_message("get_song_tuple: remote: NULL");
694 #endif
695 // return NULL;
696 } /* info.remote */ 672 } /* info.remote */
697 673
698 // if !fd, pre-open the file with aud_vfs_fopen() and reuse fd. 674 // if !fd, pre-open the file with aud_vfs_fopen() and reuse fd.
699 if(!fd) { 675 if(!fd) {
700 fd = aud_vfs_fopen(filename, "rb"); 676 fd = aud_vfs_fopen(filename, "rb");
702 return NULL; 678 return NULL;
703 local_fd = TRUE; 679 local_fd = TRUE;
704 } 680 }
705 681
706 if (!audmad_fill_info(&myinfo, fd)) { 682 if (!audmad_fill_info(&myinfo, fd)) {
707 #ifdef DEBUG 683 AUDDBG("get_song_tuple: error obtaining info\n");
708 g_message("get_song_tuple: error obtaining info\n");
709 #endif
710 if (local_fd) aud_vfs_fclose(fd); 684 if (local_fd) aud_vfs_fclose(fd);
711 return NULL; 685 return NULL;
712 } 686 }
713 687
714 tuple = aud_tuple_new(); 688 tuple = aud_tuple_new();
753 string = NULL; 727 string = NULL;
754 } 728 }
755 // genre 729 // genre
756 __set_and_free(tuple, FIELD_GENRE, NULL, input_id3_get_string(tag, ID3_FRAME_GENRE)); 730 __set_and_free(tuple, FIELD_GENRE, NULL, input_id3_get_string(tag, ID3_FRAME_GENRE));
757 __set_and_free(tuple, FIELD_COMMENT, NULL, input_id3_get_string(tag, ID3_FRAME_COMMENT)); 731 __set_and_free(tuple, FIELD_COMMENT, NULL, input_id3_get_string(tag, ID3_FRAME_COMMENT));
758 #ifdef DEBUG 732 AUDDBG("genre = %s", aud_tuple_get_string(tuple, FIELD_GENRE, NULL));
759 g_message("genre = %s", aud_tuple_get_string(tuple, FIELD_GENRE, NULL));
760 #endif
761 } 733 }
762 id3_file_close(id3file); 734 id3_file_close(id3file);
763 } // id3file 735 } // id3file
764 else { // no id3tag 736 else { // no id3tag
765 realfn = g_filename_from_uri(filename, NULL, NULL); 737 realfn = g_filename_from_uri(filename, NULL, NULL);
785 input_term(&myinfo); 757 input_term(&myinfo);
786 758
787 if(local_fd) 759 if(local_fd)
788 aud_vfs_fclose(fd); 760 aud_vfs_fclose(fd);
789 761
790 #ifdef DEBUG 762 AUDDBG("e: mad: audmad_get_song_tuple");
791 g_message("e: mad: audmad_get_song_tuple");
792 #endif
793 return tuple; 763 return tuple;
794 } 764 }
795 765
796 static Tuple *audmad_get_song_tuple(char *filename) 766 static Tuple *audmad_get_song_tuple(char *filename)
797 { 767 {