DecoderSpecificInfo.java revision dd9eb897ee7c7b507cbdcf80263bb4b5de6966bf
1/*
2 * Copyright 2011 castLabs, 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.googlecode.mp4parser.boxes.mp4.objectdescriptors;
18
19import com.coremedia.iso.Hex;
20
21import java.io.IOException;
22import java.nio.ByteBuffer;
23import java.util.Arrays;
24
25/**
26 * abstract class DecoderSpecificInfo extends BaseDescriptor : bit(8)
27 * tag=DecSpecificInfoTag
28 * {
29 * // empty. To be filled by classes extending this class.
30 * }
31 */
32@Descriptor(tags = 0x05)
33public class DecoderSpecificInfo extends BaseDescriptor {
34    byte[] bytes;
35
36    @Override
37    public void parseDetail(ByteBuffer bb) throws IOException {
38        if (sizeOfInstance > 0) {
39            bytes = new byte[sizeOfInstance];
40            bb.get(bytes);
41        }
42    }
43
44    public int serializedSize() {
45        return bytes.length;
46    }
47
48    public ByteBuffer serialize() {
49        ByteBuffer out = ByteBuffer.wrap(bytes);
50
51        return out;
52    }
53
54    @Override
55    public String toString() {
56        final StringBuilder sb = new StringBuilder();
57        sb.append("DecoderSpecificInfo");
58        sb.append("{bytes=").append(bytes == null ? "null" : Hex.encodeHex(bytes));
59        sb.append('}');
60        return sb.toString();
61    }
62
63    @Override
64    public boolean equals(Object o) {
65        if (this == o) {
66            return true;
67        }
68        if (o == null || getClass() != o.getClass()) {
69            return false;
70        }
71
72        DecoderSpecificInfo that = (DecoderSpecificInfo) o;
73
74        if (!Arrays.equals(bytes, that.bytes)) {
75            return false;
76        }
77
78        return true;
79    }
80
81    @Override
82    public int hashCode() {
83        return bytes != null ? Arrays.hashCode(bytes) : 0;
84    }
85}
86