FileDocCategorySizeDatePackage
CroppedTrack.javaAPI Docmp4parser 1.0-RC-176830Wed Dec 19 20:10:37 GMT 2012com.googlecode.mp4parser.authoring.tracks

CroppedTrack

public class CroppedTrack extends com.googlecode.mp4parser.authoring.AbstractTrack
Generates a Track that starts at fromSample and ends at toSample (exclusive). The user of this class has to make sure that the fromSample is a random access sample.
  • In AAC this is every single sample
  • In H264 this is every sample that is marked in the SyncSampleBox

Fields Summary
com.googlecode.mp4parser.authoring.Track
origTrack
private int
fromSample
private int
toSample
private long[]
syncSampleArray
Constructors Summary
public CroppedTrack(com.googlecode.mp4parser.authoring.Track origTrack, long fromSample, long toSample)

        this.origTrack = origTrack;
        assert fromSample <= Integer.MAX_VALUE;
        assert toSample <= Integer.MAX_VALUE;
        this.fromSample = (int) fromSample;
        this.toSample = (int) toSample;
    
Methods Summary
public java.util.ListgetCompositionTimeEntries()

        return getCompositionTimeEntries(origTrack.getCompositionTimeEntries(), fromSample, toSample);
    
static java.util.ListgetCompositionTimeEntries(java.util.List origSamples, long fromSample, long toSample)

        if (origSamples != null && !origSamples.isEmpty()) {
            long current = 0;
            ListIterator<CompositionTimeToSample.Entry> e = origSamples.listIterator();
            ArrayList<CompositionTimeToSample.Entry> nuList = new ArrayList<CompositionTimeToSample.Entry>();

            // Skip while not yet reached:
            CompositionTimeToSample.Entry currentEntry;
            while ((currentEntry = e.next()).getCount() + current <= fromSample) {
                current += currentEntry.getCount();
            }
            // Take just a bit from the next
            if (currentEntry.getCount() + current >= toSample) {
                nuList.add(new CompositionTimeToSample.Entry((int) (toSample - fromSample), currentEntry.getOffset()));
                return nuList; // done in one step
            } else {
                nuList.add(new CompositionTimeToSample.Entry((int) (currentEntry.getCount() + current - fromSample), currentEntry.getOffset()));
            }
            current += currentEntry.getCount();

            while (e.hasNext() && (currentEntry = e.next()).getCount() + current < toSample) {
                nuList.add(currentEntry);
                current += currentEntry.getCount();
            }

            nuList.add(new CompositionTimeToSample.Entry((int) (toSample - current), currentEntry.getOffset()));

            return nuList;
        } else {
            return null;
        }
    
public java.util.ListgetDecodingTimeEntries()

        return getDecodingTimeEntries(origTrack.getDecodingTimeEntries(), fromSample, toSample);
    
static java.util.ListgetDecodingTimeEntries(java.util.List origSamples, long fromSample, long toSample)

        if (origSamples != null && !origSamples.isEmpty()) {
            long current = 0;
            ListIterator<TimeToSampleBox.Entry> e = origSamples.listIterator();
            LinkedList<TimeToSampleBox.Entry> nuList = new LinkedList<TimeToSampleBox.Entry>();

            // Skip while not yet reached:
            TimeToSampleBox.Entry currentEntry;
            while ((currentEntry = e.next()).getCount() + current <= fromSample) {
                current += currentEntry.getCount();
            }
            // Take just a bit from the next
            if (currentEntry.getCount() + current >= toSample) {
                nuList.add(new TimeToSampleBox.Entry(toSample - fromSample, currentEntry.getDelta()));
                return nuList; // done in one step
            } else {
                nuList.add(new TimeToSampleBox.Entry(currentEntry.getCount() + current - fromSample, currentEntry.getDelta()));
            }
            current += currentEntry.getCount();

            while (e.hasNext() && (currentEntry = e.next()).getCount() + current < toSample) {
                nuList.add(currentEntry);
                current += currentEntry.getCount();
            }

            nuList.add(new TimeToSampleBox.Entry(toSample - current, currentEntry.getDelta()));

            return nuList;
        } else {
            return null;
        }
    
public java.lang.StringgetHandler()

        return origTrack.getHandler();
    
public BoxgetMediaHeaderBox()

        return origTrack.getMediaHeaderBox();
    
public java.util.ListgetSampleDependencies()

        if (origTrack.getSampleDependencies() != null && !origTrack.getSampleDependencies().isEmpty()) {
            return origTrack.getSampleDependencies().subList(fromSample, toSample);
        } else {
            return null;
        }
    
public SampleDescriptionBoxgetSampleDescriptionBox()

        return origTrack.getSampleDescriptionBox();
    
public java.util.ListgetSamples()

        return origTrack.getSamples().subList(fromSample, toSample);
    
public SubSampleInformationBoxgetSubsampleInformationBox()

        return origTrack.getSubsampleInformationBox();
    
public synchronized long[]getSyncSamples()

        if (origTrack.getSyncSamples() != null) {
            long[] origSyncSamples = origTrack.getSyncSamples();
            int i = 0, j = origSyncSamples.length;
            while (i < origSyncSamples.length && origSyncSamples[i] < fromSample) {
                i++;
            }
            while (j > 0 && toSample < origSyncSamples[j - 1]) {
                j--;
            }
            syncSampleArray = Arrays.copyOfRange(origTrack.getSyncSamples(), i, j);
            for (int k = 0; k < syncSampleArray.length; k++) {
                syncSampleArray[k] -= fromSample;
            }
            return syncSampleArray;
        }
        return null;
    
public com.googlecode.mp4parser.authoring.TrackMetaDatagetTrackMetaData()

        return origTrack.getTrackMetaData();