annotate Plugins/Input/cdaudio/cdaudio.c @ 568:f34898e3333a trunk

[svn] Announce when we're building a library or binary objective, not just a component objective.
author nenolod
date Thu, 02 Feb 2006 14:47:26 -0800
parents 2291caab50ca
children c8cf439179b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1 /* XMMS - Cross-platform multimedia player
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
2 * Copyright (C) 1998-2003 Peter Alm, Mikael Alm, Olle Hallnas,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
3 * Thomas Nilsson and 4Front Technologies
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
4 * Copyright (C) 1999-2003 Haavard Kvaalen <havardk@xmms.org>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
5 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
9 * (at your option) any later version.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
10 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
14 * GNU General Public License for more details.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
15 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
19 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
20
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
21 #ifdef HAVE_CONFIG_H
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
22 # include "config.h"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
23 #endif
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
24
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
25 #include "cdaudio.h"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
26
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
27 #include <glib.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
28 #include <glib/gi18n.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
29 #include <glib/gprintf.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
30 #include <string.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
31
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
32 #include <unistd.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
33 #include <errno.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
34 #include <fcntl.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
35 #include <sys/ioctl.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
36 #include <sys/stat.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
37
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
38 #include <libaudacious/configdb.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
39 #include <libaudacious/util.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
40 #include <libaudacious/titlestring.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
41 #include "audacious/output.h"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
42
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
43 #ifdef CDROMSTOP
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
44 # define XMMS_STOP CDROMSTOP
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
45 #elif defined CDIOCSTOP
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
46 # define XMMS_STOP CDIOCSTOP
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
47 #else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
48 # error "No stop ioctl"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
49 #endif
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
50
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
51 #ifdef CDIOCPAUSE
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
52 # define XMMS_PAUSE CDIOCPAUSE
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
53 #elif defined CDROMPAUSE
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
54 # define XMMS_PAUSE CDROMPAUSE
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
55 #else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
56 # error "No pause ioctl"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
57 #endif
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
58
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
59 #ifdef CDIOCRESUME
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
60 # define XMMS_RESUME CDIOCRESUME
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
61 #elif defined CDROMRESUME
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
62 # define XMMS_RESUME CDROMRESUME
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
63 #else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
64 # error "No resume ioctl"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
65 #endif
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
66
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
67 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
68 * Distributions should not patch this, but instead use the
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
69 * --with-cdda-device=path and --with-cdda-dir=path configure options.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
70 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
71
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
72 #ifndef CDDA_DEVICE
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
73 # ifdef HAVE_SYS_CDIO_H
392
86c4cd37b812 [svn] Support for FreeBSD 6.x CD Audio DAE.
nenolod
parents: 61
diff changeset
74 # if defined(__FreeBSD__) && !defined(CDIOCREADAUDIO)
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
75 # define CDDA_DEVICE "/dev/acd0c"
392
86c4cd37b812 [svn] Support for FreeBSD 6.x CD Audio DAE.
nenolod
parents: 61
diff changeset
76 # elif defined __FreeBSD__
86c4cd37b812 [svn] Support for FreeBSD 6.x CD Audio DAE.
nenolod
parents: 61
diff changeset
77 # define CDDA_DEVICE "/dev/acd0"
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
78 # elif defined __OpenBSD__
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
79 # define CDDA_DEVICE "/dev/cd0c"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
80 # else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
81 # define CDDA_DEVICE "/vol/dev/aliases/cdrom0"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
82 # endif
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
83 # else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
84 # define CDDA_DEVICE "/dev/cdrom"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
85 # endif
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
86 #endif
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
87
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
88 #ifndef CDDA_DIRECTORY
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
89 # ifdef HAVE_SYS_CDIO_H
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
90 # ifdef __FreeBSD__
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
91 # define CDDA_DIRECTORY "/cdrom"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
92 # elif defined __OpenBSD__
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
93 # define CDDA_DIRECTORY "/cdrom"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
94 # else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
95 # define CDDA_DIRECTORY "/cdrom/cdrom0"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
96 # endif
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
97 # else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
98 # define CDDA_DIRECTORY "/mnt/cdrom"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
99 # endif
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
100 #endif
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
101
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
102
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
103
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
104
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
105 static char *cdda_get_title(cdda_disc_toc_t * toc, int track);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
106 static gboolean stop_timeout(gpointer data);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
107
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
108 static void cdda_init(void);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
109 static int is_our_file(char *filename);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
110 static GList *scan_dir(char *dir);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
111 static void play_file(char *filename);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
112 static void stop(void);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
113 static void cdda_pause(short p);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
114 static void seek(int time);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
115 static int get_time(void);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
116 static void get_song_info(char *filename, char **title, int *length);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
117 static void get_volume(int *l, int *r);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
118 static void set_volume(int l, int r);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
119 static void cleanup(void);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
120 void cdda_fileinfo(char *filename);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
121
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
122 InputPlugin cdda_ip = {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
123 NULL,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
124 NULL,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
125 NULL, /* Description */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
126 cdda_init,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
127 NULL, /* about */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
128 cdda_configure,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
129 is_our_file,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
130 scan_dir,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
131 play_file,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
132 stop,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
133 cdda_pause,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
134 seek,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
135 NULL, /* set_eq */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
136 get_time,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
137 get_volume,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
138 set_volume,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
139 cleanup,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
140 NULL, /* obsolete */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
141 NULL, /* add_vis_pcm */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
142 NULL, /* set_info, filled in by xmms */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
143 NULL, /* set_info_text, filled in by xmms */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
144 get_song_info,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
145 NULL, /* cdda_fileinfo, *//* file_info_box */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
146 NULL /* output plugin handle */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
147 };
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
148
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
149 CDDAConfig cdda_cfg;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
150
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
151 static struct {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
152 struct driveinfo drive;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
153 cdda_disc_toc_t cd_toc;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
154 int track;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
155 int fd;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
156 gboolean playing;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
157 } cdda_playing;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
158
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
159 static struct {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
160 GThread *thread;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
161 gboolean audio_error, eof;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
162 int seek;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
163
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
164 } dae_data;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
165
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
166 static gboolean is_paused;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
167 static int pause_time;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
168
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
169 struct timeout {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
170 int id;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
171 char *device;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
172 };
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
173
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
174 static GList *timeout_list;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
175
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
176 /* Time to delay stop command in 1/10 second */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
177 #define STOP_DELAY 20
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
178
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
179 InputPlugin *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
180 get_iplugin_info(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
181 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
182 cdda_ip.description = g_strdup_printf(_("CD Audio Plugin"));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
183 return &cdda_ip;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
184 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
185
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
186
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
187
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
188 #ifdef BEEP_CDROM_SOLARIS
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
189 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
190 * Lowlevel cdrom access, Solaris style (Solaris, Linux)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
191 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
192
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
193 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
194 play_ioctl(struct cdda_msf *start, struct cdda_msf *end)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
195 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
196 struct cdrom_msf msf;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
197
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
198 msf.cdmsf_min0 = start->minute;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
199 msf.cdmsf_sec0 = start->second;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
200 msf.cdmsf_frame0 = start->frame;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
201 msf.cdmsf_min1 = end->minute;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
202 msf.cdmsf_sec1 = end->second;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
203 msf.cdmsf_frame1 = end->frame;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
204 ioctl(cdda_playing.fd, CDROMPLAYMSF, &msf);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
205 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
206
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
207 static int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
208 get_current_frame(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
209 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
210 struct cdrom_subchnl subchnl;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
211
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
212 subchnl.cdsc_format = CDROM_MSF;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
213 if (ioctl(cdda_playing.fd, CDROMSUBCHNL, &subchnl) < 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
214 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
215
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
216 switch (subchnl.cdsc_audiostatus) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
217 case CDROM_AUDIO_COMPLETED:
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
218 case CDROM_AUDIO_ERROR:
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
219 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
220 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
221
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
222 return (LBA(subchnl.cdsc_absaddr.msf));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
223 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
224
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
225 #if !defined(CDROMVOLREAD)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
226 static int volume_left = 100, volume_right = 100;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
227 #endif
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
228
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
229 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
230 drive_get_volume(int *l, int *r)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
231 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
232 #if defined(CDROMVOLREAD)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
233 struct cdrom_volctrl vol;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
234
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
235 if (cdda_playing.fd != -1 && !ioctl(cdda_playing.fd, CDROMVOLREAD, &vol)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
236 *l = (100 * vol.channel0) / 255;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
237 *r = (100 * vol.channel1) / 255;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
238 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
239 #if 0
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
240 else if (cdda_playing.fd != -1)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
241 g_message("CDROMVOLREAD failed");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
242 #endif
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
243 #else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
244 *l = volume_left;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
245 *r = volume_right;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
246 #endif
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
247 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
248
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
249 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
250 drive_set_volume(int l, int r)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
251 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
252 struct cdrom_volctrl vol;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
253
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
254 if (cdda_playing.fd != -1) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
255 vol.channel0 = vol.channel2 = (l * 255) / 100;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
256 vol.channel1 = vol.channel3 = (r * 255) / 100;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
257 ioctl(cdda_playing.fd, CDROMVOLCTRL, &vol);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
258 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
259 #if !defined(CDROMVOLREAD)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
260 volume_left = l;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
261 volume_right = r;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
262 #endif
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
263 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
264
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
265 #ifdef CDROMREADAUDIO
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
266 int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
267 read_audio_data(int fd, int pos, int num, void *buf)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
268 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
269 struct cdrom_read_audio cdra;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
270
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
271 #if 1
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
272 cdra.addr.lba = pos - CDDA_MSF_OFFSET;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
273 cdra.addr_format = CDROM_LBA;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
274 #else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
275 cdra.addr.msf.minute = pos / (60 * 75);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
276 cdra.addr.msf.second = (pos / 75) % 60;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
277 cdra.addr.msf.frame = pos % 75;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
278 cdra.addr_format = CDROM_MSF;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
279 #endif
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
280
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
281 cdra.nframes = num;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
282 cdra.buf = buf;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
283
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
284 if (ioctl(fd, CDROMREADAUDIO, &cdra) < 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
285 return -errno;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
286
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
287 return cdra.nframes;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
288 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
289 #endif /* CDROMREADAUDIO */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
290
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
291 #if defined(CDROMCDDA)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
292 int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
293 read_audio_data(int fd, int pos, int num, void *buf)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
294 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
295 struct cdrom_cdda cdra;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
296
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
297 cdra.cdda_addr = pos - CDDA_MSF_OFFSET;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
298 cdra.cdda_length = num;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
299 cdra.cdda_data = buf;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
300 cdra.cdda_subcode = CDROM_DA_NO_SUBCODE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
301 if (ioctl(fd, CDROMCDDA, &cdra) < 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
302 return -errno;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
303
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
304 return cdra.cdda_length;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
305 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
306 #endif
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
307
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
308 static gboolean
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
309 cdda_get_toc_lowlevel(int fd, cdda_disc_toc_t * info)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
310 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
311 struct cdrom_tochdr tochdr;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
312 struct cdrom_tocentry tocentry;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
313 int i;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
314
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
315
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
316
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
317 if (ioctl(fd, CDROMREADTOCHDR, &tochdr))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
318 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
319
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
320 for (i = tochdr.cdth_trk0; i <= tochdr.cdth_trk1; i++) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
321 tocentry.cdte_format = CDROM_MSF;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
322 tocentry.cdte_track = i;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
323 if (ioctl(fd, CDROMREADTOCENTRY, &tocentry))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
324 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
325 info->track[i].minute = tocentry.cdte_addr.msf.minute;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
326 info->track[i].second = tocentry.cdte_addr.msf.second;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
327 info->track[i].frame = tocentry.cdte_addr.msf.frame;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
328 info->track[i].flags.data_track =
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
329 tocentry.cdte_ctrl == CDROM_DATA_TRACK;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
330
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
331 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
332
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
333 /* Get the leadout track */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
334 tocentry.cdte_track = CDROM_LEADOUT;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
335 tocentry.cdte_format = CDROM_MSF;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
336
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
337 if (ioctl(fd, CDROMREADTOCENTRY, &tocentry))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
338 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
339 info->leadout.minute = tocentry.cdte_addr.msf.minute;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
340 info->leadout.second = tocentry.cdte_addr.msf.second;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
341 info->leadout.frame = tocentry.cdte_addr.msf.frame;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
342
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
343 info->first_track = tochdr.cdth_trk0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
344 info->last_track = tochdr.cdth_trk1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
345
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
346 return TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
347 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
348
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
349 #endif
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
350
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
351 #ifdef BEEP_CDROM_BSD
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
352 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
353 * Lowlevel cdrom access, BSD style (FreeBSD, OpenBSD, NetBSD, Darwin)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
354 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
355
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
356 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
357 play_ioctl(struct cdda_msf *start, struct cdda_msf *end)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
358 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
359 struct ioc_play_msf msf;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
360
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
361 msf.start_m = start->minute;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
362 msf.start_s = start->second;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
363 msf.start_f = start->frame;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
364 msf.end_m = end->minute;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
365 msf.end_s = end->second;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
366 msf.end_f = end->frame;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
367 ioctl(cdda_playing.fd, CDIOCPLAYMSF, &msf);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
368 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
369
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
370 static int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
371 get_current_frame(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
372 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
373 struct ioc_read_subchannel subchnl;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
374 struct cd_sub_channel_info subinfo;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
375 subchnl.address_format = CD_MSF_FORMAT;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
376 subchnl.data_format = CD_CURRENT_POSITION;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
377 subchnl.track = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
378 subchnl.data_len = sizeof(subinfo);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
379 subchnl.data = &subinfo;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
380 if (ioctl(cdda_playing.fd, CDIOCREADSUBCHANNEL, &subchnl) < 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
381 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
382
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
383 #ifdef BEEP_CDROM_BSD_DARWIN
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
384 return ((subchnl.data->what.position.absaddr[1] * 60
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
385 subchnl.data->what.position.absaddr[2]) * 75 +
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
386 subchnl.data->what.position.absaddr[3]);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
387 #else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
388 return (LBA(subchnl.data->what.position.absaddr.msf));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
389 #endif
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
390 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
391
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
392 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
393 drive_get_volume(int *l, int *r)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
394 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
395 struct ioc_vol vol;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
396
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
397 if (cdda_playing.fd != -1) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
398 ioctl(cdda_playing.fd, CDIOCGETVOL, &vol);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
399 *l = (100 * vol.vol[0]) / 255;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
400 *r = (100 * vol.vol[1]) / 255;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
401 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
402 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
403
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
404 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
405 drive_set_volume(int l, int r)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
406 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
407 struct ioc_vol vol;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
408
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
409 if (cdda_playing.fd != -1) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
410 vol.vol[0] = vol.vol[2] = (l * 255) / 100;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
411 vol.vol[1] = vol.vol[3] = (r * 255) / 100;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
412 ioctl(cdda_playing.fd, CDIOCSETVOL, &vol);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
413 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
414 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
415
392
86c4cd37b812 [svn] Support for FreeBSD 6.x CD Audio DAE.
nenolod
parents: 61
diff changeset
416 #if defined(__FreeBSD__) && !defined(CDIOCREADAUDIO)
86c4cd37b812 [svn] Support for FreeBSD 6.x CD Audio DAE.
nenolod
parents: 61
diff changeset
417 int
86c4cd37b812 [svn] Support for FreeBSD 6.x CD Audio DAE.
nenolod
parents: 61
diff changeset
418 read_audio_data(int fd, int pos, int num, void *buf)
86c4cd37b812 [svn] Support for FreeBSD 6.x CD Audio DAE.
nenolod
parents: 61
diff changeset
419 {
86c4cd37b812 [svn] Support for FreeBSD 6.x CD Audio DAE.
nenolod
parents: 61
diff changeset
420 int bs = CD_FRAMESIZE_RAW;
86c4cd37b812 [svn] Support for FreeBSD 6.x CD Audio DAE.
nenolod
parents: 61
diff changeset
421
86c4cd37b812 [svn] Support for FreeBSD 6.x CD Audio DAE.
nenolod
parents: 61
diff changeset
422 if (ioctl(fd, CDRIOCSETBLOCKSIZE, &bs) == -1)
86c4cd37b812 [svn] Support for FreeBSD 6.x CD Audio DAE.
nenolod
parents: 61
diff changeset
423 return -1;
86c4cd37b812 [svn] Support for FreeBSD 6.x CD Audio DAE.
nenolod
parents: 61
diff changeset
424 if (pread(fd, buf, num * bs, (pos - 150) * bs) != num * bs)
86c4cd37b812 [svn] Support for FreeBSD 6.x CD Audio DAE.
nenolod
parents: 61
diff changeset
425 return -1;
86c4cd37b812 [svn] Support for FreeBSD 6.x CD Audio DAE.
nenolod
parents: 61
diff changeset
426
86c4cd37b812 [svn] Support for FreeBSD 6.x CD Audio DAE.
nenolod
parents: 61
diff changeset
427 return num;
86c4cd37b812 [svn] Support for FreeBSD 6.x CD Audio DAE.
nenolod
parents: 61
diff changeset
428 }
86c4cd37b812 [svn] Support for FreeBSD 6.x CD Audio DAE.
nenolod
parents: 61
diff changeset
429 #endif
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
430
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
431 #if defined(CDIOCREADAUDIO)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
432 int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
433 read_audio_data(int fd, int pos, int num, void *buf)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
434 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
435 struct ioc_read_audio cdra;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
436
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
437 cdra.address.lba = pos - CDDA_MSF_OFFSET;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
438 cdra.address_format = CD_LBA_FORMAT;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
439 cdra.nframes = num;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
440 cdra.buffer = buf;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
441
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
442 if (ioctl(fd, CDIOCREADAUDIO, &cdra) < 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
443 return -errno;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
444
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
445 return cdra.nframes;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
446 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
447 #endif /* CDIOCREADAUDIO */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
448
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
449 #ifdef BEEP_CDROM_BSD_NETBSD /* NetBSD, OpenBSD */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
450
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
451 static gboolean
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
452 cdda_get_toc_lowlevel(int fd, cdda_disc_toc_t * info)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
453 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
454 struct ioc_toc_header tochdr;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
455 struct ioc_read_toc_entry tocentry;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
456 struct cd_toc_entry tocentrydata;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
457 int i;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
458
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
459 if (ioctl(fd, CDIOREADTOCHEADER, &tochdr))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
460 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
461
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
462 for (i = tochdr.starting_track; i <= tochdr.ending_track; i++) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
463 tocentry.address_format = CD_MSF_FORMAT;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
464
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
465 tocentry.starting_track = i;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
466 tocentry.data = &tocentrydata;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
467 tocentry.data_len = sizeof(tocentrydata);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
468 if (ioctl(fd, CDIOREADTOCENTRYS, &tocentry))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
469 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
470 info->track[i].minute = tocentry.data->addr.msf.minute;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
471 info->track[i].second = tocentry.data->addr.msf.second;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
472 info->track[i].frame = tocentry.data->addr.msf.frame;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
473 info->track[i].flags.data_track = (tocentry.data->control & 4) == 4;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
474 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
475
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
476 /* Get the leadout track */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
477 tocentry.address_format = CD_MSF_FORMAT;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
478
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
479 tocentry.starting_track = 0xAA;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
480 tocentry.data = &tocentrydata;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
481 tocentry.data_len = sizeof(tocentrydata);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
482 if (ioctl(fd, CDIOREADTOCENTRYS, &tocentry))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
483 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
484 info->leadout.minute = tocentry.data->addr.msf.minute;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
485 info->leadout.second = tocentry.data->addr.msf.second;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
486 info->leadout.frame = tocentry.data->addr.msf.frame;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
487
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
488 info->first_track = tochdr.starting_track;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
489 info->last_track = tochdr.ending_track;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
490
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
491 return TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
492 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
493
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
494 #elif defined(BEEP_CDROM_BSD_DARWIN)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
495
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
496 static gboolean
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
497 cdda_get_toc_lowlevel(int fd, cdda_disc_toc_t * info)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
498 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
499 struct ioc_toc_header tochdr;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
500 struct ioc_read_toc_entry tocentry;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
501 int i;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
502
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
503 if (ioctl(fd, CDIOREADTOCHEADER, &tochdr))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
504 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
505
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
506 for (i = tochdr.starting_track; i <= tochdr.ending_track; i++) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
507 tocentry.address_format = CD_MSF_FORMAT;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
508
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
509 tocentry.starting_track = i;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
510 if (ioctl(fd, CDIOREADTOCENTRYS, &tocentry))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
511 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
512 info->track[i].minute = tocentry.data->addr[1];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
513 info->track[i].second = tocentry.data->addr[2];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
514 info->track[i].frame = tocentry.data->addr[3];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
515 info->track[i].flags.data_track = (tocentry.data->control & 4) == 4;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
516 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
517
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
518 /* Get the leadout track */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
519 tocentry.address_format = CD_MSF_FORMAT;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
520
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
521 tocentry.starting_track = 0xAA;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
522 if (ioctl(fd, CDIOREADTOCENTRYS, &tocentry))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
523 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
524 info->leadout.minute = tocentry.data->addr[1];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
525 info->leadout.second = tocentry.data->addr[2];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
526 info->leadout.frame = tocentry.data->addr[3];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
527
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
528 return TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
529 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
530
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
531 #else /* FreeBSD */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
532
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
533 static gboolean
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
534 cdda_get_toc_lowlevel(int fd, cdda_disc_toc_t * info)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
535 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
536 struct ioc_toc_header tochdr;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
537 struct ioc_read_toc_single_entry tocentry;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
538 int i;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
539
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
540 if (ioctl(fd, CDIOREADTOCHEADER, &tochdr))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
541 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
542
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
543 for (i = tochdr.starting_track; i <= tochdr.ending_track; i++) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
544 tocentry.address_format = CD_MSF_FORMAT;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
545
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
546 tocentry.track = i;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
547 if (ioctl(fd, CDIOREADTOCENTRY, &tocentry))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
548 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
549 info->track[i].minute = tocentry.entry.addr.msf.minute;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
550 info->track[i].second = tocentry.entry.addr.msf.second;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
551 info->track[i].frame = tocentry.entry.addr.msf.frame;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
552 info->track[i].flags.data_track = (tocentry.entry.control & 4) == 4;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
553 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
554
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
555 /* Get the leadout track */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
556 tocentry.address_format = CD_MSF_FORMAT;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
557
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
558 tocentry.track = 0xAA;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
559 if (ioctl(fd, CDIOREADTOCENTRY, &tocentry))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
560 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
561 info->leadout.minute = tocentry.entry.addr.msf.minute;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
562 info->leadout.second = tocentry.entry.addr.msf.second;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
563 info->leadout.frame = tocentry.entry.addr.msf.frame;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
564
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
565 info->first_track = tochdr.starting_track;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
566 info->last_track = tochdr.ending_track;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
567
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
568 return TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
569 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
570 #endif
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
571
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
572 #endif
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
573
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
574
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
575
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
576
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
577
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
578
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
579
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
580
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
581
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
582
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
583
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
584 extern gboolean
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
585 is_mounted(const char *device_name)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
586 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
587 #if defined(HAVE_MNTENT_H) || defined(HAVE_GETMNTINFO)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
588 char devname[256];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
589 struct stat st;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
590 #if defined(HAVE_MNTENT_H)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
591 FILE *mounts;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
592 struct mntent *mnt;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
593 #elif defined(HAVE_GETMNTINFO)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
594 struct statfs *fsp;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
595 int entries;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
596 #endif
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
597
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
598 if (lstat(device_name, &st) < 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
599 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
600
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
601 if (S_ISLNK(st.st_mode))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
602 readlink(device_name, devname, 256);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
603 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
604 strncpy(devname, device_name, 256);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
605
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
606 #if defined(HAVE_MNTENT_H)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
607 if ((mounts = setmntent(MOUNTED, "r")) == NULL)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
608 return TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
609
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
610 while ((mnt = getmntent(mounts)) != NULL) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
611 if (strcmp(mnt->mnt_fsname, devname) == 0) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
612 endmntent(mounts);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
613 return TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
614 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
615 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
616 endmntent(mounts);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
617 #elif defined(HAVE_GETMNTINFO)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
618 entries = getmntinfo(&fsp, MNT_NOWAIT);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
619 if (entries < 0)
419
2291caab50ca [svn] FreeBSD 6.x/7.x newata cdrio fixes. (I now have an ia32 box to work with ;))
nenolod
parents: 392
diff changeset
620 return FALSE;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
621
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
622 while (entries-- > 0) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
623 if (!strcmp(fsp->f_mntfromname, devname))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
624 return TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
625 fsp++;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
626 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
627 #endif
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
628 #endif
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
629 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
630 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
631
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
632
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
633 gboolean
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
634 cdda_get_toc(cdda_disc_toc_t * info, const char *device)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
635 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
636 gboolean retv = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
637 int fd;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
638
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
639 if (is_mounted(device))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
640 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
641
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
642 if ((fd = open(device, CDOPENFLAGS)) == -1)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
643 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
644
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
645 memset(info, 0, sizeof(cdda_disc_toc_t));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
646
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
647 retv = cdda_get_toc_lowlevel(fd, info);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
648 close(fd);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
649
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
650 return retv;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
651 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
652
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
653 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
654 cdda_init(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
655 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
656 ConfigDb *db;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
657 struct driveinfo *drive = g_malloc0(sizeof(struct driveinfo));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
658 int ndrives = 1, i;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
659
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
660 cdda_playing.fd = -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
661 memset(&cdda_cfg, 0, sizeof(CDDAConfig));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
662
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
663 #ifdef HAVE_OSS
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
664 drive->mixer = CDDA_MIXER_OSS;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
665 drive->oss_mixer = SOUND_MIXER_CD;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
666 #endif
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
667
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
668 db = bmp_cfg_db_open();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
669
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
670 /* These names are used for backwards compatibility */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
671 bmp_cfg_db_get_string(db, "CDDA", "device", &drive->device);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
672 bmp_cfg_db_get_string(db, "CDDA", "directory", &drive->directory);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
673 bmp_cfg_db_get_int(db, "CDDA", "mixer", &drive->mixer);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
674 bmp_cfg_db_get_int(db, "CDDA", "readmode", &drive->dae);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
675
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
676 if (!drive->device)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
677 drive->device = g_strdup(CDDA_DEVICE);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
678 if (!drive->directory)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
679 drive->directory = g_strdup(CDDA_DIRECTORY);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
680
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
681 cdda_cfg.drives = g_list_append(cdda_cfg.drives, drive);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
682
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
683 bmp_cfg_db_get_int(db, "CDDA", "num_drives", &ndrives);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
684 for (i = 1; i < ndrives; i++) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
685 char label[20];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
686 drive = g_malloc0(sizeof(struct driveinfo));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
687
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
688 sprintf(label, "device%d", i);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
689 bmp_cfg_db_get_string(db, "CDDA", label, &drive->device);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
690
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
691 sprintf(label, "directory%d", i);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
692 bmp_cfg_db_get_string(db, "CDDA", label, &drive->directory);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
693
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
694 sprintf(label, "mixer%d", i);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
695 bmp_cfg_db_get_int(db, "CDDA", label, &drive->mixer);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
696
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
697 sprintf(label, "readmode%d", i);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
698 bmp_cfg_db_get_int(db, "CDDA", label, &drive->dae);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
699
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
700 cdda_cfg.drives = g_list_append(cdda_cfg.drives, drive);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
701 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
702 bmp_cfg_db_get_bool(db, "CDDA", "title_override",
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
703 &cdda_cfg.title_override);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
704 bmp_cfg_db_get_string(db, "CDDA", "name_format", &cdda_cfg.name_format);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
705 bmp_cfg_db_get_bool(db, "CDDA", "use_cddb", &cdda_cfg.use_cddb);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
706 bmp_cfg_db_get_string(db, "CDDA", "cddb_server", &cdda_cfg.cddb_server);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
707 #ifdef WITH_CDINDEX
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
708 bmp_cfg_db_get_bool(db, "CDDA", "use_cdin", &cdda_cfg.use_cdin);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
709 #else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
710 cdda_cfg.use_cdin = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
711 #endif
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
712 bmp_cfg_db_get_string(db, "CDDA", "cdin_server", &cdda_cfg.cdin_server);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
713 bmp_cfg_db_close(db);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
714
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
715 if (!cdda_cfg.cdin_server)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
716 cdda_cfg.cdin_server = g_strdup("www.cdindex.org");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
717 if (!cdda_cfg.cddb_server)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
718 cdda_cfg.cddb_server = g_strdup(CDDB_DEFAULT_SERVER);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
719 if (!cdda_cfg.name_format)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
720 cdda_cfg.name_format = g_strdup("%p - %t");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
721 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
722
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
723 struct driveinfo *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
724 cdda_find_drive(char *filename)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
725 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
726 GList *node;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
727
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
728 // FIXME: Will always return the first drive
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
729
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
730 for (node = cdda_cfg.drives; node; node = node->next) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
731 struct driveinfo *d = node->data;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
732 if (!strncmp(d->directory, filename, strlen(d->directory)))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
733 return d;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
734 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
735
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
736 return NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
737
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
738 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
739
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
740 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
741 timeout_destroy(struct timeout *entry)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
742 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
743 g_free(entry->device);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
744 g_free(entry);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
745 timeout_list = g_list_remove(timeout_list, entry);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
746 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
747
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
748 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
749 timeout_remove_for_device(char *device)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
750 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
751 GList *node;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
752
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
753 for (node = timeout_list; node; node = node->next) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
754 struct timeout *t = node->data;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
755
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
756 if (!strcmp(t->device, device)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
757 gtk_timeout_remove(t->id);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
758 timeout_destroy(t);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
759 return;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
760 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
761 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
762
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
763 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
764
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
765 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
766 cleanup(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
767 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
768 while (timeout_list) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
769 struct timeout *t = timeout_list->data;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
770 gtk_timeout_remove(t->id);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
771 stop_timeout(t);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
772 timeout_destroy(t);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
773 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
774 cddb_quit();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
775 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
776
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
777 static int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
778 is_our_file(char *filename)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
779 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
780 char *ext = ".cda";
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
781
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
782 if (cdda_find_drive(filename) == NULL) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
783 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
784 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
785
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
786 if (g_str_has_suffix(filename, ext)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
787 return TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
788 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
789 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
790 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
791
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
792
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
793 static GList *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
794 scan_dir(char *dir)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
795 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
796 GList *list = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
797 int i;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
798 cdda_disc_toc_t toc;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
799 struct driveinfo *drive;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
800
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
801 if ((drive = cdda_find_drive(dir)) == NULL)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
802 return NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
803
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
804 if (!cdda_get_toc(&toc, drive->device))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
805 return NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
806
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
807 for (i = toc.last_track; i >= toc.first_track; i--)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
808 if (!toc.track[i].flags.data_track) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
809 list = g_list_prepend(list, g_strdup_printf("Track %02d.cda", i));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
810 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
811 return list;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
812 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
813
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
814 guint
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
815 cdda_calculate_track_length(cdda_disc_toc_t * toc, int track)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
816 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
817 if (track == toc->last_track)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
818 return (LBA(toc->leadout) - LBA(toc->track[track]));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
819 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
820 return (LBA(toc->track[track + 1]) - LBA(toc->track[track]));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
821 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
822
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
823 static void *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
824 dae_play_loop(void *arg)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
825 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
826 char *buffer = g_malloc(CD_FRAMESIZE_RAW * CDDA_DAE_FRAMES);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
827 int pos = LBA(cdda_playing.cd_toc.track[cdda_playing.track]);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
828 int end, frames;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
829
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
830 if (cdda_playing.track == cdda_playing.cd_toc.last_track)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
831 end = LBA(cdda_playing.cd_toc.leadout);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
832 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
833 end = LBA(cdda_playing.cd_toc.track[cdda_playing.track + 1]);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
834
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
835 while (cdda_playing.playing) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
836 int left;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
837 char *data;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
838
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
839 if (dae_data.seek != -1) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
840 cdda_ip.output->flush(dae_data.seek * 1000);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
841 pos = LBA(cdda_playing.cd_toc.track[cdda_playing.track])
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
842 + dae_data.seek * 75;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
843 dae_data.seek = -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
844 dae_data.eof = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
845 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
846 frames = MIN(CDDA_DAE_FRAMES, end - pos);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
847 if (frames == 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
848 dae_data.eof = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
849
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
850 if (dae_data.eof) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
851 xmms_usleep(30000);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
852 continue;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
853 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
854
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
855 frames = read_audio_data(cdda_playing.fd, pos, frames, buffer);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
856 if (frames <= 0) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
857 int err = -frames;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
858 if (err == EOPNOTSUPP)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
859 dae_data.eof = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
860 else {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
861 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
862 * If the read failed, skip ahead to
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
863 * avoid getting stuck on scratches
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
864 * and such.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
865 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
866 g_message("read_audio_data() failed: %s (%d)",
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
867 strerror(err), err);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
868 pos += MIN(CDDA_DAE_FRAMES, end - pos);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
869 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
870 continue;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
871 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
872 left = frames * CD_FRAMESIZE_RAW;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
873 data = buffer;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
874 while (cdda_playing.playing && left > 0 && dae_data.seek == -1) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
875 int cur = MIN(512 * 2 * 2, left);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
876 cdda_ip.add_vis_pcm(cdda_ip.output->written_time(),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
877 FMT_S16_LE, 2, cur, data);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
878 while (cdda_ip.output->buffer_free() < cur &&
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
879 cdda_playing.playing && dae_data.seek == -1)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
880 xmms_usleep(30000);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
881 if (cdda_playing.playing && dae_data.seek == -1)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
882 produce_audio(cdda_ip.output->written_time(), FMT_S16_LE, 2, cur, data, &cdda_playing.playing);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
883 left -= cur;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
884 data += cur;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
885 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
886 pos += frames;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
887 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
888
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
889 cdda_ip.output->buffer_free();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
890 cdda_ip.output->buffer_free();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
891 g_free(buffer);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
892
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
893 g_thread_exit(NULL);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
894 return NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
895 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
896
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
897 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
898 dae_play(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
899 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
900 if (cdda_ip.output->open_audio(FMT_S16_LE, 44100, 2) == 0) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
901 dae_data.audio_error = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
902 cdda_playing.playing = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
903 return;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
904 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
905 dae_data.seek = -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
906 dae_data.eof = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
907 dae_data.audio_error = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
908 dae_data.thread = g_thread_create(dae_play_loop, NULL, TRUE, NULL);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
909 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
910
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
911 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
912 play_file(char *filename)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
913 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
914 char *tmp;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
915 struct driveinfo *drive;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
916 int track;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
917 int track_len;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
918
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
919 // g_message(g_strdup_printf("** CD_AUDIO: trying to play file %s",filename));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
920
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
921 if ((drive = cdda_find_drive(filename)) == NULL) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
922 // g_message("** CD_AUDIO: find drive check failed");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
923 return;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
924 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
925 if (is_mounted(drive->device)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
926 // g_message("** CD_AUDIO: drive is mounted");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
927 return;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
928 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
929 tmp = strrchr(filename, '/');
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
930 if (tmp)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
931 tmp++;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
932 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
933 tmp = filename;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
934
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
935 if (!sscanf(tmp, "Track %d.cda", &track)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
936 // g_message("** CD_AUDIO: filename check failed");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
937 return;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
938 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
939
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
940 if (!cdda_get_toc(&cdda_playing.cd_toc, drive->device) ||
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
941 cdda_playing.cd_toc.track[track].flags.data_track ||
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
942 track < cdda_playing.cd_toc.first_track ||
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
943 track > cdda_playing.cd_toc.last_track) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
944 // g_message("** CD_AUDIO: toc check failed");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
945 return;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
946 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
947
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
948 if ((cdda_playing.fd = open(drive->device, CDOPENFLAGS)) == -1) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
949 // g_message("** CD_AUDIO: device open failed");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
950 return;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
951 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
952 track_len = cdda_calculate_track_length(&cdda_playing.cd_toc, track);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
953 cdda_ip.set_info(cdda_get_title(&cdda_playing.cd_toc, track),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
954 (track_len * 1000) / 75, 44100 * 2 * 2 * 8, 44100, 2);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
955
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
956 memcpy(&cdda_playing.drive, drive, sizeof(struct driveinfo));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
957 #ifndef CDDA_HAS_READAUDIO
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
958 cdda_playing.drive.dae = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
959 #endif
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
960
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
961 cdda_playing.track = track;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
962
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
963 is_paused = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
964 timeout_remove_for_device(drive->device);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
965
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
966 cdda_playing.playing = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
967 if (drive->dae)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
968 dae_play();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
969 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
970 seek(0);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
971 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
972
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
973 static char *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
974 cdda_get_title(cdda_disc_toc_t * toc, int track)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
975 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
976 G_LOCK_DEFINE_STATIC(title);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
977
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
978 static guint32 cached_id;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
979 static cdinfo_t cdinfo;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
980 TitleInput *input;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
981 guint32 disc_id;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
982 char *title;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
983
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
984 disc_id = cdda_cddb_compute_discid(toc);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
985
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
986 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
987 * We want to avoid looking up a album from two threads simultaneously.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
988 * This can happen since we are called both from the main-thread and
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
989 * from the playlist-thread.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
990 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
991
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
992 G_LOCK(title);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
993 if (!(disc_id == cached_id && cdinfo.is_valid)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
994 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
995 * We try to look up the disc again if the info is not
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
996 * valid. The user might have configured a new server
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
997 * in the meantime.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
998 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
999 cdda_cdinfo_flush(&cdinfo);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1000 cached_id = disc_id;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1001
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1002 if (!cdda_cdinfo_read_file(disc_id, &cdinfo)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1003 if (cdda_cfg.use_cddb)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1004 cdda_cddb_get_info(toc, &cdinfo);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1005 if (cdinfo.is_valid)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1006 cdda_cdinfo_write_file(disc_id, &cdinfo);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1007 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1008 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1009 XMMS_NEW_TITLEINPUT(input);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1010 cdda_cdinfo_get(&cdinfo, track, &input->performer, &input->album_name,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1011 &input->track_name);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1012 G_UNLOCK(title);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1013
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1014 input->track_number = track;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1015 input->file_name = input->file_path =
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1016 g_strdup_printf(_("CD Audio Track %02u"), track);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1017 input->file_ext = "cda";
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1018 title = xmms_get_titlestring(cdda_cfg.title_override ?
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1019 cdda_cfg.name_format :
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1020 xmms_get_gentitle_format(), input);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1021 g_free(input->file_name);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1022 g_free(input);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1023
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1024 if (!title)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1025 title = g_strdup_printf(_("CD Audio Track %02u"), track);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1026 return title;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1027 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1028
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1029 static gboolean
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1030 stop_timeout(gpointer data)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1031 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1032 int fd;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1033 struct timeout *to = data;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1034
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1035 fd = open(to->device, CDOPENFLAGS);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1036 if (fd != -1) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1037 ioctl(fd, XMMS_STOP, 0);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1038 close(fd);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1039 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1040 timeout_destroy(to);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1041 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1042 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1043
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1044 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1045 stop(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1046 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1047 struct timeout *to_info;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1048 if (cdda_playing.fd < 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1049 return;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1050
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1051 cdda_playing.playing = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1052
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1053 if (cdda_playing.drive.dae) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1054 g_thread_join(dae_data.thread);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1055 cdda_ip.output->close_audio();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1056 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1057 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1058 ioctl(cdda_playing.fd, XMMS_PAUSE, 0);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1059
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1060 close(cdda_playing.fd);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1061 cdda_playing.fd = -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1062
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1063 if (!cdda_playing.drive.dae) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1064 to_info = g_malloc(sizeof(*to_info));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1065 to_info->device = g_strdup(cdda_playing.drive.device);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1066 to_info->id = gtk_timeout_add(STOP_DELAY * 100, stop_timeout,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1067 to_info);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1068 timeout_list = g_list_prepend(timeout_list, to_info);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1069 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1070 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1071
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1072 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1073 cdda_pause(short p)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1074 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1075 if (cdda_playing.drive.dae) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1076 cdda_ip.output->pause(p);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1077 return;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1078 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1079 if (p) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1080 pause_time = get_time();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1081 ioctl(cdda_playing.fd, XMMS_PAUSE, 0);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1082 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1083 else {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1084 ioctl(cdda_playing.fd, XMMS_RESUME, 0);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1085 pause_time = -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1086 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1087 is_paused = p;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1088 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1089
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1090
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1091
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1092 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1093 seek(int time)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1094 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1095 struct cdda_msf *end, start;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1096 int track = cdda_playing.track;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1097
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1098 // g_message("** CD_AUDIO: seeking...");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1099 if (cdda_playing.drive.dae) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1100 dae_data.seek = time;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1101 while (dae_data.seek != -1)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1102 xmms_usleep(20000);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1103 return;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1104 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1105
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1106 start.minute = (cdda_playing.cd_toc.track[track].minute * 60 +
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1107 cdda_playing.cd_toc.track[track].second + time) / 60;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1108 start.second = (cdda_playing.cd_toc.track[track].second + time) % 60;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1109 start.frame = cdda_playing.cd_toc.track[track].frame;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1110 if (track == cdda_playing.cd_toc.last_track)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1111 end = &cdda_playing.cd_toc.leadout;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1112 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1113 end = &cdda_playing.cd_toc.track[track + 1];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1114
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1115 play_ioctl(&start, end);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1116
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1117 if (is_paused) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1118 cdda_pause(TRUE);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1119 pause_time = time * 1000;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1120 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1121 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1122
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1123 static int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1124 get_time_analog(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1125 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1126 int frame, start_frame, length;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1127 int track = cdda_playing.track;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1128
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1129 if (is_paused && pause_time != -1)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1130 return pause_time;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1131
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1132 frame = get_current_frame();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1133
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1134 if (frame == -1)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1135 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1136
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1137 start_frame = LBA(cdda_playing.cd_toc.track[track]);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1138 length = cdda_calculate_track_length(&cdda_playing.cd_toc, track);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1139
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1140 if (frame - start_frame >= length - 20) /* 20 seems to work better */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1141 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1142
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1143 return ((frame - start_frame) * 1000) / 75;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1144 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1145
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1146 static int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1147 get_time_dae(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1148 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1149 if (dae_data.audio_error)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1150 return -2;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1151 if (!cdda_playing.playing ||
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1152 (dae_data.eof && !cdda_ip.output->buffer_playing()))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1153 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1154 return cdda_ip.output->output_time();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1155 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1156
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1157 static int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1158 get_time(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1159 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1160 if (cdda_playing.fd == -1)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1161 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1162
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1163 if (cdda_playing.drive.dae)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1164 return get_time_dae();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1165 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1166 return get_time_analog();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1167 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1168
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1169 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1170 get_song_info(char *filename, char **title, int *len)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1171 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1172 cdda_disc_toc_t toc;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1173 int t;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1174 char *tmp;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1175 struct driveinfo *drive;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1176
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1177 *title = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1178 *len = -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1179
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1180 // g_message("** CD_AUDIO: getting song info");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1181
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1182 if ((drive = cdda_find_drive(filename)) == NULL)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1183 return;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1184
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1185 tmp = strrchr(filename, '/');
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1186 if (tmp)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1187 tmp++;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1188 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1189 tmp = filename;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1190
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1191 if (!sscanf(tmp, "Track %d.cda", &t))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1192 return;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1193 if (!cdda_get_toc(&toc, drive->device))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1194 return;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1195 if (t < toc.first_track || t > toc.last_track
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1196 || toc.track[t].flags.data_track)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1197 return;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1198
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1199 *len = (cdda_calculate_track_length(&toc, t) * 1000) / 75;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1200 *title = cdda_get_title(&toc, t);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1201 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1202
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1203 #ifdef HAVE_OSS
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1204 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1205 oss_get_volume(int *l, int *r, int mixer_line)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1206 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1207 int fd, v;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1208
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1209 fd = open(DEV_MIXER, O_RDONLY);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1210 if (fd != -1) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1211 ioctl(fd, MIXER_READ(mixer_line), &v);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1212 *r = (v & 0xFF00) >> 8;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1213 *l = (v & 0x00FF);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1214 close(fd);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1215 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1216 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1217
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1218 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1219 oss_set_volume(int l, int r, int mixer_line)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1220 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1221 int fd, v;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1222
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1223 fd = open(DEV_MIXER, O_RDONLY);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1224 if (fd != -1) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1225 v = (r << 8) | l;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1226 ioctl(fd, MIXER_WRITE(mixer_line), &v);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1227 close(fd);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1228 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1229 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1230 #else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1231 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1232 oss_get_volume(int *l, int *r, int mixer_line)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1233 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1234 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1235 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1236 oss_set_volume(int l, int r, int mixer_line)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1237 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1238 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1239 #endif
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1240
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1241
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1242 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1243 get_volume(int *l, int *r)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1244 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1245 if (cdda_playing.drive.dae)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1246 cdda_ip.output->get_volume(l, r);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1247 else if (cdda_playing.drive.mixer == CDDA_MIXER_OSS)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1248 oss_get_volume(l, r, cdda_playing.drive.oss_mixer);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1249 else if (cdda_playing.drive.mixer == CDDA_MIXER_DRIVE)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1250 drive_get_volume(l, r);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1251 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1252
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1253 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1254 set_volume(int l, int r)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1255 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1256 if (cdda_playing.drive.dae)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1257 cdda_ip.output->set_volume(l, r);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1258 else if (cdda_playing.drive.mixer == CDDA_MIXER_OSS)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1259 oss_set_volume(l, r, cdda_playing.drive.oss_mixer);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1260 else if (cdda_playing.drive.mixer == CDDA_MIXER_DRIVE)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1261 drive_set_volume(l, r);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1262 }