mirror of
https://github.com/samsonjs/media.git
synced 2026-04-10 12:05:47 +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();
|
||||
}
|
||||
BaseMediaChunk currentChunk = mediaChunks.getFirst();
|
||||
Format currentFormat = currentChunk.format;
|
||||
if (downstreamFormat == null || !downstreamFormat.equals(currentFormat)) {
|
||||
eventDispatcher.downstreamFormatChanged(currentFormat, currentChunk.trigger,
|
||||
|
||||
Format format = currentChunk.format;
|
||||
if (!format.equals(downstreamFormat)) {
|
||||
eventDispatcher.downstreamFormatChanged(format, currentChunk.trigger,
|
||||
currentChunk.startTimeUs);
|
||||
downstreamFormat = currentFormat;
|
||||
}
|
||||
downstreamFormat = format;
|
||||
|
||||
int result = sampleQueue.readData(formatHolder, buffer, loadingFinished, lastSeekPositionUs);
|
||||
if (result == FORMAT_READ) {
|
||||
|
|
|
|||
|
|
@ -65,18 +65,14 @@ import java.io.IOException;
|
|||
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);
|
||||
if (chunkHeader.id == Util.getIntegerCodeForString("bext")) {
|
||||
while (chunkHeader.id != Util.getIntegerCodeForString("fmt ")) {
|
||||
input.advancePeekPosition((int) chunkHeader.size);
|
||||
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);
|
||||
|
||||
input.peekFully(scratch.data, 0, 16);
|
||||
scratch.setPosition(0);
|
||||
int type = scratch.readLittleEndianUnsignedShort();
|
||||
|
|
@ -88,11 +84,8 @@ import java.io.IOException;
|
|||
|
||||
int expectedBlockAlignment = numChannels * bitsPerSample / 8;
|
||||
if (blockAlignment != expectedBlockAlignment) {
|
||||
throw new ParserException(
|
||||
"Expected WAV block alignment of: "
|
||||
+ expectedBlockAlignment
|
||||
+ "; got: "
|
||||
+ blockAlignment);
|
||||
throw new ParserException("Expected block alignment: " + expectedBlockAlignment + "; got: "
|
||||
+ blockAlignment);
|
||||
}
|
||||
if (bitsPerSample != 16) {
|
||||
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();
|
||||
}
|
||||
HlsMediaChunk currentChunk = mediaChunks.getFirst();
|
||||
Format currentFormat = currentChunk.format;
|
||||
if (downstreamFormat == null || !downstreamFormat.equals(currentFormat)) {
|
||||
eventDispatcher.downstreamFormatChanged(currentFormat, currentChunk.trigger,
|
||||
Format format = currentChunk.format;
|
||||
if (!format.equals(downstreamFormat)) {
|
||||
eventDispatcher.downstreamFormatChanged(format, currentChunk.trigger,
|
||||
currentChunk.startTimeUs);
|
||||
downstreamFormat = currentFormat;
|
||||
}
|
||||
downstreamFormat = format;
|
||||
|
||||
return sampleQueues[group].readData(formatHolder, buffer, loadingFinished, lastSeekPositionUs);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue