mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
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
This commit is contained in:
parent
99c0ba005a
commit
523f2662ef
3 changed files with 13 additions and 19 deletions
|
|
@ -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;
|
||||||
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,11 +84,8 @@ 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: "
|
+ blockAlignment);
|
||||||
+ expectedBlockAlignment
|
|
||||||
+ "; got: "
|
|
||||||
+ blockAlignment);
|
|
||||||
}
|
}
|
||||||
if (bitsPerSample != 16) {
|
if (bitsPerSample != 16) {
|
||||||
Log.e(TAG, "Only 16-bit WAVs are supported; got: " + bitsPerSample);
|
Log.e(TAG, "Only 16-bit WAVs are supported; got: " + bitsPerSample);
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue