Module Name:    src
Committed By:   drochner
Date:           Wed Jan  4 17:26:21 UTC 2012

Modified Files:
        src/usr.bin/cdplay: cdplay.1 cdplay.c

Log Message:
-make digital mode work in non-interactive mode (init sighandler
 earlier, sleep(3) until playing finished)
-also switch to digital mode if an audio device is given on the
 cmd line, or the (new) "CDPLAY_DIGITAL" env var is set

(The latter can be used to make digital mode default per system.
As I see it, analog mode is not dead yet - two of three external
DVD drives I looked at have a speaker output.)


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/usr.bin/cdplay/cdplay.1
cvs rdiff -u -r1.45 -r1.46 src/usr.bin/cdplay/cdplay.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/cdplay/cdplay.1
diff -u src/usr.bin/cdplay/cdplay.1:1.23 src/usr.bin/cdplay/cdplay.1:1.24
--- src/usr.bin/cdplay/cdplay.1:1.23	Sat Nov 26 23:20:41 2011
+++ src/usr.bin/cdplay/cdplay.1	Wed Jan  4 17:26:21 2012
@@ -1,4 +1,4 @@
-.\"	$NetBSD: cdplay.1,v 1.23 2011/11/26 23:20:41 christos Exp $
+.\"	$NetBSD: cdplay.1,v 1.24 2012/01/04 17:26:21 drochner Exp $
 .\"
 .\" Copyright (c) 1999, 2000 Andrew Doran.
 .\" All rights reserved.
@@ -26,7 +26,7 @@
 .\"
 .\" from FreeBSD: cdcontrol.1,v 1.16.2.2 1999/01/31 15:36:01 billf Exp
 .\"
-.Dd November 26, 2011
+.Dd January 3, 2012
 .Dt CDPLAY 1
 .Os
 .Sh NAME
@@ -57,6 +57,12 @@ and
 will be tried (in this order) to find the device; as a last resort,
 .Pa /dev/sound
 will be used.
+If the
+.Dq Fl a
+command line option is used, or the
+.Ev CDPLAY_DIGITAL
+environment variable is present,
+digital transfer mode is switched on automatically.
 .It Fl f Ar device
 Specify the control device to use.
 Both absolute paths and paths relative to

Index: src/usr.bin/cdplay/cdplay.c
diff -u src/usr.bin/cdplay/cdplay.c:1.45 src/usr.bin/cdplay/cdplay.c:1.46
--- src/usr.bin/cdplay/cdplay.c:1.45	Wed Jan  4 17:07:20 2012
+++ src/usr.bin/cdplay/cdplay.c	Wed Jan  4 17:26:21 2012
@@ -1,4 +1,4 @@
-/* 	$NetBSD: cdplay.c,v 1.45 2012/01/04 17:07:20 drochner Exp $	*/
+/* 	$NetBSD: cdplay.c,v 1.46 2012/01/04 17:26:21 drochner Exp $	*/
 
 /*
  * Copyright (c) 1999, 2000, 2001 Andrew Doran.
@@ -40,7 +40,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: cdplay.c,v 1.45 2012/01/04 17:07:20 drochner Exp $");
+__RCSID("$NetBSD: cdplay.c,v 1.46 2012/01/04 17:26:21 drochner Exp $");
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -204,6 +204,7 @@ main(int argc, char **argv)
 	const char *elline;
 	int scratch, rv;
 	struct sigaction sa_timer;
+	const char *use_digital = NULL; /* historical default */
 
 	cdname = getenv("MUSIC_CD");
 	if (cdname == NULL)
@@ -219,10 +220,14 @@ main(int argc, char **argv)
 	if (!da.auname)
 		da.auname = "/dev/sound";
 
+	use_digital = getenv("CDPLAY_DIGITAL");
+
 	while ((c = getopt(argc, argv, "a:f:h")) != -1)
 		switch (c) {
 		case 'a':
 			da.auname = optarg;
+			if (!use_digital)
+				use_digital = "";
 			continue;
 		case 'f':
 			cdname = optarg;
@@ -247,6 +252,15 @@ main(int argc, char **argv)
 	opencd();
 	da.afd = -1;
 
+	sigemptyset(&sa_timer.sa_mask);
+	sa_timer.sa_handler = sig_timer;
+	sa_timer.sa_flags = SA_RESTART;
+	if ((rv = sigaction(SIGALRM, &sa_timer, NULL)) < 0)
+		err(EXIT_FAILURE, "sigaction()");
+
+	if (use_digital)
+		start_digital(use_digital);
+
 	if (argc > 0) {
 		interactive = 0;
 		for (p = buf; argc-- > 0; argv++) {
@@ -277,12 +291,6 @@ main(int argc, char **argv)
 	el_set(elptr, EL_SIGNAL, 1);
 	el_source(elptr, NULL);
 
-	sigemptyset(&sa_timer.sa_mask);
-	sa_timer.sa_handler = sig_timer;
-	sa_timer.sa_flags = SA_RESTART;
-	if ((rv = sigaction(SIGALRM, &sa_timer, NULL)) < 0)
-		err(EXIT_FAILURE, "sigaction()");
-
 	for (;;) {
 		line = NULL;
 		arg = NULL;
@@ -1131,7 +1139,7 @@ play_track(int tstart, int istart, int t
 
 	if ((rv = ioctl(fd, CDIOCPLAYTRACKS, &t)) < 0) {
 		int oerrno = errno;
-		if (errno == EINVAL && start_digital("5") == 0)
+		if (errno == EINVAL && start_digital("") == 0)
 			return play_track(tstart, istart, tend, iend);
 		errno = oerrno;
 		warn("ioctl(CDIOCPLAYTRACKS)");
@@ -1159,6 +1167,9 @@ play_digital(int start, int end)
 	da.lba_start = start;
 	da.lba_end = --end;
 	da.changed = da.playing = 1;
+	if (!interactive)
+		while (da.playing)
+			sleep(1);
 	return (0);
 }
 

Reply via email to