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.IsoTypeReader;
20import com.coremedia.iso.IsoTypeWriter;
21
22import java.nio.ByteBuffer;
23
24/**
25 * The hint media header contains general information, independent of the protocaol, for hint tracks. Resides
26 * in Media Information Box.
27 *
28 * @see com.coremedia.iso.boxes.MediaInformationBox
29 */
30public class HintMediaHeaderBox extends AbstractMediaHeaderBox {
31    private int maxPduSize;
32    private int avgPduSize;
33    private long maxBitrate;
34    private long avgBitrate;
35    public static final String TYPE = "hmhd";
36
37    public HintMediaHeaderBox() {
38        super(TYPE);
39    }
40
41    public int getMaxPduSize() {
42        return maxPduSize;
43    }
44
45    public int getAvgPduSize() {
46        return avgPduSize;
47    }
48
49    public long getMaxBitrate() {
50        return maxBitrate;
51    }
52
53    public long getAvgBitrate() {
54        return avgBitrate;
55    }
56
57    protected long getContentSize() {
58        return 20;
59    }
60
61    @Override
62    public void _parseDetails(ByteBuffer content) {
63        parseVersionAndFlags(content);
64        maxPduSize = IsoTypeReader.readUInt16(content);
65        avgPduSize = IsoTypeReader.readUInt16(content);
66        maxBitrate = IsoTypeReader.readUInt32(content);
67        avgBitrate = IsoTypeReader.readUInt32(content);
68        IsoTypeReader.readUInt32(content);    // reserved!
69
70    }
71
72    @Override
73    protected void getContent(ByteBuffer byteBuffer) {
74        writeVersionAndFlags(byteBuffer);
75        IsoTypeWriter.writeUInt16(byteBuffer, maxPduSize);
76        IsoTypeWriter.writeUInt16(byteBuffer, avgPduSize);
77        IsoTypeWriter.writeUInt32(byteBuffer, maxBitrate);
78        IsoTypeWriter.writeUInt32(byteBuffer, avgBitrate);
79        IsoTypeWriter.writeUInt32(byteBuffer, 0);
80    }
81
82    @Override
83    public String toString() {
84        return "HintMediaHeaderBox{" +
85                "maxPduSize=" + maxPduSize +
86                ", avgPduSize=" + avgPduSize +
87                ", maxBitrate=" + maxBitrate +
88                ", avgBitrate=" + avgBitrate +
89                '}';
90    }
91}
92