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.AbstractBox;
     22 
     23 import java.nio.ByteBuffer;
     24 
     25 /**
     26  * <code>class BitRateBox extends Box('btrt') {<br/>
     27  * unsigned int(32) bufferSizeDB;<br/>
     28  * // gives the size of the decoding buffer for<br/>
     29  * // the elementary stream in bytes.<br/>
     30  * unsigned int(32) maxBitrate;<br/>
     31  * // gives the maximum rate in bits/second <br/>
     32  * // over any window of one second.<br/>
     33  * unsigned int(32) avgBitrate;<br/>
     34  * // avgBitrate gives the average rate in <br/>
     35  * // bits/second over the entire presentation.<br/>
     36  * }</code>
     37  */
     38 
     39 public final class BitRateBox extends AbstractBox {
     40     public static final String TYPE = "btrt";
     41 
     42     private long bufferSizeDb;
     43     private long maxBitrate;
     44     private long avgBitrate;
     45 
     46     public BitRateBox() {
     47         super(TYPE);
     48     }
     49 
     50     protected long getContentSize() {
     51         return 12;
     52     }
     53 
     54     @Override
     55     public void _parseDetails(ByteBuffer content) {
     56         bufferSizeDb = IsoTypeReader.readUInt32(content);
     57         maxBitrate = IsoTypeReader.readUInt32(content);
     58         avgBitrate = IsoTypeReader.readUInt32(content);
     59     }
     60 
     61     @Override
     62     protected void getContent(ByteBuffer byteBuffer) {
     63         IsoTypeWriter.writeUInt32(byteBuffer, bufferSizeDb);
     64         IsoTypeWriter.writeUInt32(byteBuffer, maxBitrate);
     65         IsoTypeWriter.writeUInt32(byteBuffer, avgBitrate);
     66     }
     67 
     68     public long getBufferSizeDb() {
     69         return bufferSizeDb;
     70     }
     71 
     72     public void setBufferSizeDb(long bufferSizeDb) {
     73         this.bufferSizeDb = bufferSizeDb;
     74     }
     75 
     76     public long getMaxBitrate() {
     77         return maxBitrate;
     78     }
     79 
     80     public void setMaxBitrate(long maxBitrate) {
     81         this.maxBitrate = maxBitrate;
     82     }
     83 
     84     public long getAvgBitrate() {
     85         return avgBitrate;
     86     }
     87 
     88     public void setAvgBitrate(long avgBitrate) {
     89         this.avgBitrate = avgBitrate;
     90     }
     91 }
     92