Home | History | Annotate | Download | only in boxes
      1 /*
      2  * Copyright 2008 CoreMedia AG, Hamburg
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the License);
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *     http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an AS IS BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.coremedia.iso.boxes;
     18 
     19 import com.coremedia.iso.IsoTypeReader;
     20 import com.coremedia.iso.IsoTypeWriter;
     21 import com.googlecode.mp4parser.AbstractFullBox;
     22 
     23 import java.nio.ByteBuffer;
     24 
     25 /**
     26  * Describes the format of media access units in PDCF files.
     27  */
     28 public final class OmaDrmAccessUnitFormatBox extends AbstractFullBox {
     29     public static final String TYPE = "odaf";
     30 
     31     private boolean selectiveEncryption;
     32     private byte allBits;
     33 
     34     private int keyIndicatorLength;
     35     private int initVectorLength;
     36 
     37     protected long getContentSize() {
     38         return 7;
     39     }
     40 
     41     public OmaDrmAccessUnitFormatBox() {
     42         super("odaf");
     43     }
     44 
     45     public boolean isSelectiveEncryption() {
     46         return selectiveEncryption;
     47     }
     48 
     49     public int getKeyIndicatorLength() {
     50         return keyIndicatorLength;
     51     }
     52 
     53     public int getInitVectorLength() {
     54         return initVectorLength;
     55     }
     56 
     57     public void setInitVectorLength(int initVectorLength) {
     58         this.initVectorLength = initVectorLength;
     59     }
     60 
     61     public void setKeyIndicatorLength(int keyIndicatorLength) {
     62         this.keyIndicatorLength = keyIndicatorLength;
     63     }
     64 
     65     public void setAllBits(byte allBits) {
     66         this.allBits = allBits;
     67         selectiveEncryption = (allBits & 0x80) == 0x80;
     68     }
     69 
     70     @Override
     71     public void _parseDetails(ByteBuffer content) {
     72         parseVersionAndFlags(content);
     73         allBits = (byte) IsoTypeReader.readUInt8(content);
     74         selectiveEncryption = (allBits & 0x80) == 0x80;
     75         keyIndicatorLength = IsoTypeReader.readUInt8(content);
     76         initVectorLength = IsoTypeReader.readUInt8(content);
     77     }
     78 
     79     @Override
     80     protected void getContent(ByteBuffer byteBuffer) {
     81         writeVersionAndFlags(byteBuffer);
     82         IsoTypeWriter.writeUInt8(byteBuffer, allBits);
     83         IsoTypeWriter.writeUInt8(byteBuffer, keyIndicatorLength);
     84         IsoTypeWriter.writeUInt8(byteBuffer, initVectorLength);
     85     }
     86 
     87 }
     88