FileDocCategorySizeDatePackage
BitstreamWriter.javaAPI Docmp4parser 1.0-RC-173192Wed Dec 19 20:10:37 GMT 2012com.googlecode.mp4parser.h264.write

BitstreamWriter

public class BitstreamWriter extends Object
A dummy implementation of H264 RBSP output stream
author
Stanislav Vitvitskiy

Fields Summary
private final OutputStream
os
private int[]
curByte
private int
curBit
Constructors Summary
public BitstreamWriter(OutputStream out)


       
        this.os = out;
    
Methods Summary
public voidflush()

        for (int i = curBit; i < 8; i++) {
            curByte[i] = 0;
        }
        curBit = 0;
        writeCurByte();
    
public voidwrite1Bit(int value)

        Debug.print(value);
        if (curBit == 8) {
            curBit = 0;
            writeCurByte();
        }
        curByte[curBit++] = value;
    
public voidwriteByte(int b)

        os.write(b);

    
private voidwriteCurByte()

        int toWrite = (curByte[0] << 7) | (curByte[1] << 6) | (curByte[2] << 5)
                | (curByte[3] << 4) | (curByte[4] << 3) | (curByte[5] << 2)
                | (curByte[6] << 1) | curByte[7];
        os.write(toWrite);
    
public voidwriteNBit(long value, int n)

        for (int i = 0; i < n; i++) {
            write1Bit((int) (value >> (n - i - 1)) & 0x1);
        }
    
public voidwriteRemainingZero()

        writeNBit(0, 8 - curBit);