• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package com.googlecode.mp4parser.boxes.mp4.samplegrouping;
18 
19 import com.coremedia.iso.IsoTypeReader;
20 
21 import java.nio.ByteBuffer;
22 
23 /**
24  * For some coding systems a sync sample is specified to be a random access point after which all samples in decoding order can be correctly decoded. However, it may be possible to encode an “open” random access point, after which all samples in output order can be correctly decoded, but some samples following the random access point in decoding order and preceding the random access point in output order need not be correctly decodable. For example, an intra picture starting an open group of pictures can be followed in decoding order by (bi-)predicted pictures that however precede the intra picture in output order; though they possibly cannot be correctly decoded if the decoding starts from the intra picture, they are not needed.
25  *
26  * Such “open” random-access samples can be marked by being a member of this group. Samples marked by this group must be random access points, and may also be sync points (i.e. it is not required that samples marked by the sync sample table be excluded).
27  *
28  */
29 public class VisualRandomAccessEntry extends GroupEntry {
30     public static final String TYPE = "rap ";
31     private boolean numLeadingSamplesKnown;
32     private short numLeadingSamples;
33 
isNumLeadingSamplesKnown()34     public boolean isNumLeadingSamplesKnown() {
35         return numLeadingSamplesKnown;
36     }
37 
setNumLeadingSamplesKnown(boolean numLeadingSamplesKnown)38     public void setNumLeadingSamplesKnown(boolean numLeadingSamplesKnown) {
39         this.numLeadingSamplesKnown = numLeadingSamplesKnown;
40     }
41 
getNumLeadingSamples()42     public short getNumLeadingSamples() {
43         return numLeadingSamples;
44     }
45 
setNumLeadingSamples(short numLeadingSamples)46     public void setNumLeadingSamples(short numLeadingSamples) {
47         this.numLeadingSamples = numLeadingSamples;
48     }
49 
50     @Override
parse(ByteBuffer byteBuffer)51     public void parse(ByteBuffer byteBuffer) {
52         final byte b = byteBuffer.get();
53         numLeadingSamplesKnown = ((b & 0x80) == 0x80);
54         numLeadingSamples = (short) (b & 0x7f);
55     }
56 
57     @Override
get()58     public ByteBuffer get() {
59         ByteBuffer content = ByteBuffer.allocate(1);
60         content.put((byte) ((numLeadingSamplesKnown? 0x80 : 0x00)| (numLeadingSamples & 0x7f)));
61         content.rewind();
62         return content;
63     }
64 
65     @Override
equals(Object o)66     public boolean equals(Object o) {
67         if (this == o) return true;
68         if (o == null || getClass() != o.getClass()) return false;
69 
70         VisualRandomAccessEntry that = (VisualRandomAccessEntry) o;
71 
72         if (numLeadingSamples != that.numLeadingSamples) return false;
73         if (numLeadingSamplesKnown != that.numLeadingSamplesKnown) return false;
74 
75         return true;
76     }
77 
78     @Override
hashCode()79     public int hashCode() {
80         int result = (numLeadingSamplesKnown ? 1 : 0);
81         result = 31 * result + (int) numLeadingSamples;
82         return result;
83     }
84 
85     @Override
toString()86     public String toString() {
87         final StringBuilder sb = new StringBuilder();
88         sb.append("VisualRandomAccessEntry");
89         sb.append("{numLeadingSamplesKnown=").append(numLeadingSamplesKnown);
90         sb.append(", numLeadingSamples=").append(numLeadingSamples);
91         sb.append('}');
92         return sb.toString();
93     }
94 }
95