Java Code Examples for com.google.android.exoplayer2.decoder.SimpleOutputBuffer#setFlags()

The following examples show how to use com.google.android.exoplayer2.decoder.SimpleOutputBuffer#setFlags() . 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: AudioDecoder.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
@Override
protected @Nullable
AudioSoftDecoderException decode(
        DecoderInputBuffer inputBuffer, SimpleOutputBuffer outputBuffer, boolean reset) {
  if (reset) {
    nativeContext = ffmpegReset(nativeContext, extraData);
    if (nativeContext == 0) {
      return new AudioSoftDecoderException("Error resetting (see logcat).");
    }
  }
  ByteBuffer inputData = inputBuffer.data;
  int inputSize = inputData.limit();
  ByteBuffer outputData = outputBuffer.init(inputBuffer.timeUs, outputBufferSize);
  int result = ffmpegDecode(nativeContext, inputData, inputSize, outputData, outputBufferSize);
  if (result == DECODER_ERROR_INVALID_DATA) {
    // Treat invalid data errors as non-fatal to match the behavior of MediaCodec. No output will
    // be produced for this buffer, so mark it as decode-only to ensure that the audio sink's
    // position is reset when more audio is produced.
    outputBuffer.setFlags(C.BUFFER_FLAG_DECODE_ONLY);
    return null;
  } else if (result == DECODER_ERROR_OTHER) {
    return new AudioSoftDecoderException("Error decoding (see logcat).");
  }
  if (!hasOutputFormat) {
    channelCount = ffmpegGetChannelCount(nativeContext);
    sampleRate = ffmpegGetSampleRate(nativeContext);
    if (sampleRate == 0 && "alac".equals(codecName)) {
      Assertions.checkNotNull(extraData);
      // ALAC decoder did not set the sample rate in earlier versions of FFMPEG.
      // See https://trac.ffmpeg.org/ticket/6096
      ParsableByteArray parsableExtraData = new ParsableByteArray(extraData);
      parsableExtraData.setPosition(extraData.length - 4);
      sampleRate = parsableExtraData.readUnsignedIntToInt();
    }
    hasOutputFormat = true;
  }
  outputBuffer.data.position(0);
  outputBuffer.data.limit(result);
  return null;
}
 
Example 2
Source File: FfmpegDecoder.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected @Nullable FfmpegDecoderException decode(
    DecoderInputBuffer inputBuffer, SimpleOutputBuffer outputBuffer, boolean reset) {
  if (reset) {
    nativeContext = ffmpegReset(nativeContext, extraData);
    if (nativeContext == 0) {
      return new FfmpegDecoderException("Error resetting (see logcat).");
    }
  }
  ByteBuffer inputData = inputBuffer.data;
  int inputSize = inputData.limit();
  ByteBuffer outputData = outputBuffer.init(inputBuffer.timeUs, outputBufferSize);
  int result = ffmpegDecode(nativeContext, inputData, inputSize, outputData, outputBufferSize);
  if (result == DECODER_ERROR_INVALID_DATA) {
    // Treat invalid data errors as non-fatal to match the behavior of MediaCodec. No output will
    // be produced for this buffer, so mark it as decode-only to ensure that the audio sink's
    // position is reset when more audio is produced.
    outputBuffer.setFlags(C.BUFFER_FLAG_DECODE_ONLY);
    return null;
  } else if (result == DECODER_ERROR_OTHER) {
    return new FfmpegDecoderException("Error decoding (see logcat).");
  }
  if (!hasOutputFormat) {
    channelCount = ffmpegGetChannelCount(nativeContext);
    sampleRate = ffmpegGetSampleRate(nativeContext);
    if (sampleRate == 0 && "alac".equals(codecName)) {
      Assertions.checkNotNull(extraData);
      // ALAC decoder did not set the sample rate in earlier versions of FFMPEG.
      // See https://trac.ffmpeg.org/ticket/6096
      ParsableByteArray parsableExtraData = new ParsableByteArray(extraData);
      parsableExtraData.setPosition(extraData.length - 4);
      sampleRate = parsableExtraData.readUnsignedIntToInt();
    }
    hasOutputFormat = true;
  }
  outputBuffer.data.position(0);
  outputBuffer.data.limit(result);
  return null;
}
 
Example 3
Source File: FfmpegDecoder.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected @Nullable FfmpegDecoderException decode(
    DecoderInputBuffer inputBuffer, SimpleOutputBuffer outputBuffer, boolean reset) {
  if (reset) {
    nativeContext = ffmpegReset(nativeContext, extraData);
    if (nativeContext == 0) {
      return new FfmpegDecoderException("Error resetting (see logcat).");
    }
  }
  ByteBuffer inputData = inputBuffer.data;
  int inputSize = inputData.limit();
  ByteBuffer outputData = outputBuffer.init(inputBuffer.timeUs, outputBufferSize);
  int result = ffmpegDecode(nativeContext, inputData, inputSize, outputData, outputBufferSize);
  if (result == DECODER_ERROR_INVALID_DATA) {
    // Treat invalid data errors as non-fatal to match the behavior of MediaCodec. No output will
    // be produced for this buffer, so mark it as decode-only to ensure that the audio sink's
    // position is reset when more audio is produced.
    outputBuffer.setFlags(C.BUFFER_FLAG_DECODE_ONLY);
    return null;
  } else if (result == DECODER_ERROR_OTHER) {
    return new FfmpegDecoderException("Error decoding (see logcat).");
  }
  if (!hasOutputFormat) {
    channelCount = ffmpegGetChannelCount(nativeContext);
    sampleRate = ffmpegGetSampleRate(nativeContext);
    if (sampleRate == 0 && "alac".equals(codecName)) {
      Assertions.checkNotNull(extraData);
      // ALAC decoder did not set the sample rate in earlier versions of FFMPEG.
      // See https://trac.ffmpeg.org/ticket/6096
      ParsableByteArray parsableExtraData = new ParsableByteArray(extraData);
      parsableExtraData.setPosition(extraData.length - 4);
      sampleRate = parsableExtraData.readUnsignedIntToInt();
    }
    hasOutputFormat = true;
  }
  outputBuffer.data.position(0);
  outputBuffer.data.limit(result);
  return null;
}