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