1 package com.googlecode.mp4parser.boxes.cenc;
2 
3 import com.coremedia.iso.BoxParser;
4 import com.coremedia.iso.IsoFile;
5 import com.coremedia.iso.IsoTypeReader;
6 import com.coremedia.iso.IsoTypeWriter;
7 import com.coremedia.iso.boxes.Box;
8 import com.googlecode.mp4parser.AbstractFullBox;
9 import com.googlecode.mp4parser.util.UUIDConverter;
10 
11 import java.io.IOException;
12 import java.nio.ByteBuffer;
13 import java.util.UUID;
14 
15 
16 
17 /**
18  * This box contains information needed by a Content Protection System to play back the content. The
19  * data format is specified by the system identified by the ‘pssh’ parameter SystemID, and is considered
20  * opaque for the purposes of this specification.
21  * <p/>
22  * The data encapsulated in the Data field may be read by the identified Content Protection System to
23  * enable decryption key acquisition and decryption of media data. For license/rights-based systems, the
24  * header information may include data such as the URL of license server(s) or rights issuer(s) used,
25  * embedded licenses/rights, and/or other protection system specific metadata.
26  * <p/>
27  * A single file may be constructed to be playable by multiple key and digital rights management (DRM)
28  * systems, by including one Protection System-Specific Header box for each system supported. Readers
29  * that process such presentations must match the SystemID field in this box to the SystemID(s) of the
30  * DRM System(s) they support, and select or create the matching Protection System-Specific Header
31  * box(es) for storage and retrieval of Protection-Specific information interpreted or created by that DRM
32  * system.
33  */
34 public class ProtectionSystemSpecificHeaderBox extends AbstractFullBox {
35     public static final String TYPE = "pssh";
36 
37     public static byte[] OMA2_SYSTEM_ID = UUIDConverter.convert(UUID.fromString("A2B55680-6F43-11E0-9A3F-0002A5D5C51B"));
38     public static byte[] PLAYREADY_SYSTEM_ID = UUIDConverter.convert(UUID.fromString("9A04F079-9840-4286-AB92-E65BE0885F95"));
39 
40     byte[] content;
41     byte[] systemId;
42 
43 
getSystemId()44     public byte[] getSystemId() {
45         return systemId;
46     }
47 
setSystemId(byte[] systemId)48     public void setSystemId(byte[] systemId) {
49         assert systemId.length == 16;
50         this.systemId = systemId;
51     }
52 
getContent()53     public byte[] getContent() {
54         return content;
55     }
56 
setContent(byte[] content)57     public void setContent(byte[] content) {
58         this.content = content;
59     }
60 
ProtectionSystemSpecificHeaderBox()61     public ProtectionSystemSpecificHeaderBox() {
62         super(TYPE);
63     }
64 
65     @Override
getContentSize()66     protected long getContentSize() {
67         return 24 + content.length;
68     }
69 
70     @Override
getContent(ByteBuffer byteBuffer)71     protected void getContent(ByteBuffer byteBuffer) {
72         writeVersionAndFlags(byteBuffer);
73         assert systemId.length == 16;
74         byteBuffer.put(systemId, 0, 16);
75         IsoTypeWriter.writeUInt32(byteBuffer, content.length);
76         byteBuffer.put(content);
77     }
78 
79     @Override
_parseDetails(ByteBuffer content)80     protected void _parseDetails(ByteBuffer content) {
81         parseVersionAndFlags(content);
82         systemId = new byte[16];
83         content.get(systemId);
84         long length = IsoTypeReader.readUInt32(content);
85         this.content = new byte[content.remaining()];
86         content.get(this.content);
87         assert length == this.content.length;
88     }
89 }
90