All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jcodec.containers.mp4.boxes.TimecodeSampleEntry Maven / Gradle / Ivy

There is a newer version: 0.2.5
Show newest version
package org.jcodec.containers.mp4.boxes;

import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Map;

import org.jcodec.common.NIOUtils;
import org.jcodec.common.tools.ToJSON;

/**
 * This class is part of JCodec ( www.jcodec.org ) This software is distributed
 * under FreeBSD License
 * 
 * Describes timecode payload sample
 * 
 * @author The JCodec project
 * 
 */
public class TimecodeSampleEntry extends SampleEntry {

    public static final int FLAG_DROPFRAME = 0x1;
    public static final int FLAG_24HOURMAX = 0x2;
    public static final int FLAG_NEGATIVETIMEOK = 0x4;
    public static final int FLAG_COUNTER = 0x8;

    private static final MyFactory FACTORY = new MyFactory();
    private int flags;
    private int timescale;
    private int frameDuration;
    private byte numFrames;

    public TimecodeSampleEntry(Header header) {
        super(header);
        factory = FACTORY;
    }

    public TimecodeSampleEntry() {
        super(new Header("tmcd"));
        factory = FACTORY;
    }

    public TimecodeSampleEntry(int flags, int timescale, int frameDuration, int numFrames) {
        super(new Header("tmcd"));
        this.flags = flags;
        this.timescale = timescale;
        this.frameDuration = frameDuration;
        this.numFrames = (byte) numFrames;
    }

    public void parse(ByteBuffer input) {
        super.parse(input);

        NIOUtils.skip(input, 4);
        flags = input.getInt();
        timescale = input.getInt();
        frameDuration = input.getInt();
        numFrames = input.get();
        NIOUtils.skip(input, 1);
    }

    protected void doWrite(ByteBuffer out) {
        super.doWrite(out);
        out.putInt(0);
        out.putInt(flags);
        out.putInt(timescale);
        out.putInt(frameDuration);
        out.put(numFrames);
        out.put((byte) 207);
    }

    public static class MyFactory extends BoxFactory {
        private Map> mappings = new HashMap>();

        public MyFactory() {
        }

        public Class toClass(String fourcc) {
            return mappings.get(fourcc);
        }
    }

    public int getFlags() {
        return flags;
    }

    public int getTimescale() {
        return timescale;
    }

    public int getFrameDuration() {
        return frameDuration;
    }

    public byte getNumFrames() {
        return numFrames;
    }

    public boolean isDropFrame() {
        return (flags & FLAG_DROPFRAME) != 0;
    }

    @Override
    public void dump(StringBuilder sb) {
        sb.append(header.getFourcc() + ": {\n");
        sb.append("entry: ");

        ToJSON.toJSON(this, sb, "flags", "timescale", "frameDuration", "numFrames");
        sb.append(",\nexts: [\n");
        dumpBoxes(sb);
        sb.append("\n]\n");
        sb.append("}\n");
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy