1 /* 2 * Copyright 2008 CoreMedia AG, Hamburg 3 * 4 * Licensed under the Apache License, Version 2.0 (the License); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an AS IS BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.coremedia.iso.boxes; 18 19 import com.coremedia.iso.IsoTypeReader; 20 import com.coremedia.iso.IsoTypeWriter; 21 22 import java.nio.ByteBuffer; 23 24 import static com.googlecode.mp4parser.util.CastUtils.l2i; 25 26 /** 27 * The chunk offset table gives the index of each chunk into the containing file. Defined in ISO/IEC 14496-12. 28 */ 29 public class StaticChunkOffsetBox extends ChunkOffsetBox { 30 public static final String TYPE = "stco"; 31 32 private long[] chunkOffsets = new long[0]; 33 StaticChunkOffsetBox()34 public StaticChunkOffsetBox() { 35 super(TYPE); 36 } 37 getChunkOffsets()38 public long[] getChunkOffsets() { 39 return chunkOffsets; 40 } 41 getContentSize()42 protected long getContentSize() { 43 return 8 + chunkOffsets.length * 4; 44 } 45 setChunkOffsets(long[] chunkOffsets)46 public void setChunkOffsets(long[] chunkOffsets) { 47 this.chunkOffsets = chunkOffsets; 48 } 49 50 @Override _parseDetails(ByteBuffer content)51 public void _parseDetails(ByteBuffer content) { 52 parseVersionAndFlags(content); 53 int entryCount = l2i(IsoTypeReader.readUInt32(content)); 54 chunkOffsets = new long[entryCount]; 55 for (int i = 0; i < entryCount; i++) { 56 chunkOffsets[i] = IsoTypeReader.readUInt32(content); 57 } 58 59 } 60 61 @Override getContent(ByteBuffer byteBuffer)62 protected void getContent(ByteBuffer byteBuffer) { 63 writeVersionAndFlags(byteBuffer); 64 IsoTypeWriter.writeUInt32(byteBuffer, chunkOffsets.length); 65 for (long chunkOffset : chunkOffsets) { 66 IsoTypeWriter.writeUInt32(byteBuffer, chunkOffset); 67 } 68 } 69 70 71 } 72