Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/audio add support to play stdin.



details:   https://anonhg.NetBSD.org/src/rev/67d609c04042
branches:  trunk
changeset: 467677:67d609c04042
user:      mrg <mrg%NetBSD.org@localhost>
date:      Sat Mar 27 05:14:37 1999 +0000

description:
add support to play stdin.

diffstat:

 usr.bin/audio/common/audio.c |   7 +++++--
 usr.bin/audio/play/play.c    |  39 +++++++++++++++++++++++++++++++++++++--
 2 files changed, 42 insertions(+), 4 deletions(-)

diffs (84 lines):

diff -r bfc11632591d -r 67d609c04042 usr.bin/audio/common/audio.c
--- a/usr.bin/audio/common/audio.c      Sat Mar 27 05:13:55 1999 +0000
+++ b/usr.bin/audio/common/audio.c      Sat Mar 27 05:14:37 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: audio.c,v 1.2 1999/03/26 15:46:22 mrg Exp $    */
+/*     $NetBSD: audio.c,v 1.3 1999/03/27 05:14:37 mrg Exp $    */
 
 /*
  * Copyright (c) 1999 Matthew R. Green
@@ -271,10 +271,13 @@
 
        do {
                part = (wav_audioheaderpart *)where;
+#if 0
+printf("part `%c%c%c%c' len = %d\n", part->name[0], part->name[1], part->name[2], part->name[3], getle32(part->len));
+#endif
                where += (getle32(part->len) + 8);
        } while ((char *)where < end && strncmp(part->name, "data", 4));
 
-       if (where <= end) {
+       if ((where - getle32(part->len)) <= end) {
                *channels = getle16(fmt->channels);
                *sample = getle32(fmt->sample_rate);
                *enc = newenc;
diff -r bfc11632591d -r 67d609c04042 usr.bin/audio/play/play.c
--- a/usr.bin/audio/play/play.c Sat Mar 27 05:13:55 1999 +0000
+++ b/usr.bin/audio/play/play.c Sat Mar 27 05:14:37 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: play.c,v 1.3 1999/03/26 15:46:22 mrg Exp $     */
+/*     $NetBSD: play.c,v 1.4 1999/03/27 05:14:38 mrg Exp $     */
 
 /*
  * Copyright (c) 1999 Matthew R. Green
@@ -166,6 +166,7 @@
 
                        if ((hdrlen = audioctl_write_fromhdr(addr,
                            (size_t)filesize, ctlfd, 1)) < 0) {
+play_error:
                                if (play_errstring)
                                        errx(1, "%s: %s", play_errstring, *argv);
                                else
@@ -191,7 +192,41 @@
                        
                } while (*++argv);
        } else {
-               /* ... handle stdin */
+               char    *buffer = malloc(bufsize);
+               int     n, m;
+
+               if (buffer == NULL)
+                       err(1, "malloc of read buffer failed");
+
+               n = read(STDIN_FILENO, buffer, bufsize);
+
+               if (n < 0)
+                       err(1, "read of standard input failed");
+               if (n == 0)
+                       errx(1, "EOF on standard input");
+
+               hdrlen = audioctl_write_fromhdr(buffer, n, ctlfd, 1);
+               if (hdrlen < 0)
+                       goto play_error;
+
+               /* advance the buffer if we have to */
+               if (hdrlen > 0) {
+                       /* shouldn't happen */
+                       if (hdrlen > n)
+                               err(1, "bogus hdrlen %d > length %d?", (int)hdrlen, n);
+
+                       memmove(buffer, buffer + hdrlen, n - hdrlen);
+
+                       m = read(STDIN_FILENO, buffer + n, hdrlen);
+                       n += m;
+               }
+               /* read until EOF or error */
+               do {
+                       if (n == -1)
+                               err(1, "read of standard input failed");
+                       if (write(audiofd, buffer, n) != n)
+                               err(1, "write failed");
+               } while ((n = read(STDIN_FILENO, buffer, bufsize)));
        }
 
        exit(0);



Home | Main Index | Thread Index | Old Index