|
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 | 20 | import org.jetbrains.annotations.Nullable; |
21 | 21 | import org.slf4j.Logger; |
22 | 22 | import org.slf4j.LoggerFactory; |
23 | 23 | import xyz.gianlu.librespot.audio.GeneralAudioStream; |
24 | | -import xyz.gianlu.librespot.audio.NormalizationData; |
25 | 24 | import xyz.gianlu.librespot.audio.format.SuperAudioFormat; |
26 | | -import xyz.gianlu.librespot.player.PlayerConfiguration; |
27 | 25 |
|
28 | 26 | import java.util.*; |
29 | 27 |
|
30 | 28 | /** |
31 | 29 | * @author devgianlu |
32 | 30 | */ |
33 | | -public final class Codecs { |
34 | | - private static final Map<SuperAudioFormat, HashSet<Class<? extends Codec>>> codecs = new EnumMap<>(SuperAudioFormat.class); |
35 | | - private static final Logger LOGGER = LoggerFactory.getLogger(Codecs.class); |
| 31 | +public final class Decoders { |
| 32 | + private static final Map<SuperAudioFormat, HashSet<Class<? extends Decoder>>> decoders = new EnumMap<>(SuperAudioFormat.class); |
| 33 | + private static final Logger LOGGER = LoggerFactory.getLogger(Decoders.class); |
36 | 34 |
|
37 | 35 | static { |
38 | | - registerCodec(SuperAudioFormat.VORBIS, VorbisCodec.class); |
39 | | - registerCodec(SuperAudioFormat.MP3, Mp3Codec.class); |
| 36 | + registerDecoder(SuperAudioFormat.VORBIS, VorbisDecoder.class); |
| 37 | + registerDecoder(SuperAudioFormat.MP3, Mp3Decoder.class); |
40 | 38 | } |
41 | 39 |
|
42 | | - private Codecs() { |
| 40 | + private Decoders() { |
43 | 41 | } |
44 | 42 |
|
45 | 43 | @Nullable |
46 | | - public static Codec initCodec(@NotNull SuperAudioFormat format, @NotNull GeneralAudioStream audioFile, @Nullable NormalizationData normalizationData, @NotNull PlayerConfiguration conf, int duration) { |
47 | | - Set<Class<? extends Codec>> set = codecs.get(format); |
| 44 | + public static Decoder initDecoder(@NotNull SuperAudioFormat format, @NotNull GeneralAudioStream audioFile, float normalizationFactor, int duration) { |
| 45 | + Set<Class<? extends Decoder>> set = decoders.get(format); |
48 | 46 | if (set == null) return null; |
49 | 47 |
|
50 | | - Optional<Class<? extends Codec>> opt = set.stream().findFirst(); |
| 48 | + Optional<Class<? extends Decoder>> opt = set.stream().findFirst(); |
51 | 49 | if (!opt.isPresent()) return null; |
52 | 50 |
|
53 | 51 | try { |
54 | | - Class<? extends Codec> clazz = opt.get(); |
55 | | - return clazz.getConstructor(GeneralAudioStream.class, NormalizationData.class, PlayerConfiguration.class, int.class).newInstance(audioFile, normalizationData, conf, duration); |
| 52 | + Class<? extends Decoder> clazz = opt.get(); |
| 53 | + return clazz.getConstructor(GeneralAudioStream.class, float.class, int.class).newInstance(audioFile, normalizationFactor, duration); |
56 | 54 | } catch (ReflectiveOperationException ex) { |
57 | 55 | LOGGER.error("Failed initializing Codec instance for {}", format, ex); |
58 | 56 | return null; |
59 | 57 | } |
60 | 58 | } |
61 | 59 |
|
62 | | - public static void registerCodec(@NotNull SuperAudioFormat format, @NotNull Class<? extends Codec> clazz) { |
63 | | - codecs.computeIfAbsent(format, (key) -> new HashSet<>(5)).add(clazz); |
| 60 | + public static void registerDecoder(@NotNull SuperAudioFormat format, @NotNull Class<? extends Decoder> clazz) { |
| 61 | + decoders.computeIfAbsent(format, (key) -> new HashSet<>(5)).add(clazz); |
64 | 62 | } |
65 | 63 |
|
66 | | - public static void replaceCodecs(@NotNull SuperAudioFormat format, @NotNull Class<? extends Codec> clazz) { |
67 | | - Set<Class<? extends Codec>> set = codecs.get(format); |
| 64 | + public static void replaceDecoder(@NotNull SuperAudioFormat format, @NotNull Class<? extends Decoder> clazz) { |
| 65 | + Set<Class<? extends Decoder>> set = decoders.get(format); |
68 | 66 | if (set != null) set.clear(); |
69 | | - registerCodec(format, clazz); |
| 67 | + registerDecoder(format, clazz); |
70 | 68 | } |
71 | 69 |
|
72 | | - public static void unregisterCodec(@NotNull Class<? extends Codec> clazz) { |
73 | | - for (Set<Class<? extends Codec>> set : codecs.values()) |
| 70 | + public static void unregisterDecoder(@NotNull Class<? extends Decoder> clazz) { |
| 71 | + for (Set<Class<? extends Decoder>> set : decoders.values()) |
74 | 72 | set.remove(clazz); |
75 | 73 | } |
76 | 74 | } |
0 commit comments