本文整理汇总了Java中com.google.android.exoplayer2.util.ParsableByteArray类的典型用法代码示例。如果您正苦于以下问题:Java ParsableByteArray类的具体用法?Java ParsableByteArray怎么用?Java ParsableByteArray使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ParsableByteArray类属于com.google.android.exoplayer2.util包,在下文中一共展示了ParsableByteArray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: TsExtractor
import com.google.android.exoplayer2.util.ParsableByteArray; //导入依赖的package包/类
/**
* @param mode Mode for the extractor. One of {@link #MODE_MULTI_PMT}, {@link #MODE_SINGLE_PMT}
* and {@link #MODE_HLS}.
* @param timestampAdjuster A timestamp adjuster for offsetting and scaling sample timestamps.
* @param payloadReaderFactory Factory for injecting a custom set of payload readers.
*/
public TsExtractor(@Mode int mode, TimestampAdjuster timestampAdjuster,
TsPayloadReader.Factory payloadReaderFactory) {
this.payloadReaderFactory = Assertions.checkNotNull(payloadReaderFactory);
this.mode = mode;
if (mode == MODE_SINGLE_PMT || mode == MODE_HLS) {
timestampAdjusters = Collections.singletonList(timestampAdjuster);
} else {
timestampAdjusters = new ArrayList<>();
timestampAdjusters.add(timestampAdjuster);
}
tsPacketBuffer = new ParsableByteArray(BUFFER_SIZE);
tsScratch = new ParsableBitArray(new byte[3]);
trackIds = new SparseBooleanArray();
tsPayloadReaders = new SparseArray<>();
continuityCounters = new SparseIntArray();
resetPayloadReaders();
}
示例2: parseCoverArt
import com.google.android.exoplayer2.util.ParsableByteArray; //导入依赖的package包/类
private static ApicFrame parseCoverArt(ParsableByteArray data) {
int atomSize = data.readInt();
int atomType = data.readInt();
if (atomType == Atom.TYPE_data) {
int fullVersionInt = data.readInt();
int flags = Atom.parseFullAtomFlags(fullVersionInt);
String mimeType = flags == 13 ? "image/jpeg" : flags == 14 ? "image/png" : null;
if (mimeType == null) {
Log.w(TAG, "Unrecognized cover art flags: " + flags);
return null;
}
data.skipBytes(4); // empty (4)
byte[] pictureData = new byte[atomSize - 16];
data.readBytes(pictureData, 0, pictureData.length);
return new ApicFrame(mimeType, null, 3 /* Cover (front) */, pictureData);
}
Log.w(TAG, "Failed to parse cover art attribute");
return null;
}
示例3: skipToNextSync
import com.google.android.exoplayer2.util.ParsableByteArray; //导入依赖的package包/类
/**
* Locates the next syncword, advancing the position to the byte that immediately follows it. If a
* syncword was not located, the position is advanced to the limit.
*
* @param pesBuffer The buffer whose position should be advanced.
* @return Whether a syncword position was found.
*/
private boolean skipToNextSync(ParsableByteArray pesBuffer) {
while (pesBuffer.bytesLeft() > 0) {
if (!lastByteWas0B) {
lastByteWas0B = pesBuffer.readUnsignedByte() == 0x0B;
continue;
}
int secondByte = pesBuffer.readUnsignedByte();
if (secondByte == 0x77) {
lastByteWas0B = false;
return true;
} else {
lastByteWas0B = secondByte == 0x0B;
}
}
return false;
}
示例4: consume
import com.google.android.exoplayer2.util.ParsableByteArray; //导入依赖的package包/类
@Override
public void consume(ParsableByteArray data) {
while (data.bytesLeft() > 0) {
switch (state) {
case STATE_FINDING_HEADER:
findHeader(data);
break;
case STATE_READING_HEADER:
readHeaderRemainder(data);
break;
case STATE_READING_FRAME:
readFrameRemainder(data);
break;
}
}
}
示例5: readAmfData
import com.google.android.exoplayer2.util.ParsableByteArray; //导入依赖的package包/类
private static Object readAmfData(ParsableByteArray data, int type) {
switch (type) {
case AMF_TYPE_NUMBER:
return readAmfDouble(data);
case AMF_TYPE_BOOLEAN:
return readAmfBoolean(data);
case AMF_TYPE_STRING:
return readAmfString(data);
case AMF_TYPE_OBJECT:
return readAmfObject(data);
case AMF_TYPE_ECMA_ARRAY:
return readAmfEcmaArray(data);
case AMF_TYPE_STRICT_ARRAY:
return readAmfStrictArray(data);
case AMF_TYPE_DATE:
return readAmfDate(data);
default:
return null;
}
}
示例6: parsePayload
import com.google.android.exoplayer2.util.ParsableByteArray; //导入依赖的package包/类
@Override
protected void parsePayload(ParsableByteArray data, long timeUs) throws ParserException {
int nameType = readAmfType(data);
if (nameType != AMF_TYPE_STRING) {
// Should never happen.
throw new ParserException();
}
String name = readAmfString(data);
if (!NAME_METADATA.equals(name)) {
// We're only interested in metadata.
return;
}
int type = readAmfType(data);
if (type != AMF_TYPE_ECMA_ARRAY) {
// We're not interested in this metadata.
return;
}
// Set the duration to the value contained in the metadata, if present.
Map<String, Object> metadata = readAmfEcmaArray(data);
if (metadata.containsKey(KEY_DURATION)) {
double durationSeconds = (double) metadata.get(KEY_DURATION);
if (durationSeconds > 0.0) {
durationUs = (long) (durationSeconds * C.MICROS_PER_SECOND);
}
}
}
示例7: parseMsAcmCodecPrivate
import com.google.android.exoplayer2.util.ParsableByteArray; //导入依赖的package包/类
/**
* Parses an MS/ACM codec private, returning whether it indicates PCM audio.
*
* @return Whether the codec private indicates PCM audio.
* @throws ParserException If a parsing error occurs.
*/
private static boolean parseMsAcmCodecPrivate(ParsableByteArray buffer) throws ParserException {
try {
int formatTag = buffer.readLittleEndianUnsignedShort();
if (formatTag == WAVE_FORMAT_PCM) {
return true;
} else if (formatTag == WAVE_FORMAT_EXTENSIBLE) {
buffer.setPosition(WAVE_FORMAT_SIZE + 6); // unionSamples(2), channelMask(4)
return buffer.readLong() == WAVE_SUBFORMAT_PCM.getMostSignificantBits()
&& buffer.readLong() == WAVE_SUBFORMAT_PCM.getLeastSignificantBits();
} else {
return false;
}
} catch (ArrayIndexOutOfBoundsException e) {
throw new ParserException("Error parsing MS/ACM codec private");
}
}
示例8: consume
import com.google.android.exoplayer2.util.ParsableByteArray; //导入依赖的package包/类
@Override
public void consume(ParsableByteArray data) {
while (data.bytesLeft() > 0) {
switch (state) {
case STATE_FINDING_SAMPLE:
findNextSample(data);
break;
case STATE_READING_ID3_HEADER:
if (continueRead(data, id3HeaderBuffer.data, ID3_HEADER_SIZE)) {
parseId3Header();
}
break;
case STATE_READING_ADTS_HEADER:
int targetLength = hasCrc ? HEADER_SIZE + CRC_SIZE : HEADER_SIZE;
if (continueRead(data, adtsScratch.data, targetLength)) {
parseAdtsHeader();
}
break;
case STATE_READING_SAMPLE:
readSample(data);
break;
}
}
}
示例9: consume
import com.google.android.exoplayer2.util.ParsableByteArray; //导入依赖的package包/类
@Override
public void consume(ParsableByteArray sectionData) {
if (!formatDeclared) {
if (timestampAdjuster.getTimestampOffsetUs() == C.TIME_UNSET) {
// There is not enough information to initialize the timestamp adjuster.
return;
}
output.format(Format.createSampleFormat(null, MimeTypes.APPLICATION_SCTE35,
timestampAdjuster.getTimestampOffsetUs()));
formatDeclared = true;
}
int sampleSize = sectionData.bytesLeft();
output.sampleData(sectionData, sampleSize);
output.sampleMetadata(timestampAdjuster.getLastAdjustedTimestampUs(), C.BUFFER_FLAG_KEY_FRAME,
sampleSize, 0, null);
}
示例10: decodePrivFrame
import com.google.android.exoplayer2.util.ParsableByteArray; //导入依赖的package包/类
private static PrivFrame decodePrivFrame(ParsableByteArray id3Data, int frameSize)
throws UnsupportedEncodingException {
byte[] data = new byte[frameSize];
id3Data.readBytes(data, 0, frameSize);
int ownerEndIndex = indexOfZeroByte(data, 0);
String owner = new String(data, 0, ownerEndIndex, "ISO-8859-1");
byte[] privateData;
int privateDataStartIndex = ownerEndIndex + 1;
if (privateDataStartIndex < data.length) {
privateData = Arrays.copyOfRange(data, privateDataStartIndex, data.length);
} else {
privateData = new byte[0];
}
return new PrivFrame(owner, privateData);
}
示例11: consume
import com.google.android.exoplayer2.util.ParsableByteArray; //导入依赖的package包/类
@Override
public void consume(ParsableByteArray data) {
if (writingSample) {
if (bytesToCheck == 2 && !checkNextByte(data, 0x20)) {
// Failed to check data_identifier
return;
}
if (bytesToCheck == 1 && !checkNextByte(data, 0x00)) {
// Check and discard the subtitle_stream_id
return;
}
int dataPosition = data.getPosition();
int bytesAvailable = data.bytesLeft();
for (TrackOutput output : outputs) {
data.setPosition(dataPosition);
output.sampleData(data, bytesAvailable);
}
sampleBytesWritten += bytesAvailable;
}
}
示例12: readHeaders
import com.google.android.exoplayer2.util.ParsableByteArray; //导入依赖的package包/类
@Override
protected boolean readHeaders(ParsableByteArray packet, long position, SetupData setupData)
throws IOException, InterruptedException {
if (vorbisSetup != null) {
return false;
}
vorbisSetup = readSetupHeaders(packet);
if (vorbisSetup == null) {
return true;
}
ArrayList<byte[]> codecInitialisationData = new ArrayList<>();
codecInitialisationData.add(vorbisSetup.idHeader.data);
codecInitialisationData.add(vorbisSetup.setupHeaderData);
setupData.format = Format.createAudioSampleFormat(null, MimeTypes.AUDIO_VORBIS, null,
this.vorbisSetup.idHeader.bitrateNominal, Format.NO_VALUE,
this.vorbisSetup.idHeader.channels, (int) this.vorbisSetup.idHeader.sampleRate,
codecInitialisationData, null, 0, null);
return true;
}
示例13: sniff
import com.google.android.exoplayer2.util.ParsableByteArray; //导入依赖的package包/类
@Override
public boolean sniff(ExtractorInput input) throws IOException, InterruptedException {
try {
OggPageHeader header = new OggPageHeader();
if (!header.populate(input, true) || (header.type & 0x02) != 0x02) {
return false;
}
int length = Math.min(header.bodySize, MAX_VERIFICATION_BYTES);
ParsableByteArray scratch = new ParsableByteArray(length);
input.peekFully(scratch.data, 0, length);
if (FlacReader.verifyBitstreamType(resetPosition(scratch))) {
streamReader = new FlacReader();
} else if (VorbisReader.verifyBitstreamType(resetPosition(scratch))) {
streamReader = new VorbisReader();
} else if (OpusReader.verifyBitstreamType(resetPosition(scratch))) {
streamReader = new OpusReader();
} else {
return false;
}
return true;
} catch (ParserException e) {
return false;
}
}
示例14: parseVttCueBox
import com.google.android.exoplayer2.util.ParsableByteArray; //导入依赖的package包/类
private static Cue parseVttCueBox(ParsableByteArray sampleData, WebvttCue.Builder builder,
int remainingCueBoxBytes) throws SubtitleDecoderException {
builder.reset();
while (remainingCueBoxBytes > 0) {
if (remainingCueBoxBytes < BOX_HEADER_SIZE) {
throw new SubtitleDecoderException("Incomplete vtt cue box header found.");
}
int boxSize = sampleData.readInt();
int boxType = sampleData.readInt();
remainingCueBoxBytes -= BOX_HEADER_SIZE;
int payloadLength = boxSize - BOX_HEADER_SIZE;
String boxPayload = new String(sampleData.data, sampleData.getPosition(), payloadLength);
sampleData.skipBytes(payloadLength);
remainingCueBoxBytes -= payloadLength;
if (boxType == TYPE_sttg) {
WebvttCueParser.parseCueSettingsList(boxPayload, builder);
} else if (boxType == TYPE_payl) {
WebvttCueParser.parseCueText(null, boxPayload.trim(), builder,
Collections.<WebvttCssStyle>emptyList());
} else {
// Other VTTCueBox children are still not supported and are ignored.
}
}
return builder.build();
}
示例15: readHeaders
import com.google.android.exoplayer2.util.ParsableByteArray; //导入依赖的package包/类
@Override
protected boolean readHeaders(ParsableByteArray packet, long position, SetupData setupData)
throws IOException, InterruptedException {
if (!headerRead) {
byte[] metadata = Arrays.copyOf(packet.data, packet.limit());
int channelCount = metadata[9] & 0xFF;
int preskip = ((metadata[11] & 0xFF) << 8) | (metadata[10] & 0xFF);
List<byte[]> initializationData = new ArrayList<>(3);
initializationData.add(metadata);
putNativeOrderLong(initializationData, preskip);
putNativeOrderLong(initializationData, DEFAULT_SEEK_PRE_ROLL_SAMPLES);
setupData.format = Format.createAudioSampleFormat(null, MimeTypes.AUDIO_OPUS, null,
Format.NO_VALUE, Format.NO_VALUE, channelCount, SAMPLE_RATE, initializationData, null, 0,
null);
headerRead = true;
} else {
boolean headerPacket = packet.readInt() == OPUS_CODE;
packet.setPosition(0);
return headerPacket;
}
return true;
}