wav: try to read as much PCM data as possible
authorKostya Shishkov <kostya.shishkov@gmail.com>
Fri, 25 Aug 2023 16:55:42 +0000 (18:55 +0200)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Fri, 25 Aug 2023 16:55:42 +0000 (18:55 +0200)
Otherwise read_buf_some() may return random small buffer size that
is not even aligned to the sample size.

nihav-commonfmt/src/demuxers/wav.rs

index 90196177322731c8ae9986d8e5f3987c3ac61b09..193623eea2f3c72359fd236ddf215fac329dcbcc 100644 (file)
@@ -103,8 +103,14 @@ impl<'a> DemuxCore<'a> for WAVDemuxer<'a> {
                     bsize
                 };
             let mut buf = vec![0; bsize];
-            let size                    = self.src.read_buf_some(buf.as_mut_slice())?;
-            buf.truncate(size);
+            let mut tot_size = 0;
+            while let Ok(psize)         = self.src.read_buf_some(&mut buf[tot_size..]) {
+                tot_size += psize;
+                if tot_size == buf.len() {
+                    break;
+                }
+            }
+            buf.truncate(tot_size);
             Ok(NAPacket::new(stream, ts, true, buf))
         } else {
             self.src.read_packet(stream, ts, true, self.block_size)