1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
|
/* gstcdplay
* Copyright (c) 2002 Charles Schmidt <cbschmid@uiuc.edu>
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CDROM_BSD_NETBSD /* net & open */
#ifndef CDIOREADTOCHDR
#define CDIOREADTOCHDR CDIOREADTOCHEADER
#endif
gboolean cd_init(struct cd *cd,const gchar *device)
{
struct ioc_toc_header toc_header;
struct ioc_read_toc_entry toc_entry;
struct cd_toc_entry toc_entry_data;
guint i;
cd->fd = open(device,O_RDONLY | O_NONBLOCK);
if (cd->fd == -1) {
return FALSE;
}
/* get the toc header information */
if (ioctl(cd->fd,CDIOREADTOCHDR,&toc_header) != 0) {
close(cd->fd);
cd->fd = -1;
return FALSE;
}
/* read each entry in the toc header */
for (i = 1; i <= toc_header.ending_track; i++) {
toc_entry.address_format = CD_MSF_FORMAT;
toc_entry.starting_track = i;
toc_entry.data = &toc_entry_data;
toc_entry.data_len = sizeof(toc_entry_data);
if (ioctl(cd->fd,CDIOREADTOCENTRYS,&toc_entry) != 0) {
close(cd->fd);
cd->fd = -1;
return FALSE;
}
cd->tracks[i].minute = toc_entry.data->addr.msf.minute;
cd->tracks[i].second = toc_entry.data->addr.msf.second;
cd->tracks[i].frame = toc_entry.data->addr.msf.frame;
cd->tracks[i].data_track = (toc_entry.data->control & 4) == 4;
}
/* read the leadout */
toc_entry.address_format = CD_MSF_FORMAT;
toc_entry.starting_track = 0xAA; /* leadout */
toc_entry.data = &toc_entry_data;
toc_entry.data_len = sizeof(toc_entry_data);
if (ioctl(cd->fd,CDIOREADTOCENTRYS,&toc_entry) != 0) {
close(cd->fd);
cd->fd = -1;
return FALSE;
}
cd->tracks[LEADOUT].minute = toc_entry.data->addr.msf.minute;
cd->tracks[LEADOUT].second = toc_entry.data->addr.msf.second;
cd->tracks[LEADOUT].frame = toc_entry.data->addr.msf.frame;
cd->num_tracks = toc_header.ending_track;
return TRUE;
}
#elif defined HAVE_CDROM_BSD_DARWIN
gboolean cd_init(struct cd *cd,const gchar *device)
{
struct ioc_toc_header toc_header;
struct ioc_read_toc_entry toc_entry;
guint i;
cd->fd = open(device,O_RDONLY | O_NONBLOCK);
if (cd->fd == -1) {
return FALSE;
}
/* get the toc header information */
if (ioctl(cd->fd,CDIOREADTOCHDR,&toc_header) != 0) {
close(cd->fd);
cd->fd = -1;
return FALSE;
}
/* read each entry in the toc header */
for (i = 1; i <= toc_header.ending_track; i++) {
toc_entry.address_format = CD_MSF_FORMAT;
toc_entry.starting_track = i;
if (ioctl(cd->fd,CDIOREADTOCENTRYS,&toc_entry) != 0) {
close(cd->fd);
cd->fd = -1;
return FALSE;
}
cd->tracks[i].minute = toc_entry.data->addr[1];
cd->tracks[i].second = toc_entry.data->addr[2];
cd->tracks[i].frame = toc_entry.data->addr[3];
cd->tracks[i].data_track = (toc_entry.data->control & 4) == 4;
}
/* read the leadout */
toc_entry.address_format = CD_MSF_FORMAT;
toc_entry.starting_track = 0xAA; /* leadout */
toc_entry.data = &toc_entry_data;
toc_entry.data_len = sizeof(toc_entry_data);
if (ioctl(cd->fd,CDIOREADTOCENTRYS,&toc_entry) != 0) {
close(cd->fd);
cd->fd = -1;
return FALSE;
}
cd->tracks[LEADOUT].minute = toc_entry.data->addr[1];
cd->tracks[LEADOUT].second = toc_entry.data->addr[2];
cd->tracks[LEADOUT].frame = toc_entry.data->addr[3];
cd->num_tracks = toc_header.ending_track;
return TRUE;
}
#else /* free */
gboolean cd_init(struct cd *cd,const gchar *device)
{
struct ioc_toc_header toc_header;
struct ioc_read_toc_entry toc_entry;
guint i;
cd->fd = open(device,O_RDONLY | O_NONBLOCK);
if (cd->fd == -1) {
return FALSE;
}
/* get the toc header information */
if (ioctl(cd->fd,CDIOREADTOCHDR,&toc_header) != 0) {
close(cd->fd);
cd->fd = -1;
return FALSE;
}
/* read each entry in the toc header */
for (i = 1; i <= toc_header.ending_track; i++) {
toc_entry.address_format = CD_MSF_FORMAT;
toc_entry.starting_track = i;
if (ioctl(cd->fd,CDIOREADTOCENTRYS,&toc_entry) != 0) {
close(cd->fd);
cd->fd = -1;
return FALSE;
}
cd->tracks[i].minute = toc_entry.entry.addr.msf.minute;
cd->tracks[i].second = toc_entry.entry.addr.msf.second;
cd->tracks[i].frame = toc_entry.entry.addr.msf.frame;
cd->tracks[i].data_track = (toc_entry.data->control & 4) == 4;
}
/* read the leadout */
toc_entry.address_format = CD_MSF_FORMAT;
toc_entry.starting_track = 0xAA; /* leadout */
toc_entry.data = &toc_entry_data;
toc_entry.data_len = sizeof(toc_entry_data);
if (ioctl(cd->fd,CDIOREADTOCENTRYS,&toc_entry) != 0) {
close(cd->fd);
cd->fd = -1;
return FALSE;
}
cd->tracks[LEADOUT].minute = toc_entry.entry.addr.msf.minute;
cd->tracks[LEADOUT].second = toc_entry.entry.addr.msf.second;
cd->tracks[LEADOUT].frame = toc_entry.entry.addr.msf.frame;
cd->num_tracks = toc_header.ending_track;
return TRUE;
}
#endif
gboolean cd_start(struct cd *cd,gint start_track,gint end_track)
{
struct ioc_play_msf msf;
if (cd->fd == -1) {
return FALSE;
}
cd_fix_track_range(cd,&start_track,&end_track);
msf.start_m = cd->tracks[start_track].minute;
msf.start_s = cd->tracks[start_track].second;
msf.start_f = cd->tracks[start_track].frame;
if (end_track == LEADOUT) {
msf.end_m = cd->tracks[end_track].minute;
msf.end_s = cd->tracks[end_track].second;
msf.end_f = cd->tracks[end_track].frame;
} else {
msf.end_m = cd->tracks[end_track+1].minute;
msf.end_s = cd->tracks[end_track+1].second;
msf.end_f = cd->tracks[end_track+1].frame;
}
if (ioctl(cd->fd,CDIOCPLAYMSF,&msf) != 0) {
return FALSE;
}
}
gboolean cd_pause(struct cd *cd)
{
if (cd->fd == -1) {
return FALSE;
}
if (ioctl(cd->fd,CDIOCPAUSE,NULL) != 0) {
return FALSE;
}
return TRUE;
}
gboolean cd_resume(struct cd *cd)
{
if (cd->fd == -1) {
return FALSE;
}
if (ioctl(cd->fd,CDIOCRESUME,NULL) != 0) {
return FALSE;
}
return TRUE;
}
gboolean cd_stop(struct cd *cd)
{
if (cd->fd == -1) {
return FALSE;
}
if (ioctl(cd->fd,CDIOCSTOP,NULL) != 0) {
return FALSE;
}
return TRUE;
}
/* -1 for error, 0 for not playing, 1 for playing */
CDStatus cd_status(struct cd *cd)
{
struct ioc_read_subchannel sub_channel;
struct cd_sub_channel_info sub_channel_info;
if (cd->fd == -1) {
return -1;
}
sub_channel.address_format = CD_MSF_FORMAT;
sub_channel.data_format = CD_CURRENT_POSITION;
sub_channel.track = 0;
sub_channel.data = &sub_channel_info;
sub_channel.data_len = sizeof(sub_channel_info);
if (ioctl(cd->fd,CDIOCREADSUBCHANNEL,&sub_channel) != 0) {
return FALSE;
}
switch (sub_channel.data->header.audio_status) {
case CD_AS_PLAY_IN_PROGRESS:
case CD_AS_PLAY_PAUSED:
return CD_PLAYING;
break;
case CD_AS_PLAY_COMPLETED:
return CD_COMPLETED;
break;
case CD_AS_AUDIO_INVALID:
case CD_AS_PLAY_ERROR:
default:
return CD_ERROR;
break;
}
}
gint cd_current_track(struct cd *cd)
{
struct ioc_read_subchannel sub_channel;
struct cd_sub_channel_info sub_channel_info;
if (cd->fd == -1) {
return -1;
}
sub_channel.address_format = CD_MSF_FORMAT;
sub_channel.data_format = CD_TRACK_INFO;
sub_channel.track = 0;
sub_channel.data = &sub_channel_info;
sub_channel.data_len = sizeof(sub_channel_info);
if (ioctl(cd->fd,CDIOCREADSUBCHANNEL,&sub_channel) != 0) {
return -1;
}
#ifdef __NetBSD__
return sub_channel.data->what.track_info.track_number;
#else
return sub_channel.data->track_number;
#endif
}
gboolean cd_close(struct cd *cd)
{
if (cd->fd == -1) {
return TRUE;
}
if (close(cd->fd) != 0) {
return FALSE;
}
cd->fd = -1;
return TRUE;
}
|