use of com.google.android.exoplayer2.util.ParsableByteArray in project ExoPlayer by google.
the class CssParserTest method assertInputLimit.
private void assertInputLimit(String expectedLine, String s) {
ParsableByteArray input = new ParsableByteArray(Util.getUtf8Bytes(s));
CssParser.skipStyleBlock(input);
assertEquals(expectedLine, input.readLine());
}
use of com.google.android.exoplayer2.util.ParsableByteArray in project ExoPlayer by google.
the class CssParserTest method assertParserProduces.
private void assertParserProduces(WebvttCssStyle expected, String styleBlock) {
ParsableByteArray input = new ParsableByteArray(Util.getUtf8Bytes(styleBlock));
WebvttCssStyle actualElem = parser.parseBlock(input);
assertEquals(expected.hasBackgroundColor(), actualElem.hasBackgroundColor());
if (expected.hasBackgroundColor()) {
assertEquals(expected.getBackgroundColor(), actualElem.getBackgroundColor());
}
assertEquals(expected.hasFontColor(), actualElem.hasFontColor());
if (expected.hasFontColor()) {
assertEquals(expected.getFontColor(), actualElem.getFontColor());
}
assertEquals(expected.getFontFamily(), actualElem.getFontFamily());
assertEquals(expected.getFontSize(), actualElem.getFontSize());
assertEquals(expected.getFontSizeUnit(), actualElem.getFontSizeUnit());
assertEquals(expected.getStyle(), actualElem.getStyle());
assertEquals(expected.isLinethrough(), actualElem.isLinethrough());
assertEquals(expected.isUnderline(), actualElem.isUnderline());
assertEquals(expected.getTextAlign(), actualElem.getTextAlign());
}
use of com.google.android.exoplayer2.util.ParsableByteArray in project ExoPlayer by google.
the class AvcConfig method parse.
/**
* Parses AVC configuration data.
*
* @param data A {@link ParsableByteArray}, whose position is set to the start of the AVC
* configuration data to parse.
* @return A parsed representation of the HEVC configuration data.
* @throws ParserException If an error occurred parsing the data.
*/
public static AvcConfig parse(ParsableByteArray data) throws ParserException {
try {
// Skip to the AVCDecoderConfigurationRecord (defined in 14496-15)
data.skipBytes(4);
int nalUnitLengthFieldLength = (data.readUnsignedByte() & 0x3) + 1;
if (nalUnitLengthFieldLength == 3) {
throw new IllegalStateException();
}
List<byte[]> initializationData = new ArrayList<>();
int numSequenceParameterSets = data.readUnsignedByte() & 0x1F;
for (int j = 0; j < numSequenceParameterSets; j++) {
initializationData.add(buildNalUnitForChild(data));
}
int numPictureParameterSets = data.readUnsignedByte();
for (int j = 0; j < numPictureParameterSets; j++) {
initializationData.add(buildNalUnitForChild(data));
}
int width = Format.NO_VALUE;
int height = Format.NO_VALUE;
float pixelWidthAspectRatio = 1;
if (numSequenceParameterSets > 0) {
byte[] sps = initializationData.get(0);
SpsData spsData = NalUnitUtil.parseSpsNalUnit(initializationData.get(0), nalUnitLengthFieldLength, sps.length);
width = spsData.width;
height = spsData.height;
pixelWidthAspectRatio = spsData.pixelWidthAspectRatio;
}
return new AvcConfig(initializationData, nalUnitLengthFieldLength, width, height, pixelWidthAspectRatio);
} catch (ArrayIndexOutOfBoundsException e) {
throw new ParserException("Error parsing AVC config", e);
}
}
use of com.google.android.exoplayer2.util.ParsableByteArray in project ExoPlayer by google.
the class HevcConfig method parse.
/**
* Parses HEVC configuration data.
*
* @param data A {@link ParsableByteArray}, whose position is set to the start of the HEVC
* configuration data to parse.
* @return A parsed representation of the HEVC configuration data.
* @throws ParserException If an error occurred parsing the data.
*/
public static HevcConfig parse(ParsableByteArray data) throws ParserException {
try {
// Skip to the NAL unit length size field.
data.skipBytes(21);
int lengthSizeMinusOne = data.readUnsignedByte() & 0x03;
// Calculate the combined size of all VPS/SPS/PPS bitstreams.
int numberOfArrays = data.readUnsignedByte();
int csdLength = 0;
int csdStartPosition = data.getPosition();
for (int i = 0; i < numberOfArrays; i++) {
// completeness (1), nal_unit_type (7)
data.skipBytes(1);
int numberOfNalUnits = data.readUnsignedShort();
for (int j = 0; j < numberOfNalUnits; j++) {
int nalUnitLength = data.readUnsignedShort();
// Start code and NAL unit.
csdLength += 4 + nalUnitLength;
data.skipBytes(nalUnitLength);
}
}
// Concatenate the codec-specific data into a single buffer.
data.setPosition(csdStartPosition);
byte[] buffer = new byte[csdLength];
int bufferPosition = 0;
for (int i = 0; i < numberOfArrays; i++) {
// completeness (1), nal_unit_type (7)
data.skipBytes(1);
int numberOfNalUnits = data.readUnsignedShort();
for (int j = 0; j < numberOfNalUnits; j++) {
int nalUnitLength = data.readUnsignedShort();
System.arraycopy(NalUnitUtil.NAL_START_CODE, 0, buffer, bufferPosition, NalUnitUtil.NAL_START_CODE.length);
bufferPosition += NalUnitUtil.NAL_START_CODE.length;
System.arraycopy(data.data, data.getPosition(), buffer, bufferPosition, nalUnitLength);
bufferPosition += nalUnitLength;
data.skipBytes(nalUnitLength);
}
}
List<byte[]> initializationData = csdLength == 0 ? null : Collections.singletonList(buffer);
return new HevcConfig(initializationData, lengthSizeMinusOne + 1);
} catch (ArrayIndexOutOfBoundsException e) {
throw new ParserException("Error parsing HEVC config", e);
}
}
use of com.google.android.exoplayer2.util.ParsableByteArray in project ExoPlayer by google.
the class VorbisUtilTest method testReadCommentHeader.
public void testReadCommentHeader() throws ParserException {
byte[] data = TestData.getCommentHeaderDataUTF8();
ParsableByteArray headerData = new ParsableByteArray(data, data.length);
VorbisUtil.CommentHeader commentHeader = VorbisUtil.readVorbisCommentHeader(headerData);
assertEquals("Xiph.Org libVorbis I 20120203 (Omnipresent)", commentHeader.vendor);
assertEquals(3, commentHeader.comments.length);
assertEquals("ALBUM=รครถ", commentHeader.comments[0]);
assertEquals("TITLE=A sample song", commentHeader.comments[1]);
assertEquals("ARTIST=Google", commentHeader.comments[2]);
}
Aggregations