1 package com.googlecode.mp4parser.boxes; 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.nio.ByteOrder; 9 import java.util.Arrays; 10 import java.util.UUID; 11 12 /** 13 * 14 */ 15 public abstract class AbstractTrackEncryptionBox extends AbstractFullBox { 16 int defaultAlgorithmId; 17 int defaultIvSize; 18 byte[] default_KID; 19 AbstractTrackEncryptionBox(String type)20 protected AbstractTrackEncryptionBox(String type) { 21 super(type); 22 } 23 getDefaultAlgorithmId()24 public int getDefaultAlgorithmId() { 25 return defaultAlgorithmId; 26 } 27 setDefaultAlgorithmId(int defaultAlgorithmId)28 public void setDefaultAlgorithmId(int defaultAlgorithmId) { 29 this.defaultAlgorithmId = defaultAlgorithmId; 30 } 31 getDefaultIvSize()32 public int getDefaultIvSize() { 33 return defaultIvSize; 34 } 35 setDefaultIvSize(int defaultIvSize)36 public void setDefaultIvSize(int defaultIvSize) { 37 this.defaultIvSize = defaultIvSize; 38 } 39 getDefault_KID()40 public String getDefault_KID() { 41 ByteBuffer b = ByteBuffer.wrap(default_KID); 42 b.order(ByteOrder.BIG_ENDIAN); 43 return new UUID(b.getLong(), b.getLong()).toString(); 44 } 45 setDefault_KID(byte[] default_KID)46 public void setDefault_KID(byte[] default_KID) { 47 this.default_KID = default_KID; 48 } 49 50 @Override _parseDetails(ByteBuffer content)51 public void _parseDetails(ByteBuffer content) { 52 parseVersionAndFlags(content); 53 defaultAlgorithmId = IsoTypeReader.readUInt24(content); 54 defaultIvSize = IsoTypeReader.readUInt8(content); 55 default_KID = new byte[16]; 56 content.get(default_KID); 57 } 58 59 @Override getContent(ByteBuffer byteBuffer)60 protected void getContent(ByteBuffer byteBuffer) { 61 writeVersionAndFlags(byteBuffer); 62 IsoTypeWriter.writeUInt24(byteBuffer, defaultAlgorithmId); 63 IsoTypeWriter.writeUInt8(byteBuffer, defaultIvSize); 64 byteBuffer.put(default_KID); 65 } 66 67 @Override getContentSize()68 protected long getContentSize() { 69 return 24; 70 } 71 72 @Override equals(Object o)73 public boolean equals(Object o) { 74 if (this == o) return true; 75 if (o == null || getClass() != o.getClass()) return false; 76 77 AbstractTrackEncryptionBox that = (AbstractTrackEncryptionBox) o; 78 79 if (defaultAlgorithmId != that.defaultAlgorithmId) return false; 80 if (defaultIvSize != that.defaultIvSize) return false; 81 if (!Arrays.equals(default_KID, that.default_KID)) return false; 82 83 return true; 84 } 85 86 @Override hashCode()87 public int hashCode() { 88 int result = defaultAlgorithmId; 89 result = 31 * result + defaultIvSize; 90 result = 31 * result + (default_KID != null ? Arrays.hashCode(default_KID) : 0); 91 return result; 92 } 93 } 94