Home | History | Annotate | Download | only in boxes
      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.googlecode.mp4parser.AbstractContainerBox;
     20 
     21 /**
     22  * Tracks are used for two purposes: (a) to contain media data (media tracks) and (b) to contain packetization
     23  * information for streaming protocols (hint tracks).  <br>
     24  * There shall be at least one media track within an ISO file, and all the media tracks that contributed to the hint
     25  * tracks shall remain in the file, even if the media data within them is not referenced by the hint tracks; after
     26  * deleting all hint tracks, the entire un-hinted presentation shall remain.
     27  */
     28 public class TrackBox extends AbstractContainerBox {
     29     public static final String TYPE = "trak";
     30 
     31     public TrackBox() {
     32         super(TYPE);
     33     }
     34 
     35     public TrackHeaderBox getTrackHeaderBox() {
     36         for (Box box : boxes) {
     37             if (box instanceof TrackHeaderBox) {
     38                 return (TrackHeaderBox) box;
     39             }
     40         }
     41         return null;
     42     }
     43 
     44     /**
     45      * Gets the SampleTableBox at mdia/minf/stbl if existing.
     46      *
     47      * @return the SampleTableBox or <code>null</code>
     48      */
     49     public SampleTableBox getSampleTableBox() {
     50         MediaBox mdia = getMediaBox();
     51         if (mdia != null) {
     52             MediaInformationBox minf = mdia.getMediaInformationBox();
     53             if (minf != null) {
     54                 return minf.getSampleTableBox();
     55             }
     56         }
     57         return null;
     58 
     59     }
     60 
     61 
     62     public MediaBox getMediaBox() {
     63         for (Box box : boxes) {
     64             if (box instanceof MediaBox) {
     65                 return (MediaBox) box;
     66             }
     67         }
     68         return null;
     69     }
     70 
     71 }
     72