FileDocCategorySizeDatePackage
BitReaderBuffer.javaAPI Docmp4parser 1.0-RC-171241Wed Dec 19 20:10:37 GMT 2012com.googlecode.mp4parser.boxes.mp4.objectdescriptors

BitReaderBuffer

public class BitReaderBuffer extends Object

Fields Summary
private ByteBuffer
buffer
int
initialPos
int
position
Constructors Summary
public BitReaderBuffer(ByteBuffer buffer)

        this.buffer = buffer;
        initialPos = buffer.position();
    
Methods Summary
public intbyteSync()

        int left = 8 - position % 8;
        if (left == 8) {
            left = 0;
        }
        readBits(left);
        return left;
    
public intgetPosition()

        return position;
    
public intreadBits(int i)

        byte b = buffer.get(initialPos + position / 8);
        int v = b < 0 ? b + 256 : b;
        int left = 8 - position % 8;
        int rc;
        if (i <= left) {
            rc = (v << (position % 8) & 0xFF) >> ((position % 8) + (left - i));
            position += i;
        } else {
            int now = left;
            int then = i - left;
            rc = readBits(now);
            rc = rc << then;
            rc += readBits(then);
        }
        buffer.position(initialPos + (int) Math.ceil((double) position / 8));
        return rc;
    
public intremainingBits()

        return buffer.limit() * 8 - position;