• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2009 castLabs GmbH, Berlin
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.googlecode.mp4parser.AbstractFullBox;
23 
24 import java.nio.ByteBuffer;
25 import java.util.LinkedList;
26 import java.util.List;
27 
28 import static com.googlecode.mp4parser.util.CastUtils.l2i;
29 
30 public class SampleAuxiliaryInformationSizesBox extends AbstractFullBox {
31     public static final String TYPE = "saiz";
32 
33     private int defaultSampleInfoSize;
34     private List<Short> sampleInfoSizes = new LinkedList<Short>();
35     private int sampleCount;
36     private String auxInfoType;
37     private String auxInfoTypeParameter;
38 
SampleAuxiliaryInformationSizesBox()39     public SampleAuxiliaryInformationSizesBox() {
40         super(TYPE);
41     }
42 
43     @Override
getContentSize()44     protected long getContentSize() {
45         int size = 4;
46         if ((getFlags() & 1) == 1) {
47             size += 8;
48         }
49 
50         size += 5;
51         size += defaultSampleInfoSize == 0 ? sampleInfoSizes.size() : 0;
52         return size;
53     }
54 
55     @Override
getContent(ByteBuffer byteBuffer)56     protected void getContent(ByteBuffer byteBuffer) {
57         writeVersionAndFlags(byteBuffer);
58         if ((getFlags() & 1) == 1) {
59             byteBuffer.put(IsoFile.fourCCtoBytes(auxInfoType));
60             byteBuffer.put(IsoFile.fourCCtoBytes(auxInfoTypeParameter));
61         }
62 
63         IsoTypeWriter.writeUInt8(byteBuffer, defaultSampleInfoSize);
64 
65         if (defaultSampleInfoSize == 0) {
66             IsoTypeWriter.writeUInt32(byteBuffer, sampleInfoSizes.size());
67             for (short sampleInfoSize : sampleInfoSizes) {
68                 IsoTypeWriter.writeUInt8(byteBuffer, sampleInfoSize);
69             }
70         } else {
71             IsoTypeWriter.writeUInt32(byteBuffer, sampleCount);
72         }
73     }
74 
75     @Override
_parseDetails(ByteBuffer content)76     public void _parseDetails(ByteBuffer content) {
77         parseVersionAndFlags(content);
78         if ((getFlags() & 1) == 1) {
79             auxInfoType = IsoTypeReader.read4cc(content);
80             auxInfoTypeParameter = IsoTypeReader.read4cc(content);
81         }
82 
83         defaultSampleInfoSize = (short) IsoTypeReader.readUInt8(content);
84         sampleCount = l2i(IsoTypeReader.readUInt32(content));
85 
86         sampleInfoSizes.clear();
87 
88         if (defaultSampleInfoSize == 0) {
89             for (int i = 0; i < sampleCount; i++) {
90                 sampleInfoSizes.add((short) IsoTypeReader.readUInt8(content));
91             }
92         }
93     }
94 
getAuxInfoType()95     public String getAuxInfoType() {
96         return auxInfoType;
97     }
98 
setAuxInfoType(String auxInfoType)99     public void setAuxInfoType(String auxInfoType) {
100         this.auxInfoType = auxInfoType;
101     }
102 
getAuxInfoTypeParameter()103     public String getAuxInfoTypeParameter() {
104         return auxInfoTypeParameter;
105     }
106 
setAuxInfoTypeParameter(String auxInfoTypeParameter)107     public void setAuxInfoTypeParameter(String auxInfoTypeParameter) {
108         this.auxInfoTypeParameter = auxInfoTypeParameter;
109     }
110 
getDefaultSampleInfoSize()111     public int getDefaultSampleInfoSize() {
112         return defaultSampleInfoSize;
113     }
114 
setDefaultSampleInfoSize(int defaultSampleInfoSize)115     public void setDefaultSampleInfoSize(int defaultSampleInfoSize) {
116         assert defaultSampleInfoSize <= 255;
117         this.defaultSampleInfoSize = defaultSampleInfoSize;
118     }
119 
getSampleInfoSizes()120     public List<Short> getSampleInfoSizes() {
121         return sampleInfoSizes;
122     }
123 
setSampleInfoSizes(List<Short> sampleInfoSizes)124     public void setSampleInfoSizes(List<Short> sampleInfoSizes) {
125         this.sampleInfoSizes = sampleInfoSizes;
126     }
127 
getSampleCount()128     public int getSampleCount() {
129         return sampleCount;
130     }
131 
setSampleCount(int sampleCount)132     public void setSampleCount(int sampleCount) {
133         this.sampleCount = sampleCount;
134     }
135 
136     @Override
toString()137     public String toString() {
138         return "SampleAuxiliaryInformationSizesBox{" +
139                 "defaultSampleInfoSize=" + defaultSampleInfoSize +
140                 ", sampleCount=" + sampleCount +
141                 ", auxInfoType='" + auxInfoType + '\'' +
142                 ", auxInfoTypeParameter='" + auxInfoTypeParameter + '\'' +
143                 '}';
144     }
145 }
146