Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-1-5]: src/usr.bin/audio/play Pull up revision 1.23 (via patch, re...
details: https://anonhg.NetBSD.org/src/rev/8eda80a715ae
branches: netbsd-1-5
changeset: 490834:8eda80a715ae
user: he <he%NetBSD.org@localhost>
date: Sun Mar 11 21:30:28 2001 +0000
description:
Pull up revision 1.23 (via patch, requested by hubertf):
Do not play trailing garbage at the end of RIFF WAVE (.wav) files.
Fixes PR#12328.
diffstat:
usr.bin/audio/play/play.c | 54 +++++++++++++++++++++++++++++++---------------
1 files changed, 36 insertions(+), 18 deletions(-)
diffs (139 lines):
diff -r 9ae291541e99 -r 8eda80a715ae usr.bin/audio/play/play.c
--- a/usr.bin/audio/play/play.c Sun Mar 11 21:30:08 2001 +0000
+++ b/usr.bin/audio/play/play.c Sun Mar 11 21:30:28 2001 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: play.c,v 1.17 2000/02/27 08:20:01 mrg Exp $ */
+/* $NetBSD: play.c,v 1.17.4.1 2001/03/11 21:30:28 he Exp $ */
/*
* Copyright (c) 1999 Matthew R. Green
@@ -48,7 +48,7 @@
int main __P((int, char *[]));
void usage __P((void));
void play_fd __P((int, char *));
-ssize_t audioctl_write_fromhdr __P((void *, size_t, int));
+ssize_t audioctl_write_fromhdr __P((void *, size_t, int, size_t *));
audio_info_t info;
int volume;
@@ -65,6 +65,7 @@
char const *play_errstring = NULL;
size_t bufsize;
int audiofd, ctlfd;
+size_t datasize;
int
main(argc, argv)
@@ -229,7 +230,7 @@
* get the header length and set up the audio device
*/
if ((hdrlen = audioctl_write_fromhdr(addr,
- (size_t)filesize, ctlfd)) < 0) {
+ (size_t)filesize, ctlfd, &datasize)) < 0) {
if (play_errstring)
errx(1, "%s: %s", play_errstring, *argv);
else
@@ -238,14 +239,18 @@
filesize -= hdrlen;
addr = (char *)addr + hdrlen;
+ if (filesize < datasize || datasize == 0) {
+ warn("bogus datasize:%u", datasize);
+ datasize = filesize;
+ }
- while (filesize > bufsize) {
+ while (datasize > bufsize) {
if (write(audiofd, addr, bufsize) != bufsize)
err(1, "write failed");
addr = (char *)addr + bufsize;
- filesize -= bufsize;
+ datasize -= bufsize;
}
- if (write(audiofd, addr, (size_t)filesize) != (ssize_t)filesize)
+ if (write(audiofd, addr, (size_t)datasize) != (ssize_t)datasize)
err(1, "final write failed");
if (ioctl(audiofd, AUDIO_DRAIN) < 0 && !qflag)
@@ -273,7 +278,9 @@
{
char *buffer = malloc(bufsize);
ssize_t hdrlen;
- int n, m;
+ int n;
+ size_t datasize;
+ size_t datainbuf;
if (buffer == NULL)
err(1, "malloc of read buffer failed");
@@ -285,7 +292,7 @@
if (n == 0)
errx(1, "EOF on standard input");
- hdrlen = audioctl_write_fromhdr(buffer, n, ctlfd);
+ hdrlen = audioctl_write_fromhdr(buffer, n, ctlfd, &datasize);
if (hdrlen < 0) {
if (play_errstring)
errx(1, "%s: %s", play_errstring, file);
@@ -300,17 +307,26 @@
err(1, "bogus hdrlen %d > length %d?", (int)hdrlen, n);
memmove(buffer, buffer + hdrlen, n - hdrlen);
+ }
- m = read(fd, buffer + n, hdrlen);
- n += m;
- }
- /* read until EOF or error */
+ datainbuf = n;
do {
- if (n == -1)
- err(1, "read of standard input failed");
- if (write(audiofd, buffer, n) != n)
+ if (datasize < datainbuf) {
+ datainbuf = datasize;
+ }
+ else {
+ n = read(fd, buffer + datainbuf, MIN(bufsize - datainbuf, datasize));
+ if (n == -1)
+ err(1, "read of %s failed", file);
+ datainbuf += n;
+ }
+ if (write(audiofd, buffer, datainbuf) != datainbuf)
err(1, "write failed");
- } while ((n = read(fd, buffer, bufsize)));
+
+ datasize -= datainbuf;
+ datainbuf = 0;
+ }
+ while (datasize);
if (ioctl(audiofd, AUDIO_DRAIN) < 0 && !qflag)
warn("audio drain ioctl failed");
@@ -323,10 +339,11 @@
* uses the local "info" variable. blah... fix me!
*/
ssize_t
-audioctl_write_fromhdr(hdr, fsz, fd)
+audioctl_write_fromhdr(hdr, fsz, fd, datasize)
void *hdr;
size_t fsz;
int fd;
+ size_t *datasize;
{
sun_audioheader *sunhdr;
ssize_t hdr_len;
@@ -347,11 +364,12 @@
info.play.channels = ntohl(sunhdr->channels);
hdr_len = ntohl(sunhdr->hdr_size);
+ *datasize = ntohl(sunhdr->data_size);
goto set_audio_mode;
}
hdr_len = audio_parse_wav_hdr(hdr, fsz, &info.play.encoding,
- &info.play.precision, &info.play.sample_rate, &info.play.channels);
+ &info.play.precision, &info.play.sample_rate, &info.play.channels, datasize);
switch (hdr_len) {
case AUDIO_ESHORTHDR:
Home |
Main Index |
Thread Index |
Old Index