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.IsoFile;
     20 import com.coremedia.iso.IsoTypeReader;
     21 import com.coremedia.iso.IsoTypeWriter;
     22 import com.coremedia.iso.Utf8;
     23 import com.googlecode.mp4parser.AbstractFullBox;
     24 
     25 import java.nio.ByteBuffer;
     26 
     27 
     28 /**
     29  * Contained a the <code>UserDataBox</code> and containing information about the media's rating. E.g.
     30  * PG13or FSK16.
     31  */
     32 public class RatingBox extends AbstractFullBox {
     33     public static final String TYPE = "rtng";
     34 
     35     private String ratingEntity;
     36     private String ratingCriteria;
     37     private String language;
     38     private String ratingInfo;
     39 
     40     public RatingBox() {
     41         super(TYPE);
     42     }
     43 
     44 
     45     public void setRatingEntity(String ratingEntity) {
     46         this.ratingEntity = ratingEntity;
     47     }
     48 
     49     public void setRatingCriteria(String ratingCriteria) {
     50         this.ratingCriteria = ratingCriteria;
     51     }
     52 
     53     public void setLanguage(String language) {
     54         this.language = language;
     55     }
     56 
     57     public void setRatingInfo(String ratingInfo) {
     58         this.ratingInfo = ratingInfo;
     59     }
     60 
     61     public String getLanguage() {
     62         return language;
     63     }
     64 
     65     /**
     66      * Gets a four-character code that indicates the rating entity grading the asset, e.g., 'BBFC'. The values of this
     67      * field should follow common names of worldwide movie rating systems, such as those mentioned in
     68      * [http://www.movie-ratings.net/, October 2002].
     69      *
     70      * @return the rating organization
     71      */
     72     public String getRatingEntity() {
     73         return ratingEntity;
     74     }
     75 
     76     /**
     77      * Gets the four-character code that indicates which rating criteria are being used for the corresponding rating
     78      * entity, e.g., 'PG13'.
     79      *
     80      * @return the actual rating
     81      */
     82     public String getRatingCriteria() {
     83         return ratingCriteria;
     84     }
     85 
     86     public String getRatingInfo() {
     87         return ratingInfo;
     88     }
     89 
     90     protected long getContentSize() {
     91         return 15 + Utf8.utf8StringLengthInBytes(ratingInfo);
     92     }
     93 
     94     @Override
     95     public void _parseDetails(ByteBuffer content) {
     96         parseVersionAndFlags(content);
     97         ratingEntity = IsoTypeReader.read4cc(content);
     98         ratingCriteria = IsoTypeReader.read4cc(content);
     99         language = IsoTypeReader.readIso639(content);
    100         ratingInfo = IsoTypeReader.readString(content);
    101 
    102     }
    103 
    104     @Override
    105     protected void getContent(ByteBuffer byteBuffer) {
    106         writeVersionAndFlags(byteBuffer);
    107         byteBuffer.put(IsoFile.fourCCtoBytes(ratingEntity));
    108         byteBuffer.put(IsoFile.fourCCtoBytes(ratingCriteria));
    109         IsoTypeWriter.writeIso639(byteBuffer, language);
    110         byteBuffer.put(Utf8.convert(ratingInfo));
    111         byteBuffer.put((byte) 0);
    112     }
    113 
    114     public String toString() {
    115         StringBuilder buffer = new StringBuilder();
    116         buffer.append("RatingBox[language=").append(getLanguage());
    117         buffer.append("ratingEntity=").append(getRatingEntity());
    118         buffer.append(";ratingCriteria=").append(getRatingCriteria());
    119         buffer.append(";language=").append(getLanguage());
    120         buffer.append(";ratingInfo=").append(getRatingInfo());
    121         buffer.append("]");
    122         return buffer.toString();
    123     }
    124 }
    125