|
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 |
|
17 | | -package xyz.gianlu.librespot.player.codecs; |
| 17 | +package xyz.gianlu.librespot.player.decoders; |
18 | 18 |
|
19 | 19 | import org.jetbrains.annotations.NotNull; |
20 | | -import org.jetbrains.annotations.Nullable; |
21 | 20 | import org.slf4j.Logger; |
22 | 21 | import org.slf4j.LoggerFactory; |
23 | | -import xyz.gianlu.librespot.audio.AbsChunkedInputStream; |
24 | | -import xyz.gianlu.librespot.audio.GeneralAudioStream; |
25 | | -import xyz.gianlu.librespot.audio.NormalizationData; |
26 | | -import xyz.gianlu.librespot.player.PlayerConfiguration; |
27 | 22 | import xyz.gianlu.librespot.player.mixing.output.OutputAudioFormat; |
28 | 23 |
|
29 | 24 | import java.io.Closeable; |
30 | 25 | import java.io.IOException; |
31 | 26 | import java.io.OutputStream; |
32 | 27 |
|
33 | 28 | /** |
34 | | - * @author Gianlu |
| 29 | + * @author devgianlu |
35 | 30 | */ |
36 | | -public abstract class Codec implements Closeable { |
| 31 | +public abstract class Decoder implements Closeable { |
37 | 32 | public static final int BUFFER_SIZE = 2048; |
38 | | - private static final Logger LOGGER = LoggerFactory.getLogger(Codec.class); |
39 | | - protected final AbsChunkedInputStream audioIn; |
| 33 | + private static final Logger LOGGER = LoggerFactory.getLogger(Decoder.class); |
| 34 | + protected final SeekableInputStream audioIn; |
40 | 35 | protected final float normalizationFactor; |
41 | 36 | protected final int duration; |
42 | | - private final GeneralAudioStream audioFile; |
43 | 37 | protected volatile boolean closed = false; |
44 | 38 | protected int seekZero = 0; |
45 | 39 | private OutputAudioFormat format; |
46 | 40 |
|
47 | | - public Codec(@NotNull GeneralAudioStream audioFile, @Nullable NormalizationData normalizationData, @NotNull PlayerConfiguration conf, int duration) { |
48 | | - this.audioIn = audioFile.stream(); |
49 | | - this.audioFile = audioFile; |
| 41 | + public Decoder(@NotNull SeekableInputStream audioIn, float normalizationFactor, int duration) { |
| 42 | + this.audioIn = audioIn; |
50 | 43 | this.duration = duration; |
51 | | - if (conf.enableNormalisation) |
52 | | - this.normalizationFactor = normalizationData != null ? normalizationData.getFactor(conf.normalisationPregain) : 1; |
53 | | - else |
54 | | - this.normalizationFactor = 1; |
| 44 | + this.normalizationFactor = normalizationFactor; |
55 | 45 | } |
56 | 46 |
|
57 | 47 | public final int writeSomeTo(@NotNull OutputStream out) throws IOException, CodecException { |
@@ -108,25 +98,27 @@ public final int duration() { |
108 | 98 | return duration; |
109 | 99 | } |
110 | 100 |
|
111 | | - public int size() { |
| 101 | + public final int size() { |
112 | 102 | return audioIn.size(); |
113 | 103 | } |
114 | 104 |
|
115 | | - public int decodedLength() { |
116 | | - return audioIn.decodedLength(); |
117 | | - } |
118 | | - |
119 | | - public int decryptTimeMs() { |
120 | | - return audioFile.decryptTimeMs(); |
121 | | - } |
122 | | - |
123 | 105 | public static class CannotGetTimeException extends Exception { |
124 | | - CannotGetTimeException() { |
| 106 | + public CannotGetTimeException(String message) { |
| 107 | + super(message); |
| 108 | + } |
| 109 | + |
| 110 | + public CannotGetTimeException(String message, Throwable cause) { |
| 111 | + super(message, cause); |
125 | 112 | } |
126 | 113 | } |
127 | 114 |
|
128 | 115 | public static class CodecException extends Exception { |
129 | | - CodecException() { |
| 116 | + public CodecException(String message) { |
| 117 | + super(message); |
| 118 | + } |
| 119 | + |
| 120 | + public CodecException(String message, Throwable cause) { |
| 121 | + super(message, cause); |
130 | 122 | } |
131 | 123 | } |
132 | 124 | } |
0 commit comments