long inputLength = input.getLength(); int bytesToSearch = (int) (inputLength == C.LENGTH_UNBOUNDED || inputLength > SEARCH_LENGTH ? SEARCH_LENGTH : inputLength); input.peekFully(scratch.data, 0, 4); long tag = scratch.readUnsignedInt(); peekLength = 4; return false; input.peekFully(scratch.data, 0, 1); tag = (tag << 8) & 0xFFFFFF00; tag |= scratch.data[0] & 0xFF; input.advancePeekPosition((int) size); peekLength += size;
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(); }
int startPosition = 0; while (true) { input.peekFully(scratch.data, 0, 3); scratch.setPosition(0); if (scratch.readUnsignedInt24() != ID3_TAG) { break; input.advancePeekPosition(3); input.peekFully(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); input.advancePeekPosition(headerLength); startPosition += 3 + 3 + 4 + headerLength; input.resetPeekPosition(); input.advancePeekPosition(startPosition); input.peekFully(scratch.data, 0, 4); scratch.setPosition(0); int headerData = scratch.readInt(); input.resetPeekPosition(); input.advancePeekPosition(++headerPosition); continue; input.advancePeekPosition(frameSize - 4);
@Override public boolean sniff(ExtractorInput input) throws IOException, InterruptedException { byte[] scratch = new byte[1]; for (int i = 0; i < 5; i++) { input.peekFully(scratch, 0, 1); if ((scratch[0] & 0xFF) != 0x47) { return false; } input.advancePeekPosition(TS_PACKET_SIZE - 1); } return true; }
/** * 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; }
loadDataSpec.absoluteStreamPosition, dataSource.open(loadDataSpec)); if (skipLoadedBytes) { input.skipFully(bytesLoaded); bytesLoaded = (int) (input.getPosition() - dataSpec.absoluteStreamPosition);
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(); long endPosition = input.getPosition() + atomSize - atomHeaderBytesRead; containerAtoms.add(new ContainerAtom(atomType, endPosition)); enterReadingAtomHeaderState();
/** Returns the reading position of {@code bufferingInput} relative to the extractor's stream. */ private static long getPosition(ExtractorInput extractorInput, BufferingInput bufferingInput) { return extractorInput.getPosition() - bufferingInput.getAvailableByteCount(); }
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: input.skipFully(contentSize - blockTrackNumberLength); blockState = BLOCK_STATE_START; return;
/** * Appends data to the rolling buffer. * * @param input The source from which to read. * @param length The maximum length of the read. * @param allowEndOfInput True if encountering the end of the input having appended no data is * allowed, and should result in {@link C#RESULT_END_OF_INPUT} being returned. False if it * should be considered an error, causing an {@link EOFException} to be thrown. * @return The number of bytes appended, or {@link C#RESULT_END_OF_INPUT} if the input has ended. * @throws IOException If an error occurs reading from the source. * @throws InterruptedException If the thread has been interrupted. */ public int appendData(ExtractorInput input, int length, boolean allowEndOfInput) throws IOException, InterruptedException { length = prepareForAppend(length); int bytesAppended = input.read(lastAllocation.data, lastAllocation.translateOffset(lastAllocationOffset), length); if (bytesAppended == C.RESULT_END_OF_INPUT) { if (allowEndOfInput) { return C.RESULT_END_OF_INPUT; } throw new EOFException(); } lastAllocationOffset += bytesAppended; totalBytesWritten += bytesAppended; return bytesAppended; }
/** * Peeks a variable-length unsigned EBML integer from the input. */ private long readUint(ExtractorInput input) throws IOException, InterruptedException { input.peekFully(scratch.data, 0, 1); int value = scratch.data[0] & 0xFF; if (value == 0) { return Long.MIN_VALUE; } int mask = 0x80; int length = 0; while ((value & mask) == 0) { mask >>= 1; length++; } value &= ~mask; input.peekFully(scratch.data, 1, length); for (int i = 0; i < length; i++) { value <<= 8; value += scratch.data[i + 1] & 0xFF; } peekLength += length + 1; 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)); }
@Override public boolean sniff(ExtractorInput input) throws IOException, InterruptedException { ParsableByteArray scratch = new ParsableByteArray(10); input.peekFully(scratch.data, 0, 10); int value = scratch.readUnsignedInt24(); if (value != Util.getIntegerCodeForString("ID3")) { value = value >> 8; } else { int length = (scratch.data[6] & 0x7F) << 21 | ((scratch.data[7] & 0x7F) << 14) | ((scratch.data[8] & 0x7F) << 7) | (scratch.data[9] & 0x7F); input.advancePeekPosition(length); input.peekFully(scratch.data, 0, 2); scratch.setPosition(0); value = scratch.readUnsignedShort(); } return (value & 0xFFF6) == 0xFFF0; }
while (true) { if (!masterElementsStack.isEmpty() && input.getPosition() >= masterElementsStack.peek().elementEndPosition) { output.endMasterElement(masterElementsStack.pop().elementId); return true; switch (type) { case TYPE_MASTER: long elementContentPosition = input.getPosition(); long elementEndPosition = elementContentPosition + elementContentSize; masterElementsStack.add(new MasterElement(elementId, elementEndPosition)); return true; case TYPE_UNKNOWN: input.skipFully((int) elementContentSize); elementState = ELEMENT_STATE_READ_ID; break;
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(); long endPosition = input.getPosition() + atomSize - Atom.HEADER_SIZE; containerAtoms.add(new ContainerAtom(atomType, endPosition)); enterReadingAtomHeaderState();
@Override public int read(ExtractorInput input, PositionHolder seekPosition) throws IOException, InterruptedException { sampleRead = false; boolean continueReading = true; while (continueReading && !sampleRead) { continueReading = reader.read(input); if (continueReading && maybeSeekForCues(seekPosition, input.getPosition())) { return Extractor.RESULT_SEEK; } } return continueReading ? Extractor.RESULT_CONTINUE : Extractor.RESULT_END_OF_INPUT; }
@Override public int read(ExtractorInput input, PositionHolder seekPosition) throws IOException, InterruptedException { int bytesRead = input.read(packetBuffer.data, 0, MAX_PACKET_SIZE); if (bytesRead == -1) { return RESULT_END_OF_INPUT; } // Feed whatever data we have to the reader, regardless of whether the read finished or not. packetBuffer.setPosition(0); packetBuffer.setLimit(bytesRead); // TODO: Make it possible for adtsReader to consume the dataSource directly, so that it becomes // unnecessary to copy the data through packetBuffer. adtsReader.consume(packetBuffer, firstSampleTimestampUs, firstPacket); firstPacket = false; return RESULT_CONTINUE; }
throws IOException, InterruptedException { long atomPayloadSize = atomSize - atomHeaderBytesRead; long atomEndPosition = input.getPosition() + atomPayloadSize; boolean seekRequired = false; if (atomData != null) { input.readFully(atomData.data, atomHeaderBytesRead, (int) atomPayloadSize); if (!containerAtoms.isEmpty()) { containerAtoms.peek().add(new Atom.LeafAtom(atomType, atomData)); input.skipFully((int) atomPayloadSize); } else { positionHolder.position = input.getPosition() + atomPayloadSize; seekRequired = true;