• 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.IsoTypeReader;
20 import com.coremedia.iso.IsoTypeWriter;
21 import com.googlecode.mp4parser.AbstractFullBox;
22 
23 import java.nio.ByteBuffer;
24 import java.util.LinkedList;
25 import java.util.List;
26 
27 import static com.googlecode.mp4parser.util.CastUtils.l2i;
28 
29 /*
30 aligned(8) class SampleAuxiliaryInformationOffsetsBox
31             extends FullBox(‘saio’, version, flags)
32 {
33             if (flags & 1) {
34                         unsigned int(32) aux_info_type;
35                         unsigned int(32) aux_info_type_parameter;
36             }
37             unsigned int(32) entry_count;
38             if ( version == 0 )
39             {
40                         unsigned int(32) offset[ entry_count ];
41             }
42             else
43             {
44                         unsigned int(64) offset[ entry_count ];
45             }
46 }
47  */
48 public class SampleAuxiliaryInformationOffsetsBox extends AbstractFullBox {
49     public static final String TYPE = "saio";
50 
51     private List<Long> offsets = new LinkedList<Long>();
52     private long auxInfoType;
53     private long auxInfoTypeParameter;
54 
SampleAuxiliaryInformationOffsetsBox()55     public SampleAuxiliaryInformationOffsetsBox() {
56         super(TYPE);
57     }
58 
59     @Override
getContentSize()60     protected long getContentSize() {
61         return 8 + (getVersion() == 0 ? 4 * offsets.size() : 8 * offsets.size()) + ((getFlags() & 1) == 1 ? 8 : 0);
62     }
63 
64     @Override
getContent(ByteBuffer byteBuffer)65     protected void getContent(ByteBuffer byteBuffer) {
66         writeVersionAndFlags(byteBuffer);
67         if ((getFlags() & 1) == 1) {
68             IsoTypeWriter.writeUInt32(byteBuffer, auxInfoType);
69             IsoTypeWriter.writeUInt32(byteBuffer, auxInfoTypeParameter);
70         }
71 
72         IsoTypeWriter.writeUInt32(byteBuffer, offsets.size());
73         for (Long offset : offsets) {
74             if (getVersion() == 0) {
75                 IsoTypeWriter.writeUInt32(byteBuffer, offset);
76             } else {
77                 IsoTypeWriter.writeUInt64(byteBuffer, offset);
78             }
79         }
80     }
81 
82     @Override
_parseDetails(ByteBuffer content)83     public void _parseDetails(ByteBuffer content) {
84         parseVersionAndFlags(content);
85 
86         if ((getFlags() & 1) == 1) {
87             auxInfoType = IsoTypeReader.readUInt32(content);
88             auxInfoTypeParameter = IsoTypeReader.readUInt32(content);
89         }
90 
91         int entryCount = l2i(IsoTypeReader.readUInt32(content));
92         offsets.clear();
93 
94         for (int i = 0; i < entryCount; i++) {
95             if (getVersion() == 0) {
96                 offsets.add(IsoTypeReader.readUInt32(content));
97             } else {
98                 offsets.add(IsoTypeReader.readUInt64(content));
99             }
100         }
101     }
102 
103 
getAuxInfoType()104     public long getAuxInfoType() {
105         return auxInfoType;
106     }
107 
setAuxInfoType(long auxInfoType)108     public void setAuxInfoType(long auxInfoType) {
109         this.auxInfoType = auxInfoType;
110     }
111 
getAuxInfoTypeParameter()112     public long getAuxInfoTypeParameter() {
113         return auxInfoTypeParameter;
114     }
115 
setAuxInfoTypeParameter(long auxInfoTypeParameter)116     public void setAuxInfoTypeParameter(long auxInfoTypeParameter) {
117         this.auxInfoTypeParameter = auxInfoTypeParameter;
118     }
119 
getOffsets()120     public List<Long> getOffsets() {
121         return offsets;
122     }
123 
setOffsets(List<Long> offsets)124     public void setOffsets(List<Long> offsets) {
125         this.offsets = offsets;
126     }
127 }
128