Fix wrong RF64 data size and add unit test

This commit is contained in:
Kasem 2021-10-14 19:21:30 -07:00
parent 55a86b8a00
commit 8501e997e0
3 changed files with 13 additions and 4 deletions

View file

@ -48,7 +48,7 @@ import java.io.IOException;
// Allocate a scratch buffer large enough to store the format chunk.
ParsableByteArray scratch = new ParsableByteArray(16);
// Attempt to read the RIFF chunk.
// Attempt to read the RIFF or RF64 chunk.
ChunkHeader chunkHeader = ChunkHeader.peek(input, scratch);
if (chunkHeader.id != WavUtil.RIFF_FOURCC && chunkHeader.id != WavUtil.RF64_FOURCC) {
return null;
@ -117,7 +117,10 @@ import java.io.IOException;
ParsableByteArray scratch = new ParsableByteArray(ChunkHeader.SIZE_IN_BYTES);
// Skip all chunks until we find the data header.
ChunkHeader chunkHeader = ChunkHeader.peek(input, scratch);
// Data size holder. To be determined from data chunk or ds64 chunk in case of RF64.
long dataSize = -1;
while (chunkHeader.id != WavUtil.DATA_FOURCC) {
if (chunkHeader.id != WavUtil.RIFF_FOURCC && chunkHeader.id != WavUtil.FMT_FOURCC) {
Log.w(TAG, "Ignoring unknown WAV chunk: " + chunkHeader.id);
@ -131,9 +134,9 @@ import java.io.IOException;
int ds64Size = (int) chunkHeader.size;
ParsableByteArray ds64Bytes = new ParsableByteArray(ds64Size);
input.peekFully(ds64Bytes.getData(), 0, ds64Size);
// ds64 chunk contains 64bit sizes. From position 12 to 20 is the data size
ds64Bytes.setPosition(12);
dataSize = ds64Bytes.readLong();
// ds64 chunk contains 64bit sizes. From position 8 to 16 is the data size
ds64Bytes.setPosition(8);
dataSize = ds64Bytes.readLittleEndianLong();
}
if (bytesToSkip > Integer.MAX_VALUE) {
throw ParserException.createForUnsupportedContainerFeature(

View file

@ -53,4 +53,10 @@ public final class WavExtractorTest {
ExtractorAsserts.assertBehavior(
WavExtractor::new, "media/wav/sample_ima_adpcm.wav", simulationConfig);
}
@Test
public void sample_RF64() throws Exception {
ExtractorAsserts
.assertBehavior(WavExtractor::new, "media/wav/sample_rf64.wav", simulationConfig);
}
}

Binary file not shown.