comparison src/mpg123/mpg123.c @ 562:997496d252d4 trunk

[svn] Use InputPlayback standard flags in mpg123, drop set_time().
author iabervon
date Sun, 28 Jan 2007 22:14:55 -0800
parents 914c96de3244
children c5022551db57
comparison
equal deleted inserted replaced
561:914c96de3244 562:997496d252d4
31 static struct frame fr, temp_fr; 31 static struct frame fr, temp_fr;
32 32
33 PlayerInfo *mpgdec_info = NULL; 33 PlayerInfo *mpgdec_info = NULL;
34 static GThread *decode_thread; 34 static GThread *decode_thread;
35 35
36 static gboolean audio_error = FALSE, output_opened = FALSE, dopause = FALSE; 36 static gboolean output_opened = FALSE, dopause = FALSE;
37 gint mpgdec_bitrate, mpgdec_frequency, mpgdec_length, mpgdec_layer, 37 gint mpgdec_bitrate, mpgdec_frequency, mpgdec_length, mpgdec_layer,
38 mpgdec_lsf; 38 mpgdec_lsf;
39 gchar *mpgdec_title = NULL, *mpgdec_filename = NULL; 39 gchar *mpgdec_title = NULL, *mpgdec_filename = NULL;
40 static int disp_bitrate, skip_frames = 0; 40 static int disp_bitrate, skip_frames = 0;
41 static int cpu_fflags, cpu_efflags; 41 static int cpu_fflags, cpu_efflags;
643 return r; 643 return r;
644 } 644 }
645 645
646 646
647 static int 647 static int
648 mpgdec_seek(struct frame *fr, xing_header_t * xh, gboolean vbr, int time) 648 mpgdec_seek(InputPlayback *playback, struct frame *fr, xing_header_t * xh,
649 gboolean vbr, int time)
649 { 650 {
650 int jumped = -1; 651 int jumped = -1;
651 652
652 if (xh) { 653 if (xh) {
653 int percent = ((double) time * 100.0) / 654 int percent = ((double) time * 100.0) /
654 (mpgdec_info->num_frames * mpgdec_info->tpf); 655 (mpgdec_info->num_frames * mpgdec_info->tpf);
655 int byte = mpgdec_seek_point(xh, percent); 656 int byte = mpgdec_seek_point(xh, percent);
656 jumped = mpgdec_stream_jump_to_byte(fr, byte); 657 jumped = mpgdec_stream_jump_to_byte(playback, fr, byte);
657 } 658 }
658 else if (vbr && mpgdec_length > 0) { 659 else if (vbr && mpgdec_length > 0) {
659 int byte = ((guint64) time * 1000 * mpgdec_info->filesize) / 660 int byte = ((guint64) time * 1000 * mpgdec_info->filesize) /
660 mpgdec_length; 661 mpgdec_length;
661 jumped = mpgdec_stream_jump_to_byte(fr, byte); 662 jumped = mpgdec_stream_jump_to_byte(playback, fr, byte);
662 } 663 }
663 else { 664 else {
664 int frame = time / mpgdec_info->tpf; 665 int frame = time / mpgdec_info->tpf;
665 jumped = mpgdec_stream_jump_to_frame(fr, frame); 666 jumped = mpgdec_stream_jump_to_frame(playback, fr, frame);
666 } 667 }
667 668
668 return jumped; 669 return jumped;
669 } 670 }
670 671
686 mpgdec_pcm_point = 0; 687 mpgdec_pcm_point = 0;
687 mpgdec_filename = filename; 688 mpgdec_filename = filename;
688 689
689 mpgdec_read_frame_init(); 690 mpgdec_read_frame_init();
690 691
691 mpgdec_open_stream(filename, -1, 0); 692 mpgdec_open_stream(playback, filename, -1, 0);
692 693
693 if (mpgdec_info->eof || !mpgdec_read_frame(&fr)) 694 if (playback->eof || !mpgdec_read_frame(&fr))
694 mpgdec_info->eof = TRUE; 695 playback->eof = TRUE;
695 696
696 if (!mpgdec_info->eof && mpgdec_info->going) { 697 if (!playback->eof && playback->playing) {
697 if (mpgdec_cfg.channels == 2) 698 if (mpgdec_cfg.channels == 2)
698 fr.single = -1; 699 fr.single = -1;
699 else 700 else
700 fr.single = 3; 701 fr.single = 3;
701 702
713 } 714 }
714 715
715 for (;;) { 716 for (;;) {
716 memcpy(&temp_fr, &fr, sizeof(struct frame)); 717 memcpy(&temp_fr, &fr, sizeof(struct frame));
717 if (!mpgdec_read_frame(&temp_fr)) { 718 if (!mpgdec_read_frame(&temp_fr)) {
718 mpgdec_info->eof = TRUE; 719 playback->eof = TRUE;
719 break; 720 break;
720 } 721 }
721 if (fr.lay != temp_fr.lay || 722 if (fr.lay != temp_fr.lay ||
722 fr.sampling_frequency != temp_fr.sampling_frequency || 723 fr.sampling_frequency != temp_fr.sampling_frequency ||
723 fr.stereo != temp_fr.stereo || fr.lsf != temp_fr.lsf) 724 fr.stereo != temp_fr.stereo || fr.lsf != temp_fr.lsf)
786 mpgdec_freqs[fr.sampling_frequency], fr.stereo); 787 mpgdec_freqs[fr.sampling_frequency], fr.stereo);
787 788
788 output_opened = TRUE; 789 output_opened = TRUE;
789 790
790 if (!open_output(playback)) { 791 if (!open_output(playback)) {
791 audio_error = TRUE; 792 playback->error = TRUE;
792 mpgdec_info->eof = TRUE; 793 playback->eof = TRUE;
793 } 794 }
794 else 795 else
795 play_frame(playback, &fr); 796 play_frame(playback, &fr);
796 } 797 }
797 798
798 mpgdec_info->first_frame = FALSE; 799 mpgdec_info->first_frame = FALSE;
799 while (mpgdec_info->going) { 800 while (playback->playing) {
800 if (mpgdec_info->jump_to_time != -1) { 801 if (mpgdec_info->jump_to_time != -1) {
801 void *xp = NULL; 802 void *xp = NULL;
802 if (have_xing_header) 803 if (have_xing_header)
803 xp = &xing_header; 804 xp = &xing_header;
804 if (mpgdec_seek(&fr, xp, vbr, mpgdec_info->jump_to_time) > -1) { 805 if (mpgdec_seek(playback, &fr, xp, vbr,
806 mpgdec_info->jump_to_time) > -1) {
805 playback->output->flush(mpgdec_info->jump_to_time * 1000); 807 playback->output->flush(mpgdec_info->jump_to_time * 1000);
806 mpgdec_info->eof = FALSE; 808 playback->eof = FALSE;
807 } 809 }
808 mpgdec_info->jump_to_time = -1; 810 mpgdec_info->jump_to_time = -1;
809 } 811 }
810 if (!mpgdec_info->eof) { 812 if (!playback->eof) {
811 if (mpgdec_read_frame(&fr) != 0) { 813 if (mpgdec_read_frame(&fr) != 0) {
812 if (fr.lay != mpgdec_layer || fr.lsf != mpgdec_lsf) { 814 if (fr.lay != mpgdec_layer || fr.lsf != mpgdec_lsf) {
813 memcpy(&temp_fr, &fr, sizeof(struct frame)); 815 memcpy(&temp_fr, &fr, sizeof(struct frame));
814 if (mpgdec_read_frame(&temp_fr) != 0) { 816 if (mpgdec_read_frame(&temp_fr) != 0) {
815 if (fr.lay == temp_fr.lay && fr.lsf == temp_fr.lsf) { 817 if (fr.lay == temp_fr.lay && fr.lsf == temp_fr.lsf) {
897 } 899 }
898 } 900 }
899 else { 901 else {
900 playback->output->buffer_free(); 902 playback->output->buffer_free();
901 playback->output->buffer_free(); 903 playback->output->buffer_free();
902 mpgdec_info->eof = TRUE; 904 playback->eof = TRUE;
903 g_usleep(10000); 905 g_usleep(10000);
904 } 906 }
905 } 907 }
906 else { 908 else {
907 g_usleep(10000); 909 g_usleep(10000);
913 g_free(old_title); 915 g_free(old_title);
914 916
915 old_title = NULL; 917 old_title = NULL;
916 mpgdec_title = NULL; 918 mpgdec_title = NULL;
917 mpgdec_stream_close(); 919 mpgdec_stream_close();
918 if (output_opened && !audio_error) 920 if (output_opened && !playback->error)
919 playback->output->close_audio(); 921 playback->output->close_audio();
920 g_free(mpgdec_pcm_sample); 922 g_free(mpgdec_pcm_sample);
921 mpgdec_filename = NULL; 923 mpgdec_filename = NULL;
922 g_free(filename);
923 924
924 return NULL; 925 return NULL;
925 } 926 }
926 927
927 static void 928 static void
929 { 930 {
930 memset(&fr, 0, sizeof(struct frame)); 931 memset(&fr, 0, sizeof(struct frame));
931 memset(&temp_fr, 0, sizeof(struct frame)); 932 memset(&temp_fr, 0, sizeof(struct frame));
932 933
933 mpgdec_info = g_malloc0(sizeof(PlayerInfo)); 934 mpgdec_info = g_malloc0(sizeof(PlayerInfo));
934 mpgdec_info->going = 1; 935 mpgdec_info->playback = playback;
936 playback->playing = TRUE;
935 mpgdec_info->first_frame = TRUE; 937 mpgdec_info->first_frame = TRUE;
936 mpgdec_info->output_audio = TRUE; 938 mpgdec_info->output_audio = TRUE;
937 mpgdec_info->jump_to_time = -1; 939 mpgdec_info->jump_to_time = -1;
938 skip_frames = 0; 940 skip_frames = 0;
939 audio_error = FALSE; 941 playback->error = FALSE;
940 output_opened = FALSE; 942 output_opened = FALSE;
941 dopause = FALSE; 943 dopause = FALSE;
942 944
943 decode_thread = g_thread_create(decode_loop, playback, TRUE, 945 decode_thread = g_thread_create(decode_loop, playback, TRUE,
944 NULL); 946 NULL);
945 } 947 }
946 948
947 static void 949 static void
948 stop(InputPlayback * data) 950 stop(InputPlayback * playback)
949 { 951 {
950 if (mpgdec_info && mpgdec_info->going) { 952 if (mpgdec_info && playback->playing) {
951 mpgdec_info->going = FALSE; 953 playback->playing = FALSE;
952 g_thread_join(decode_thread); 954 g_thread_join(decode_thread);
953 g_free(mpgdec_info); 955 g_free(mpgdec_info);
954 mpgdec_info = NULL; 956 mpgdec_info = NULL;
955 } 957 }
956 } 958 }
969 { 971 {
970 if (output_opened) 972 if (output_opened)
971 playback->output->pause(p); 973 playback->output->pause(p);
972 else 974 else
973 dopause = p; 975 dopause = p;
974 }
975
976 static int
977 get_time(InputPlayback * playback)
978 {
979 if (audio_error)
980 return -2;
981 if (!mpgdec_info)
982 return -1;
983 if (!mpgdec_info->going
984 || (mpgdec_info->eof && !playback->output->buffer_playing()))
985 return -1;
986 return playback->output->output_time();
987 } 976 }
988 977
989 static void 978 static void
990 aboutbox(void) 979 aboutbox(void)
991 { 980 {
1020 play_file, 1009 play_file,
1021 stop, 1010 stop,
1022 do_pause, 1011 do_pause,
1023 seek, 1012 seek,
1024 NULL, 1013 NULL,
1025 get_time, 1014 NULL,
1026 NULL, NULL, 1015 NULL, NULL,
1027 cleanup, 1016 cleanup,
1028 NULL, 1017 NULL,
1029 NULL, NULL, NULL, 1018 NULL, NULL, NULL,
1030 get_song_info, 1019 get_song_info,