/* * 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.f4vutil.box; import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.buffer.DynamicChannelBuffer; import android.util.Log; import com.flazr.io.f4vutil.Payload; import com.flazr.util.Utils; public class MDHD implements Payload { 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(); Log.d("version: {}", ""+String.valueOf(Utils.toHexChars(version))); flags = new byte[3]; in.readBytes(flags,0,3); 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(); } Log.d("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 = new DynamicChannelBuffer(ChannelBuffers.BIG_ENDIAN,256); out.writeByte(version); byte[] writeArray = new byte[3]; out.writeBytes(writeArray,0,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; } }