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

TextTrackImpl

public class TextTrackImpl extends com.googlecode.mp4parser.authoring.AbstractTrack

Fields Summary
com.googlecode.mp4parser.authoring.TrackMetaData
trackMetaData
SampleDescriptionBox
sampleDescriptionBox
List
subs
Constructors Summary
public TextTrackImpl()

        sampleDescriptionBox = new SampleDescriptionBox();
        TextSampleEntry tx3g = new TextSampleEntry("tx3g");
        tx3g.setDataReferenceIndex(1);
        tx3g.setStyleRecord(new TextSampleEntry.StyleRecord());
        tx3g.setBoxRecord(new TextSampleEntry.BoxRecord());
        sampleDescriptionBox.addBox(tx3g);

        FontTableBox ftab = new FontTableBox();
        ftab.setEntries(Collections.singletonList(new FontTableBox.FontRecord(1, "Serif")));

        tx3g.addBox(ftab);


        trackMetaData.setCreationTime(new Date());
        trackMetaData.setModificationTime(new Date());
        trackMetaData.setTimescale(1000); // Text tracks use millieseconds


    
Methods Summary
public java.util.ListgetCompositionTimeEntries()

        return null;
    
public java.util.ListgetDecodingTimeEntries()

        List<TimeToSampleBox.Entry> stts = new LinkedList<TimeToSampleBox.Entry>();
        long lastEnd = 0;
        for (Line sub : subs) {
            long silentTime = sub.from - lastEnd;
            if (silentTime > 0) {
                stts.add(new TimeToSampleBox.Entry(1, silentTime));
            } else if (silentTime < 0) {
                throw new Error("Subtitle display times may not intersect");
            }
            stts.add(new TimeToSampleBox.Entry(1, sub.to - sub.from));
            lastEnd = sub.to;
        }
        return stts;
    
public java.lang.StringgetHandler()

        return "sbtl";
    
public AbstractMediaHeaderBoxgetMediaHeaderBox()

        return new NullMediaHeaderBox();
    
public java.util.ListgetSampleDependencies()

        return null;
    
public SampleDescriptionBoxgetSampleDescriptionBox()

        return sampleDescriptionBox;
    
public java.util.ListgetSamples()

        List<ByteBuffer> samples = new LinkedList<ByteBuffer>();
        long lastEnd = 0;
        for (Line sub : subs) {
            long silentTime = sub.from - lastEnd;
            if (silentTime > 0) {
                samples.add(ByteBuffer.wrap(new byte[]{0, 0}));
            } else if (silentTime < 0) {
                throw new Error("Subtitle display times may not intersect");
            }
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            DataOutputStream dos = new DataOutputStream(baos);
            try {
                dos.writeShort(sub.text.getBytes("UTF-8").length);
                dos.write(sub.text.getBytes("UTF-8"));
                dos.close();
            } catch (IOException e) {
                throw new Error("VM is broken. Does not support UTF-8");
            }
            samples.add(ByteBuffer.wrap(baos.toByteArray()));
            lastEnd = sub.to;
        }
        return samples;
    
public java.util.ListgetSubs()


       
        return subs;
    
public SubSampleInformationBoxgetSubsampleInformationBox()

        return null;
    
public long[]getSyncSamples()

        return null;
    
public com.googlecode.mp4parser.authoring.TrackMetaDatagetTrackMetaData()

        return trackMetaData;