MovieExtendsHeaderBox.java revision dd9eb897ee7c7b507cbdcf80263bb4b5de6966bf
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
17package com.coremedia.iso.boxes.fragment;
18
19import com.coremedia.iso.IsoTypeReader;
20import com.coremedia.iso.IsoTypeWriter;
21import com.googlecode.mp4parser.AbstractFullBox;
22
23import java.nio.ByteBuffer;
24
25/**
26 * aligned(8) class MovieExtendsHeaderBox extends FullBox('mehd', version, 0) {
27 * if (version==1) {
28 * unsigned int(64) fragment_duration;
29 * } else { // version==0
30 * unsigned int(32) fragment_duration;
31 * }
32 * }
33 */
34public class MovieExtendsHeaderBox extends AbstractFullBox {
35    public static final String TYPE = "mehd";
36    private long fragmentDuration;
37
38    public MovieExtendsHeaderBox() {
39        super(TYPE);
40    }
41
42    @Override
43    protected long getContentSize() {
44        return getVersion() == 1 ? 12 : 8;
45    }
46
47    @Override
48    public void _parseDetails(ByteBuffer content) {
49        parseVersionAndFlags(content);
50        fragmentDuration = getVersion() == 1 ? IsoTypeReader.readUInt64(content) : IsoTypeReader.readUInt32(content);
51    }
52
53
54    @Override
55    protected void getContent(ByteBuffer byteBuffer) {
56        writeVersionAndFlags(byteBuffer);
57        if (getVersion() == 1) {
58            IsoTypeWriter.writeUInt64(byteBuffer, fragmentDuration);
59        } else {
60            IsoTypeWriter.writeUInt32(byteBuffer, fragmentDuration);
61        }
62    }
63
64    public long getFragmentDuration() {
65        return fragmentDuration;
66    }
67
68    public void setFragmentDuration(long fragmentDuration) {
69        this.fragmentDuration = fragmentDuration;
70    }
71}
72