use of com.google.android.exoplayer2.util.ParsableByteArray in project ExoPlayer by google.
the class PsshAtomUtil method parsePsshAtom.
/**
* Parses the UUID and scheme specific data from a PSSH atom. Version 0 and 1 PSSH atoms are
* supported.
*
* @param atom The atom to parse.
* @return A pair consisting of the parsed UUID and scheme specific data. Null if the input is
* not a valid PSSH atom, or if the PSSH atom has an unsupported version.
*/
private static Pair<UUID, byte[]> parsePsshAtom(byte[] atom) {
ParsableByteArray atomData = new ParsableByteArray(atom);
if (atomData.limit() < Atom.FULL_HEADER_SIZE + 16 + /* UUID */
4) /* DataSize */
{
// Data too short.
return null;
}
atomData.setPosition(0);
int atomSize = atomData.readInt();
if (atomSize != atomData.bytesLeft() + 4) {
// Not an atom, or incorrect atom size.
return null;
}
int atomType = atomData.readInt();
if (atomType != Atom.TYPE_pssh) {
// Not an atom, or incorrect atom type.
return null;
}
int atomVersion = Atom.parseFullAtomVersion(atomData.readInt());
if (atomVersion > 1) {
Log.w(TAG, "Unsupported pssh version: " + atomVersion);
return null;
}
UUID uuid = new UUID(atomData.readLong(), atomData.readLong());
if (atomVersion == 1) {
int keyIdCount = atomData.readUnsignedIntToInt();
atomData.skipBytes(16 * keyIdCount);
}
int dataSize = atomData.readUnsignedIntToInt();
if (dataSize != atomData.bytesLeft()) {
// Incorrect dataSize.
return null;
}
byte[] data = new byte[dataSize];
atomData.readBytes(data, 0, dataSize);
return Pair.create(uuid, data);
}
use of com.google.android.exoplayer2.util.ParsableByteArray in project ExoPlayer by google.
the class FlacReader method readHeaders.
@Override
protected boolean readHeaders(ParsableByteArray packet, long position, SetupData setupData) throws IOException, InterruptedException {
byte[] data = packet.data;
if (streamInfo == null) {
streamInfo = new FlacStreamInfo(data, 17);
byte[] metadata = Arrays.copyOfRange(data, 9, packet.limit());
// Set the last metadata block flag, ignore the other blocks
metadata[4] = (byte) 0x80;
List<byte[]> initializationData = Collections.singletonList(metadata);
setupData.format = Format.createAudioSampleFormat(null, MimeTypes.AUDIO_FLAC, null, Format.NO_VALUE, streamInfo.bitRate(), streamInfo.channels, streamInfo.sampleRate, initializationData, null, 0, null);
} else if ((data[0] & 0x7F) == SEEKTABLE_PACKET_TYPE) {
flacOggSeeker = new FlacOggSeeker();
flacOggSeeker.parseSeekTable(packet);
} else if (isAudioPacket(data)) {
if (flacOggSeeker != null) {
flacOggSeeker.setFirstFrameOffset(position);
setupData.oggSeeker = flacOggSeeker;
}
return false;
}
return true;
}
use of com.google.android.exoplayer2.util.ParsableByteArray in project ExoPlayer by google.
the class OggExtractor method sniff.
@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;
}
}
Aggregations