summaryrefslogtreecommitdiff
path: root/isoparser/src/main/java/com/googlecode/mp4parser/boxes/mp4/objectdescriptors/InitialObjectDescriptor.java
blob: 7a1f0949bd248361eda5a5ddbdda3b7c13d95c7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
 * Copyright 2011 castLabs, Berlin
 *
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.googlecode.mp4parser.boxes.mp4.objectdescriptors;


import com.coremedia.iso.IsoTypeReader;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;

/*
class InitialObjectDescriptor extends ObjectDescriptorBase : bit(8)
tag=InitialObjectDescrTag {
bit(10) ObjectDescriptorID;
bit(1) URL_Flag;
bit(1) includeInlineProfileLevelFlag;
const bit(4) reserved=0b1111;
if (URL_Flag) {
bit(8) URLlength;
bit(8) URLstring[URLlength];
} else {
bit(8) ODProfileLevelIndication;
bit(8) sceneProfileLevelIndication;
bit(8) audioProfileLevelIndication;
bit(8) visualProfileLevelIndication;
bit(8) graphicsProfileLevelIndication;
ES_Descriptor esDescr[1 .. 255];
OCI_Descriptor ociDescr[0 .. 255];
IPMP_DescriptorPointer ipmpDescrPtr[0 .. 255];
IPMP_Descriptor ipmpDescr [0 .. 255];
IPMP_ToolListDescriptor toolListDescr[0 .. 1];
}
ExtensionDescriptor extDescr[0 .. 255];
}
*/
//@Descriptor(tags = {0x02, 0x10})
public class InitialObjectDescriptor extends ObjectDescriptorBase {
    private int objectDescriptorId;
    int urlFlag;
    int includeInlineProfileLevelFlag;

    int urlLength;
    String urlString;

    int oDProfileLevelIndication;
    int sceneProfileLevelIndication;
    int audioProfileLevelIndication;
    int visualProfileLevelIndication;
    int graphicsProfileLevelIndication;

    List<ESDescriptor> esDescriptors = new ArrayList<ESDescriptor>();

    List<ExtensionDescriptor> extensionDescriptors = new ArrayList<ExtensionDescriptor>();

    List<BaseDescriptor> unknownDescriptors = new ArrayList<BaseDescriptor>();

    @Override
    public void parseDetail(ByteBuffer bb) throws IOException {
        int data = IsoTypeReader.readUInt16(bb);
        objectDescriptorId = (data & 0xFFC0) >> 6;

        urlFlag = (data & 0x3F) >> 5;
        includeInlineProfileLevelFlag = (data & 0x1F) >> 4;

        int sizeLeft = getSize() - 2;
        if (urlFlag == 1) {
            urlLength = IsoTypeReader.readUInt8(bb);
            urlString = IsoTypeReader.readString(bb, urlLength);
            sizeLeft = sizeLeft - (1 + urlLength);
        } else {
            oDProfileLevelIndication = IsoTypeReader.readUInt8(bb);
            sceneProfileLevelIndication = IsoTypeReader.readUInt8(bb);
            audioProfileLevelIndication = IsoTypeReader.readUInt8(bb);
            visualProfileLevelIndication = IsoTypeReader.readUInt8(bb);
            graphicsProfileLevelIndication = IsoTypeReader.readUInt8(bb);

            sizeLeft = sizeLeft - 5;

            if (sizeLeft > 2) {
                final BaseDescriptor descriptor = ObjectDescriptorFactory.createFrom(-1, bb);
                sizeLeft = sizeLeft - descriptor.getSize();
                if (descriptor instanceof ESDescriptor) {
                    esDescriptors.add((ESDescriptor) descriptor);
                } else {
                    unknownDescriptors.add(descriptor);
                }
            }
        }

        if (sizeLeft > 2) {
            final BaseDescriptor descriptor = ObjectDescriptorFactory.createFrom(-1, bb);
            if (descriptor instanceof ExtensionDescriptor) {
                extensionDescriptors.add((ExtensionDescriptor) descriptor);
            } else {
                unknownDescriptors.add(descriptor);
            }
        }
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder();
        sb.append("InitialObjectDescriptor");
        sb.append("{objectDescriptorId=").append(objectDescriptorId);
        sb.append(", urlFlag=").append(urlFlag);
        sb.append(", includeInlineProfileLevelFlag=").append(includeInlineProfileLevelFlag);
        sb.append(", urlLength=").append(urlLength);
        sb.append(", urlString='").append(urlString).append('\'');
        sb.append(", oDProfileLevelIndication=").append(oDProfileLevelIndication);
        sb.append(", sceneProfileLevelIndication=").append(sceneProfileLevelIndication);
        sb.append(", audioProfileLevelIndication=").append(audioProfileLevelIndication);
        sb.append(", visualProfileLevelIndication=").append(visualProfileLevelIndication);
        sb.append(", graphicsProfileLevelIndication=").append(graphicsProfileLevelIndication);
        sb.append(", esDescriptors=").append(esDescriptors);
        sb.append(", extensionDescriptors=").append(extensionDescriptors);
        sb.append(", unknownDescriptors=").append(unknownDescriptors);
        sb.append('}');
        return sb.toString();
    }
}