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