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
17package com.coremedia.iso.boxes;
18
19import com.coremedia.iso.IsoFile;
20import com.coremedia.iso.IsoTypeReader;
21import com.coremedia.iso.IsoTypeWriter;
22import com.coremedia.iso.Utf8;
23import com.googlecode.mp4parser.AbstractFullBox;
24
25import java.nio.ByteBuffer;
26
27/**
28 * Classification of the media according to 3GPP 26.244.
29 */
30public class ClassificationBox extends AbstractFullBox {
31    public static final String TYPE = "clsf";
32
33
34    private String classificationEntity;
35    private int classificationTableIndex;
36    private String language;
37    private String classificationInfo;
38
39    public ClassificationBox() {
40        super(TYPE);
41    }
42
43    public String getLanguage() {
44        return language;
45    }
46
47    public String getClassificationEntity() {
48        return classificationEntity;
49    }
50
51    public int getClassificationTableIndex() {
52        return classificationTableIndex;
53    }
54
55    public String getClassificationInfo() {
56        return classificationInfo;
57    }
58
59    public void setClassificationEntity(String classificationEntity) {
60        this.classificationEntity = classificationEntity;
61    }
62
63    public void setClassificationTableIndex(int classificationTableIndex) {
64        this.classificationTableIndex = classificationTableIndex;
65    }
66
67    public void setLanguage(String language) {
68        this.language = language;
69    }
70
71    public void setClassificationInfo(String classificationInfo) {
72        this.classificationInfo = classificationInfo;
73    }
74
75    protected long getContentSize() {
76        return 4 + 2 + 2 + Utf8.utf8StringLengthInBytes(classificationInfo) + 1;
77    }
78
79    @Override
80    public void _parseDetails(ByteBuffer content) {
81        parseVersionAndFlags(content);
82        byte[] cE = new byte[4];
83        content.get(cE);
84        classificationEntity = IsoFile.bytesToFourCC(cE);
85        classificationTableIndex = IsoTypeReader.readUInt16(content);
86        language = IsoTypeReader.readIso639(content);
87        classificationInfo = IsoTypeReader.readString(content);
88    }
89
90    @Override
91    protected void getContent(ByteBuffer byteBuffer) {
92        byteBuffer.put(IsoFile.fourCCtoBytes(classificationEntity));
93        IsoTypeWriter.writeUInt16(byteBuffer, classificationTableIndex);
94        IsoTypeWriter.writeIso639(byteBuffer, language);
95        byteBuffer.put(Utf8.convert(classificationInfo));
96        byteBuffer.put((byte) 0);
97    }
98
99
100    public String toString() {
101        StringBuilder buffer = new StringBuilder();
102        buffer.append("ClassificationBox[language=").append(getLanguage());
103        buffer.append("classificationEntity=").append(getClassificationEntity());
104        buffer.append(";classificationTableIndex=").append(getClassificationTableIndex());
105        buffer.append(";language=").append(getLanguage());
106        buffer.append(";classificationInfo=").append(getClassificationInfo());
107        buffer.append("]");
108        return buffer.toString();
109    }
110}
111