Aplay Fails When Reading From stdin
I recently updated may alsa from 1.1.4.1 to 1.1.6. I now noticed that aplay does not work properly (the same as 1.1.4.1) when reading the sound file data from stdin. This might have something to do with the recent change with reading the sound file header.
With the previous version of aplay, aplay would report:
Playing WAVE 'stdin' : Signed 16 bit Little Endian, Rate 22050 Hz, Mono
With 1.1.6, aplay reports:
Playing raw data 'stdin' : Unsigned 8 bit, Rate 8000 Hz, Mono
This results in static/noise output. If I explicitly add the '-f S16_LE -r 22050' options to aplay, then it does play correctly.
Is this a known bug and is there a fix?
Jay
Quoted 10 lines · Jay Foster
I recently updated may alsa from 1.1.4.1 to 1.1.6. I now noticed that aplay does not work properly (the same as 1.1.4.1) when reading the sound file data from stdin. This might have something to do with the recent change with reading the sound file header.
With the previous version of aplay, aplay would report:
Playing WAVE 'stdin' : Signed 16 bit Little Endian, Rate 22050 Hz, Mono
Quoted 8 lines
With 1.1.6, aplay reports:
Playing raw data 'stdin' : Unsigned 8 bit, Rate 8000 Hz, Mono
This results in static/noise output. If I explicitly add the '-f
S16_LE-r 22050' options to aplay, then it does play correctly.Is this a known bug and is there a fix?
It works fine on my system.
% aplay test.wav
Playing WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
% aplay < ~/test/test.wav
Playing WAVE 'stdin' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
% aplay --version
aplay: version 1.1.6 by Jaroslav Kysela <[email protected]>
Takashi
Quoted 24 lines · Takashi Iwai
Quoted 9 lines · Jay Foster
I recently updated may alsa from 1.1.4.1 to 1.1.6. I now noticed that aplay does not work properly (the same as 1.1.4.1) when reading the sound file data from stdin. This might have something to do with the recent change with reading the sound file header.
With the previous version of aplay, aplay would report:
Playing WAVE 'stdin' : Signed 16 bit Little Endian, Rate 22050 Hz, Mono
Quoted 8 lines
With 1.1.6, aplay reports:
Playing raw data 'stdin' : Unsigned 8 bit, Rate 8000 Hz, Mono
This results in static/noise output. If I explicitly add the '-f
S16_LE-r 22050' options to aplay, then it does play correctly.Is this a known bug and is there a fix?
It works fine on my system.
% aplay test.wav
Playing WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
Quoted 10 lines
% aplay < ~/test/test.wav
Playing WAVE 'stdin' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo% aplay --version
aplay: version 1.1.6 by Jaroslav Kysela <[email protected]>Takashi
Well, it does not work for me:
cat bird-calls.wav | /usr/bin/aplay -Dplughw:0 -- Playing raw data 'stdin' : Unsigned 8 bit, Rate 8000 Hz, Mono ^CAborted by signal Interrupt...
aplay: pcm_write:2051: write error: Interrupted system call
aplay -Dplughw:0 bird-calls.wav
Playing WAVE 'bird-calls.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
Looks like aplay may now have problems reading from stdin if stdin is a pipe.
Jay
Quoted 45 lines · Jay Foster
Quoted 24 lines · Takashi Iwai
Quoted 9 lines · Jay Foster
I recently updated may alsa from 1.1.4.1 to 1.1.6. I now noticed that aplay does not work properly (the same as 1.1.4.1) when reading the sound file data from stdin. This might have something to do with the recent change with reading the sound file header.
With the previous version of aplay, aplay would report:
Playing WAVE 'stdin' : Signed 16 bit Little Endian, Rate 22050 Hz, Mono
Quoted 8 lines
With 1.1.6, aplay reports:
Playing raw data 'stdin' : Unsigned 8 bit, Rate 8000 Hz, Mono
This results in static/noise output. If I explicitly add the '-f
S16_LE-r 22050' options to aplay, then it does play correctly.Is this a known bug and is there a fix?
It works fine on my system.
% aplay test.wav
Playing WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, StereoQuoted 10 lines
% aplay < ~/test/test.wav
Playing WAVE 'stdin' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo% aplay --version
aplay: version 1.1.6 by Jaroslav Kysela <[email protected]>Takashi
Well, it does not work for me:
cat bird-calls.wav |
/usr/bin/aplay-Dplughw:0 -- Playing raw data 'stdin' : Unsigned 8 bit, Rate 8000 Hz, Mono ^CAborted by signal Interrupt...
aplay: pcm_write:2051: write error: Interrupted system call
Quoted 6 lines
aplay -Dplughw:0 bird-calls.wav
Playing WAVE 'bird-calls.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, StereoLooks like aplay may now have problems reading from stdin if stdin is a pipe.
OK, now I see it. It's in the safety check of file stat. The fix patch is below.
thanks,
Takashi
---
aplay/aplay.c +20 -17
@@ -2808,7 +2808,7 @@ static void playback_go(int fd, size_t loaded, off64_t count, int rtype, char *nsnd_pcm_nonblock (handle, nonblock); } -static int read_header (int *loaded,int header_size) +static int read_header (int *loaded,int header_size,int is_stdin) {int ret;struct stat buf;
@@ -2821,7 +2821,7 @@ static int read_header(int *loaded, int header_size)/* don't be adventurous, get out if file size is smaller than * requested header size */ -if (buf.st_size < header_size) +if (!is_stdin && buf.st_size < header_size)return -1 ;if (*loaded < header_size) {
@@ -2836,9 +2836,9 @@ static int read_header(int *loaded, int header_size)return 0 ; } -static int playback_au (char *name,int *loaded) +static int playback_au (char *name,int *loaded,int is_stdin) { -if (read_header (loaded,sizeof (AuHeader)) <0 ) +if (read_header (loaded,sizeof (AuHeader), is_stdin) <0 )return -1 ;if (test_au (fd, audiobuf) <0 )
@@ -2851,11 +2851,11 @@ static int playback_au(char *name, int *loaded)return 0 ; } -static int playback_voc (char *name,int *loaded) +static int playback_voc (char *name,int *loaded,int is_stdin) {int ofs; -if (read_header (loaded,sizeof (VocHeader)) <0 ) +if (read_header (loaded,sizeof (VocHeader), is_stdin) <0 )return -1 ;if ((ofs =test_vocfile (audiobuf)) <0 )
@@ -2867,11 +2867,11 @@ static int playback_voc(char *name, int *loaded)return 0 ; } -static int playback_wave (char *name,int *loaded) +static int playback_wave (char *name,int *loaded,int is_stdin) {ssize_t dtawave; -if (read_header (loaded,sizeof (WaveHeader)) <0 ) +if (read_header (loaded,sizeof (WaveHeader), is_stdin) <0 )return -1 ;if ((dtawave =test_wavefile (fd, audiobuf, *loaded)) <0 )
@@ -2883,7 +2883,7 @@ static int playback_wave(char *name, int *loaded)return 0 ; } -static int playback_raw (char *name,int *loaded) +static int playback_raw (char *name,int *loaded,int is_stdin) {init_raw_data (); pbrec_count =calc_count ();
@@ -2899,13 +2899,16 @@ static int playback_raw(char *name, int *loaded)static void playback (char *name) {int loaded =0 ; +int is_stdin; pbrec_count =LLONG_MAX ; fdcount =0 ;if (!name || !strcmp (name,"-" )) { + is_stdin =1 ; fd =fileno (stdin); name ="stdin" ; }else { + is_stdin =0 ;init_stdin ();if ((fd =open (name,O_RDONLY ,0 )) ==-1 ) {perror (name);
@@ -2915,23 +2918,23 @@ static void playback(char *name)switch (file_type) {case FORMAT_AU : -playback_au (name, &loaded); +playback_au (name, &loaded, is_stdin);break ;case FORMAT_VOC : -playback_voc (name, &loaded); +playback_voc (name, &loaded, is_stdin);break ;case FORMAT_WAVE : -playback_wave (name, &loaded); +playback_wave (name, &loaded, is_stdin);break ;case FORMAT_RAW : -playback_raw (name, &loaded); +playback_raw (name, &loaded, is_stdin);break ;default :/* parse the file header */ -if (playback_au (name, &loaded) <0 && -playback_voc (name, &loaded) <0 && -playback_wave (name, &loaded) <0 ) -playback_raw (name, &loaded);/* should be raw data */ +if (playback_au (name, &loaded, is_stdin) <0 && +playback_voc (name, &loaded, is_stdin) <0 && +playback_wave (name, &loaded, is_stdin) <0 ) +playback_raw (name, &loaded, is_stdin);/* should be raw data */ break ; }
Quoted 173 lines · Takashi Iwai
Quoted 44 lines · Jay Foster
Quoted 24 lines · Takashi Iwai
Quoted 9 lines · Jay Foster
I recently updated may alsa from 1.1.4.1 to 1.1.6. I now noticed that aplay does not work properly (the same as 1.1.4.1) when reading the sound file data from stdin. This might have something to do with the recent change with reading the sound file header.
With the previous version of aplay, aplay would report:
Playing WAVE 'stdin' : Signed 16 bit Little Endian, Rate 22050 Hz, Mono
Quoted 8 lines
With 1.1.6, aplay reports:
Playing raw data 'stdin' : Unsigned 8 bit, Rate 8000 Hz, Mono
This results in static/noise output. If I explicitly add the '-f
S16_LE-r 22050' options to aplay, then it does play correctly.Is this a known bug and is there a fix?
It works fine on my system.
% aplay test.wav
Playing WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, StereoQuoted 10 lines
% aplay < ~/test/test.wav
Playing WAVE 'stdin' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo% aplay --version
aplay: version 1.1.6 by Jaroslav Kysela <[email protected]>Takashi
Well, it does not work for me:
cat bird-calls.wav |
/usr/bin/aplay-Dplughw:0 -- Playing raw data 'stdin' : Unsigned 8 bit, Rate 8000 Hz, Mono ^CAborted by signal Interrupt...
aplay: pcm_write:2051: write error: Interrupted system callQuoted 6 lines
aplay -Dplughw:0 bird-calls.wav
Playing WAVE 'bird-calls.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, StereoLooks like aplay may now have problems reading from stdin if stdin is a pipe.
OK, now I see it. It's in the safety check of file stat. The fix patch is below.
thanks,
Takashi
---
aplay/aplay.c +16
-14@@ -2808,7 +2808,7 @@ static void playback_go(int fd, size_t loaded, off64_t count, int rtype, char *nsnd_pcm_nonblock (handle, nonblock); } -static int read_header (int *loaded,int header_size) +static int read_header (int *loaded,int header_size,int is_stdin) {int ret;struct stat buf;@@ -2821,7 +2821,7 @@ static int read_header(int *loaded, int header_size)/* don't be adventurous, get out if file size is smaller than * requested header size */ -if (buf.st_size < header_size) +if (!is_stdin && buf.st_size < header_size)return -1 ;if (*loaded < header_size) {@@ -2836,9 +2836,9 @@ static int read_header(int *loaded, int header_size)return 0 ; } -static int playback_au (char *name,int *loaded) +static int playback_au (char *name,int *loaded,int is_stdin) { -if (read_header (loaded,sizeof (AuHeader)) <0 ) +if (read_header (loaded,sizeof (AuHeader), is_stdin) <0 )return -1 ;if (test_au (fd, audiobuf) <0 )@@ -2851,11 +2851,11 @@ static int playback_au(char *name, int *loaded)return 0 ; } -static int playback_voc (char *name,int *loaded) +static int playback_voc (char *name,int *loaded,int is_stdin) {int ofs; -if (read_header (loaded,sizeof (VocHeader)) <0 ) +if (read_header (loaded,sizeof (VocHeader), is_stdin) <0 )return -1 ;if ((ofs =test_vocfile (audiobuf)) <0 )@@ -2867,11 +2867,11 @@ static int playback_voc(char *name, int *loaded)return 0 ; } -static int playback_wave (char *name,int *loaded) +static int playback_wave (char *name,int *loaded,int is_stdin) {ssize_t dtawave; -if (read_header (loaded,sizeof (WaveHeader)) <0 ) +if (read_header (loaded,sizeof (WaveHeader), is_stdin) <0 )return -1 ;if ((dtawave =test_wavefile (fd, audiobuf, *loaded)) <0 )@@ -2883,7 +2883,7 @@ static int playback_wave(char *name, int *loaded)return 0 ; } -static int playback_raw (char *name,int *loaded) +static int playback_raw (char *name,int *loaded,int is_stdin) {init_raw_data (); pbrec_count =calc_count ();@@ -2899,13 +2899,16 @@ static int playback_raw(char *name, int *loaded)static void playback (char *name) {int loaded =0 ; +int is_stdin; pbrec_count =LLONG_MAX ; fdcount =0 ;if (!name || !strcmp (name,"-" )) { + is_stdin =1 ; fd =fileno (stdin); name ="stdin" ; }else { + is_stdin =0 ;init_stdin ();if ((fd =open (name,O_RDONLY ,0 )) ==-1 ) {perror (name);@@ -2915,23 +2918,23 @@ static void playback(char *name)switch (file_type) {case FORMAT_AU : -playback_au (name, &loaded); +playback_au (name, &loaded, is_stdin);break ;case FORMAT_VOC : -playback_voc (name, &loaded); +playback_voc (name, &loaded, is_stdin);break ;case FORMAT_WAVE : -playback_wave (name, &loaded); +playback_wave (name, &loaded, is_stdin);break ;case FORMAT_RAW : -playback_raw (name, &loaded); +playback_raw (name, &loaded, is_stdin);break ;default :/* parse the file header */ - if (playback_au(name, &loaded) < 0 &&
aplay/aplay.c static void playback(char *name) · line 2940
Quoted 10 lines
aplay/aplay.c +4
-3- playback_voc(name, &loaded) < 0 && - playback_wave(name, &loaded) < 0) -playback_raw (name, &loaded);/* should be raw data */ +if (playback_au (name, &loaded, is_stdin) <0 && +playback_voc (name, &loaded, is_stdin) <0 && +playback_wave (name, &loaded, is_stdin) <0 ) +playback_raw (name, &loaded, is_stdin);/* should be raw data */ break ; }
Thanks. That works.
Jay
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Quoted 54 lines · Jay Foster
Quoted 50 lines · Takashi Iwai
Quoted 48 lines · Jay Foster
Quoted 24 lines · Takashi Iwai
Quoted 9 lines · Jay Foster
I recently updated may alsa from 1.1.4.1 to 1.1.6. I now noticed that aplay does not work properly (the same as 1.1.4.1) when reading the sound file data from stdin. This might have something to do with the recent change with reading the sound file header.
With the previous version of aplay, aplay would report:
Playing WAVE 'stdin' : Signed 16 bit Little Endian, Rate 22050 Hz, Mono
Quoted 8 lines
With 1.1.6, aplay reports:
Playing raw data 'stdin' : Unsigned 8 bit, Rate 8000 Hz, Mono
This results in static/noise output. If I explicitly add the '-f
S16_LE-r 22050' options to aplay, then it does play correctly.Is this a known bug and is there a fix?
It works fine on my system.
% aplay test.wav
Playing WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, StereoQuoted 10 lines
% aplay < ~/test/test.wav
Playing WAVE 'stdin' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo% aplay --version
aplay: version 1.1.6 by Jaroslav Kysela <[email protected]>Takashi
Well, it does not work for me:
cat bird-calls.wav |
/usr/bin/aplay-Dplughw:0 -- Playing raw data 'stdin' : Unsigned 8 bit, Rate 8000 Hz, Mono ^CAborted by signal Interrupt...
aplay: pcm_write:2051: write error: Interrupted system callaplay -Dplughw:0 bird-calls.wav
Playing WAVE 'bird-calls.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines
Looks like aplay may now have problems reading from stdin if stdin is a pipe.
OK, now I see it. It's in the safety check of file stat. The fix patch is below.
Thanks. That works.
Actually the fix below would be much simpler and better. I'm going to apply it.
Takashi
-- 8< --
From: Takashi Iwai <[email protected]>
Subject: [PATCH] aplay: Fix invalid file size check for non-regular files
aplay tries to check the file size via fstat() at parsing the format headers and avoids parsing when the size is shorter than the given size. This works fine for regular files, but when a special file like pipe is passed, it fails, eventually leading to the fallback mode wrongly.
A proper fix is to do this sanity check only for a regular file.
--- aplay/aplay.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
aplay/aplay.c +2 -1
@@ -2821,7 +2821,8 @@ static int read_header(int *loaded, int header_size)/* don't be adventurous, get out if file size is smaller than * requested header size */ -if (buf.st_size < header_size) +if ((buf.st_mode &S_IFMT ) ==S_IFREG && + buf.st_size < header_size)return -1 ;if (*loaded < header_size) {
Signature · 6 lines
2.16.3 _______________________________________________ Alsa-devel mailing list [email protected] http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Quoted 89 lines · Takashi Iwai
Quoted 52 lines · Jay Foster
Quoted 49 lines · Takashi Iwai
Quoted 47 lines · Jay Foster
Quoted 24 lines · Takashi Iwai
Quoted 9 lines · Jay Foster
I recently updated may alsa from 1.1.4.1 to 1.1.6. I now noticed that aplay does not work properly (the same as 1.1.4.1) when reading the sound file data from stdin. This might have something to do with the recent change with reading the sound file header.
With the previous version of aplay, aplay would report:
Playing WAVE 'stdin' : Signed 16 bit Little Endian, Rate 22050 Hz, Mono
Quoted 8 lines
With 1.1.6, aplay reports:
Playing raw data 'stdin' : Unsigned 8 bit, Rate 8000 Hz, Mono
This results in static/noise output. If I explicitly add the '-f
S16_LE-r 22050' options to aplay, then it does play correctly.Is this a known bug and is there a fix?
It works fine on my system.
% aplay test.wav
Playing WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, StereoQuoted 10 lines
% aplay < ~/test/test.wav
Playing WAVE 'stdin' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo% aplay --version
aplay: version 1.1.6 by Jaroslav Kysela <[email protected]>Takashi
Well, it does not work for me:
cat bird-calls.wav |
/usr/bin/aplay-Dplughw:0 -- Playing raw data 'stdin' : Unsigned 8 bit, Rate 8000 Hz, Mono ^CAborted by signal Interrupt...
aplay: pcm_write:2051: write error: Interrupted system callaplay -Dplughw:0 bird-calls.wav
Playing WAVE 'bird-calls.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, StereoQuoted 6 lines
Quoted 5 lines
Quoted 2 lines
Looks like aplay may now have problems reading from stdin if stdin is a pipe.
OK, now I see it. It's in the safety check of file stat. The fix patch is below.
Thanks. That works.
Actually the fix below would be much simpler and better. I'm going to apply it.
Takashi
-- 8< --
From: Takashi Iwai <[email protected]>
Subject: [PATCH] aplay: Fix invalid file size check for non-regular filesaplay tries to check the file size via
fstat()at parsing the format headers and avoids parsing when the size is shorter than the given size. This works fine for regular files, but when a special file like pipe is passed, it fails, eventually leading to the fallback mode wrongly.A proper fix is to do this sanity check only for a regular file.
Reported-by Jay Foster <[email protected]>Signed-off-by Takashi Iwai <[email protected]>--- aplay/aplay.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)aplay/aplay.c +0
-0
aplay/aplay.c static int read_header(int *loaded, int header_size) · line 2828
Quoted 9 lines
aplay/aplay.c +2
-1@@ -2821,7 +2821,8 @@ static int read_header(int *loaded, int header_size)/* don't be adventurous, get out if file size is smaller than * requested header size */ -if (buf.st_size < header_size) +if ((buf.st_mode &S_IFMT ) ==S_IFREG && + buf.st_size < header_size)return -1 ;if (*loaded < header_size) {
Thanks. Your new patch also works.
Jay
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel