1package com.googlecode.mp4parser.boxes.piff; 2 3import com.coremedia.iso.IsoFile; 4import com.coremedia.iso.IsoTypeReader; 5import com.coremedia.iso.IsoTypeWriter; 6import com.googlecode.mp4parser.AbstractFullBox; 7import com.googlecode.mp4parser.util.Path; 8import com.googlecode.mp4parser.util.UUIDConverter; 9 10import java.io.FileInputStream; 11import java.io.IOException; 12import java.lang.Override;import java.lang.String;import java.lang.StringBuilder;import java.nio.ByteBuffer; 13import java.util.UUID; 14 15import static com.googlecode.mp4parser.util.CastUtils.l2i; 16 17/** 18 * aligned(8) class UuidBasedProtectionSystemSpecificHeaderBox extends FullBox(‘uuid’, 19 * extended_type=0xd08a4f18-10f3-4a82-b6c8-32d8aba183d3, 20 * version=0, flags=0) 21 * { 22 * unsigned int(8)[16] SystemID; 23 * unsigned int(32) DataSize; 24 * unsigned int(8)[DataSize] Data; 25 * } 26 */ 27public class UuidBasedProtectionSystemSpecificHeaderBox extends AbstractFullBox { 28 public static byte[] USER_TYPE = new byte[]{(byte) 0xd0, (byte) 0x8a, 0x4f, 0x18, 0x10, (byte) 0xf3, 0x4a, (byte) 0x82, 29 (byte) 0xb6, (byte) 0xc8, 0x32, (byte) 0xd8, (byte) 0xab, (byte) 0xa1, (byte) 0x83, (byte) 0xd3}; 30 31 UUID systemId; 32 33 ProtectionSpecificHeader protectionSpecificHeader; 34 35 public UuidBasedProtectionSystemSpecificHeaderBox() { 36 super("uuid", USER_TYPE); 37 } 38 39 @Override 40 protected long getContentSize() { 41 return 24 + protectionSpecificHeader.getData().limit(); 42 } 43 44 @Override 45 public byte[] getUserType() { 46 return USER_TYPE; 47 } 48 49 @Override 50 protected void getContent(ByteBuffer byteBuffer) { 51 writeVersionAndFlags(byteBuffer); 52 IsoTypeWriter.writeUInt64(byteBuffer, systemId.getMostSignificantBits()); 53 IsoTypeWriter.writeUInt64(byteBuffer, systemId.getLeastSignificantBits()); 54 ByteBuffer data = protectionSpecificHeader.getData(); 55 data.rewind(); 56 IsoTypeWriter.writeUInt32(byteBuffer, data.limit()); 57 byteBuffer.put(data); 58 } 59 60 @Override 61 protected void _parseDetails(ByteBuffer content) { 62 parseVersionAndFlags(content); 63 byte[] systemIdBytes = new byte[16]; 64 content.get(systemIdBytes); 65 systemId = UUIDConverter.convert(systemIdBytes); 66 int dataSize = l2i(IsoTypeReader.readUInt32(content)); 67 protectionSpecificHeader = ProtectionSpecificHeader.createFor(systemId, content); 68 } 69 70 public UUID getSystemId() { 71 return systemId; 72 } 73 74 public void setSystemId(UUID systemId) { 75 this.systemId = systemId; 76 } 77 78 public String getSystemIdString() { 79 return systemId.toString(); 80 } 81 82 public ProtectionSpecificHeader getProtectionSpecificHeader() { 83 return protectionSpecificHeader; 84 } 85 86 public String getProtectionSpecificHeaderString() { 87 return protectionSpecificHeader.toString(); 88 } 89 90 public void setProtectionSpecificHeader(ProtectionSpecificHeader protectionSpecificHeader) { 91 this.protectionSpecificHeader = protectionSpecificHeader; 92 } 93 94 @Override 95 public String toString() { 96 final StringBuilder sb = new StringBuilder(); 97 sb.append("UuidBasedProtectionSystemSpecificHeaderBox"); 98 sb.append("{systemId=").append(systemId.toString()); 99 sb.append(", dataSize=").append(protectionSpecificHeader.getData().limit()); 100 sb.append('}'); 101 return sb.toString(); 102 } 103 104 105 106} 107