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
19
20import com.coremedia.iso.IsoTypeWriter;
21import com.googlecode.mp4parser.FullContainerBox;
22
23import java.nio.ByteBuffer;
24
25/**
26 * The data reference object contains a table of data references (normally URLs) that declare the location(s) of
27 * the media data used within the presentation. The data reference index in the sample description ties entries in
28 * this table to the samples in the track. A track may be split over several sources in this way.
29 * If the flag is set indicating that the data is in the same file as this box, then no string (not even an empty one)
30 * shall be supplied in the entry field.
31 * The DataEntryBox within the DataReferenceBox shall be either a DataEntryUrnBox or a DataEntryUrlBox.
32 *
33 * @see com.coremedia.iso.boxes.DataEntryUrlBox
34 * @see com.coremedia.iso.boxes.DataEntryUrnBox
35 */
36public class DataReferenceBox extends FullContainerBox {
37
38    public static final String TYPE = "dref";
39
40    public DataReferenceBox() {
41        super(TYPE);
42
43    }
44
45    @Override
46    protected long getContentSize() {
47        return super.getContentSize() + 4;
48    }
49
50    @Override
51    public void _parseDetails(ByteBuffer content) {
52        parseVersionAndFlags(content);
53        content.get(new byte[4]); // basically a skip of 4 bytes signaling the number of child boxes
54        parseChildBoxes(content);
55    }
56
57
58    @Override
59    protected void getContent(ByteBuffer byteBuffer) {
60        writeVersionAndFlags(byteBuffer);
61        IsoTypeWriter.writeUInt32(byteBuffer, getBoxes().size());
62        writeChildBoxes(byteBuffer);
63    }
64
65}
66