| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
package org.jaudiotagger.audio.asf.data; |
| 20 | |
|
| 21 | |
import org.jaudiotagger.audio.asf.util.Utils; |
| 22 | |
|
| 23 | |
import java.util.Arrays; |
| 24 | |
import java.util.HashMap; |
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | 44 | public final class GUID |
| 33 | |
{ |
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | 44 | public final static GUID GUID_AUDIO_ERROR_CONCEALEMENT_ABSENT = new GUID(new int[]{0x40, 0xA4, 0xF1, 0x49, 0xCE, 0x4E, 0xD0, 0x11, 0xA3, 0xAC, 0x00, 0xA0, 0xC9, 0x03, 0x48, 0xF6}, "Audio error concealment absent."); |
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | 44 | public final static GUID GUID_AUDIO_ERROR_CONCEALEMENT_INTERLEAVED = new GUID(new int[]{0x40, 0xA4, 0xF1, 0x49, 0xCE, 0x4E, 0xD0, 0x11, 0xA3, 0xAC, 0x00, 0xA0, 0xC9, 0x03, 0x48, 0xF6}, "Interleaved audio error concealment."); |
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | 44 | public final static GUID GUID_AUDIOSTREAM = new GUID(new int[]{0x40, 0x9E, 0x69, 0xF8, 0x4D, 0x5B, 0xCF, 0x11, 0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B}, " Audio stream"); |
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | 44 | public final static GUID GUID_CONTENT_BRANDING = new GUID(new int[]{0xFA, 0xB3, 0x11, 0x22, 0x23, 0xBD, 0xD2, 0x11, 0xB4, 0xB7, 0x00, 0xA0, 0xC9, 0x55, 0xFC, 0x6E}); |
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | 44 | public final static GUID GUID_CONTENT_ENCRYPTION = new GUID(new int[]{0xfb, 0xb3, 0x11, 0x22, 0x23, 0xbd, 0xd2, 0x11, 0xb4, 0xb7, 0x00, 0xa0, 0xc9, 0x55, 0xfc, 0x6e}, "Content Encryption Object"); |
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | 44 | public final static GUID GUID_CONTENTDESCRIPTION = new GUID(new int[]{0x33, 0x26, 0xB2, 0x75, 0x8E, 0x66, 0xCF, 0x11, 0xA6, 0xD9, 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C}, "Content Description"); |
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | 44 | public final static GUID GUID_ENCODING = new GUID(new int[]{0x40, 0x52, 0xD1, 0x86, 0x1D, 0x31, 0xD0, 0x11, 0xA3, 0xA4, 0x00, 0xA0, 0xC9, 0x03, 0x48, 0xF6}, "Encoding description"); |
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | 44 | public final static GUID GUID_EXTENDED_CONTENT_DESCRIPTION = new GUID(new int[]{0x40, 0xA4, 0xD0, 0xD2, 0x07, 0xE3, 0xD2, 0x11, 0x97, 0xF0, 0x00, 0xA0, 0xC9, 0x5E, 0xA8, 0x50}, "Extended Content Description"); |
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | 44 | public final static GUID GUID_FILE = new GUID(new int[]{0xA1, 0xDC, 0xAB, 0x8C, 0x47, 0xA9, 0xCF, 0x11, 0x8E, 0xE4, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65}, "File header"); |
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | 44 | public final static GUID GUID_HEADER = new GUID(new int[]{0x30, 0x26, 0xb2, 0x75, 0x8e, 0x66, 0xcf, 0x11, 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c}, "Asf header"); |
| 90 | |
|
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | 44 | public final static GUID GUID_HEADER_EXTENSION = new GUID(new int[]{0xB5, 0x03, 0xBF, 0x5F, 0x2E, 0xA9, 0xCF, 0x11, 0x8E, 0xE3, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65}, "Header Extension"); |
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
public final static int GUID_LENGTH = 16; |
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | 44 | public final static GUID GUID_STREAM = new GUID(new int[]{0x91, 0x07, 0xDC, 0xB7, 0xB7, 0xA9, 0xCF, 0x11, 0x8E, 0xE6, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65}, "Stream"); |
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | 44 | public final static GUID GUID_STREAM_BITRATE_PROPERTIES = new GUID(new int[]{0xCE, 0x75, 0xF8, 0x7B, 0x8D, 0x46, 0xD1, 0x11, 0x8D, 0x82, 0x00, 0x60, 0x97, 0xC9, 0xA2, 0xB2}, "Stream bitrate properties"); |
| 111 | |
|
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | |
|
| 118 | |
private final static HashMap<GUID, GUID> GUID_TO_CONFIGURED; |
| 119 | |
|
| 120 | |
|
| 121 | |
|
| 122 | |
|
| 123 | |
|
| 124 | 44 | public final static GUID GUID_UNSPECIFIED = new GUID(new int[]{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, "Unspecified"); |
| 125 | |
|
| 126 | |
|
| 127 | |
|
| 128 | |
|
| 129 | 44 | public final static GUID GUID_VIDEOSTREAM = new GUID(new int[]{0xC0, 0xEF, 0x19, 0xBC, 0x4D, 0x5B, 0xCF, 0x11, 0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B}, "Video stream"); |
| 130 | |
|
| 131 | |
|
| 132 | |
|
| 133 | |
|
| 134 | |
public final static GUID[] KNOWN_GUIDS; |
| 135 | |
|
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 139 | 44 | public final static GUID SCRIPT_COMMAND_OBJECT = new GUID(new int[]{0x30, 0x1a, 0xfb, 0x1e, 0x62, 0x0b, 0xd0, 0x11, 0xa3, 0x9b, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6}, "Script Command Object"); |
| 140 | |
|
| 141 | |
static |
| 142 | |
{ |
| 143 | 44 | KNOWN_GUIDS = new GUID[]{GUID_AUDIO_ERROR_CONCEALEMENT_ABSENT, GUID_AUDIO_ERROR_CONCEALEMENT_INTERLEAVED, GUID_CONTENTDESCRIPTION, GUID_AUDIOSTREAM, GUID_ENCODING, GUID_FILE, GUID_HEADER, GUID_STREAM, GUID_EXTENDED_CONTENT_DESCRIPTION, GUID_VIDEOSTREAM, GUID_HEADER_EXTENSION, GUID_STREAM_BITRATE_PROPERTIES, GUID_HEADER_EXTENSION, GUID_STREAM_BITRATE_PROPERTIES, SCRIPT_COMMAND_OBJECT, GUID_CONTENT_ENCRYPTION, GUID_CONTENT_BRANDING, GUID_UNSPECIFIED}; |
| 144 | 44 | GUID_TO_CONFIGURED = new HashMap<GUID, GUID>(KNOWN_GUIDS.length); |
| 145 | 836 | for (final GUID curr : KNOWN_GUIDS) |
| 146 | |
{ |
| 147 | 792 | GUID_TO_CONFIGURED.put(curr, curr); |
| 148 | |
} |
| 149 | 44 | } |
| 150 | |
|
| 151 | |
|
| 152 | |
|
| 153 | |
|
| 154 | |
|
| 155 | |
|
| 156 | |
|
| 157 | |
|
| 158 | |
|
| 159 | |
public static boolean assertGUID(int[] value) |
| 160 | |
{ |
| 161 | 2153 | boolean result = false; |
| 162 | 2153 | if (value != null) |
| 163 | |
{ |
| 164 | 2153 | if (value.length == GUID.GUID_LENGTH) |
| 165 | |
{ |
| 166 | 2153 | result = true; |
| 167 | |
} |
| 168 | |
} |
| 169 | 2153 | return result; |
| 170 | |
} |
| 171 | |
|
| 172 | |
|
| 173 | |
|
| 174 | |
|
| 175 | |
|
| 176 | |
|
| 177 | |
|
| 178 | |
public static GUID getConfigured(final GUID orig) |
| 179 | |
{ |
| 180 | 0 | assert orig != null; |
| 181 | 0 | GUID result = null; |
| 182 | 0 | if (orig != null) |
| 183 | |
{ |
| 184 | 0 | result = GUID_TO_CONFIGURED.get(orig); |
| 185 | |
} |
| 186 | 0 | return result; |
| 187 | |
} |
| 188 | |
|
| 189 | |
|
| 190 | |
|
| 191 | |
|
| 192 | |
|
| 193 | |
|
| 194 | |
|
| 195 | |
|
| 196 | |
|
| 197 | |
|
| 198 | |
public static String getGuidDescription(GUID guid) |
| 199 | |
{ |
| 200 | 0 | String result = null; |
| 201 | 0 | if (guid == null) |
| 202 | |
{ |
| 203 | 0 | throw new IllegalArgumentException("Argument must not be null."); |
| 204 | |
} |
| 205 | 0 | if (getConfigured(guid) != null) |
| 206 | |
{ |
| 207 | 0 | result = getConfigured(guid).getDescription(); |
| 208 | |
} |
| 209 | 0 | return result; |
| 210 | |
} |
| 211 | |
|
| 212 | |
|
| 213 | |
|
| 214 | |
|
| 215 | 2153 | private String description = ""; |
| 216 | |
|
| 217 | |
|
| 218 | |
|
| 219 | |
|
| 220 | |
|
| 221 | 2153 | private int[] guid = null; |
| 222 | |
|
| 223 | |
|
| 224 | |
|
| 225 | |
|
| 226 | |
|
| 227 | |
|
| 228 | |
private int hashCode; |
| 229 | |
|
| 230 | |
|
| 231 | |
|
| 232 | |
|
| 233 | |
|
| 234 | |
|
| 235 | |
public GUID(int[] value) |
| 236 | 2153 | { |
| 237 | 2153 | setGUID(value); |
| 238 | 2153 | } |
| 239 | |
|
| 240 | |
|
| 241 | |
|
| 242 | |
|
| 243 | |
|
| 244 | |
|
| 245 | |
|
| 246 | |
|
| 247 | |
public GUID(int[] value, String desc) |
| 248 | |
{ |
| 249 | 660 | this(value); |
| 250 | 660 | if (desc == null) |
| 251 | |
{ |
| 252 | 0 | throw new IllegalArgumentException("Argument must not be null."); |
| 253 | |
} |
| 254 | 660 | this.description = desc; |
| 255 | 660 | } |
| 256 | |
|
| 257 | |
|
| 258 | |
|
| 259 | |
|
| 260 | |
|
| 261 | |
|
| 262 | |
|
| 263 | |
public boolean equals(Object obj) |
| 264 | |
{ |
| 265 | 16213 | boolean result = false; |
| 266 | 16213 | if (obj instanceof GUID) |
| 267 | |
{ |
| 268 | 16213 | GUID other = (GUID) obj; |
| 269 | 16213 | result = Arrays.equals(this.getGUID(), other.getGUID()); |
| 270 | |
} |
| 271 | 16213 | return result; |
| 272 | |
} |
| 273 | |
|
| 274 | |
|
| 275 | |
|
| 276 | |
|
| 277 | |
|
| 278 | |
|
| 279 | |
|
| 280 | |
public byte[] getBytes() |
| 281 | |
{ |
| 282 | 275 | byte[] result = new byte[this.guid.length]; |
| 283 | 4675 | for (int i = 0; i < result.length; i++) |
| 284 | |
{ |
| 285 | 4400 | result[i] = (byte) (this.guid[i] & 0xFF); |
| 286 | |
} |
| 287 | 275 | return result; |
| 288 | |
} |
| 289 | |
|
| 290 | |
|
| 291 | |
|
| 292 | |
|
| 293 | |
public String getDescription() |
| 294 | |
{ |
| 295 | 0 | return description; |
| 296 | |
} |
| 297 | |
|
| 298 | |
|
| 299 | |
|
| 300 | |
|
| 301 | |
|
| 302 | |
|
| 303 | |
public int[] getGUID() |
| 304 | |
{ |
| 305 | 32426 | int[] copy = new int[this.guid.length]; |
| 306 | 32426 | System.arraycopy(this.guid, 0, copy, 0, this.guid.length); |
| 307 | 32426 | return copy; |
| 308 | |
} |
| 309 | |
|
| 310 | |
|
| 311 | |
|
| 312 | |
|
| 313 | |
@Override |
| 314 | |
public int hashCode() |
| 315 | |
{ |
| 316 | 5636 | if (this.hashCode == -1) |
| 317 | |
{ |
| 318 | 0 | int tmp = 0; |
| 319 | 0 | for (int curr : getGUID()) |
| 320 | |
{ |
| 321 | 0 | tmp = tmp * 31 + curr; |
| 322 | |
} |
| 323 | 0 | this.hashCode = tmp; |
| 324 | |
} |
| 325 | 5636 | return this.hashCode; |
| 326 | |
} |
| 327 | |
|
| 328 | |
|
| 329 | |
|
| 330 | |
|
| 331 | |
|
| 332 | |
|
| 333 | |
|
| 334 | |
public boolean isValid() |
| 335 | |
{ |
| 336 | 0 | return assertGUID(getGUID()); |
| 337 | |
} |
| 338 | |
|
| 339 | |
|
| 340 | |
|
| 341 | |
|
| 342 | |
|
| 343 | |
|
| 344 | |
|
| 345 | |
|
| 346 | |
private void setGUID(int[] value) |
| 347 | |
{ |
| 348 | 2153 | if (assertGUID(value)) |
| 349 | |
{ |
| 350 | 2153 | this.guid = new int[GUID_LENGTH]; |
| 351 | 2153 | System.arraycopy(value, 0, this.guid, 0, GUID_LENGTH); |
| 352 | |
} |
| 353 | |
else |
| 354 | |
{ |
| 355 | 0 | throw new IllegalArgumentException("The given guid doesn't match the GUID specification."); |
| 356 | |
} |
| 357 | 2153 | } |
| 358 | |
|
| 359 | |
|
| 360 | |
|
| 361 | |
|
| 362 | |
|
| 363 | |
|
| 364 | |
public String toString() |
| 365 | |
{ |
| 366 | 0 | StringBuffer result = new StringBuffer(); |
| 367 | 0 | String descr = getDescription(); |
| 368 | 0 | if (Utils.isBlank(descr)) |
| 369 | |
{ |
| 370 | 0 | descr = getGuidDescription(this); |
| 371 | |
} |
| 372 | 0 | if (!Utils.isBlank(descr)) |
| 373 | |
{ |
| 374 | 0 | result.append("Description: " + descr + Utils.LINE_SEPARATOR + " "); |
| 375 | |
} |
| 376 | 0 | for (int i = 0; i < guid.length; i++) |
| 377 | |
{ |
| 378 | 0 | String tmp = Integer.toHexString(guid[i]); |
| 379 | 0 | if (tmp.length() < 2) |
| 380 | |
{ |
| 381 | 0 | tmp = "0" + tmp; |
| 382 | |
} |
| 383 | 0 | if (i > 0) |
| 384 | |
{ |
| 385 | 0 | result.append(", "); |
| 386 | |
} |
| 387 | 0 | result.append("0x" + tmp); |
| 388 | |
} |
| 389 | 0 | return result.toString(); |
| 390 | |
} |
| 391 | |
} |