| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| StreamBitratePropertiesReader |
|
| 1.25;1.25 |
| 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.io; | |
| 20 | ||
| 21 | import org.jaudiotagger.audio.asf.data.Chunk; | |
| 22 | import org.jaudiotagger.audio.asf.data.GUID; | |
| 23 | import org.jaudiotagger.audio.asf.data.StreamBitratePropertiesChunk; | |
| 24 | import org.jaudiotagger.audio.asf.util.Utils; | |
| 25 | ||
| 26 | import java.io.IOException; | |
| 27 | import java.io.InputStream; | |
| 28 | import java.math.BigInteger; | |
| 29 | ||
| 30 | /** | |
| 31 | * This class reads the chunk containing the stream bitrate properties.<br> | |
| 32 | * | |
| 33 | * @author Christian Laireiter | |
| 34 | */ | |
| 35 | public class StreamBitratePropertiesReader implements ChunkReader { | |
| 36 | ||
| 37 | /** | |
| 38 | * The GUID this reader {@linkplain #getApplyingIds() applies to} | |
| 39 | */ | |
| 40 | 4 | private final static GUID[] APPLYING = { GUID.GUID_STREAM_BITRATE_PROPERTIES }; |
| 41 | ||
| 42 | /** | |
| 43 | * Should not be used for now. | |
| 44 | */ | |
| 45 | 4 | protected StreamBitratePropertiesReader() { |
| 46 | // NOTHING toDo | |
| 47 | 4 | } |
| 48 | ||
| 49 | /** | |
| 50 | * {@inheritDoc} | |
| 51 | */ | |
| 52 | public boolean canFail() { | |
| 53 | 80 | return false; |
| 54 | } | |
| 55 | ||
| 56 | /** | |
| 57 | * {@inheritDoc} | |
| 58 | */ | |
| 59 | public GUID[] getApplyingIds() { | |
| 60 | 4 | return APPLYING.clone(); |
| 61 | } | |
| 62 | ||
| 63 | /** | |
| 64 | * {@inheritDoc} | |
| 65 | */ | |
| 66 | public Chunk read(final GUID guid, final InputStream stream, | |
| 67 | final long chunkStart) throws IOException { | |
| 68 | 80 | final BigInteger chunkLen = Utils.readBig64(stream); |
| 69 | 80 | final StreamBitratePropertiesChunk result = new StreamBitratePropertiesChunk( |
| 70 | chunkLen); | |
| 71 | ||
| 72 | /* | |
| 73 | * Read the amount of bitrate records | |
| 74 | */ | |
| 75 | 80 | final long recordCount = Utils.readUINT16(stream); |
| 76 | 160 | for (int i = 0; i < recordCount; i++) { |
| 77 | 80 | final int flags = Utils.readUINT16(stream); |
| 78 | 80 | final long avgBitrate = Utils.readUINT32(stream); |
| 79 | 80 | result.addBitrateRecord(flags & 0x00FF, avgBitrate); |
| 80 | } | |
| 81 | ||
| 82 | 80 | result.setPosition(chunkStart); |
| 83 | ||
| 84 | 80 | return result; |
| 85 | } | |
| 86 | ||
| 87 | } |