1 /* 2 * Copyright 2009 castLabs GmbH, 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.coremedia.iso.boxes.fragment; 18 19 import com.googlecode.mp4parser.boxes.mp4.objectdescriptors.BitReaderBuffer; 20 import com.googlecode.mp4parser.boxes.mp4.objectdescriptors.BitWriterBuffer; 21 22 import java.io.IOException; 23 import java.nio.ByteBuffer; 24 25 /** 26 * bit(6) reserved=0; 27 * unsigned int(2) sample_depends_on; 28 * unsigned int(2) sample_is_depended_on; 29 * unsigned int(2) sample_has_redundancy; 30 * bit(3) sample_padding_value; 31 * bit(1) sample_is_difference_sample; 32 * // i.e. when 1 signals a non-key or non-sync sample 33 * unsigned int(16) sample_degradation_priority; 34 */ 35 public class SampleFlags { 36 private int reserved; 37 private int sampleDependsOn; 38 private int sampleIsDependedOn; 39 private int sampleHasRedundancy; 40 private int samplePaddingValue; 41 private boolean sampleIsDifferenceSample; 42 private int sampleDegradationPriority; 43 44 public SampleFlags() { 45 46 } 47 48 public SampleFlags(ByteBuffer bb) { 49 BitReaderBuffer brb = new BitReaderBuffer(bb); 50 reserved = brb.readBits(6); 51 sampleDependsOn = brb.readBits(2); 52 sampleIsDependedOn = brb.readBits(2); 53 sampleHasRedundancy = brb.readBits(2); 54 samplePaddingValue = brb.readBits(3); 55 sampleIsDifferenceSample = brb.readBits(1) == 1; 56 sampleDegradationPriority = brb.readBits(16); 57 } 58 59 60 public void getContent(ByteBuffer os) { 61 BitWriterBuffer bitWriterBuffer = new BitWriterBuffer(os); 62 bitWriterBuffer.writeBits(reserved, 6); 63 bitWriterBuffer.writeBits(sampleDependsOn, 2); 64 bitWriterBuffer.writeBits(sampleIsDependedOn, 2); 65 bitWriterBuffer.writeBits(sampleHasRedundancy, 2); 66 bitWriterBuffer.writeBits(samplePaddingValue, 3); 67 bitWriterBuffer.writeBits(this.sampleIsDifferenceSample ? 1 : 0, 1); 68 bitWriterBuffer.writeBits(sampleDegradationPriority, 16); 69 } 70 71 public int getReserved() { 72 return reserved; 73 } 74 75 public void setReserved(int reserved) { 76 this.reserved = reserved; 77 } 78 79 /** 80 * @see #setSampleDependsOn(int) 81 */ 82 public int getSampleDependsOn() { 83 return sampleDependsOn; 84 } 85 86 /** 87 * sample_depends_on takes one of the following four values: 88 * <pre> 89 * 0: the dependency of this sample is unknown; 90 * 1: this sample does depend on others (not an I picture); 91 * 2: this sample does not depend on others (I picture); 92 * 3: reserved 93 * </pre> 94 * 95 */ 96 public void setSampleDependsOn(int sampleDependsOn) { 97 this.sampleDependsOn = sampleDependsOn; 98 } 99 100 /** 101 * @see #setSampleIsDependedOn(int) 102 */ 103 public int getSampleIsDependedOn() { 104 return sampleIsDependedOn; 105 } 106 107 /** 108 * sample_is_depended_on takes one of the following four values: 109 * <pre> 110 * 0: the dependency of other samples on this sample is unknown; 111 * 1: other samples may depend on this one (not disposable); 112 * 2: no other sample depends on this one (disposable); 113 * 3: reserved 114 * </pre> 115 * 116 */ 117 public void setSampleIsDependedOn(int sampleIsDependedOn) { 118 this.sampleIsDependedOn = sampleIsDependedOn; 119 } 120 121 /** 122 * @see #setSampleHasRedundancy(int) 123 */ 124 public int getSampleHasRedundancy() { 125 return sampleHasRedundancy; 126 } 127 128 /** 129 * sample_has_redundancy takes one of the following four values: 130 * <pre> 131 * 0: it is unknown whether there is redundant coding in this sample; 132 * 1: there is redundant coding in this sample; 133 * 2: there is no redundant coding in this sample; 134 * 3: reserved 135 * </pre> 136 */ 137 public void setSampleHasRedundancy(int sampleHasRedundancy) { 138 this.sampleHasRedundancy = sampleHasRedundancy; 139 } 140 141 public int getSamplePaddingValue() { 142 return samplePaddingValue; 143 } 144 145 public void setSamplePaddingValue(int samplePaddingValue) { 146 this.samplePaddingValue = samplePaddingValue; 147 } 148 149 public boolean isSampleIsDifferenceSample() { 150 return sampleIsDifferenceSample; 151 } 152 153 154 public void setSampleIsDifferenceSample(boolean sampleIsDifferenceSample) { 155 this.sampleIsDifferenceSample = sampleIsDifferenceSample; 156 } 157 158 public int getSampleDegradationPriority() { 159 return sampleDegradationPriority; 160 } 161 162 public void setSampleDegradationPriority(int sampleDegradationPriority) { 163 this.sampleDegradationPriority = sampleDegradationPriority; 164 } 165 166 @Override 167 public String toString() { 168 return "SampleFlags{" + 169 "reserved=" + reserved + 170 ", sampleDependsOn=" + sampleDependsOn + 171 ", sampleHasRedundancy=" + sampleHasRedundancy + 172 ", samplePaddingValue=" + samplePaddingValue + 173 ", sampleIsDifferenceSample=" + sampleIsDifferenceSample + 174 ", sampleDegradationPriority=" + sampleDegradationPriority + 175 '}'; 176 } 177 178 @Override 179 public boolean equals(Object o) { 180 if (this == o) return true; 181 if (o == null || getClass() != o.getClass()) return false; 182 183 SampleFlags that = (SampleFlags) o; 184 185 if (reserved != that.reserved) return false; 186 if (sampleDegradationPriority != that.sampleDegradationPriority) return false; 187 if (sampleDependsOn != that.sampleDependsOn) return false; 188 if (sampleHasRedundancy != that.sampleHasRedundancy) return false; 189 if (sampleIsDependedOn != that.sampleIsDependedOn) return false; 190 if (sampleIsDifferenceSample != that.sampleIsDifferenceSample) return false; 191 if (samplePaddingValue != that.samplePaddingValue) return false; 192 193 return true; 194 } 195 196 @Override 197 public int hashCode() { 198 int result = reserved; 199 result = 31 * result + sampleDependsOn; 200 result = 31 * result + sampleIsDependedOn; 201 result = 31 * result + sampleHasRedundancy; 202 result = 31 * result + samplePaddingValue; 203 result = 31 * result + (sampleIsDifferenceSample ? 1 : 0); 204 result = 31 * result + sampleDegradationPriority; 205 return result; 206 } 207 } 208