Mercurial > audlegacy-plugins
annotate src/cdaudio-ng/cdaudio-ng.c @ 2057:cf4fa45ffd80
playlist API vtabling
author | William Pitcock <nenolod@atheme.org> |
---|---|
date | Sat, 13 Oct 2007 23:09:40 -0500 |
parents | 2f2ffbc2d04d |
children | 04421592e6a3 |
rev | line source |
---|---|
1508
a99d8f3b3e7c
Fixed some dos/windows eols
Calin Crisan ccrisan@gmail.com
parents:
1490
diff
changeset
|
1 /* |
a99d8f3b3e7c
Fixed some dos/windows eols
Calin Crisan ccrisan@gmail.com
parents:
1490
diff
changeset
|
2 * Audacious CD Digital Audio plugin |
a99d8f3b3e7c
Fixed some dos/windows eols
Calin Crisan ccrisan@gmail.com
parents:
1490
diff
changeset
|
3 * |
a99d8f3b3e7c
Fixed some dos/windows eols
Calin Crisan ccrisan@gmail.com
parents:
1490
diff
changeset
|
4 * Copyright (c) 2007 Calin Crisan <ccrisan@gmail.com> |
a99d8f3b3e7c
Fixed some dos/windows eols
Calin Crisan ccrisan@gmail.com
parents:
1490
diff
changeset
|
5 * |
a99d8f3b3e7c
Fixed some dos/windows eols
Calin Crisan ccrisan@gmail.com
parents:
1490
diff
changeset
|
6 * This program is free software; you can redistribute it and/or modify |
a99d8f3b3e7c
Fixed some dos/windows eols
Calin Crisan ccrisan@gmail.com
parents:
1490
diff
changeset
|
7 * it under the terms of the GNU General Public License as published by |
a99d8f3b3e7c
Fixed some dos/windows eols
Calin Crisan ccrisan@gmail.com
parents:
1490
diff
changeset
|
8 * the Free Software Foundation; under version 3 of the License. |
a99d8f3b3e7c
Fixed some dos/windows eols
Calin Crisan ccrisan@gmail.com
parents:
1490
diff
changeset
|
9 * |
a99d8f3b3e7c
Fixed some dos/windows eols
Calin Crisan ccrisan@gmail.com
parents:
1490
diff
changeset
|
10 * This program is distributed in the hope that it will be useful, |
a99d8f3b3e7c
Fixed some dos/windows eols
Calin Crisan ccrisan@gmail.com
parents:
1490
diff
changeset
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
a99d8f3b3e7c
Fixed some dos/windows eols
Calin Crisan ccrisan@gmail.com
parents:
1490
diff
changeset
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
a99d8f3b3e7c
Fixed some dos/windows eols
Calin Crisan ccrisan@gmail.com
parents:
1490
diff
changeset
|
13 * GNU General Public License for more details. |
a99d8f3b3e7c
Fixed some dos/windows eols
Calin Crisan ccrisan@gmail.com
parents:
1490
diff
changeset
|
14 * |
a99d8f3b3e7c
Fixed some dos/windows eols
Calin Crisan ccrisan@gmail.com
parents:
1490
diff
changeset
|
15 * You should have received a copy of the GNU General Public License |
a99d8f3b3e7c
Fixed some dos/windows eols
Calin Crisan ccrisan@gmail.com
parents:
1490
diff
changeset
|
16 * along with this program. If not, see <http://www.gnu.org/licenses>. |
a99d8f3b3e7c
Fixed some dos/windows eols
Calin Crisan ccrisan@gmail.com
parents:
1490
diff
changeset
|
17 */ |
1490
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
18 |
2049
9550e809dc12
Added a short TODO comment section.
Matti Hamalainen <ccr@tnsp.org>
parents:
2048
diff
changeset
|
19 /* TODO (added by ccr) |
9550e809dc12
Added a short TODO comment section.
Matti Hamalainen <ccr@tnsp.org>
parents:
2048
diff
changeset
|
20 * - DAE seems to be always used, does analog mode work at all? |
9550e809dc12
Added a short TODO comment section.
Matti Hamalainen <ccr@tnsp.org>
parents:
2048
diff
changeset
|
21 * - maybe make CDDB lib optional? |
9550e809dc12
Added a short TODO comment section.
Matti Hamalainen <ccr@tnsp.org>
parents:
2048
diff
changeset
|
22 * - use_cddb/use_cdtext don't seem to be checked in all necessary places. why? |
9550e809dc12
Added a short TODO comment section.
Matti Hamalainen <ccr@tnsp.org>
parents:
2048
diff
changeset
|
23 */ |
9550e809dc12
Added a short TODO comment section.
Matti Hamalainen <ccr@tnsp.org>
parents:
2048
diff
changeset
|
24 |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
25 #include "config.h" |
1048 | 26 |
27 #include <string.h> | |
28 #include <stdlib.h> | |
29 #include <unistd.h> | |
30 #include <errno.h> | |
31 #include <libgen.h> | |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
32 #include <stdarg.h> |
1048 | 33 |
34 #include <cdio/cdio.h> | |
35 #include <cdio/cdtext.h> | |
36 #include <cdio/track.h> | |
37 #include <cdio/cdda.h> | |
38 #include <cdio/audio.h> | |
39 #include <cdio/sector.h> | |
40 #include <cdio/cd_types.h> | |
1282 | 41 #include <cddb/cddb.h> |
1048 | 42 |
43 #include <glib.h> | |
44 | |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
45 #include <audacious/plugin.h> |
1048 | 46 #include <audacious/i18n.h> |
1529 | 47 #include <audacious/output.h> |
48 #include <audacious/playlist.h> | |
49 #include <audacious/ui_plugin_menu.h> | |
1048 | 50 #include <audacious/util.h> |
51 | |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
52 #include "cdaudio-ng.h" |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
53 #include "configure.h" |
1123 | 54 |
2046 | 55 struct cdng_cfg_t cdng_cfg; |
2047 | 56 static gint firsttrackno = -1; |
57 static gint lasttrackno = -1; | |
1123 | 58 static CdIo_t *pcdio = NULL; |
1048 | 59 static trackinfo_t *trackinfo = NULL; |
60 static gboolean is_paused = FALSE; | |
2047 | 61 static gint playing_track = -1; |
1123 | 62 static dae_params_t *pdae_params = NULL; |
2047 | 63 static InputPlayback *pglobalinputplayback = NULL; |
1490
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
64 static GtkWidget *main_menu_item, *playlist_menu_item; |
1048 | 65 |
2047 | 66 static void cdaudio_init(void); |
67 static void cdaudio_about(void); | |
68 static void cdaudio_configure(void); | |
69 static gint cdaudio_is_our_file(gchar *filename); | |
1048 | 70 static GList *cdaudio_scan_dir(gchar *dirname); |
2047 | 71 static void cdaudio_play_file(InputPlayback *pinputplayback); |
72 static void cdaudio_stop(InputPlayback *pinputplayback); | |
73 static void cdaudio_pause(InputPlayback *pinputplayback, gshort paused); | |
74 static void cdaudio_seek(InputPlayback *pinputplayback, gint time); | |
75 static gint cdaudio_get_time(InputPlayback *pinputplayback); | |
76 static gint cdaudio_get_volume(gint *l, gint *r); | |
77 static gint cdaudio_set_volume(gint l, gint r); | |
78 static void cdaudio_cleanup(void); | |
79 static void cdaudio_get_song_info(gchar *filename, gchar **title, gint *length); | |
1466 | 80 static Tuple *cdaudio_get_song_tuple(gchar *filename); |
1048 | 81 |
2047 | 82 static void menu_click(void); |
83 static Tuple *create_tuple_from_trackinfo(gchar *filename); | |
84 static void dae_play_loop(dae_params_t *pdae_params); | |
85 static gint calculate_track_length(gint startlsn, gint endlsn); | |
86 static gint find_trackno_from_filename(gchar *filename); | |
87 static void cleanup_on_error(void); | |
1048 | 88 |
89 | |
90 static InputPlugin inputplugin = { | |
1624
db87d84ed8f3
cdaudio-ng: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents:
1529
diff
changeset
|
91 .description = "CD Audio Plugin NG", |
db87d84ed8f3
cdaudio-ng: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents:
1529
diff
changeset
|
92 .init = cdaudio_init, |
db87d84ed8f3
cdaudio-ng: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents:
1529
diff
changeset
|
93 .about = cdaudio_about, |
db87d84ed8f3
cdaudio-ng: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents:
1529
diff
changeset
|
94 .configure = cdaudio_configure, |
db87d84ed8f3
cdaudio-ng: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents:
1529
diff
changeset
|
95 .is_our_file = cdaudio_is_our_file, |
db87d84ed8f3
cdaudio-ng: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents:
1529
diff
changeset
|
96 .scan_dir = cdaudio_scan_dir, |
db87d84ed8f3
cdaudio-ng: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents:
1529
diff
changeset
|
97 .play_file = cdaudio_play_file, |
db87d84ed8f3
cdaudio-ng: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents:
1529
diff
changeset
|
98 .stop = cdaudio_stop, |
db87d84ed8f3
cdaudio-ng: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents:
1529
diff
changeset
|
99 .pause = cdaudio_pause, |
db87d84ed8f3
cdaudio-ng: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents:
1529
diff
changeset
|
100 .seek = cdaudio_seek, |
db87d84ed8f3
cdaudio-ng: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents:
1529
diff
changeset
|
101 .get_time = cdaudio_get_time, |
db87d84ed8f3
cdaudio-ng: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents:
1529
diff
changeset
|
102 .get_volume = cdaudio_get_volume, |
db87d84ed8f3
cdaudio-ng: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents:
1529
diff
changeset
|
103 .set_volume = cdaudio_set_volume, |
db87d84ed8f3
cdaudio-ng: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents:
1529
diff
changeset
|
104 .cleanup = cdaudio_cleanup, |
db87d84ed8f3
cdaudio-ng: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents:
1529
diff
changeset
|
105 .get_song_info = cdaudio_get_song_info, |
db87d84ed8f3
cdaudio-ng: C99 initialisers
William Pitcock <nenolod@atheme.org>
parents:
1529
diff
changeset
|
106 .get_song_tuple = cdaudio_get_song_tuple |
1048 | 107 }; |
108 | |
1098
334afe46961c
[svn] - cdaudio-ng (aka Zither's CD Audio Plugin): convert to plugin API v2
nenolod
parents:
1048
diff
changeset
|
109 InputPlugin *cdaudio_iplist[] = { &inputplugin, NULL }; |
1048 | 110 |
1395
761e17b23e0c
added Discovery plugin type
Cristi Magherusan <majeru@atheme-project.org>
parents:
1389
diff
changeset
|
111 DECLARE_PLUGIN(cdaudio, NULL, NULL, cdaudio_iplist, NULL, NULL, NULL, NULL, NULL); |
1048 | 112 |
1123 | 113 |
2047 | 114 static void cdaudio_error(const char *fmt, ...) |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
115 { |
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
116 va_list ap; |
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
117 fprintf(stderr, "cdaudio-ng: "); |
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
118 va_start(ap, fmt); |
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
119 vfprintf(stderr, fmt, ap); |
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
120 va_end(ap); |
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
121 } |
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
122 |
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
123 |
2047 | 124 static void CDDEBUG(const char *fmt, ...) |
1048 | 125 { |
2046 | 126 if (cdng_cfg.debug) { |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
127 va_list ap; |
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
128 fprintf(stderr, "cdaudio-ng: "); |
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
129 va_start(ap, fmt); |
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
130 vfprintf(stderr, fmt, ap); |
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
131 va_end(ap); |
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
132 } |
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
133 } |
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
134 |
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
135 |
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
136 static void cdaudio_init() |
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
137 { |
2037 | 138 ConfigDb *db; |
139 gchar *menu_item_text; | |
140 | |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
141 CDDEBUG("cdaudio_init()\n"); |
2046 | 142 |
143 memset(&cdng_cfg, 0, sizeof(cdng_cfg)); | |
1125 | 144 |
2044 | 145 if ((db = aud_cfg_db_open()) == NULL) { |
2037 | 146 cdaudio_error("Failed to read configuration.\n"); |
147 cleanup_on_error(); | |
148 return; | |
149 } | |
150 | |
1123 | 151 if (!cdio_init()) { |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
152 cdaudio_error("Failed to initialize cdio subsystem.\n"); |
1123 | 153 cleanup_on_error(); |
154 return; | |
155 } | |
1382
28766475ca0a
More and more translatable strings... ;-)
Stany HENRY <StrassBoy@gmail.com>
parents:
1378
diff
changeset
|
156 |
1282 | 157 libcddb_init(); |
1382
28766475ca0a
More and more translatable strings... ;-)
Stany HENRY <StrassBoy@gmail.com>
parents:
1378
diff
changeset
|
158 |
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
|
159 /* |
2046 | 160 if (!aud_cfg_db_get_bool(db, "CDDA", "use_dae", &cdng_cfg.use_dae)) |
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
|
161 */ |
2048 | 162 cdng_cfg.use_dae = TRUE; |
163 | |
2046 | 164 if (!aud_cfg_db_get_int(db, "CDDA", "limitspeed", &cdng_cfg.limitspeed)) |
165 cdng_cfg.limitspeed = 1; | |
166 if (!aud_cfg_db_get_bool(db, "CDDA", "use_cdtext", &cdng_cfg.use_cdtext)) | |
167 cdng_cfg.use_cdtext = TRUE; | |
168 if (!aud_cfg_db_get_bool(db, "CDDA", "use_cddb", &cdng_cfg.use_cddb)) | |
169 cdng_cfg.use_cddb = TRUE; | |
170 if (!aud_cfg_db_get_string(db, "CDDA", "cddbserver", &cdng_cfg.cddb_server)) | |
171 cdng_cfg.cddb_server = g_strdup(CDDA_DEFAULT_CDDB_SERVER); | |
172 if (!aud_cfg_db_get_int(db, "CDDA", "cddbport", &cdng_cfg.cddb_port)) | |
173 cdng_cfg.cddb_port = CDDA_DEFAULT_CDDB_PORT; | |
174 if (!aud_cfg_db_get_string(db, "CDDA", "device", &cdng_cfg.device)) | |
175 cdng_cfg.device = g_strdup(""); | |
176 if (!aud_cfg_db_get_bool(db, "CDDA", "debug", &cdng_cfg.debug)) | |
177 cdng_cfg.debug = FALSE; | |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
178 |
2044 | 179 aud_cfg_db_close(db); |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
180 |
2048 | 181 CDDEBUG("use_dae = %d, limitspeed = %d, use_cdtext = %d, use_cddb = %d, cddbserver = \"%s\", cddbport = %d, device = \"%s\", debug = %d\n", |
182 cdng_cfg.use_dae, cdng_cfg.limitspeed, cdng_cfg.use_cdtext, cdng_cfg.use_cddb, | |
2046 | 183 cdng_cfg.cddb_server, cdng_cfg.cddb_port, cdng_cfg.device, cdng_cfg.debug); |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
184 |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
185 configure_create_gui(); |
1490
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
186 |
2037 | 187 menu_item_text = _("Add CD"); |
1529 | 188 main_menu_item = gtk_image_menu_item_new_with_label(menu_item_text); |
1490
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
189 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(main_menu_item), gtk_image_new_from_stock(GTK_STOCK_CDROM, GTK_ICON_SIZE_MENU)); |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
190 gtk_widget_show(main_menu_item); |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
191 audacious_menu_plugin_item_add(AUDACIOUS_MENU_MAIN, main_menu_item); |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
192 g_signal_connect(G_OBJECT(main_menu_item), "button_press_event", G_CALLBACK(menu_click), NULL); |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
193 |
1529 | 194 playlist_menu_item = gtk_image_menu_item_new_with_label(menu_item_text); |
1490
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
195 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(playlist_menu_item), gtk_image_new_from_stock(GTK_STOCK_CDROM, GTK_ICON_SIZE_MENU)); |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
196 gtk_widget_show(playlist_menu_item); |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
197 audacious_menu_plugin_item_add(AUDACIOUS_MENU_PLAYLIST, playlist_menu_item); |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
198 g_signal_connect(G_OBJECT(playlist_menu_item), "button_press_event", G_CALLBACK(menu_click), NULL); |
1482
3b2a302fe43f
Register cdda:// with uri_set_plugin
Christian Birchinger <joker@netswarm.net>
parents:
1473
diff
changeset
|
199 |
1997 | 200 aud_uri_set_plugin("cdda://", &inputplugin); |
1048 | 201 } |
202 | |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
203 static void cdaudio_about() |
1048 | 204 { |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
205 CDDEBUG("cdaudio_about()\n"); |
1382
28766475ca0a
More and more translatable strings... ;-)
Stany HENRY <StrassBoy@gmail.com>
parents:
1378
diff
changeset
|
206 |
1377
4eb2bacab83a
Added an information box to cdaudio-ng
Calin Crisan ccrisan@gmail.com
parents:
1349
diff
changeset
|
207 static GtkWidget* about_window = NULL; |
1382
28766475ca0a
More and more translatable strings... ;-)
Stany HENRY <StrassBoy@gmail.com>
parents:
1378
diff
changeset
|
208 |
2047 | 209 if (about_window) { |
210 gdk_window_raise(about_window->window); | |
211 } | |
212 about_window = audacious_info_dialog(_("About CD Audio Plugin NG"), | |
213 _("Copyright (c) 2007, by Calin Crisan <ccrisan@gmail.com> and The Audacious Team.\n\n" | |
214 "Many thanks to libcdio developers <http://www.gnu.org/software/libcdio/>\n" | |
215 "\tand to libcddb developers <http://libcddb.sourceforge.net/>.\n\n" | |
216 "Also thank you Tony Vroon for mentoring & guiding me.\n\n" | |
217 "This was a Google Summer of Code 2007 project."), _("OK"), FALSE, NULL, NULL); | |
1382
28766475ca0a
More and more translatable strings... ;-)
Stany HENRY <StrassBoy@gmail.com>
parents:
1378
diff
changeset
|
218 |
2047 | 219 g_signal_connect(G_OBJECT(about_window), "destroy", |
220 G_CALLBACK(gtk_widget_destroyed), &about_window); | |
1048 | 221 } |
222 | |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
223 static void cdaudio_configure() |
1048 | 224 { |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
225 CDDEBUG("cdaudio_configure()\n"); |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
226 |
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
|
227 /* |
1303 | 228 if (playing_track != -1) |
229 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
|
230 */ |
1303 | 231 |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
232 configure_show_gui(); |
1048 | 233 } |
234 | |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
235 static gint cdaudio_is_our_file(gchar *filename) |
1048 | 236 { |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
237 CDDEBUG("cdaudio_is_our_file(\"%s\")\n", filename); |
1125 | 238 |
1048 | 239 if ((filename != NULL) && strlen(filename) > 4 && (!strcasecmp(filename + strlen(filename) - 4, ".cda"))) { |
2047 | 240 /* no CD information yet */ |
1123 | 241 if (pcdio == NULL) { |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
242 CDDEBUG("no CD information, scanning\n"); |
1125 | 243 cdaudio_scan_dir(CDDA_DEFAULT); |
1048 | 244 } |
1123 | 245 |
2047 | 246 /* 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
|
247 if (cdio_get_media_changed(pcdio) && pcdio != NULL) { |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
248 CDDEBUG("CD changed, rescanning\n"); |
1389
e2754a023ae0
Fixed surprise eject segfault
Calin Crisan ccrisan@gmail.com
parents:
1388
diff
changeset
|
249 if (cdaudio_scan_dir(CDDA_DEFAULT) == NULL) |
e2754a023ae0
Fixed surprise eject segfault
Calin Crisan ccrisan@gmail.com
parents:
1388
diff
changeset
|
250 pcdio = NULL; |
1048 | 251 } |
1382
28766475ca0a
More and more translatable strings... ;-)
Stany HENRY <StrassBoy@gmail.com>
parents:
1378
diff
changeset
|
252 |
1313
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
253 if (pcdio == NULL) { |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
254 CDDEBUG("\"%s\" is not our file\n", filename); |
1313
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
255 return FALSE; |
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
256 } |
1123 | 257 |
2047 | 258 /* check if the requested track actually exists on the current audio cd */ |
1958
2db72dd92ee3
Use glib types and functions in some places.
Matti Hamalainen <ccr@tnsp.org>
parents:
1708
diff
changeset
|
259 gint trackno = find_trackno_from_filename(filename); |
1125 | 260 if (trackno < firsttrackno || trackno > lasttrackno) { |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
261 CDDEBUG("\"%s\" is not our file\n", filename); |
1123 | 262 return FALSE; |
1125 | 263 } |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
264 |
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
265 CDDEBUG("\"%s\" is our file\n", filename); |
1123 | 266 return TRUE; |
1048 | 267 } |
1125 | 268 else { |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
269 CDDEBUG("\"%s\" is not our file\n", filename); |
1123 | 270 return FALSE; |
1125 | 271 } |
1048 | 272 } |
273 | |
2043
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
274 |
2046 | 275 static void cdaudio_set_strinfo(trackinfo_t *t, |
2043
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
276 const gchar *performer, const gchar *name, const gchar *genre) |
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
277 { |
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
278 g_strlcpy(t->performer, performer, DEF_STRING_LEN); |
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
279 g_strlcpy(t->name, name, DEF_STRING_LEN); |
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
280 g_strlcpy(t->genre, genre, DEF_STRING_LEN); |
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
281 } |
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
282 |
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
283 |
2046 | 284 static void cdaudio_set_fullinfo(trackinfo_t *t, |
2043
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
285 const lsn_t startlsn, const lsn_t endlsn, |
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
286 const gchar *performer, const gchar *name, const gchar *genre) |
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
287 { |
2046 | 288 t->startlsn = startlsn; |
289 t->endlsn = endlsn; | |
2043
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
290 cdaudio_set_strinfo(t, performer, name, genre); |
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
291 } |
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
292 |
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
293 |
2047 | 294 static GList *cdaudio_scan_dir(gchar *dirname) |
1048 | 295 { |
2043
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
296 gint trackno; |
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
297 |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
298 CDDEBUG("cdaudio_scan_dir(\"%s\")\n", dirname); |
1125 | 299 |
2047 | 300 /* if the given dirname does not belong to us, we return NULL */ |
1125 | 301 if (strstr(dirname, CDDA_DEFAULT) == NULL) { |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
302 CDDEBUG("\"%s\" directory does not belong to us\n", dirname); |
1048 | 303 return NULL; |
1125 | 304 } |
1123 | 305 |
2047 | 306 /* find an available, audio capable, cd drive */ |
2046 | 307 if (cdng_cfg.device != NULL && strlen(cdng_cfg.device) > 0) { |
308 pcdio = cdio_open(cdng_cfg.device, DRIVER_UNKNOWN); | |
1282 | 309 if (pcdio == NULL) { |
2046 | 310 cdaudio_error("Failed to open CD device \"%s\".\n", cdng_cfg.device); |
1282 | 311 return NULL; |
312 } | |
313 } | |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
314 else { |
1958
2db72dd92ee3
Use glib types and functions in some places.
Matti Hamalainen <ccr@tnsp.org>
parents:
1708
diff
changeset
|
315 gchar **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
|
316 pcdio = NULL; |
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
317 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
|
318 pcdio = cdio_open(*ppcd_drives, DRIVER_UNKNOWN); |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
319 if (pcdio == NULL) { |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
320 cdaudio_error("Failed to open CD.\n"); |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
321 cleanup_on_error(); |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
322 return NULL; |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
323 } |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
324 CDDEBUG("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
|
325 } |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
326 else { |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
327 cdaudio_error("Unable to find or access a CDDA capable drive.\n"); |
1123 | 328 cleanup_on_error(); |
329 return NULL; | |
330 } | |
1389
e2754a023ae0
Fixed surprise eject segfault
Calin Crisan ccrisan@gmail.com
parents:
1388
diff
changeset
|
331 if (ppcd_drives != NULL && *ppcd_drives != NULL) |
e2754a023ae0
Fixed surprise eject segfault
Calin Crisan ccrisan@gmail.com
parents:
1388
diff
changeset
|
332 cdio_free_device_list(ppcd_drives); |
1048 | 333 } |
334 | |
2047 | 335 /* limit read speed */ |
2046 | 336 if (cdng_cfg.limitspeed > 0 && cdng_cfg.use_dae) { |
337 CDDEBUG("setting drive speed limit to %dx\n", cdng_cfg.limitspeed); | |
338 if (cdio_set_speed(pcdio, cdng_cfg.limitspeed) != DRIVER_OP_SUCCESS) | |
339 cdaudio_error("Failed to set drive speed to %dx.\n", cdng_cfg.limitspeed); | |
1193 | 340 } |
1282 | 341 |
2047 | 342 /* get general track initialization */ |
1194 | 343 cdrom_drive_t *pcdrom_drive = cdio_cddap_identify_cdio(pcdio, 1, NULL); // todo : check return / NULL |
1048 | 344 firsttrackno = cdio_get_first_track_num(pcdrom_drive->p_cdio); |
345 lasttrackno = cdio_get_last_track_num(pcdrom_drive->p_cdio); | |
1123 | 346 if (firsttrackno == CDIO_INVALID_TRACK || lasttrackno == CDIO_INVALID_TRACK) { |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
347 cdaudio_error("Failed to retrieve first/last track number.\n"); |
1123 | 348 cleanup_on_error(); |
349 return NULL; | |
350 } | |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
351 CDDEBUG("first track is %d and last track is %d\n", firsttrackno, lasttrackno); |
1048 | 352 |
1958
2db72dd92ee3
Use glib types and functions in some places.
Matti Hamalainen <ccr@tnsp.org>
parents:
1708
diff
changeset
|
353 g_free(trackinfo); |
2db72dd92ee3
Use glib types and functions in some places.
Matti Hamalainen <ccr@tnsp.org>
parents:
1708
diff
changeset
|
354 trackinfo = (trackinfo_t *) g_new(trackinfo_t, (lasttrackno + 1)); |
1282 | 355 |
2043
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
356 cdaudio_set_fullinfo(&trackinfo[0], |
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
357 cdio_get_track_lsn(pcdrom_drive->p_cdio, 0), |
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
358 cdio_get_track_last_lsn(pcdrom_drive->p_cdio, CDIO_CDROM_LEADOUT_TRACK), |
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
359 "", "", ""); |
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
360 |
1282 | 361 for (trackno = firsttrackno; trackno <= lasttrackno; trackno++) { |
2043
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
362 cdaudio_set_fullinfo(&trackinfo[trackno], |
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
363 cdio_get_track_lsn(pcdrom_drive->p_cdio, trackno), |
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
364 cdio_get_track_last_lsn(pcdrom_drive->p_cdio, trackno), |
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
365 "", "", ""); |
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
366 |
1282 | 367 if (trackinfo[trackno].startlsn == CDIO_INVALID_LSN || trackinfo[trackno].endlsn == CDIO_INVALID_LSN) { |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
368 cdaudio_error("Failed to retrieve stard/end lsn for track %d.\n", trackno); |
1282 | 369 cleanup_on_error(); |
370 return NULL; | |
371 } | |
372 } | |
373 | |
2047 | 374 /* initialize de cddb subsystem */ |
1282 | 375 cddb_conn_t *pcddb_conn = NULL; |
376 cddb_disc_t *pcddb_disc = NULL; | |
377 cddb_track_t *pcddb_track = NULL; | |
378 | |
2046 | 379 if (cdng_cfg.use_cddb) { |
1282 | 380 pcddb_conn = cddb_new(); |
381 if (pcddb_conn == NULL) | |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
382 cdaudio_error("Failed to create the cddb connection.\n"); |
1282 | 383 else { |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
384 CDDEBUG("getting CDDB info\n"); |
1282 | 385 |
2046 | 386 cddb_set_server_name(pcddb_conn, cdng_cfg.cddb_server); |
387 cddb_set_server_port(pcddb_conn, cdng_cfg.cddb_port); | |
1282 | 388 |
389 pcddb_disc = cddb_disc_new(); | |
390 for (trackno = firsttrackno; trackno <= lasttrackno; trackno++) { | |
391 pcddb_track = cddb_track_new(); | |
392 cddb_track_set_frame_offset(pcddb_track, trackinfo[trackno].startlsn); | |
393 cddb_disc_add_track(pcddb_disc, pcddb_track); | |
394 } | |
395 | |
396 msf_t startmsf, endmsf; | |
397 cdio_get_track_msf(pcdio, 1, &startmsf); | |
398 cdio_get_track_msf(pcdio, CDIO_CDROM_LEADOUT_TRACK, &endmsf); | |
399 cddb_disc_set_length(pcddb_disc, cdio_audio_get_msf_seconds(&endmsf) - cdio_audio_get_msf_seconds(&startmsf)); | |
400 | |
2042 | 401 gint matches; |
1282 | 402 if ((matches = cddb_query(pcddb_conn, pcddb_disc)) == -1) { |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
403 cdaudio_error("Failed to query the CDDB server: %s\n", cddb_error_str(cddb_errno(pcddb_conn))); |
1282 | 404 cddb_disc_destroy(pcddb_disc); |
405 pcddb_disc = NULL; | |
406 } | |
407 else { | |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
408 CDDEBUG("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
|
409 |
1282 | 410 cddb_read(pcddb_conn, pcddb_disc); |
411 if (cddb_errno(pcddb_conn) != CDDB_ERR_OK) { | |
412 fprintf(stderr, "cdaudio-ng: failed to read the cddb info: %s\n", cddb_error_str(cddb_errno(pcddb_conn))); | |
413 cddb_disc_destroy(pcddb_disc); | |
414 pcddb_disc = NULL; | |
415 } | |
416 else { | |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
417 CDDEBUG("we have got the cddb info\n"); |
2043
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
418 cdaudio_set_strinfo(&trackinfo[0], |
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
419 cddb_disc_get_artist(pcddb_disc), |
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
420 cddb_disc_get_title(pcddb_disc), |
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
421 cddb_disc_get_genre(pcddb_disc)); |
1282 | 422 } |
423 } | |
424 } | |
425 } | |
426 | |
2047 | 427 /* adding trackinfo[0] information (the disc) */ |
2046 | 428 if (cdng_cfg.use_cdtext) { |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
429 CDDEBUG("getting cd-text information for disc\n"); |
1282 | 430 cdtext_t *pcdtext = cdio_get_cdtext(pcdrom_drive->p_cdio, 0); |
431 if (pcdtext == NULL || pcdtext->field[CDTEXT_TITLE] == NULL) { | |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
432 CDDEBUG("no cd-text available for disc\n"); |
1282 | 433 } |
434 else { | |
2043
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
435 cdaudio_set_strinfo(&trackinfo[0], |
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
436 pcdtext->field[CDTEXT_PERFORMER] ? pcdtext->field[CDTEXT_PERFORMER] : "", |
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
437 pcdtext->field[CDTEXT_TITLE] ? pcdtext->field[CDTEXT_TITLE] : "", |
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
438 pcdtext->field[CDTEXT_GENRE] ? pcdtext->field[CDTEXT_GENRE] : ""); |
1282 | 439 } |
440 } | |
441 | |
2047 | 442 /* add track "file" names to the list */ |
1282 | 443 GList *list = NULL; |
1048 | 444 for (trackno = firsttrackno; trackno <= lasttrackno; trackno++) { |
1382
28766475ca0a
More and more translatable strings... ;-)
Stany HENRY <StrassBoy@gmail.com>
parents:
1378
diff
changeset
|
445 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
|
446 cdtext_t *pcdtext = NULL; |
2046 | 447 if (cdng_cfg.use_cdtext) { |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
448 CDDEBUG("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
|
449 pcdtext = cdio_get_cdtext(pcdrom_drive->p_cdio, trackno); |
1282 | 450 if (pcdtext == NULL || pcdtext->field[CDTEXT_PERFORMER] == NULL) { |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
451 CDDEBUG("no cd-text available for track %d\n", trackno); |
1282 | 452 pcdtext = NULL; |
453 } | |
454 } | |
1048 | 455 |
456 if (pcdtext != NULL) { | |
2043
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
457 cdaudio_set_strinfo(&trackinfo[trackno], |
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
458 pcdtext->field[CDTEXT_PERFORMER] ? pcdtext->field[CDTEXT_PERFORMER] : "", |
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
459 pcdtext->field[CDTEXT_TITLE] ? pcdtext->field[CDTEXT_TITLE] : "", |
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
460 pcdtext->field[CDTEXT_GENRE] ? pcdtext->field[CDTEXT_GENRE] : ""); |
1048 | 461 } |
2043
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
462 else if (pcddb_disc != NULL) { |
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
463 cddb_track_t *pcddb_track = cddb_disc_get_track(pcddb_disc, trackno - 1); |
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
464 cdaudio_set_strinfo(&trackinfo[trackno], |
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
465 cddb_track_get_artist(pcddb_track), |
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
466 cddb_track_get_title(pcddb_track), |
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
467 cddb_disc_get_genre(pcddb_disc)); |
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
468 } |
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
469 else { |
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
470 cdaudio_set_strinfo(&trackinfo[trackno], "", "", ""); |
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
471 } |
1282 | 472 |
2043
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
473 if (strlen(trackinfo[trackno].name) == 0) { |
2047 | 474 g_snprintf(trackinfo[trackno].name, DEF_STRING_LEN, |
2043
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
475 "CD Audio Track %02u", trackno); |
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
476 } |
1048 | 477 |
1282 | 478 } |
479 | |
2046 | 480 if (cdng_cfg.debug) { |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
481 CDDEBUG("disc has : performer = \"%s\", name = \"%s\", genre = \"%s\"\n", |
2043
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
482 trackinfo[0].performer, trackinfo[0].name, trackinfo[0].genre); |
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
483 |
1282 | 484 for (trackno = firsttrackno; trackno <= lasttrackno; trackno++) { |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
485 CDDEBUG("track %d has : performer = \"%s\", name = \"%s\", genre = \"%s\", startlsn = %d, endlsn = %d\n", |
1282 | 486 trackno, trackinfo[trackno].performer, trackinfo[trackno].name, trackinfo[trackno].genre, trackinfo[trackno].startlsn, trackinfo[trackno].endlsn); |
1123 | 487 } |
1282 | 488 } |
1125 | 489 |
1282 | 490 if (pcddb_disc != NULL) |
491 cddb_disc_destroy(pcddb_disc); | |
2043
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
492 |
1282 | 493 if (pcddb_conn != NULL) |
494 cddb_destroy(pcddb_conn); | |
1048 | 495 |
496 return list; | |
497 } | |
498 | |
2047 | 499 static void cdaudio_play_file(InputPlayback *pinputplayback) |
1125 | 500 { |
1466 | 501 Tuple *tuple; |
1958
2db72dd92ee3
Use glib types and functions in some places.
Matti Hamalainen <ccr@tnsp.org>
parents:
1708
diff
changeset
|
502 gchar *title; |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
503 |
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
504 CDDEBUG("cdaudio_play_file(\"%s\")\n", pinputplayback->filename); |
1382
28766475ca0a
More and more translatable strings... ;-)
Stany HENRY <StrassBoy@gmail.com>
parents:
1378
diff
changeset
|
505 |
1313
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
506 pglobalinputplayback = pinputplayback; |
1125 | 507 |
1048 | 508 if (trackinfo == NULL) { |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
509 CDDEBUG("no CD information, scanning\n"); |
1125 | 510 cdaudio_scan_dir(CDDA_DEFAULT); |
1048 | 511 } |
512 | |
1123 | 513 if (cdio_get_media_changed(pcdio)) { |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
514 CDDEBUG("CD changed, rescanning\n"); |
1125 | 515 cdaudio_scan_dir(CDDA_DEFAULT); |
1048 | 516 } |
1123 | 517 |
1389
e2754a023ae0
Fixed surprise eject segfault
Calin Crisan ccrisan@gmail.com
parents:
1388
diff
changeset
|
518 if (trackinfo == NULL) { |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
519 CDDEBUG("no CD information can be retrieved, aborting\n"); |
1389
e2754a023ae0
Fixed surprise eject segfault
Calin Crisan ccrisan@gmail.com
parents:
1388
diff
changeset
|
520 pinputplayback->playing = FALSE; |
e2754a023ae0
Fixed surprise eject segfault
Calin Crisan ccrisan@gmail.com
parents:
1388
diff
changeset
|
521 return; |
e2754a023ae0
Fixed surprise eject segfault
Calin Crisan ccrisan@gmail.com
parents:
1388
diff
changeset
|
522 } |
e2754a023ae0
Fixed surprise eject segfault
Calin Crisan ccrisan@gmail.com
parents:
1388
diff
changeset
|
523 |
2043
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
524 gint trackno = find_trackno_from_filename(pinputplayback->filename); |
1123 | 525 if (trackno < firsttrackno || trackno > lasttrackno) { |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
526 cdaudio_error("Track #%d is out of range [%d..%d]\n", trackno, firsttrackno, lasttrackno); |
1123 | 527 cleanup_on_error(); |
1048 | 528 return; |
1123 | 529 } |
1048 | 530 |
531 pinputplayback->playing = TRUE; | |
532 playing_track = trackno; | |
1123 | 533 is_paused = FALSE; |
534 | |
2047 | 535 tuple = create_tuple_from_trackinfo(pinputplayback->filename); |
2055 | 536 title = aud_tuple_formatter_make_title_string(tuple, aud_get_gentitle_format()); |
1387
20c6caad7e03
Fixed the play/stop indication; added a temporary workaround for including the last 3 seconds in playback
Calin Crisan ccrisan@gmail.com
parents:
1382
diff
changeset
|
537 |
1984
489e32a8e106
change some places to use set_params() instead of set_info() directly
William Pitcock <nenolod@atheme.org>
parents:
1976
diff
changeset
|
538 pinputplayback->set_params(pinputplayback, title, calculate_track_length(trackinfo[trackno].startlsn, trackinfo[trackno].endlsn), 1411200, 44100, 2); |
1958
2db72dd92ee3
Use glib types and functions in some places.
Matti Hamalainen <ccr@tnsp.org>
parents:
1708
diff
changeset
|
539 g_free(title); |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1967
diff
changeset
|
540 aud_tuple_free(tuple); |
1387
20c6caad7e03
Fixed the play/stop indication; added a temporary workaround for including the last 3 seconds in playback
Calin Crisan ccrisan@gmail.com
parents:
1382
diff
changeset
|
541 |
2046 | 542 if (cdng_cfg.use_dae) { |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
543 CDDEBUG("using digital audio extraction\n"); |
1125 | 544 |
1123 | 545 if (pdae_params != NULL) { |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
546 cdaudio_error("DAE playback seems to be already started.\n"); |
1123 | 547 return; |
548 } | |
549 | |
550 if (pinputplayback->output->open_audio(FMT_S16_LE, 44100, 2) == 0) { | |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
551 cdaudio_error("Failed to open audio output.\n"); |
1123 | 552 cleanup_on_error(); |
553 return; | |
554 } | |
555 | |
1349
ab387ad5b88e
Converted to new threading model
Calin Crisan ccrisan@gmail.com
parents:
1341
diff
changeset
|
556 /* |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
557 CDDEBUG("starting dae thread...\n"); |
1349
ab387ad5b88e
Converted to new threading model
Calin Crisan ccrisan@gmail.com
parents:
1341
diff
changeset
|
558 */ |
1958
2db72dd92ee3
Use glib types and functions in some places.
Matti Hamalainen <ccr@tnsp.org>
parents:
1708
diff
changeset
|
559 pdae_params = (dae_params_t *) g_new(dae_params_t, 1); |
1123 | 560 pdae_params->startlsn = trackinfo[trackno].startlsn; |
561 pdae_params->endlsn = trackinfo[trackno].endlsn; | |
562 pdae_params->pplayback = pinputplayback; | |
563 pdae_params->seektime = -1; | |
564 pdae_params->currlsn = trackinfo[trackno].startlsn; | |
1349
ab387ad5b88e
Converted to new threading model
Calin Crisan ccrisan@gmail.com
parents:
1341
diff
changeset
|
565 pdae_params->thread = g_thread_self(); |
1447
195b5657303e
updated input plugins to use set_pb_ready to signal to the core that they're ready for playback
Giacomo Lozito <james@develia.org>
parents:
1395
diff
changeset
|
566 pinputplayback->set_pb_ready(pinputplayback); |
1349
ab387ad5b88e
Converted to new threading model
Calin Crisan ccrisan@gmail.com
parents:
1341
diff
changeset
|
567 dae_play_loop(pdae_params); |
1123 | 568 } |
569 else { | |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
570 CDDEBUG("not using digital audio extraction\n"); |
1125 | 571 |
1123 | 572 msf_t startmsf, endmsf; |
573 cdio_lsn_to_msf(trackinfo[trackno].startlsn, &startmsf); | |
574 cdio_lsn_to_msf(trackinfo[trackno].endlsn, &endmsf); | |
575 if (cdio_audio_play_msf(pcdio, &startmsf, &endmsf) != DRIVER_OP_SUCCESS) { | |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
576 cdaudio_error("Failed to play analog audio CD.\n"); |
1123 | 577 cleanup_on_error(); |
578 return; | |
579 } | |
580 } | |
1048 | 581 } |
582 | |
2047 | 583 static void cdaudio_stop(InputPlayback *pinputplayback) |
1125 | 584 { |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
585 CDDEBUG("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
|
586 |
1313
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
587 pglobalinputplayback = NULL; |
1382
28766475ca0a
More and more translatable strings... ;-)
Stany HENRY <StrassBoy@gmail.com>
parents:
1378
diff
changeset
|
588 |
1313
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
589 if (playing_track == -1) |
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
590 return; |
1125 | 591 |
1303 | 592 if (pinputplayback != NULL) |
593 pinputplayback->playing = FALSE; | |
1048 | 594 playing_track = -1; |
1123 | 595 is_paused = FALSE; |
596 | |
2046 | 597 if (cdng_cfg.use_dae) { |
1123 | 598 if (pdae_params != NULL) { |
599 g_thread_join(pdae_params->thread); | |
1958
2db72dd92ee3
Use glib types and functions in some places.
Matti Hamalainen <ccr@tnsp.org>
parents:
1708
diff
changeset
|
600 g_free(pdae_params); |
1123 | 601 pdae_params = NULL; |
602 } | |
603 } | |
604 else { | |
605 if (cdio_audio_stop(pcdio) != DRIVER_OP_SUCCESS) { | |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
606 cdaudio_error("Failed to stop analog CD.\n"); |
1123 | 607 return; |
608 } | |
609 } | |
1048 | 610 } |
611 | |
2047 | 612 static void cdaudio_pause(InputPlayback *pinputplayback, gshort paused) |
1048 | 613 { |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
614 CDDEBUG("cdaudio_pause(\"%s\", %d)\n", pinputplayback->filename, paused); |
1125 | 615 |
1048 | 616 if (!is_paused) { |
617 is_paused = TRUE; | |
2046 | 618 if (!cdng_cfg.use_dae) |
1123 | 619 if (cdio_audio_pause(pcdio) != DRIVER_OP_SUCCESS) { |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
620 cdaudio_error("Failed to pause analog CD!\n"); |
1123 | 621 cleanup_on_error(); |
622 return; | |
623 } | |
1048 | 624 } |
625 else { | |
626 is_paused = FALSE; | |
2046 | 627 if (!cdng_cfg.use_dae) |
1123 | 628 if (cdio_audio_resume(pcdio) != DRIVER_OP_SUCCESS) { |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
629 cdaudio_error("Failed to resume analog CD!\n"); |
1123 | 630 cleanup_on_error(); |
631 return; | |
632 } | |
1048 | 633 } |
634 } | |
635 | |
2047 | 636 static void cdaudio_seek(InputPlayback *pinputplayback, gint time) |
1048 | 637 { |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
638 CDDEBUG("cdaudio_seek(\"%s\", %d)\n", pinputplayback->filename, time); |
1125 | 639 |
1048 | 640 if (playing_track == -1) |
641 return; | |
642 | |
2046 | 643 if (cdng_cfg.use_dae) { |
1123 | 644 if (pdae_params != NULL) { |
645 pdae_params->seektime = time * 1000; | |
646 } | |
647 } | |
648 else { | |
1958
2db72dd92ee3
Use glib types and functions in some places.
Matti Hamalainen <ccr@tnsp.org>
parents:
1708
diff
changeset
|
649 gint newstartlsn = trackinfo[playing_track].startlsn + time * 75; |
1123 | 650 msf_t startmsf, endmsf; |
651 cdio_lsn_to_msf(newstartlsn, &startmsf); | |
652 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
|
653 |
1123 | 654 if (cdio_audio_play_msf(pcdio, &startmsf, &endmsf) != DRIVER_OP_SUCCESS) { |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
655 cdaudio_error("Failed to play analog CD\n"); |
1123 | 656 cleanup_on_error(); |
657 return; | |
658 } | |
659 } | |
1048 | 660 } |
661 | |
2047 | 662 static gint cdaudio_get_time(InputPlayback *pinputplayback) |
1048 | 663 { |
2047 | 664 //CDDEBUG("cdaudio_get_time(\"%s\")\n", pinputplayback->filename); // annoying! |
1125 | 665 |
1048 | 666 if (playing_track == -1) |
667 return -1; | |
668 | |
2046 | 669 if (!cdng_cfg.use_dae) { |
1123 | 670 cdio_subchannel_t subchannel; |
671 if (cdio_audio_read_subchannel(pcdio, &subchannel) != DRIVER_OP_SUCCESS) { | |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
672 cdaudio_error("Failed to read analog CD subchannel.\n"); |
1123 | 673 cleanup_on_error(); |
1313
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
674 return 0; |
1123 | 675 } |
1958
2db72dd92ee3
Use glib types and functions in some places.
Matti Hamalainen <ccr@tnsp.org>
parents:
1708
diff
changeset
|
676 gint currlsn = cdio_msf_to_lsn(&subchannel.abs_addr); |
1048 | 677 |
2047 | 678 /* 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
|
679 if (currlsn == trackinfo[playing_track].endlsn) |
1123 | 680 return -1; |
681 | |
682 return calculate_track_length(trackinfo[playing_track].startlsn, currlsn); | |
1048 | 683 } |
1123 | 684 else { |
685 if (pdae_params != NULL) | |
1314
b93270e2b7e4
Continuous playing in DAE mode works again
Calin Crisan ccrisan@gmail.com
parents:
1313
diff
changeset
|
686 if (pdae_params->pplayback->playing) |
b93270e2b7e4
Continuous playing in DAE mode works again
Calin Crisan ccrisan@gmail.com
parents:
1313
diff
changeset
|
687 return pinputplayback->output->output_time(); |
b93270e2b7e4
Continuous playing in DAE mode works again
Calin Crisan ccrisan@gmail.com
parents:
1313
diff
changeset
|
688 else |
b93270e2b7e4
Continuous playing in DAE mode works again
Calin Crisan ccrisan@gmail.com
parents:
1313
diff
changeset
|
689 return -1; |
1123 | 690 else |
691 return -1; | |
692 } | |
1048 | 693 } |
694 | |
2047 | 695 static gint cdaudio_get_volume(gint *l, gint *r) |
1048 | 696 { |
1125 | 697 //printf("cdaudio-ng: cdaudio_get_volume()\n"); // annoying! |
698 | |
2046 | 699 if (cdng_cfg.use_dae) { |
1123 | 700 *l = *r = 0; |
701 return FALSE; | |
702 } | |
703 else { | |
704 cdio_audio_volume_t volume; | |
705 if (cdio_audio_get_volume(pcdio, &volume) != DRIVER_OP_SUCCESS) { | |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
706 cdaudio_error("Failed to retrieve analog CD volume.\n"); |
1123 | 707 cleanup_on_error(); |
708 *l = *r = 0; | |
709 return FALSE; | |
710 } | |
711 *l = volume.level[0]; | |
712 *r = volume.level[1]; | |
1382
28766475ca0a
More and more translatable strings... ;-)
Stany HENRY <StrassBoy@gmail.com>
parents:
1378
diff
changeset
|
713 |
1123 | 714 return TRUE; |
715 } | |
1048 | 716 } |
717 | |
2047 | 718 static gint cdaudio_set_volume(gint l, gint r) |
1048 | 719 { |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
720 CDDEBUG("cdaudio_set_volume(%d, %d)\n", l, r); |
1125 | 721 |
2046 | 722 if (cdng_cfg.use_dae) { |
1123 | 723 return FALSE; |
724 } | |
725 else { | |
726 cdio_audio_volume_t volume = {{l, r, 0, 0}}; | |
727 if (cdio_audio_set_volume(pcdio, &volume) != DRIVER_OP_SUCCESS) { | |
728 fprintf(stderr, "cdaudio-ng: failed to set analog cd volume\n"); | |
729 cleanup_on_error(); | |
730 return FALSE; | |
731 } | |
1382
28766475ca0a
More and more translatable strings... ;-)
Stany HENRY <StrassBoy@gmail.com>
parents:
1378
diff
changeset
|
732 |
1123 | 733 return TRUE; |
734 } | |
1048 | 735 } |
736 | |
2047 | 737 static void cdaudio_cleanup(void) |
1048 | 738 { |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
739 CDDEBUG("cdaudio_cleanup()\n"); |
1125 | 740 |
1282 | 741 libcddb_shutdown(); |
742 | |
2046 | 743 if (pcdio != NULL) { |
744 if (playing_track != -1 && !cdng_cfg.use_dae) | |
1123 | 745 cdio_audio_stop(pcdio); |
746 cdio_destroy(pcdio); | |
747 pcdio = NULL; | |
748 } | |
749 if (trackinfo != NULL) { | |
1958
2db72dd92ee3
Use glib types and functions in some places.
Matti Hamalainen <ccr@tnsp.org>
parents:
1708
diff
changeset
|
750 g_free(trackinfo); |
1123 | 751 trackinfo = NULL; |
752 } | |
753 playing_track = -1; | |
1282 | 754 |
1189
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
755 // todo: destroy the gui |
af5bd4592100
Added cdaudio-ng.h; added a configure dialog
zither@litestep.network
parents:
1125
diff
changeset
|
756 |
2044 | 757 ConfigDb *db = aud_cfg_db_open(); |
2046 | 758 /*aud_cfg_db_set_bool(db, "CDDA", "use_dae", cdng_cfg.use_dae);*/ |
759 aud_cfg_db_set_int(db, "CDDA", "limitspeed", cdng_cfg.limitspeed); | |
760 aud_cfg_db_set_bool(db, "CDDA", "use_cdtext", cdng_cfg.use_cdtext); | |
761 aud_cfg_db_set_bool(db, "CDDA", "use_cddb", cdng_cfg.use_cddb); | |
762 aud_cfg_db_set_string(db, "CDDA", "cddbserver", cdng_cfg.cddb_server); | |
763 aud_cfg_db_set_int(db, "CDDA", "cddbport", cdng_cfg.cddb_port); | |
764 aud_cfg_db_set_string(db, "CDDA", "device", cdng_cfg.device); | |
765 aud_cfg_db_set_bool(db, "CDDA", "debug", cdng_cfg.debug); | |
2044 | 766 aud_cfg_db_close(db); |
1048 | 767 } |
768 | |
2047 | 769 static void cdaudio_get_song_info(gchar *filename, gchar **title, gint *length) |
1048 | 770 { |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
771 CDDEBUG("cdaudio_get_song_info(\"%s\")\n", filename); |
1125 | 772 |
1958
2db72dd92ee3
Use glib types and functions in some places.
Matti Hamalainen <ccr@tnsp.org>
parents:
1708
diff
changeset
|
773 gint trackno = find_trackno_from_filename(filename); |
2047 | 774 Tuple *tuple = create_tuple_from_trackinfo(filename); |
1125 | 775 |
2046 | 776 if (tuple) { |
2055 | 777 *title = aud_tuple_formatter_process_string(tuple, aud_get_gentitle_format()); |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1967
diff
changeset
|
778 aud_tuple_free(tuple); |
1466 | 779 tuple = NULL; |
780 } | |
1125 | 781 *length = calculate_track_length(trackinfo[trackno].startlsn, trackinfo[trackno].endlsn); |
1048 | 782 } |
783 | |
2047 | 784 static Tuple *cdaudio_get_song_tuple(gchar *filename) |
1048 | 785 { |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
786 CDDEBUG("cdaudio_get_song_tuple(\"%s\")\n", filename); |
1125 | 787 |
2047 | 788 return create_tuple_from_trackinfo(filename); |
1341
4ca99d2be90e
Titles are now built using tuples, with the preferred format
Calin Crisan ccrisan@gmail.com
parents:
1340
diff
changeset
|
789 } |
4ca99d2be90e
Titles are now built using tuples, with the preferred format
Calin Crisan ccrisan@gmail.com
parents:
1340
diff
changeset
|
790 |
4ca99d2be90e
Titles are now built using tuples, with the preferred format
Calin Crisan ccrisan@gmail.com
parents:
1340
diff
changeset
|
791 |
2047 | 792 /* |
793 * auxiliar functions | |
794 */ | |
795 static void menu_click() | |
1490
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
796 { |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
797 GList *list, *node; |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
798 gchar *filename; |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
799 |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
800 if (!(list = cdaudio_scan_dir(CDDA_DEFAULT))) { |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
801 const gchar *markup = |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
802 N_("<b><big>No playable CD found.</big></b>\n\n" |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
803 "No CD inserted, or inserted CD is not an audio CD.\n"); |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
804 |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
805 GtkWidget *dialog = |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
806 gtk_message_dialog_new_with_markup(NULL, |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
807 GTK_DIALOG_DESTROY_WITH_PARENT, |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
808 GTK_MESSAGE_ERROR, |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
809 GTK_BUTTONS_OK, |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
810 _(markup)); |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
811 gtk_dialog_run(GTK_DIALOG(dialog)); |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
812 gtk_widget_destroy(dialog); |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
813 return; |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
814 } |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
815 |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
816 for (node = list; node; node = g_list_next(node)) { |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
817 filename = g_build_filename(CDDA_DEFAULT, node->data, NULL); |
2057
cf4fa45ffd80
playlist API vtabling
William Pitcock <nenolod@atheme.org>
parents:
2055
diff
changeset
|
818 aud_playlist_add(aud_playlist_get_active(), filename); |
1490
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
819 g_free(filename); |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
820 g_free(node->data); |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
821 } |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
822 |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
823 g_list_free(list); |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
824 } |
032053ca08ab
Add CD menu entry is now created with the ui_plugin_menu functions
Calin Crisan ccrisan@gmail.com
parents:
1482
diff
changeset
|
825 |
2047 | 826 static Tuple *create_tuple_from_trackinfo(gchar *filename) |
1341
4ca99d2be90e
Titles are now built using tuples, with the preferred format
Calin Crisan ccrisan@gmail.com
parents:
1340
diff
changeset
|
827 { |
2043
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
828 Tuple *tuple = aud_tuple_new_from_filename(filename); |
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
829 |
1389
e2754a023ae0
Fixed surprise eject segfault
Calin Crisan ccrisan@gmail.com
parents:
1388
diff
changeset
|
830 if (trackinfo == NULL) |
2043
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
831 return tuple; |
1389
e2754a023ae0
Fixed surprise eject segfault
Calin Crisan ccrisan@gmail.com
parents:
1388
diff
changeset
|
832 |
1958
2db72dd92ee3
Use glib types and functions in some places.
Matti Hamalainen <ccr@tnsp.org>
parents:
1708
diff
changeset
|
833 gint 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
|
834 |
1048 | 835 if (trackno < firsttrackno || trackno > lasttrackno) |
2043
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
836 return tuple; |
1048 | 837 |
1466 | 838 if(strlen(trackinfo[trackno].performer)) { |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1967
diff
changeset
|
839 aud_tuple_associate_string(tuple, FIELD_ARTIST, NULL, trackinfo[trackno].performer); |
1466 | 840 } |
841 if(strlen(trackinfo[0].name)) { | |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1967
diff
changeset
|
842 aud_tuple_associate_string(tuple, FIELD_ALBUM, NULL, trackinfo[0].name); |
1466 | 843 } |
844 if(strlen(trackinfo[trackno].name)) { | |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1967
diff
changeset
|
845 aud_tuple_associate_string(tuple, FIELD_TITLE, NULL, trackinfo[trackno].name); |
1466 | 846 } |
2043
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
847 |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1967
diff
changeset
|
848 aud_tuple_associate_int(tuple, FIELD_TRACK_NUMBER, NULL, trackno); |
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1967
diff
changeset
|
849 aud_tuple_associate_string(tuple, -1, "ext", "cda"); //XXX should do? --yaz |
1466 | 850 |
2043
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
851 aud_tuple_associate_int(tuple, FIELD_LENGTH, NULL, |
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
852 calculate_track_length(trackinfo[trackno].startlsn, trackinfo[trackno].endlsn)); |
624effc5a687
Clean up the str(n)cpy mess somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
2042
diff
changeset
|
853 |
1466 | 854 if(strlen(trackinfo[trackno].genre)) { |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1967
diff
changeset
|
855 aud_tuple_associate_string(tuple, FIELD_GENRE, NULL, trackinfo[trackno].genre); |
1466 | 856 } |
1048 | 857 //tuple->year = 0; todo: set the year |
858 | |
859 return tuple; | |
860 } | |
861 | |
2047 | 862 static void dae_play_loop(dae_params_t *pdae_params) |
1123 | 863 { |
1958
2db72dd92ee3
Use glib types and functions in some places.
Matti Hamalainen <ccr@tnsp.org>
parents:
1708
diff
changeset
|
864 guchar *buffer = g_new(guchar, CDDA_DAE_FRAMES * CDIO_CD_FRAMESIZE_RAW); |
1123 | 865 |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
866 CDDEBUG("dae started\n"); |
1123 | 867 cdio_lseek(pcdio, pdae_params->startlsn * CDIO_CD_FRAMESIZE_RAW, SEEK_SET); |
868 | |
869 gboolean output_paused = FALSE; | |
1958
2db72dd92ee3
Use glib types and functions in some places.
Matti Hamalainen <ccr@tnsp.org>
parents:
1708
diff
changeset
|
870 gint read_error_counter = 0; |
1125 | 871 |
1387
20c6caad7e03
Fixed the play/stop indication; added a temporary workaround for including the last 3 seconds in playback
Calin Crisan ccrisan@gmail.com
parents:
1382
diff
changeset
|
872 //pdae_params->endlsn += 75 * 3; |
20c6caad7e03
Fixed the play/stop indication; added a temporary workaround for including the last 3 seconds in playback
Calin Crisan ccrisan@gmail.com
parents:
1382
diff
changeset
|
873 |
1123 | 874 while (pdae_params->pplayback->playing) { |
2047 | 875 /* handle pause status */ |
1123 | 876 if (is_paused) { |
877 if (!output_paused) { | |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
878 CDDEBUG("playback was not paused, pausing\n"); |
1123 | 879 pdae_params->pplayback->output->pause(TRUE); |
880 output_paused = TRUE; | |
881 } | |
1958
2db72dd92ee3
Use glib types and functions in some places.
Matti Hamalainen <ccr@tnsp.org>
parents:
1708
diff
changeset
|
882 g_usleep(1000); |
1123 | 883 continue; |
884 } | |
1125 | 885 else { |
1123 | 886 if (output_paused) { |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
887 CDDEBUG("playback was paused, resuming\n"); |
1123 | 888 pdae_params->pplayback->output->pause(FALSE); |
889 output_paused = FALSE; | |
890 } | |
1125 | 891 } |
1123 | 892 |
2047 | 893 /* check if we have to seek */ |
1123 | 894 if (pdae_params->seektime != -1) { |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
895 CDDEBUG("requested seek to %d ms\n", pdae_params->seektime); |
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
896 gint newlsn = pdae_params->startlsn + ((pdae_params->seektime * 75) / 1000); |
1123 | 897 cdio_lseek(pcdio, newlsn * CDIO_CD_FRAMESIZE_RAW, SEEK_SET); |
898 pdae_params->pplayback->output->flush(pdae_params->seektime); | |
899 pdae_params->currlsn = newlsn; | |
900 pdae_params->seektime = -1; | |
901 } | |
902 | |
2047 | 903 /* compute the actual number of sectors to read */ |
1958
2db72dd92ee3
Use glib types and functions in some places.
Matti Hamalainen <ccr@tnsp.org>
parents:
1708
diff
changeset
|
904 gint lsncount = CDDA_DAE_FRAMES <= (pdae_params->endlsn - pdae_params->currlsn + 1) ? CDDA_DAE_FRAMES : (pdae_params->endlsn - pdae_params->currlsn + 1); |
2047 | 905 |
906 /* check too see if we have reached the end of the song */ | |
1387
20c6caad7e03
Fixed the play/stop indication; added a temporary workaround for including the last 3 seconds in playback
Calin Crisan ccrisan@gmail.com
parents:
1382
diff
changeset
|
907 if (lsncount <= 0) { |
20c6caad7e03
Fixed the play/stop indication; added a temporary workaround for including the last 3 seconds in playback
Calin Crisan ccrisan@gmail.com
parents:
1382
diff
changeset
|
908 sleep(3); |
1123 | 909 break; |
1387
20c6caad7e03
Fixed the play/stop indication; added a temporary workaround for including the last 3 seconds in playback
Calin Crisan ccrisan@gmail.com
parents:
1382
diff
changeset
|
910 } |
1123 | 911 |
912 if (cdio_read_audio_sectors(pcdio, buffer, pdae_params->currlsn, lsncount) != DRIVER_OP_SUCCESS) { | |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
913 CDDEBUG("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
|
914 read_error_counter++; |
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
915 if (read_error_counter >= 2) { |
1387
20c6caad7e03
Fixed the play/stop indication; added a temporary workaround for including the last 3 seconds in playback
Calin Crisan ccrisan@gmail.com
parents:
1382
diff
changeset
|
916 read_error_counter = 0; |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
917 cdaudio_error("This CD can no longer be played, stopping.\n"); |
1313
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
918 break; |
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
919 } |
1123 | 920 } |
1313
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
921 else |
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
922 read_error_counter = 0; |
1123 | 923 |
1958
2db72dd92ee3
Use glib types and functions in some places.
Matti Hamalainen <ccr@tnsp.org>
parents:
1708
diff
changeset
|
924 gint remainingbytes = lsncount * CDIO_CD_FRAMESIZE_RAW; |
2db72dd92ee3
Use glib types and functions in some places.
Matti Hamalainen <ccr@tnsp.org>
parents:
1708
diff
changeset
|
925 guchar *bytebuff = buffer; |
1123 | 926 while (pdae_params->pplayback->playing && remainingbytes > 0 && pdae_params->seektime == -1) { |
2047 | 927 /* compute the actual number of bytes to play */ |
1958
2db72dd92ee3
Use glib types and functions in some places.
Matti Hamalainen <ccr@tnsp.org>
parents:
1708
diff
changeset
|
928 gint bytecount = CDIO_CD_FRAMESIZE_RAW <= remainingbytes ? CDIO_CD_FRAMESIZE_RAW : remainingbytes; |
2047 | 929 |
930 /* wait until the output buffer has enough room */ | |
1123 | 931 while (pdae_params->pplayback->playing && pdae_params->pplayback->output->buffer_free() < bytecount && pdae_params->seektime == -1) |
2041 | 932 g_usleep(1000); |
2047 | 933 |
934 /* play the sound :) */ | |
1123 | 935 if (pdae_params->pplayback->playing && pdae_params->seektime == -1) |
1998
8f3188746b64
chase last changeset in aud
William Pitcock <nenolod@atheme.org>
parents:
1997
diff
changeset
|
936 pdae_params->pplayback->pass_audio(pdae_params->pplayback, FMT_S16_LE, 2, |
8f3188746b64
chase last changeset in aud
William Pitcock <nenolod@atheme.org>
parents:
1997
diff
changeset
|
937 bytecount, bytebuff, &pdae_params->pplayback->playing); |
1123 | 938 remainingbytes -= bytecount; |
939 bytebuff += bytecount; | |
940 } | |
941 pdae_params->currlsn += lsncount; | |
942 } | |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
943 CDDEBUG("dae ended\n"); |
1123 | 944 |
945 pdae_params->pplayback->playing = FALSE; | |
1314
b93270e2b7e4
Continuous playing in DAE mode works again
Calin Crisan ccrisan@gmail.com
parents:
1313
diff
changeset
|
946 pdae_params->pplayback->output->close_audio(); |
1123 | 947 is_paused = FALSE; |
948 | |
949 pdae_params->pplayback->output->close_audio(); | |
1958
2db72dd92ee3
Use glib types and functions in some places.
Matti Hamalainen <ccr@tnsp.org>
parents:
1708
diff
changeset
|
950 g_free(buffer); |
1123 | 951 } |
952 | |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
953 static gint calculate_track_length(gint startlsn, gint endlsn) |
1048 | 954 { |
955 return ((endlsn - startlsn + 1) * 1000) / 75; | |
956 } | |
957 | |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
958 static gint find_trackno_from_filename(gchar *filename) |
1048 | 959 { |
2040
997c71881e5b
No need for that long buffer.
Matti Hamalainen <ccr@tnsp.org>
parents:
2038
diff
changeset
|
960 gchar tracknostr[3]; |
1048 | 961 if ((filename == NULL) || strlen(filename) <= 6) |
962 return -1; | |
963 | |
964 strncpy(tracknostr, filename + strlen(filename) - 6, 2); | |
965 tracknostr[2] = '\0'; | |
966 return strtol(tracknostr, NULL, 10); | |
967 } | |
1123 | 968 |
1959
3fef1171cd6c
Basic start of cleanup of cdaudio-ng.
Matti Hamalainen <ccr@tnsp.org>
parents:
1958
diff
changeset
|
969 static void cleanup_on_error() |
1123 | 970 { |
1313
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
971 if (playing_track != -1) { |
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
972 playing_track = -1; |
1123 | 973 } |
1313
28df54b3eaea
Ejecting the cd while playing no longer crashes the player.
Calin Crisan ccrisan@gmail.com
parents:
1303
diff
changeset
|
974 |
1123 | 975 if (trackinfo != NULL) { |
1958
2db72dd92ee3
Use glib types and functions in some places.
Matti Hamalainen <ccr@tnsp.org>
parents:
1708
diff
changeset
|
976 g_free(trackinfo); |
1123 | 977 trackinfo = NULL; |
978 } | |
979 } | |
1193 | 980 |