FileDocCategorySizeDatePackage
TrackRunBox.javaAPI Docmp4parser 1.0-RC-1711046Wed Dec 19 20:10:38 GMT 2012com.coremedia.iso.boxes.fragment

TrackRunBox

public class TrackRunBox extends com.googlecode.mp4parser.AbstractFullBox
aligned(8) class TrackRunBox extends FullBox('trun', 0, tr_flags) { unsigned int(32) sample_count; // the following are optional fields signed int(32) data_offset; unsigned int(32) first_sample_flags; // all fields in the following array are optional { unsigned int(32) sample_duration; unsigned int(32) sample_size; unsigned int(32) sample_flags unsigned int(32) sample_composition_time_offset; }[ sample_count ] }

Fields Summary
public static final String
TYPE
private int
dataOffset
private SampleFlags
firstSampleFlags
private List
entries
Constructors Summary
public TrackRunBox()

        super(TYPE);
    
Methods Summary
public void_parseDetails(java.nio.ByteBuffer content)

        parseVersionAndFlags(content);
        long sampleCount = IsoTypeReader.readUInt32(content);

        if ((getFlags() & 0x1) == 1) { //dataOffsetPresent
            dataOffset = l2i(IsoTypeReader.readUInt32(content));
        } else {
            dataOffset = -1;
        }
        if ((getFlags() & 0x4) == 0x4) { //firstSampleFlagsPresent
            firstSampleFlags = new SampleFlags(content);
        }

        for (int i = 0; i < sampleCount; i++) {
            Entry entry = new Entry();
            if ((getFlags() & 0x100) == 0x100) { //sampleDurationPresent
                entry.sampleDuration = IsoTypeReader.readUInt32(content);
            }
            if ((getFlags() & 0x200) == 0x200) { //sampleSizePresent
                entry.sampleSize = IsoTypeReader.readUInt32(content);
            }
            if ((getFlags() & 0x400) == 0x400) { //sampleFlagsPresent
                entry.sampleFlags = new SampleFlags(content);
            }
            if ((getFlags() & 0x800) == 0x800) { //sampleCompositionTimeOffsetPresent
                entry.sampleCompositionTimeOffset = content.getInt();
            }
            entries.add(entry);
        }

    
protected voidgetContent(java.nio.ByteBuffer byteBuffer)

        writeVersionAndFlags(byteBuffer);
        IsoTypeWriter.writeUInt32(byteBuffer, entries.size());
        int flags = getFlags();

        if ((flags & 0x1) == 1) { //dataOffsetPresent
            IsoTypeWriter.writeUInt32(byteBuffer, dataOffset);
        }
        if ((flags & 0x4) == 0x4) { //firstSampleFlagsPresent
            firstSampleFlags.getContent(byteBuffer);
        }

        for (Entry entry : entries) {
            if ((flags & 0x100) == 0x100) { //sampleDurationPresent
                IsoTypeWriter.writeUInt32(byteBuffer, entry.sampleDuration);
            }
            if ((flags & 0x200) == 0x200) { //sampleSizePresent
                IsoTypeWriter.writeUInt32(byteBuffer, entry.sampleSize);
            }
            if ((flags & 0x400) == 0x400) { //sampleFlagsPresent
                entry.sampleFlags.getContent(byteBuffer);
            }
            if ((flags & 0x800) == 0x800) { //sampleCompositionTimeOffsetPresent
                byteBuffer.putInt(entry.sampleCompositionTimeOffset);
            }
        }
    
protected longgetContentSize()

        long size = 8;
        int flags = getFlags();

        if ((flags & 0x1) == 0x1) { //dataOffsetPresent
            size += 4;
        }
        if ((flags & 0x4) == 0x4) { //firstSampleFlagsPresent
            size += 4;
        }

        long entrySize = 0;
        if ((flags & 0x100) == 0x100) { //sampleDurationPresent
            entrySize += 4;
        }
        if ((flags & 0x200) == 0x200) { //sampleSizePresent
            entrySize += 4;
        }
        if ((flags & 0x400) == 0x400) { //sampleFlagsPresent
            entrySize += 4;
        }
        if ((flags & 0x800) == 0x800) { //sampleCompositionTimeOffsetPresent
            entrySize += 4;
        }
        size += entrySize * entries.size();
        return size;
    
public intgetDataOffset()

        return dataOffset;
    
public java.util.ListgetEntries()



       
        return entries;
    
public SampleFlagsgetFirstSampleFlags()

        return firstSampleFlags;
    
public long[]getSampleCompositionTimeOffsets()

        if (isSampleCompositionTimeOffsetPresent()) {
            long[] result = new long[entries.size()];

            for (int i = 0; i < result.length; i++) {
                result[i] = entries.get(i).getSampleCompositionTimeOffset();
            }
            return result;
        }
        return null;
    
public longgetSampleCount()

        return entries.size();
    
public TrackExtendsBoxgetTrackExtendsBox()

        final TrackFragmentHeaderBox tfhd = ((TrackFragmentBox) getParent()).getTrackFragmentHeaderBox();
        final List<MovieBox> movieBoxes = tfhd.getIsoFile().getBoxes(MovieBox.class);
        if (movieBoxes.size() == 0) {
            return null;
        }

        final List<TrackExtendsBox> trexBoxes = movieBoxes.get(0).getBoxes(TrackExtendsBox.class, true);
        TrackExtendsBox trex = null;
        for (TrackExtendsBox aTrex : trexBoxes) {
            if (aTrex.getTrackId() == tfhd.getTrackId()) {
                trex = aTrex;
            }
        }
        return trex;
    
public booleanisDataOffsetPresent()

        return (getFlags() & 0x1) == 1;
    
public booleanisFirstSampleFlagsPresent()

        return (getFlags() & 0x4) == 0x4;
    
public booleanisSampleCompositionTimeOffsetPresent()

        return (getFlags() & 0x800) == 0x800;
    
public booleanisSampleDurationPresent()

        return (getFlags() & 0x100) == 0x100;
    
public booleanisSampleFlagsPresent()

        return (getFlags() & 0x400) == 0x400;
    
public booleanisSampleSizePresent()

        return (getFlags() & 0x200) == 0x200;
    
public voidsetDataOffset(int dataOffset)

        if (dataOffset == -1) {
            setFlags(getFlags() & (0xFFFFFF ^ 1));
        } else {
            setFlags(getFlags() | 0x1); // turn on dataoffset
        }
        this.dataOffset = dataOffset;
    
public voidsetDataOffsetPresent(boolean v)

        if (v) {
            setFlags(getFlags() | 0x01);
        } else {
            setFlags(getFlags() & (0xFFFFFF ^ 0x1));
        }
    
public voidsetEntries(java.util.List entries)

        this.entries = entries;
    
public voidsetFirstSampleFlags(SampleFlags firstSampleFlags)

        if (firstSampleFlags == null) {
            setFlags(getFlags() & (0xFFFFFF ^ 0x4));
        } else {
            setFlags(getFlags() | 0x4);
        }
        this.firstSampleFlags = firstSampleFlags;
    
public voidsetSampleCompositionTimeOffsetPresent(boolean v)

        if (v) {
            setFlags(getFlags() | 0x800);
        } else {
            setFlags(getFlags() & (0xFFFFFF ^ 0x800));
        }

    
public voidsetSampleDurationPresent(boolean v)


        if (v) {
            setFlags(getFlags() | 0x100);
        } else {
            setFlags(getFlags() & (0xFFFFFF ^ 0x100));
        }
    
public voidsetSampleFlagsPresent(boolean v)

        if (v) {
            setFlags(getFlags() | 0x400);
        } else {
            setFlags(getFlags() & (0xFFFFFF ^ 0x400));
        }
    
public voidsetSampleSizePresent(boolean v)

        if (v) {
            setFlags(getFlags() | 0x200);
        } else {
            setFlags(getFlags() & (0xFFFFFF ^ 0x200));
        }
    
public java.lang.StringtoString()

        final StringBuilder sb = new StringBuilder();
        sb.append("TrackRunBox");
        sb.append("{sampleCount=").append(entries.size());
        sb.append(", dataOffset=").append(dataOffset);
        sb.append(", dataOffsetPresent=").append(isDataOffsetPresent());
        sb.append(", sampleSizePresent=").append(isSampleSizePresent());
        sb.append(", sampleDurationPresent=").append(isSampleDurationPresent());
        sb.append(", sampleFlagsPresentPresent=").append(isSampleFlagsPresent());
        sb.append(", sampleCompositionTimeOffsetPresent=").append(isSampleCompositionTimeOffsetPresent());
        sb.append(", firstSampleFlags=").append(firstSampleFlags);
        sb.append('}");
        return sb.toString();