• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  * Meta information in a 'udta' box about a track.
28  * Defined in 3GPP 26.244.
29  *
30  * @see com.coremedia.iso.boxes.UserDataBox
31  */
32 public class AlbumBox extends AbstractFullBox {
33     public static final String TYPE = "albm";
34 
35     private String language;
36     private String albumTitle;
37     private int trackNumber;
38 
AlbumBox()39     public AlbumBox() {
40         super(TYPE);
41     }
42 
43     /**
44      * Declares the language code for the {@link #getAlbumTitle()} return value. See ISO 639-2/T for the set of three
45      * character codes.Each character is packed as the difference between its ASCII value and 0x60. The code is
46      * confined to being three lower-case letters, so these values are strictly positive.
47      *
48      * @return the language code
49      */
getLanguage()50     public String getLanguage() {
51         return language;
52     }
53 
getAlbumTitle()54     public String getAlbumTitle() {
55         return albumTitle;
56     }
57 
getTrackNumber()58     public int getTrackNumber() {
59         return trackNumber;
60     }
61 
setLanguage(String language)62     public void setLanguage(String language) {
63         this.language = language;
64     }
65 
setAlbumTitle(String albumTitle)66     public void setAlbumTitle(String albumTitle) {
67         this.albumTitle = albumTitle;
68     }
69 
setTrackNumber(int trackNumber)70     public void setTrackNumber(int trackNumber) {
71         this.trackNumber = trackNumber;
72     }
73 
getContentSize()74     protected long getContentSize() {
75         return 6 + Utf8.utf8StringLengthInBytes(albumTitle) + 1 + (trackNumber == -1 ? 0 : 1);
76     }
77 
78     @Override
_parseDetails(ByteBuffer content)79     public void _parseDetails(ByteBuffer content) {
80         parseVersionAndFlags(content);
81         language = IsoTypeReader.readIso639(content);
82         albumTitle = IsoTypeReader.readString(content);
83 
84         if (content.remaining() > 0) {
85             trackNumber = IsoTypeReader.readUInt8(content);
86         } else {
87             trackNumber = -1;
88         }
89     }
90 
91     @Override
getContent(ByteBuffer byteBuffer)92     protected void getContent(ByteBuffer byteBuffer) {
93         writeVersionAndFlags(byteBuffer);
94         IsoTypeWriter.writeIso639(byteBuffer, language);
95         byteBuffer.put(Utf8.convert(albumTitle));
96         byteBuffer.put((byte) 0);
97         if (trackNumber != -1) {
98             IsoTypeWriter.writeUInt8(byteBuffer, trackNumber);
99         }
100     }
101 
toString()102     public String toString() {
103         StringBuilder buffer = new StringBuilder();
104         buffer.append("AlbumBox[language=").append(getLanguage()).append(";");
105         buffer.append("albumTitle=").append(getAlbumTitle());
106         if (trackNumber >= 0) {
107             buffer.append(";trackNumber=").append(getTrackNumber());
108         }
109         buffer.append("]");
110         return buffer.toString();
111     }
112 }
113