Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue where padding was not skipped when reading odd-sized chunks from WAV files #1117

Merged
merged 4 commits into from Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions RELEASENOTES.md
Expand Up @@ -19,6 +19,8 @@
* Add support for composition-level audio effects.
* Track Selection:
* Extractors:
* Fix issue where padding was not skipped when reading odd-sized chunks
from WAV files ([#1117](https://github.com/androidx/media/pull/1117)).
* Audio:
* Allow renderer recovery by disabling offload if audio track fails to
initialize in offload mode.
Expand Down
Expand Up @@ -172,6 +172,12 @@ private static ChunkHeader skipToChunk(
while (chunkHeader.id != chunkId) {
Log.w(TAG, "Ignoring unknown WAV chunk: " + chunkHeader.id);
long bytesToSkip = ChunkHeader.SIZE_IN_BYTES + chunkHeader.size;
// According to the RIFF specification, if a chunk's body size is odd, it's followed by a
// padding byte of value 0. This ensures each chunk occupies an even number of bytes in the
// file. The padding byte isn't included in the size field.
if (chunkHeader.size % 2 != 0) {
bytesToSkip++; // padding present if size is odd, skip it.
}
if (bytesToSkip > Integer.MAX_VALUE) {
throw ParserException.createForUnsupportedContainerFeature(
"Chunk is too large (~2GB+) to skip; id: " + chunkHeader.id);
Expand Down
Expand Up @@ -48,6 +48,15 @@ public void sample_withTrailingBytes_extractsSameData() throws Exception {
simulationConfig);
}

@Test
public void sample_withOddMetadataChunkSize_extractsSameData() throws Exception {
ExtractorAsserts.assertBehavior(
WavExtractor::new,
"media/wav/sample_with_odd_metadata_chunk_size.wav",
new AssertionConfig.Builder().setDumpFilesPrefix("extractordumps/wav/sample.wav").build(),
simulationConfig);
}

@Test
public void sample_imaAdpcm() throws Exception {
ExtractorAsserts.assertBehavior(
Expand Down
Binary file not shown.