TemporalLevelEntry.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 * The Temporal Level sample grouping ('tele') provides a codec-independent sample grouping that can be used to group samples (access units) in a track (and potential track fragments) according to temporal level, where samples of one temporal level have no coding dependencies on samples of higher temporal levels. The temporal level equals the sample group description index (taking values 1, 2, 3, etc). The bitstream containing only the access units from the first temporal level to a higher temporal level remains conforming to the coding standard. 23 * 24 * A grouping according to temporal level facilitates easy extraction of temporal subsequences, for instance using the Subsegment Indexing box in 0. 25 * 26 */ 27public class TemporalLevelEntry extends GroupEntry { 28 public static final String TYPE = "tele"; 29 private boolean levelIndependentlyDecodable; 30 private short reserved; 31 32 public boolean isLevelIndependentlyDecodable() { 33 return levelIndependentlyDecodable; 34 } 35 36 public void setLevelIndependentlyDecodable(boolean levelIndependentlyDecodable) { 37 this.levelIndependentlyDecodable = levelIndependentlyDecodable; 38 } 39 40 @Override 41 public void parse(ByteBuffer byteBuffer) { 42 final byte b = byteBuffer.get(); 43 levelIndependentlyDecodable = ((b & 0x80) == 0x80); 44 } 45 46 @Override 47 public ByteBuffer get() { 48 ByteBuffer content = ByteBuffer.allocate(1); 49 content.put((byte) (levelIndependentlyDecodable ? 0x80 : 0x00)); 50 content.rewind(); 51 return content; 52 } 53 54 @Override 55 public boolean equals(Object o) { 56 if (this == o) return true; 57 if (o == null || getClass() != o.getClass()) return false; 58 59 TemporalLevelEntry that = (TemporalLevelEntry) o; 60 61 if (levelIndependentlyDecodable != that.levelIndependentlyDecodable) return false; 62 if (reserved != that.reserved) return false; 63 64 return true; 65 } 66 67 @Override 68 public int hashCode() { 69 int result = (levelIndependentlyDecodable ? 1 : 0); 70 result = 31 * result + (int) reserved; 71 return result; 72 } 73 74 @Override 75 public String toString() { 76 final StringBuilder sb = new StringBuilder(); 77 sb.append("TemporalLevelEntry"); 78 sb.append("{levelIndependentlyDecodable=").append(levelIndependentlyDecodable); 79 sb.append('}'); 80 return sb.toString(); 81 } 82} 83