use of com.google.android.exoplayer2.extractor.ExtractorInput in project ExoPlayer by google.
the class FlacDecoderJni method readFromExtractorInput.
private int readFromExtractorInput(ExtractorInput extractorInput, byte[] tempBuffer, int offset, int length) throws IOException {
int read = extractorInput.read(tempBuffer, offset, length);
if (read == C.RESULT_END_OF_INPUT) {
endOfExtractorInput = true;
read = 0;
}
return read;
}
use of com.google.android.exoplayer2.extractor.ExtractorInput in project ExoPlayer by google.
the class FlacDecoderJni method read.
/**
* Reads up to {@code length} bytes from the data source.
*
* <p>This method blocks until at least one byte of data can be read, the end of the input is
* detected or an exception is thrown.
*
* @param target A target {@link ByteBuffer} into which data should be written.
* @return Returns the number of bytes read, or -1 on failure. If all of the data has already been
* read from the source, then 0 is returned.
*/
// Called from native code.
@SuppressWarnings("unused")
public int read(ByteBuffer target) throws IOException {
int byteCount = target.remaining();
if (byteBufferData != null) {
byteCount = min(byteCount, byteBufferData.remaining());
int originalLimit = byteBufferData.limit();
byteBufferData.limit(byteBufferData.position() + byteCount);
target.put(byteBufferData);
byteBufferData.limit(originalLimit);
} else if (extractorInput != null) {
ExtractorInput extractorInput = this.extractorInput;
byte[] tempBuffer = Util.castNonNull(this.tempBuffer);
byteCount = min(byteCount, TEMP_BUFFER_SIZE);
int read = readFromExtractorInput(extractorInput, tempBuffer, /* offset= */
0, byteCount);
if (read < 4) {
// Reading less than 4 bytes, most of the time, happens because of getting the bytes left in
// the buffer of the input. Do another read to reduce the number of calls to this method
// from the native code.
read += readFromExtractorInput(extractorInput, tempBuffer, read, /* length= */
byteCount - read);
}
byteCount = read;
target.put(tempBuffer, 0, byteCount);
} else {
return -1;
}
return byteCount;
}
use of com.google.android.exoplayer2.extractor.ExtractorInput in project ExoPlayer by google.
the class FlacExtractor method decodeStreamMetadata.
// Requires initialized.
@RequiresNonNull({ "decoderJni", "extractorOutput", "trackOutput" })
// Ensures stream metadata decoded.
@EnsuresNonNull({ "streamMetadata", "outputFrameHolder" })
@SuppressWarnings("nullness:contracts.postcondition")
private void decodeStreamMetadata(ExtractorInput input) throws IOException {
if (streamMetadataDecoded) {
return;
}
FlacDecoderJni flacDecoderJni = decoderJni;
FlacStreamMetadata streamMetadata;
try {
streamMetadata = flacDecoderJni.decodeStreamMetadata();
} catch (IOException e) {
flacDecoderJni.reset(/* newPosition= */
0);
input.setRetryPosition(/* position= */
0, e);
throw e;
}
streamMetadataDecoded = true;
if (this.streamMetadata == null) {
this.streamMetadata = streamMetadata;
outputBuffer.reset(streamMetadata.getMaxDecodedFrameSize());
outputFrameHolder = new OutputFrameHolder(ByteBuffer.wrap(outputBuffer.getData()));
binarySearchSeeker = outputSeekMap(flacDecoderJni, streamMetadata, input.getLength(), extractorOutput, outputFrameHolder);
@Nullable Metadata metadata = streamMetadata.getMetadataCopyWithAppendedEntriesFrom(id3Metadata);
outputFormat(streamMetadata, metadata, trackOutput);
}
}
use of com.google.android.exoplayer2.extractor.ExtractorInput in project ExoPlayer by google.
the class FlacExtractor method read.
@Override
public int read(final ExtractorInput input, PositionHolder seekPosition) throws IOException {
if (input.getPosition() == 0 && !id3MetadataDisabled && id3Metadata == null) {
id3Metadata = FlacMetadataReader.peekId3Metadata(input, /* parseData= */
true);
}
FlacDecoderJni decoderJni = initDecoderJni(input);
try {
decodeStreamMetadata(input);
if (binarySearchSeeker != null && binarySearchSeeker.isSeeking()) {
return handlePendingSeek(input, seekPosition, outputBuffer, outputFrameHolder, trackOutput);
}
ByteBuffer outputByteBuffer = outputFrameHolder.byteBuffer;
long lastDecodePosition = decoderJni.getDecodePosition();
try {
decoderJni.decodeSampleWithBacktrackPosition(outputByteBuffer, lastDecodePosition);
} catch (FlacDecoderJni.FlacFrameDecodeException e) {
throw new IOException("Cannot read frame at position " + lastDecodePosition, e);
}
int outputSize = outputByteBuffer.limit();
if (outputSize == 0) {
return RESULT_END_OF_INPUT;
}
outputSample(outputBuffer, outputSize, decoderJni.getLastFrameTimestamp(), trackOutput);
return decoderJni.isEndOfData() ? RESULT_END_OF_INPUT : RESULT_CONTINUE;
} finally {
decoderJni.clearData();
}
}
use of com.google.android.exoplayer2.extractor.ExtractorInput in project ExoPlayer by google.
the class JpegExtractor method sniffMotionPhotoVideo.
private void sniffMotionPhotoVideo(ExtractorInput input) throws IOException {
// Check if the file is truncated.
boolean peekedData = input.peekFully(scratch.getData(), /* offset= */
0, /* length= */
1, /* allowEndOfInput= */
true);
if (!peekedData) {
endReadingWithImageTrack();
} else {
input.resetPeekPosition();
if (mp4Extractor == null) {
mp4Extractor = new Mp4Extractor();
}
mp4ExtractorStartOffsetExtractorInput = new StartOffsetExtractorInput(input, mp4StartPosition);
if (mp4Extractor.sniff(mp4ExtractorStartOffsetExtractorInput)) {
mp4Extractor.init(new StartOffsetExtractorOutput(mp4StartPosition, checkNotNull(extractorOutput)));
startReadingMotionPhoto();
} else {
endReadingWithImageTrack();
}
}
}
Aggregations