From f80d9ab996334eca46048c2ee25c51e52d7fef7f Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Fri, 25 Aug 2023 18:55:42 +0200 Subject: [PATCH] wav: try to read as much PCM data as possible 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 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/nihav-commonfmt/src/demuxers/wav.rs b/nihav-commonfmt/src/demuxers/wav.rs index 9019617..193623e 100644 --- a/nihav-commonfmt/src/demuxers/wav.rs +++ b/nihav-commonfmt/src/demuxers/wav.rs @@ -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) -- 2.39.5