本文整理汇总了Java中com.google.android.exoplayer2.extractor.ExtractorInput.readFully方法的典型用法代码示例。如果您正苦于以下问题:Java ExtractorInput.readFully方法的具体用法?Java ExtractorInput.readFully怎么用?Java ExtractorInput.readFully使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.android.exoplayer2.extractor.ExtractorInput
的用法示例。
在下文中一共展示了ExtractorInput.readFully方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readAtomPayload
import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
/**
* Processes the atom payload. If {@link #atomData} is null and the size is at or above the
* threshold {@link #RELOAD_MINIMUM_SEEK_DISTANCE}, {@code true} is returned and the caller should
* restart loading at the position in {@code positionHolder}. Otherwise, the atom is read/skipped.
*/
private boolean readAtomPayload(ExtractorInput input, PositionHolder positionHolder)
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 (atomType == Atom.TYPE_ftyp) {
isQuickTime = processFtypAtom(atomData);
} else if (!containerAtoms.isEmpty()) {
containerAtoms.peek().add(new Atom.LeafAtom(atomType, atomData));
}
} else {
// We don't need the data. Skip or seek, depending on how large the atom is.
if (atomPayloadSize < RELOAD_MINIMUM_SEEK_DISTANCE) {
input.skipFully((int) atomPayloadSize);
} else {
positionHolder.position = input.getPosition() + atomPayloadSize;
seekRequired = true;
}
}
processAtomEnded(atomEndPosition);
return seekRequired && parserState != STATE_READING_SAMPLE;
}
示例2: readTagHeader
import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
/**
* Reads a tag header from the provided {@link ExtractorInput}.
*
* @param input The {@link ExtractorInput} from which to read.
* @return True if tag header was read successfully. Otherwise, false.
* @throws IOException If an error occurred reading or parsing data from the source.
* @throws InterruptedException If the thread was interrupted.
*/
private boolean readTagHeader(ExtractorInput input) throws IOException, InterruptedException {
if (!input.readFully(tagHeaderBuffer.data, 0, FLV_TAG_HEADER_SIZE, true)) {
// We've reached the end of the stream.
return false;
}
tagHeaderBuffer.setPosition(0);
tagType = tagHeaderBuffer.readUnsignedByte();
tagDataSize = tagHeaderBuffer.readUnsignedInt24();
tagTimestampUs = tagHeaderBuffer.readUnsignedInt24();
tagTimestampUs = ((tagHeaderBuffer.readUnsignedByte() << 24) | tagTimestampUs) * 1000L;
tagHeaderBuffer.skipBytes(3); // streamId
parserState = STATE_READING_TAG_DATA;
return true;
}
示例3: parseTimestampAndSampleCount
import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
private boolean parseTimestampAndSampleCount(ExtractorInput input) throws IOException,
InterruptedException {
dataScratch.reset();
if (version == 0) {
if (!input.readFully(dataScratch.data, 0, TIMESTAMP_SIZE_V0 + 1, true)) {
return false;
}
// version 0 timestamps are 45kHz, so we need to convert them into us
timestampUs = dataScratch.readUnsignedInt() * 1000 / 45;
} else if (version == 1) {
if (!input.readFully(dataScratch.data, 0, TIMESTAMP_SIZE_V1 + 1, true)) {
return false;
}
timestampUs = dataScratch.readLong();
} else {
throw new ParserException("Unsupported version number: " + version);
}
remainingSampleCount = dataScratch.readUnsignedByte();
sampleBytesWritten = 0;
return true;
}
示例4: readAtomPayload
import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
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);
}
processAtomEnded(input.getPosition());
}
示例5: readInteger
import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
/**
* 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;
}
示例6: readString
import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
/**
* 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 {
if (byteLength == 0) {
return "";
}
byte[] stringBytes = new byte[byteLength];
input.readFully(stringBytes, 0, byteLength);
return new String(stringBytes);
}
示例7: readUnsignedVarint
import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
/**
* Reads an EBML variable-length integer (varint) from an {@link ExtractorInput} such that
* reading can be resumed later if an error occurs having read only some of it.
* <p>
* If an value is successfully read, then the reader will automatically reset itself ready to
* read another value.
* <p>
* If an {@link IOException} or {@link InterruptedException} is throw, the read can be resumed
* later by calling this method again, passing an {@link ExtractorInput} providing data starting
* where the previous one left off.
*
* @param input The {@link ExtractorInput} from which the integer should be read.
* @param allowEndOfInput True if encountering the end of the input having read 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.
* @param removeLengthMask Removes the variable-length integer length mask from the value.
* @param maximumAllowedLength Maximum allowed length of the variable integer to be read.
* @return The read value, or {@link C#RESULT_END_OF_INPUT} if {@code allowEndOfStream} is true
* and the end of the input was encountered, or {@link C#RESULT_MAX_LENGTH_EXCEEDED} if the
* length of the varint exceeded maximumAllowedLength.
* @throws IOException If an error occurs reading from the input.
* @throws InterruptedException If the thread is interrupted.
*/
public long readUnsignedVarint(ExtractorInput input, boolean allowEndOfInput,
boolean removeLengthMask, int maximumAllowedLength) throws IOException, InterruptedException {
if (state == STATE_BEGIN_READING) {
// Read the first byte to establish the length.
if (!input.readFully(scratch, 0, 1, allowEndOfInput)) {
return C.RESULT_END_OF_INPUT;
}
int firstByte = scratch[0] & 0xFF;
length = parseUnsignedVarintLength(firstByte);
if (length == C.LENGTH_UNSET) {
throw new IllegalStateException("No valid varint length mask found");
}
state = STATE_READ_CONTENTS;
}
if (length > maximumAllowedLength) {
state = STATE_BEGIN_READING;
return C.RESULT_MAX_LENGTH_EXCEEDED;
}
if (length != 1) {
// Read the remaining bytes.
input.readFully(scratch, 1, length - 1);
}
state = STATE_BEGIN_READING;
return assembleVarint(scratch, length, removeLengthMask);
}
示例8: readScratch
import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
/**
* 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);
}
示例9: readToTarget
import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
/**
* 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;
}
示例10: readFlvHeader
import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
/**
* Reads an FLV container header from the provided {@link ExtractorInput}.
*
* @param input The {@link ExtractorInput} from which to read.
* @return True if header was read successfully. False if the end of stream was reached.
* @throws IOException If an error occurred reading or parsing data from the source.
* @throws InterruptedException If the thread was interrupted.
*/
private boolean readFlvHeader(ExtractorInput input) throws IOException, InterruptedException {
if (!input.readFully(headerBuffer.data, 0, FLV_HEADER_SIZE, true)) {
// We've reached the end of the stream.
return false;
}
headerBuffer.setPosition(0);
headerBuffer.skipBytes(4);
int flags = headerBuffer.readUnsignedByte();
boolean hasAudio = (flags & 0x04) != 0;
boolean hasVideo = (flags & 0x01) != 0;
if (hasAudio && audioReader == null) {
audioReader = new AudioTagPayloadReader(
extractorOutput.track(TAG_TYPE_AUDIO, C.TRACK_TYPE_AUDIO));
}
if (hasVideo && videoReader == null) {
videoReader = new VideoTagPayloadReader(
extractorOutput.track(TAG_TYPE_VIDEO, C.TRACK_TYPE_VIDEO));
}
if (metadataReader == null) {
metadataReader = new ScriptTagPayloadReader(null);
}
extractorOutput.endTracks();
extractorOutput.seekMap(this);
// We need to skip any additional content in the FLV header, plus the 4 byte previous tag size.
bytesToNextTagHeader = headerBuffer.readInt() - FLV_HEADER_SIZE + 4;
parserState = STATE_SKIPPING_TO_TAG_HEADER;
return true;
}
示例11: prepareTagData
import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
private ParsableByteArray prepareTagData(ExtractorInput input) throws IOException,
InterruptedException {
if (tagDataSize > tagData.capacity()) {
tagData.reset(new byte[Math.max(tagData.capacity() * 2, tagDataSize)], 0);
} else {
tagData.setPosition(0);
}
tagData.setLimit(tagDataSize);
input.readFully(tagData.data, 0, tagDataSize);
return tagData;
}
示例12: parseHeader
import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
private boolean parseHeader(ExtractorInput input) throws IOException, InterruptedException {
dataScratch.reset();
if (input.readFully(dataScratch.data, 0, HEADER_SIZE, true)) {
if (dataScratch.readInt() != HEADER_ID) {
throw new IOException("Input not RawCC");
}
version = dataScratch.readUnsignedByte();
// no versions use the flag fields yet
return true;
} else {
return false;
}
}
示例13: parseSamples
import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
private void parseSamples(ExtractorInput input) throws IOException, InterruptedException {
for (; remainingSampleCount > 0; remainingSampleCount--) {
dataScratch.reset();
input.readFully(dataScratch.data, 0, 3);
trackOutput.sampleData(dataScratch, 3);
sampleBytesWritten += 3;
}
if (sampleBytesWritten > 0) {
trackOutput.sampleMetadata(timestampUs, C.BUFFER_FLAG_KEY_FRAME, sampleBytesWritten, 0, null);
}
}
示例14: readFlvHeader
import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
/**
* Reads an FLV container header from the provided {@link ExtractorInput}.
*
* @param input The {@link ExtractorInput} from which to read.
* @return True if header was read successfully. False if the end of stream was reached.
* @throws IOException If an error occurred reading or parsing data from the source.
* @throws InterruptedException If the thread was interrupted.
*/
private boolean readFlvHeader(ExtractorInput input) throws IOException, InterruptedException {
if (!input.readFully(headerBuffer.data, 0, FLV_HEADER_SIZE, true)) {
// We've reached the end of the stream.
return false;
}
headerBuffer.setPosition(0);
headerBuffer.skipBytes(4);
int flags = headerBuffer.readUnsignedByte();
boolean hasAudio = (flags & 0x04) != 0;
boolean hasVideo = (flags & 0x01) != 0;
if (hasAudio && audioReader == null) {
audioReader = new AudioTagPayloadReader(extractorOutput.track(TAG_TYPE_AUDIO));
}
if (hasVideo && videoReader == null) {
videoReader = new VideoTagPayloadReader(extractorOutput.track(TAG_TYPE_VIDEO));
}
if (metadataReader == null) {
metadataReader = new ScriptTagPayloadReader(null);
}
extractorOutput.endTracks();
extractorOutput.seekMap(this);
// We need to skip any additional content in the FLV header, plus the 4 byte previous tag size.
bytesToNextTagHeader = headerBuffer.readInt() - FLV_HEADER_SIZE + 4;
parserState = STATE_SKIPPING_TO_TAG_HEADER;
return true;
}
示例15: readAtomHeader
import com.google.android.exoplayer2.extractor.ExtractorInput; //导入方法依赖的package包/类
private boolean readAtomHeader(ExtractorInput input) throws IOException, InterruptedException {
if (atomHeaderBytesRead == 0) {
// Read the standard length atom header.
if (!input.readFully(atomHeader.data, 0, Atom.HEADER_SIZE, true)) {
return false;
}
atomHeaderBytesRead = Atom.HEADER_SIZE;
atomHeader.setPosition(0);
atomSize = atomHeader.readUnsignedInt();
atomType = atomHeader.readInt();
}
if (atomSize == Atom.LONG_SIZE_PREFIX) {
// Read the extended atom size.
int headerBytesRemaining = Atom.LONG_HEADER_SIZE - Atom.HEADER_SIZE;
input.readFully(atomHeader.data, Atom.HEADER_SIZE, headerBytesRemaining);
atomHeaderBytesRead += headerBytesRemaining;
atomSize = atomHeader.readUnsignedLongToLong();
}
if (shouldParseContainerAtom(atomType)) {
long endPosition = input.getPosition() + atomSize - atomHeaderBytesRead;
containerAtoms.add(new ContainerAtom(atomType, endPosition));
if (atomSize == atomHeaderBytesRead) {
processAtomEnded(endPosition);
} else {
// Start reading the first child atom.
enterReadingAtomHeaderState();
}
} else if (shouldParseLeafAtom(atomType)) {
// We don't support parsing of leaf atoms that define extended atom sizes, or that have
// lengths greater than Integer.MAX_VALUE.
Assertions.checkState(atomHeaderBytesRead == Atom.HEADER_SIZE);
Assertions.checkState(atomSize <= Integer.MAX_VALUE);
atomData = new ParsableByteArray((int) atomSize);
System.arraycopy(atomHeader.data, 0, atomData.data, 0, Atom.HEADER_SIZE);
parserState = STATE_READING_ATOM_PAYLOAD;
} else {
atomData = null;
parserState = STATE_READING_ATOM_PAYLOAD;
}
return true;
}