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

Add support for RF64 wave files #9543

Merged
merged 4 commits into from
Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add support for RF64 wave files
  • Loading branch information
KasemJaffer committed Oct 7, 2021
commit 55a86b8a00aa8bd57881a94bc98d71a97b7ff08d
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
/** Utilities for handling WAVE files. */
public final class WavUtil {

/** Four character code for "RF64". */
public static final int RF64_FOURCC = 0x52463634;
/** Four character code for "ds64". */
public static final int DS64_FOURCC = 0x64733634;
/** Four character code for "RIFF". */
public static final int RIFF_FOURCC = 0x52494646;
/** Four character code for "WAVE". */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static WavHeader peek(ExtractorInput input) throws IOException {

// Attempt to read the RIFF chunk.
ChunkHeader chunkHeader = ChunkHeader.peek(input, scratch);
if (chunkHeader.id != WavUtil.RIFF_FOURCC) {
if (chunkHeader.id != WavUtil.RIFF_FOURCC && chunkHeader.id != WavUtil.RF64_FOURCC) {
return null;
}

Expand Down Expand Up @@ -117,14 +117,23 @@ public static Pair<Long, Long> skipToData(ExtractorInput input) throws IOExcepti
ParsableByteArray scratch = new ParsableByteArray(ChunkHeader.SIZE_IN_BYTES);
// Skip all chunks until we find the data header.
ChunkHeader chunkHeader = ChunkHeader.peek(input, scratch);
long dataSize = -1;
while (chunkHeader.id != WavUtil.DATA_FOURCC) {
if (chunkHeader.id != WavUtil.RIFF_FOURCC && chunkHeader.id != WavUtil.FMT_FOURCC) {
KasemJaffer marked this conversation as resolved.
Show resolved Hide resolved
Log.w(TAG, "Ignoring unknown WAV chunk: " + chunkHeader.id);
}
long bytesToSkip = ChunkHeader.SIZE_IN_BYTES + chunkHeader.size;
// Override size of RIFF chunk, since it describes its size as the entire file.
if (chunkHeader.id == WavUtil.RIFF_FOURCC) {
// Also, ignore the size of RF64 chunk, since its always going to be 0xFFFFFFFF
if (chunkHeader.id == WavUtil.RIFF_FOURCC || chunkHeader.id == WavUtil.RF64_FOURCC) {
bytesToSkip = ChunkHeader.SIZE_IN_BYTES + 4;
} else if (chunkHeader.id == WavUtil.DS64_FOURCC) {
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();
}
if (bytesToSkip > Integer.MAX_VALUE) {
throw ParserException.createForUnsupportedContainerFeature(
Expand All @@ -133,11 +142,15 @@ public static Pair<Long, Long> skipToData(ExtractorInput input) throws IOExcepti
input.skipFully((int) bytesToSkip);
chunkHeader = ChunkHeader.peek(input, scratch);
}
// Use size from data chunk if it wasn't determined from ds64 chunk
if (dataSize == -1) {
dataSize = chunkHeader.size;
}
// Skip past the "data" header.
input.skipFully(ChunkHeader.SIZE_IN_BYTES);

long dataStartPosition = input.getPosition();
long dataEndPosition = dataStartPosition + chunkHeader.size;
long dataEndPosition = dataStartPosition + dataSize;
long inputLength = input.getLength();
if (inputLength != C.LENGTH_UNSET && dataEndPosition > inputLength) {
Log.w(TAG, "Data exceeds input length: " + dataEndPosition + ", " + inputLength);
Expand Down