From patchwork Sat May 5 06:51:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 10381995 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C08FA60467 for ; Sat, 5 May 2018 06:52:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B116D294E1 for ; Sat, 5 May 2018 06:52:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A5392295AD; Sat, 5 May 2018 06:52:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7403C294E1 for ; Sat, 5 May 2018 06:52:10 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 41CC42675CD; Sat, 5 May 2018 08:52:08 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 7FC132675D3; Sat, 5 May 2018 08:51:55 +0200 (CEST) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by alsa0.perex.cz (Postfix) with ESMTP id 7F67E26728A for ; Sat, 5 May 2018 08:51:46 +0200 (CEST) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 0F06DAF08; Sat, 5 May 2018 06:51:45 +0000 (UTC) Date: Sat, 05 May 2018 08:51:44 +0200 Message-ID: From: Takashi Iwai To: jay@systech.com In-Reply-To: <399d9244-ae31-84c0-d587-bc62707a873f@systech.com> References: <8c51a51a-cfa0-e1a7-0682-8f3c13ddc2a7@systech.com> <399d9244-ae31-84c0-d587-bc62707a873f@systech.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Cc: alsa-devel@alsa-project.org Subject: Re: [alsa-devel] Aplay Fails When Reading From stdin X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP On Fri, 04 May 2018 21:57:35 +0200, Jay Foster wrote: > > > > On 5/4/2018 12:47 PM, Takashi Iwai wrote: > > On Fri, 04 May 2018 19:51:05 +0200, > > Jay Foster wrote: > >> 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? > > 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 > > > > > > 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. OK, now I see it. It's in the safety check of file stat. The fix patch is below. thanks, Takashi diff --git a/aplay/aplay.c b/aplay/aplay.c index bbd7fffa04fc..2a851a73ba6e 100644 --- a/aplay/aplay.c +++ b/aplay/aplay.c @@ -2808,7 +2808,7 @@ static void playback_go(int fd, size_t loaded, off64_t count, int rtype, char *n snd_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; }