| 1 |
/* $Id: cdrom.c,v 1.4 1999/03/10 07:58:02 boyns Exp $ */ |
| 2 |
|
| 3 |
/* |
| 4 |
* Copyright (C) 1993-99 Mark R. Boyns <[email protected]> |
| 5 |
* |
| 6 |
* This file is part of rplay. |
| 7 |
* |
| 8 |
* rplay is free software; you can redistribute it and/or modify |
| 9 |
* it under the terms of the GNU General Public License as published by |
| 10 |
* the Free Software Foundation; either version 2 of the License, or |
| 11 |
* (at your option) any later version. |
| 12 |
* |
| 13 |
* rplay is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
* GNU General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU General Public License |
| 19 |
* along with rplay; see the file COPYING. If not, write to the |
| 20 |
* Free Software Foundation, Inc., |
| 21 |
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. |
| 22 |
*/ |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
/* A lot of the CDDA code is based on read_cdda 1.01 by Jim Mintha |
| 27 |
([email protected]) which seems to have borrowed code from Workman |
| 28 |
sources written by Steven Grimm ([email protected]). */ |
| 29 |
|
| 30 |
#ifdef HAVE_CONFIG_H |
| 31 |
#include "config.h" |
| 32 |
#endif |
| 33 |
|
| 34 |
#ifdef HAVE_CDROM |
| 35 |
|
| 36 |
#include <sys/types.h> |
| 37 |
#include <sys/errno.h> |
| 38 |
#include "rplayd.h" |
| 39 |
#include "cdrom.h" |
| 40 |
|
| 41 |
CDROM_TABLE cdrom_table[MAX_CDROMS] = |
| 42 |
{ |
| 43 |
#if defined (sun) && defined (SVR4) /* Solaris 2.x */ |
| 44 |
{"cdrom:", "/vol/dev/aliases/cdrom0", 0, 0}, |
| 45 |
{"cdrom0:", "/vol/dev/aliases/cdrom0", 0, 0}, |
| 46 |
{"cdrom1:", "/vol/dev/aliases/cdrom1", 0, 0}, |
| 47 |
{"cdrom2:", "/vol/dev/aliases/cdrom2", 0, 0}, |
| 48 |
{"cdrom3:", "/vol/dev/aliases/cdrom3", 0, 0}, |
| 49 |
#else /* not solaris */ |
| 50 |
#if defined (linux) |
| 51 |
{"cdrom:", "/dev/cdrom", 0, 0}, |
| 52 |
{"cdrom0:", "/dev/cdrom0", 0, 0}, |
| 53 |
{"cdrom1:", "/dev/cdrom1", 0, 0}, |
| 54 |
{"cdrom2:", "/dev/cdrom2", 0, 0}, |
| 55 |
{"cdrom3:", "/dev/cdrom3", 0, 0}, |
| 56 |
#endif /* linux */ |
| 57 |
#endif |
| 58 |
}; |
| 59 |
|
| 60 |
typedef struct |
| 61 |
{ |
| 62 |
char *device; |
| 63 |
int starting_track; |
| 64 |
int ending_track; |
| 65 |
int num_blocks; |
| 66 |
int fd; |
| 67 |
char *buffer; |
| 68 |
int buffer_length; |
| 69 |
int starting_block; |
| 70 |
int current_block; |
| 71 |
int ending_block; |
| 72 |
} |
| 73 |
CDROM_INFO; |
| 74 |
|
| 75 |
/* Internal prototypes. */ |
| 76 |
#ifdef HAVE_CDDA |
| 77 |
#ifdef __STDC__ |
| 78 |
static void cdda_cdrom_reader(CDROM_TABLE * cdt, int starting_track, int ending_track, int output_fd); |
| 79 |
#else |
| 80 |
static void cdda_cdrom_reader( /* CDROM_TABLE *cdt, int starting_track, int ending_track, int output_fd */ ); |
| 81 |
#endif |
| 82 |
#endif /* HAVE_CDDA */ |
| 83 |
|
| 84 |
#ifdef linux |
| 85 |
#ifdef __STDC__ |
| 86 |
static void linux_cdrom_reader(CDROM_TABLE * cdt, int starting_track, int ending_track, int output_fd); |
| 87 |
#else |
| 88 |
static void linux_cdrom_reader( /* CDROM_TABLE *cdt, int starting_track, int ending_track, int output_fd */ ); |
| 89 |
#endif |
| 90 |
#endif /* linux */ |
| 91 |
|
| 92 |
/* starting_track and ending_track can be 0 which means first and last */ |
| 93 |
#ifdef __STDC__ |
| 94 |
void |
| 95 |
cdrom_reader(int index, int starting_track, int ending_track, int output_fd) |
| 96 |
#else |
| 97 |
void |
| 98 |
cdrom_reader(index, starting_track, ending_track, output_fd) |
| 99 |
int index; |
| 100 |
int starting_track; |
| 101 |
int ending_track; |
| 102 |
int output_fd; |
| 103 |
#endif |
| 104 |
{ |
| 105 |
CDROM_TABLE *cdt; |
| 106 |
|
| 107 |
cdt = &cdrom_table[index]; |
| 108 |
|
| 109 |
report(REPORT_DEBUG, "cdrom_reader: %s%s tracks %d..%d\n", |
| 110 |
cdt->name, cdt->device, starting_track, ending_track); |
| 111 |
|
| 112 |
rplay_audio_close(); /* prevent device busy problems */ |
| 113 |
|
| 114 |
#ifdef HAVE_CDDA |
| 115 |
cdda_cdrom_reader(cdt, starting_track, ending_track, output_fd); |
| 116 |
#else |
| 117 |
#ifdef linux |
| 118 |
linux_cdrom_reader(cdt, starting_track, ending_track, output_fd); |
| 119 |
#endif /* linux */ |
| 120 |
#endif /* HAVE_CDDA */ |
| 121 |
|
| 122 |
/* Add more cdrom readers here. */ |
| 123 |
|
| 124 |
exit(0); |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
/******************************************************************************/ |
| 129 |
|
| 130 |
#ifdef HAVE_CDDA |
| 131 |
|
| 132 |
/* A nicer interface to reading from the CDDA interface using the |
| 133 |
CDROM_INFO structure and the cdda_open, cdda_read, and cdda_close |
| 134 |
routines. */ |
| 135 |
|
| 136 |
#define CDDA_BLOCK_SIZE 2368 |
| 137 |
#define CDDA_BLOCK_IGNORE 16 |
| 138 |
|
| 139 |
static int cdda_open(CDROM_INFO * info); |
| 140 |
static int cdda_read(CDROM_INFO * info); |
| 141 |
static int cdda_close(CDROM_INFO * info); |
| 142 |
static int internal_cdda_init(CDROM_INFO * info); |
| 143 |
static int internal_cdda_read(CDROM_INFO * info); |
| 144 |
static int internal_cdda_toc(CDROM_INFO * info); |
| 145 |
|
| 146 |
#ifdef __STDC__ |
| 147 |
static void |
| 148 |
cdda_cdrom_reader(CDROM_TABLE * cdt, int starting_track, int ending_track, int output_fd) |
| 149 |
#else |
| 150 |
static void |
| 151 |
cdda_cdrom_reader(cdt, starting_track, ending_track, output_fd) |
| 152 |
CDROM_TABLE *cdt; |
| 153 |
int starting_track; |
| 154 |
int ending_track; |
| 155 |
int output_fd; |
| 156 |
#endif |
| 157 |
{ |
| 158 |
CDROM_INFO info; |
| 159 |
int n, i; |
| 160 |
char *p; |
| 161 |
|
| 162 |
info.device = cdt->device; |
| 163 |
info.starting_track = starting_track; |
| 164 |
info.ending_track = ending_track; |
| 165 |
info.num_blocks = 30; |
| 166 |
info.fd = -1; |
| 167 |
info.buffer = NULL; |
| 168 |
|
| 169 |
if (cdda_open(&info) < 0) |
| 170 |
{ |
| 171 |
return; |
| 172 |
} |
| 173 |
|
| 174 |
for (;;) |
| 175 |
{ |
| 176 |
n = cdda_read(&info); |
| 177 |
if (n <= 0) |
| 178 |
{ |
| 179 |
break; |
| 180 |
} |
| 181 |
|
| 182 |
p = info.buffer; |
| 183 |
for (i = 0; i < info.num_blocks; i++) |
| 184 |
{ |
| 185 |
write(output_fd, p, CDDA_BLOCK_SIZE - CDDA_BLOCK_IGNORE); |
| 186 |
p += CDDA_BLOCK_SIZE; |
| 187 |
} |
| 188 |
} |
| 189 |
|
| 190 |
cdda_close(&info); |
| 191 |
} |
| 192 |
|
| 193 |
#ifdef __STDC__ |
| 194 |
static int |
| 195 |
cdda_open(CDROM_INFO * info) |
| 196 |
#else |
| 197 |
static int |
| 198 |
cdda_open(info) |
| 199 |
CDROM_INFO *info; |
| 200 |
#endif |
| 201 |
{ |
| 202 |
if (info->fd < 0) |
| 203 |
{ |
| 204 |
if (internal_cdda_init(info) < 0) |
| 205 |
{ |
| 206 |
return -1; |
| 207 |
} |
| 208 |
} |
| 209 |
|
| 210 |
return internal_cdda_toc(info); |
| 211 |
} |
| 212 |
|
| 213 |
#ifdef __STDC__ |
| 214 |
static int |
| 215 |
cdda_read(CDROM_INFO * info) |
| 216 |
#else |
| 217 |
static int |
| 218 |
cdda_read(info) |
| 219 |
CDROM_INFO *info; |
| 220 |
#endif |
| 221 |
{ |
| 222 |
int n; |
| 223 |
|
| 224 |
n = internal_cdda_read(info); |
| 225 |
if (n < 0) |
| 226 |
{ |
| 227 |
return -1; |
| 228 |
} |
| 229 |
|
| 230 |
return n; |
| 231 |
} |
| 232 |
|
| 233 |
#ifdef __STDC__ |
| 234 |
static int |
| 235 |
cdda_close(CDROM_INFO * info) |
| 236 |
#else |
| 237 |
static int |
| 238 |
cdda_close(info) |
| 239 |
CDROM_INFO *info; |
| 240 |
#endif |
| 241 |
{ |
| 242 |
close(info->fd); |
| 243 |
info->fd = -1; |
| 244 |
if (info->buffer) |
| 245 |
{ |
| 246 |
free((char *) info->buffer); |
| 247 |
} |
| 248 |
info->buffer = NULL; |
| 249 |
return 0; |
| 250 |
} |
| 251 |
|
| 252 |
/* End of nicer CDDA interface. */ |
| 253 |
|
| 254 |
#include <sys/cdio.h> |
| 255 |
#include <sys/ioctl.h> |
| 256 |
#include <sys/param.h> |
| 257 |
#include <sys/stat.h> |
| 258 |
#include <sys/scsi/impl/uscsi.h> |
| 259 |
#include <sys/time.h> |
| 260 |
#include <ustat.h> |
| 261 |
|
| 262 |
#define CDDABLKSIZE 2368 |
| 263 |
#define SAMPLES_PER_BLK 588 |
| 264 |
|
| 265 |
#ifdef __STDC__ |
| 266 |
static int |
| 267 |
internal_cdda_init(CDROM_INFO * info) |
| 268 |
#else |
| 269 |
static int |
| 270 |
internal_cdda_init(info) |
| 271 |
CDROM_INFO *info; |
| 272 |
#endif |
| 273 |
{ |
| 274 |
struct cdrom_cdda cdda; |
| 275 |
|
| 276 |
info->fd = open(info->device, 0); |
| 277 |
if (info->fd < 0) |
| 278 |
{ |
| 279 |
perror(info->device); |
| 280 |
return -1; |
| 281 |
} |
| 282 |
|
| 283 |
info->buffer = (char *) malloc(info->num_blocks * CDDABLKSIZE + CDDABLKSIZE); |
| 284 |
if (info->buffer == NULL) |
| 285 |
{ |
| 286 |
fprintf(stderr, "malloc: out of memory\n"); |
| 287 |
return -1; |
| 288 |
} |
| 289 |
|
| 290 |
info->buffer_length = info->num_blocks * CDDABLKSIZE; |
| 291 |
|
| 292 |
cdda.cdda_addr = 200; |
| 293 |
cdda.cdda_length = 1; |
| 294 |
cdda.cdda_data = info->buffer; |
| 295 |
cdda.cdda_subcode = CDROM_DA_SUBQ; |
| 296 |
|
| 297 |
if (ioctl(info->fd, CDROMCDDA, &cdda) < 0) |
| 298 |
{ |
| 299 |
perror("ioctl: CDROMCDDA"); |
| 300 |
free((char *) info->buffer); |
| 301 |
info->buffer = NULL; |
| 302 |
close(info->fd); |
| 303 |
return -1; |
| 304 |
} |
| 305 |
|
| 306 |
return 0; |
| 307 |
} |
| 308 |
|
| 309 |
#ifdef __STDC__ |
| 310 |
static int |
| 311 |
internal_cdda_read(CDROM_INFO * info) |
| 312 |
#else |
| 313 |
static int |
| 314 |
internal_cdda_read(info) |
| 315 |
CDROM_INFO *info; |
| 316 |
#endif |
| 317 |
{ |
| 318 |
struct cdrom_cdda cdda; |
| 319 |
int blk; |
| 320 |
unsigned char *q; |
| 321 |
|
| 322 |
if (info->current_block >= info->ending_block) |
| 323 |
{ |
| 324 |
return 0; |
| 325 |
} |
| 326 |
|
| 327 |
cdda.cdda_addr = info->current_block; |
| 328 |
if (info->current_block + info->num_blocks > info->ending_block) |
| 329 |
{ |
| 330 |
cdda.cdda_length = info->ending_block - info->current_block; |
| 331 |
} |
| 332 |
else |
| 333 |
{ |
| 334 |
cdda.cdda_length = info->num_blocks; |
| 335 |
} |
| 336 |
|
| 337 |
cdda.cdda_data = info->buffer; |
| 338 |
cdda.cdda_subcode = CDROM_DA_SUBQ; |
| 339 |
|
| 340 |
if (ioctl(info->fd, CDROMCDDA, &cdda) < 0) |
| 341 |
{ |
| 342 |
if (errno == ENXIO) |
| 343 |
{ |
| 344 |
perror("ioctl: CDROMCDDA: CD ejected"); |
| 345 |
return -1; |
| 346 |
} |
| 347 |
|
| 348 |
if (info->current_block + info->num_blocks > info->ending_block) |
| 349 |
{ |
| 350 |
return 0; |
| 351 |
} |
| 352 |
|
| 353 |
if (ioctl(info->fd, CDROMCDDA, &cdda) < 0) |
| 354 |
{ |
| 355 |
if (ioctl(info->fd, CDROMCDDA, &cdda) < 0) |
| 356 |
{ |
| 357 |
if (ioctl(info->fd, CDROMCDDA, &cdda) < 0) |
| 358 |
{ |
| 359 |
perror("ioctl: CDROMCDDA"); |
| 360 |
return -1; |
| 361 |
} |
| 362 |
} |
| 363 |
} |
| 364 |
} |
| 365 |
|
| 366 |
info->current_block += cdda.cdda_length; |
| 367 |
|
| 368 |
return cdda.cdda_length * CDDABLKSIZE; |
| 369 |
} |
| 370 |
|
| 371 |
#ifdef __STDC__ |
| 372 |
static int |
| 373 |
internal_cdda_toc(CDROM_INFO * info) |
| 374 |
#else |
| 375 |
static int |
| 376 |
internal_cdda_toc(info) |
| 377 |
CDROM_INFO *info; |
| 378 |
#endif |
| 379 |
{ |
| 380 |
struct cdrom_tochdr hdr; |
| 381 |
struct cdrom_tocentry entry; |
| 382 |
int i; |
| 383 |
|
| 384 |
if (ioctl(info->fd, CDROMREADTOCHDR, &hdr) < 0) |
| 385 |
{ |
| 386 |
perror("ioctl: CDROMREADTOCHDR"); |
| 387 |
return -1; |
| 388 |
} |
| 389 |
|
| 390 |
info->starting_block = 0; |
| 391 |
info->ending_block = 0; |
| 392 |
|
| 393 |
if (info->starting_track == 0) |
| 394 |
{ |
| 395 |
info->starting_track = hdr.cdth_trk0; |
| 396 |
} |
| 397 |
if (info->ending_track == 0) |
| 398 |
{ |
| 399 |
info->ending_track = hdr.cdth_trk1; |
| 400 |
} |
| 401 |
|
| 402 |
for (i = 1; i <= hdr.cdth_trk1; i++) |
| 403 |
{ |
| 404 |
entry.cdte_track = i; |
| 405 |
entry.cdte_format = CDROM_MSF; |
| 406 |
|
| 407 |
if (ioctl(info->fd, CDROMREADTOCENTRY, &entry) < 0) |
| 408 |
{ |
| 409 |
perror("ioctl: CDROMREADTOCENTRY"); |
| 410 |
return -1; |
| 411 |
} |
| 412 |
|
| 413 |
if (i == info->starting_track) |
| 414 |
{ |
| 415 |
info->starting_block = entry.cdte_addr.msf.minute * 60 * 75 + |
| 416 |
entry.cdte_addr.msf.second * 75 + entry.cdte_addr.msf.frame; |
| 417 |
} |
| 418 |
|
| 419 |
if (i == info->ending_track + 1) |
| 420 |
{ |
| 421 |
info->ending_block = entry.cdte_addr.msf.minute * 60 * 75 + |
| 422 |
entry.cdte_addr.msf.second * 75 + entry.cdte_addr.msf.frame; |
| 423 |
} |
| 424 |
} |
| 425 |
|
| 426 |
entry.cdte_track = CDROM_LEADOUT; |
| 427 |
entry.cdte_format = CDROM_MSF; |
| 428 |
|
| 429 |
if (ioctl(info->fd, CDROMREADTOCENTRY, &entry) < 0) |
| 430 |
{ |
| 431 |
perror("ioctl: CDROMREADTOCENTRY"); |
| 432 |
return -1; |
| 433 |
} |
| 434 |
|
| 435 |
if (info->ending_block == 0) |
| 436 |
{ |
| 437 |
info->ending_block = entry.cdte_addr.msf.minute * 60 * 75 + |
| 438 |
entry.cdte_addr.msf.second * 75 + entry.cdte_addr.msf.frame; |
| 439 |
} |
| 440 |
|
| 441 |
/* Move back two seconds - don't know why but works */ |
| 442 |
info->starting_block -= 150; |
| 443 |
info->ending_block -= 150; |
| 444 |
|
| 445 |
info->current_block = info->starting_block; |
| 446 |
|
| 447 |
return 0; |
| 448 |
} |
| 449 |
|
| 450 |
#else |
| 451 |
|
| 452 |
/******************************************************************************/ |
| 453 |
|
| 454 |
#if defined (linux) |
| 455 |
|
| 456 |
#include <linux/cdrom.h> |
| 457 |
|
| 458 |
#ifdef __STDC__ |
| 459 |
static int |
| 460 |
linux_read_toc(CDROM_INFO * info) |
| 461 |
#else |
| 462 |
static int |
| 463 |
linux_read_toc(info) |
| 464 |
CDROM_INFO *info; |
| 465 |
#endif |
| 466 |
{ |
| 467 |
struct cdrom_tochdr hdr; |
| 468 |
struct cdrom_tocentry entry; |
| 469 |
int i; |
| 470 |
|
| 471 |
if (ioctl(info->fd, CDROMREADTOCHDR, &hdr) < 0) |
| 472 |
{ |
| 473 |
perror("ioctl: CDROMREADTOCHDR"); |
| 474 |
return -1; |
| 475 |
} |
| 476 |
|
| 477 |
info->starting_block = 0; |
| 478 |
info->ending_block = 0; |
| 479 |
|
| 480 |
if (info->starting_track == 0) |
| 481 |
{ |
| 482 |
info->starting_track = hdr.cdth_trk0; |
| 483 |
} |
| 484 |
if (info->ending_track == 0) |
| 485 |
{ |
| 486 |
info->ending_track = hdr.cdth_trk1; |
| 487 |
} |
| 488 |
|
| 489 |
for (i = 1; i <= hdr.cdth_trk1; i++) |
| 490 |
{ |
| 491 |
entry.cdte_track = i; |
| 492 |
entry.cdte_format = CDROM_MSF; |
| 493 |
|
| 494 |
if (ioctl(info->fd, CDROMREADTOCENTRY, &entry) < 0) |
| 495 |
{ |
| 496 |
perror("ioctl: CDROMREADTOCENTRY"); |
| 497 |
return -1; |
| 498 |
} |
| 499 |
|
| 500 |
if (i == info->starting_track) |
| 501 |
{ |
| 502 |
info->starting_block = entry.cdte_addr.msf.minute * 60 * 75 + |
| 503 |
entry.cdte_addr.msf.second * 75 + entry.cdte_addr.msf.frame; |
| 504 |
} |
| 505 |
|
| 506 |
if (i == info->ending_track + 1) |
| 507 |
{ |
| 508 |
info->ending_block = entry.cdte_addr.msf.minute * 60 * 75 + |
| 509 |
entry.cdte_addr.msf.second * 75 + entry.cdte_addr.msf.frame; |
| 510 |
} |
| 511 |
} |
| 512 |
|
| 513 |
entry.cdte_track = CDROM_LEADOUT; |
| 514 |
entry.cdte_format = CDROM_MSF; |
| 515 |
|
| 516 |
if (ioctl(info->fd, CDROMREADTOCENTRY, &entry) < 0) |
| 517 |
{ |
| 518 |
perror("ioctl: CDROMREADTOCENTRY"); |
| 519 |
return -1; |
| 520 |
} |
| 521 |
|
| 522 |
if (info->ending_block == 0) |
| 523 |
{ |
| 524 |
info->ending_block = entry.cdte_addr.msf.minute * 60 * 75 + |
| 525 |
entry.cdte_addr.msf.second * 75 + entry.cdte_addr.msf.frame; |
| 526 |
} |
| 527 |
|
| 528 |
/* Move back two seconds - don't know why but works */ |
| 529 |
info->starting_block -= 150; |
| 530 |
info->ending_block -= 150; |
| 531 |
|
| 532 |
info->current_block = info->starting_block; |
| 533 |
|
| 534 |
return 0; |
| 535 |
} |
| 536 |
|
| 537 |
#ifdef __STDC__ |
| 538 |
static void |
| 539 |
linux_cdrom_reader(CDROM_TABLE * cdt, int starting_track, int ending_track, int output_fd) |
| 540 |
#else |
| 541 |
static void |
| 542 |
linux_cdrom_reader(cdt, starting_track, ending_track, output_fd) |
| 543 |
CDROM_TABLE *cdt; |
| 544 |
int starting_track; |
| 545 |
int ending_track; |
| 546 |
int output_fd; |
| 547 |
#endif |
| 548 |
{ |
| 549 |
CDROM_INFO info; |
| 550 |
int n, i; |
| 551 |
char *p; |
| 552 |
|
| 553 |
info.device = cdt->device; |
| 554 |
info.starting_track = starting_track; |
| 555 |
info.ending_track = ending_track; |
| 556 |
info.num_blocks = 30; |
| 557 |
info.fd = -1; |
| 558 |
info.buffer = NULL; |
| 559 |
|
| 560 |
info.fd = open(info.device, 0); |
| 561 |
if (info.fd < 0) |
| 562 |
{ |
| 563 |
perror(info.device); |
| 564 |
return; |
| 565 |
} |
| 566 |
|
| 567 |
info.buffer = (char *) malloc(info.num_blocks * CD_FRAMESIZE_RAW + CD_FRAMESIZE_RAW); |
| 568 |
if (info.buffer == NULL) |
| 569 |
{ |
| 570 |
fprintf(stderr, "malloc: out of memory\n"); |
| 571 |
return; |
| 572 |
} |
| 573 |
|
| 574 |
linux_read_toc(&info); |
| 575 |
|
| 576 |
/* printf ("start track=%d block=%d\n", info.starting_track, info.starting_block); */ |
| 577 |
/* printf ("end track=%d block=%d\n", info.ending_track, info.ending_block); */ |
| 578 |
|
| 579 |
while (info.current_block < info.ending_block) |
| 580 |
{ |
| 581 |
int frames; |
| 582 |
int max_retries = 5; |
| 583 |
|
| 584 |
if (info.current_block + info.num_blocks > info.ending_block) |
| 585 |
{ |
| 586 |
frames = info.ending_block - info.current_block; |
| 587 |
} |
| 588 |
else |
| 589 |
{ |
| 590 |
frames = info.num_blocks; |
| 591 |
} |
| 592 |
|
| 593 |
for (i = 0; i < max_retries; i++) |
| 594 |
{ |
| 595 |
struct cdrom_read_audio audio; |
| 596 |
|
| 597 |
audio.addr_format = CDROM_LBA; |
| 598 |
audio.addr.lba = info.current_block; |
| 599 |
audio.nframes = frames; |
| 600 |
audio.buf = info.buffer; |
| 601 |
|
| 602 |
if (ioctl(info.fd, CDROMREADAUDIO, &audio) >= 0) |
| 603 |
{ |
| 604 |
break; |
| 605 |
} |
| 606 |
} |
| 607 |
if (i == max_retries) |
| 608 |
{ |
| 609 |
perror(info.device); |
| 610 |
break; |
| 611 |
} |
| 612 |
|
| 613 |
if (write(output_fd, info.buffer, CD_FRAMESIZE_RAW * frames) < 0) |
| 614 |
{ |
| 615 |
break; |
| 616 |
} |
| 617 |
|
| 618 |
info.current_block += frames; |
| 619 |
} |
| 620 |
|
| 621 |
free(info.buffer); |
| 622 |
close(info.fd); |
| 623 |
} |
| 624 |
|
| 625 |
#endif /* linux */ |
| 626 |
#endif /* HAVE_CDDA */ |
| 627 |
#endif /* HAVE_CDROM */ |