comparison src/mpg123/mpg123.c @ 561:914c96de3244 trunk

[svn] Convert plugins to use InputPlayback.output instead of InputPlugin.output
author iabervon
date Sun, 28 Jan 2007 21:09:12 -0800
parents d5782f3bd760
children 997496d252d4
comparison
equal deleted inserted replaced
560:7b4b37819c9d 561:914c96de3244
352 352
353 return ret; 353 return ret;
354 } 354 }
355 355
356 static void 356 static void
357 play_frame(struct frame *fr) 357 play_frame(InputPlayback *playback, struct frame *fr)
358 { 358 {
359 if (fr->error_protection) { 359 if (fr->error_protection) {
360 bsi.wordpointer += 2; 360 bsi.wordpointer += 2;
361 /* mpgdec_getbits(16); *//* skip crc */ 361 /* mpgdec_getbits(16); *//* skip crc */
362 } 362 }
363 if (!fr->do_layer(fr)) { 363 if (!fr->do_layer(playback, fr)) {
364 skip_frames = 2; 364 skip_frames = 2;
365 mpgdec_info->output_audio = FALSE; 365 mpgdec_info->output_audio = FALSE;
366 } 366 }
367 else { 367 else {
368 if (!skip_frames) 368 if (!skip_frames)
624 624
625 bmp_title_input_free(tuple); 625 bmp_title_input_free(tuple);
626 } 626 }
627 627
628 static int 628 static int
629 open_output(void) 629 open_output(InputPlayback *playback)
630 { 630 {
631 int r; 631 int r;
632 AFormat fmt = mpgdec_cfg.resolution == 16 ? FMT_S16_NE : FMT_U8; 632 AFormat fmt = mpgdec_cfg.resolution == 16 ? FMT_S16_NE : FMT_U8;
633 /* int freq = mpgdec_freqs[fr.sampling_frequency] >> mpgdec_cfg.downsample; */ 633 /* int freq = mpgdec_freqs[fr.sampling_frequency] >> mpgdec_cfg.downsample; */
634 int freq = mpgdec_frequency; 634 int freq = mpgdec_frequency;
635 int channels = mpgdec_cfg.channels == 2 ? fr.stereo : 1; 635 int channels = mpgdec_cfg.channels == 2 ? fr.stereo : 1;
636 r = mpgdec_ip.output->open_audio(fmt, freq, channels); 636 r = playback->output->open_audio(fmt, freq, channels);
637 637
638 if (r && dopause) { 638 if (r && dopause) {
639 mpgdec_ip.output->pause(TRUE); 639 playback->output->pause(TRUE);
640 dopause = FALSE; 640 dopause = FALSE;
641 } 641 }
642 642
643 return r; 643 return r;
644 } 644 }
673 decode_loop(void *arg) 673 decode_loop(void *arg)
674 { 674 {
675 static gchar *old_title = NULL; 675 static gchar *old_title = NULL;
676 gboolean have_xing_header = FALSE, vbr = FALSE; 676 gboolean have_xing_header = FALSE, vbr = FALSE;
677 int disp_count = 0; 677 int disp_count = 0;
678 char *filename = arg; 678 InputPlayback *playback = arg;
679 char *filename = playback->filename;
679 xing_header_t xing_header; 680 xing_header_t xing_header;
680 681
681 /* This is used by fileinfo on http streams */ 682 /* This is used by fileinfo on http streams */
682 mpgdec_bitrate = 0; 683 mpgdec_bitrate = 0;
683 684
784 mpgdec_bitrate * 1000, 785 mpgdec_bitrate * 1000,
785 mpgdec_freqs[fr.sampling_frequency], fr.stereo); 786 mpgdec_freqs[fr.sampling_frequency], fr.stereo);
786 787
787 output_opened = TRUE; 788 output_opened = TRUE;
788 789
789 if (!open_output()) { 790 if (!open_output(playback)) {
790 audio_error = TRUE; 791 audio_error = TRUE;
791 mpgdec_info->eof = TRUE; 792 mpgdec_info->eof = TRUE;
792 } 793 }
793 else 794 else
794 play_frame(&fr); 795 play_frame(playback, &fr);
795 } 796 }
796 797
797 mpgdec_info->first_frame = FALSE; 798 mpgdec_info->first_frame = FALSE;
798 while (mpgdec_info->going) { 799 while (mpgdec_info->going) {
799 if (mpgdec_info->jump_to_time != -1) { 800 if (mpgdec_info->jump_to_time != -1) {
800 void *xp = NULL; 801 void *xp = NULL;
801 if (have_xing_header) 802 if (have_xing_header)
802 xp = &xing_header; 803 xp = &xing_header;
803 if (mpgdec_seek(&fr, xp, vbr, mpgdec_info->jump_to_time) > -1) { 804 if (mpgdec_seek(&fr, xp, vbr, mpgdec_info->jump_to_time) > -1) {
804 mpgdec_ip.output->flush(mpgdec_info->jump_to_time * 1000); 805 playback->output->flush(mpgdec_info->jump_to_time * 1000);
805 mpgdec_info->eof = FALSE; 806 mpgdec_info->eof = FALSE;
806 } 807 }
807 mpgdec_info->jump_to_time = -1; 808 mpgdec_info->jump_to_time = -1;
808 } 809 }
809 if (!mpgdec_info->eof) { 810 if (!mpgdec_info->eof) {
839 if (!have_xing_header 840 if (!have_xing_header
840 && !CHECK_STREAM(filename)) { 841 && !CHECK_STREAM(filename)) {
841 double rel = mpgdec_relative_pos(); 842 double rel = mpgdec_relative_pos();
842 if (rel) { 843 if (rel) {
843 mpgdec_length = 844 mpgdec_length =
844 mpgdec_ip.output->written_time() / rel; 845 playback->output->written_time() / rel;
845 vbr = TRUE; 846 vbr = TRUE;
846 } 847 }
847 848
848 if (rel == 0 || !(mpgdec_length > 0)) { 849 if (rel == 0 || !(mpgdec_length > 0)) {
849 mpgdec_info->num_frames = 850 mpgdec_info->num_frames =
862 } 863 }
863 864
864 } 865 }
865 else 866 else
866 disp_count--; 867 disp_count--;
867 play_frame(&fr); 868 play_frame(playback, &fr);
868 869
869 if (mpgdec_info->filesize == 0) 870 if (mpgdec_info->filesize == 0)
870 { 871 {
871 gchar *new_title = mpgdec_metadata("track-name"); 872 gchar *new_title = mpgdec_metadata("track-name");
872 gchar *srv_name = mpgdec_metadata("stream-name"); 873 gchar *srv_name = mpgdec_metadata("stream-name");
894 mpgdec_frequency, mpgdec_stereo); 895 mpgdec_frequency, mpgdec_stereo);
895 } 896 }
896 } 897 }
897 } 898 }
898 else { 899 else {
899 mpgdec_ip.output->buffer_free(); 900 playback->output->buffer_free();
900 mpgdec_ip.output->buffer_free(); 901 playback->output->buffer_free();
901 mpgdec_info->eof = TRUE; 902 mpgdec_info->eof = TRUE;
902 g_usleep(10000); 903 g_usleep(10000);
903 } 904 }
904 } 905 }
905 else { 906 else {
913 914
914 old_title = NULL; 915 old_title = NULL;
915 mpgdec_title = NULL; 916 mpgdec_title = NULL;
916 mpgdec_stream_close(); 917 mpgdec_stream_close();
917 if (output_opened && !audio_error) 918 if (output_opened && !audio_error)
918 mpgdec_ip.output->close_audio(); 919 playback->output->close_audio();
919 g_free(mpgdec_pcm_sample); 920 g_free(mpgdec_pcm_sample);
920 mpgdec_filename = NULL; 921 mpgdec_filename = NULL;
921 g_free(filename); 922 g_free(filename);
922 923
923 return NULL; 924 return NULL;
924 } 925 }
925 926
926 static void 927 static void
927 play_file(InputPlayback *data) 928 play_file(InputPlayback *playback)
928 { 929 {
929 char *filename = data->filename;
930 memset(&fr, 0, sizeof(struct frame)); 930 memset(&fr, 0, sizeof(struct frame));
931 memset(&temp_fr, 0, sizeof(struct frame)); 931 memset(&temp_fr, 0, sizeof(struct frame));
932 932
933 mpgdec_info = g_malloc0(sizeof(PlayerInfo)); 933 mpgdec_info = g_malloc0(sizeof(PlayerInfo));
934 mpgdec_info->going = 1; 934 mpgdec_info->going = 1;
938 skip_frames = 0; 938 skip_frames = 0;
939 audio_error = FALSE; 939 audio_error = FALSE;
940 output_opened = FALSE; 940 output_opened = FALSE;
941 dopause = FALSE; 941 dopause = FALSE;
942 942
943 decode_thread = g_thread_create(decode_loop, g_strdup(filename), TRUE, 943 decode_thread = g_thread_create(decode_loop, playback, TRUE,
944 NULL); 944 NULL);
945 } 945 }
946 946
947 static void 947 static void
948 stop(InputPlayback * data) 948 stop(InputPlayback * data)
963 while (mpgdec_info->jump_to_time != -1) 963 while (mpgdec_info->jump_to_time != -1)
964 g_usleep(10000); 964 g_usleep(10000);
965 } 965 }
966 966
967 static void 967 static void
968 do_pause(InputPlayback * data, short p) 968 do_pause(InputPlayback * playback, short p)
969 { 969 {
970 if (output_opened) 970 if (output_opened)
971 mpgdec_ip.output->pause(p); 971 playback->output->pause(p);
972 else 972 else
973 dopause = p; 973 dopause = p;
974 } 974 }
975 975
976 static int 976 static int
977 get_time(InputPlayback * data) 977 get_time(InputPlayback * playback)
978 { 978 {
979 if (audio_error) 979 if (audio_error)
980 return -2; 980 return -2;
981 if (!mpgdec_info) 981 if (!mpgdec_info)
982 return -1; 982 return -1;
983 if (!mpgdec_info->going 983 if (!mpgdec_info->going
984 || (mpgdec_info->eof && !mpgdec_ip.output->buffer_playing())) 984 || (mpgdec_info->eof && !playback->output->buffer_playing()))
985 return -1; 985 return -1;
986 return mpgdec_ip.output->output_time(); 986 return playback->output->output_time();
987 } 987 }
988 988
989 static void 989 static void
990 aboutbox(void) 990 aboutbox(void)
991 { 991 {