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

The following examples show how to use com.google.android.exoplayer2.decoder.SimpleOutputBuffer#init() . 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
@Override
public FlacDecoderException decode(DecoderInputBuffer inputBuffer,
    SimpleOutputBuffer outputBuffer, boolean reset) {
  if (reset) {
    decoderJni.flush();
  }
  decoderJni.setData(inputBuffer.data);
  ByteBuffer outputData = outputBuffer.init(inputBuffer.timeUs, maxOutputBufferSize);
  int result;
  try {
    result = decoderJni.decodeSample(outputData);
  } catch (IOException | InterruptedException e) {
    // Never happens.
    throw new IllegalStateException(e);
  }
  if (result < 0) {
    return new FlacDecoderException("Frame decoding failed");
  }
  outputData.position(0);
  outputData.limit(result);
  return null;
}
 
Example 2
Source File: FfmpegDecoder.java    From TelePlus-Android 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 < 0) {
    return new FfmpegDecoderException("Error decoding (see logcat). Code: " + result);
  }
  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 PowerFileExplorer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public 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, OUTPUT_BUFFER_SIZE);
  int result = ffmpegDecode(nativeContext, inputData, inputSize, outputData, OUTPUT_BUFFER_SIZE);
  if (result < 0) {
    return new FfmpegDecoderException("Error decoding (see logcat). Code: " + result);
  }
  if (!hasOutputFormat) {
    channelCount = ffmpegGetChannelCount(nativeContext);
    sampleRate = ffmpegGetSampleRate(nativeContext);
    if (sampleRate == 0 && "alac".equals(codecName)) {
      // 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 4
Source File: FfmpegDecoder.java    From TelePlus-Android 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 < 0) {
    return new FfmpegDecoderException("Error decoding (see logcat). Code: " + result);
  }
  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 5
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 6
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 7
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;
}