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