Commit 523f2662 by olly Committed by Oliver Woodman

Skip arbitrary chunks before WAV fmt chunk.

I've seen a sample that has a LIST chunk prior to fmt. It
seems best just to skip all chunks until the format is
located. As per the RIFF spec:

"Programs must expect (and ignore) any unknown chunks
encountered, as with all RIFF forms."

https://www.aelius.com/njh/wavemetatools/doc/riffmci.pdf
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=121682470
parent 99c0ba00
...@@ -218,12 +218,13 @@ public class ChunkTrackStream implements TrackStream, Loader.Callback { ...@@ -218,12 +218,13 @@ public class ChunkTrackStream implements TrackStream, Loader.Callback {
mediaChunks.removeFirst(); mediaChunks.removeFirst();
} }
BaseMediaChunk currentChunk = mediaChunks.getFirst(); BaseMediaChunk currentChunk = mediaChunks.getFirst();
Format currentFormat = currentChunk.format;
if (downstreamFormat == null || !downstreamFormat.equals(currentFormat)) { Format format = currentChunk.format;
eventDispatcher.downstreamFormatChanged(currentFormat, currentChunk.trigger, if (!format.equals(downstreamFormat)) {
eventDispatcher.downstreamFormatChanged(format, currentChunk.trigger,
currentChunk.startTimeUs); currentChunk.startTimeUs);
downstreamFormat = currentFormat;
} }
downstreamFormat = format;
int result = sampleQueue.readData(formatHolder, buffer, loadingFinished, lastSeekPositionUs); int result = sampleQueue.readData(formatHolder, buffer, loadingFinished, lastSeekPositionUs);
if (result == FORMAT_READ) { if (result == FORMAT_READ) {
......
...@@ -65,18 +65,14 @@ import java.io.IOException; ...@@ -65,18 +65,14 @@ import java.io.IOException;
return null; return null;
} }
// If a bext chunk is present, skip it. Otherwise we expect a format chunk. // Skip chunks until we find the format chunk.
chunkHeader = ChunkHeader.peek(input, scratch); chunkHeader = ChunkHeader.peek(input, scratch);
if (chunkHeader.id == Util.getIntegerCodeForString("bext")) { while (chunkHeader.id != Util.getIntegerCodeForString("fmt ")) {
input.advancePeekPosition((int) chunkHeader.size); input.advancePeekPosition((int) chunkHeader.size);
chunkHeader = ChunkHeader.peek(input, scratch); chunkHeader = ChunkHeader.peek(input, scratch);
} }
if (chunkHeader.id != Util.getIntegerCodeForString("fmt ")) {
throw new ParserException("Expected format chunk; found: " + chunkHeader.id);
}
Assertions.checkState(chunkHeader.size >= 16); Assertions.checkState(chunkHeader.size >= 16);
input.peekFully(scratch.data, 0, 16); input.peekFully(scratch.data, 0, 16);
scratch.setPosition(0); scratch.setPosition(0);
int type = scratch.readLittleEndianUnsignedShort(); int type = scratch.readLittleEndianUnsignedShort();
...@@ -88,10 +84,7 @@ import java.io.IOException; ...@@ -88,10 +84,7 @@ import java.io.IOException;
int expectedBlockAlignment = numChannels * bitsPerSample / 8; int expectedBlockAlignment = numChannels * bitsPerSample / 8;
if (blockAlignment != expectedBlockAlignment) { if (blockAlignment != expectedBlockAlignment) {
throw new ParserException( throw new ParserException("Expected block alignment: " + expectedBlockAlignment + "; got: "
"Expected WAV block alignment of: "
+ expectedBlockAlignment
+ "; got: "
+ blockAlignment); + blockAlignment);
} }
if (bitsPerSample != 16) { if (bitsPerSample != 16) {
......
...@@ -307,12 +307,12 @@ public final class HlsSampleSource implements SampleSource, Loader.Callback { ...@@ -307,12 +307,12 @@ public final class HlsSampleSource implements SampleSource, Loader.Callback {
mediaChunks.removeFirst(); mediaChunks.removeFirst();
} }
HlsMediaChunk currentChunk = mediaChunks.getFirst(); HlsMediaChunk currentChunk = mediaChunks.getFirst();
Format currentFormat = currentChunk.format; Format format = currentChunk.format;
if (downstreamFormat == null || !downstreamFormat.equals(currentFormat)) { if (!format.equals(downstreamFormat)) {
eventDispatcher.downstreamFormatChanged(currentFormat, currentChunk.trigger, eventDispatcher.downstreamFormatChanged(format, currentChunk.trigger,
currentChunk.startTimeUs); currentChunk.startTimeUs);
downstreamFormat = currentFormat;
} }
downstreamFormat = format;
return sampleQueues[group].readData(formatHolder, buffer, loadingFinished, lastSeekPositionUs); return sampleQueues[group].readData(formatHolder, buffer, loadingFinished, lastSeekPositionUs);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment