comparison src/cdaudio/cdaudio.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 daa0323924d6
comparison
equal deleted inserted replaced
560:7b4b37819c9d 561:914c96de3244
115 static void cdda_pause(InputPlayback *playback, short p); 115 static void cdda_pause(InputPlayback *playback, short p);
116 static void seek(InputPlayback *playback, int time); 116 static void seek(InputPlayback *playback, int time);
117 static int get_time(InputPlayback *playback); 117 static int get_time(InputPlayback *playback);
118 static void get_song_info(char *filename, char **title, int *length); 118 static void get_song_info(char *filename, char **title, int *length);
119 static TitleInput *get_song_tuple(char *filename); 119 static TitleInput *get_song_tuple(char *filename);
120 static void get_volume(int *l, int *r); 120 static gint get_volume(int *l, int *r);
121 static void set_volume(int l, int r); 121 static gint set_volume(int l, int r);
122 static void cleanup(void); 122 static void cleanup(void);
123 void cdda_fileinfo(char *filename); 123 void cdda_fileinfo(char *filename);
124 124
125 InputPlugin cdda_ip = { 125 InputPlugin cdda_ip = {
126 NULL, 126 NULL,
855 else 855 else
856 return (LBA(toc->track[track + 1]) - LBA(toc->track[track])); 856 return (LBA(toc->track[track + 1]) - LBA(toc->track[track]));
857 } 857 }
858 858
859 static void * 859 static void *
860 dae_play_loop(void *arg) 860 dae_play_loop(void *data)
861 { 861 {
862 InputPlayback *playback = data;
862 char *buffer = g_malloc(CD_FRAMESIZE_RAW * CDDA_DAE_FRAMES); 863 char *buffer = g_malloc(CD_FRAMESIZE_RAW * CDDA_DAE_FRAMES);
863 int pos = LBA(cdda_playing.cd_toc.track[cdda_playing.track]); 864 int pos = LBA(cdda_playing.cd_toc.track[cdda_playing.track]);
864 int end, frames; 865 int end, frames;
865 866
866 if (cdda_playing.track == cdda_playing.cd_toc.last_track) 867 if (cdda_playing.track == cdda_playing.cd_toc.last_track)
871 while (cdda_playing.playing) { 872 while (cdda_playing.playing) {
872 int left; 873 int left;
873 char *data; 874 char *data;
874 875
875 if (dae_data.seek != -1) { 876 if (dae_data.seek != -1) {
876 cdda_ip.output->flush(dae_data.seek * 1000); 877 playback->output->flush(dae_data.seek * 1000);
877 pos = LBA(cdda_playing.cd_toc.track[cdda_playing.track]) 878 pos = LBA(cdda_playing.cd_toc.track[cdda_playing.track])
878 + dae_data.seek * 75; 879 + dae_data.seek * 75;
879 dae_data.seek = -1; 880 dae_data.seek = -1;
880 dae_data.eof = FALSE; 881 dae_data.eof = FALSE;
881 } 882 }
907 } 908 }
908 left = frames * CD_FRAMESIZE_RAW; 909 left = frames * CD_FRAMESIZE_RAW;
909 data = buffer; 910 data = buffer;
910 while (cdda_playing.playing && left > 0 && dae_data.seek == -1) { 911 while (cdda_playing.playing && left > 0 && dae_data.seek == -1) {
911 int cur = MIN(512 * 2 * 2, left); 912 int cur = MIN(512 * 2 * 2, left);
912 cdda_ip.add_vis_pcm(cdda_ip.output->written_time(), 913 cdda_ip.add_vis_pcm(playback->output->written_time(),
913 FMT_S16_LE, 2, cur, data); 914 FMT_S16_LE, 2, cur, data);
914 while (cdda_ip.output->buffer_free() < cur && 915 while (playback->output->buffer_free() < cur &&
915 cdda_playing.playing && dae_data.seek == -1) 916 cdda_playing.playing && dae_data.seek == -1)
916 xmms_usleep(30000); 917 xmms_usleep(30000);
917 if (cdda_playing.playing && dae_data.seek == -1) 918 if (cdda_playing.playing && dae_data.seek == -1)
918 produce_audio(cdda_ip.output->written_time(), FMT_S16_LE, 2, cur, data, &cdda_playing.playing); 919 produce_audio(playback->output->written_time(), FMT_S16_LE, 2, cur, data, &cdda_playing.playing);
919 left -= cur; 920 left -= cur;
920 data += cur; 921 data += cur;
921 } 922 }
922 pos += frames; 923 pos += frames;
923 } 924 }
924 925
925 cdda_ip.output->buffer_free(); 926 playback->output->buffer_free();
926 cdda_ip.output->buffer_free(); 927 playback->output->buffer_free();
927 g_free(buffer); 928 g_free(buffer);
928 929
929 g_thread_exit(NULL); 930 g_thread_exit(NULL);
930 return NULL; 931 return NULL;
931 } 932 }
932 933
933 static void 934 static void
934 dae_play(void) 935 dae_play(InputPlayback *playback)
935 { 936 {
936 if (cdda_ip.output->open_audio(FMT_S16_LE, 44100, 2) == 0) { 937 if (playback->output->open_audio(FMT_S16_LE, 44100, 2) == 0) {
937 dae_data.audio_error = TRUE; 938 dae_data.audio_error = TRUE;
938 cdda_playing.playing = FALSE; 939 cdda_playing.playing = FALSE;
939 return; 940 return;
940 } 941 }
941 dae_data.seek = -1; 942 dae_data.seek = -1;
942 dae_data.eof = FALSE; 943 dae_data.eof = FALSE;
943 dae_data.audio_error = FALSE; 944 dae_data.audio_error = FALSE;
944 dae_data.thread = g_thread_create(dae_play_loop, NULL, TRUE, NULL); 945 dae_data.thread = g_thread_create(dae_play_loop, playback, TRUE, NULL);
945 } 946 }
946 947
947 static void 948 static void
948 play_file(InputPlayback *playback) 949 play_file(InputPlayback *playback)
949 { 950 {
1000 is_paused = FALSE; 1001 is_paused = FALSE;
1001 timeout_remove_for_device(drive->device); 1002 timeout_remove_for_device(drive->device);
1002 1003
1003 cdda_playing.playing = TRUE; 1004 cdda_playing.playing = TRUE;
1004 if (drive->dae) 1005 if (drive->dae)
1005 dae_play(); 1006 dae_play(playback);
1006 else 1007 else
1007 seek(playback, 0); 1008 seek(playback, 0);
1008 return; 1009 return;
1009 } 1010 }
1010 1011
1089 timeout_destroy(to); 1090 timeout_destroy(to);
1090 return FALSE; 1091 return FALSE;
1091 } 1092 }
1092 1093
1093 static void 1094 static void
1094 stop(InputPlayback * data) 1095 stop(InputPlayback * playback)
1095 { 1096 {
1096 struct timeout *to_info; 1097 struct timeout *to_info;
1097 if (cdda_playing.fd < 0) 1098 if (cdda_playing.fd < 0)
1098 return; 1099 return;
1099 1100
1100 cdda_playing.playing = FALSE; 1101 cdda_playing.playing = FALSE;
1101 1102
1102 if (cdda_playing.drive.dae) { 1103 if (cdda_playing.drive.dae) {
1103 g_thread_join(dae_data.thread); 1104 g_thread_join(dae_data.thread);
1104 cdda_ip.output->close_audio(); 1105 playback->output->close_audio();
1105 } 1106 }
1106 else 1107 else
1107 ioctl(cdda_playing.fd, XMMS_PAUSE, 0); 1108 ioctl(cdda_playing.fd, XMMS_PAUSE, 0);
1108 1109
1109 close(cdda_playing.fd); 1110 close(cdda_playing.fd);
1117 timeout_list = g_list_prepend(timeout_list, to_info); 1118 timeout_list = g_list_prepend(timeout_list, to_info);
1118 } 1119 }
1119 } 1120 }
1120 1121
1121 static void 1122 static void
1122 cdda_pause(InputPlayback *data, short p) 1123 cdda_pause(InputPlayback *playback, short p)
1123 { 1124 {
1124 if (cdda_playing.drive.dae) { 1125 if (cdda_playing.drive.dae) {
1125 cdda_ip.output->pause(p); 1126 playback->output->pause(p);
1126 return; 1127 return;
1127 } 1128 }
1128 if (p) { 1129 if (p) {
1129 pause_time = get_time(data); 1130 pause_time = get_time(playback);
1130 ioctl(cdda_playing.fd, XMMS_PAUSE, 0); 1131 ioctl(cdda_playing.fd, XMMS_PAUSE, 0);
1131 } 1132 }
1132 else { 1133 else {
1133 ioctl(cdda_playing.fd, XMMS_RESUME, 0); 1134 ioctl(cdda_playing.fd, XMMS_RESUME, 0);
1134 pause_time = -1; 1135 pause_time = -1;
1191 1192
1192 return ((frame - start_frame) * 1000) / 75; 1193 return ((frame - start_frame) * 1000) / 75;
1193 } 1194 }
1194 1195
1195 static int 1196 static int
1196 get_time_dae(void) 1197 get_time_dae(InputPlayback *playback)
1197 { 1198 {
1198 if (dae_data.audio_error) 1199 if (dae_data.audio_error)
1199 return -2; 1200 return -2;
1200 if (!cdda_playing.playing || 1201 if (!cdda_playing.playing ||
1201 (dae_data.eof && !cdda_ip.output->buffer_playing())) 1202 (dae_data.eof && !playback->output->buffer_playing()))
1202 return -1; 1203 return -1;
1203 return cdda_ip.output->output_time(); 1204 return playback->output->output_time();
1204 } 1205 }
1205 1206
1206 static int 1207 static int
1207 get_time(InputPlayback *playback) 1208 get_time(InputPlayback *playback)
1208 { 1209 {
1209 if (cdda_playing.fd == -1) 1210 if (cdda_playing.fd == -1)
1210 return -1; 1211 return -1;
1211 1212
1212 if (cdda_playing.drive.dae) 1213 if (cdda_playing.drive.dae)
1213 return get_time_dae(); 1214 return get_time_dae(playback);
1214 else 1215 else
1215 return get_time_analog(); 1216 return get_time_analog();
1216 } 1217 }
1217 1218
1218 static void 1219 static void
1322 { 1323 {
1323 } 1324 }
1324 #endif 1325 #endif
1325 1326
1326 1327
1327 static void 1328 static gint
1328 get_volume(int *l, int *r) 1329 get_volume(int *l, int *r)
1329 { 1330 {
1330 if (cdda_playing.drive.dae) 1331 if (cdda_playing.drive.dae)
1331 cdda_ip.output->get_volume(l, r); 1332 return 0;
1332 else if (cdda_playing.drive.mixer == CDDA_MIXER_OSS) 1333 else if (cdda_playing.drive.mixer == CDDA_MIXER_OSS)
1333 oss_get_volume(l, r, cdda_playing.drive.oss_mixer); 1334 oss_get_volume(l, r, cdda_playing.drive.oss_mixer);
1334 else if (cdda_playing.drive.mixer == CDDA_MIXER_DRIVE) 1335 else if (cdda_playing.drive.mixer == CDDA_MIXER_DRIVE)
1335 drive_get_volume(l, r); 1336 drive_get_volume(l, r);
1336 } 1337 return 1;
1337 1338 }
1338 static void 1339
1340 static gint
1339 set_volume(int l, int r) 1341 set_volume(int l, int r)
1340 { 1342 {
1341 if (cdda_playing.drive.dae) 1343 if (cdda_playing.drive.dae)
1342 cdda_ip.output->set_volume(l, r); 1344 return 0;
1343 else if (cdda_playing.drive.mixer == CDDA_MIXER_OSS) 1345 else if (cdda_playing.drive.mixer == CDDA_MIXER_OSS)
1344 oss_set_volume(l, r, cdda_playing.drive.oss_mixer); 1346 oss_set_volume(l, r, cdda_playing.drive.oss_mixer);
1345 else if (cdda_playing.drive.mixer == CDDA_MIXER_DRIVE) 1347 else if (cdda_playing.drive.mixer == CDDA_MIXER_DRIVE)
1346 drive_set_volume(l, r); 1348 drive_set_volume(l, r);
1347 } 1349 return 1;
1350 }