Java Code Examples for com.google.android.exoplayer2.audio.WavUtil#DATA_FOURCC

The following examples show how to use com.google.android.exoplayer2.audio.WavUtil#DATA_FOURCC . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WavHeaderReader.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * Skips to the data in the given WAV input stream. After calling, the input stream's position
 * will point to the start of sample data in the WAV, and the data bounds of the provided {@link
 * WavHeader} will have been set.
 *
 * <p>If an exception is thrown, the input position will be left pointing to a chunk header and
 * the bounds of the provided {@link WavHeader} will not have been set.
 *
 * @param input Input stream to skip to the data chunk in. Its peek position must be pointing to a
 *     valid chunk header.
 * @param wavHeader WAV header to populate with data bounds.
 * @throws ParserException If an error occurs parsing chunks.
 * @throws IOException If reading from the input fails.
 * @throws InterruptedException If interrupted while reading from input.
 */
public static void skipToData(ExtractorInput input, WavHeader wavHeader)
    throws IOException, InterruptedException {
  Assertions.checkNotNull(input);
  Assertions.checkNotNull(wavHeader);

  // Make sure the peek position is set to the read position before we peek the first header.
  input.resetPeekPosition();

  ParsableByteArray scratch = new ParsableByteArray(ChunkHeader.SIZE_IN_BYTES);
  // Skip all chunks until we hit the data header.
  ChunkHeader chunkHeader = ChunkHeader.peek(input, scratch);
  while (chunkHeader.id != WavUtil.DATA_FOURCC) {
    if (chunkHeader.id != WavUtil.RIFF_FOURCC && chunkHeader.id != WavUtil.FMT_FOURCC) {
      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) {
      bytesToSkip = ChunkHeader.SIZE_IN_BYTES + 4;
    }
    if (bytesToSkip > Integer.MAX_VALUE) {
      throw new ParserException("Chunk is too large (~2GB+) to skip; id: " + chunkHeader.id);
    }
    input.skipFully((int) bytesToSkip);
    chunkHeader = ChunkHeader.peek(input, scratch);
  }
  // Skip past the "data" header.
  input.skipFully(ChunkHeader.SIZE_IN_BYTES);

  int dataStartPosition = (int) input.getPosition();
  long dataEndPosition = dataStartPosition + chunkHeader.size;
  long inputLength = input.getLength();
  if (inputLength != C.LENGTH_UNSET && dataEndPosition > inputLength) {
    Log.w(TAG, "Data exceeds input length: " + dataEndPosition + ", " + inputLength);
    dataEndPosition = inputLength;
  }
  wavHeader.setDataBounds(dataStartPosition, dataEndPosition);
}
 
Example 2
Source File: WavHeaderReader.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Skips to the data in the given WAV input stream. After calling, the input stream's position
 * will point to the start of sample data in the WAV, and the data bounds of the provided {@link
 * WavHeader} will have been set.
 *
 * <p>If an exception is thrown, the input position will be left pointing to a chunk header and
 * the bounds of the provided {@link WavHeader} will not have been set.
 *
 * @param input Input stream to skip to the data chunk in. Its peek position must be pointing to a
 *     valid chunk header.
 * @param wavHeader WAV header to populate with data bounds.
 * @throws ParserException If an error occurs parsing chunks.
 * @throws IOException If reading from the input fails.
 * @throws InterruptedException If interrupted while reading from input.
 */
public static void skipToData(ExtractorInput input, WavHeader wavHeader)
    throws IOException, InterruptedException {
  Assertions.checkNotNull(input);
  Assertions.checkNotNull(wavHeader);

  // Make sure the peek position is set to the read position before we peek the first header.
  input.resetPeekPosition();

  ParsableByteArray scratch = new ParsableByteArray(ChunkHeader.SIZE_IN_BYTES);
  // Skip all chunks until we hit the data header.
  ChunkHeader chunkHeader = ChunkHeader.peek(input, scratch);
  while (chunkHeader.id != WavUtil.DATA_FOURCC) {
    if (chunkHeader.id != WavUtil.RIFF_FOURCC && chunkHeader.id != WavUtil.FMT_FOURCC) {
      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) {
      bytesToSkip = ChunkHeader.SIZE_IN_BYTES + 4;
    }
    if (bytesToSkip > Integer.MAX_VALUE) {
      throw new ParserException("Chunk is too large (~2GB+) to skip; id: " + chunkHeader.id);
    }
    input.skipFully((int) bytesToSkip);
    chunkHeader = ChunkHeader.peek(input, scratch);
  }
  // Skip past the "data" header.
  input.skipFully(ChunkHeader.SIZE_IN_BYTES);

  int dataStartPosition = (int) input.getPosition();
  long dataEndPosition = dataStartPosition + chunkHeader.size;
  long inputLength = input.getLength();
  if (inputLength != C.LENGTH_UNSET && dataEndPosition > inputLength) {
    Log.w(TAG, "Data exceeds input length: " + dataEndPosition + ", " + inputLength);
    dataEndPosition = inputLength;
  }
  wavHeader.setDataBounds(dataStartPosition, dataEndPosition);
}
 
Example 3
Source File: WavHeaderReader.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Skips to the data in the given WAV input stream. After calling, the input stream's position
 * will point to the start of sample data in the WAV, and the data bounds of the provided {@link
 * WavHeader} will have been set.
 *
 * <p>If an exception is thrown, the input position will be left pointing to a chunk header and
 * the bounds of the provided {@link WavHeader} will not have been set.
 *
 * @param input Input stream to skip to the data chunk in. Its peek position must be pointing to a
 *     valid chunk header.
 * @param wavHeader WAV header to populate with data bounds.
 * @throws ParserException If an error occurs parsing chunks.
 * @throws IOException If reading from the input fails.
 * @throws InterruptedException If interrupted while reading from input.
 */
public static void skipToData(ExtractorInput input, WavHeader wavHeader)
    throws IOException, InterruptedException {
  Assertions.checkNotNull(input);
  Assertions.checkNotNull(wavHeader);

  // Make sure the peek position is set to the read position before we peek the first header.
  input.resetPeekPosition();

  ParsableByteArray scratch = new ParsableByteArray(ChunkHeader.SIZE_IN_BYTES);
  // Skip all chunks until we hit the data header.
  ChunkHeader chunkHeader = ChunkHeader.peek(input, scratch);
  while (chunkHeader.id != WavUtil.DATA_FOURCC) {
    if (chunkHeader.id != WavUtil.RIFF_FOURCC && chunkHeader.id != WavUtil.FMT_FOURCC) {
      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) {
      bytesToSkip = ChunkHeader.SIZE_IN_BYTES + 4;
    }
    if (bytesToSkip > Integer.MAX_VALUE) {
      throw new ParserException("Chunk is too large (~2GB+) to skip; id: " + chunkHeader.id);
    }
    input.skipFully((int) bytesToSkip);
    chunkHeader = ChunkHeader.peek(input, scratch);
  }
  // Skip past the "data" header.
  input.skipFully(ChunkHeader.SIZE_IN_BYTES);

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