annotate src/cdaudio-ng/cdaudio-ng.c @ 1378:7a7f446bc87c

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