/* * myLib - https://github.com/taktod/myLib * Copyright (c) 2014 ttProject. All rights reserved. * * Licensed under The MIT license. */ package com.ttProject.frame.vp8.type; import java.nio.ByteBuffer; import com.ttProject.frame.vp8.Vp8Frame; import com.ttProject.nio.channels.IReadChannel; import com.ttProject.unit.extra.bit.Bit1; import com.ttProject.unit.extra.bit.Bit19; import com.ttProject.unit.extra.bit.Bit3; import com.ttProject.util.BufferUtil; /** * intraFrame for vp8 * @author taktod */ public class IntraFrame extends Vp8Frame { private ByteBuffer buffer; /** * constructor * @param frameType * @param version * @param showFrame * @param firstPartSize */ public IntraFrame(Bit1 frameType, Bit3 version, Bit1 showFrame, Bit19 firstPartSize) { super(frameType, version, showFrame, firstPartSize); } /** * {@inheritDoc} */ @Override public void minimumLoad(IReadChannel channel) throws Exception { setReadPosition(channel.position()); setSize(channel.size()); super.update(); } /** * {@inheritDoc} */ @Override public void load(IReadChannel channel) throws Exception { channel.position(getReadPosition()); buffer = BufferUtil.safeRead(channel, getSize() - getReadPosition()); super.update(); } /** * {@inheritDoc} */ @Override protected void requestUpdate() throws Exception { if(buffer == null) { throw new Exception("buffer is not loaded yet."); } setData(BufferUtil.connect(getHeaderBuffer(), buffer)); } /** * {@inheritDoc} */ @Override public ByteBuffer getPackBuffer() throws Exception { return getData(); } }