Home | History | Annotate | Download | only in mp4parser
      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.googlecode.mp4parser;
     18 
     19 
     20 import com.coremedia.iso.IsoTypeReader;
     21 import com.coremedia.iso.IsoTypeWriter;
     22 import com.coremedia.iso.boxes.FullBox;
     23 
     24 import java.nio.ByteBuffer;
     25 
     26 /**
     27  * Base class for all ISO Full boxes.
     28  */
     29 public abstract class AbstractFullBox extends AbstractBox implements FullBox {
     30     private int version;
     31     private int flags;
     32 
     33     protected AbstractFullBox(String type) {
     34         super(type);
     35     }
     36 
     37     protected AbstractFullBox(String type, byte[] userType) {
     38         super(type, userType);
     39     }
     40 
     41     public int getVersion() {
     42         return version;
     43     }
     44 
     45     public void setVersion(int version) {
     46         this.version = version;
     47     }
     48 
     49     public int getFlags() {
     50         return flags;
     51     }
     52 
     53     public void setFlags(int flags) {
     54         this.flags = flags;
     55     }
     56 
     57 
     58     /**
     59      * Parses the version/flags header and returns the remaining box size.
     60      *
     61      * @param content
     62      * @return number of bytes read
     63      */
     64     protected final long parseVersionAndFlags(ByteBuffer content) {
     65         version = IsoTypeReader.readUInt8(content);
     66         flags = IsoTypeReader.readUInt24(content);
     67         return 4;
     68     }
     69 
     70     protected final void writeVersionAndFlags(ByteBuffer bb) {
     71         IsoTypeWriter.writeUInt8(bb, version);
     72         IsoTypeWriter.writeUInt24(bb, flags);
     73     }
     74 }
     75