2004-09-10 09:34:54 +04:00
|
|
|
/* $NetBSD: cdplay.c,v 1.28 2004/09/10 05:36:00 itojun Exp $ */
|
1999-06-05 17:21:59 +04:00
|
|
|
|
|
|
|
/*
|
2001-08-20 13:50:10 +04:00
|
|
|
* Copyright (c) 1999, 2000, 2001 Andrew Doran.
|
1999-06-05 17:21:59 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2001-08-20 13:50:10 +04:00
|
|
|
* Compact Disc Control Utility, originally by Serge V. Vakulenko
|
|
|
|
* <vak@cronyx.ru>. First appeared in FreeBSD under the guise of
|
|
|
|
* cdcontrol(1). Based on the non-X based CD player by Jean-Marc
|
|
|
|
* Zucconi and Andrey A. Chernov. Fixed and further modified on
|
|
|
|
* by Jukka Ukkonen <jau@funet.fi>. Lots of fixes and improvements
|
|
|
|
* made subsequently by The NetBSD Project.
|
1999-06-05 17:21:59 +04:00
|
|
|
*
|
2000-06-13 17:36:42 +04:00
|
|
|
* from FreeBSD: cdcontrol.c,v 1.17.2.1 1999/01/31 15:36:01 billf Exp
|
1999-06-05 17:21:59 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#ifndef lint
|
2004-09-10 09:34:54 +04:00
|
|
|
__RCSID("$NetBSD: cdplay.c,v 1.28 2004/09/10 05:36:00 itojun Exp $");
|
1999-06-05 17:21:59 +04:00
|
|
|
#endif /* not lint */
|
|
|
|
|
2002-01-23 04:09:15 +03:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
2000-01-05 21:15:20 +03:00
|
|
|
#include <sys/endian.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/cdio.h>
|
|
|
|
|
2003-01-31 00:23:57 +03:00
|
|
|
#include <assert.h>
|
|
|
|
|
1999-06-05 17:21:59 +04:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
1999-11-26 21:34:58 +03:00
|
|
|
#include <histedit.h>
|
2002-09-29 01:48:35 +04:00
|
|
|
#include <limits.h>
|
2001-08-20 15:24:57 +04:00
|
|
|
#include <signal.h>
|
1999-06-05 17:21:59 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2000-12-16 04:36:00 +03:00
|
|
|
#include <util.h>
|
1999-06-05 17:21:59 +04:00
|
|
|
|
2001-08-20 13:50:10 +04:00
|
|
|
enum cmd {
|
2001-08-20 15:24:57 +04:00
|
|
|
CMD_CLOSE,
|
2001-08-20 13:50:10 +04:00
|
|
|
CMD_EJECT,
|
|
|
|
CMD_HELP,
|
|
|
|
CMD_INFO,
|
2001-08-20 15:24:57 +04:00
|
|
|
CMD_NEXT,
|
2001-08-20 13:50:10 +04:00
|
|
|
CMD_PAUSE,
|
|
|
|
CMD_PLAY,
|
2001-08-20 15:24:57 +04:00
|
|
|
CMD_PREV,
|
2001-08-20 13:50:10 +04:00
|
|
|
CMD_QUIT,
|
|
|
|
CMD_RESET,
|
2001-08-20 15:24:57 +04:00
|
|
|
CMD_RESUME,
|
2001-08-20 13:50:10 +04:00
|
|
|
CMD_SET,
|
2001-08-20 15:24:57 +04:00
|
|
|
CMD_SHUFFLE,
|
|
|
|
CMD_SKIP,
|
2001-08-20 13:50:10 +04:00
|
|
|
CMD_STATUS,
|
2001-08-20 15:24:57 +04:00
|
|
|
CMD_STOP,
|
|
|
|
CMD_VOLUME,
|
2001-08-20 13:50:10 +04:00
|
|
|
};
|
1999-06-05 17:21:59 +04:00
|
|
|
|
|
|
|
struct cmdtab {
|
2001-08-20 13:50:10 +04:00
|
|
|
enum cmd command;
|
|
|
|
const char *name;
|
|
|
|
unsigned int min;
|
|
|
|
const char *args;
|
|
|
|
} const cmdtab[] = {
|
2001-08-20 15:24:57 +04:00
|
|
|
{ CMD_HELP, "?", 1, 0 },
|
|
|
|
{ CMD_CLOSE, "close", 1, NULL },
|
|
|
|
{ CMD_EJECT, "eject", 1, NULL },
|
|
|
|
{ CMD_HELP, "help", 1, NULL },
|
|
|
|
{ CMD_INFO, "info", 1, NULL },
|
|
|
|
{ CMD_NEXT, "next", 1, NULL },
|
|
|
|
{ CMD_PAUSE, "pause", 2, NULL },
|
|
|
|
{ CMD_PLAY, "play", 1, "min1:sec1[.fram1] [min2:sec2[.fram2]]" },
|
|
|
|
{ CMD_PLAY, "play", 1, "track1[.index1] [track2[.index2]]" },
|
|
|
|
{ CMD_PLAY, "play", 1, "tr1 m1:s1[.f1] [[tr2] [m2:s2[.f2]]]" },
|
|
|
|
{ CMD_PLAY, "play", 1, "[#block [len]]" },
|
|
|
|
{ CMD_PREV, "prev", 2, NULL },
|
|
|
|
{ CMD_QUIT, "quit", 1, NULL },
|
|
|
|
{ CMD_RESET, "reset", 4, NULL },
|
|
|
|
{ CMD_RESUME, "resume", 4, NULL },
|
|
|
|
{ CMD_SET, "set", 2, "msf | lba" },
|
|
|
|
{ CMD_SHUFFLE, "shuffle", 2, NULL },
|
|
|
|
{ CMD_SKIP, "skip", 2, NULL },
|
|
|
|
{ CMD_STATUS, "status", 3, NULL },
|
|
|
|
{ CMD_STOP, "stop", 3, NULL },
|
|
|
|
{ CMD_VOLUME, "volume", 1, "<l> <r>|left|right|mute|mono|stereo" },
|
1999-06-05 17:21:59 +04:00
|
|
|
};
|
|
|
|
|
2003-02-19 15:55:58 +03:00
|
|
|
#define CD_MAX_TRACK 99 /* largest 2 digit BCD number */
|
|
|
|
|
|
|
|
struct cd_toc_entry toc_buffer[CD_MAX_TRACK + 1];
|
1999-06-05 17:21:59 +04:00
|
|
|
|
|
|
|
const char *cdname;
|
|
|
|
int fd = -1;
|
|
|
|
int msf = 1;
|
2001-08-20 15:24:57 +04:00
|
|
|
int shuffle;
|
|
|
|
int interactive = 1;
|
|
|
|
struct itimerval itv_timer;
|
1999-06-05 17:21:59 +04:00
|
|
|
|
1999-11-26 21:34:58 +03:00
|
|
|
History *hist;
|
|
|
|
HistEvent he;
|
|
|
|
EditLine *elptr;
|
|
|
|
|
2001-08-20 13:50:10 +04:00
|
|
|
int get_vol(int *, int *);
|
2001-08-20 15:24:57 +04:00
|
|
|
int get_status(int *, int *, int *, int *, int *);
|
2001-08-20 13:50:10 +04:00
|
|
|
void help(void);
|
|
|
|
int info(const char *);
|
|
|
|
void lba2msf(u_long, u_int *, u_int *, u_int *);
|
|
|
|
int main(int, char **);
|
|
|
|
u_int msf2lba(u_int, u_int, u_int);
|
|
|
|
int opencd(void);
|
|
|
|
const char *parse(char *, int *);
|
2001-08-20 15:24:57 +04:00
|
|
|
int play(const char *, int);
|
2001-08-20 13:50:10 +04:00
|
|
|
int play_blocks(int, int);
|
|
|
|
int play_msf(int, int, int, int, int, int);
|
|
|
|
int play_track(int, int, int, int);
|
|
|
|
int print_status(const char *);
|
2003-02-19 15:55:58 +03:00
|
|
|
void print_track(struct cd_toc_entry *);
|
2001-08-20 13:50:10 +04:00
|
|
|
const char *prompt(void);
|
|
|
|
int read_toc_entrys(int);
|
|
|
|
int run(int, const char *);
|
|
|
|
int setvol(int, int);
|
2003-09-12 04:39:38 +04:00
|
|
|
void sig_timer(int);
|
2001-08-20 15:24:57 +04:00
|
|
|
int skip(int, int);
|
2001-08-20 13:50:10 +04:00
|
|
|
const char *strstatus(int);
|
|
|
|
void usage(void);
|
1999-09-19 01:15:23 +04:00
|
|
|
|
2003-01-31 00:23:57 +03:00
|
|
|
void toc2msf(u_int, u_int *, u_int *, u_int *);
|
|
|
|
int toc2lba(u_int);
|
|
|
|
void addmsf(u_int *, u_int *, u_int *, u_int, u_int, u_int);
|
|
|
|
|
2001-08-20 13:50:10 +04:00
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
1999-06-05 17:21:59 +04:00
|
|
|
{
|
2001-08-20 13:50:10 +04:00
|
|
|
const char *arg;
|
|
|
|
char buf[80], *p;
|
2000-01-05 21:15:20 +03:00
|
|
|
static char defdev[16];
|
2001-08-20 13:50:10 +04:00
|
|
|
int cmd, len, c;
|
1999-11-26 21:34:58 +03:00
|
|
|
char *line;
|
|
|
|
const char *elline;
|
2001-08-20 15:24:57 +04:00
|
|
|
int scratch, rv;
|
|
|
|
struct sigaction sa_timer;
|
1999-06-05 17:21:59 +04:00
|
|
|
|
|
|
|
cdname = getenv("MUSIC_CD");
|
2001-08-20 13:50:10 +04:00
|
|
|
if (cdname == NULL)
|
1999-06-05 17:21:59 +04:00
|
|
|
cdname = getenv("CD_DRIVE");
|
2001-08-20 13:50:10 +04:00
|
|
|
if (cdname == NULL)
|
1999-06-05 17:21:59 +04:00
|
|
|
cdname = getenv("DISC");
|
2001-08-20 13:50:10 +04:00
|
|
|
if (cdname == NULL)
|
1999-06-05 17:21:59 +04:00
|
|
|
cdname = getenv("CDPLAY");
|
|
|
|
|
2001-08-20 13:50:10 +04:00
|
|
|
while ((c = getopt(argc, argv, "f:h")) != -1)
|
|
|
|
switch (c) {
|
1999-06-05 17:21:59 +04:00
|
|
|
case 'f':
|
|
|
|
cdname = optarg;
|
|
|
|
continue;
|
|
|
|
case 'h':
|
|
|
|
default:
|
|
|
|
usage();
|
2001-08-20 13:50:10 +04:00
|
|
|
/* NOTREACHED */
|
1999-06-05 17:21:59 +04:00
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
2001-08-20 17:44:08 +04:00
|
|
|
if (argc > 0 && strcasecmp(*argv, "help") == 0)
|
1999-06-05 17:21:59 +04:00
|
|
|
usage();
|
|
|
|
|
2001-08-20 13:50:10 +04:00
|
|
|
if (cdname == NULL) {
|
2003-07-14 13:18:22 +04:00
|
|
|
snprintf(defdev, sizeof(defdev), "cd0%c",
|
|
|
|
'a' + getrawpartition());
|
1999-06-05 17:21:59 +04:00
|
|
|
cdname = defdev;
|
|
|
|
}
|
2001-08-20 13:50:10 +04:00
|
|
|
|
1999-09-19 01:15:23 +04:00
|
|
|
opencd();
|
2001-08-20 15:24:57 +04:00
|
|
|
|
1999-06-05 17:21:59 +04:00
|
|
|
if (argc > 0) {
|
2001-08-20 15:24:57 +04:00
|
|
|
interactive = 0;
|
2001-08-20 13:50:10 +04:00
|
|
|
for (p = buf; argc-- > 0; argv++) {
|
1999-06-05 17:21:59 +04:00
|
|
|
len = strlen(*argv);
|
|
|
|
|
|
|
|
if (p + len >= buf + sizeof(buf) - 1)
|
|
|
|
usage();
|
|
|
|
if (p > buf)
|
|
|
|
*p++ = ' ';
|
|
|
|
|
2003-07-14 15:54:06 +04:00
|
|
|
strlcpy(p, *argv, sizeof(buf) - (p - buf));
|
1999-06-05 17:21:59 +04:00
|
|
|
p += len;
|
|
|
|
}
|
2001-08-20 13:50:10 +04:00
|
|
|
*p = '\0';
|
1999-06-05 17:21:59 +04:00
|
|
|
arg = parse(buf, &cmd);
|
|
|
|
return (run(cmd, arg));
|
|
|
|
}
|
2001-08-20 13:50:10 +04:00
|
|
|
|
1999-06-05 17:21:59 +04:00
|
|
|
printf("Type `?' for command list\n\n");
|
|
|
|
|
1999-11-26 21:34:58 +03:00
|
|
|
hist = history_init();
|
|
|
|
history(hist, &he, H_SETSIZE, 100); /* 100 elt history buffer */
|
2001-02-20 02:03:42 +03:00
|
|
|
elptr = el_init(getprogname(), stdin, stdout, stderr);
|
1999-11-26 21:34:58 +03:00
|
|
|
el_set(elptr, EL_EDITOR, "emacs");
|
|
|
|
el_set(elptr, EL_PROMPT, prompt);
|
|
|
|
el_set(elptr, EL_HIST, history, hist);
|
|
|
|
el_source(elptr, NULL);
|
|
|
|
|
2001-08-20 15:24:57 +04:00
|
|
|
sigemptyset(&sa_timer.sa_mask);
|
2003-09-12 04:39:38 +04:00
|
|
|
sa_timer.sa_handler = sig_timer;
|
2001-08-20 15:24:57 +04:00
|
|
|
sa_timer.sa_flags = SA_RESTART;
|
|
|
|
if ((rv = sigaction(SIGALRM, &sa_timer, NULL)) < 0)
|
|
|
|
err(EXIT_FAILURE, "sigaction()");
|
|
|
|
|
1999-06-05 17:21:59 +04:00
|
|
|
for (;;) {
|
1999-11-26 21:34:58 +03:00
|
|
|
line = NULL;
|
|
|
|
do {
|
|
|
|
if (((elline = el_gets(elptr, &scratch)) != NULL)
|
|
|
|
&& (scratch != 0)){
|
|
|
|
history(hist, &he, H_ENTER, elline);
|
|
|
|
line = strdup(elline);
|
|
|
|
arg = parse(line, &cmd);
|
|
|
|
} else {
|
|
|
|
cmd = CMD_QUIT;
|
|
|
|
fprintf(stderr, "\r\n");
|
|
|
|
arg = 0;
|
|
|
|
break;
|
|
|
|
}
|
2001-08-20 13:50:10 +04:00
|
|
|
} while (arg == NULL);
|
1999-11-26 21:34:58 +03:00
|
|
|
|
1999-06-05 17:21:59 +04:00
|
|
|
if (run(cmd, arg) < 0) {
|
2001-08-20 13:50:10 +04:00
|
|
|
if (fd != -1)
|
|
|
|
close(fd);
|
1999-06-05 17:21:59 +04:00
|
|
|
fd = -1;
|
|
|
|
}
|
|
|
|
fflush(stdout);
|
1999-11-26 21:34:58 +03:00
|
|
|
if (line != NULL)
|
|
|
|
free(line);
|
1999-06-05 17:21:59 +04:00
|
|
|
}
|
2001-08-20 13:50:10 +04:00
|
|
|
|
1999-11-26 21:34:58 +03:00
|
|
|
el_end(elptr);
|
|
|
|
history_end(hist);
|
2001-08-20 13:50:10 +04:00
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
/* NOTREACHED */
|
1999-06-05 17:21:59 +04:00
|
|
|
}
|
|
|
|
|
2001-08-20 13:50:10 +04:00
|
|
|
void
|
|
|
|
usage(void)
|
1999-06-05 17:21:59 +04:00
|
|
|
{
|
|
|
|
|
2001-08-20 13:50:10 +04:00
|
|
|
fprintf(stderr, "usage: cdplay [-f device] [command ...]\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
help(void)
|
|
|
|
{
|
|
|
|
const struct cmdtab *c, *mc;
|
|
|
|
const char *s;
|
|
|
|
int i, n;
|
|
|
|
|
|
|
|
mc = cmdtab + sizeof(cmdtab) / sizeof(cmdtab[0]);
|
|
|
|
for (c = cmdtab; c < mc; c++) {
|
|
|
|
for (i = c->min, s = c->name; *s != '\0'; s++, i--) {
|
|
|
|
n = (i > 0 ? toupper(*s) : *s);
|
|
|
|
putchar(n);
|
2000-01-05 21:15:20 +03:00
|
|
|
}
|
2001-08-20 13:50:10 +04:00
|
|
|
if (c->args != NULL)
|
|
|
|
printf(" %s", c->args);
|
|
|
|
putchar('\n');
|
2000-01-05 21:15:20 +03:00
|
|
|
}
|
2001-08-20 13:50:10 +04:00
|
|
|
printf(
|
|
|
|
"\nThe word \"play\" is not required for the play commands.\n"
|
|
|
|
"The plain target address is taken as a synonym for play.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
run(int cmd, const char *arg)
|
|
|
|
{
|
|
|
|
int l, r, rv;
|
|
|
|
|
|
|
|
if (cmd == CMD_QUIT) {
|
2001-08-20 15:24:57 +04:00
|
|
|
close(fd);
|
2001-08-20 13:50:10 +04:00
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
|
2000-01-05 21:15:20 +03:00
|
|
|
if (fd < 0 && !opencd())
|
|
|
|
return (0);
|
2001-08-20 13:50:10 +04:00
|
|
|
|
2000-01-05 21:15:20 +03:00
|
|
|
switch (cmd) {
|
|
|
|
case CMD_INFO:
|
2001-08-20 13:50:10 +04:00
|
|
|
rv = info(arg);
|
|
|
|
break;
|
1999-06-05 17:21:59 +04:00
|
|
|
|
|
|
|
case CMD_STATUS:
|
2001-08-20 13:50:10 +04:00
|
|
|
rv = print_status(arg);
|
|
|
|
break;
|
1999-06-05 17:21:59 +04:00
|
|
|
|
|
|
|
case CMD_PAUSE:
|
2001-08-20 13:50:10 +04:00
|
|
|
if ((rv = ioctl(fd, CDIOCPAUSE)) < 0)
|
|
|
|
warn("ioctl(CDIOCPAUSE)");
|
|
|
|
break;
|
1999-06-05 17:21:59 +04:00
|
|
|
|
|
|
|
case CMD_RESUME:
|
2001-08-20 13:50:10 +04:00
|
|
|
if ((rv = ioctl(fd, CDIOCRESUME)) < 0)
|
|
|
|
warn("ioctl(CDIOCRESUME)");
|
|
|
|
break;
|
1999-06-05 17:21:59 +04:00
|
|
|
|
|
|
|
case CMD_STOP:
|
2001-08-20 13:50:10 +04:00
|
|
|
if ((rv = ioctl(fd, CDIOCSTOP)) < 0)
|
|
|
|
warn("ioctl(CDIOCSTOP)");
|
|
|
|
if (ioctl(fd, CDIOCALLOW) < 0)
|
|
|
|
warn("ioctl(CDIOCALLOW)");
|
|
|
|
break;
|
1999-06-05 17:21:59 +04:00
|
|
|
|
|
|
|
case CMD_RESET:
|
2001-08-20 13:50:10 +04:00
|
|
|
if ((rv = ioctl(fd, CDIOCRESET)) >= 0) {
|
|
|
|
close(fd);
|
|
|
|
fd = -1;
|
|
|
|
} else
|
|
|
|
warn("ioctl(CDIOCRESET)");
|
1999-06-05 17:21:59 +04:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
case CMD_EJECT:
|
2001-08-20 15:24:57 +04:00
|
|
|
if (shuffle)
|
|
|
|
run(CMD_SHUFFLE, NULL);
|
2001-08-20 13:50:10 +04:00
|
|
|
if (ioctl(fd, CDIOCALLOW) < 0)
|
|
|
|
warn("ioctl(CDIOCALLOW)");
|
|
|
|
if ((rv = ioctl(fd, CDIOCEJECT)) < 0)
|
|
|
|
warn("ioctl(CDIOCEJECT)");
|
|
|
|
break;
|
1999-06-05 17:21:59 +04:00
|
|
|
|
|
|
|
case CMD_CLOSE:
|
1999-09-19 01:15:23 +04:00
|
|
|
ioctl(fd, CDIOCALLOW);
|
2001-08-20 13:50:10 +04:00
|
|
|
if ((rv = ioctl(fd, CDIOCCLOSE)) >= 0) {
|
|
|
|
close(fd);
|
|
|
|
fd = -1;
|
|
|
|
} else
|
|
|
|
warn("ioctl(CDIOCCLOSE)");
|
|
|
|
break;
|
1999-06-05 17:21:59 +04:00
|
|
|
|
|
|
|
case CMD_PLAY:
|
|
|
|
while (isspace(*arg))
|
|
|
|
arg++;
|
2001-08-20 15:24:57 +04:00
|
|
|
rv = play(arg, 1);
|
2001-08-20 13:50:10 +04:00
|
|
|
break;
|
1999-06-05 17:21:59 +04:00
|
|
|
|
2001-07-01 09:04:26 +04:00
|
|
|
case CMD_PREV:
|
2001-08-20 15:24:57 +04:00
|
|
|
rv = skip(-1, 1);
|
2001-08-20 13:50:10 +04:00
|
|
|
break;
|
2001-07-01 09:04:26 +04:00
|
|
|
|
|
|
|
case CMD_NEXT:
|
2001-08-20 15:24:57 +04:00
|
|
|
rv = skip(1, 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CMD_SHUFFLE:
|
|
|
|
if (interactive == 0)
|
|
|
|
errx(EXIT_FAILURE,
|
|
|
|
"`shuffle' valid only in interactive mode");
|
|
|
|
if (shuffle == 0) {
|
|
|
|
itv_timer.it_interval.tv_sec = 1;
|
|
|
|
itv_timer.it_interval.tv_usec = 0;
|
|
|
|
itv_timer.it_value.tv_sec = 1;
|
|
|
|
itv_timer.it_value.tv_usec = 0;
|
|
|
|
if (setitimer(ITIMER_REAL, &itv_timer, NULL) == 0) {
|
|
|
|
shuffle = 1;
|
|
|
|
skip(0, 1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
itv_timer.it_interval.tv_sec = 0;
|
|
|
|
itv_timer.it_interval.tv_usec = 0;
|
|
|
|
itv_timer.it_value.tv_sec = 0;
|
|
|
|
itv_timer.it_value.tv_usec = 0;
|
|
|
|
if (setitimer(ITIMER_REAL, &itv_timer, NULL) == 0)
|
|
|
|
shuffle = 0;
|
|
|
|
}
|
|
|
|
printf("shuffle play:\t%s\n", shuffle ? "on" : "off");
|
|
|
|
rv = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CMD_SKIP:
|
|
|
|
if (!interactive)
|
|
|
|
errx(EXIT_FAILURE,
|
|
|
|
"`skip' valid only in interactive mode");
|
|
|
|
if (!shuffle)
|
|
|
|
warnx("`skip' valid only in shuffle mode");
|
|
|
|
else
|
|
|
|
skip(0, 1);
|
2001-08-20 13:50:10 +04:00
|
|
|
break;
|
|
|
|
|
1999-06-05 17:21:59 +04:00
|
|
|
case CMD_SET:
|
2001-08-20 13:50:10 +04:00
|
|
|
if (strcasecmp(arg, "msf") == 0)
|
1999-06-05 17:21:59 +04:00
|
|
|
msf = 1;
|
2001-08-20 13:50:10 +04:00
|
|
|
else if (strcasecmp(arg, "lba") == 0)
|
2000-01-05 21:15:20 +03:00
|
|
|
msf = 0;
|
1999-06-05 17:21:59 +04:00
|
|
|
else
|
2000-01-05 21:15:20 +03:00
|
|
|
warnx("invalid command arguments");
|
2001-08-20 13:50:10 +04:00
|
|
|
break;
|
1999-06-05 17:21:59 +04:00
|
|
|
|
|
|
|
case CMD_VOLUME:
|
2001-08-20 13:50:10 +04:00
|
|
|
if (strncasecmp(arg, "left", strlen(arg)) == 0)
|
|
|
|
rv = ioctl(fd, CDIOCSETLEFT);
|
|
|
|
else if (strncasecmp(arg, "right", strlen(arg)) == 0)
|
|
|
|
rv = ioctl(fd, CDIOCSETRIGHT);
|
|
|
|
else if (strncasecmp(arg, "mono", strlen(arg)) == 0)
|
|
|
|
rv = ioctl(fd, CDIOCSETMONO);
|
|
|
|
else if (strncasecmp(arg, "stereo", strlen(arg)) == 0)
|
|
|
|
rv = ioctl(fd, CDIOCSETSTEREO);
|
|
|
|
else if (strncasecmp(arg, "mute", strlen(arg)) == 0)
|
|
|
|
rv = ioctl(fd, CDIOCSETMUTE);
|
|
|
|
else {
|
|
|
|
rv = 0;
|
|
|
|
if (sscanf(arg, "%d %d", &l, &r) != 2) {
|
|
|
|
if (sscanf(arg, "%d", &l) == 1)
|
|
|
|
r = l;
|
|
|
|
else {
|
|
|
|
warnx("invalid command arguments");
|
|
|
|
break;
|
|
|
|
}
|
2000-08-30 14:13:52 +04:00
|
|
|
}
|
2001-08-20 13:50:10 +04:00
|
|
|
rv = setvol(l, r);
|
1999-06-05 17:21:59 +04:00
|
|
|
}
|
2001-08-20 13:50:10 +04:00
|
|
|
break;
|
|
|
|
|
1999-06-05 17:21:59 +04:00
|
|
|
case CMD_HELP:
|
|
|
|
default:
|
|
|
|
help();
|
2001-08-20 13:50:10 +04:00
|
|
|
rv = 0;
|
|
|
|
break;
|
1999-06-05 17:21:59 +04:00
|
|
|
}
|
2001-08-20 13:50:10 +04:00
|
|
|
|
|
|
|
return (rv);
|
1999-06-05 17:21:59 +04:00
|
|
|
}
|
|
|
|
|
2001-08-20 13:50:10 +04:00
|
|
|
int
|
2001-08-20 15:24:57 +04:00
|
|
|
play(const char *arg, int fromuser)
|
1999-06-05 17:21:59 +04:00
|
|
|
{
|
2003-01-31 00:23:57 +03:00
|
|
|
int rv, n, start, end, istart, iend, blk, len, relend;
|
2001-08-20 13:50:10 +04:00
|
|
|
u_int tr1, tr2, m1, m2, s1, s2, f1, f2, tm, ts, tf;
|
1999-06-05 17:21:59 +04:00
|
|
|
struct ioc_toc_header h;
|
2001-08-20 13:50:10 +04:00
|
|
|
|
2001-08-20 15:24:57 +04:00
|
|
|
if (shuffle && fromuser) {
|
2001-08-20 16:37:21 +04:00
|
|
|
warnx("`play' not valid in shuffle mode");
|
2001-08-20 15:24:57 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2001-08-20 13:50:10 +04:00
|
|
|
if ((rv = ioctl(fd, CDIOREADTOCHEADER, &h)) < 0) {
|
|
|
|
warn("ioctl(CDIOREADTOCHEADER)");
|
|
|
|
return (rv);
|
|
|
|
}
|
1999-06-05 17:21:59 +04:00
|
|
|
|
1999-06-05 18:03:32 +04:00
|
|
|
end = 0;
|
|
|
|
istart = iend = 1;
|
1999-06-05 17:21:59 +04:00
|
|
|
n = h.ending_track - h.starting_track + 1;
|
2001-08-20 13:50:10 +04:00
|
|
|
rv = read_toc_entrys((n + 1) * sizeof(struct cd_toc_entry));
|
|
|
|
if (rv < 0)
|
|
|
|
return (rv);
|
1999-06-05 17:21:59 +04:00
|
|
|
|
2001-08-20 13:50:10 +04:00
|
|
|
if (arg == NULL || *arg == '\0') {
|
1999-06-05 17:21:59 +04:00
|
|
|
/* Play the whole disc */
|
2001-08-20 15:24:57 +04:00
|
|
|
return (play_track(h.starting_track, 1, h.ending_track, 99));
|
1999-06-05 17:21:59 +04:00
|
|
|
}
|
2001-08-20 13:50:10 +04:00
|
|
|
|
|
|
|
if (strchr(arg, '#') != NULL) {
|
1999-06-05 17:21:59 +04:00
|
|
|
/* Play block #blk [ len ] */
|
1999-09-19 01:15:23 +04:00
|
|
|
len = 0;
|
1999-06-05 17:21:59 +04:00
|
|
|
|
|
|
|
if (2 != sscanf(arg, "#%d%d", &blk, &len) &&
|
|
|
|
1 != sscanf(arg, "#%d", &blk))
|
|
|
|
goto Clean_up;
|
|
|
|
|
|
|
|
if (len == 0) {
|
2003-01-31 00:23:57 +03:00
|
|
|
len = toc2lba(n);
|
1999-06-05 17:21:59 +04:00
|
|
|
}
|
1999-09-19 01:15:23 +04:00
|
|
|
return (play_blocks(blk, len));
|
1999-06-05 17:21:59 +04:00
|
|
|
}
|
2001-08-20 13:50:10 +04:00
|
|
|
|
|
|
|
if (strchr(arg, ':') != NULL) {
|
1999-06-05 17:21:59 +04:00
|
|
|
/*
|
|
|
|
* Play MSF m1:s1 [ .f1 ] [ m2:s2 [ .f2 ] ]
|
|
|
|
*
|
|
|
|
* Will now also undestand timed addresses relative
|
|
|
|
* to the beginning of a track in the form...
|
|
|
|
*
|
|
|
|
* tr1 m1:s1[.f1] [[tr2] [m2:s2[.f2]]]
|
|
|
|
*/
|
2003-01-31 00:23:57 +03:00
|
|
|
relend = 1;
|
1999-06-05 17:21:59 +04:00
|
|
|
tr2 = m2 = s2 = f2 = f1 = 0;
|
2001-08-20 13:50:10 +04:00
|
|
|
if (8 == sscanf(arg, "%d %d:%d.%d %d %d:%d.%d", &tr1, &m1,
|
1999-09-19 01:15:23 +04:00
|
|
|
&s1, &f1, &tr2, &m2, &s2, &f2))
|
1999-06-05 17:21:59 +04:00
|
|
|
goto Play_Relative_Addresses;
|
|
|
|
|
|
|
|
tr2 = m2 = s2 = f2 = f1 = 0;
|
2001-08-20 13:50:10 +04:00
|
|
|
if (7 == sscanf(arg, "%d %d:%d %d %d:%d.%d", &tr1, &m1, &s1,
|
1999-09-19 01:15:23 +04:00
|
|
|
&tr2, &m2, &s2, &f2))
|
1999-06-05 17:21:59 +04:00
|
|
|
goto Play_Relative_Addresses;
|
|
|
|
|
|
|
|
tr2 = m2 = s2 = f2 = f1 = 0;
|
2001-08-20 13:50:10 +04:00
|
|
|
if (7 == sscanf(arg, "%d %d:%d.%d %d %d:%d", &tr1, &m1, &s1,
|
1999-09-19 01:15:23 +04:00
|
|
|
&f1, &tr2, &m2, &s2))
|
1999-06-05 17:21:59 +04:00
|
|
|
goto Play_Relative_Addresses;
|
|
|
|
|
|
|
|
tr2 = m2 = s2 = f2 = f1 = 0;
|
2001-08-20 13:50:10 +04:00
|
|
|
if (7 == sscanf(arg, "%d %d:%d.%d %d:%d.%d", &tr1, &m1, &s1,
|
1999-09-19 01:15:23 +04:00
|
|
|
&f1, &m2, &s2, &f2))
|
1999-06-05 17:21:59 +04:00
|
|
|
goto Play_Relative_Addresses;
|
|
|
|
|
|
|
|
tr2 = m2 = s2 = f2 = f1 = 0;
|
1999-09-19 01:15:23 +04:00
|
|
|
if (6 == sscanf(arg, "%d %d:%d.%d %d:%d", &tr1, &m1, &s1, &f1,
|
|
|
|
&m2, &s2))
|
1999-06-05 17:21:59 +04:00
|
|
|
goto Play_Relative_Addresses;
|
|
|
|
|
|
|
|
tr2 = m2 = s2 = f2 = f1 = 0;
|
2001-08-20 13:50:10 +04:00
|
|
|
if (6 == sscanf(arg, "%d %d:%d %d:%d.%d", &tr1, &m1, &s1, &m2,
|
1999-09-19 01:15:23 +04:00
|
|
|
&s2, &f2))
|
1999-06-05 17:21:59 +04:00
|
|
|
goto Play_Relative_Addresses;
|
|
|
|
|
|
|
|
tr2 = m2 = s2 = f2 = f1 = 0;
|
2001-08-20 13:50:10 +04:00
|
|
|
if (6 == sscanf(arg, "%d %d:%d.%d %d %d", &tr1, &m1, &s1, &f1,
|
1999-09-19 01:15:23 +04:00
|
|
|
&tr2, &m2))
|
1999-06-05 17:21:59 +04:00
|
|
|
goto Play_Relative_Addresses;
|
|
|
|
|
2003-01-31 00:23:57 +03:00
|
|
|
tr2 = m2 = s2 = f2 = f1 = 0;
|
|
|
|
if (6 == sscanf(arg, "%d %d:%d %d %d:%d", &tr1, &m1, &s1, &tr2,
|
|
|
|
&m2, &s2))
|
|
|
|
goto Play_Relative_Addresses;
|
|
|
|
|
1999-06-05 17:21:59 +04:00
|
|
|
tr2 = m2 = s2 = f2 = f1 = 0;
|
2001-08-20 13:50:10 +04:00
|
|
|
if (5 == sscanf(arg, "%d %d:%d %d:%d", &tr1, &m1, &s1, &m2,
|
1999-09-19 01:15:23 +04:00
|
|
|
&s2))
|
1999-06-05 17:21:59 +04:00
|
|
|
goto Play_Relative_Addresses;
|
|
|
|
|
|
|
|
tr2 = m2 = s2 = f2 = f1 = 0;
|
2001-08-20 13:50:10 +04:00
|
|
|
if (5 == sscanf(arg, "%d %d:%d %d %d", &tr1, &m1, &s1, &tr2,
|
1999-09-19 01:15:23 +04:00
|
|
|
&m2))
|
1999-06-05 17:21:59 +04:00
|
|
|
goto Play_Relative_Addresses;
|
|
|
|
|
2003-01-31 00:23:57 +03:00
|
|
|
relend=0;
|
1999-06-05 17:21:59 +04:00
|
|
|
tr2 = m2 = s2 = f2 = f1 = 0;
|
2001-08-20 13:50:10 +04:00
|
|
|
if (5 == sscanf(arg, "%d %d:%d.%d %d", &tr1, &m1, &s1, &f1,
|
1999-09-19 01:15:23 +04:00
|
|
|
&tr2))
|
1999-06-05 17:21:59 +04:00
|
|
|
goto Play_Relative_Addresses;
|
|
|
|
|
|
|
|
tr2 = m2 = s2 = f2 = f1 = 0;
|
|
|
|
if (4 == sscanf(arg, "%d %d:%d %d", &tr1, &m1, &s1, &tr2))
|
|
|
|
goto Play_Relative_Addresses;
|
|
|
|
|
|
|
|
tr2 = m2 = s2 = f2 = f1 = 0;
|
|
|
|
if (4 == sscanf(arg, "%d %d:%d.%d", &tr1, &m1, &s1, &f1))
|
|
|
|
goto Play_Relative_Addresses;
|
|
|
|
|
|
|
|
tr2 = m2 = s2 = f2 = f1 = 0;
|
|
|
|
if (3 == sscanf(arg, "%d %d:%d", &tr1, &m1, &s1))
|
|
|
|
goto Play_Relative_Addresses;
|
|
|
|
|
|
|
|
tr2 = m2 = s2 = f2 = f1 = 0;
|
|
|
|
goto Try_Absolute_Timed_Addresses;
|
|
|
|
|
|
|
|
Play_Relative_Addresses:
|
|
|
|
if (!tr1)
|
|
|
|
tr1 = 1;
|
1999-06-05 18:03:32 +04:00
|
|
|
else if (tr1 > n)
|
|
|
|
tr1 = n;
|
1999-06-05 17:21:59 +04:00
|
|
|
|
2003-01-31 00:23:57 +03:00
|
|
|
toc2msf(tr1-1, &tm, &ts, &tf);
|
|
|
|
addmsf(&m1, &s1, &f1, tm, ts, tf);
|
|
|
|
|
|
|
|
toc2msf(tr1, &tm, &ts, &tf);
|
|
|
|
|
2001-08-20 13:50:10 +04:00
|
|
|
if ((m1 > tm) || ((m1 == tm) && ((s1 > ts) || ((s1 == ts) &&
|
1999-06-05 18:03:32 +04:00
|
|
|
(f1 > tf))))) {
|
2002-06-11 10:06:18 +04:00
|
|
|
warnx("Track %d is not that long.", tr1);
|
1999-06-05 17:21:59 +04:00
|
|
|
return (0);
|
|
|
|
}
|
2003-01-31 00:23:57 +03:00
|
|
|
tr1--; /* XXXXX ???? */
|
1999-06-05 17:21:59 +04:00
|
|
|
|
|
|
|
|
|
|
|
if (!tr2) {
|
2003-01-31 00:23:57 +03:00
|
|
|
if (relend) {
|
1999-06-05 17:21:59 +04:00
|
|
|
tr2 = tr1;
|
2003-01-31 00:23:57 +03:00
|
|
|
|
|
|
|
addmsf(&m2, &s2, &f2, m1, s1, f1);
|
1999-06-05 17:21:59 +04:00
|
|
|
} else {
|
|
|
|
tr2 = n;
|
2003-01-31 00:23:57 +03:00
|
|
|
|
|
|
|
toc2msf(n, &m2, &s2, &f2);
|
1999-06-05 17:21:59 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (tr2 > n) {
|
|
|
|
tr2 = n;
|
|
|
|
m2 = s2 = f2 = 0;
|
|
|
|
} else {
|
2003-01-31 00:23:57 +03:00
|
|
|
if (relend)
|
1999-06-05 17:21:59 +04:00
|
|
|
tr2--;
|
2003-01-31 00:23:57 +03:00
|
|
|
|
|
|
|
toc2msf(tr2, &tm, &ts, &tf);
|
|
|
|
addmsf(&m2, &s2, &f2, tm, ts, tf);
|
1999-06-05 17:21:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-31 00:23:57 +03:00
|
|
|
toc2msf(n, &tm, &ts, &tf);
|
1999-06-05 18:03:32 +04:00
|
|
|
|
2001-08-20 13:50:10 +04:00
|
|
|
if ((tr2 < n) && ((m2 > tm) || ((m2 == tm) && ((s2 > ts) ||
|
1999-06-05 18:03:32 +04:00
|
|
|
((s2 == ts) && (f2 > tf)))))) {
|
2002-06-11 10:06:18 +04:00
|
|
|
warnx("The playing time of the disc is not that long.");
|
1999-06-05 17:21:59 +04:00
|
|
|
return (0);
|
|
|
|
}
|
1999-06-05 18:03:32 +04:00
|
|
|
|
1999-06-05 17:21:59 +04:00
|
|
|
return (play_msf(m1, s1, f1, m2, s2, f2));
|
|
|
|
|
|
|
|
Try_Absolute_Timed_Addresses:
|
2002-09-29 01:48:35 +04:00
|
|
|
m2 = UINT_MAX;
|
|
|
|
|
1999-06-05 17:21:59 +04:00
|
|
|
if (6 != sscanf(arg, "%d:%d.%d%d:%d.%d",
|
|
|
|
&m1, &s1, &f1, &m2, &s2, &f2) &&
|
|
|
|
5 != sscanf(arg, "%d:%d.%d%d:%d", &m1, &s1, &f1, &m2, &s2) &&
|
|
|
|
5 != sscanf(arg, "%d:%d%d:%d.%d", &m1, &s1, &m2, &s2, &f2) &&
|
|
|
|
3 != sscanf(arg, "%d:%d.%d", &m1, &s1, &f1) &&
|
|
|
|
4 != sscanf(arg, "%d:%d%d:%d", &m1, &s1, &m2, &s2) &&
|
|
|
|
2 != sscanf(arg, "%d:%d", &m1, &s1))
|
|
|
|
goto Clean_up;
|
|
|
|
|
2002-09-29 01:48:35 +04:00
|
|
|
if (m2 == UINT_MAX) {
|
1999-06-05 17:21:59 +04:00
|
|
|
if (msf) {
|
|
|
|
m2 = toc_buffer[n].addr.msf.minute;
|
|
|
|
s2 = toc_buffer[n].addr.msf.second;
|
|
|
|
f2 = toc_buffer[n].addr.msf.frame;
|
|
|
|
} else {
|
2000-01-05 21:15:20 +03:00
|
|
|
lba2msf(be32toh(toc_buffer[n].addr.lba),
|
1999-06-05 17:21:59 +04:00
|
|
|
&tm, &ts, &tf);
|
|
|
|
m2 = tm;
|
|
|
|
s2 = ts;
|
|
|
|
f2 = tf;
|
|
|
|
}
|
|
|
|
}
|
1999-09-19 01:15:23 +04:00
|
|
|
return (play_msf(m1, s1, f1, m2, s2, f2));
|
1999-06-05 17:21:59 +04:00
|
|
|
}
|
2001-08-20 13:50:10 +04:00
|
|
|
|
1999-06-05 17:21:59 +04:00
|
|
|
/*
|
|
|
|
* Play track trk1 [ .idx1 ] [ trk2 [ .idx2 ] ]
|
|
|
|
*/
|
|
|
|
if (4 != sscanf(arg, "%d.%d%d.%d", &start, &istart, &end, &iend) &&
|
|
|
|
3 != sscanf(arg, "%d.%d%d", &start, &istart, &end) &&
|
|
|
|
3 != sscanf(arg, "%d%d.%d", &start, &end, &iend) &&
|
|
|
|
2 != sscanf(arg, "%d.%d", &start, &istart) &&
|
|
|
|
2 != sscanf(arg, "%d%d", &start, &end) &&
|
|
|
|
1 != sscanf(arg, "%d", &start))
|
|
|
|
goto Clean_up;
|
|
|
|
|
|
|
|
if (end == 0)
|
|
|
|
end = n;
|
|
|
|
return (play_track(start, istart, end, iend));
|
|
|
|
|
|
|
|
Clean_up:
|
|
|
|
warnx("invalid command arguments");
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2001-08-20 15:24:57 +04:00
|
|
|
void
|
2003-09-12 04:39:38 +04:00
|
|
|
sig_timer(int sig)
|
2001-08-20 15:24:57 +04:00
|
|
|
{
|
|
|
|
sigset_t anymore;
|
|
|
|
|
|
|
|
sigpending(&anymore);
|
|
|
|
if (sigismember(&anymore, SIGALRM))
|
|
|
|
return;
|
|
|
|
setitimer(ITIMER_REAL, &itv_timer, NULL);
|
|
|
|
if (fd != -1)
|
|
|
|
skip(0, 0);
|
|
|
|
}
|
|
|
|
|
2001-07-01 09:04:26 +04:00
|
|
|
int
|
2001-08-20 15:24:57 +04:00
|
|
|
skip(int dir, int fromuser)
|
2001-07-01 09:04:26 +04:00
|
|
|
{
|
2001-08-20 13:50:10 +04:00
|
|
|
char str[16];
|
2001-08-20 15:24:57 +04:00
|
|
|
int rv, trk, idx, m, s, f;
|
2001-07-01 09:04:26 +04:00
|
|
|
struct ioc_toc_header h;
|
2001-08-20 13:50:10 +04:00
|
|
|
|
|
|
|
if ((rv = ioctl(fd, CDIOREADTOCHEADER, &h)) < 0) {
|
|
|
|
warn("ioctl(CDIOREADTOCHEADER)");
|
|
|
|
return (rv);
|
2001-07-01 09:04:26 +04:00
|
|
|
}
|
2001-08-20 15:24:57 +04:00
|
|
|
if ((rv = get_status(&trk, &idx, &m, &s, &f)) < 0)
|
2001-08-20 13:50:10 +04:00
|
|
|
return (rv);
|
2001-08-20 15:24:57 +04:00
|
|
|
|
|
|
|
if (dir == 0) {
|
|
|
|
if (fromuser || (rv != CD_AS_PLAY_IN_PROGRESS &&
|
|
|
|
rv != CD_AS_PLAY_PAUSED))
|
|
|
|
trk = h.starting_track +
|
2004-09-10 09:34:54 +04:00
|
|
|
arc4random() % (h.ending_track - h.starting_track + 1);
|
2001-08-20 15:24:57 +04:00
|
|
|
else
|
|
|
|
return (0);
|
|
|
|
} else {
|
|
|
|
trk += dir;
|
|
|
|
if (trk > h.ending_track)
|
|
|
|
trk = h.starting_track;
|
|
|
|
else if(trk < h.starting_track)
|
|
|
|
trk = h.ending_track;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shuffle)
|
2003-07-14 13:18:22 +04:00
|
|
|
snprintf(str, sizeof(str), "%d %d", trk, trk);
|
2001-08-20 15:24:57 +04:00
|
|
|
else
|
2003-07-14 13:18:22 +04:00
|
|
|
snprintf(str, sizeof(str), "%d", trk);
|
2001-08-20 15:24:57 +04:00
|
|
|
|
|
|
|
return (play(str, 0));
|
2001-07-01 09:04:26 +04:00
|
|
|
}
|
|
|
|
|
2001-08-20 13:50:10 +04:00
|
|
|
const char *
|
|
|
|
strstatus(int sts)
|
1999-06-05 17:21:59 +04:00
|
|
|
{
|
2001-08-20 13:50:10 +04:00
|
|
|
const char *str;
|
1999-06-05 18:03:32 +04:00
|
|
|
|
1999-06-05 17:21:59 +04:00
|
|
|
switch (sts) {
|
2001-08-20 13:50:10 +04:00
|
|
|
case CD_AS_AUDIO_INVALID:
|
|
|
|
str = "invalid";
|
|
|
|
break;
|
|
|
|
case CD_AS_PLAY_IN_PROGRESS:
|
|
|
|
str = "playing";
|
|
|
|
break;
|
|
|
|
case CD_AS_PLAY_PAUSED:
|
|
|
|
str = "paused";
|
|
|
|
break;
|
|
|
|
case CD_AS_PLAY_COMPLETED:
|
|
|
|
str = "completed";
|
|
|
|
break;
|
|
|
|
case CD_AS_PLAY_ERROR:
|
|
|
|
str = "error";
|
|
|
|
break;
|
|
|
|
case CD_AS_NO_STATUS:
|
|
|
|
str = "not playing";
|
|
|
|
break;
|
1999-06-05 17:21:59 +04:00
|
|
|
default:
|
2001-08-20 13:50:10 +04:00
|
|
|
str = "<unknown>";
|
|
|
|
break;
|
1999-06-05 17:21:59 +04:00
|
|
|
}
|
2001-08-20 13:50:10 +04:00
|
|
|
|
|
|
|
return (str);
|
1999-06-05 17:21:59 +04:00
|
|
|
}
|
|
|
|
|
2001-08-20 13:50:10 +04:00
|
|
|
int
|
|
|
|
print_status(const char *arg)
|
1999-06-05 17:21:59 +04:00
|
|
|
{
|
|
|
|
struct cd_sub_channel_info data;
|
1999-06-05 18:03:32 +04:00
|
|
|
struct ioc_read_subchannel ss;
|
2001-08-20 15:24:57 +04:00
|
|
|
int rv, trk, idx, m, s, f;
|
1999-06-05 18:03:32 +04:00
|
|
|
struct ioc_vol v;
|
1999-06-05 17:21:59 +04:00
|
|
|
|
2001-08-20 15:24:57 +04:00
|
|
|
if ((rv = get_status(&trk, &idx, &m, &s, &f)) >= 0) {
|
|
|
|
printf("audio status:\t%s\n", strstatus(rv));
|
2001-08-20 13:50:10 +04:00
|
|
|
printf("current track:\t%d\n", trk);
|
2001-08-20 15:24:57 +04:00
|
|
|
printf("current index:\t%d\n", idx);
|
2001-08-20 13:50:10 +04:00
|
|
|
printf("position:\t%d:%02d.%02d\n", m, s, f);
|
|
|
|
} else
|
|
|
|
printf("audio status:\tno info available\n");
|
|
|
|
|
2001-08-20 15:24:57 +04:00
|
|
|
printf("shuffle play:\t%s\n", shuffle ? "on" : "off");
|
|
|
|
|
2001-08-20 13:50:10 +04:00
|
|
|
bzero(&ss, sizeof(ss));
|
|
|
|
ss.data = &data;
|
|
|
|
ss.data_len = sizeof(data);
|
|
|
|
ss.address_format = msf ? CD_MSF_FORMAT : CD_LBA_FORMAT;
|
|
|
|
ss.data_format = CD_MEDIA_CATALOG;
|
|
|
|
|
2001-08-20 15:24:57 +04:00
|
|
|
if (ioctl(fd, CDIOCREADSUBCHANNEL, (char *)&ss) >= 0) {
|
2001-08-20 13:50:10 +04:00
|
|
|
printf("media catalog:\t%sactive",
|
|
|
|
ss.data->what.media_catalog.mc_valid ? "" : "in");
|
|
|
|
if (ss.data->what.media_catalog.mc_valid &&
|
|
|
|
ss.data->what.media_catalog.mc_number[0])
|
|
|
|
printf(" (%.15s)",
|
|
|
|
ss.data->what.media_catalog.mc_number);
|
|
|
|
putchar('\n');
|
|
|
|
} else
|
|
|
|
printf("media catalog:\tnone\n");
|
|
|
|
|
2001-08-20 15:24:57 +04:00
|
|
|
if (ioctl(fd, CDIOCGETVOL, &v) >= 0) {
|
2001-08-20 13:50:10 +04:00
|
|
|
printf("left volume:\t%d\n", v.vol[0]);
|
|
|
|
printf("right volume:\t%d\n", v.vol[1]);
|
|
|
|
} else {
|
|
|
|
printf("left volume:\tnot available\n");
|
|
|
|
printf("right volume:\tnot available\n");
|
1999-06-05 17:21:59 +04:00
|
|
|
}
|
2001-08-20 13:50:10 +04:00
|
|
|
|
2001-08-20 15:24:57 +04:00
|
|
|
; return (0);
|
1999-06-05 17:21:59 +04:00
|
|
|
}
|
|
|
|
|
2001-08-20 13:50:10 +04:00
|
|
|
int
|
|
|
|
info(const char *arg)
|
1999-06-05 17:21:59 +04:00
|
|
|
{
|
|
|
|
struct ioc_toc_header h;
|
|
|
|
int rc, i, n;
|
|
|
|
|
|
|
|
if ((rc = ioctl(fd, CDIOREADTOCHEADER, &h)) < 0) {
|
2001-08-20 13:50:10 +04:00
|
|
|
warn("ioctl(CDIOREADTOCHEADER)");
|
1999-06-05 17:21:59 +04:00
|
|
|
return (rc);
|
|
|
|
}
|
|
|
|
|
|
|
|
n = h.ending_track - h.starting_track + 1;
|
|
|
|
rc = read_toc_entrys((n + 1) * sizeof(struct cd_toc_entry));
|
|
|
|
if (rc < 0)
|
|
|
|
return (rc);
|
|
|
|
|
2003-02-19 15:55:58 +03:00
|
|
|
printf("track start duration block length type\n");
|
|
|
|
printf("--------------------------------------------------\n");
|
1999-06-05 17:21:59 +04:00
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
printf("%5d ", toc_buffer[i].track);
|
2003-02-19 15:55:58 +03:00
|
|
|
print_track(toc_buffer + i);
|
1999-06-05 17:21:59 +04:00
|
|
|
}
|
2003-02-28 08:48:58 +03:00
|
|
|
printf(" - "); /* Lead-out area */
|
2003-02-19 15:55:58 +03:00
|
|
|
print_track(toc_buffer + n);
|
1999-06-05 17:21:59 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2001-08-20 13:50:10 +04:00
|
|
|
void
|
|
|
|
lba2msf(u_long lba, u_int *m, u_int *s, u_int *f)
|
1999-06-05 17:21:59 +04:00
|
|
|
{
|
2001-08-20 13:50:10 +04:00
|
|
|
|
1999-06-05 17:21:59 +04:00
|
|
|
lba += 150; /* block start offset */
|
|
|
|
lba &= 0xffffff; /* negative lbas use only 24 bits */
|
|
|
|
*m = lba / (60 * 75);
|
|
|
|
lba %= (60 * 75);
|
|
|
|
*s = lba / 75;
|
|
|
|
*f = lba % 75;
|
|
|
|
}
|
|
|
|
|
2001-08-20 13:50:10 +04:00
|
|
|
u_int
|
|
|
|
msf2lba(u_int m, u_int s, u_int f)
|
1999-06-05 17:21:59 +04:00
|
|
|
{
|
1999-06-05 18:03:32 +04:00
|
|
|
|
1999-06-05 17:21:59 +04:00
|
|
|
return (((m * 60) + s) * 75 + f) - 150;
|
|
|
|
}
|
|
|
|
|
2001-08-20 13:50:10 +04:00
|
|
|
void
|
2003-02-19 15:55:58 +03:00
|
|
|
print_track(struct cd_toc_entry *e)
|
1999-06-05 17:21:59 +04:00
|
|
|
{
|
|
|
|
int block, next, len;
|
2001-08-20 13:50:10 +04:00
|
|
|
u_int m, s, f;
|
1999-06-05 17:21:59 +04:00
|
|
|
|
|
|
|
if (msf) {
|
|
|
|
/* Print track start */
|
|
|
|
printf("%2d:%02d.%02d ", e->addr.msf.minute,
|
|
|
|
e->addr.msf.second, e->addr.msf.frame);
|
|
|
|
|
|
|
|
block = msf2lba(e->addr.msf.minute, e->addr.msf.second,
|
|
|
|
e->addr.msf.frame);
|
|
|
|
} else {
|
2000-06-14 17:51:45 +04:00
|
|
|
block = e->addr.lba;
|
1999-06-05 17:21:59 +04:00
|
|
|
lba2msf(block, &m, &s, &f);
|
|
|
|
/* Print track start */
|
|
|
|
printf("%2d:%02d.%02d ", m, s, f);
|
|
|
|
}
|
2003-02-19 15:55:58 +03:00
|
|
|
if (e->track > CD_MAX_TRACK) {
|
|
|
|
/* lead-out area -- print block */
|
|
|
|
printf(" - %6d - lead-out\n", block);
|
1999-06-05 17:21:59 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (msf)
|
|
|
|
next = msf2lba(e[1].addr.msf.minute, e[1].addr.msf.second,
|
|
|
|
e[1].addr.msf.frame);
|
|
|
|
else
|
2000-06-14 17:51:45 +04:00
|
|
|
next = e[1].addr.lba;
|
1999-06-05 17:21:59 +04:00
|
|
|
len = next - block;
|
|
|
|
lba2msf(len, &m, &s, &f);
|
|
|
|
|
|
|
|
/* Print duration, block, length, type */
|
2003-02-19 15:55:58 +03:00
|
|
|
printf("%2d:%02d.%02d %6d %6d %8s\n", m, s, f, block, len,
|
1999-06-05 17:21:59 +04:00
|
|
|
(e->control & 4) ? "data" : "audio");
|
|
|
|
}
|
|
|
|
|
2001-08-20 13:50:10 +04:00
|
|
|
int
|
|
|
|
play_track(int tstart, int istart, int tend, int iend)
|
1999-06-05 17:21:59 +04:00
|
|
|
{
|
|
|
|
struct ioc_play_track t;
|
2001-08-20 13:50:10 +04:00
|
|
|
int rv;
|
1999-06-05 17:21:59 +04:00
|
|
|
|
|
|
|
t.start_track = tstart;
|
|
|
|
t.start_index = istart;
|
|
|
|
t.end_track = tend;
|
|
|
|
t.end_index = iend;
|
|
|
|
|
2001-08-20 13:50:10 +04:00
|
|
|
if ((rv = ioctl(fd, CDIOCPLAYTRACKS, &t)) < 0)
|
|
|
|
warn("ioctl(CDIOCPLAYTRACKS)");
|
|
|
|
return (rv);
|
1999-06-05 17:21:59 +04:00
|
|
|
}
|
|
|
|
|
2001-08-20 13:50:10 +04:00
|
|
|
int
|
|
|
|
play_blocks(int blk, int len)
|
1999-06-05 17:21:59 +04:00
|
|
|
{
|
|
|
|
struct ioc_play_blocks t;
|
2001-08-20 13:50:10 +04:00
|
|
|
int rv;
|
1999-06-05 17:21:59 +04:00
|
|
|
|
|
|
|
t.blk = blk;
|
|
|
|
t.len = len;
|
|
|
|
|
2001-08-20 13:50:10 +04:00
|
|
|
if ((rv = ioctl(fd, CDIOCPLAYBLOCKS, &t)) < 0)
|
|
|
|
warn("ioctl(CDIOCPLAYBLOCKS");
|
|
|
|
return (rv);
|
1999-06-05 17:21:59 +04:00
|
|
|
}
|
|
|
|
|
2001-08-20 13:50:10 +04:00
|
|
|
int
|
|
|
|
setvol(int left, int right)
|
1999-06-05 17:21:59 +04:00
|
|
|
{
|
|
|
|
struct ioc_vol v;
|
2001-08-20 13:50:10 +04:00
|
|
|
int rv;
|
1999-06-05 17:21:59 +04:00
|
|
|
|
|
|
|
v.vol[0] = left;
|
|
|
|
v.vol[1] = right;
|
|
|
|
v.vol[2] = 0;
|
|
|
|
v.vol[3] = 0;
|
|
|
|
|
2001-08-20 13:50:10 +04:00
|
|
|
if ((rv = ioctl(fd, CDIOCSETVOL, &v)) < 0)
|
|
|
|
warn("ioctl(CDIOCSETVOL)");
|
|
|
|
return (rv);
|
1999-06-05 17:21:59 +04:00
|
|
|
}
|
|
|
|
|
2001-08-20 13:50:10 +04:00
|
|
|
int
|
|
|
|
read_toc_entrys(int len)
|
1999-06-05 17:21:59 +04:00
|
|
|
{
|
|
|
|
struct ioc_read_toc_entry t;
|
2001-08-20 13:50:10 +04:00
|
|
|
int rv;
|
1999-06-05 17:21:59 +04:00
|
|
|
|
|
|
|
t.address_format = msf ? CD_MSF_FORMAT : CD_LBA_FORMAT;
|
|
|
|
t.starting_track = 0;
|
|
|
|
t.data_len = len;
|
|
|
|
t.data = toc_buffer;
|
|
|
|
|
2001-08-20 13:50:10 +04:00
|
|
|
if ((rv = ioctl(fd, CDIOREADTOCENTRYS, &t)) < 0)
|
|
|
|
warn("ioctl(CDIOREADTOCENTRYS)");
|
|
|
|
return (rv);
|
1999-06-05 17:21:59 +04:00
|
|
|
}
|
|
|
|
|
2001-08-20 13:50:10 +04:00
|
|
|
int
|
|
|
|
play_msf(int start_m, int start_s, int start_f, int end_m, int end_s,
|
|
|
|
int end_f)
|
1999-06-05 17:21:59 +04:00
|
|
|
{
|
|
|
|
struct ioc_play_msf a;
|
2001-08-20 13:50:10 +04:00
|
|
|
int rv;
|
1999-06-05 17:21:59 +04:00
|
|
|
|
|
|
|
a.start_m = start_m;
|
|
|
|
a.start_s = start_s;
|
|
|
|
a.start_f = start_f;
|
|
|
|
a.end_m = end_m;
|
|
|
|
a.end_s = end_s;
|
|
|
|
a.end_f = end_f;
|
|
|
|
|
2001-08-20 13:50:10 +04:00
|
|
|
if ((rv = ioctl(fd, CDIOCPLAYMSF, &a)) < 0)
|
|
|
|
warn("ioctl(CDIOREADTOCENTRYS)");
|
|
|
|
return (rv);
|
1999-06-05 17:21:59 +04:00
|
|
|
}
|
|
|
|
|
2001-08-20 13:50:10 +04:00
|
|
|
int
|
2001-08-20 15:24:57 +04:00
|
|
|
get_status(int *trk, int *idx, int *min, int *sec, int *frame)
|
1999-06-05 17:21:59 +04:00
|
|
|
{
|
|
|
|
struct ioc_read_subchannel s;
|
|
|
|
struct cd_sub_channel_info data;
|
2001-08-20 13:50:10 +04:00
|
|
|
u_int mm, ss, ff;
|
|
|
|
int rv;
|
1999-06-05 17:21:59 +04:00
|
|
|
|
|
|
|
bzero(&s, sizeof(s));
|
|
|
|
s.data = &data;
|
|
|
|
s.data_len = sizeof(data);
|
|
|
|
s.address_format = msf ? CD_MSF_FORMAT : CD_LBA_FORMAT;
|
|
|
|
s.data_format = CD_CURRENT_POSITION;
|
|
|
|
|
2001-08-20 13:50:10 +04:00
|
|
|
if ((rv = ioctl(fd, CDIOCREADSUBCHANNEL, &s)) < 0) {
|
|
|
|
warn("ioctl(CDIOCREADSUBCHANNEL)");
|
|
|
|
return (rv);
|
|
|
|
}
|
1999-06-05 17:21:59 +04:00
|
|
|
|
|
|
|
*trk = s.data->what.position.track_number;
|
2001-08-20 15:24:57 +04:00
|
|
|
*idx = s.data->what.position.index_number;
|
1999-06-05 17:21:59 +04:00
|
|
|
if (msf) {
|
|
|
|
*min = s.data->what.position.reladdr.msf.minute;
|
|
|
|
*sec = s.data->what.position.reladdr.msf.second;
|
|
|
|
*frame = s.data->what.position.reladdr.msf.frame;
|
|
|
|
} else {
|
2001-08-20 13:50:10 +04:00
|
|
|
lba2msf(be32toh(s.data->what.position.reladdr.lba), &mm,
|
|
|
|
&ss, &ff);
|
1999-06-05 17:21:59 +04:00
|
|
|
*min = mm;
|
|
|
|
*sec = ss;
|
|
|
|
*frame = ff;
|
|
|
|
}
|
|
|
|
|
1999-09-19 01:15:23 +04:00
|
|
|
return (s.data->header.audio_status);
|
1999-06-05 17:21:59 +04:00
|
|
|
}
|
|
|
|
|
2001-08-20 13:50:10 +04:00
|
|
|
const char *
|
|
|
|
prompt(void)
|
1999-06-05 17:21:59 +04:00
|
|
|
{
|
2001-08-20 13:50:10 +04:00
|
|
|
|
1999-11-26 21:34:58 +03:00
|
|
|
return ("cdplay> ");
|
1999-06-05 17:21:59 +04:00
|
|
|
}
|
|
|
|
|
2001-08-20 13:50:10 +04:00
|
|
|
const char *
|
|
|
|
parse(char *buf, int *cmd)
|
1999-06-05 17:21:59 +04:00
|
|
|
{
|
2001-08-20 13:50:10 +04:00
|
|
|
const struct cmdtab *c, *mc;
|
1999-09-19 01:15:23 +04:00
|
|
|
char *p, *q;
|
1999-06-05 17:21:59 +04:00
|
|
|
int len;
|
|
|
|
|
|
|
|
for (p = buf; isspace(*p); p++)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (isdigit(*p) || (p[0] == '#' && isdigit(p[1]))) {
|
|
|
|
*cmd = CMD_PLAY;
|
|
|
|
return (p);
|
|
|
|
}
|
1999-09-19 01:15:23 +04:00
|
|
|
|
2001-08-20 13:50:10 +04:00
|
|
|
for (buf = p; *p != '\0' && !isspace(*p); p++)
|
1999-06-05 17:21:59 +04:00
|
|
|
continue;
|
|
|
|
|
2001-08-20 13:50:10 +04:00
|
|
|
if ((len = p - buf) == 0)
|
1999-06-05 17:21:59 +04:00
|
|
|
return (0);
|
|
|
|
|
2001-08-20 13:50:10 +04:00
|
|
|
if (*p != '\0') { /* It must be a spacing character! */
|
1999-06-05 17:21:59 +04:00
|
|
|
*p++ = 0;
|
2001-08-20 13:50:10 +04:00
|
|
|
for (q = p; *q != '\0' && *q != '\n' && *q != '\r'; q++)
|
1999-06-05 17:21:59 +04:00
|
|
|
continue;
|
|
|
|
*q = 0;
|
|
|
|
}
|
1999-09-19 01:15:23 +04:00
|
|
|
|
1999-06-05 17:21:59 +04:00
|
|
|
*cmd = -1;
|
1999-09-19 01:15:23 +04:00
|
|
|
|
2001-08-20 13:50:10 +04:00
|
|
|
mc = cmdtab + sizeof(cmdtab) / sizeof(cmdtab[0]);
|
|
|
|
for (c = cmdtab; c < mc; c++) {
|
1999-06-05 17:21:59 +04:00
|
|
|
/* Is it an exact match? */
|
2001-08-20 13:50:10 +04:00
|
|
|
if (strcasecmp(buf, c->name) == 0) {
|
1999-06-05 17:21:59 +04:00
|
|
|
*cmd = c->command;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Try short hand forms then... */
|
2001-08-20 13:50:10 +04:00
|
|
|
if (len >= c->min && strncasecmp(buf, c->name, len) == 0) {
|
1999-06-05 17:21:59 +04:00
|
|
|
if (*cmd != -1 && *cmd != c->command) {
|
|
|
|
warnx("ambiguous command");
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
*cmd = c->command;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*cmd == -1) {
|
|
|
|
warnx("invalid command, enter ``help'' for commands");
|
|
|
|
return (0);
|
|
|
|
}
|
1999-09-19 01:15:23 +04:00
|
|
|
|
1999-06-05 17:21:59 +04:00
|
|
|
while (isspace(*p))
|
|
|
|
p++;
|
1999-09-19 01:15:23 +04:00
|
|
|
return (p);
|
1999-06-05 17:21:59 +04:00
|
|
|
}
|
|
|
|
|
2001-08-20 13:50:10 +04:00
|
|
|
int
|
|
|
|
opencd(void)
|
1999-06-05 17:21:59 +04:00
|
|
|
{
|
|
|
|
char devbuf[80];
|
|
|
|
|
|
|
|
if (fd > -1)
|
|
|
|
return (1);
|
|
|
|
|
2000-12-16 04:36:00 +03:00
|
|
|
fd = opendisk(cdname, O_RDONLY, devbuf, sizeof(devbuf), 0);
|
1999-06-05 17:21:59 +04:00
|
|
|
if (fd < 0) {
|
|
|
|
if (errno == ENXIO) {
|
2001-08-20 13:50:10 +04:00
|
|
|
/*
|
|
|
|
* ENXIO has an overloaded meaning here. The
|
|
|
|
* original "Device not configured" should be
|
|
|
|
* interpreted as "No disc in drive %s".
|
|
|
|
*/
|
1999-06-05 17:21:59 +04:00
|
|
|
warnx("no disc in drive %s", devbuf);
|
|
|
|
return (0);
|
|
|
|
}
|
2001-08-20 13:50:10 +04:00
|
|
|
err(EXIT_FAILURE, "%s", devbuf);
|
1999-06-05 17:21:59 +04:00
|
|
|
}
|
1999-09-19 01:15:23 +04:00
|
|
|
|
1999-06-05 17:21:59 +04:00
|
|
|
return (1);
|
|
|
|
}
|
2003-01-31 00:23:57 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
toc2msf(u_int i, u_int *m, u_int *s, u_int *f)
|
|
|
|
{
|
|
|
|
struct cd_toc_entry *ctep;
|
|
|
|
|
|
|
|
assert(i >= 0);
|
2003-02-19 15:55:58 +03:00
|
|
|
assert(i <= CD_MAX_TRACK);
|
2003-01-31 00:23:57 +03:00
|
|
|
|
|
|
|
ctep = &toc_buffer[i];
|
|
|
|
|
|
|
|
if (msf) {
|
|
|
|
*m = ctep->addr.msf.minute;
|
|
|
|
*s = ctep->addr.msf.second;
|
|
|
|
*f = ctep->addr.msf.frame;
|
|
|
|
} else {
|
|
|
|
lba2msf(be32toh(ctep->addr.lba), m, s, f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
toc2lba(u_int i)
|
|
|
|
{
|
|
|
|
struct cd_toc_entry *ctep;
|
|
|
|
|
|
|
|
assert(i > 0);
|
2003-02-19 15:55:58 +03:00
|
|
|
assert(i <= CD_MAX_TRACK);
|
2003-01-31 00:23:57 +03:00
|
|
|
|
|
|
|
ctep = &toc_buffer[i-1];
|
|
|
|
|
|
|
|
if (msf) {
|
|
|
|
return msf2lba(
|
|
|
|
ctep->addr.msf.minute,
|
|
|
|
ctep->addr.msf.second,
|
|
|
|
ctep->addr.msf.frame);
|
|
|
|
} else {
|
|
|
|
return be32toh(ctep->addr.lba);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
addmsf(u_int *m, u_int *s, u_int *f, u_int m2, u_int s2, u_int f2)
|
|
|
|
{
|
|
|
|
*f += f2;
|
|
|
|
if (*f > 75) {
|
|
|
|
*s += *f / 75;
|
|
|
|
*f %= 75;
|
|
|
|
}
|
|
|
|
|
|
|
|
*s += s2;
|
|
|
|
if (*s > 60) {
|
|
|
|
*m += *s / 60;
|
|
|
|
*s %= 60;
|
|
|
|
}
|
|
|
|
|
|
|
|
*m += m2;
|
|
|
|
}
|