com.google.android.exoplayer.util.ParsableBitArray

Here are the examples of the java api class com.google.android.exoplayer.util.ParsableBitArray taken from open source projects.

1. VorbisBitArrayTest#testReadBitCompareWithMSb()

Project: ExoPlayer
Source File: VorbisBitArrayTest.java
View license
public void testReadBitCompareWithMSb() {
    byte[] data = { 0x0F };
    VorbisBitArray lsb = new VorbisBitArray(data);
    ParsableBitArray msb = new ParsableBitArray(data);
    assertEquals(lsb.readBit(), !msb.readBit());
    assertEquals(lsb.readBit(), !msb.readBit());
    assertEquals(lsb.readBit(), !msb.readBit());
    assertEquals(lsb.readBit(), !msb.readBit());
    assertEquals(lsb.readBit(), !msb.readBit());
    assertEquals(lsb.readBit(), !msb.readBit());
    assertEquals(lsb.readBit(), !msb.readBit());
    assertEquals(lsb.readBit(), !msb.readBit());
}

2. VorbisBitArrayTest#testReadBitsCompareWithMSbBeyondByteBoundary()

Project: ExoPlayer
Source File: VorbisBitArrayTest.java
View license
public void testReadBitsCompareWithMSbBeyondByteBoundary() {
    byte[] data = { (byte) 0xF0, 0x0F };
    VorbisBitArray lsb = new VorbisBitArray(data);
    ParsableBitArray msb = new ParsableBitArray(data);
    assertEquals(0x00, lsb.readBits(4));
    assertEquals(0x0F, msb.readBits(4));
    assertEquals(0xFF, lsb.readBits(8));
    assertEquals(0x00, msb.readBits(8));
    assertEquals(0x00, lsb.readBits(4));
    assertEquals(0x0F, msb.readBits(4));
}

3. H264Reader#unescape()

Project: ExoPlayer
Source File: H264Reader.java
View license
private static ParsableBitArray unescape(NalUnitTargetBuffer buffer) {
    int length = NalUnitUtil.unescapeStream(buffer.nalData, buffer.nalLength);
    ParsableBitArray bitArray = new ParsableBitArray(buffer.nalData, length);
    // NAL header
    bitArray.skipBits(32);
    return bitArray;
}

4. VorbisBitArrayTest#testReadBitsCompareWithMSb()

Project: ExoPlayer
Source File: VorbisBitArrayTest.java
View license
public void testReadBitsCompareWithMSb() {
    byte[] data = { 0x0F };
    VorbisBitArray lsb = new VorbisBitArray(data);
    ParsableBitArray msb = new ParsableBitArray(data);
    assertEquals(15, lsb.readBits(4));
    assertEquals(lsb.readBits(4), msb.readBits(4));
    assertEquals(15, msb.readBits(4));
}

5. AdtsExtractor#sniff()

Project: ExoPlayer
Source File: AdtsExtractor.java
View license
@Override
public boolean sniff(ExtractorInput input) throws IOException, InterruptedException {
    // Skip any ID3 headers.
    ParsableByteArray scratch = new ParsableByteArray(10);
    ParsableBitArray scratchBits = new ParsableBitArray(scratch.data);
    int startPosition = 0;
    while (true) {
        input.peekFully(scratch.data, 0, 10);
        scratch.setPosition(0);
        if (scratch.readUnsignedInt24() != ID3_TAG) {
            break;
        }
        int length = (scratch.data[6] & 0x7F) << 21 | ((scratch.data[7] & 0x7F) << 14) | ((scratch.data[8] & 0x7F) << 7) | (scratch.data[9] & 0x7F);
        startPosition += 10 + length;
        input.advancePeekPosition(length);
    }
    input.resetPeekPosition();
    input.advancePeekPosition(startPosition);
    // Try to find four or more consecutive AAC audio frames, exceeding the MPEG TS packet size.
    int headerPosition = startPosition;
    int validFramesSize = 0;
    int validFramesCount = 0;
    while (true) {
        input.peekFully(scratch.data, 0, 2);
        scratch.setPosition(0);
        int syncBytes = scratch.readUnsignedShort();
        if ((syncBytes & 0xFFF6) != 0xFFF0) {
            validFramesCount = 0;
            validFramesSize = 0;
            input.resetPeekPosition();
            if (++headerPosition - startPosition >= MAX_SNIFF_BYTES) {
                return false;
            }
            input.advancePeekPosition(headerPosition);
        } else {
            if (++validFramesCount >= 4 && validFramesSize > 188) {
                return true;
            }
            // Skip the frame.
            input.peekFully(scratch.data, 0, 4);
            scratchBits.setPosition(14);
            int frameSize = scratchBits.readBits(13);
            // Either the stream is malformed OR we're not parsing an ADTS stream.
            if (frameSize <= 6) {
                return false;
            }
            input.advancePeekPosition(frameSize - 6);
            validFramesSize += frameSize;
        }
    }
}