Search in sources :

Example 21 with ParsableByteArray

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());
}
Also used : ParsableByteArray(com.google.android.exoplayer2.util.ParsableByteArray)

Example 22 with ParsableByteArray

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());
}
Also used : ParsableByteArray(com.google.android.exoplayer2.util.ParsableByteArray)

Example 23 with ParsableByteArray

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);
    }
}
Also used : ParserException(com.google.android.exoplayer2.ParserException) ArrayList(java.util.ArrayList) SpsData(com.google.android.exoplayer2.util.NalUnitUtil.SpsData)

Example 24 with ParsableByteArray

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);
    }
}
Also used : ParserException(com.google.android.exoplayer2.ParserException)

Example 25 with ParsableByteArray

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]);
}
Also used : ParsableByteArray(com.google.android.exoplayer2.util.ParsableByteArray)

Aggregations

ParsableByteArray (com.google.android.exoplayer2.util.ParsableByteArray)48 ParserException (com.google.android.exoplayer2.ParserException)11 Format (com.google.android.exoplayer2.Format)6 ArrayList (java.util.ArrayList)4 SeekMap (com.google.android.exoplayer2.extractor.SeekMap)3 Metadata (com.google.android.exoplayer2.metadata.Metadata)3 TrackOutput (com.google.android.exoplayer2.extractor.TrackOutput)2 ContainerAtom (com.google.android.exoplayer2.extractor.mp4.Atom.ContainerAtom)2 FlacStreamInfo (com.google.android.exoplayer2.util.FlacStreamInfo)2 AvcConfig (com.google.android.exoplayer2.video.AvcConfig)2 ByteBuffer (java.nio.ByteBuffer)2 Matcher (java.util.regex.Matcher)2 Spanned (android.text.Spanned)1 ChunkIndex (com.google.android.exoplayer2.extractor.ChunkIndex)1 MpegAudioHeader (com.google.android.exoplayer2.extractor.MpegAudioHeader)1 LeafAtom (com.google.android.exoplayer2.extractor.mp4.Atom.LeafAtom)1 TrackIdGenerator (com.google.android.exoplayer2.extractor.ts.TsPayloadReader.TrackIdGenerator)1 CommentFrame (com.google.android.exoplayer2.metadata.id3.CommentFrame)1 TextInformationFrame (com.google.android.exoplayer2.metadata.id3.TextInformationFrame)1 FakeExtractorOutput (com.google.android.exoplayer2.testutil.FakeExtractorOutput)1