FileDocCategorySizeDatePackage
IsoSampleNALUnitReader.javaAPI Docmp4parser 1.0-RC-172775Wed Dec 19 20:10:21 GMT 2012com.coremedia.iso.gui

IsoSampleNALUnitReader

public class IsoSampleNALUnitReader extends Object
Input stream that automatically unwraps NAL units and allows for NAL unit navigation
author
Stanislav Vitvitskiy

Fields Summary
private final ByteBuffer
src
private int
nalLengthSize
Constructors Summary
public IsoSampleNALUnitReader(ByteBuffer src, int nalLengthSize)


           
        this.src = src;
        this.nalLengthSize = nalLengthSize;
    
Methods Summary
public java.nio.ByteBuffernextNALUnit()

        if (src.remaining() < 5) {
            return null;
        }

        long nalLength;
        if (src.remaining() >= nalLengthSize) {

            if (nalLengthSize == 1) {
                nalLength = IsoTypeReader.readUInt8(src);
            } else if (nalLengthSize == 2) {
                nalLength = IsoTypeReader.readUInt16(src);
            } else if (nalLengthSize == 3) {
                nalLength = IsoTypeReader.readUInt24(src);
            } else if (nalLengthSize == 4) {
                nalLength = IsoTypeReader.readUInt32(src);
            } else {
                throw new IOException("Unknown NAL Length isze ");
            }

            if (nalLength == 0) {
                return null;
            }
            ByteBuffer nal = src.slice();
            nal.limit(l2i(nalLength));
            src.position(src.position() + l2i(nalLength));
            return nal;
        } else {
            throw new RuntimeException("remaining bytes less than nalLengthSize found in sample. should not be here.");
        }