1 /* 2 * Copyright 2008 CoreMedia AG, Hamburg 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.sampleentry; 18 19 20 import com.coremedia.iso.IsoFile; 21 import com.coremedia.iso.IsoTypeReader; 22 import com.coremedia.iso.IsoTypeWriter; 23 import com.googlecode.mp4parser.AbstractBox; 24 25 import java.nio.ByteBuffer; 26 27 /** 28 * AMR audio format specific subbox of an audio sample entry. 29 * 30 * @see com.coremedia.iso.boxes.sampleentry.AudioSampleEntry 31 */ 32 public class AmrSpecificBox extends AbstractBox { 33 public static final String TYPE = "damr"; 34 35 private String vendor; 36 private int decoderVersion; 37 private int modeSet; 38 private int modeChangePeriod; 39 private int framesPerSample; 40 AmrSpecificBox()41 public AmrSpecificBox() { 42 super(TYPE); 43 } 44 getVendor()45 public String getVendor() { 46 return vendor; 47 } 48 getDecoderVersion()49 public int getDecoderVersion() { 50 return decoderVersion; 51 } 52 getModeSet()53 public int getModeSet() { 54 return modeSet; 55 } 56 getModeChangePeriod()57 public int getModeChangePeriod() { 58 return modeChangePeriod; 59 } 60 getFramesPerSample()61 public int getFramesPerSample() { 62 return framesPerSample; 63 } 64 getContentSize()65 protected long getContentSize() { 66 return 9; 67 } 68 69 @Override _parseDetails(ByteBuffer content)70 public void _parseDetails(ByteBuffer content) { 71 byte[] v = new byte[4]; 72 content.get(v); 73 vendor = IsoFile.bytesToFourCC(v); 74 75 decoderVersion = IsoTypeReader.readUInt8(content); 76 modeSet = IsoTypeReader.readUInt16(content); 77 modeChangePeriod = IsoTypeReader.readUInt8(content); 78 framesPerSample = IsoTypeReader.readUInt8(content); 79 80 } 81 82 getContent(ByteBuffer byteBuffer)83 public void getContent(ByteBuffer byteBuffer) { 84 byteBuffer.put(IsoFile.fourCCtoBytes(vendor)); 85 IsoTypeWriter.writeUInt8(byteBuffer, decoderVersion); 86 IsoTypeWriter.writeUInt16(byteBuffer, modeSet); 87 IsoTypeWriter.writeUInt8(byteBuffer, modeChangePeriod); 88 IsoTypeWriter.writeUInt8(byteBuffer, framesPerSample); 89 } 90 toString()91 public String toString() { 92 StringBuilder buffer = new StringBuilder(); 93 buffer.append("AmrSpecificBox[vendor=").append(getVendor()); 94 buffer.append(";decoderVersion=").append(getDecoderVersion()); 95 buffer.append(";modeSet=").append(getModeSet()); 96 buffer.append(";modeChangePeriod=").append(getModeChangePeriod()); 97 buffer.append(";framesPerSample=").append(getFramesPerSample()); 98 buffer.append("]"); 99 return buffer.toString(); 100 } 101 } 102