RollRecoveryEntry.java revision dd9eb897ee7c7b507cbdcf80263bb4b5de6966bf
1/*
2 * Copyright 2012 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.samplegrouping;
18
19import java.nio.ByteBuffer;
20
21/**
22 * roll_distance is a signed integer that gives the number of samples that must be decoded in order for
23 * a sample to be decoded correctly. A positive value indicates the number of samples after the sample
24 * that is a group member that must be decoded such that at the last of these recovery is complete, i.e.
25 * the last sample is correct. A negative value indicates the number of samples before the sample that is
26 * a group member that must be decoded in order for recovery to be complete at the marked sample.
27 * The value zero must not be used; the sync sample table documents random access points for which
28 * no recovery roll is needed.
29 */
30public class RollRecoveryEntry extends GroupEntry {
31    public static final String TYPE = "roll";
32    private short rollDistance;
33
34    public short getRollDistance() {
35        return rollDistance;
36    }
37
38    public void setRollDistance(short rollDistance) {
39        this.rollDistance = rollDistance;
40    }
41
42    @Override
43    public void parse(ByteBuffer byteBuffer) {
44        rollDistance = byteBuffer.getShort();
45    }
46
47    @Override
48    public ByteBuffer get() {
49        ByteBuffer content = ByteBuffer.allocate(2);
50        content.putShort(rollDistance);
51        content.rewind();
52        return content;
53    }
54
55    @Override
56    public boolean equals(Object o) {
57        if (this == o) {
58            return true;
59        }
60        if (o == null || getClass() != o.getClass()) {
61            return false;
62        }
63
64        RollRecoveryEntry entry = (RollRecoveryEntry) o;
65
66        if (rollDistance != entry.rollDistance) {
67            return false;
68        }
69
70        return true;
71    }
72
73    @Override
74    public int hashCode() {
75        return (int) rollDistance;
76    }
77}
78