-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
256 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...agers/src/main/java/com/dunctebot/sourcemanagers/elgato/streamdeck/ElgatoInputStream.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.dunctebot.sourcemanagers.elgato.streamdeck; | ||
|
||
import com.sedmelluq.discord.lavaplayer.tools.io.SeekableInputStream; | ||
import com.sedmelluq.discord.lavaplayer.track.info.AudioTrackInfoProvider; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
// TODO: can I inject a custom probe into LP? | ||
// See: MediaContainerRegistry | ||
public class ElgatoInputStream extends SeekableInputStream { | ||
private static final byte XOR_VAL = 0x5E; | ||
|
||
private final SeekableInputStream inputStream; | ||
|
||
public ElgatoInputStream(SeekableInputStream inputStream) { | ||
super(inputStream.getContentLength(), inputStream.getMaxSkipDistance()); | ||
this.inputStream = inputStream; | ||
} | ||
|
||
@Override | ||
public long getPosition() { | ||
return this.inputStream.getPosition(); | ||
} | ||
|
||
// TODO: Will this work? | ||
@Override | ||
protected void seekHard(long position) throws IOException { | ||
((ElgatoInputStream) this.inputStream).seekHard(position); | ||
} | ||
|
||
@Override | ||
public boolean canSeekHard() { | ||
return this.inputStream.canSeekHard(); | ||
} | ||
|
||
@Override | ||
public List<AudioTrackInfoProvider> getTrackInfoProviders() { | ||
return this.inputStream.getTrackInfoProviders(); | ||
} | ||
|
||
@Override | ||
public int read() throws IOException { | ||
final var read = this.inputStream.read(); | ||
|
||
if (read == -1) { | ||
return -1; | ||
} | ||
|
||
return read ^ XOR_VAL; | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
super.close(); | ||
this.inputStream.close(); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...ain/java/com/dunctebot/sourcemanagers/elgato/streamdeck/StreamDeckAudioSourceManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.dunctebot.sourcemanagers.elgato.streamdeck; | ||
|
||
import com.dunctebot.sourcemanagers.AbstractDuncteBotHttpSource; | ||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager; | ||
import com.sedmelluq.discord.lavaplayer.tools.Units; | ||
import com.sedmelluq.discord.lavaplayer.track.AudioItem; | ||
import com.sedmelluq.discord.lavaplayer.track.AudioReference; | ||
import com.sedmelluq.discord.lavaplayer.track.AudioTrack; | ||
import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo; | ||
|
||
import java.io.DataInput; | ||
import java.io.DataOutput; | ||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.util.List; | ||
import java.util.Locale; | ||
|
||
// TODO: http vs local file | ||
public class StreamDeckAudioSourceManager extends AbstractDuncteBotHttpSource { | ||
@Override | ||
public String getSourceName() { | ||
return "StreamDeckAudio"; | ||
} | ||
|
||
@Override | ||
public AudioItem loadItem(AudioPlayerManager manager, AudioReference reference) { | ||
try { | ||
final var url = new URI(reference.getIdentifier()); | ||
|
||
if (url.getPath().toLowerCase(Locale.ROOT).endsWith(".streamdeckaudio")) { | ||
final var parts = List.of(url.getPath().split("/")); | ||
final var fileName = parts.get(parts.size() - 1); | ||
|
||
return new StreamDeckAudioTrack( | ||
new AudioTrackInfo( | ||
fileName, | ||
"Elgato", | ||
Units.CONTENT_LENGTH_UNKNOWN, | ||
fileName, | ||
false, | ||
url.toString() | ||
), | ||
this | ||
); | ||
} | ||
} catch (URISyntaxException ignored) { | ||
return null; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
@Override | ||
public boolean isTrackEncodable(AudioTrack track) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void encodeTrack(AudioTrack track, DataOutput output) throws IOException { | ||
// Nothing to encode | ||
} | ||
|
||
@Override | ||
public AudioTrack decodeTrack(AudioTrackInfo trackInfo, DataInput input) throws IOException { | ||
return new StreamDeckAudioTrack(trackInfo, this); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...rs/src/main/java/com/dunctebot/sourcemanagers/elgato/streamdeck/StreamDeckAudioTrack.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.dunctebot.sourcemanagers.elgato.streamdeck; | ||
|
||
import com.dunctebot.sourcemanagers.Mp3Track; | ||
import com.sedmelluq.discord.lavaplayer.container.wav.WavAudioTrack; | ||
import com.sedmelluq.discord.lavaplayer.tools.io.SeekableInputStream; | ||
import com.sedmelluq.discord.lavaplayer.track.AudioTrack; | ||
import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo; | ||
import com.sedmelluq.discord.lavaplayer.track.InternalAudioTrack; | ||
|
||
public class StreamDeckAudioTrack extends Mp3Track { | ||
private final StreamDeckAudioSourceManager manager; | ||
|
||
public StreamDeckAudioTrack(AudioTrackInfo trackInfo, StreamDeckAudioSourceManager manager) { | ||
super(trackInfo, manager); | ||
this.manager = manager; | ||
} | ||
|
||
@Override | ||
protected SeekableInputStream wrapStream(SeekableInputStream stream) { | ||
return new ElgatoInputStream(stream); | ||
} | ||
|
||
@Override | ||
protected InternalAudioTrack createAudioTrack(AudioTrackInfo trackInfo, SeekableInputStream stream) { | ||
return new WavAudioTrack(trackInfo, stream); | ||
} | ||
|
||
@Override | ||
public String getPlaybackUrl() { | ||
return this.trackInfo.uri; | ||
} | ||
|
||
@Override | ||
protected AudioTrack makeShallowClone() { | ||
return new StreamDeckAudioTrack(this.trackInfo, this.manager); | ||
} | ||
|
||
@Override | ||
public StreamDeckAudioSourceManager getSourceManager() { | ||
return this.manager; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import com.dunctebot.sourcemanagers.elgato.streamdeck.StreamDeckAudioSourceManager; | ||
import com.sedmelluq.discord.lavaplayer.format.AudioDataFormat; | ||
import com.sedmelluq.discord.lavaplayer.format.AudioPlayerInputStream; | ||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer; | ||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager; | ||
import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager; | ||
import com.sedmelluq.discord.lavaplayer.player.FunctionalResultHandler; | ||
|
||
import javax.sound.sampled.AudioInputStream; | ||
import javax.sound.sampled.AudioSystem; | ||
import javax.sound.sampled.DataLine; | ||
import javax.sound.sampled.SourceDataLine; | ||
|
||
import static com.sedmelluq.discord.lavaplayer.format.StandardAudioDataFormats.COMMON_PCM_S16_BE; | ||
|
||
public class LocalPlaybackTest { | ||
public static void main(String[] args) throws Exception { | ||
final var mngr = new StreamDeckAudioSourceManager(); | ||
|
||
AudioPlayerManager manager = new DefaultAudioPlayerManager(); | ||
|
||
manager.registerSourceManager(mngr); | ||
|
||
manager.getConfiguration().setOutputFormat(COMMON_PCM_S16_BE); | ||
|
||
AudioPlayer player = manager.createPlayer(); | ||
|
||
player.setVolume(35); | ||
|
||
manager.loadItem( | ||
"https://cdn.discordapp.com/attachments/340834322674089986/1242398908815118376/Fanfare_-_Show_Intro.streamDeckAudio?ex=664f0326&is=664db1a6&hm=9a4898f7301601b3bc14cfda4101aab0ed94cdfb5fe89d2a0917dc4e01514da6&", | ||
new FunctionalResultHandler(item -> { | ||
player.playTrack(item); | ||
}, playlist -> { | ||
player.playTrack(playlist.getTracks().get(0)); | ||
}, null, null) | ||
); | ||
|
||
|
||
AudioDataFormat format = manager.getConfiguration().getOutputFormat(); | ||
AudioInputStream stream = AudioPlayerInputStream.createStream(player, format, 10000L, false); | ||
SourceDataLine.Info info = new DataLine.Info(SourceDataLine.class, stream.getFormat()); | ||
SourceDataLine line = (SourceDataLine) AudioSystem.getLine(info); | ||
|
||
line.open(stream.getFormat()); | ||
line.start(); | ||
|
||
byte[] buffer = new byte[COMMON_PCM_S16_BE.maximumChunkSize()]; | ||
int chunkSize; | ||
|
||
while ((chunkSize = stream.read(buffer)) >= 0) { | ||
line.write(buffer, 0, chunkSize); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
org.slf4j.simpleLogger.defaultLogLevel=TRACE | ||
|
||
defaultLogLevel=TRACE |