/* * Flazr <http://flazr.com> Copyright (C) 2009 Peter Thomas. * * This file is part of Flazr. * * Flazr is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Flazr is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with Flazr. If not, see <http://www.gnu.org/licenses/>. */ package com.flazr.io.f4v.box; import com.flazr.io.f4v.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.flazr.util.Utils; import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.buffer.ChannelBuffers; public class MDHD implements Payload { private static final Logger logger = LoggerFactory.getLogger(MDHD.class); private byte version; private byte[] flags; private long creationTime; private long modificationTime; private int timeScale; private long duration; private byte pad; private byte language; private short reserved; public MDHD(ChannelBuffer in) { read(in); } public int getTimeScale() { return timeScale; } public long getDuration() { return duration; } @Override public void read(ChannelBuffer in) { version = in.readByte(); logger.debug("version: {}", Utils.toHex(version)); flags = new byte[3]; in.readBytes(flags); if (version == 0x00) { creationTime = in.readInt(); modificationTime = in.readInt(); } else { creationTime = in.readLong(); modificationTime = in.readLong(); } timeScale = in.readInt(); if (version == 0x00) { duration = in.readInt(); } else { duration = in.readLong(); } logger.debug("creationTime {} modificationTime {} timeScale {} duration {}", new Object[]{creationTime, modificationTime, timeScale, duration}); pad = in.readByte(); language = in.readByte(); // TODO convert to ISO codes ? reserved = in.readShort(); } @Override public ChannelBuffer write() { ChannelBuffer out = ChannelBuffers.dynamicBuffer(); out.writeByte(version); out.writeBytes(new byte[3]); // flags if (version == 0x00) { out.writeInt((int) creationTime); out.writeInt((int) modificationTime); } else { out.writeLong(creationTime); out.writeLong(modificationTime); } out.writeInt(timeScale); if (version == 0x00) { out.writeInt((int) duration); } else { out.writeLong(duration); } out.writeByte(pad); out.writeByte(language); out.writeShort(reserved); return out; } }