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 17package com.coremedia.iso.boxes; 18 19import com.coremedia.iso.IsoTypeReader; 20import com.coremedia.iso.IsoTypeWriter; 21import com.googlecode.mp4parser.AbstractBox; 22 23import java.nio.ByteBuffer; 24 25/** 26 * Contains a reference to a track. The type of the box gives the kind of reference. 27 */ 28public class TrackReferenceTypeBox extends AbstractBox { 29 30 public static final String TYPE1 = "hint"; 31 public static final String TYPE2 = "cdsc"; 32 33 private long[] trackIds; 34 35 public TrackReferenceTypeBox(String type) { 36 super(type); 37 } 38 39 public long[] getTrackIds() { 40 return trackIds; 41 } 42 43 @Override 44 public void _parseDetails(ByteBuffer content) { 45 int count = (int) (content.remaining() / 4); 46 trackIds = new long[count]; 47 for (int i = 0; i < count; i++) { 48 trackIds[i] = IsoTypeReader.readUInt32(content); 49 } 50 } 51 52 @Override 53 protected void getContent(ByteBuffer byteBuffer) { 54 for (long trackId : trackIds) { 55 IsoTypeWriter.writeUInt32(byteBuffer, trackId); 56 } 57 } 58 59 60 protected long getContentSize() { 61 return trackIds.length * 4; 62 } 63 64 public String toString() { 65 StringBuilder buffer = new StringBuilder(); 66 buffer.append("TrackReferenceTypeBox[type=").append(getType()); 67 for (int i = 0; i < trackIds.length; i++) { 68 buffer.append(";trackId"); 69 buffer.append(i); 70 buffer.append("="); 71 buffer.append(trackIds[i]); 72 } 73 buffer.append("]"); 74 return buffer.toString(); 75 } 76} 77