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.coremedia.iso.Utf8;
22 import com.googlecode.mp4parser.AbstractFullBox;
23 
24 import java.nio.ByteBuffer;
25 
26 /**
27  * <code>
28  * Box Type: 'titl'<br>
29  * Container: {@link UserDataBox} ('udta')<br>
30  * Mandatory: No<br>
31  * Quantity: Zero or one<br><br>
32  * </code>
33  * <p/>
34  * Title for the media.
35  */
36 public class TitleBox extends AbstractFullBox {
37     public static final String TYPE = "titl";
38 
39     private String language;
40     private String title;
41 
TitleBox()42     public TitleBox() {
43         super(TYPE);
44     }
45 
getLanguage()46     public String getLanguage() {
47         return language;
48     }
49 
getTitle()50     public String getTitle() {
51         return title;
52     }
53 
54     /**
55      * Sets the 3-letter ISO-639 language for this title.
56      *
57      * @param language 3-letter ISO-639 code
58      */
setLanguage(String language)59     public void setLanguage(String language) {
60         this.language = language;
61     }
62 
setTitle(String title)63     public void setTitle(String title) {
64         this.title = title;
65     }
66 
getContentSize()67     protected long getContentSize() {
68         return 7 + Utf8.utf8StringLengthInBytes(title);
69     }
70 
71 
getContent(ByteBuffer byteBuffer)72     protected void getContent(ByteBuffer byteBuffer) {
73         writeVersionAndFlags(byteBuffer);
74         IsoTypeWriter.writeIso639(byteBuffer, language);
75         byteBuffer.put(Utf8.convert(title));
76         byteBuffer.put((byte) 0);
77     }
78 
79     @Override
_parseDetails(ByteBuffer content)80     public void _parseDetails(ByteBuffer content) {
81         parseVersionAndFlags(content);
82         language = IsoTypeReader.readIso639(content);
83         title = IsoTypeReader.readString(content);
84     }
85 
toString()86     public String toString() {
87         return "TitleBox[language=" + getLanguage() + ";title=" + getTitle() + "]";
88     }
89 }
90