]> git.alsa-project.org Git - alsa-utils.git/commitdiff
aplay: Fix playback for small raw files
authorDaniel Baluta <daniel.baluta@gmail.com>
Tue, 8 Aug 2017 22:06:00 +0000 (01:06 +0300)
committerTakashi Iwai <tiwai@suse.de>
Wed, 9 Aug 2017 08:39:36 +0000 (10:39 +0200)
This fixes a bug when trying to play files with size
smaller than maximum supported header size.

Lets have a look at the following example:

$ aplay -s 2 sample.raw

-> playback_go(fd = 10, loaded = 26, count = 2, name="sample.raw")
--> l = loaded = 26
--> c = count - written = 2
--> c -= l = 2 - 26 = -24
---> r = safe_read(fd, audiobuf + 26, -24)
---> r = -1, EXIT_FAILURE

In this case we have already 'loaded' from the input file more
bytes that we need to send to pcm device. So, we need to adjust
the number of bytes loaded and avoid reading a negative number
of bytes.

Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
aplay/aplay.c

index 28da6c53194aa1b4245a6b2bc8f0ae34067eb5ee..0aa1688a6710fda7e4c80a214e1de724ce82d3f9 100644 (file)
@@ -2774,6 +2774,13 @@ static void playback_go(int fd, size_t loaded, off64_t count, int rtype, char *n
                        c = count - written;
                        if (c > chunk_bytes)
                                c = chunk_bytes;
+
+                       /* c < l, there is more data loaded
+                        * then we actually need to write
+                        */
+                       if (c < l)
+                               l = c;
+
                        c -= l;
 
                        if (c == 0)