1 package com.coremedia.iso.boxes.dece; 2 3 import com.coremedia.iso.IsoTypeReader; 4 import com.coremedia.iso.IsoTypeWriter; 5 import com.googlecode.mp4parser.AbstractFullBox; 6 7 import java.nio.ByteBuffer; 8 import java.util.ArrayList; 9 import java.util.List; 10 11 /** 12 * aligned(8) class TrickPlayBox 13 * extends FullBox(‘trik’, version=0, flags=0) 14 * { 15 * for (i=0; I < sample_count; i++) { 16 * unsigned int(2) pic_type; 17 * unsigned int(6) dependency_level; 18 * } 19 * } 20 */ 21 public class TrickPlayBox extends AbstractFullBox { 22 public static final String TYPE = "trik"; 23 24 private List<Entry> entries = new ArrayList<Entry>(); 25 TrickPlayBox()26 public TrickPlayBox() { 27 super(TYPE); 28 } 29 setEntries(List<Entry> entries)30 public void setEntries(List<Entry> entries) { 31 this.entries = entries; 32 } 33 getEntries()34 public List<Entry> getEntries() { 35 return entries; 36 } 37 38 public static class Entry { 39 Entry()40 public Entry() { 41 } 42 Entry(int value)43 public Entry(int value) { 44 this.value = value; 45 } 46 47 48 private int value; 49 getPicType()50 public int getPicType() { 51 return (value >> 6) & 0x03; 52 } 53 setPicType(int picType)54 public void setPicType(int picType) { 55 value = value & (0xff >> 3); 56 value = (picType & 0x03) << 6 | value; 57 } 58 getDependencyLevel()59 public int getDependencyLevel() { 60 return value & 0x3f; 61 } 62 setDependencyLevel(int dependencyLevel)63 public void setDependencyLevel(int dependencyLevel) { 64 value = (dependencyLevel & 0x3f) | value; 65 } 66 67 68 @Override toString()69 public String toString() { 70 final StringBuilder sb = new StringBuilder(); 71 sb.append("Entry"); 72 sb.append("{picType=").append(getPicType()); 73 sb.append(",dependencyLevel=").append(getDependencyLevel()); 74 sb.append('}'); 75 return sb.toString(); 76 } 77 } 78 79 @Override getContentSize()80 protected long getContentSize() { 81 return 4 + entries.size(); 82 } 83 84 @Override _parseDetails(ByteBuffer content)85 public void _parseDetails(ByteBuffer content) { 86 parseVersionAndFlags(content); 87 while (content.remaining() > 0) { 88 entries.add(new Entry(IsoTypeReader.readUInt8(content))); 89 } 90 } 91 92 @Override getContent(ByteBuffer byteBuffer)93 protected void getContent(ByteBuffer byteBuffer) { 94 writeVersionAndFlags(byteBuffer); 95 for (Entry entry : entries) { 96 IsoTypeWriter.writeUInt8(byteBuffer, entry.value); 97 } 98 } 99 100 @Override toString()101 public String toString() { 102 final StringBuilder sb = new StringBuilder(); 103 sb.append("TrickPlayBox"); 104 sb.append("{entries=").append(entries); 105 sb.append('}'); 106 return sb.toString(); 107 } 108 } 109