1package com.googlecode.mp4parser.boxes; 2 3import com.coremedia.iso.IsoTypeReader; 4import com.coremedia.iso.IsoTypeWriter; 5import com.googlecode.mp4parser.AbstractFullBox; 6 7import java.nio.ByteBuffer; 8import java.nio.ByteOrder; 9import java.util.Arrays; 10import java.util.UUID; 11 12/** 13 * 14 */ 15public abstract class AbstractTrackEncryptionBox extends AbstractFullBox { 16 int defaultAlgorithmId; 17 int defaultIvSize; 18 byte[] default_KID; 19 20 protected AbstractTrackEncryptionBox(String type) { 21 super(type); 22 } 23 24 public int getDefaultAlgorithmId() { 25 return defaultAlgorithmId; 26 } 27 28 public void setDefaultAlgorithmId(int defaultAlgorithmId) { 29 this.defaultAlgorithmId = defaultAlgorithmId; 30 } 31 32 public int getDefaultIvSize() { 33 return defaultIvSize; 34 } 35 36 public void setDefaultIvSize(int defaultIvSize) { 37 this.defaultIvSize = defaultIvSize; 38 } 39 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 46 public void setDefault_KID(byte[] default_KID) { 47 this.default_KID = default_KID; 48 } 49 50 @Override 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 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 68 protected long getContentSize() { 69 return 24; 70 } 71 72 @Override 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 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