Coverage Report - org.jaudiotagger.audio.asf.data.FileHeader
 
Classes in this File Line Coverage Branch Coverage Complexity
FileHeader
51%
15/29
N/A
1
 
 1  
 /*
 2  
  * Entagged Audio Tag library
 3  
  * Copyright (c) 2004-2005 Christian Laireiter <liree@web.de>
 4  
  * 
 5  
  * This library is free software; you can redistribute it and/or
 6  
  * modify it under the terms of the GNU Lesser General Public
 7  
  * License as published by the Free Software Foundation; either
 8  
  * version 2.1 of the License, or (at your option) any later version.
 9  
  *  
 10  
  * This library is distributed in the hope that it will be useful,
 11  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 13  
  * Lesser General Public License for more details.
 14  
  * 
 15  
  * You should have received a copy of the GNU Lesser General Public
 16  
  * License along with this library; if not, write to the Free Software
 17  
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 18  
  */
 19  
 package org.jaudiotagger.audio.asf.data;
 20  
 
 21  
 import org.jaudiotagger.audio.asf.util.Utils;
 22  
 
 23  
 import java.math.BigInteger;
 24  
 import java.util.Date;
 25  
 
 26  
 /**
 27  
  * This class stores the information about the file, which is contained within a
 28  
  * special chunk of ASF files.<br>
 29  
  * 
 30  
  * @author Christian Laireiter
 31  
  */
 32  
 public class FileHeader extends Chunk {
 33  
 
 34  
     /**
 35  
      * Duration of the media content in 100ns steps.
 36  
      */
 37  
     private final BigInteger duration;
 38  
 
 39  
     /**
 40  
      * The time the file was created.
 41  
      */
 42  
     private final Date fileCreationTime;
 43  
 
 44  
     /**
 45  
      * Size of the file or stream.
 46  
      */
 47  
     private final BigInteger fileSize;
 48  
 
 49  
     /**
 50  
      * Usually contains value of 2.
 51  
      */
 52  
     private final long flags;
 53  
 
 54  
     /**
 55  
      * Maximum size of stream packages. <br>
 56  
      * <b>Warning: </b> must be same size as {@link #minPackageSize}. Its not
 57  
      * known how to handle deviating values.
 58  
      */
 59  
     private final long maxPackageSize;
 60  
 
 61  
     /**
 62  
      * Minimun size of stream packages. <br>
 63  
      * <b>Warning: </b> must be same size as {@link #maxPackageSize}. Its not
 64  
      * known how to handle deviating values.
 65  
      */
 66  
     private final long minPackageSize;
 67  
 
 68  
     /**
 69  
      * Number of stream packages within the File.
 70  
      */
 71  
     private final BigInteger packageCount;
 72  
 
 73  
     /**
 74  
      * No Idea of the Meaning, but stored anyway. <br>
 75  
      * Source documentation says it is: "Timestamp of end position"
 76  
      */
 77  
     private final BigInteger timeEndPos;
 78  
 
 79  
     /**
 80  
      * Like {@link #timeEndPos}no Idea.
 81  
      */
 82  
     private final BigInteger timeStartPos;
 83  
 
 84  
     /**
 85  
      * Size of an uncompressed video frame.
 86  
      */
 87  
     private final long uncompressedFrameSize;
 88  
 
 89  
     /**
 90  
      * Creates an instance.
 91  
      * 
 92  
      * @param chunckLen
 93  
      *            Length of the file header (chunk)
 94  
      * @param size
 95  
      *            Size of file or stream
 96  
      * @param fileTime
 97  
      *            Time file or stream was created. Time is calculated since 1st
 98  
      *            january of 1601 in 100ns steps.
 99  
      * @param pkgCount
 100  
      *            Number of stream packages.
 101  
      * @param dur
 102  
      *            Duration of media clip in 100ns steps
 103  
      * @param timestampStart
 104  
      *            Timestamp of start {@link #timeStartPos}
 105  
      * @param timestampEnd
 106  
      *            Timestamp of end {@link #timeEndPos}
 107  
      * @param headerFlags
 108  
      *            some stream related flags.
 109  
      * @param minPkgSize
 110  
      *            minimum size of packages
 111  
      * @param maxPkgSize
 112  
      *            maximum size of packages
 113  
      * @param uncmpVideoFrameSize
 114  
      *            Size of an uncompressed Video Frame.
 115  
      */
 116  
     public FileHeader(final BigInteger chunckLen, final BigInteger size,
 117  
             final BigInteger fileTime, final BigInteger pkgCount,
 118  
             final BigInteger dur, final BigInteger timestampStart,
 119  
             final BigInteger timestampEnd, final long headerFlags,
 120  
             final long minPkgSize, final long maxPkgSize,
 121  
             final long uncmpVideoFrameSize) {
 122  278
         super(GUID.GUID_FILE, chunckLen);
 123  278
         this.fileSize = size;
 124  278
         this.packageCount = pkgCount;
 125  278
         this.duration = dur;
 126  278
         this.timeStartPos = timestampStart;
 127  278
         this.timeEndPos = timestampEnd;
 128  278
         this.flags = headerFlags;
 129  278
         this.minPackageSize = minPkgSize;
 130  278
         this.maxPackageSize = maxPkgSize;
 131  278
         this.uncompressedFrameSize = uncmpVideoFrameSize;
 132  278
         this.fileCreationTime = Utils.getDateOf(fileTime).getTime();
 133  278
     }
 134  
 
 135  
     /**
 136  
      * @return Returns the duration.
 137  
      */
 138  
     public BigInteger getDuration() {
 139  198
         return this.duration;
 140  
     }
 141  
 
 142  
     /**
 143  
      * This method converts {@link #getDuration()}from 100ns steps to normal
 144  
      * seconds.
 145  
      * 
 146  
      * @return Duration of the media in seconds.
 147  
      */
 148  
     public int getDurationInSeconds() {
 149  0
         return this.duration.divide(new BigInteger("10000000")).intValue();
 150  
     }
 151  
 
 152  
     /**
 153  
      * @return Returns the fileCreationTime.
 154  
      */
 155  
     public Date getFileCreationTime() {
 156  0
         return new Date(this.fileCreationTime.getTime());
 157  
     }
 158  
 
 159  
     /**
 160  
      * @return Returns the fileSize.
 161  
      */
 162  
     public BigInteger getFileSize() {
 163  202
         return this.fileSize;
 164  
     }
 165  
 
 166  
     /**
 167  
      * @return Returns the flags.
 168  
      */
 169  
     public long getFlags() {
 170  0
         return this.flags;
 171  
     }
 172  
 
 173  
     /**
 174  
      * @return Returns the maxPackageSize.
 175  
      */
 176  
     public long getMaxPackageSize() {
 177  0
         return this.maxPackageSize;
 178  
     }
 179  
 
 180  
     /**
 181  
      * @return Returns the minPackageSize.
 182  
      */
 183  
     public long getMinPackageSize() {
 184  0
         return this.minPackageSize;
 185  
     }
 186  
 
 187  
     /**
 188  
      * @return Returns the packageCount.
 189  
      */
 190  
     public BigInteger getPackageCount() {
 191  0
         return this.packageCount;
 192  
     }
 193  
 
 194  
     /**
 195  
      * This method converts {@link #getDuration()} from 100ns steps to normal
 196  
      * seconds with a fractional part taking milliseconds.<br>
 197  
      * 
 198  
      * @return The duration of the media in seconds (with a precision of
 199  
      *         milliseconds)
 200  
      */
 201  
     public float getPreciseDuration() {
 202  198
         return (float) (getDuration().doubleValue() / 10000000d);
 203  
     }
 204  
 
 205  
     /**
 206  
      * @return Returns the timeEndPos.
 207  
      */
 208  
     public BigInteger getTimeEndPos() {
 209  0
         return this.timeEndPos;
 210  
     }
 211  
 
 212  
     /**
 213  
      * @return Returns the timeStartPos.
 214  
      */
 215  
     public BigInteger getTimeStartPos() {
 216  0
         return this.timeStartPos;
 217  
     }
 218  
 
 219  
     /**
 220  
      * @return Returns the uncompressedFrameSize.
 221  
      */
 222  
     public long getUncompressedFrameSize() {
 223  0
         return this.uncompressedFrameSize;
 224  
     }
 225  
 
 226  
     /**
 227  
      * (overridden)
 228  
      * 
 229  
      * @see org.jaudiotagger.audio.asf.data.Chunk#prettyPrint(String)
 230  
      */
 231  
     @Override
 232  
     public String prettyPrint(final String prefix) {
 233  0
         final StringBuilder result = new StringBuilder(super.prettyPrint(prefix));
 234  0
         result.append(prefix).append("  |-> Filesize      = ").append(
 235  
                 getFileSize().toString()).append(" Bytes").append(
 236  
                 Utils.LINE_SEPARATOR);
 237  0
         result.append(prefix).append("  |-> Media duration= ").append(
 238  
                 getDuration().divide(new BigInteger("10000")).toString())
 239  
                 .append(" ms").append(Utils.LINE_SEPARATOR);
 240  0
         result.append(prefix).append("  |-> Created at    = ").append(
 241  
                 getFileCreationTime()).append(Utils.LINE_SEPARATOR);
 242  0
         return result.toString();
 243  
     }
 244  
 }