com.google.android.exoplayer2.util.FlacStreamInfo Java Examples

The following examples show how to use com.google.android.exoplayer2.util.FlacStreamInfo. 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: FlacDecoder.java    From Jockey with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a Flac decoder.
 *
 * @param numInputBuffers The number of input buffers.
 * @param numOutputBuffers The number of output buffers.
 * @param initializationData Codec-specific initialization data. It should contain only one entry
 *    which is the flac file header.
 * @throws FlacDecoderException Thrown if an exception occurs when initializing the decoder.
 */
public FlacDecoder(int numInputBuffers, int numOutputBuffers, List<byte[]> initializationData)
    throws FlacDecoderException {
  super(new DecoderInputBuffer[numInputBuffers], new SimpleOutputBuffer[numOutputBuffers]);
  if (initializationData.size() != 1) {
    throw new FlacDecoderException("Initialization data must be of length 1");
  }
  decoderJni = new FlacDecoderJni();
  decoderJni.setData(ByteBuffer.wrap(initializationData.get(0)));
  FlacStreamInfo streamInfo;
  try {
    streamInfo = decoderJni.decodeMetadata();
  } catch (IOException | InterruptedException e) {
    // Never happens.
    throw new IllegalStateException(e);
  }
  if (streamInfo == null) {
    throw new FlacDecoderException("Metadata decoding failed");
  }

  setInitialInputBufferSize(streamInfo.maxFrameSize);
  maxOutputBufferSize = streamInfo.maxDecodedFrameSize();
}
 
Example #2
Source File: FlacBinarySearchSeeker.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public FlacBinarySearchSeeker(
    FlacStreamInfo streamInfo,
    long firstFramePosition,
    long inputLength,
    FlacDecoderJni decoderJni) {
  super(
      new FlacSeekTimestampConverter(streamInfo),
      new FlacTimestampSeeker(decoderJni),
      streamInfo.durationUs(),
      /* floorTimePosition= */ 0,
      /* ceilingTimePosition= */ streamInfo.totalSamples,
      /* floorBytePosition= */ firstFramePosition,
      /* ceilingBytePosition= */ inputLength,
      /* approxBytesPerFrame= */ streamInfo.getApproxBytesPerFrame(),
      /* minimumSearchRange= */ Math.max(1, streamInfo.minFrameSize));
  this.decoderJni = Assertions.checkNotNull(decoderJni);
}
 
Example #3
Source File: FlacExtractor.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void outputFormat(FlacStreamInfo streamInfo) {
  Format mediaFormat =
      Format.createAudioSampleFormat(
          /* id= */ null,
          MimeTypes.AUDIO_RAW,
          /* codecs= */ null,
          streamInfo.bitRate(),
          streamInfo.maxDecodedFrameSize(),
          streamInfo.channels,
          streamInfo.sampleRate,
          getPcmEncoding(streamInfo.bitsPerSample),
          /* encoderDelay= */ 0,
          /* encoderPadding= */ 0,
          /* initializationData= */ null,
          /* drmInitData= */ null,
          /* selectionFlags= */ 0,
          /* language= */ null,
          isId3MetadataDisabled ? null : id3Metadata);
  trackOutput.format(mediaFormat);
}
 
Example #4
Source File: FlacExtractor.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void outputFormat(FlacStreamInfo streamInfo) {
  Format mediaFormat =
      Format.createAudioSampleFormat(
          /* id= */ null,
          MimeTypes.AUDIO_RAW,
          /* codecs= */ null,
          streamInfo.bitRate(),
          streamInfo.maxDecodedFrameSize(),
          streamInfo.channels,
          streamInfo.sampleRate,
          getPcmEncoding(streamInfo.bitsPerSample),
          /* encoderDelay= */ 0,
          /* encoderPadding= */ 0,
          /* initializationData= */ null,
          /* drmInitData= */ null,
          /* selectionFlags= */ 0,
          /* language= */ null,
          isId3MetadataDisabled ? null : id3Metadata);
  trackOutput.format(mediaFormat);
}
 
Example #5
Source File: FlacBinarySearchSeeker.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public FlacBinarySearchSeeker(
    FlacStreamInfo streamInfo,
    long firstFramePosition,
    long inputLength,
    FlacDecoderJni decoderJni) {
  super(
      new FlacSeekTimestampConverter(streamInfo),
      new FlacTimestampSeeker(decoderJni),
      streamInfo.durationUs(),
      /* floorTimePosition= */ 0,
      /* ceilingTimePosition= */ streamInfo.totalSamples,
      /* floorBytePosition= */ firstFramePosition,
      /* ceilingBytePosition= */ inputLength,
      /* approxBytesPerFrame= */ streamInfo.getApproxBytesPerFrame(),
      /* minimumSearchRange= */ Math.max(1, streamInfo.minFrameSize));
  this.decoderJni = Assertions.checkNotNull(decoderJni);
}
 
