comparison src/madplug/plugin.c @ 773:22c82f3c0411 trunk

[svn] - reduce connection latency to http stream. - remove unnecessary functions. - remove redundant dialog which had been shown when madplug failed to open audio output. - some cleanups.
author yaz
date Fri, 02 Mar 2007 20:28:55 -0800
parents 1d3f70ac6b31
children 6f519e34ddf0
comparison
equal deleted inserted replaced
772:18dd1dd2d232 773:22c82f3c0411
384 #ifdef DEBUG 384 #ifdef DEBUG
385 g_message("f: audmad_get_song_info: %s", url); 385 g_message("f: audmad_get_song_info: %s", url);
386 #endif /* DEBUG */ 386 #endif /* DEBUG */
387 387
388 if (input_init(&myinfo, url) == FALSE) { 388 if (input_init(&myinfo, url) == FALSE) {
389 #ifdef DEBUG
389 g_message("error initialising input"); 390 g_message("error initialising input");
390 return;
391 }
392
393 // don't try to get from stopped stream.
394 if(myinfo.remote && (!myinfo.playback || !myinfo.playback->playing)){
395 #ifdef DEBUG
396 g_message("get_song_info: remote and not playing.");
397 #endif 391 #endif
398 return; 392 return;
399 } 393 }
400 394
401 if (input_get_info(&myinfo, info.remote ? TRUE : audmad_config.fast_play_time_calc) == TRUE) { 395 if (input_get_info(&myinfo, info.remote ? TRUE : audmad_config.fast_play_time_calc) == TRUE) {
484 // tuple stuff 478 // tuple stuff
485 static TitleInput *audmad_get_song_tuple(char *filename) 479 static TitleInput *audmad_get_song_tuple(char *filename)
486 { 480 {
487 TitleInput *tuple = NULL; 481 TitleInput *tuple = NULL;
488 gchar *string = NULL; 482 gchar *string = NULL;
489 VFSFile *file;
490 483
491 struct id3_file *id3file = NULL; 484 struct id3_file *id3file = NULL;
492 struct id3_tag *tag = NULL; 485 struct id3_tag *tag = NULL;
493 486
494 #ifdef DEBUG 487 #ifdef DEBUG
525 tuple->file_path = g_path_get_dirname(filename); 518 tuple->file_path = g_path_get_dirname(filename);
526 tuple->file_ext = extname(filename); 519 tuple->file_ext = extname(filename);
527 tuple->length = -1; 520 tuple->length = -1;
528 tuple->mtime = 0; // this indicates streaming 521 tuple->mtime = 0; // this indicates streaming
529 #ifdef DEBUG 522 #ifdef DEBUG
530 g_message("get_song_tuple remote: tuple"); 523 g_message("get_song_tuple: remote: tuple");
531 #endif 524 #endif
532 return tuple; 525 return tuple;
533 } 526 }
534 #ifdef DEBUG 527 #ifdef DEBUG
535 g_message("get_song_tuple: remote: NULL"); 528 g_message("get_song_tuple: remote: NULL");
536 #endif 529 #endif
537 return NULL; 530 return NULL;
538 } 531 }
539 532
540 if ((file = vfs_fopen(filename, "rb")) != NULL) { 533 tuple = bmp_title_input_new();
541 534
542 tuple = bmp_title_input_new(); 535 id3file = id3_file_open(filename, ID3_FILE_MODE_READONLY);
543 id3file = id3_file_open(filename, ID3_FILE_MODE_READONLY); 536 if (id3file) {
544 537
545 if (id3file) { 538 tag = id3_file_tag(id3file);
546 tag = id3_file_tag(id3file); 539 if (tag) {
547 540 tuple->performer =
548 if (tag) { 541 input_id3_get_string(tag, ID3_FRAME_ARTIST);
549 tuple->performer = 542 tuple->album_name =
550 input_id3_get_string(tag, ID3_FRAME_ARTIST); 543 input_id3_get_string(tag, ID3_FRAME_ALBUM);
551 tuple->album_name = 544 tuple->track_name =
552 input_id3_get_string(tag, ID3_FRAME_ALBUM); 545 input_id3_get_string(tag, ID3_FRAME_TITLE);
553 tuple->track_name = 546
554 input_id3_get_string(tag, ID3_FRAME_TITLE); 547 // year
555 548 string = NULL;
556 // year 549 string = input_id3_get_string(tag, ID3_FRAME_YEAR); //TDRC
550 if (!string)
551 string = input_id3_get_string(tag, "TYER");
552
553 if (string) {
554 tuple->year = atoi(string);
555 g_free(string);
557 string = NULL; 556 string = NULL;
558 string = input_id3_get_string(tag, ID3_FRAME_YEAR); //TDRC
559 if (!string)
560 string = input_id3_get_string(tag, "TYER");
561
562 if (string) {
563 tuple->year = atoi(string);
564 g_free(string);
565 string = NULL;
566 }
567
568 tuple->file_name = g_path_get_basename(filename);
569 tuple->file_path = g_path_get_dirname(filename);
570 tuple->file_ext = extname(filename);
571
572 // length
573 tuple->length = -1;
574 string = input_id3_get_string(tag, "TLEN");
575 if (string) {
576 tuple->length = atoi(string);
577 #ifdef DEBUG
578 g_message("get_song_tuple: TLEN = %d", tuple->length);
579 #endif
580 g_free(string);
581 string = NULL;
582 }
583 else {
584 char *dummy = NULL;
585 int length = 0;
586 audmad_get_song_info(filename, &dummy, &length);
587 tuple->length = length;
588 g_free(dummy);
589 }
590
591 // track number
592 string = input_id3_get_string(tag, ID3_FRAME_TRACK);
593 if (string) {
594 tuple->track_number = atoi(string);
595 g_free(string);
596 string = NULL;
597 }
598 // genre
599 tuple->genre = input_id3_get_string(tag, ID3_FRAME_GENRE);
600 #ifdef DEBUG
601 g_message("genre = %s", tuple->genre);
602 #endif
603 // comment
604 tuple->comment =
605 input_id3_get_string(tag, ID3_FRAME_COMMENT);
606
607 } 557 }
608 id3_file_close(id3file); 558
609 }
610 else { // no id3tag
611 tuple->file_name = g_path_get_basename(filename); 559 tuple->file_name = g_path_get_basename(filename);
612 tuple->file_path = g_path_get_dirname(filename); 560 tuple->file_path = g_path_get_dirname(filename);
613 tuple->file_ext = extname(filename); 561 tuple->file_ext = extname(filename);
562
614 // length 563 // length
615 { 564 tuple->length = -1;
565 string = input_id3_get_string(tag, "TLEN");
566 if (string) {
567 tuple->length = atoi(string);
568 #ifdef DEBUG
569 g_message("get_song_tuple: TLEN = %d", tuple->length);
570 #endif
571 g_free(string);
572 string = NULL;
573 }
574 else {
616 char *dummy = NULL; 575 char *dummy = NULL;
617 int length = 0; 576 int length = 0;
618 if(tuple->length == -1) { 577 audmad_get_song_info(filename, &dummy, &length);
619 audmad_get_song_info(filename, &dummy, &length); 578 tuple->length = length;
620 tuple->length = length;
621 }
622 g_free(dummy); 579 g_free(dummy);
623 } 580 }
581
582 // track number
583 string = input_id3_get_string(tag, ID3_FRAME_TRACK);
584 if (string) {
585 tuple->track_number = atoi(string);
586 g_free(string);
587 string = NULL;
588 }
589 // genre
590 tuple->genre = input_id3_get_string(tag, ID3_FRAME_GENRE);
591 #ifdef DEBUG
592 g_message("genre = %s", tuple->genre);
593 #endif
594 // comment
595 tuple->comment =
596 input_id3_get_string(tag, ID3_FRAME_COMMENT);
597
624 } 598 }
625 vfs_fclose(file); 599 id3_file_close(id3file);
600 }
601 else { // no id3tag
602 tuple->file_name = g_path_get_basename(filename);
603 tuple->file_path = g_path_get_dirname(filename);
604 tuple->file_ext = extname(filename);
605 // length
606 {
607 char *dummy = NULL;
608 int length = 0;
609 if(tuple->length == -1) {
610 audmad_get_song_info(filename, &dummy, &length);
611 tuple->length = length;
612 }
613 g_free(dummy);
614 }
626 } 615 }
627 #ifdef DEBUG 616 #ifdef DEBUG
628 g_message("e: mad: audmad_get_song_tuple"); 617 g_message("e: mad: audmad_get_song_tuple");
629 #endif 618 #endif
630 return tuple; 619 return tuple;
631 620 }
632 }
633
634 // probably this function is nolonger needed.
635 #if 0
636 /**
637 * Retrieve meta-information about URL.
638 * For local files this means ID3 tag etc.
639 */
640 gboolean mad_get_info(struct mad_info_t * info, gboolean fast_scan)
641 {
642 TitleInput *tuple = NULL;
643
644 #ifdef DEBUG
645 g_message("f: mad_get_info: %s", info->filename);
646 #endif
647 if (info->remote) {
648 return TRUE;
649 }
650
651 tuple = audmad_get_song_tuple(info->filename);
652
653 info->title = xmms_get_titlestring(audmad_config.title_override == TRUE ?
654 audmad_config.id3_format : xmms_get_gentitle_format(), tuple);
655
656 /* scan mp3 file, decoding headers unless fast_scan is set */
657 if (scan_file(info, fast_scan) == FALSE)
658 return FALSE;
659
660 /* reset the input file to the start */
661 vfs_rewind(info->infile);
662 info->offset = 0;
663
664 /* use the filename for the title as a last resort */
665 if (!info->title)
666 {
667 char *pos = strrchr(info->filename, '/');
668 if (pos)
669 info->title = g_strdup(pos + 1);
670 else
671 info->title = g_strdup(info->filename);
672 }
673
674 #ifdef DEBUG
675 g_message("e: mad_get_info");
676 #endif
677 return TRUE;
678 }
679 #endif
680 621
681 622
682 static gchar *fmts[] = { "mp3", "mp2", "mpg", NULL }; 623 static gchar *fmts[] = { "mp3", "mp2", "mpg", NULL };
683 624
684 InputPlugin *get_iplugin_info(void) 625 InputPlugin *get_iplugin_info(void)