FileDocCategorySizeDatePackage
AbstractManifestWriter.javaAPI Docmp4parser 1.0-RC-175030Wed Dec 19 20:10:37 GMT 2012com.googlecode.mp4parser.authoring.adaptivestreaming

AbstractManifestWriter

public abstract class AbstractManifestWriter extends Object implements ManifestWriter
Created with IntelliJ IDEA. User: mstattma Date: 17.08.12 Time: 02:51 To change this template use File | Settings | File Templates.

Fields Summary
private static final Logger
LOG
private com.googlecode.mp4parser.authoring.builder.FragmentIntersectionFinder
intersectionFinder
protected long[]
audioFragmentsDurations
protected long[]
videoFragmentsDurations
Constructors Summary
protected AbstractManifestWriter(com.googlecode.mp4parser.authoring.builder.FragmentIntersectionFinder intersectionFinder)


       
        this.intersectionFinder = intersectionFinder;
    
Methods Summary
public long[]calculateFragmentDurations(com.googlecode.mp4parser.authoring.Track track, com.googlecode.mp4parser.authoring.Movie movie)
Calculates the length of each fragment in the given track (as part of movie).

param
track target of calculation
param
movie the track must be part of this movie
return
the duration of each fragment in track timescale

        long[] startSamples = intersectionFinder.sampleNumbers(track, movie);
        long[] durations = new long[startSamples.length];
        int currentFragment = 0;
        int currentSample = 1; // sync samples start with 1 !

        for (TimeToSampleBox.Entry entry : track.getDecodingTimeEntries()) {
            for (int max = currentSample + l2i(entry.getCount()); currentSample < max; currentSample++) {
                // in this loop we go through the entry.getCount() samples starting from current sample.
                // the next entry.getCount() samples have the same decoding time.
                if (currentFragment != startSamples.length - 1 && currentSample == startSamples[currentFragment + 1]) {
                    // we are not in the last fragment && the current sample is the start sample of the next fragment
                    currentFragment++;
                }
                durations[currentFragment] += entry.getDelta();


            }
        }
        return durations;

    
protected long[]checkFragmentsAlign(long[] referenceTimes, long[] checkTimes)


        if (referenceTimes == null || referenceTimes.length == 0) {
            return checkTimes;
        }
        long[] referenceTimesMinusLast = new long[referenceTimes.length - 1];
        System.arraycopy(referenceTimes, 0, referenceTimesMinusLast, 0, referenceTimes.length - 1);
        long[] checkTimesMinusLast = new long[checkTimes.length - 1];
        System.arraycopy(checkTimes, 0, checkTimesMinusLast, 0, checkTimes.length - 1);

        if (!Arrays.equals(checkTimesMinusLast, referenceTimesMinusLast)) {
            String log = "";
            log += (referenceTimes.length);
            log += ("Reference     :  [");
            for (long l : referenceTimes) {
                log += (String.format("%10d,", l));
            }
            log += ("]");
            LOG.warning(log);
            log = "";

            log += (checkTimes.length);
            log += ("Current       :  [");
            for (long l : checkTimes) {
                log += (String.format("%10d,", l));
            }
            log += ("]");
            LOG.warning(log);
            throw new IOException("Track does not have the same fragment borders as its predecessor.");

        } else {
            return checkTimes;
        }
    
public longgetBitrate(com.googlecode.mp4parser.authoring.Track track)

        long bitrate = 0;
        for (ByteBuffer sample : track.getSamples()) {
            bitrate += sample.limit();
        }
        bitrate *= 8; // from bytes to bits
        bitrate /= ((double) getDuration(track)) / track.getTrackMetaData().getTimescale(); // per second
        return bitrate;
    
protected static longgetDuration(com.googlecode.mp4parser.authoring.Track track)

        long duration = 0;
        for (TimeToSampleBox.Entry entry : track.getDecodingTimeEntries()) {
            duration += entry.getCount() * entry.getDelta();
        }
        return duration;
    
protected java.lang.StringgetFormat(com.coremedia.iso.boxes.sampleentry.SampleEntry se)

        String type = se.getType();
        if (type.equals("encv") || type.equals("enca") || type.equals("encv")) {
            OriginalFormatBox frma = se.getBoxes(OriginalFormatBox.class, true).get(0);
            type = frma.getDataFormat();
        }
        return type;