Example #6
Source File: FlacExtractor.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void updateFlacStreamInfo(ExtractorInput input, FlacStreamInfo streamInfo) {
  this.streamInfo = streamInfo;
  outputSeekMap(input, streamInfo);
  outputFormat(streamInfo);
  outputBuffer = new ParsableByteArray(streamInfo.maxDecodedFrameSize());
  outputByteBuffer = ByteBuffer.wrap(outputBuffer.data);
  outputFrameHolder = new BinarySearchSeeker.OutputFrameHolder(outputByteBuffer);
}
 
Example #7
Source File: FlacDecoder.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a Flac decoder.
 *
 * @param numInputBuffers The number of input buffers.
 * @param numOutputBuffers The number of output buffers.
 * @param maxInputBufferSize The maximum required input buffer size if known, or {@link
 *     Format#NO_VALUE} otherwise.
 * @param initializationData Codec-specific initialization data. It should contain only one entry
 *     which is the flac file header.
 * @throws FlacDecoderException Thrown if an exception occurs when initializing the decoder.
 */
public FlacDecoder(
    int numInputBuffers,
    int numOutputBuffers,
    int maxInputBufferSize,
    List<byte[]> initializationData)
    throws FlacDecoderException {
  super(new DecoderInputBuffer[numInputBuffers], new SimpleOutputBuffer[numOutputBuffers]);
  if (initializationData.size() != 1) {
    throw new FlacDecoderException("Initialization data must be of length 1");
  }
  decoderJni = new FlacDecoderJni();
  decoderJni.setData(ByteBuffer.wrap(initializationData.get(0)));
  FlacStreamInfo streamInfo;
  try {
    streamInfo = decoderJni.decodeMetadata();
  } catch (IOException | InterruptedException e) {
    // Never happens.
    throw new IllegalStateException(e);
  }
  if (streamInfo == null) {
    throw new FlacDecoderException("Metadata decoding failed");
  }

  int initialInputBufferSize =
      maxInputBufferSize != Format.NO_VALUE ? maxInputBufferSize : streamInfo.maxFrameSize;
  setInitialInputBufferSize(initialInputBufferSize);
  maxOutputBufferSize = streamInfo.maxDecodedFrameSize();
}
 
Example #8
Source File: FlacExtractor.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private SeekMap getSeekMapForNonSeekTableFlac(ExtractorInput input, FlacStreamInfo streamInfo) {
  long inputLength = input.getLength();
  if (inputLength != C.LENGTH_UNSET) {
    long firstFramePosition = decoderJni.getDecodePosition();
    flacBinarySearchSeeker =
        new FlacBinarySearchSeeker(streamInfo, firstFramePosition, inputLength, decoderJni);
    return flacBinarySearchSeeker.getSeekMap();
  } else { // can't seek at all, because there's no SeekTable and the input length is unknown.
    return new SeekMap.Unseekable(streamInfo.durationUs());
  }
}
 
Example #9
Source File: FlacExtractor.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void outputSeekMap(ExtractorInput input, FlacStreamInfo streamInfo) {
  boolean hasSeekTable = decoderJni.getSeekPosition(0) != -1;
  SeekMap seekMap =
      hasSeekTable
          ? new FlacSeekMap(streamInfo.durationUs(), decoderJni)
          : getSeekMapForNonSeekTableFlac(input, streamInfo);
  extractorOutput.seekMap(seekMap);
}
 
Example #10
Source File: FlacExtractor.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private FlacStreamInfo decodeStreamInfo(ExtractorInput input)
    throws InterruptedException, IOException {
  try {
    FlacStreamInfo streamInfo = decoderJni.decodeMetadata();
    if (streamInfo == null) {
      throw new IOException("Metadata decoding failed");
    }
    return streamInfo;
  } catch (IOException e) {
    decoderJni.reset(0);
    input.setRetryPosition(0, e);
    throw e;
  }
}
 
Example #11
Source File: FlacExtractor.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void updateFlacStreamInfo(ExtractorInput input, FlacStreamInfo streamInfo) {
  this.streamInfo = streamInfo;
  outputSeekMap(input, streamInfo);
  outputFormat(streamInfo);
  outputBuffer = new ParsableByteArray(streamInfo.maxDecodedFrameSize());
  outputByteBuffer = ByteBuffer.wrap(outputBuffer.data);
  outputFrameHolder = new BinarySearchSeeker.OutputFrameHolder(outputByteBuffer);
}
 
Example #12
Source File: FlacExtractor.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void readPastStreamInfo(ExtractorInput input) throws InterruptedException, IOException {
  if (readPastStreamInfo) {
    return;
  }

  FlacStreamInfo streamInfo = decodeStreamInfo(input);
  readPastStreamInfo = true;
  if (this.streamInfo == null) {
    updateFlacStreamInfo(input, streamInfo);
  }
}
 
Example #13
Source File: FlacDecoder.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a Flac decoder.
 *
 * @param numInputBuffers The number of input buffers.
 * @param numOutputBuffers The number of output buffers.
 * @param maxInputBufferSize The maximum required input buffer size if known, or {@link
 *     Format#NO_VALUE} otherwise.
 * @param initializationData Codec-specific initialization data. It should contain only one entry
 *     which is the flac file header.
 * @throws FlacDecoderException Thrown if an exception occurs when initializing the decoder.
 */
public FlacDecoder(
    int numInputBuffers,
    int numOutputBuffers,
    int maxInputBufferSize,
    List<byte[]> initializationData)
    throws FlacDecoderException {
  super(new DecoderInputBuffer[numInputBuffers], new SimpleOutputBuffer[numOutputBuffers]);
  if (initializationData.size() != 1) {
    throw new FlacDecoderException("Initialization data must be of length 1");
  }
  decoderJni = new FlacDecoderJni();
  decoderJni.setData(ByteBuffer.wrap(initializationData.get(0)));
  FlacStreamInfo streamInfo;
  try {
    streamInfo = decoderJni.decodeMetadata();
  } catch (IOException | InterruptedException e) {
    // Never happens.
    throw new IllegalStateException(e);
  }
  if (streamInfo == null) {
    throw new FlacDecoderException("Metadata decoding failed");
  }

  int initialInputBufferSize =
      maxInputBufferSize != Format.NO_VALUE ? maxInputBufferSize : streamInfo.maxFrameSize;
  setInitialInputBufferSize(initialInputBufferSize);
  maxOutputBufferSize = streamInfo.maxDecodedFrameSize();
}
 
Example #14
Source File: FlacExtractor.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private SeekMap getSeekMapForNonSeekTableFlac(ExtractorInput input, FlacStreamInfo streamInfo) {
  long inputLength = input.getLength();
  if (inputLength != C.LENGTH_UNSET) {
    long firstFramePosition = decoderJni.getDecodePosition();
    flacBinarySearchSeeker =
        new FlacBinarySearchSeeker(streamInfo, firstFramePosition, inputLength, decoderJni);
    return flacBinarySearchSeeker.getSeekMap();
  } else { // can't seek at all, because there's no SeekTable and the input length is unknown.
    return new SeekMap.Unseekable(streamInfo.durationUs());
  }
}
 
Example #15
Source File: FlacExtractor.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void outputSeekMap(ExtractorInput input, FlacStreamInfo streamInfo) {
  boolean hasSeekTable = decoderJni.getSeekPosition(0) != -1;
  SeekMap seekMap =
      hasSeekTable
          ? new FlacSeekMap(streamInfo.durationUs(), decoderJni)
          : getSeekMapForNonSeekTableFlac(input, streamInfo);
  extractorOutput.seekMap(seekMap);
}
 
Example #16
Source File: FlacExtractor.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private FlacStreamInfo decodeStreamInfo(ExtractorInput input)
    throws InterruptedException, IOException {
  try {
    FlacStreamInfo streamInfo = decoderJni.decodeMetadata();
    if (streamInfo == null) {
      throw new IOException("Metadata decoding failed");
    }
    return streamInfo;
  } catch (IOException e) {
    decoderJni.reset(0);
    input.setRetryPosition(0, e);
    throw e;
  }
}
 
Example #17
Source File: FlacExtractor.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void readPastStreamInfo(ExtractorInput input) throws InterruptedException, IOException {
  if (readPastStreamInfo) {
    return;
  }

  FlacStreamInfo streamInfo = decodeStreamInfo(input);
  readPastStreamInfo = true;
  if (this.streamInfo == null) {
    updateFlacStreamInfo(input, streamInfo);
  }
}
 
Example #18
Source File: FlacDecoderJni.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
private native FlacStreamInfo flacDecodeMetadata(long context)
throws IOException, InterruptedException;
 
Example #19
Source File: FlacDecoderJni.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
/** Decodes and consumes the StreamInfo section from the FLAC stream. */
public FlacStreamInfo decodeMetadata() throws IOException, InterruptedException {
  return flacDecodeMetadata(nativeDecoderContext);
}
 
Example #20
Source File: FlacBinarySearchSeeker.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public FlacSeekTimestampConverter(FlacStreamInfo streamInfo) {
  this.streamInfo = streamInfo;
}
 
Example #21
Source File: FlacBinarySearchSeeker.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public FlacSeekTimestampConverter(FlacStreamInfo streamInfo) {
  this.streamInfo = streamInfo;
}
 
Example #22
Source File: FlacDecoderJni.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
/** Decodes and consumes the StreamInfo section from the FLAC stream. */
public FlacStreamInfo decodeMetadata() throws IOException, InterruptedException {
  return flacDecodeMetadata(nativeDecoderContext);
}
 
Example #23
Source File: FlacDecoderJni.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
private native FlacStreamInfo flacDecodeMetadata(long context)
throws IOException, InterruptedException;
 
Example #24
Source File: FlacDecoderJni.java    From Jockey with Apache License 2.0 4 votes vote down vote up
public FlacStreamInfo decodeMetadata() throws IOException, InterruptedException {
  return flacDecodeMetadata(nativeDecoderContext);
}
 
Example #25
Source File: FlacDecoderJni.java    From Jockey with Apache License 2.0 4 votes vote down vote up
private native FlacStreamInfo flacDecodeMetadata(long context)
throws IOException, InterruptedException;