| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| FileHeader |
|
| 1.0;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 java.math.BigInteger; | |
| 22 | import java.util.Date; | |
| 23 | ||
| 24 | import org.jaudiotagger.audio.asf.util.Utils; | |
| 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 | /** | |
| 36 | * Duration of the media content in 100ns steps. | |
| 37 | */ | |
| 38 | private final BigInteger duration; | |
| 39 | ||
| 40 | /** | |
| 41 | * The time the file was created. | |
| 42 | */ | |
| 43 | private final Date fileCreationTime; | |
| 44 | ||
| 45 | /** | |
| 46 | * Size of the file or stream. | |
| 47 | */ | |
| 48 | private BigInteger fileSize; | |
| 49 | ||
| 50 | /** | |
| 51 | * Usually contains value of 2. | |
| 52 | */ | |
| 53 | private final long flags; | |
| 54 | ||
| 55 | /** | |
| 56 | * Maximum size of stream packages. <br> | |
| 57 | * <b>Warning: </b> must be same size as {@link #minPackageSize}. Its not | |
| 58 | * known how to handle deviating values. | |
| 59 | */ | |
| 60 | private final long maxPackageSize; | |
| 61 | ||
| 62 | /** | |
| 63 | * Minimun size of stream packages. <br> | |
| 64 | * <b>Warning: </b> must be same size as {@link #maxPackageSize}. Its not | |
| 65 | * known how to handle deviating values. | |
| 66 | */ | |
| 67 | private final long minPackageSize; | |
| 68 | ||
| 69 | /** | |
| 70 | * Number of stream packages within the File. | |
| 71 | */ | |
| 72 | private final BigInteger packageCount; | |
| 73 | ||
| 74 | /** | |
| 75 | * No Idea of the Meaning, but stored anyway. <br> | |
| 76 | * Source documentation says it is: "Timestamp of end position" | |
| 77 | */ | |
| 78 | private final BigInteger timeEndPos; | |
| 79 | ||
| 80 | /** | |
| 81 | * Like {@link #timeEndPos}no Idea. | |
| 82 | */ | |
| 83 | private final BigInteger timeStartPos; | |
| 84 | ||
| 85 | /** | |
| 86 | * Size of an uncompressed video frame. | |
| 87 | */ | |
| 88 | private final long uncompressedFrameSize; | |
| 89 | ||
| 90 | /** | |
| 91 | * Creates an instance. | |
| 92 | * | |
| 93 | * @param chunckLen Length of the file header (chunk) | |
| 94 | * @param size Size of file or stream | |
| 95 | * @param fileTime Time file or stream was created. Time is calculated since 1st | |
| 96 | * january of 1601 in 100ns steps. | |
| 97 | * @param pkgCount Number of stream packages. | |
| 98 | * @param dur Duration of media clip in 100ns steps | |
| 99 | * @param timestampStart Timestamp of start {@link #timeStartPos} | |
| 100 | * @param timestampEnd Timestamp of end {@link #timeEndPos} | |
| 101 | * @param headerFlags some stream related flags. | |
| 102 | * @param minPkgSize minimun size of packages | |
| 103 | * @param maxPkgSize maximum size of packages | |
| 104 | * @param uncmpVideoFrameSize Size of an uncompressed Video Frame. | |
| 105 | */ | |
| 106 | public FileHeader(BigInteger chunckLen, | |
| 107 | BigInteger size, BigInteger fileTime, BigInteger pkgCount, | |
| 108 | BigInteger dur, BigInteger timestampStart, BigInteger timestampEnd, | |
| 109 | long headerFlags, long minPkgSize, long maxPkgSize, | |
| 110 | long uncmpVideoFrameSize) | |
| 111 | { | |
| 112 | 55 | super(GUID.GUID_FILE, chunckLen); |
| 113 | 55 | this.fileSize = size; |
| 114 | 55 | this.packageCount = pkgCount; |
| 115 | 55 | this.duration = dur; |
| 116 | 55 | this.timeStartPos = timestampStart; |
| 117 | 55 | this.timeEndPos = timestampEnd; |
| 118 | 55 | this.flags = headerFlags; |
| 119 | 55 | this.minPackageSize = minPkgSize; |
| 120 | 55 | this.maxPackageSize = maxPkgSize; |
| 121 | 55 | this.uncompressedFrameSize = uncmpVideoFrameSize; |
| 122 | 55 | this.fileCreationTime = Utils.getDateOf(fileTime).getTime(); |
| 123 | 55 | } |
| 124 | ||
| 125 | /** | |
| 126 | * @return Returns the duration. | |
| 127 | */ | |
| 128 | public BigInteger getDuration() | |
| 129 | { | |
| 130 | 39 | return duration; |
| 131 | } | |
| 132 | ||
| 133 | /** | |
| 134 | * This method converts {@link #getDuration()}from 100ns steps to normal | |
| 135 | * seconds. | |
| 136 | * | |
| 137 | * @return Duration of the media in seconds. | |
| 138 | */ | |
| 139 | public int getDurationInSeconds() | |
| 140 | { | |
| 141 | 0 | return duration.divide(new BigInteger("10000000")).intValue(); |
| 142 | } | |
| 143 | ||
| 144 | /** | |
| 145 | * @return Returns the fileCreationTime. | |
| 146 | */ | |
| 147 | public Date getFileCreationTime() | |
| 148 | { | |
| 149 | 0 | return fileCreationTime; |
| 150 | } | |
| 151 | ||
| 152 | /** | |
| 153 | * @return Returns the fileSize. | |
| 154 | */ | |
| 155 | public BigInteger getFileSize() | |
| 156 | { | |
| 157 | 40 | return fileSize; |
| 158 | } | |
| 159 | ||
| 160 | /** | |
| 161 | * @return Returns the flags. | |
| 162 | */ | |
| 163 | public long getFlags() | |
| 164 | { | |
| 165 | 0 | return flags; |
| 166 | } | |
| 167 | ||
| 168 | /** | |
| 169 | * @return Returns the maxPackageSize. | |
| 170 | */ | |
| 171 | public long getMaxPackageSize() | |
| 172 | { | |
| 173 | 0 | return maxPackageSize; |
| 174 | } | |
| 175 | ||
| 176 | /** | |
| 177 | * @return Returns the minPackageSize. | |
| 178 | */ | |
| 179 | public long getMinPackageSize() | |
| 180 | { | |
| 181 | 0 | return minPackageSize; |
| 182 | } | |
| 183 | ||
| 184 | /** | |
| 185 | * @return Returns the packageCount. | |
| 186 | */ | |
| 187 | public BigInteger getPackageCount() | |
| 188 | { | |
| 189 | 0 | return packageCount; |
| 190 | } | |
| 191 | ||
| 192 | /** | |
| 193 | * This method converts {@link #getDuration()} from 100ns steps to normal | |
| 194 | * seconds with a fractional part taking milliseconds.<br> | |
| 195 | * | |
| 196 | * @return The duraion of the media in seconds (with a precision of | |
| 197 | * milliseconds) | |
| 198 | */ | |
| 199 | public float getPreciseDuration() | |
| 200 | { | |
| 201 | 39 | double doub = getDuration().doubleValue() / 10000000d; |
| 202 | 39 | return (float) doub; |
| 203 | } | |
| 204 | ||
| 205 | /** | |
| 206 | * @return Returns the timeEndPos. | |
| 207 | */ | |
| 208 | public BigInteger getTimeEndPos() | |
| 209 | { | |
| 210 | 0 | return timeEndPos; |
| 211 | } | |
| 212 | ||
| 213 | /** | |
| 214 | * @return Returns the timeStartPos. | |
| 215 | */ | |
| 216 | public BigInteger getTimeStartPos() | |
| 217 | { | |
| 218 | 0 | return timeStartPos; |
| 219 | } | |
| 220 | ||
| 221 | /** | |
| 222 | * @return Returns the uncompressedFrameSize. | |
| 223 | */ | |
| 224 | public long getUncompressedFrameSize() | |
| 225 | { | |
| 226 | 0 | return uncompressedFrameSize; |
| 227 | } | |
| 228 | ||
| 229 | /** | |
| 230 | * (overridden) | |
| 231 | * | |
| 232 | * @see org.jaudiotagger.audio.asf.data.Chunk#prettyPrint(String) | |
| 233 | */ | |
| 234 | public String prettyPrint(final String prefix) | |
| 235 | { | |
| 236 | 0 | StringBuffer result = new StringBuffer(super.prettyPrint(prefix)); |
| 237 | 0 | result.append(prefix + " |-> Filesize = " + getFileSize().toString() + " Bytes" + Utils.LINE_SEPARATOR); |
| 238 | 0 | result |
| 239 | .append(prefix + " |-> Media duration= " | |
| 240 | + getDuration().divide(new BigInteger("10000")).toString() | |
| 241 | + " ms" + Utils.LINE_SEPARATOR); | |
| 242 | 0 | result.append(prefix + " |-> Created at = " + getFileCreationTime() + Utils.LINE_SEPARATOR); |
| 243 | 0 | return result.toString(); |
| 244 | } | |
| 245 | } |