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; 18 19 import com.coremedia.iso.IsoTypeWriter; 20 import com.coremedia.iso.boxes.sampleentry.SampleEntry; 21 import com.googlecode.mp4parser.FullContainerBox; 22 23 import java.nio.ByteBuffer; 24 25 /** 26 * The sample description table gives detailed information about the coding type used, and any initialization 27 * information needed for that coding. <br> 28 * The information stored in the sample description box after the entry-count is both track-type specific as 29 * documented here, and can also have variants within a track type (e.g. different codings may use different 30 * specific information after some common fields, even within a video track).<br> 31 * For video tracks, a VisualSampleEntry is used; for audio tracks, an AudioSampleEntry. Hint tracks use an 32 * entry format specific to their protocol, with an appropriate name. Timed Text tracks use a TextSampleEntry 33 * For hint tracks, the sample description contains appropriate declarative data for the streaming protocol being 34 * used, and the format of the hint track. The definition of the sample description is specific to the protocol. 35 * Multiple descriptions may be used within a track.<br> 36 * The 'protocol' and 'codingname' fields are registered identifiers that uniquely identify the streaming protocol or 37 * compression format decoder to be used. A given protocol or codingname may have optional or required 38 * extensions to the sample description (e.g. codec initialization parameters). All such extensions shall be within 39 * boxes; these boxes occur after the required fields. Unrecognized boxes shall be ignored. 40 * <br> 41 * Defined in ISO/IEC 14496-12 42 * 43 * @see com.coremedia.iso.boxes.sampleentry.VisualSampleEntry 44 * @see com.coremedia.iso.boxes.sampleentry.TextSampleEntry 45 * @see com.coremedia.iso.boxes.sampleentry.AudioSampleEntry 46 */ 47 public class SampleDescriptionBox extends FullContainerBox { 48 public static final String TYPE = "stsd"; 49 SampleDescriptionBox()50 public SampleDescriptionBox() { 51 super(TYPE); 52 } 53 54 @Override getContentSize()55 protected long getContentSize() { 56 return super.getContentSize() + 4; 57 } 58 59 @Override _parseDetails(ByteBuffer content)60 public void _parseDetails(ByteBuffer content) { 61 parseVersionAndFlags(content); 62 content.get(new byte[4]); 63 parseChildBoxes(content); 64 } 65 66 @Override getContent(ByteBuffer byteBuffer)67 protected void getContent(ByteBuffer byteBuffer) { 68 writeVersionAndFlags(byteBuffer); 69 IsoTypeWriter.writeUInt32(byteBuffer, boxes.size()); 70 writeChildBoxes(byteBuffer); 71 } 72 getSampleEntry()73 public SampleEntry getSampleEntry() { 74 for (Box box : boxes) { 75 if (box instanceof SampleEntry) { 76 return (SampleEntry) box; 77 } 78 } 79 return null; 80 } 81 } 82