Mercurial > audlegacy-plugins
annotate src/cdaudio-ng/cdaudio-ng.c @ 1323:50c8594c8836
Automated merge with ssh://hg.atheme.org//hg/audacious-plugins
author | William Pitcock <nenolod@atheme-project.org> |
---|---|
date | Sat, 21 Jul 2007 10:24:22 -0500 |
parents | b93270e2b7e4 |
children | 83cbc6968a0b |
rev | line source |
---|---|
1048 | 1 |
2 /* | |
3 todo: | |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
4 - about dialog |
1048 | 5 */ |
6 | |
7 #include <string.h> | |
8 #include <stdlib.h> | |
9 #include <unistd.h> | |
10 #include <errno.h> | |
11 #include <libgen.h> | |
12 | |
13 #include <cdio/cdio.h> | |
14 #include <cdio/cdtext.h> | |
15 #include <cdio/track.h> | |
16 #include <cdio/cdda.h> | |
17 #include <cdio/audio.h> | |
18 #include <cdio/sector.h> | |
19 #include <cdio/cd_types.h> | |
1282 | 20 #include <cddb/cddb.h> |
1048 | 21 |
22 #include <glib.h> | |
23 | |
24 #include <audacious/i18n.h> | |
25 #include <audacious/configdb.h> | |
1123 | 26 #include <audacious/plugin.h> |
1303 | 27 //#include <audacious/playback.h> // todo: this should be available soon (by 1.4) |
1048 | 28 #include <audacious/util.h> |
29 #include <audacious/output.h> | |
30 | |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
31 #include "cdaudio-ng.h" |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
32 #include "configure.h" |
1123 | 33 |
1048 | 34 |
35 static int firsttrackno = -1; | |
36 static int lasttrackno = -1; | |
1123 | 37 static CdIo_t *pcdio = NULL; |
1048 | 38 static trackinfo_t *trackinfo = NULL; |
1282 | 39 |
1123 | 40 static gboolean use_dae = TRUE; |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
41 static gboolean use_cdtext = TRUE; |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
42 static gboolean use_cddb = TRUE; |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
43 static char device[DEF_STRING_LEN]; |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
44 static int limitspeed = 1; |
1048 | 45 static gboolean is_paused = FALSE; |
46 static int playing_track = -1; | |
1123 | 47 static dae_params_t *pdae_params = NULL; |
1193 | 48 static gboolean debug = FALSE; |
1303 | 49 static char cddb_server[DEF_STRING_LEN]; |
50 static int cddb_port; | |
1313
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
51 static InputPlayback *pglobalinputplayback = NULL; |
1048 | 52 |
53 static void cdaudio_init(); | |
54 static void cdaudio_about(); | |
55 static void cdaudio_configure(); | |
56 static gint cdaudio_is_our_file(gchar *filename); | |
57 static GList *cdaudio_scan_dir(gchar *dirname); | |
58 static void cdaudio_play_file(InputPlayback *pinputplayback); | |
59 static void cdaudio_stop(InputPlayback *pinputplayback); | |
60 static void cdaudio_pause(InputPlayback *pinputplayback, gshort paused); | |
61 static void cdaudio_seek(InputPlayback *pinputplayback, gint time); | |
62 static gint cdaudio_get_time(InputPlayback *pinputplayback); | |
63 static gint cdaudio_get_volume(gint *l, gint *r); | |
64 static gint cdaudio_set_volume(gint l, gint r); | |
65 static void cdaudio_cleanup(); | |
66 static void cdaudio_get_song_info(gchar *filename, gchar **title, gint *length); | |
67 static TitleInput *cdaudio_get_song_tuple(gchar *filename); | |
68 | |
1123 | 69 static void *dae_playing_thread_core(dae_params_t *pdae_params); |
1048 | 70 static int calculate_track_length(int startlsn, int endlsn); |
71 static int find_trackno_from_filename(char *filename); | |
1123 | 72 static void cleanup_on_error(); |
1048 | 73 |
74 | |
75 static InputPlugin inputplugin = { | |
76 NULL, | |
77 NULL, | |
1123 | 78 "CD Audio Plugin NG", |
1048 | 79 cdaudio_init, |
1303 | 80 NULL /*cdaudio_about*/, // todo: implement an about dialog |
1048 | 81 cdaudio_configure, |
82 cdaudio_is_our_file, | |
83 cdaudio_scan_dir, | |
84 cdaudio_play_file, | |
85 cdaudio_stop, | |
86 cdaudio_pause, | |
87 cdaudio_seek, | |
88 NULL, | |
89 cdaudio_get_time, | |
90 cdaudio_get_volume, | |
91 cdaudio_set_volume, | |
92 cdaudio_cleanup, | |
93 NULL, | |
94 NULL, | |
95 NULL, | |
96 NULL, | |
97 cdaudio_get_song_info, | |
1313
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
98 NULL, |
1048 | 99 NULL, |
100 cdaudio_get_song_tuple | |
101 }; | |
102 | |
1098
334afe46961c
[svn] - cdaudio-ng (aka Zither's CD Audio Plugin): convert to plugin API v2
nenolod
parents:
1048
diff
changeset
|
103 InputPlugin *cdaudio_iplist[] = { &inputplugin, NULL }; |
1048 | 104 |
1098
334afe46961c
[svn] - cdaudio-ng (aka Zither's CD Audio Plugin): convert to plugin API v2
nenolod
parents:
1048
diff
changeset
|
105 DECLARE_PLUGIN(cdaudio, NULL, NULL, cdaudio_iplist, NULL, NULL, NULL, NULL); |
1048 | 106 |
1123 | 107 |
1048 | 108 void cdaudio_init() |
109 { | |
1193 | 110 if (debug) |
111 printf("cdaudio-ng: cdaudio_init()\n"); | |
1125 | 112 |
1123 | 113 if (!cdio_init()) { |
114 fprintf(stderr, "cdaudio-ng: failed to initialize cdio subsystem\n"); | |
115 cleanup_on_error(); | |
116 return; | |
117 } | |
1282 | 118 |
119 libcddb_init(); | |
120 | |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
121 ConfigDb *db = bmp_cfg_db_open(); |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
122 gchar *string = NULL; |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
123 |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
124 if (!bmp_cfg_db_get_bool(db, "CDDA", "use_dae", &use_dae)) |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
125 use_dae = TRUE; |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
126 if (!bmp_cfg_db_get_int(db, "CDDA", "limitspeed", &limitspeed)) |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
127 limitspeed = 1; |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
128 if (!bmp_cfg_db_get_bool(db, "CDDA", "use_cdtext", &use_cdtext)) |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
129 use_cdtext = TRUE; |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
130 if (!bmp_cfg_db_get_bool(db, "CDDA", "use_cddb", &use_cddb)) |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
131 use_cddb = TRUE; |
1303 | 132 if (!bmp_cfg_db_get_string(db, "CDDA", "cddbserver", &string)) |
133 strcpy(cddb_server, ""); | |
134 else | |
135 strcpy(cddb_server, string); | |
136 if (!bmp_cfg_db_get_int(db, "CDDA", "cddbport", &cddb_port)) | |
137 cddb_port = 1; | |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
138 if (!bmp_cfg_db_get_string(db, "CDDA", "device", &string)) |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
139 strcpy(device, ""); |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
140 else |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
141 strcpy(device, string); |
1193 | 142 if (!bmp_cfg_db_get_bool(db, "CDDA", "debug", &debug)) |
143 debug = FALSE; | |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
144 |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
145 bmp_cfg_db_close(db); |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
146 |
1193 | 147 if (debug) |
1303 | 148 printf("cdaudio-ng: configuration: use_dae = %d, limitspeed = %d, use_cdtext = %d, use_cddb = %d, cddbserver = \"%s\", cddbport = %d, device = \"%s\", debug = %d\n", use_dae, limitspeed, use_cdtext, use_cddb, cddb_server, cddb_port, device, debug); |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
149 |
1303 | 150 configure_set_variables(&use_dae, &limitspeed, &use_cdtext, &use_cddb, device, &debug, cddb_server, &cddb_port); |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
151 configure_create_gui(); |
1048 | 152 } |
153 | |
154 void cdaudio_about() | |
155 { | |
1193 | 156 if (debug) |
157 printf("cdaudio-ng: cdaudio_about()\n"); | |
1048 | 158 } |
159 | |
160 void cdaudio_configure() | |
161 { | |
1193 | 162 if (debug) |
163 printf("cdaudio-ng: cdaudio_configure()\n"); | |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
164 |
1303 | 165 /* if playback is started, we stop it */ |
166 if (playing_track != -1) | |
167 playback_stop(); | |
168 | |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
169 configure_show_gui(); |
1048 | 170 } |
171 | |
172 gint cdaudio_is_our_file(gchar *filename) | |
173 { | |
1193 | 174 if (debug) |
175 printf("cdaudio-ng: cdaudio_is_our_file(\"%s\")\n", filename); | |
1125 | 176 |
1048 | 177 if ((filename != NULL) && strlen(filename) > 4 && (!strcasecmp(filename + strlen(filename) - 4, ".cda"))) { |
1123 | 178 /* no CD information yet */ |
179 if (pcdio == NULL) { | |
1193 | 180 if (debug) |
181 printf("cdaudio-ng: no cd information, scanning\n"); | |
1125 | 182 cdaudio_scan_dir(CDDA_DEFAULT); |
1048 | 183 } |
1123 | 184 |
185 /* reload the cd information if the media has changed */ | |
1313
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
186 if (cdio_get_media_changed(pcdio) && pcdio != NULL) { |
1193 | 187 if (debug) |
188 printf("cdaudio-ng: cd changed, rescanning\n"); | |
1125 | 189 cdaudio_scan_dir(CDDA_DEFAULT); |
1048 | 190 } |
1313
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
191 |
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
192 if (pcdio == NULL) { |
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
193 if (debug) |
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
194 printf("cdaudio-ng: \"%s\" is not our file\n", filename); |
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
195 return FALSE; |
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
196 } |
1123 | 197 |
198 /* check if the requested track actually exists on the current audio cd */ | |
199 int trackno = find_trackno_from_filename(filename); | |
1125 | 200 if (trackno < firsttrackno || trackno > lasttrackno) { |
1193 | 201 if (debug) |
202 printf("cdaudio-ng: \"%s\" is not our file\n", filename); | |
1123 | 203 return FALSE; |
1125 | 204 } |
1123 | 205 |
1193 | 206 if (debug) |
207 printf("cdaudio-ng: \"%s\" is our file\n", filename); | |
1123 | 208 return TRUE; |
1048 | 209 } |
1125 | 210 else { |
1193 | 211 if (debug) |
212 printf("cdaudio-ng: \"%s\" is not our file\n", filename); | |
1123 | 213 return FALSE; |
1125 | 214 } |
1048 | 215 } |
216 | |
217 GList *cdaudio_scan_dir(gchar *dirname) | |
218 { | |
1193 | 219 if (debug) |
220 printf("cdaudio-ng: cdaudio_scan_dir(\"%s\")\n", dirname); | |
1125 | 221 |
1123 | 222 /* if the given dirname does not belong to us, we return NULL */ |
1125 | 223 if (strstr(dirname, CDDA_DEFAULT) == NULL) { |
1193 | 224 if (debug) |
225 printf("cdaudio-ng: \"%s\" directory does not belong to us\n", dirname); | |
1048 | 226 return NULL; |
1125 | 227 } |
1123 | 228 |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
229 /* find an available, audio capable, cd drive */ |
1282 | 230 if (device != NULL && strlen(device) > 0) { |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
231 pcdio = cdio_open(device, DRIVER_UNKNOWN); |
1282 | 232 if (pcdio == NULL) { |
233 fprintf(stderr, "cdaudio-ng: failed to open cd device \"%s\"\n", device); | |
234 return NULL; | |
235 } | |
236 } | |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
237 else { |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
238 char **ppcd_drives = cdio_get_devices_with_cap(NULL, CDIO_FS_AUDIO, false); |
1313
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
239 pcdio = NULL; |
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
240 if (ppcd_drives != NULL && *ppcd_drives != NULL) { /* we have at least one audio capable cd drive */ |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
241 pcdio = cdio_open(*ppcd_drives, DRIVER_UNKNOWN); |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
242 if (pcdio == NULL) { |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
243 fprintf(stderr, "cdaudio-ng: failed to open cd\n"); |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
244 cleanup_on_error(); |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
245 return NULL; |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
246 } |
1313
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
247 if (debug) |
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
248 printf("cdaudio-ng: found cd drive \"%s\" with audio capable media\n", *ppcd_drives); |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
249 } |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
250 else { |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
251 fprintf(stderr, "cdaudio-ng: unable find or access a cdda capable drive\n"); |
1123 | 252 cleanup_on_error(); |
253 return NULL; | |
254 } | |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
255 cdio_free_device_list(ppcd_drives); |
1048 | 256 } |
257 | |
1193 | 258 /* limit read speed */ |
1282 | 259 if (limitspeed > 0 && !use_dae) { |
1193 | 260 if (debug) |
261 printf("cdaudio-ng: setting drive speed limit to %dx\n", limitspeed); | |
1194 | 262 if (cdio_set_speed(pcdio, limitspeed) != DRIVER_OP_SUCCESS) |
1193 | 263 fprintf(stderr, "cdaudio-ng: failed to set drive speed to %dx\n", limitspeed); |
264 } | |
1282 | 265 |
266 /* get general track initialization */ | |
1194 | 267 cdrom_drive_t *pcdrom_drive = cdio_cddap_identify_cdio(pcdio, 1, NULL); // todo : check return / NULL |
1048 | 268 firsttrackno = cdio_get_first_track_num(pcdrom_drive->p_cdio); |
269 lasttrackno = cdio_get_last_track_num(pcdrom_drive->p_cdio); | |
1123 | 270 if (firsttrackno == CDIO_INVALID_TRACK || lasttrackno == CDIO_INVALID_TRACK) { |
1282 | 271 fprintf(stderr, "cdaudio-ng: failed to retrieve first/last track number\n"); |
1123 | 272 cleanup_on_error(); |
273 return NULL; | |
274 } | |
1193 | 275 if (debug) |
276 printf("cdaudio-ng: first track is %d and last track is %d\n", firsttrackno, lasttrackno); | |
1048 | 277 |
1123 | 278 if (trackinfo != NULL) /* if a previously allocated track information exists, we free it */ |
1048 | 279 free(trackinfo); |
280 trackinfo = (trackinfo_t *) malloc(sizeof(trackinfo_t) * (lasttrackno + 1)); | |
281 int trackno; | |
1282 | 282 |
1303 | 283 trackinfo[0].startlsn = cdio_get_track_lsn(pcdrom_drive->p_cdio, trackno); |
284 trackinfo[0].endlsn = cdio_get_track_last_lsn(pcdrom_drive->p_cdio, CDIO_CDROM_LEADOUT_TRACK); | |
285 strcpy(trackinfo[0].performer, ""); | |
286 strcpy(trackinfo[0].name, ""); | |
287 strcpy(trackinfo[0].genre, ""); | |
1282 | 288 for (trackno = firsttrackno; trackno <= lasttrackno; trackno++) { |
289 trackinfo[trackno].startlsn = cdio_get_track_lsn(pcdrom_drive->p_cdio, trackno); | |
290 trackinfo[trackno].endlsn = cdio_get_track_last_lsn(pcdrom_drive->p_cdio, trackno); | |
1303 | 291 strcpy(trackinfo[trackno].performer, ""); |
292 strcpy(trackinfo[trackno].name, ""); | |
293 strcpy(trackinfo[trackno].genre, ""); | |
1282 | 294 |
295 if (trackinfo[trackno].startlsn == CDIO_INVALID_LSN || trackinfo[trackno].endlsn == CDIO_INVALID_LSN) { | |
296 fprintf(stderr, "cdaudio-ng: failed to retrieve stard/end lsn for track %d\n", trackno); | |
297 cleanup_on_error(); | |
298 return NULL; | |
299 } | |
300 } | |
301 | |
302 /* initialize de cddb subsystem */ | |
303 cddb_conn_t *pcddb_conn = NULL; | |
304 cddb_disc_t *pcddb_disc = NULL; | |
305 cddb_track_t *pcddb_track = NULL; | |
306 | |
307 if (use_cddb) { | |
308 pcddb_conn = cddb_new(); | |
309 if (pcddb_conn == NULL) | |
310 fprintf(stderr, "cdaudio-ng: failed to create the cddb connection\n"); | |
311 else { | |
312 if (debug) | |
313 printf("cdaudio-ng: getting cddb info\n"); | |
314 | |
1303 | 315 cddb_set_server_name(pcddb_conn, cddb_server); |
316 cddb_set_server_port(pcddb_conn, cddb_port); | |
1282 | 317 |
318 pcddb_disc = cddb_disc_new(); | |
319 for (trackno = firsttrackno; trackno <= lasttrackno; trackno++) { | |
320 pcddb_track = cddb_track_new(); | |
321 cddb_track_set_frame_offset(pcddb_track, trackinfo[trackno].startlsn); | |
322 cddb_disc_add_track(pcddb_disc, pcddb_track); | |
323 } | |
324 | |
325 msf_t startmsf, endmsf; | |
326 cdio_get_track_msf(pcdio, 1, &startmsf); | |
327 cdio_get_track_msf(pcdio, CDIO_CDROM_LEADOUT_TRACK, &endmsf); | |
328 cddb_disc_set_length(pcddb_disc, cdio_audio_get_msf_seconds(&endmsf) - cdio_audio_get_msf_seconds(&startmsf)); | |
329 | |
330 int matches; | |
331 if ((matches = cddb_query(pcddb_conn, pcddb_disc)) == -1) { | |
332 fprintf(stderr, "cdaudio-ng: failed to query the cddb server: %s\n", cddb_error_str(cddb_errno(pcddb_conn))); | |
333 cddb_disc_destroy(pcddb_disc); | |
334 pcddb_disc = NULL; | |
335 } | |
336 else { | |
337 if (debug) | |
338 printf("cdaudio-ng: discid = %X, category = \"%s\"\n", cddb_disc_get_discid(pcddb_disc), cddb_disc_get_category_str(pcddb_disc)); | |
339 | |
340 cddb_read(pcddb_conn, pcddb_disc); | |
341 if (cddb_errno(pcddb_conn) != CDDB_ERR_OK) { | |
342 fprintf(stderr, "cdaudio-ng: failed to read the cddb info: %s\n", cddb_error_str(cddb_errno(pcddb_conn))); | |
343 cddb_disc_destroy(pcddb_disc); | |
344 pcddb_disc = NULL; | |
345 } | |
346 else { | |
347 if (debug) | |
348 printf("cdaudio-ng: we have got the cddb info\n"); | |
349 | |
350 strcpy(trackinfo[0].performer, cddb_disc_get_artist(pcddb_disc)); | |
351 strcpy(trackinfo[0].name, cddb_disc_get_title(pcddb_disc)); | |
352 strcpy(trackinfo[0].genre, cddb_disc_get_genre(pcddb_disc)); | |
353 } | |
354 } | |
355 } | |
356 } | |
357 | |
358 /* adding trackinfo[0] information (the disc) */ | |
359 if (use_cdtext) { | |
360 if (debug) | |
361 printf("cdaudio-ng: getting cd-text information for disc\n"); | |
362 cdtext_t *pcdtext = cdio_get_cdtext(pcdrom_drive->p_cdio, 0); | |
363 if (pcdtext == NULL || pcdtext->field[CDTEXT_TITLE] == NULL) { | |
364 if (debug) | |
365 printf("cdaudio-ng: no cd-text available for disc\n"); | |
366 } | |
367 else { | |
368 strcpy(trackinfo[0].performer, pcdtext->field[CDTEXT_PERFORMER] != NULL ? pcdtext->field[CDTEXT_PERFORMER] : ""); | |
369 strcpy(trackinfo[0].name, pcdtext->field[CDTEXT_TITLE] != NULL ? pcdtext->field[CDTEXT_TITLE] : ""); | |
370 strcpy(trackinfo[0].genre, pcdtext->field[CDTEXT_GENRE] != NULL ? pcdtext->field[CDTEXT_GENRE] : ""); | |
371 } | |
372 } | |
373 | |
374 /* add track "file" names to the list */ | |
375 GList *list = NULL; | |
1048 | 376 for (trackno = firsttrackno; trackno <= lasttrackno; trackno++) { |
377 list = g_list_append(list, g_strdup_printf("track%02u.cda", trackno)); | |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
378 cdtext_t *pcdtext = NULL; |
1282 | 379 if (use_cdtext) { |
380 if (debug) | |
381 printf("cdaudio-ng: getting cd-text information for track %d\n", trackno); | |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
382 pcdtext = cdio_get_cdtext(pcdrom_drive->p_cdio, trackno); |
1282 | 383 if (pcdtext == NULL || pcdtext->field[CDTEXT_PERFORMER] == NULL) { |
384 if (debug) | |
385 printf("cdaudio-ng: no cd-text available for track %d\n", trackno); | |
386 pcdtext = NULL; | |
387 } | |
388 } | |
1048 | 389 |
390 if (pcdtext != NULL) { | |
391 strcpy(trackinfo[trackno].performer, pcdtext->field[CDTEXT_PERFORMER] != NULL ? pcdtext->field[CDTEXT_PERFORMER] : ""); | |
392 strcpy(trackinfo[trackno].name, pcdtext->field[CDTEXT_TITLE] != NULL ? pcdtext->field[CDTEXT_TITLE] : ""); | |
393 strcpy(trackinfo[trackno].genre, pcdtext->field[CDTEXT_GENRE] != NULL ? pcdtext->field[CDTEXT_GENRE] : ""); | |
394 } | |
1282 | 395 else |
396 if (pcddb_disc != NULL) { | |
397 cddb_track_t *pcddb_track = cddb_disc_get_track(pcddb_disc, trackno - 1); | |
398 strcpy(trackinfo[trackno].performer, cddb_track_get_artist(pcddb_track)); | |
399 strcpy(trackinfo[trackno].name, cddb_track_get_title(pcddb_track)); | |
400 strcpy(trackinfo[trackno].genre, cddb_disc_get_genre(pcddb_disc)); | |
401 } | |
402 else { | |
403 strcpy(trackinfo[trackno].performer, ""); | |
404 strcpy(trackinfo[trackno].name, ""); | |
405 strcpy(trackinfo[trackno].genre, ""); | |
406 } | |
407 | |
1048 | 408 if (strlen(trackinfo[trackno].name) == 0) |
409 sprintf(trackinfo[trackno].name, "CD Audio Track %02u", trackno); | |
410 | |
1282 | 411 } |
412 | |
413 if (debug) { | |
414 printf("cdaudio-ng: disc has : performer = \"%s\", name = \"%s\", genre = \"%s\"\n", | |
415 trackinfo[0].performer, trackinfo[0].name, trackinfo[0].genre); | |
416 for (trackno = firsttrackno; trackno <= lasttrackno; trackno++) { | |
417 printf("cdaudio-ng: track %d has : performer = \"%s\", name = \"%s\", genre = \"%s\", startlsn = %d, endlsn = %d\n", | |
418 trackno, trackinfo[trackno].performer, trackinfo[trackno].name, trackinfo[trackno].genre, trackinfo[trackno].startlsn, trackinfo[trackno].endlsn); | |
1123 | 419 } |
1282 | 420 } |
1125 | 421 |
1282 | 422 if (pcddb_disc != NULL) |
423 cddb_disc_destroy(pcddb_disc); | |
424 if (pcddb_conn != NULL) | |
425 cddb_destroy(pcddb_conn); | |
1048 | 426 |
427 return list; | |
428 } | |
429 | |
430 void cdaudio_play_file(InputPlayback *pinputplayback) | |
1125 | 431 { |
1193 | 432 if (debug) |
433 printf("cdaudio-ng: cdaudio_play_file(\"%s\")\n", pinputplayback->filename); | |
1313
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
434 |
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
435 pglobalinputplayback = pinputplayback; |
1125 | 436 |
1048 | 437 if (trackinfo == NULL) { |
1193 | 438 if (debug) |
439 printf("cdaudio-ng: no cd information, scanning\n"); | |
1125 | 440 cdaudio_scan_dir(CDDA_DEFAULT); |
1048 | 441 } |
442 | |
1123 | 443 if (cdio_get_media_changed(pcdio)) { |
1193 | 444 if (debug) |
445 printf("cdaudio-ng: cd changed, rescanning\n"); | |
1125 | 446 cdaudio_scan_dir(CDDA_DEFAULT); |
1048 | 447 } |
1123 | 448 |
1048 | 449 int trackno = find_trackno_from_filename(pinputplayback->filename); |
1123 | 450 if (trackno < firsttrackno || trackno > lasttrackno) { |
1125 | 451 fprintf(stderr, "cdaudio-ng: trackno %d is out of range [%d..%d]\n", trackno, firsttrackno, lasttrackno); |
1123 | 452 cleanup_on_error(); |
1048 | 453 return; |
1123 | 454 } |
1048 | 455 |
456 pinputplayback->playing = TRUE; | |
457 playing_track = trackno; | |
1123 | 458 is_paused = FALSE; |
459 | |
460 if (use_dae) { | |
1193 | 461 if (debug) |
462 printf("cdaudio-ng: using digital audio extraction\n"); | |
1125 | 463 |
1123 | 464 if (pdae_params != NULL) { |
465 fprintf(stderr, "cdaudio-ng: dae playback seems to be already started\n"); | |
466 return; | |
467 } | |
468 | |
469 if (pinputplayback->output->open_audio(FMT_S16_LE, 44100, 2) == 0) { | |
470 fprintf(stderr, "cdaudio-ng: failed open audio output\n"); | |
471 cleanup_on_error(); | |
472 return; | |
473 } | |
474 | |
1193 | 475 if (debug) |
476 printf("cdaudio-ng: starting dae thread...\n"); | |
1123 | 477 pdae_params = (dae_params_t *) malloc(sizeof(dae_params_t)); |
478 pdae_params->startlsn = trackinfo[trackno].startlsn; | |
479 pdae_params->endlsn = trackinfo[trackno].endlsn; | |
480 pdae_params->pplayback = pinputplayback; | |
481 pdae_params->seektime = -1; | |
482 pdae_params->currlsn = trackinfo[trackno].startlsn; | |
483 pdae_params->thread = g_thread_create((GThreadFunc) dae_playing_thread_core, pdae_params, TRUE, NULL); | |
484 } | |
485 else { | |
1193 | 486 if (debug) |
487 printf("cdaudio-ng: not using digital audio extraction\n"); | |
1125 | 488 |
1123 | 489 msf_t startmsf, endmsf; |
490 cdio_lsn_to_msf(trackinfo[trackno].startlsn, &startmsf); | |
491 cdio_lsn_to_msf(trackinfo[trackno].endlsn, &endmsf); | |
492 if (cdio_audio_play_msf(pcdio, &startmsf, &endmsf) != DRIVER_OP_SUCCESS) { | |
493 fprintf(stderr, "cdaudio-ng: failed to play analog audio cd\n"); | |
494 cleanup_on_error(); | |
495 return; | |
496 } | |
497 } | |
498 | |
1048 | 499 char title[DEF_STRING_LEN]; |
1123 | 500 |
1048 | 501 if (strlen(trackinfo[trackno].performer) > 0) { |
502 strcpy(title, trackinfo[trackno].performer); | |
503 strcat(title, " - "); | |
504 } | |
505 else | |
506 strcpy(title, ""); | |
507 strcat(title, trackinfo[trackno].name); | |
1123 | 508 |
1048 | 509 inputplugin.set_info(title, calculate_track_length(trackinfo[trackno].startlsn, trackinfo[trackno].endlsn), 128000, 44100, 2); |
510 } | |
511 | |
512 void cdaudio_stop(InputPlayback *pinputplayback) | |
1125 | 513 { |
1193 | 514 if (debug) |
1303 | 515 printf("cdaudio-ng: cdaudio_stop(\"%s\")\n", pinputplayback != NULL ? pinputplayback->filename : "N/A"); |
1313
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
516 |
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
517 pglobalinputplayback = NULL; |
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
518 |
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
519 if (playing_track == -1) |
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
520 return; |
1125 | 521 |
1303 | 522 if (pinputplayback != NULL) |
523 pinputplayback->playing = FALSE; | |
1048 | 524 playing_track = -1; |
1123 | 525 is_paused = FALSE; |
526 | |
527 if (use_dae) { | |
528 if (pdae_params != NULL) { | |
529 g_thread_join(pdae_params->thread); | |
530 free(pdae_params); | |
531 pdae_params = NULL; | |
532 } | |
533 } | |
534 else { | |
535 if (cdio_audio_stop(pcdio) != DRIVER_OP_SUCCESS) { | |
536 fprintf(stderr, "cdaudio-ng: failed to stop analog cd\n"); | |
537 return; | |
538 } | |
539 } | |
1048 | 540 } |
541 | |
542 void cdaudio_pause(InputPlayback *pinputplayback, gshort paused) | |
543 { | |
1193 | 544 if (debug) |
545 printf("cdaudio-ng: cdaudio_pause(\"%s\", %d)\n", pinputplayback->filename, paused); | |
1125 | 546 |
1048 | 547 if (!is_paused) { |
548 is_paused = TRUE; | |
1123 | 549 if (!use_dae) |
550 if (cdio_audio_pause(pcdio) != DRIVER_OP_SUCCESS) { | |
551 fprintf(stderr, "cdaudio-ng: failed to pause analog cd\n"); | |
552 cleanup_on_error(); | |
553 return; | |
554 } | |
1048 | 555 } |
556 else { | |
557 is_paused = FALSE; | |
1123 | 558 if (!use_dae) |
559 if (cdio_audio_resume(pcdio) != DRIVER_OP_SUCCESS) { | |
560 fprintf(stderr, "cdaudio-ng: failed to resume analog cd\n"); | |
561 cleanup_on_error(); | |
562 return; | |
563 } | |
1048 | 564 } |
565 } | |
566 | |
567 void cdaudio_seek(InputPlayback *pinputplayback, gint time) | |
568 { | |
1193 | 569 if (debug) |
570 printf("cdaudio-ng: cdaudio_seek(\"%s\", %d)\n", pinputplayback->filename, time); | |
1125 | 571 |
1048 | 572 if (playing_track == -1) |
573 return; | |
574 | |
1123 | 575 if (use_dae) { |
576 if (pdae_params != NULL) { | |
577 pdae_params->seektime = time * 1000; | |
578 } | |
579 } | |
580 else { | |
581 int newstartlsn = trackinfo[playing_track].startlsn + time * 75; | |
582 msf_t startmsf, endmsf; | |
583 cdio_lsn_to_msf(newstartlsn, &startmsf); | |
584 cdio_lsn_to_msf(trackinfo[playing_track].endlsn, &endmsf); | |
585 | |
586 if (cdio_audio_play_msf(pcdio, &startmsf, &endmsf) != DRIVER_OP_SUCCESS) { | |
587 fprintf(stderr, "cdaudio-ng: failed to play analog cd\n"); | |
588 cleanup_on_error(); | |
589 return; | |
590 } | |
591 } | |
1048 | 592 } |
593 | |
594 gint cdaudio_get_time(InputPlayback *pinputplayback) | |
595 { | |
1125 | 596 //printf("cdaudio-ng: cdaudio_get_time(\"%s\")\n", pinputplayback->filename); // annoying! |
597 | |
1048 | 598 if (playing_track == -1) |
599 return -1; | |
600 | |
1123 | 601 if (!use_dae) { |
602 cdio_subchannel_t subchannel; | |
603 if (cdio_audio_read_subchannel(pcdio, &subchannel) != DRIVER_OP_SUCCESS) { | |
604 fprintf(stderr, "cdaudio-ng: failed to read analog cd subchannel\n"); | |
605 cleanup_on_error(); | |
1313
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
606 return 0; |
1123 | 607 } |
608 int currlsn = cdio_msf_to_lsn(&subchannel.abs_addr); | |
1048 | 609 |
1123 | 610 /* check to see if we have reached the end of the song */ |
1314
b93270e2b7e4
Continuous playing in DAE mode works again
Calin Crisan ccrisan@gmail.com
parents:
1313
diff
changeset
|
611 if (currlsn == trackinfo[playing_track].endlsn) |
1123 | 612 return -1; |
613 | |
614 return calculate_track_length(trackinfo[playing_track].startlsn, currlsn); | |
1048 | 615 } |
1123 | 616 else { |
617 if (pdae_params != NULL) | |
1314
b93270e2b7e4
Continuous playing in DAE mode works again
Calin Crisan ccrisan@gmail.com
parents:
1313
diff
changeset
|
618 if (pdae_params->pplayback->playing) |
b93270e2b7e4
Continuous playing in DAE mode works again
Calin Crisan ccrisan@gmail.com
parents:
1313
diff
changeset
|
619 return pinputplayback->output->output_time(); |
b93270e2b7e4
Continuous playing in DAE mode works again
Calin Crisan ccrisan@gmail.com
parents:
1313
diff
changeset
|
620 else |
b93270e2b7e4
Continuous playing in DAE mode works again
Calin Crisan ccrisan@gmail.com
parents:
1313
diff
changeset
|
621 return -1; |
1123 | 622 else |
623 return -1; | |
624 } | |
1048 | 625 } |
626 | |
627 gint cdaudio_get_volume(gint *l, gint *r) | |
628 { | |
1125 | 629 //printf("cdaudio-ng: cdaudio_get_volume()\n"); // annoying! |
630 | |
1123 | 631 if (use_dae) { |
632 *l = *r = 0; | |
633 return FALSE; | |
634 } | |
635 else { | |
636 cdio_audio_volume_t volume; | |
637 if (cdio_audio_get_volume(pcdio, &volume) != DRIVER_OP_SUCCESS) { | |
638 fprintf(stderr, "cdaudio-ng: failed to retrieve analog cd volume\n"); | |
639 cleanup_on_error(); | |
640 *l = *r = 0; | |
641 return FALSE; | |
642 } | |
643 *l = volume.level[0]; | |
644 *r = volume.level[1]; | |
645 | |
646 return TRUE; | |
647 } | |
1048 | 648 } |
649 | |
650 gint cdaudio_set_volume(gint l, gint r) | |
651 { | |
1193 | 652 if (debug) |
653 printf("cdaudio-ng: cdaudio_set_volume(%d, %d)\n", l, r); | |
1125 | 654 |
1123 | 655 if (use_dae) { |
656 return FALSE; | |
657 } | |
658 else { | |
659 cdio_audio_volume_t volume = {{l, r, 0, 0}}; | |
660 if (cdio_audio_set_volume(pcdio, &volume) != DRIVER_OP_SUCCESS) { | |
661 fprintf(stderr, "cdaudio-ng: failed to set analog cd volume\n"); | |
662 cleanup_on_error(); | |
663 return FALSE; | |
664 } | |
665 | |
666 return TRUE; | |
667 } | |
1048 | 668 } |
669 | |
670 void cdaudio_cleanup() | |
671 { | |
1193 | 672 if (debug) |
673 printf("cdaudio-ng: cdaudio_cleanup()\n"); | |
1125 | 674 |
1282 | 675 libcddb_shutdown(); |
676 | |
1123 | 677 if (pcdio!= NULL) { |
678 if (playing_track != -1 && !use_dae) | |
679 cdio_audio_stop(pcdio); | |
680 cdio_destroy(pcdio); | |
681 pcdio = NULL; | |
682 } | |
683 if (trackinfo != NULL) { | |
684 free(trackinfo); | |
685 trackinfo = NULL; | |
686 } | |
687 playing_track = -1; | |
1282 | 688 |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
689 // todo: destroy the gui |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
690 |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
691 ConfigDb *db = bmp_cfg_db_open(); |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
692 bmp_cfg_db_set_bool(db, "CDDA", "use_dae", use_dae); |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
693 bmp_cfg_db_set_int(db, "CDDA", "limitspeed", limitspeed); |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
694 bmp_cfg_db_set_bool(db, "CDDA", "use_cdtext", use_cdtext); |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
695 bmp_cfg_db_set_bool(db, "CDDA", "use_cddb", use_cddb); |
1303 | 696 bmp_cfg_db_set_string(db, "CDDA", "cddbserver", cddb_server); |
697 bmp_cfg_db_set_int(db, "CDDA", "cddbport", cddb_port); | |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
698 bmp_cfg_db_set_string(db, "CDDA", "device", device); |
1193 | 699 bmp_cfg_db_set_bool(db, "CDDA", "debug", debug); |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
700 bmp_cfg_db_close(db); |
1048 | 701 } |
702 | |
703 void cdaudio_get_song_info(gchar *filename, gchar **title, gint *length) | |
704 { | |
1193 | 705 if (debug) |
706 printf("cdaudio-ng: cdaudio_get_song_info(\"%s\")\n", filename); | |
1125 | 707 |
708 int trackno = find_trackno_from_filename(filename); | |
709 char *thetitle = (char *) malloc(DEF_STRING_LEN); | |
710 | |
711 if (strlen(trackinfo[trackno].performer) > 0) { | |
712 strcpy(thetitle, trackinfo[trackno].performer); | |
713 strcat(thetitle, " - "); | |
714 } | |
715 else | |
716 strcpy(thetitle, ""); | |
717 strcat(thetitle, trackinfo[trackno].name); | |
718 | |
719 *title = thetitle; | |
720 *length = calculate_track_length(trackinfo[trackno].startlsn, trackinfo[trackno].endlsn); | |
1048 | 721 } |
722 | |
723 TitleInput *cdaudio_get_song_tuple(gchar *filename) | |
724 { | |
1193 | 725 if (debug) |
726 printf("cdaudio-ng: cdaudio_get_song_tuple(\"%s\")\n", filename); | |
1125 | 727 |
1048 | 728 TitleInput *tuple = bmp_title_input_new(); |
729 | |
730 /* return information about the requested track */ | |
731 int trackno = find_trackno_from_filename(filename); | |
732 if (trackno < firsttrackno || trackno > lasttrackno) | |
733 return NULL; | |
734 | |
735 tuple->performer = strlen(trackinfo[trackno].performer) > 0 ? g_strdup(trackinfo[trackno].performer) : NULL; | |
1282 | 736 tuple->album_name = strlen(trackinfo[0].name) > 0 ? g_strdup(trackinfo[0].name) : NULL; |
1048 | 737 tuple->track_name = strlen(trackinfo[trackno].name) > 0 ? g_strdup(trackinfo[trackno].name) : NULL; |
738 tuple->track_number = trackno; | |
739 tuple->file_name = g_strdup(basename(filename)); | |
740 tuple->file_path = g_strdup(basename(filename)); | |
741 tuple->file_ext = g_strdup("cda"); | |
742 tuple->length = calculate_track_length(trackinfo[trackno].startlsn, trackinfo[trackno].endlsn); | |
743 tuple->genre = strlen(trackinfo[trackno].genre) > 0 ? g_strdup(trackinfo[trackno].genre) : NULL; | |
744 //tuple->year = 0; todo: set the year | |
745 | |
746 return tuple; | |
747 } | |
748 | |
749 | |
750 /* auxiliar functions */ | |
751 | |
1123 | 752 void *dae_playing_thread_core(dae_params_t *pdae_params) |
753 { | |
754 unsigned char *buffer = (unsigned char *) malloc(CDDA_DAE_FRAMES * CDIO_CD_FRAMESIZE_RAW); | |
755 | |
1193 | 756 if (debug) |
757 printf("cdaudio-ng: dae thread started\n"); | |
1123 | 758 cdio_lseek(pcdio, pdae_params->startlsn * CDIO_CD_FRAMESIZE_RAW, SEEK_SET); |
759 | |
760 gboolean output_paused = FALSE; | |
1313
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
761 int read_error_counter = 0; |
1125 | 762 |
1123 | 763 while (pdae_params->pplayback->playing) { |
764 /* handle pause status */ | |
765 if (is_paused) { | |
766 if (!output_paused) { | |
1193 | 767 if (debug) |
768 printf("cdaudio-ng: playback was not paused, pausing\n"); | |
1123 | 769 pdae_params->pplayback->output->pause(TRUE); |
770 output_paused = TRUE; | |
771 } | |
772 usleep(1000); | |
773 continue; | |
774 } | |
1125 | 775 else { |
1123 | 776 if (output_paused) { |
1193 | 777 if (debug) |
778 printf("cdaudio-ng: playback was paused, resuming\n"); | |
1123 | 779 pdae_params->pplayback->output->pause(FALSE); |
780 output_paused = FALSE; | |
781 } | |
1125 | 782 } |
1123 | 783 |
784 /* check if we have to seek */ | |
785 if (pdae_params->seektime != -1) { | |
1193 | 786 if (debug) |
787 printf("cdaudio-ng: requested seek to %d ms\n", pdae_params->seektime); | |
1123 | 788 int newlsn = pdae_params->startlsn + pdae_params->seektime * 75 / 1000; |
789 cdio_lseek(pcdio, newlsn * CDIO_CD_FRAMESIZE_RAW, SEEK_SET); | |
790 pdae_params->pplayback->output->flush(pdae_params->seektime); | |
791 pdae_params->currlsn = newlsn; | |
792 pdae_params->seektime = -1; | |
793 } | |
794 | |
795 /* compute the actual number of sectors to read */ | |
796 int lsncount = CDDA_DAE_FRAMES <= (pdae_params->endlsn - pdae_params->currlsn + 1) ? CDDA_DAE_FRAMES : (pdae_params->endlsn - pdae_params->currlsn + 1); | |
797 /* check too see if we have reached the end of the song */ | |
798 if (lsncount <= 0) | |
799 break; | |
800 | |
801 if (cdio_read_audio_sectors(pcdio, buffer, pdae_params->currlsn, lsncount) != DRIVER_OP_SUCCESS) { | |
802 fprintf(stderr, "cdaudio-ng: failed to read audio sector\n"); | |
1313
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
803 read_error_counter++; |
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
804 if (read_error_counter >= 2) { |
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
805 fprintf(stderr, "cdaudio-ng: this cd can no longer be played, stopping\n"); |
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
806 break; |
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
807 } |
1123 | 808 } |
1313
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
809 else |
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
810 read_error_counter = 0; |
1123 | 811 |
812 int remainingbytes = lsncount * CDIO_CD_FRAMESIZE_RAW; | |
813 unsigned char *bytebuff = buffer; | |
814 while (pdae_params->pplayback->playing && remainingbytes > 0 && pdae_params->seektime == -1) { | |
815 /* compute the actual number of bytes to play */ | |
816 int bytecount = CDIO_CD_FRAMESIZE_RAW <= remainingbytes ? CDIO_CD_FRAMESIZE_RAW : remainingbytes; | |
817 /* wait until the output buffer has enough room */ | |
818 while (pdae_params->pplayback->playing && pdae_params->pplayback->output->buffer_free() < bytecount && pdae_params->seektime == -1) | |
819 usleep(1000); | |
820 /* play the sound :) */ | |
821 if (pdae_params->pplayback->playing && pdae_params->seektime == -1) | |
822 produce_audio(pdae_params->pplayback->output->written_time(), FMT_S16_LE, 2, bytecount, bytebuff, &pdae_params->pplayback->playing); | |
823 remainingbytes -= bytecount; | |
824 bytebuff += bytecount; | |
825 } | |
826 pdae_params->currlsn += lsncount; | |
827 } | |
1193 | 828 if (debug) |
829 printf("cdaudio-ng: dae thread ended\n"); | |
1123 | 830 |
831 pdae_params->pplayback->playing = FALSE; | |
1314
b93270e2b7e4
Continuous playing in DAE mode works again
Calin Crisan ccrisan@gmail.com
parents:
1313
diff
changeset
|
832 pdae_params->pplayback->output->close_audio(); |
1123 | 833 is_paused = FALSE; |
834 | |
835 pdae_params->pplayback->output->close_audio(); | |
836 free(buffer); | |
837 | |
838 g_thread_exit(NULL); | |
839 return NULL; | |
840 } | |
841 | |
1048 | 842 int calculate_track_length(int startlsn, int endlsn) |
843 { | |
844 return ((endlsn - startlsn + 1) * 1000) / 75; | |
845 } | |
846 | |
847 int find_trackno_from_filename(char *filename) | |
848 { | |
849 if ((filename == NULL) || strlen(filename) <= 6) | |
850 return -1; | |
851 | |
852 char tracknostr[3]; | |
853 strncpy(tracknostr, filename + strlen(filename) - 6, 2); | |
854 tracknostr[2] = '\0'; | |
855 return strtol(tracknostr, NULL, 10); | |
856 } | |
1123 | 857 |
858 void cleanup_on_error() | |
859 { | |
1313
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
860 if (playing_track != -1) { |
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
861 playing_track = -1; |
1314
b93270e2b7e4
Continuous playing in DAE mode works again
Calin Crisan ccrisan@gmail.com
parents:
1313
diff
changeset
|
862 playback_stop(); |
1123 | 863 } |
1313
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
864 |
1123 | 865 if (trackinfo != NULL) { |
866 free(trackinfo); | |
867 trackinfo = NULL; | |
868 } | |
869 } | |
1193 | 870 |