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