/** * Reads and returns an integer of length {@code byteLength} from the {@link ExtractorInput}. * * @param input The {@link ExtractorInput} from which to read. * @param byteLength The length of the integer being read. * @return The read integer value. * @throws IOException If an error occurs reading from the input. * @throws InterruptedException If the thread is interrupted. */ private long readInteger(ExtractorInput input, int byteLength) throws IOException, InterruptedException { input.readFully(scratch, 0, byteLength); long value = 0; for (int i = 0; i < byteLength; i++) { value = (value << 8) | (scratch[i] & 0xFF); } return value; }
/** * Reads and returns a string of length {@code byteLength} from the {@link ExtractorInput}. * * @param input The {@link ExtractorInput} from which to read. * @param byteLength The length of the float being read. * @return The read string value. * @throws IOException If an error occurs reading from the input. * @throws InterruptedException If the thread is interrupted. */ private String readString(ExtractorInput input, int byteLength) throws IOException, InterruptedException { byte[] stringBytes = new byte[byteLength]; input.readFully(stringBytes, 0, byteLength); return new String(stringBytes, Charset.forName(C.UTF8_NAME)); }
/** * Fills {@link #sampleEncryptionData} from the provided input. * * @param input An {@link ExtractorInput} from which to read the encryption data. */ public void fillEncryptionData(ExtractorInput input) throws IOException, InterruptedException { input.readFully(sampleEncryptionData.data, 0, sampleEncryptionDataLength); sampleEncryptionData.setPosition(0); sampleEncryptionDataNeedsFill = false; }
/** Ensures the buffer contains enough data to read {@code length} bytes. */ private boolean ensureLoaded(ExtractorInput extractorInput, int length) throws InterruptedException, IOException { if (length + readPosition - markPosition > capacity) { throw new BufferOverflowException(); } int bytesToLoad = length - (writePosition - readPosition); if (bytesToLoad > 0) { if (!extractorInput.readFully(buffer.data, writePosition, bytesToLoad, true)) { return false; } writePosition += bytesToLoad; } return true; }
/** * Writes {@code length} bytes of sample data into {@code target} at {@code offset}, consisting of * pending {@link #sampleStrippedBytes} and any remaining data read from {@code input}. */ private void readToTarget(ExtractorInput input, byte[] target, int offset, int length) throws IOException, InterruptedException { int pendingStrippedBytes = Math.min(length, sampleStrippedBytes.bytesLeft()); input.readFully(target, offset + pendingStrippedBytes, length - pendingStrippedBytes); if (pendingStrippedBytes > 0) { sampleStrippedBytes.readBytes(target, offset, pendingStrippedBytes); } sampleBytesRead += length; }
private void readAtomPayload(ExtractorInput input) throws IOException, InterruptedException { int atomPayloadSize = (int) atomSize - atomHeaderBytesRead; if (atomData != null) { input.readFully(atomData.data, Atom.HEADER_SIZE, atomPayloadSize); onLeafAtomRead(new LeafAtom(atomType, atomData), input.getPosition()); } else { input.skipFully(atomPayloadSize); } long currentPosition = input.getPosition(); while (!containerAtoms.isEmpty() && containerAtoms.peek().endPosition == currentPosition) { onContainerAtomRead(containerAtoms.pop()); } enterReadingAtomHeaderState(); }
boolean seekRequired = false; if (atomData != null) { input.readFully(atomData.data, atomHeaderBytesRead, (int) atomPayloadSize); if (!containerAtoms.isEmpty()) { containerAtoms.peek().add(new Atom.LeafAtom(atomType, atomData));
/** * Ensures {@link #scratch} contains at least {@code requiredLength} bytes of data, reading from * the extractor input if necessary. */ private void readScratch(ExtractorInput input, int requiredLength) throws IOException, InterruptedException { if (scratch.limit() >= requiredLength) { return; } if (scratch.capacity() < requiredLength) { scratch.reset(Arrays.copyOf(scratch.data, Math.max(scratch.data.length * 2, requiredLength)), scratch.limit()); } input.readFully(scratch.data, scratch.limit(), requiredLength - scratch.limit()); scratch.setLimit(requiredLength); }
private boolean readAtomHeader(ExtractorInput input) throws IOException, InterruptedException { if (atomHeaderBytesRead == 0) { if (!input.readFully(atomHeader.data, 0, Atom.HEADER_SIZE, true)) { return false; input.readFully(atomHeader.data, Atom.HEADER_SIZE, headerBytesRemaining); atomHeaderBytesRead += headerBytesRemaining; atomSize = atomHeader.readUnsignedLongToLong();
private boolean readAtomHeader(ExtractorInput input) throws IOException, InterruptedException { if (atomHeaderBytesRead == 0) { if (!input.readFully(atomHeader.data, 0, Atom.HEADER_SIZE, true)) { return false; input.readFully(atomHeader.data, Atom.HEADER_SIZE, headerBytesRemaining); atomHeaderBytesRead += headerBytesRemaining; atomSize = atomHeader.readUnsignedLongToLong();
case ID_SEEK_ID: Arrays.fill(seekEntryIdBytes.data, (byte) 0); input.readFully(seekEntryIdBytes.data, 4 - contentSize, contentSize); seekEntryIdBytes.setPosition(0); seekEntryId = (int) seekEntryIdBytes.readUnsignedInt(); case ID_CODEC_PRIVATE: currentTrack.codecPrivate = new byte[contentSize]; input.readFully(currentTrack.codecPrivate, 0, contentSize); return; case ID_CONTENT_COMPRESSION_SETTINGS: input.readFully(currentTrack.sampleStrippedBytes, 0, contentSize); return; case ID_CONTENT_ENCRYPTION_KEY_ID: currentTrack.encryptionKeyId = new byte[contentSize]; input.readFully(currentTrack.encryptionKeyId, 0, contentSize); return; case ID_SIMPLE_BLOCK:
@Override public int read(ExtractorInput input, PositionHolder seekPosition) throws IOException, InterruptedException { if (!input.readFully(tsPacketBuffer.data, 0, TS_PACKET_SIZE, true)) { return RESULT_END_OF_INPUT;
if (sampleCurrentNalBytesRemaining == 0) { input.readFully(nalLength.data, nalUnitLengthFieldLengthDiff, nalUnitLengthFieldLength); nalLength.setPosition(0); sampleCurrentNalBytesRemaining = nalLength.readUnsignedIntToInt();
if (sampleCurrentNalBytesRemaining == 0) { input.readFully(nalLength.data, nalUnitLengthFieldLengthDiff, nalUnitLengthFieldLength); nalLength.setPosition(0); sampleCurrentNalBytesRemaining = nalLength.readUnsignedIntToInt();
extractorInput.readFully(scratch.data, 0, 4); int headerLength = ((scratch.data[0] & 0x7F) << 21) | ((scratch.data[1] & 0x7F) << 14) | ((scratch.data[2] & 0x7F) << 7) | (scratch.data[3] & 0x7F);